|
@@ -14,6 +14,23 @@ class AESTests: XCTestCase {
|
|
|
// 128 bit key
|
|
|
let aesKey:[Byte] = [0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f]
|
|
|
|
|
|
+ func testAES_encrypt2() {
|
|
|
+ let key:[Byte] = [0x36, 0x37, 0x39, 0x66, 0x62, 0x31, 0x64, 0x64, 0x66, 0x37, 0x64, 0x38, 0x31, 0x62, 0x65, 0x65];
|
|
|
+ let iv:[Byte] = [0x6b, 0x64, 0x66, 0x36, 0x37, 0x33, 0x39, 0x38, 0x44, 0x46, 0x37, 0x33, 0x38, 0x33, 0x66, 0x64]
|
|
|
+ let input:[Byte] = [0x62, 0x72, 0x61, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00];
|
|
|
+
|
|
|
+ let expected:[Byte] = [0xae,0x8c,0x59,0x95,0xb2,0x6f,0x8e,0x3d,0xb0,0x6f,0x0a,0xa5,0xfe,0xc4,0xf0,0xc2];
|
|
|
+
|
|
|
+ if let aes = AES(key: NSData.withBytes(key), iv: NSData.withBytes(iv), blockMode: .CBC) {
|
|
|
+ let encrypted = aes.encrypt(NSData.withBytes(input))
|
|
|
+ XCTAssertEqual(encrypted!, NSData.withBytes(expected), "encryption failed")
|
|
|
+ let decrypted = aes.decrypt(encrypted!)
|
|
|
+ XCTAssertEqual(decrypted!, NSData.withBytes(input), "decryption failed")
|
|
|
+ } else {
|
|
|
+ XCTAssert(false, "failed")
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
func testAES_encrypt() {
|
|
|
let input:[Byte] = [0x00, 0x11, 0x22, 0x33,
|
|
|
0x44, 0x55, 0x66, 0x77,
|
|
@@ -25,7 +42,7 @@ class AESTests: XCTestCase {
|
|
|
0xd8, 0xcd, 0xb7, 0x80,
|
|
|
0x70, 0xb4, 0xc5, 0x5a];
|
|
|
|
|
|
- if let aes = AES(key: NSData.withBytes(aesKey), iv: nil, blockMode: .Plain) {
|
|
|
+ if let aes = AES(key: NSData.withBytes(aesKey), iv: nil, blockMode: .ECB) {
|
|
|
let encrypted = aes.encrypt(NSData.withBytes(input))
|
|
|
XCTAssertEqual(encrypted!, NSData.withBytes(expected), "encryption failed")
|
|
|
let decrypted = aes.decrypt(encrypted!)
|