|
@@ -85,7 +85,7 @@ final class AESTests: XCTestCase {
|
|
|
let decrypted = try! aes.decrypt(encrypted, padding: nil)
|
|
|
XCTAssertEqual(decrypted, plaintext, "decryption failed")
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// https://github.com/krzyzanowskim/CryptoSwift/issues/142
|
|
|
func testAES_encrypt_cfb_long() {
|
|
|
let key: [UInt8] = [56, 118, 37, 51, 125, 78, 103, 107, 119, 40, 74, 88, 117, 112, 123, 75, 122, 89, 72, 36, 46, 91, 106, 60, 54, 110, 34, 126, 69, 126, 61, 87]
|
|
@@ -95,7 +95,35 @@ final class AESTests: XCTestCase {
|
|
|
let decrypted: [UInt8] = try! AES(key: key, iv: iv, blockMode: .CFB).decrypt(encrypted)
|
|
|
XCTAssert(decrypted == plaintext, "decryption failed")
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
+ func testAES_encrypt_ofb128() {
|
|
|
+ let key:[UInt8] = [0x2b,0x7e,0x15,0x16,0x28,0xae,0xd2,0xa6,0xab,0xf7,0x15,0x88,0x09,0xcf,0x4f,0x3c];
|
|
|
+ let iv:[UInt8] = [0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F]
|
|
|
+ let plaintext:[UInt8] = [0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a]
|
|
|
+ let expected:[UInt8] = [0x3b,0x3f,0xd9,0x2e,0xb7,0x2d,0xad,0x20,0x33,0x34,0x49,0xf8,0xe8,0x3c,0xfb,0x4a];
|
|
|
+
|
|
|
+ let aes = try! AES(key: key, iv:iv, blockMode: .OFB)
|
|
|
+ XCTAssertTrue(aes.blockMode == .OFB, "Invalid block mode")
|
|
|
+ let encrypted = try! aes.encrypt(plaintext, padding: nil)
|
|
|
+ XCTAssertEqual(encrypted, expected, "encryption failed")
|
|
|
+ let decrypted = try! aes.decrypt(encrypted, padding: nil)
|
|
|
+ XCTAssertEqual(decrypted, plaintext, "decryption failed")
|
|
|
+ }
|
|
|
+
|
|
|
+ func testAES_encrypt_ofb256() {
|
|
|
+ let key: [UInt8] = [0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4]
|
|
|
+ let iv: [UInt8] = [0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F]
|
|
|
+ let plaintext: [UInt8] = [0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a]
|
|
|
+ let expected:[UInt8] = [0xdc,0x7e,0x84,0xbf,0xda,0x79,0x16,0x4b,0x7e,0xcd,0x84,0x86,0x98,0x5d,0x38,0x60];
|
|
|
+
|
|
|
+ let aes = try! AES(key: key, iv:iv, blockMode: .OFB)
|
|
|
+ XCTAssertTrue(aes.blockMode == .OFB, "Invalid block mode")
|
|
|
+ let encrypted = try! aes.encrypt(plaintext, padding: nil)
|
|
|
+ XCTAssertEqual(encrypted, expected, "encryption failed")
|
|
|
+ let decrypted = try! aes.decrypt(encrypted, padding: nil)
|
|
|
+ XCTAssertEqual(decrypted, plaintext, "decryption failed")
|
|
|
+ }
|
|
|
+
|
|
|
func testAES_encrypt_ctr() {
|
|
|
let key:[UInt8] = [0x2b,0x7e,0x15,0x16,0x28,0xae,0xd2,0xa6,0xab,0xf7,0x15,0x88,0x09,0xcf,0x4f,0x3c];
|
|
|
let iv:[UInt8] = [0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff]
|