|
@@ -124,6 +124,21 @@ final class AESTests: XCTestCase {
|
|
|
XCTAssertEqual(decrypted, plaintext, "decryption failed")
|
|
|
}
|
|
|
|
|
|
+ func testAES_encrypt_pcbc256() {
|
|
|
+ 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] = [0xf5,0x8c,0x4c,0x04,0xd6,0xe5,0xf1,0xba,0x77,0x9e,0xab,0xfb,0x5f,0x7b,0xfb,0xd6];
|
|
|
+
|
|
|
+ let aes = try! AES(key: key, iv:iv, blockMode: .PCBC)
|
|
|
+ XCTAssertTrue(aes.blockMode == .PCBC, "Invalid block mode")
|
|
|
+ let encrypted = try! aes.encrypt(plaintext, padding: nil)
|
|
|
+ print(encrypted.toHexString())
|
|
|
+ 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]
|