|
@@ -13,6 +13,17 @@ final class AESTests: XCTestCase {
|
|
// 128 bit key
|
|
// 128 bit key
|
|
let aesKey: Array<UInt8> = [0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f]
|
|
let aesKey: Array<UInt8> = [0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f]
|
|
|
|
|
|
|
|
+ func testAESEncrypt() {
|
|
|
|
+ let input: Array<UInt8> = [0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff]
|
|
|
|
+ let expected: Array<UInt8> = [0x69, 0xc4, 0xe0, 0xd8, 0x6a, 0x7b, 0x4, 0x30, 0xd8, 0xcd, 0xb7, 0x80, 0x70, 0xb4, 0xc5, 0x5a]
|
|
|
|
+
|
|
|
|
+ let aes = try! AES(key: aesKey, blockMode: .ECB, padding: NoPadding())
|
|
|
|
+ let encrypted = try! aes.encrypt(input)
|
|
|
|
+ XCTAssertEqual(encrypted, expected, "encryption failed")
|
|
|
|
+ let decrypted = try! aes.decrypt(encrypted)
|
|
|
|
+ XCTAssertEqual(decrypted, input, "decryption failed")
|
|
|
|
+ }
|
|
|
|
+
|
|
func testAESEncrypt2() {
|
|
func testAESEncrypt2() {
|
|
let key: Array<UInt8> = [0x36, 0x37, 0x39, 0x66, 0x62, 0x31, 0x64, 0x64, 0x66, 0x37, 0x64, 0x38, 0x31, 0x62, 0x65, 0x65]
|
|
let key: Array<UInt8> = [0x36, 0x37, 0x39, 0x66, 0x62, 0x31, 0x64, 0x64, 0x66, 0x37, 0x64, 0x38, 0x31, 0x62, 0x65, 0x65]
|
|
let iv: Array<UInt8> = [0x6b, 0x64, 0x66, 0x36, 0x37, 0x33, 0x39, 0x38, 0x44, 0x46, 0x37, 0x33, 0x38, 0x33, 0x66, 0x64]
|
|
let iv: Array<UInt8> = [0x6b, 0x64, 0x66, 0x36, 0x37, 0x33, 0x39, 0x38, 0x44, 0x46, 0x37, 0x33, 0x38, 0x33, 0x66, 0x64]
|
|
@@ -40,17 +51,6 @@ final class AESTests: XCTestCase {
|
|
XCTAssertEqual(decrypted, input, "decryption failed")
|
|
XCTAssertEqual(decrypted, input, "decryption failed")
|
|
}
|
|
}
|
|
|
|
|
|
- func testAESEncrypt() {
|
|
|
|
- let input: Array<UInt8> = [0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff]
|
|
|
|
- let expected: Array<UInt8> = [0x69, 0xc4, 0xe0, 0xd8, 0x6a, 0x7b, 0x4, 0x30, 0xd8, 0xcd, 0xb7, 0x80, 0x70, 0xb4, 0xc5, 0x5a]
|
|
|
|
-
|
|
|
|
- let aes = try! AES(key: aesKey, blockMode: .ECB, padding: NoPadding())
|
|
|
|
- let encrypted = try! aes.encrypt(input)
|
|
|
|
- XCTAssertEqual(encrypted, expected, "encryption failed")
|
|
|
|
- let decrypted = try! aes.decrypt(encrypted)
|
|
|
|
- XCTAssertEqual(decrypted, input, "decryption failed")
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
func testAESEncryptCBCNoPadding() {
|
|
func testAESEncryptCBCNoPadding() {
|
|
let key: Array<UInt8> = [0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c]
|
|
let key: Array<UInt8> = [0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c]
|
|
let iv: Array<UInt8> = [0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F]
|
|
let iv: Array<UInt8> = [0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F]
|
|
@@ -367,9 +367,9 @@ extension AESTests {
|
|
|
|
|
|
static func allTests() -> [(String, (AESTests) -> () -> Void)] {
|
|
static func allTests() -> [(String, (AESTests) -> () -> Void)] {
|
|
var tests = [
|
|
var tests = [
|
|
|
|
+ ("testAESEncrypt", testAESEncrypt),
|
|
("testAESEncrypt2", testAESEncrypt2),
|
|
("testAESEncrypt2", testAESEncrypt2),
|
|
("testAESEncrypt3", testAESEncrypt3),
|
|
("testAESEncrypt3", testAESEncrypt3),
|
|
- ("testAESEncrypt", testAESEncrypt),
|
|
|
|
("testAESEncryptCBCNoPadding", testAESEncryptCBCNoPadding),
|
|
("testAESEncryptCBCNoPadding", testAESEncryptCBCNoPadding),
|
|
("testAESEncryptCBCWithPadding", testAESEncryptCBCWithPadding),
|
|
("testAESEncryptCBCWithPadding", testAESEncryptCBCWithPadding),
|
|
("testAESEncryptCBCWithPaddingPartial", testAESEncryptCBCWithPaddingPartial),
|
|
("testAESEncryptCBCWithPaddingPartial", testAESEncryptCBCWithPaddingPartial),
|