|
@@ -440,33 +440,6 @@ extension AESTests {
|
|
XCTAssertEqual(decrypted, plaintext)
|
|
XCTAssertEqual(decrypted, plaintext)
|
|
}
|
|
}
|
|
|
|
|
|
- func testAESGCMTestCaseIrregularCombined() {
|
|
|
|
- // echo -n "0123456789010123456789012345" | openssl enc -aes-128-gcm -K feffe9928665731c6d6a8f9467308308 -iv cafebabefacedbaddecaf888 -nopad -nosalt
|
|
|
|
- // openssl note: The enc program does not support authenticated encryption modes like CCM and GCM. The utility does not store or retrieve the authentication tag
|
|
|
|
- let key = Array<UInt8>(hex: "0xfeffe9928665731c6d6a8f9467308308")
|
|
|
|
- //let plaintext = Array<UInt8>(hex: "0xd9313225f88406e5a55909c5aff5269a86a7a9531534f7da2e4c303d8a318a721c3c0c95956809532fcf0e2449a6b525b16aedf5aa0de657ba637b391aafd255")
|
|
|
|
- let plaintext = "0123456789010123456789012345".bytes
|
|
|
|
- let iv = Array<UInt8>(hex: "0xcafebabefacedbaddecaf888")
|
|
|
|
-
|
|
|
|
- let encGCM = GCM(iv: iv, mode: .combined)
|
|
|
|
- let aes = try! AES(key: key, blockMode: encGCM, padding: .noPadding)
|
|
|
|
- let encrypted = try! aes.encrypt(plaintext)
|
|
|
|
-
|
|
|
|
- XCTAssertNotNil(encGCM.authenticationTag)
|
|
|
|
- XCTAssertEqual(Array(encrypted), [UInt8](hex: "0xab831ed4edc644f6d61218431b14c0355138be4b010f630b29be7a2b9793b9fbecc7b44cc86dfd697a50c1c6")) // C
|
|
|
|
- XCTAssertEqual(encGCM.authenticationTag, [UInt8](hex: "0x9793b9fbecc7b44cc86dfd697a50c1c6")) // T (128-bit)
|
|
|
|
-
|
|
|
|
- // decrypt
|
|
|
|
- func decrypt(_ encrypted: Array<UInt8>) -> Array<UInt8> {
|
|
|
|
- let decGCM = GCM(iv: iv, mode: .combined)
|
|
|
|
- let aes = try! AES(key: key, blockMode: decGCM, padding: .noPadding)
|
|
|
|
- return try! aes.decrypt(encrypted)
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- let decrypted = decrypt(encrypted)
|
|
|
|
- XCTAssertEqual(decrypted, plaintext)
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
func testAESGCMTestCase4() {
|
|
func testAESGCMTestCase4() {
|
|
// Test Case 4
|
|
// Test Case 4
|
|
let key = Array<UInt8>(hex: "0xfeffe9928665731c6d6a8f9467308308")
|
|
let key = Array<UInt8>(hex: "0xfeffe9928665731c6d6a8f9467308308")
|
|
@@ -525,6 +498,58 @@ extension AESTests {
|
|
XCTAssertEqual(Array(encrypted), [UInt8](hex: "")) // C
|
|
XCTAssertEqual(Array(encrypted), [UInt8](hex: "")) // C
|
|
XCTAssertEqual(gcm.authenticationTag, [UInt8](hex: "0xcd33b28ac773f74ba00ed1f312572435")) // T (128-bit)
|
|
XCTAssertEqual(gcm.authenticationTag, [UInt8](hex: "0xcd33b28ac773f74ba00ed1f312572435")) // T (128-bit)
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ func testAESGCMTestCaseIrregularCombined1() {
|
|
|
|
+ // echo -n "0123456789010123456789012345" | openssl enc -aes-128-gcm -K feffe9928665731c6d6a8f9467308308 -iv cafebabefacedbaddecaf888 -nopad -nosalt
|
|
|
|
+ // openssl note: The enc program does not support authenticated encryption modes like CCM and GCM. The utility does not store or retrieve the authentication tag
|
|
|
|
+ let key = Array<UInt8>(hex: "0xfeffe9928665731c6d6a8f9467308308")
|
|
|
|
+ let plaintext = "0123456789010123456789012345".bytes
|
|
|
|
+ let iv = Array<UInt8>(hex: "0xcafebabefacedbaddecaf888")
|
|
|
|
+
|
|
|
|
+ let encGCM = GCM(iv: iv, mode: .combined)
|
|
|
|
+ let aes = try! AES(key: key, blockMode: encGCM, padding: .noPadding)
|
|
|
|
+ let encrypted = try! aes.encrypt(plaintext)
|
|
|
|
+
|
|
|
|
+ XCTAssertNotNil(encGCM.authenticationTag)
|
|
|
|
+ XCTAssertEqual(Array(encrypted), [UInt8](hex: "0xab831ed4edc644f6d61218431b14c0355138be4b010f630b29be7a2b9793b9fbecc7b44cc86dfd697a50c1c6")) // C
|
|
|
|
+ XCTAssertEqual(encGCM.authenticationTag, [UInt8](hex: "0x9793b9fbecc7b44cc86dfd697a50c1c6")) // T (128-bit)
|
|
|
|
+
|
|
|
|
+ // decrypt
|
|
|
|
+ func decrypt(_ encrypted: Array<UInt8>) -> Array<UInt8> {
|
|
|
|
+ let decGCM = GCM(iv: iv, mode: .combined)
|
|
|
|
+ let aes = try! AES(key: key, blockMode: decGCM, padding: .noPadding)
|
|
|
|
+ return try! aes.decrypt(encrypted)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ let decrypted = decrypt(encrypted)
|
|
|
|
+ XCTAssertEqual(decrypted, plaintext)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ func testAESGCMTestCaseIrregularCombined2() {
|
|
|
|
+ // echo -n "0123456789010123456789012345012345678901012345678901234567" | openssl enc -aes-128-gcm -K feffe9928665731c6d6a8f9467308308 -iv cafebabefacedbaddecaf888 -nopad -nosalt
|
|
|
|
+ // openssl note: The enc program does not support authenticated encryption modes like CCM and GCM. The utility does not store or retrieve the authentication tag
|
|
|
|
+ let key = Array<UInt8>(hex: "0xfeffe9928665731c6d6a8f9467308308")
|
|
|
|
+ let plaintext = "0123456789010123456789012345012345678901012345678901234567".bytes
|
|
|
|
+ let iv = Array<UInt8>(hex: "0xcafebabefacedbaddecaf888")
|
|
|
|
+
|
|
|
|
+ let encGCM = GCM(iv: iv, mode: .combined)
|
|
|
|
+ let aes = try! AES(key: key, blockMode: encGCM, padding: .noPadding)
|
|
|
|
+ let encrypted = try! aes.encrypt(plaintext)
|
|
|
|
+
|
|
|
|
+ XCTAssertNotNil(encGCM.authenticationTag)
|
|
|
|
+ XCTAssertEqual(Array(encrypted), [UInt8](hex: "0xab831ed4edc644f6d61218431b14c0355138be4b010f630b29be7a2b93ac196f09dc2e10f937aa7e6271564dd117291792f0d6fdf2347ef5b10c86a7f414f0c91a8e59fd2405b850527e")) // C
|
|
|
|
+ XCTAssertEqual(encGCM.authenticationTag, [UInt8](hex: "0x86a7f414f0c91a8e59fd2405b850527e")) // T (128-bit)
|
|
|
|
+
|
|
|
|
+ // decrypt
|
|
|
|
+ func decrypt(_ encrypted: Array<UInt8>) -> Array<UInt8> {
|
|
|
|
+ let decGCM = GCM(iv: iv, mode: .combined)
|
|
|
|
+ let aes = try! AES(key: key, blockMode: decGCM, padding: .noPadding)
|
|
|
|
+ return try! aes.decrypt(encrypted)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ let decrypted = decrypt(encrypted)
|
|
|
|
+ XCTAssertEqual(decrypted, plaintext)
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
extension AESTests {
|
|
extension AESTests {
|
|
@@ -560,6 +585,8 @@ extension AESTests {
|
|
("testAESGCMTestCase5", testAESGCMTestCase5),
|
|
("testAESGCMTestCase5", testAESGCMTestCase5),
|
|
("testAESGCMTestCase6", testAESGCMTestCase6),
|
|
("testAESGCMTestCase6", testAESGCMTestCase6),
|
|
("testAESGCMTestCase7", testAESGCMTestCase7),
|
|
("testAESGCMTestCase7", testAESGCMTestCase7),
|
|
|
|
+ ("testAESGCMTestCaseIrregularCombined1", testAESGCMTestCaseIrregularCombined1),
|
|
|
|
+ ("testAESGCMTestCaseIrregularCombined2", testAESGCMTestCaseIrregularCombined2),
|
|
]
|
|
]
|
|
return tests
|
|
return tests
|
|
}
|
|
}
|