File tree Expand file tree Collapse file tree 2 files changed +8
-1
lines changed Expand file tree Collapse file tree 2 files changed +8
-1
lines changed Original file line number Diff line number Diff line change @@ -174,7 +174,7 @@ public final class SHA256 {
174
174
//
175
175
// inputBitLength + 1 + bitsToAppend ≡ 448 mod 512
176
176
let mod = inputBitLength % 512
177
- let bitsToAppend = mod == 448 ? 512 : 448 - mod - 1
177
+ let bitsToAppend = mod < 448 ? 448 - 1 - mod : 512 + 448 - mod - 1
178
178
179
179
// We already appended first 7 bits with 0x80 above.
180
180
input += [ UInt8] ( repeating: 0 , count: ( bitsToAppend - 7 ) / 8 )
Original file line number Diff line number Diff line change @@ -37,7 +37,14 @@ class SHA256Tests: XCTestCase {
37
37
XCTAssertEqual ( SHA256 ( stream. bytes) . digestString ( ) , " 23d00697ba26b4140869bab958431251e7e41982794d41b605b6a1d5dee56abf " )
38
38
}
39
39
40
+ func testLargeData( ) {
41
+ let data : [ UInt8 ] = ( 0 ..< 1788 ) . map { _ in 0x03 }
42
+ let digest = SHA256 ( data) . digestString ( )
43
+ XCTAssertEqual ( digest, " 907422e2f24d749d0add2b504ccae8ad1aa392477591905880fb2dc494e33d63 " )
44
+ }
45
+
40
46
static var allTests = [
41
47
( " testBasics " , testBasics) ,
48
+ ( " testLargeData " , testLargeData) ,
42
49
]
43
50
}
You can’t perform that action at this time.
0 commit comments