浏览代码

Merge branch 'develop'

Marcin Krzyżanowski 9 年之前
父节点
当前提交
f464a4028a
共有 55 个文件被更改,包括 326 次插入308 次删除
  1. 4 0
      CHANGELOG
  2. 4 4
      CryptoSwift.playground/Contents.swift
  3. 2 2
      CryptoSwift.podspec
  4. 6 0
      CryptoSwift.xcodeproj/project.pbxproj
  5. 67 67
      CryptoSwiftTests/AESTests.swift
  6. 10 10
      CryptoSwiftTests/ChaCha20Tests.swift
  7. 1 1
      CryptoSwiftTests/ExtensionsTest.swift
  8. 15 15
      CryptoSwiftTests/HMACTests.swift
  9. 10 10
      CryptoSwiftTests/HashTests.swift
  10. 1 1
      CryptoSwiftTests/Helpers.swift
  11. 12 5
      CryptoSwiftTests/PBKDF.swift
  12. 6 6
      CryptoSwiftTests/PaddingTests.swift
  13. 3 3
      CryptoSwiftTests/Poly1305Tests.swift
  14. 14 14
      CryptoSwiftTests/RabbitTests.swift
  15. 14 14
      README.md
  16. 7 7
      Sources/CryptoSwift/AES.swift
  17. 1 1
      Sources/CryptoSwift/Array+Extension.swift
  18. 3 3
      Sources/CryptoSwift/Authenticator.swift
  19. 1 1
      Sources/CryptoSwift/BlockMode/BlockMode.swift
  20. 2 2
      Sources/CryptoSwift/BlockMode/BlockModeWorker.swift
  21. 2 2
      Sources/CryptoSwift/BlockMode/CBC.swift
  22. 2 2
      Sources/CryptoSwift/BlockMode/CFB.swift
  23. 3 3
      Sources/CryptoSwift/BlockMode/CTR.swift
  24. 2 2
      Sources/CryptoSwift/BlockMode/ECB.swift
  25. 2 2
      Sources/CryptoSwift/BlockMode/OFB.swift
  26. 2 2
      Sources/CryptoSwift/BlockMode/PCBC.swift
  27. 1 1
      Sources/CryptoSwift/BytesSequence.swift
  28. 3 3
      Sources/CryptoSwift/CRC.swift
  29. 9 9
      Sources/CryptoSwift/ChaCha20.swift
  30. 2 2
      Sources/CryptoSwift/Cipher.swift
  31. 3 3
      Sources/CryptoSwift/Cryptors.swift
  32. 1 1
      Sources/CryptoSwift/Foundation/CSArrayType+Foundation.swift
  33. 5 5
      Sources/CryptoSwift/Foundation/NSData+Extension.swift
  34. 1 1
      Sources/CryptoSwift/Foundation/String+FoundationExtension.swift
  35. 4 4
      Sources/CryptoSwift/Generics.swift
  36. 8 8
      Sources/CryptoSwift/HMAC.swift
  37. 1 1
      Sources/CryptoSwift/Hash.swift
  38. 1 1
      Sources/CryptoSwift/Info.plist
  39. 2 2
      Sources/CryptoSwift/IntExtension.swift
  40. 5 5
      Sources/CryptoSwift/MD5.swift
  41. 2 2
      Sources/CryptoSwift/NoPadding.swift
  42. 4 4
      Sources/CryptoSwift/PKCS5/PBKDF1.swift
  43. 11 10
      Sources/CryptoSwift/PKCS5/PBKDF2.swift
  44. 2 2
      Sources/CryptoSwift/PKCS7.swift
  45. 2 2
      Sources/CryptoSwift/Padding.swift
  46. 17 17
      Sources/CryptoSwift/Poly1305.swift
  47. 14 14
      Sources/CryptoSwift/Rabbit.swift
  48. 6 6
      Sources/CryptoSwift/SHA1.swift
  49. 9 9
      Sources/CryptoSwift/SHA2.swift
  50. 2 2
      Sources/CryptoSwift/SecureBytes.swift
  51. 2 2
      Sources/CryptoSwift/String+Extension.swift
  52. 2 2
      Sources/CryptoSwift/UInt32Extension.swift
  53. 2 2
      Sources/CryptoSwift/UInt64Extension.swift
  54. 7 7
      Sources/CryptoSwift/UpdatableCryptor.swift
  55. 2 2
      Sources/CryptoSwift/Utils.swift

+ 4 - 0
CHANGELOG

@@ -1,3 +1,7 @@
+0.5.1
+- Fixed PBKDF2 not taking key length parameter into account
+- Switch to Array<> in code
+
 0.5
 - Added PBKDF1 https://tools.ietf.org/html/rfc2898#section-5.1
 - Added PBKDF2 https://tools.ietf.org/html/rfc2898#section-5.2

+ 4 - 4
CryptoSwift.playground/Contents.swift

@@ -10,7 +10,7 @@ import XCPlayground
 //: # AES
 //: One-time shot
 do {
-    let aes = try AES(key: "passwordpassword", iv: "drowssapdrowssap")
+    let aes = try AES(key: "passwordpassword", iv: "drowssapdrowssap") // aes128
     let ciphertext = try aes.encrypt("Nullam quis risus eget urna mollis ornare vel eu leo.".utf8.map({$0}))
     print(ciphertext.toHexString())
 } catch {
@@ -19,7 +19,7 @@ do {
 
 //: Incremental encryption
 do {
-    let aes = try AES(key: "passwordpassword", iv: "drowssapdrowssap")
+    let aes = try AES(key: "passwordpassword", iv: "drowssapdrowssap") // aes128
     var encryptor = aes.makeEncryptor()
 
     var ciphertext = Array<UInt8>()
@@ -36,7 +36,7 @@ do {
 //: Encrypt stream incrementally
 do {
     // write until all is written
-    func writeToStream(stream: NSOutputStream, bytes: [UInt8]) {
+    func writeToStream(stream: NSOutputStream, bytes: Array<UInt8>) {
         var writtenCount = 0
         while stream.hasSpaceAvailable && writtenCount < bytes.count {
             let c = stream.write(bytes, maxLength: bytes.count)
@@ -58,7 +58,7 @@ do {
     inputStream.open()
     outputStream.open()
 
-    var buffer = [UInt8](count: 2, repeatedValue: 0)
+    var buffer = Array<UInt8>(count: 2, repeatedValue: 0)
 
     // encrypt input stream data and write encrypted result to output stream
     while (inputStream.hasBytesAvailable) {

+ 2 - 2
CryptoSwift.podspec

@@ -1,7 +1,7 @@
 Pod::Spec.new do |s|
   s.name         = "CryptoSwift"
-  s.version      = "0.5"
-  s.summary      = "Cryptography in Swift. SHA, MD5, CRC, PBKDF2, Poly1305, HMAC, ChaCha20, Rabbit, AES."
+  s.version      = "0.5.1"
+  s.summary      = "Cryptography in Swift. SHA, MD5, CRC, PBKDF, Poly1305, HMAC, ChaCha20, Rabbit, AES."
   s.description  = "Cryptography functions and helpers for Swift implemented in Swift. SHA, MD5, PBKDF1, PBKDF2, CRC, Poly1305, HMAC, ChaCha20, Rabbit, AES."
   s.homepage     = "https://github.com/krzyzanowskim/CryptoSwift"
   s.license      = {:type => "Attribution License", :file => "LICENSE"}

+ 6 - 0
CryptoSwift.xcodeproj/project.pbxproj

@@ -759,9 +759,11 @@
 					};
 					754BE45419693E190098E6F3 = {
 						CreatedOnToolsVersion = 6.0;
+						LastSwiftMigration = 0800;
 					};
 					754BE45F19693E190098E6F3 = {
 						CreatedOnToolsVersion = 6.0;
+						LastSwiftMigration = 0800;
 						TestTargetID = 754BE45419693E190098E6F3;
 					};
 				};
@@ -1288,6 +1290,7 @@
 				PRODUCT_NAME = CryptoSwift;
 				SKIP_INSTALL = YES;
 				SWIFT_OPTIMIZATION_LEVEL = "-Onone";
+				SWIFT_VERSION = 2.3;
 			};
 			name = Debug;
 		};
@@ -1313,6 +1316,7 @@
 				SKIP_INSTALL = YES;
 				SWIFT_DISABLE_SAFETY_CHECKS = YES;
 				SWIFT_OPTIMIZATION_LEVEL = "-O";
+				SWIFT_VERSION = 2.3;
 			};
 			name = Release;
 		};
@@ -1335,6 +1339,7 @@
 				PRODUCT_BUNDLE_IDENTIFIER = "com.hakore.${PRODUCT_NAME:rfc1034identifier}";
 				PRODUCT_NAME = "$(TARGET_NAME)";
 				SWIFT_OBJC_BRIDGING_HEADER = CryptoSwiftTests/Bridging.h;
+				SWIFT_VERSION = 2.3;
 			};
 			name = Debug;
 		};
@@ -1357,6 +1362,7 @@
 				SWIFT_DISABLE_SAFETY_CHECKS = YES;
 				SWIFT_OBJC_BRIDGING_HEADER = CryptoSwiftTests/Bridging.h;
 				SWIFT_OPTIMIZATION_LEVEL = "-O";
+				SWIFT_VERSION = 2.3;
 			};
 			name = Release;
 		};

+ 67 - 67
CryptoSwiftTests/AESTests.swift

@@ -10,14 +10,14 @@ import XCTest
 
 final class AESTests: XCTestCase {
     // 128 bit key
-    let aesKey:[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 testAES_encrypt2() {
-        let key:[UInt8]   = [0x36, 0x37, 0x39, 0x66, 0x62, 0x31, 0x64, 0x64, 0x66, 0x37, 0x64, 0x38, 0x31, 0x62, 0x65, 0x65];
-        let iv:[UInt8]    = [0x6b, 0x64, 0x66, 0x36, 0x37, 0x33, 0x39, 0x38, 0x44, 0x46, 0x37, 0x33, 0x38, 0x33, 0x66, 0x64]
-        let input:[UInt8] = [0x62, 0x72, 0x61, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00];
+        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 input:Array<UInt8> = [0x62, 0x72, 0x61, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00];
         
-        let expected:[UInt8] = [0xae,0x8c,0x59,0x95,0xb2,0x6f,0x8e,0x3d,0xb0,0x6f,0x0a,0xa5,0xfe,0xc4,0xf0,0xc2];
+        let expected:Array<UInt8> = [0xae,0x8c,0x59,0x95,0xb2,0x6f,0x8e,0x3d,0xb0,0x6f,0x0a,0xa5,0xfe,0xc4,0xf0,0xc2];
         
         let aes = try! AES(key: key, iv: iv, blockMode: .CBC, padding: NoPadding())
         let encrypted = try! aes.encrypt(input)
@@ -29,8 +29,8 @@ final class AESTests: XCTestCase {
     func testAES_encrypt3() {
         let key = "679fb1ddf7d81bee"
         let iv = "kdf67398DF7383fd"
-        let input:[UInt8] = [0x62, 0x72, 0x61, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00];
-        let expected:[UInt8] = [0xae,0x8c,0x59,0x95,0xb2,0x6f,0x8e,0x3d,0xb0,0x6f,0x0a,0xa5,0xfe,0xc4,0xf0,0xc2];
+        let input:Array<UInt8> = [0x62, 0x72, 0x61, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00];
+        let expected:Array<UInt8> = [0xae,0x8c,0x59,0x95,0xb2,0x6f,0x8e,0x3d,0xb0,0x6f,0x0a,0xa5,0xfe,0xc4,0xf0,0xc2];
         
         let aes = try! AES(key: key, iv: iv, blockMode: .CBC, padding: NoPadding())
         let encrypted = try! aes.encrypt(input)
@@ -40,8 +40,8 @@ final class AESTests: XCTestCase {
     }
     
     func testAES_encrypt() {
-        let input:[UInt8] = [0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff];
-        let expected:[UInt8] = [0x69, 0xc4, 0xe0, 0xd8, 0x6a, 0x7b, 0x4, 0x30, 0xd8, 0xcd, 0xb7, 0x80, 0x70, 0xb4, 0xc5, 0x5a];
+        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)
@@ -51,10 +51,10 @@ final class AESTests: XCTestCase {
     }
 
     func testAES_encrypt_cbc_no_padding() {
-        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] = [0x76,0x49,0xab,0xac,0x81,0x19,0xb2,0x46,0xce,0xe9,0x8e,0x9b,0x12,0xe9,0x19,0x7d];
+        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 plaintext:Array<UInt8> = [0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a]
+        let expected:Array<UInt8> = [0x76,0x49,0xab,0xac,0x81,0x19,0xb2,0x46,0xce,0xe9,0x8e,0x9b,0x12,0xe9,0x19,0x7d];
 
         let aes = try! AES(key: key, iv:iv, blockMode: .CBC, padding: NoPadding())
         let encrypted = try! aes.encrypt(plaintext)
@@ -64,10 +64,10 @@ final class AESTests: XCTestCase {
     }
 
     func testAES_encrypt_cbc_with_padding() {
-        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] = [0x76,0x49,0xab,0xac,0x81,0x19,0xb2,0x46,0xce,0xe9,0x8e,0x9b,0x12,0xe9,0x19,0x7d,0x89,0x64,0xe0,0xb1,0x49,0xc1,0x0b,0x7b,0x68,0x2e,0x6e,0x39,0xaa,0xeb,0x73,0x1c]
+        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 plaintext:Array<UInt8> = [0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a]
+        let expected:Array<UInt8> = [0x76,0x49,0xab,0xac,0x81,0x19,0xb2,0x46,0xce,0xe9,0x8e,0x9b,0x12,0xe9,0x19,0x7d,0x89,0x64,0xe0,0xb1,0x49,0xc1,0x0b,0x7b,0x68,0x2e,0x6e,0x39,0xaa,0xeb,0x73,0x1c]
         
         let aes = try! AES(key: key, iv:iv, blockMode: .CBC, padding: PKCS7())
         let encrypted = try! aes.encrypt(plaintext)
@@ -77,13 +77,13 @@ final class AESTests: XCTestCase {
     }
 
     func testAES_encrypt_cbc_with_padding_partial() {
-        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,0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a]
+        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 plaintext:Array<UInt8> = [0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a,0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a]
 
         let aes = try! AES(key: key, iv:iv, blockMode: .CBC, padding: PKCS7())
 
-        var ciphertext = [UInt8]()
+        var ciphertext = Array<UInt8>()
         var encryptor = aes.makeEncryptor()
         ciphertext += try! encryptor.update(withBytes: Array(plaintext[0..<8]))
         ciphertext += try! encryptor.update(withBytes: Array(plaintext[8..<16]))
@@ -107,12 +107,12 @@ final class AESTests: XCTestCase {
     }
 
     func testAES_decrypt_cbc_with_padding_partial() {
-        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 ciphertext:[UInt8] = [118, 73, 171, 172, 129, 25, 178, 70, 206, 233, 142, 155, 18, 233, 25, 125, 76, 187, 200, 88, 117, 107, 53, 129, 37, 82, 158, 150, 152, 163, 143, 68, 169, 105, 137, 234, 93, 98, 239, 215, 41, 45, 51, 254, 138, 92, 251, 17]
+        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 ciphertext:Array<UInt8> = [118, 73, 171, 172, 129, 25, 178, 70, 206, 233, 142, 155, 18, 233, 25, 125, 76, 187, 200, 88, 117, 107, 53, 129, 37, 82, 158, 150, 152, 163, 143, 68, 169, 105, 137, 234, 93, 98, 239, 215, 41, 45, 51, 254, 138, 92, 251, 17]
 
         let aes = try! AES(key: key, iv:iv, blockMode: .CBC, padding: PKCS7())
-        var plaintext = [UInt8]()
+        var plaintext = Array<UInt8>()
         var decryptor = aes.makeDecryptor()
         plaintext += try! decryptor.update(withBytes: Array(ciphertext[0..<8]))
         plaintext += try! decryptor.update(withBytes: Array(ciphertext[8..<16]))
@@ -122,10 +122,10 @@ final class AESTests: XCTestCase {
     }
 
     func testAES_encrypt_cfb() {
-        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 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 plaintext:Array<UInt8> = [0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a]
+        let expected:Array<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: .CFB, padding: NoPadding())
         let encrypted = try! aes.encrypt(plaintext)
@@ -136,19 +136,19 @@ final class AESTests: XCTestCase {
 
     // 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]
-        let iv: [UInt8] = [69, 122, 99, 87, 83, 112, 110, 65, 54, 109, 107, 89, 73, 122, 74, 49]
-        let plaintext: [UInt8] = [123, 10, 32, 32, 34, 67, 111, 110, 102, 105, 114, 109, 34, 32, 58, 32, 34, 116, 101, 115, 116, 105, 110, 103, 34, 44, 10, 32, 32, 34, 70, 105, 114, 115, 116, 78, 97, 109, 101, 34, 32, 58, 32, 34, 84, 101, 115, 116, 34, 44, 10, 32, 32, 34, 69, 109, 97, 105, 108, 34, 32, 58, 32, 34, 116, 101, 115, 116, 64, 116, 101, 115, 116, 46, 99, 111, 109, 34, 44, 10, 32, 32, 34, 76, 97, 115, 116, 78, 97, 109, 101, 34, 32, 58, 32, 34, 84, 101, 115, 116, 101, 114, 34, 44, 10, 32, 32, 34, 80, 97, 115, 115, 119, 111, 114, 100, 34, 32, 58, 32, 34, 116, 101, 115, 116, 105, 110, 103, 34, 44, 10, 32, 32, 34, 85, 115, 101, 114, 110, 97, 109, 101, 34, 32, 58, 32, 34, 84, 101, 115, 116, 34, 10, 125]
-        let encrypted: [UInt8] = try! AES(key: key, iv: iv, blockMode: .CFB).encrypt(plaintext)
-        let decrypted: [UInt8] = try! AES(key: key, iv: iv, blockMode: .CFB).decrypt(encrypted)
+        let key: Array<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]
+        let iv: Array<UInt8> = [69, 122, 99, 87, 83, 112, 110, 65, 54, 109, 107, 89, 73, 122, 74, 49]
+        let plaintext: Array<UInt8> = [123, 10, 32, 32, 34, 67, 111, 110, 102, 105, 114, 109, 34, 32, 58, 32, 34, 116, 101, 115, 116, 105, 110, 103, 34, 44, 10, 32, 32, 34, 70, 105, 114, 115, 116, 78, 97, 109, 101, 34, 32, 58, 32, 34, 84, 101, 115, 116, 34, 44, 10, 32, 32, 34, 69, 109, 97, 105, 108, 34, 32, 58, 32, 34, 116, 101, 115, 116, 64, 116, 101, 115, 116, 46, 99, 111, 109, 34, 44, 10, 32, 32, 34, 76, 97, 115, 116, 78, 97, 109, 101, 34, 32, 58, 32, 34, 84, 101, 115, 116, 101, 114, 34, 44, 10, 32, 32, 34, 80, 97, 115, 115, 119, 111, 114, 100, 34, 32, 58, 32, 34, 116, 101, 115, 116, 105, 110, 103, 34, 44, 10, 32, 32, 34, 85, 115, 101, 114, 110, 97, 109, 101, 34, 32, 58, 32, 34, 84, 101, 115, 116, 34, 10, 125]
+        let encrypted: Array<UInt8> = try! AES(key: key, iv: iv, blockMode: .CFB).encrypt(plaintext)
+        let decrypted: Array<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 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 plaintext:Array<UInt8> = [0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a]
+        let expected:Array<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, padding: NoPadding())
         let encrypted = try! aes.encrypt(plaintext)
@@ -158,10 +158,10 @@ final class AESTests: XCTestCase {
     }
 
     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 key: Array<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: Array<UInt8> = [0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F]
+        let plaintext: Array<UInt8> = [0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a]
+        let expected:Array<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, padding: NoPadding())
         let encrypted = try! aes.encrypt(plaintext)
@@ -171,10 +171,10 @@ final class AESTests: XCTestCase {
     }
 
     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 key: Array<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: Array<UInt8> = [0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F]
+        let plaintext: Array<UInt8> = [0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a]
+        let expected:Array<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, padding: NoPadding())
         let encrypted = try! aes.encrypt(plaintext)
@@ -185,10 +185,10 @@ final class AESTests: XCTestCase {
     }
 
     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]
-        let plaintext:[UInt8] = [0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a]
-        let expected:[UInt8] = [0x87,0x4d,0x61,0x91,0xb6,0x20,0xe3,0x26,0x1b,0xef,0x68,0x64,0x99,0x0d,0xb6,0xce]
+        let key:Array<UInt8> = [0x2b,0x7e,0x15,0x16,0x28,0xae,0xd2,0xa6,0xab,0xf7,0x15,0x88,0x09,0xcf,0x4f,0x3c];
+        let iv:Array<UInt8> = [0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff]
+        let plaintext:Array<UInt8> = [0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a]
+        let expected:Array<UInt8> = [0x87,0x4d,0x61,0x91,0xb6,0x20,0xe3,0x26,0x1b,0xef,0x68,0x64,0x99,0x0d,0xb6,0xce]
         
         let aes = try! AES(key: key, iv:iv, blockMode: .CTR, padding: NoPadding())
         let encrypted = try! aes.encrypt(plaintext)
@@ -198,10 +198,10 @@ final class AESTests: XCTestCase {
     }
 
     func testAES_encrypt_ctr_irregular_length() {
-        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]
-        let plaintext:[UInt8] = [0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a,0x01]
-        let expected:[UInt8] = [0x87,0x4d,0x61,0x91,0xb6,0x20,0xe3,0x26,0x1b,0xef,0x68,0x64,0x99,0x0d,0xb6,0xce,0x37]
+        let key:Array<UInt8> = [0x2b,0x7e,0x15,0x16,0x28,0xae,0xd2,0xa6,0xab,0xf7,0x15,0x88,0x09,0xcf,0x4f,0x3c];
+        let iv:Array<UInt8> = [0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff]
+        let plaintext:Array<UInt8> = [0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a,0x01]
+        let expected:Array<UInt8> = [0x87,0x4d,0x61,0x91,0xb6,0x20,0xe3,0x26,0x1b,0xef,0x68,0x64,0x99,0x0d,0xb6,0xce,0x37]
 
         let aes = try! AES(key: key, iv:iv, blockMode: .CTR, padding: NoPadding())
         let encrypted = try! aes.encrypt(plaintext)
@@ -211,9 +211,9 @@ final class AESTests: XCTestCase {
     }
 
     func testAES_encrypt_performance() {
-        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 message = [UInt8](count: 1024 * 1024, repeatedValue: 7)
+        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 message = Array<UInt8>(count: 1024 * 1024, repeatedValue: 7)
         let aes = try! AES(key: key, iv: iv, blockMode: .CBC, padding: PKCS7())
         measureMetrics([XCTPerformanceMetric_WallClockTime], automaticallyStartMeasuring: true, forBlock: { () -> Void in
             try! aes.encrypt(message)
@@ -221,9 +221,9 @@ final class AESTests: XCTestCase {
     }
 
     func testAES_decrypt_performance() {
-        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 message = [UInt8](count: 1024 * 1024, repeatedValue: 7)
+        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 message = Array<UInt8>(count: 1024 * 1024, repeatedValue: 7)
         let aes = try! AES(key: key, iv: iv, blockMode: .CBC, padding: PKCS7())
         measureMetrics([XCTPerformanceMetric_WallClockTime], automaticallyStartMeasuring: true, forBlock: { () -> Void in
             try! aes.decrypt(message)
@@ -231,9 +231,9 @@ final class AESTests: XCTestCase {
     }
 
     func testAESPerformanceCommonCrypto() {
-        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 message = [UInt8](count: 1024 * 1024, repeatedValue: 7)
+        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 message = Array<UInt8>(count: 1024 * 1024, repeatedValue: 7)
         
         measureMetrics([XCTPerformanceMetric_WallClockTime], automaticallyStartMeasuring: false, forBlock: { () -> Void in
             let keyData     = NSData.withBytes(key)
@@ -270,10 +270,10 @@ final class AESTests: XCTestCase {
     }
 
     func testAESWithWrongKey() {
-        let key:[UInt8] = [0x2b,0x7e,0x15,0x16,0x28,0xae,0xd2,0xa6,0xab,0xf7,0x15,0x88,0x09,0xcf,0x4f,0x3c];
-        let key2:[UInt8] = [0x22,0x7e,0x15,0x16,0x28,0xae,0xd2,0xa6,0xab,0xf7,0x15,0x88,0x09,0xcf,0x4f,0x33];
-        let iv:[UInt8] = [0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F]
-        let plaintext:[UInt8] = [49, 46, 50, 50, 50, 51, 51, 51, 51]
+        let key:Array<UInt8> = [0x2b,0x7e,0x15,0x16,0x28,0xae,0xd2,0xa6,0xab,0xf7,0x15,0x88,0x09,0xcf,0x4f,0x3c];
+        let key2:Array<UInt8> = [0x22,0x7e,0x15,0x16,0x28,0xae,0xd2,0xa6,0xab,0xf7,0x15,0x88,0x09,0xcf,0x4f,0x33];
+        let iv:Array<UInt8> = [0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F]
+        let plaintext:Array<UInt8> = [49, 46, 50, 50, 50, 51, 51, 51, 51]
 
         let aes = try! AES(key: key, iv:iv, blockMode: .CBC, padding: PKCS7())
         let aes2 = try! AES(key: key2, iv:iv, blockMode: .CBC, padding: PKCS7())

+ 10 - 10
CryptoSwiftTests/ChaCha20Tests.swift

@@ -19,7 +19,7 @@ final class ChaCha20Tests: XCTestCase {
     }
 
     func testChaCha20() {
-        let keys:[[UInt8]] = [
+        let keys:[Array<UInt8>] = [
             [0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00],
             [0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01],
             [0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00],
@@ -27,7 +27,7 @@ final class ChaCha20Tests: XCTestCase {
             [0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F,0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1A,0x1B,0x1C,0x1D,0x1E,0x1F]
         ]
         
-        let ivs:[[UInt8]] = [
+        let ivs:[Array<UInt8>] = [
             [0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00],
             [0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00],
             [0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01],
@@ -45,7 +45,7 @@ final class ChaCha20Tests: XCTestCase {
 
         for idx in 0..<keys.count {            
             let expectedHex = expectedHexes[idx]
-            let message = [UInt8](count: (expectedHex.characters.count / 2), repeatedValue: 0)
+            let message = Array<UInt8>(count: (expectedHex.characters.count / 2), repeatedValue: 0)
             
             do {
                 let encrypted = try ChaCha20(key: keys[idx], iv: ivs[idx])!.encrypt(message)
@@ -68,10 +68,10 @@ final class ChaCha20Tests: XCTestCase {
     }
 
     func testVector1Py() {
-        let key:[UInt8] = [0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00]
-        let iv:[UInt8]  = [0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00]
-        let expected:[UInt8] = [0x76,0xB8,0xE0,0xAD,0xA0,0xF1,0x3D,0x90,0x40,0x5D,0x6A,0xE5,0x53,0x86,0xBD,0x28,0xBD,0xD2,0x19,0xB8,0xA0,0x8D,0xED,0x1A,0xA8,0x36,0xEF,0xCC,0x8B,0x77,0x0D,0xC7,0xDA,0x41,0x59,0x7C,0x51,0x57,0x48,0x8D,0x77,0x24,0xE0,0x3F,0xB8,0xD8,0x4A,0x37,0x6A,0x43,0xB8,0xF4,0x15,0x18,0xA1,0x1C,0xC3,0x87,0xB6,0x69,0xB2,0xEE,0x65,0x86]
-        let message = [UInt8](count: expected.count, repeatedValue: 0)
+        let key:Array<UInt8> = [0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00]
+        let iv:Array<UInt8>  = [0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00]
+        let expected:Array<UInt8> = [0x76,0xB8,0xE0,0xAD,0xA0,0xF1,0x3D,0x90,0x40,0x5D,0x6A,0xE5,0x53,0x86,0xBD,0x28,0xBD,0xD2,0x19,0xB8,0xA0,0x8D,0xED,0x1A,0xA8,0x36,0xEF,0xCC,0x8B,0x77,0x0D,0xC7,0xDA,0x41,0x59,0x7C,0x51,0x57,0x48,0x8D,0x77,0x24,0xE0,0x3F,0xB8,0xD8,0x4A,0x37,0x6A,0x43,0xB8,0xF4,0x15,0x18,0xA1,0x1C,0xC3,0x87,0xB6,0x69,0xB2,0xEE,0x65,0x86]
+        let message = Array<UInt8>(count: expected.count, repeatedValue: 0)
 
         print(message.count)
 
@@ -80,9 +80,9 @@ final class ChaCha20Tests: XCTestCase {
     }
 
     func testChaCha20Performance() {
-        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 message = [UInt8](count: (1024 * 1024) * 1, repeatedValue: 7)
+        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 message = Array<UInt8>(count: (1024 * 1024) * 1, repeatedValue: 7)
         measureMetrics([XCTPerformanceMetric_WallClockTime], automaticallyStartMeasuring: true, forBlock: { () -> Void in
             let encrypted = try! ChaCha20(key: key, iv: iv)?.encrypt(message)
             self.stopMeasuring()

+ 1 - 1
CryptoSwiftTests/ExtensionsTest.swift

@@ -20,7 +20,7 @@ final class ExtensionsTest: XCTestCase {
 
     func testArrayChunksPerformance() {
         measureMetrics([XCTPerformanceMetric_WallClockTime], automaticallyStartMeasuring: false, forBlock: { () -> Void in
-            let message = [UInt8](count: 1024 * 1024, repeatedValue: 7)
+            let message = Array<UInt8>(count: 1024 * 1024, repeatedValue: 7)
             self.startMeasuring()
             message.chunks(AES.blockSize)
             self.stopMeasuring()

+ 15 - 15
CryptoSwiftTests/HMACTests.swift

@@ -20,45 +20,45 @@ final class HMACTests: XCTestCase {
     
     
     func testMD5() {
-        let key:[UInt8] = []
-        let msg:[UInt8] = []
-        let expectedMac:[UInt8] = [0x74,0xe6,0xf7,0x29,0x8a,0x9c,0x2d,0x16,0x89,0x35,0xf5,0x8c,0x00,0x1b,0xad,0x88]
+        let key:Array<UInt8> = []
+        let msg:Array<UInt8> = []
+        let expectedMac:Array<UInt8> = [0x74,0xe6,0xf7,0x29,0x8a,0x9c,0x2d,0x16,0x89,0x35,0xf5,0x8c,0x00,0x1b,0xad,0x88]
         
         let hmac = try! Authenticator.HMAC(key: key, variant: .md5).authenticate(msg)
         XCTAssertEqual(hmac, expectedMac, "Invalid authentication result")
     }
     
     func testSHA1() {
-        let key:[UInt8] = []
-        let msg:[UInt8] = []
-        let expectedMac:[UInt8] = [0xfb,0xdb,0x1d,0x1b,0x18,0xaa,0x6c,0x08,0x32,0x4b,0x7d,0x64,0xb7,0x1f,0xb7,0x63,0x70,0x69,0x0e,0x1d]
+        let key:Array<UInt8> = []
+        let msg:Array<UInt8> = []
+        let expectedMac:Array<UInt8> = [0xfb,0xdb,0x1d,0x1b,0x18,0xaa,0x6c,0x08,0x32,0x4b,0x7d,0x64,0xb7,0x1f,0xb7,0x63,0x70,0x69,0x0e,0x1d]
         
         let hmac = try! Authenticator.HMAC(key: key, variant: .sha1).authenticate(msg)
         XCTAssertEqual(hmac, expectedMac, "Invalid authentication result")
     }
 
     func testSHA256() {
-        let key:[UInt8] = []
-        let msg:[UInt8] = []
-        let expectedMac:[UInt8] = [0xb6,0x13,0x67,0x9a,0x08,0x14,0xd9,0xec,0x77,0x2f,0x95,0xd7,0x78,0xc3,0x5f,0xc5,0xff,0x16,0x97,0xc4,0x93,0x71,0x56,0x53,0xc6,0xc7,0x12,0x14,0x42,0x92,0xc5,0xad]
+        let key:Array<UInt8> = []
+        let msg:Array<UInt8> = []
+        let expectedMac:Array<UInt8> = [0xb6,0x13,0x67,0x9a,0x08,0x14,0xd9,0xec,0x77,0x2f,0x95,0xd7,0x78,0xc3,0x5f,0xc5,0xff,0x16,0x97,0xc4,0x93,0x71,0x56,0x53,0xc6,0xc7,0x12,0x14,0x42,0x92,0xc5,0xad]
         
         let hmac = try! Authenticator.HMAC(key: key, variant: .sha256).authenticate(msg)
         XCTAssertEqual(hmac, expectedMac, "Invalid authentication result")
     }
 
     func testSHA384() {
-        let key:[UInt8] = []
-        let msg:[UInt8] = []
-        let expectedMac:[UInt8] = [0x6c, 0x1f, 0x2e, 0xe9, 0x38, 0xfa, 0xd2, 0xe2, 0x4b, 0xd9, 0x12, 0x98, 0x47, 0x43, 0x82, 0xca, 0x21, 0x8c, 0x75, 0xdb, 0x3d, 0x83, 0xe1, 0x14, 0xb3, 0xd4, 0x36, 0x77, 0x76, 0xd1, 0x4d, 0x35, 0x51, 0x28, 0x9e, 0x75, 0xe8, 0x20, 0x9c, 0xd4, 0xb7, 0x92, 0x30, 0x28, 0x40, 0x23, 0x4a, 0xdc]
+        let key:Array<UInt8> = []
+        let msg:Array<UInt8> = []
+        let expectedMac:Array<UInt8> = [0x6c, 0x1f, 0x2e, 0xe9, 0x38, 0xfa, 0xd2, 0xe2, 0x4b, 0xd9, 0x12, 0x98, 0x47, 0x43, 0x82, 0xca, 0x21, 0x8c, 0x75, 0xdb, 0x3d, 0x83, 0xe1, 0x14, 0xb3, 0xd4, 0x36, 0x77, 0x76, 0xd1, 0x4d, 0x35, 0x51, 0x28, 0x9e, 0x75, 0xe8, 0x20, 0x9c, 0xd4, 0xb7, 0x92, 0x30, 0x28, 0x40, 0x23, 0x4a, 0xdc]
 
         let hmac = try! Authenticator.HMAC(key: key, variant: .sha384).authenticate(msg)
         XCTAssertEqual(hmac, expectedMac, "Invalid authentication result")
     }
 
     func testSHA512() {
-        let key:[UInt8] = []
-        let msg:[UInt8] = []
-        let expectedMac:[UInt8] = [0xb9, 0x36, 0xce, 0xe8, 0x6c, 0x9f, 0x87, 0xaa, 0x5d, 0x3c, 0x6f, 0x2e, 0x84, 0xcb, 0x5a, 0x42, 0x39, 0xa5, 0xfe, 0x50, 0x48, 0x0a, 0x6e, 0xc6, 0x6b, 0x70, 0xab, 0x5b, 0x1f, 0x4a, 0xc6, 0x73, 0x0c, 0x6c, 0x51, 0x54, 0x21, 0xb3, 0x27, 0xec, 0x1d, 0x69, 0x40, 0x2e, 0x53, 0xdf, 0xb4, 0x9a, 0xd7, 0x38, 0x1e, 0xb0, 0x67, 0xb3, 0x38, 0xfd, 0x7b, 0x0c, 0xb2, 0x22, 0x47, 0x22, 0x5d, 0x47]
+        let key:Array<UInt8> = []
+        let msg:Array<UInt8> = []
+        let expectedMac:Array<UInt8> = [0xb9, 0x36, 0xce, 0xe8, 0x6c, 0x9f, 0x87, 0xaa, 0x5d, 0x3c, 0x6f, 0x2e, 0x84, 0xcb, 0x5a, 0x42, 0x39, 0xa5, 0xfe, 0x50, 0x48, 0x0a, 0x6e, 0xc6, 0x6b, 0x70, 0xab, 0x5b, 0x1f, 0x4a, 0xc6, 0x73, 0x0c, 0x6c, 0x51, 0x54, 0x21, 0xb3, 0x27, 0xec, 0x1d, 0x69, 0x40, 0x2e, 0x53, 0xdf, 0xb4, 0x9a, 0xd7, 0x38, 0x1e, 0xb0, 0x67, 0xb3, 0x38, 0xfd, 0x7b, 0x0c, 0xb2, 0x22, 0x47, 0x22, 0x5d, 0x47]
 
         let hmac = try! Authenticator.HMAC(key: key, variant: .sha512).authenticate(msg)
         XCTAssertEqual(hmac, expectedMac, "Invalid authentication result")

+ 10 - 10
CryptoSwiftTests/HashTests.swift

@@ -20,7 +20,7 @@ final class CryptoSwiftTests: XCTestCase {
     }
     
     func testMD5_data() {
-        let data = [0x31, 0x32, 0x33] as [UInt8] // "1", "2", "3"
+        let data = [0x31, 0x32, 0x33] as Array<UInt8> // "1", "2", "3"
         XCTAssertEqual(Hash.md5(data).calculate(), [0x20,0x2c,0xb9,0x62,0xac,0x59,0x07,0x5b,0x96,0x4b,0x07,0x15,0x2d,0x23,0x4b,0x70], "MD5 calculation failed");
     }
 
@@ -70,7 +70,7 @@ final class CryptoSwiftTests: XCTestCase {
     }
     
     func testSHA1() {
-        let data:NSData = NSData(bytes: [0x31, 0x32, 0x33] as [UInt8], length: 3)
+        let data:NSData = NSData(bytes: [0x31, 0x32, 0x33] as Array<UInt8>, length: 3)
         if let hash = data.sha1() {
             XCTAssertEqual(hash.toHexString(), "40bd001563085fc35165329ea1ff5c5ecbdbbeef", "SHA1 calculation failed");
         }
@@ -81,14 +81,14 @@ final class CryptoSwiftTests: XCTestCase {
     }
     
     func testSHA224() {
-        let data:NSData = NSData(bytes: [0x31, 0x32, 0x33] as [UInt8], length: 3)
+        let data:NSData = NSData(bytes: [0x31, 0x32, 0x33] as Array<UInt8>, length: 3)
         if let hash = data.sha224() {
             XCTAssertEqual(hash.toHexString(), "78d8045d684abd2eece923758f3cd781489df3a48e1278982466017f", "SHA224 calculation failed");
         }
     }
 
     func testSHA256() {
-        let data:NSData = NSData(bytes: [0x31, 0x32, 0x33] as [UInt8], length: 3)
+        let data:NSData = NSData(bytes: [0x31, 0x32, 0x33] as Array<UInt8>, length: 3)
         if let hash = data.sha256() {
             XCTAssertEqual(hash.toHexString(), "a665a45920422f9d417e4867efdc4fb8a04a1f3fff1fa07e998e86f7f7a27ae3", "SHA256 calculation failed");
         }
@@ -98,7 +98,7 @@ final class CryptoSwiftTests: XCTestCase {
     }
 
     func testSHA384() {
-        let data:NSData = NSData(bytes: [49, 50, 51] as [UInt8], length: 3)
+        let data:NSData = NSData(bytes: [49, 50, 51] as Array<UInt8>, length: 3)
         if let hash = data.sha384() {
             XCTAssertEqual(hash.toHexString(), "9a0a82f0c0cf31470d7affede3406cc9aa8410671520b727044eda15b4c25532a9b5cd8aaf9cec4919d76255b6bfb00f", "SHA384 calculation failed");
         }
@@ -108,7 +108,7 @@ final class CryptoSwiftTests: XCTestCase {
     }
 
     func testSHA512() {
-        let data:NSData = NSData(bytes: [49, 50, 51] as [UInt8], length: 3)
+        let data:NSData = NSData(bytes: [49, 50, 51] as Array<UInt8>, length: 3)
         if let hash = data.sha512() {
             XCTAssertEqual(hash.toHexString(), "3c9909afec25354d551dae21590bb26e38d53f2173b8d3dc3eee4c047e7ab1c1eb8b85103e3be7ba613b31bb5c9c36214dc9f14a42fd7a2fdb84856bca5c44c2", "SHA512 calculation failed");
         }
@@ -118,7 +118,7 @@ final class CryptoSwiftTests: XCTestCase {
     }
     
     func testCRC32() {
-        let data:NSData = NSData(bytes: [49, 50, 51] as [UInt8], length: 3)
+        let data:NSData = NSData(bytes: [49, 50, 51] as Array<UInt8>, length: 3)
         if let crc = data.crc32(nil) {
             XCTAssertEqual(crc.toHexString(), "884863d2", "CRC32 calculation failed");
         }
@@ -127,7 +127,7 @@ final class CryptoSwiftTests: XCTestCase {
     }
     
     func testCRC32NotReflected() {
-        let bytes : [UInt8] = [0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39]
+        let bytes : Array<UInt8> = [0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39]
         let data:NSData = NSData(bytes: bytes, length: bytes.count)
         if let crc = data.crc32(nil, reflect: false) {
             XCTAssertEqual(crc.toHexString(), "fc891918", "CRC32 (with reflection) calculation failed");
@@ -137,12 +137,12 @@ final class CryptoSwiftTests: XCTestCase {
     }
     
     func testCRC16() {
-        let result = CRC().crc16([49,50,51,52,53,54,55,56,57] as [UInt8])
+        let result = CRC().crc16([49,50,51,52,53,54,55,56,57] as Array<UInt8>)
         XCTAssert(result == 0xBB3D, "CRC16 failed")
     }
     
     func testChecksum() {
-        let data:NSData = NSData(bytes: [49, 50, 51] as [UInt8], length: 3)
+        let data:NSData = NSData(bytes: [49, 50, 51] as Array<UInt8>, length: 3)
         XCTAssert(data.checksum() == 0x96, "Invalid checksum")
     }
 

+ 1 - 1
CryptoSwiftTests/Helpers.swift

@@ -6,7 +6,7 @@
 //  Copyright (c) 2014 Marcin Krzyzanowski. All rights reserved.
 //
 
-func compareMatrix(a:[[UInt8]], b:[[UInt8]]) -> Bool {
+func compareMatrix(a:[Array<UInt8>], b:[Array<UInt8>]) -> Bool {
     for (i,arr) in a.enumerate() {
         for (j,val) in arr.enumerate() {
             if (val != b[i][j]) {

+ 12 - 5
CryptoSwiftTests/PBKDF.swift

@@ -20,17 +20,24 @@ class PBKDF: XCTestCase {
     }
 
     func test_pbkdf1() {
-        let password: [UInt8] = [0x70,0x61,0x73,0x73,0x77,0x6F,0x72,0x64]
-        let salt: [UInt8] = [0x78,0x57,0x8E,0x5A,0x5D,0x63,0xCB,0x06]
+        let password: Array<UInt8> = [0x70,0x61,0x73,0x73,0x77,0x6F,0x72,0x64]
+        let salt: Array<UInt8> = [0x78,0x57,0x8E,0x5A,0x5D,0x63,0xCB,0x06]
         let value = try! PKCS5.PBKDF1(password: password, salt: salt, iterations: 1000, keyLength: 16, variant: .sha1).calculate()
         XCTAssertEqual(value.toHexString(), "dc19847e05c64d2faf10ebfb4a3d2a20")
     }
 
     func test_pbkdf2() {
-        let password: [UInt8] = "s33krit".utf8.map {$0}
-        let salt: [UInt8] = "nacl".utf8.map {$0}
+        let password: Array<UInt8> = "s33krit".utf8.map {$0}
+        let salt: Array<UInt8> = "nacl".utf8.map {$0}
         let value = try! PKCS5.PBKDF2(password: password, salt: salt, iterations: 2, keyLength: 123, variant: .sha1).calculate()
         XCTAssert(value.toHexString() == "a53cf3df485e5cd91c17c4978048e3ca86e03cced5f748fb55eff9c1edfce7f9f490c0beee768b85c1ba14ec5750cf059fea52565ffd9e4f9dba01c5c953955e7f1012b6a9eb40629ce767982e598df9081048e22781b35187c16d61ac43f69b88630a9e80233b4c58bdc74ea5c06b5bb1b2c2a86e3ddc2775b852c4508ac85a6a47c0e23a3d8dc6e4dca583", "PBKDF2 fail")
     }
 
-}
+    func test_pbkdf2_length() {
+        let password: Array<UInt8> = "s33krit".utf8.map {$0}
+        let salt: Array<UInt8> = "nacl".utf8.map {$0}
+        let value = try! PKCS5.PBKDF2(password: password, salt: salt, iterations: 2, keyLength: 8, variant: .sha1).calculate()
+        XCTAssert(value.toHexString() == "a53cf3df485e5cd9", "PBKDF2 fail")
+    }
+
+}

+ 6 - 6
CryptoSwiftTests/PaddingTests.swift

@@ -10,8 +10,8 @@ import XCTest
 
 final class PaddingTests: XCTestCase {
     func testPKCS7_0() {
-        let input:[UInt8]    = [1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6]
-        let expected:[UInt8] = [1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16]
+        let input:Array<UInt8>    = [1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6]
+        let expected:Array<UInt8> = [1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16]
         let padded = PKCS7().add(input, blockSize: 16)
         XCTAssertEqual(padded, expected, "PKCS7 failed")
         let clean = PKCS7().remove(padded, blockSize: nil)
@@ -19,8 +19,8 @@ final class PaddingTests: XCTestCase {
     }
     
     func testPKCS7_1() {
-        let input:[UInt8]    = [1,2,3,4,5,6,7,8,9,0,1,2,3,4,5]
-        let expected:[UInt8] = [1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,1]
+        let input:Array<UInt8>    = [1,2,3,4,5,6,7,8,9,0,1,2,3,4,5]
+        let expected:Array<UInt8> = [1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,1]
         let padded = PKCS7().add(input, blockSize: 16)
         XCTAssertEqual(padded, expected, "PKCS7 failed")
         let clean = PKCS7().remove(padded, blockSize: nil)
@@ -28,8 +28,8 @@ final class PaddingTests: XCTestCase {
     }
     
     func testPKCS7_2() {
-        let input:[UInt8]    = [1,2,3,4,5,6,7,8,9,0,1,2,3,4]
-        let expected:[UInt8] = [1,2,3,4,5,6,7,8,9,0,1,2,3,4,2,2]
+        let input:Array<UInt8>    = [1,2,3,4,5,6,7,8,9,0,1,2,3,4]
+        let expected:Array<UInt8> = [1,2,3,4,5,6,7,8,9,0,1,2,3,4,2,2]
         let padded = PKCS7().add(input, blockSize: 16)
         XCTAssertEqual(padded, expected, "PKCS7 failed")
         let clean = PKCS7().remove(padded, blockSize: nil)

+ 3 - 3
CryptoSwiftTests/Poly1305Tests.swift

@@ -20,9 +20,9 @@ final class Poly1305Tests: XCTestCase {
     
     
     func testPoly1305() {
-        let key:[UInt8] = [0xdd,0xde,0xdf,0xe0,0xe1,0xe2,0xe3,0xe4,0xe5,0xe6,0xe7,0xe8,0xe9,0xea,0xeb,0xec,0xed,0xee,0xef,0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,0xf8,0xf9,0xfa,0xfb,0xfc]
-        let msg:[UInt8] = [0x79,0x7a,0x7b,0x7c,0x7d,0x7e,0x7f,0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f,0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9a,0x9b,0x9c,0x9d,0x9e,0x9f,0xa0,0xa1,0xa2,0xa3,0xa4,0xa5,0xa6,0xa7,0xa8,0xa9,0xaa,0xab,0xac,0xad,0xae,0xaf,0xb0,0xb1,0xb2,0xb3,0xb4,0xb5,0xb6,0xb7,0xb8,0xb9,0xba,0xbb,0xbc,0xbd,0xbe,0xbf,0xc0,0xc1]
-        let expectedMac:[UInt8] = [0xdd,0xb9,0xda,0x7d,0xdd,0x5e,0x52,0x79,0x27,0x30,0xed,0x5c,0xda,0x5f,0x90,0xa4]
+        let key:Array<UInt8> = [0xdd,0xde,0xdf,0xe0,0xe1,0xe2,0xe3,0xe4,0xe5,0xe6,0xe7,0xe8,0xe9,0xea,0xeb,0xec,0xed,0xee,0xef,0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,0xf8,0xf9,0xfa,0xfb,0xfc]
+        let msg:Array<UInt8> = [0x79,0x7a,0x7b,0x7c,0x7d,0x7e,0x7f,0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f,0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9a,0x9b,0x9c,0x9d,0x9e,0x9f,0xa0,0xa1,0xa2,0xa3,0xa4,0xa5,0xa6,0xa7,0xa8,0xa9,0xaa,0xab,0xac,0xad,0xae,0xaf,0xb0,0xb1,0xb2,0xb3,0xb4,0xb5,0xb6,0xb7,0xb8,0xb9,0xba,0xbb,0xbc,0xbd,0xbe,0xbf,0xc0,0xc1]
+        let expectedMac:Array<UInt8> = [0xdd,0xb9,0xda,0x7d,0xdd,0x5e,0x52,0x79,0x27,0x30,0xed,0x5c,0xda,0x5f,0x90,0xa4]
         
         let mac = try! Authenticator.Poly1305(key: key).authenticate(msg)
         XCTAssertEqual(mac, expectedMac, "Invalid authentication result")

+ 14 - 14
CryptoSwiftTests/RabbitTests.swift

@@ -20,26 +20,26 @@ class RabbitTests: XCTestCase {
     }
     
     func testInitialization() {
-        var key = [UInt8](count: Rabbit.keySize - 1, repeatedValue: 0)
-        var iv: [UInt8]?
+        var key = Array<UInt8>(count: Rabbit.keySize - 1, repeatedValue: 0)
+        var iv: Array<UInt8>?
         XCTAssertNil(Rabbit(key: key, iv: iv))
         
-        key = [UInt8](count: Rabbit.keySize + 1, repeatedValue: 0)
+        key = Array<UInt8>(count: Rabbit.keySize + 1, repeatedValue: 0)
         XCTAssertNil(Rabbit(key: key, iv: iv))
         
-        key = [UInt8](count: Rabbit.keySize, repeatedValue: 0)
+        key = Array<UInt8>(count: Rabbit.keySize, repeatedValue: 0)
         XCTAssertNotNil(Rabbit(key: key, iv: iv))
         
-        iv = [UInt8](count: Rabbit.ivSize - 1, repeatedValue: 0)
+        iv = Array<UInt8>(count: Rabbit.ivSize - 1, repeatedValue: 0)
         XCTAssertNil(Rabbit(key: key, iv: iv))
         
-        iv = [UInt8](count: Rabbit.ivSize, repeatedValue: 0)
+        iv = Array<UInt8>(count: Rabbit.ivSize, repeatedValue: 0)
         XCTAssertNotNil(Rabbit(key: key, iv: iv))
     }
     
     func testRabbitWithoutIV() {
         // Examples from Appendix A: Test Vectors in http://tools.ietf.org/rfc/rfc4503.txt
-        let cases: [([UInt8], [UInt8])] = [
+        let cases: [(Array<UInt8>, Array<UInt8>)] = [
             // First case
             (
                 [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00],
@@ -69,7 +69,7 @@ class RabbitTests: XCTestCase {
             ),
         ]
         
-        let plainText = [UInt8](count: 48, repeatedValue: 0)
+        let plainText = Array<UInt8>(count: 48, repeatedValue: 0)
         for (key, expectedCipher) in cases {
             let rabbit = Rabbit(key: key)!
             let cipherText = rabbit.encrypt(plainText)
@@ -80,8 +80,8 @@ class RabbitTests: XCTestCase {
     
     func testRabbitWithIV() {
         // Examples from Appendix A: Test Vectors in http://tools.ietf.org/rfc/rfc4503.txt
-        let key = [UInt8](count: Rabbit.keySize, repeatedValue: 0)
-        let cases: [([UInt8], [UInt8])] = [
+        let key = Array<UInt8>(count: Rabbit.keySize, repeatedValue: 0)
+        let cases: [(Array<UInt8>, Array<UInt8>)] = [
             (
                 [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00],
                 [
@@ -108,7 +108,7 @@ class RabbitTests: XCTestCase {
             ),
         ]
         
-        let plainText = [UInt8](count: 48, repeatedValue: 0)
+        let plainText = Array<UInt8>(count: 48, repeatedValue: 0)
         for (iv, expectedCipher) in cases {
             let rabbit = Rabbit(key: key, iv: iv)!
             let cipherText = rabbit.encrypt(plainText)
@@ -118,9 +118,9 @@ class RabbitTests: XCTestCase {
     }
     
     func testRabbitPerformance() {
-        let key: [UInt8] = [UInt8](count: Rabbit.keySize, repeatedValue: 0)
-        let iv: [UInt8] = [UInt8](count: Rabbit.ivSize, repeatedValue: 0)
-        let message = [UInt8](count: (1024 * 1024) * 1, repeatedValue: 7)
+        let key: Array<UInt8> = Array<UInt8>(count: Rabbit.keySize, repeatedValue: 0)
+        let iv: Array<UInt8> = Array<UInt8>(count: Rabbit.ivSize, repeatedValue: 0)
+        let message = Array<UInt8>(count: (1024 * 1024) * 1, repeatedValue: 7)
         measureMetrics([XCTPerformanceMetric_WallClockTime], automaticallyStartMeasuring: true, forBlock: { () -> Void in
             let encrypted = Rabbit(key: key, iv: iv)?.encrypt(message)
             self.stopMeasuring()

+ 14 - 14
README.md

@@ -165,7 +165,7 @@ For you convenience CryptoSwift provide two function to easily convert array of
 
 ```swift
 let data: NSData = NSData(bytes: [0x01, 0x02, 0x03])
-let bytes:[UInt8] = data.arrayOfBytes()
+let bytes:Array<UInt8> = data.arrayOfBytes()
 ```
 
 Make bytes out of `String`:
@@ -178,7 +178,7 @@ let bytes = "string".utf8.map({$0})
 Hashing a data or array of bytes (aka `Array<UInt8>`)
 ```swift
 /* Hash enum usage */
-let input:[UInt8] = [49, 50, 51]
+let input:Array<UInt8> = [49, 50, 51]
 
 let output = input.md5()
 // alternatively: let output = CryptoSwift.Hash.md5(input).calculate()
@@ -212,15 +212,15 @@ let hash = "123".md5()
 
 ```swift
 // Calculate Message Authentication Code (MAC) for message
-let mac: [UInt8] = try! Authenticator.Poly1305(key: key).authenticate(message)
-let hmac: [UInt8] = try! Authenticator.HMAC(key: key, variant: .sha256).authenticate(message)
+let mac: Array<UInt8> = try! Authenticator.Poly1305(key: key).authenticate(message)
+let hmac: Array<UInt8> = try! Authenticator.HMAC(key: key, variant: .sha256).authenticate(message)
 ```
 
 #####Password-Based Key Derivation Function
 
 ```swift
-let password: [UInt8] = "s33krit".utf8.map {$0}
-let salt: [UInt8] = "nacl".utf8.map {$0}
+let password: Array<UInt8> = "s33krit".utf8.map {$0}
+let salt: Array<UInt8> = "nacl".utf8.map {$0}
 
 let value = try! PKCS5.PBKDF1(password: password, salt: salt, iterations: 4096, variant: .sha1).calculate()
 
@@ -241,8 +241,8 @@ let paddedData = PKCS7().add(arr, blockSize: AES.blockSize)
 #####ChaCha20
 
 ```swift
-let encrypted: [UInt8] = ChaCha20(key: key, iv: iv).encrypt(message)
-let decrypted: [UInt8] = ChaCha20(key: key, iv: iv).decrypt(encrypted)
+let encrypted: Array<UInt8> = ChaCha20(key: key, iv: iv).encrypt(message)
+let decrypted: Array<UInt8> = ChaCha20(key: key, iv: iv).decrypt(encrypted)
 ```
 
 #####Rabbit
@@ -261,7 +261,7 @@ Notice regarding padding: *Manual padding of data is optional and CryptoSwift is
 let input = NSData()
 let encrypted = try! input.encrypt(AES(key: "secret0key000000", iv:"0123456789012345"))
 
-let input: [UInt8] = [0,1,2,3,4,5,6,7,8,9]
+let input: Array<UInt8> = [0,1,2,3,4,5,6,7,8,9]
 input.encrypt(AES(key: "secret0key000000", iv:"0123456789012345", blockMode: .CBC))
 ```
 
@@ -288,10 +288,10 @@ Check this helper functions to work with **Base64** encoded data directly:
 
 ######AES Advanced usage
 ```swift
-let input: [UInt8] = [0,1,2,3,4,5,6,7,8,9]
+let input: Array<UInt8> = [0,1,2,3,4,5,6,7,8,9]
 
-let key: [UInt8] = [0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00]
-let iv: [UInt8] = AES.randomIV(AES.blockSize)
+let key: Array<UInt8> = [0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00]
+let iv: Array<UInt8> = AES.randomIV(AES.blockSize)
 
 do {
     let encrypted = try AES(key: key, iv: iv, blockMode: .CBC, padding: PKCS7()).encrypt(input)
@@ -304,8 +304,8 @@ do {
 AES without data padding
 
 ```swift
-let input: [UInt8] = [0,1,2,3,4,5,6,7,8,9]
-let encrypted: [UInt8] = try! AES(key: "secret0key000000", iv:"0123456789012345", blockMode: .CBC, padding: NoPadding()).encrypt(input)
+let input: Array<UInt8> = [0,1,2,3,4,5,6,7,8,9]
+let encrypted: Array<UInt8> = try! AES(key: "secret0key000000", iv:"0123456789012345", blockMode: .CBC, padding: NoPadding()).encrypt(input)
 ```
 
 Using convenience extensions

文件差异内容过多而无法显示
+ 7 - 7
Sources/CryptoSwift/AES.swift


+ 1 - 1
Sources/CryptoSwift/Array+Extension.swift

@@ -10,7 +10,7 @@ extension Array {
 
     /** split in chunks with given chunk size */
     func chunks(chunksize:Int) -> [Array<Element>] {
-        var words = [[Element]]()
+        var words = Array<Array<Element>>()
         words.reserveCapacity(self.count / chunksize)        
         for idx in chunksize.stride(through: self.count, by: chunksize) {
             let word = Array(self[idx - chunksize..<idx]) // this is slow for large table

+ 3 - 3
Sources/CryptoSwift/Authenticator.swift

@@ -20,15 +20,15 @@ public enum Authenticator {
     
     - parameter key: 256-bit key
     */
-    case Poly1305(key: [UInt8])
-    case HMAC(key: [UInt8], variant:CryptoSwift.HMAC.Variant)
+    case Poly1305(key: Array<UInt8>)
+    case HMAC(key: Array<UInt8>, variant:CryptoSwift.HMAC.Variant)
     
     /**
     Generates an authenticator for message using a one-time key and returns the 16-byte result
     
     - returns: 16-byte message authentication code
     */
-    public func authenticate(message: [UInt8]) throws -> [UInt8] {
+    public func authenticate(message: Array<UInt8>) throws -> Array<UInt8> {
         switch (self) {
         case .Poly1305(let key):
             guard let auth = CryptoSwift.Poly1305(key: key)?.authenticate(message) else {

+ 1 - 1
Sources/CryptoSwift/BlockMode/BlockMode.swift

@@ -6,7 +6,7 @@
 //  Copyright © 2016 Marcin Krzyzanowski. All rights reserved.
 //
 
-typealias CipherOperationOnBlock = (block: [UInt8]) -> [UInt8]?
+typealias CipherOperationOnBlock = (block: Array<UInt8>) -> Array<UInt8>?
 
 public enum BlockMode {
     case ECB, CBC, PCBC, CFB, OFB, CTR

+ 2 - 2
Sources/CryptoSwift/BlockMode/BlockModeWorker.swift

@@ -8,6 +8,6 @@
 
 protocol BlockModeWorker {
     var cipherOperation: CipherOperationOnBlock { get }
-    mutating func encrypt(plaintext: Array<UInt8>) -> [UInt8]
-    mutating func decrypt(ciphertext: Array<UInt8>) -> [UInt8]
+    mutating func encrypt(plaintext: Array<UInt8>) -> Array<UInt8>
+    mutating func decrypt(ciphertext: Array<UInt8>) -> Array<UInt8>
 }

+ 2 - 2
Sources/CryptoSwift/BlockMode/CBC.swift

@@ -20,7 +20,7 @@ struct CBCModeWorker: BlockModeWorker {
         self.cipherOperation = cipherOperation
     }
 
-    mutating func encrypt(plaintext: Array<UInt8>) -> [UInt8] {
+    mutating func encrypt(plaintext: Array<UInt8>) -> Array<UInt8> {
         guard let ciphertext = cipherOperation(block: xor(prev ?? iv, plaintext)) else {
             return plaintext
         }
@@ -28,7 +28,7 @@ struct CBCModeWorker: BlockModeWorker {
         return ciphertext ?? []
     }
 
-    mutating func decrypt(ciphertext: Array<UInt8>) -> [UInt8] {
+    mutating func decrypt(ciphertext: Array<UInt8>) -> Array<UInt8> {
         guard let plaintext = cipherOperation(block: ciphertext) else {
             return ciphertext
         }

+ 2 - 2
Sources/CryptoSwift/BlockMode/CFB.swift

@@ -20,7 +20,7 @@ struct CFBModeWorker: BlockModeWorker {
         self.cipherOperation = cipherOperation
     }
 
-    mutating func encrypt(plaintext: Array<UInt8>) -> [UInt8] {
+    mutating func encrypt(plaintext: Array<UInt8>) -> Array<UInt8> {
         guard let ciphertext = cipherOperation(block: prev ?? iv) else {
             return plaintext
         }
@@ -28,7 +28,7 @@ struct CFBModeWorker: BlockModeWorker {
         return prev ?? []
     }
 
-    mutating func decrypt(ciphertext: Array<UInt8>) -> [UInt8] {
+    mutating func decrypt(ciphertext: Array<UInt8>) -> Array<UInt8> {
         guard let plaintext = cipherOperation(block: prev ?? iv) else {
             return ciphertext
         }

+ 3 - 3
Sources/CryptoSwift/BlockMode/CTR.swift

@@ -20,7 +20,7 @@ struct CTRModeWorker: BlockModeWorker {
         self.cipherOperation = cipherOperation
     }
 
-    mutating func encrypt(plaintext: Array<UInt8>) -> [UInt8] {
+    mutating func encrypt(plaintext: Array<UInt8>) -> Array<UInt8> {
         let nonce = buildNonce(iv, counter: UInt64(counter))
         counter = counter + 1
 
@@ -31,7 +31,7 @@ struct CTRModeWorker: BlockModeWorker {
         return xor(plaintext, ciphertext)
     }
 
-    mutating func decrypt(ciphertext: Array<UInt8>) -> [UInt8] {
+    mutating func decrypt(ciphertext: Array<UInt8>) -> Array<UInt8> {
         let nonce = buildNonce(iv, counter: UInt64(counter))
         counter = counter + 1
 
@@ -42,7 +42,7 @@ struct CTRModeWorker: BlockModeWorker {
     }
 }
 
-private func buildNonce(iv: [UInt8], counter: UInt64) -> [UInt8] {
+private func buildNonce(iv: Array<UInt8>, counter: UInt64) -> Array<UInt8> {
     let noncePartLen = AES.blockSize / 2
     let noncePrefix = Array(iv[0..<noncePartLen])
     let nonceSuffix = Array(iv[noncePartLen..<iv.count])

+ 2 - 2
Sources/CryptoSwift/BlockMode/ECB.swift

@@ -16,14 +16,14 @@ struct ECBModeWorker: BlockModeWorker {
         self.cipherOperation = cipherOperation
     }
 
-    mutating func encrypt(plaintext: Array<UInt8>) -> [UInt8] {
+    mutating func encrypt(plaintext: Array<UInt8>) -> Array<UInt8> {
         guard let ciphertext = cipherOperation(block: plaintext) else {
             return plaintext
         }
         return ciphertext
     }
 
-    mutating func decrypt(ciphertext: Array<UInt8>) -> [UInt8] {
+    mutating func decrypt(ciphertext: Array<UInt8>) -> Array<UInt8> {
         return encrypt(ciphertext)
     }
 }

+ 2 - 2
Sources/CryptoSwift/BlockMode/OFB.swift

@@ -20,7 +20,7 @@ struct OFBModeWorker: BlockModeWorker {
         self.cipherOperation = cipherOperation
     }
 
-    mutating func encrypt(plaintext: Array<UInt8>) -> [UInt8] {
+    mutating func encrypt(plaintext: Array<UInt8>) -> Array<UInt8> {
         guard let ciphertext = cipherOperation(block: prev ?? iv) else {
             return plaintext
         }
@@ -28,7 +28,7 @@ struct OFBModeWorker: BlockModeWorker {
         return xor(plaintext, ciphertext)
     }
 
-    mutating func decrypt(ciphertext: Array<UInt8>) -> [UInt8] {
+    mutating func decrypt(ciphertext: Array<UInt8>) -> Array<UInt8> {
         guard let decrypted = cipherOperation(block: prev ?? iv) else {
             return ciphertext
         }

+ 2 - 2
Sources/CryptoSwift/BlockMode/PCBC.swift

@@ -20,7 +20,7 @@ struct PCBCModeWorker: BlockModeWorker {
         self.cipherOperation = cipherOperation
     }
 
-    mutating func encrypt(plaintext: Array<UInt8>) -> [UInt8] {
+    mutating func encrypt(plaintext: Array<UInt8>) -> Array<UInt8> {
         guard let ciphertext = cipherOperation(block: xor(prev ?? iv, plaintext)) else {
             return plaintext
         }
@@ -28,7 +28,7 @@ struct PCBCModeWorker: BlockModeWorker {
         return ciphertext ?? []
     }
 
-    mutating func decrypt(ciphertext: Array<UInt8>) -> [UInt8] {
+    mutating func decrypt(ciphertext: Array<UInt8>) -> Array<UInt8> {
         guard let plaintext = cipherOperation(block: ciphertext) else {
             return ciphertext
         }

+ 1 - 1
Sources/CryptoSwift/BytesSequence.swift

@@ -8,7 +8,7 @@
 
 struct BytesSequence: SequenceType {
     let chunkSize: Int
-    let data: [UInt8]
+    let data: Array<UInt8>
     
     func generate() -> AnyGenerator<ArraySlice<UInt8>> {
         

+ 3 - 3
Sources/CryptoSwift/CRC.swift

@@ -8,7 +8,7 @@
 
 final class CRC {
     
-    private static let table32:[UInt32] = [0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3,
+    private static let table32:Array<UInt32> = [0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3,
         0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91,
         0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,
         0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5,
@@ -74,7 +74,7 @@ final class CRC {
         0x4400, 0x84C1, 0x8581, 0x4540, 0x8701, 0x47C0, 0x4680, 0x8641,
         0x8201, 0x42C0, 0x4380, 0x8341, 0x4100, 0x81C1, 0x8081, 0x4040]
     
-    func crc32(message:[UInt8], seed: UInt32? = nil, reflect : Bool = true) -> UInt32 {
+    func crc32(message:Array<UInt8>, seed: UInt32? = nil, reflect : Bool = true) -> UInt32 {
         var crc:UInt32 = seed != nil ? seed! : 0xffffffff
         for chunk in BytesSequence(chunkSize: 256, data: message) {
             for b in chunk {
@@ -85,7 +85,7 @@ final class CRC {
         return (reflect ? crc : reverseUInt32(crc)) ^ 0xffffffff
     }
     
-    func crc16(message:[UInt8], seed: UInt16? = nil) -> UInt16 {
+    func crc16(message:Array<UInt8>, seed: UInt16? = nil) -> UInt16 {
         var crc:UInt16 = seed != nil ? seed! : 0x0000
         for chunk in BytesSequence(chunkSize: 256, data: message) {
             for b in chunk {

+ 9 - 9
Sources/CryptoSwift/ChaCha20.swift

@@ -17,7 +17,7 @@ final public class ChaCha20: BlockCipher {
     private var context:Context?
     
     final private class Context {
-        var input:[UInt32] = [UInt32](count: 16, repeatedValue: 0)
+        var input:Array<UInt32> = Array<UInt32>(count: 16, repeatedValue: 0)
         
         deinit {
             for i in 0..<input.count {
@@ -26,7 +26,7 @@ final public class ChaCha20: BlockCipher {
         }
     }
     
-    public init?(key:[UInt8], iv:[UInt8]) {
+    public init?(key:Array<UInt8>, iv:Array<UInt8>) {
         if let c = contextSetup(iv: iv, key: key) {
             context = c
         } else {
@@ -34,7 +34,7 @@ final public class ChaCha20: BlockCipher {
         }
     }
     
-    private final func wordToByte(input:[UInt32] /* 64 */) -> [UInt8]? /* 16 */ {
+    private final func wordToByte(input:Array<UInt32> /* 64 */) -> Array<UInt8>? /* 16 */ {
         if (input.count != stateSize) {
             return nil;
         }
@@ -52,7 +52,7 @@ final public class ChaCha20: BlockCipher {
             quarterround(&x[3], &x[4], &x[9],  &x[14])
         }
 
-        var output = [UInt8]()
+        var output = Array<UInt8>()
         output.reserveCapacity(16)
 
         for i in 0..<16 {
@@ -63,7 +63,7 @@ final public class ChaCha20: BlockCipher {
         return output;
     }
         
-    private func contextSetup(iv  iv:[UInt8], key:[UInt8]) -> Context? {
+    private func contextSetup(iv  iv:Array<UInt8>, key:Array<UInt8>) -> Context? {
         let ctx = Context()
         let kbits = key.count * 8
         
@@ -112,13 +112,13 @@ final public class ChaCha20: BlockCipher {
         return ctx
     }
     
-    private final func encryptBytes(message:[UInt8]) throws -> [UInt8] {
+    private final func encryptBytes(message:Array<UInt8>) throws -> Array<UInt8> {
         
         guard let ctx = context else {
             throw Error.MissingContext
         }
         
-        var c:[UInt8] = [UInt8](count: message.count, repeatedValue: 0)
+        var c:Array<UInt8> = Array<UInt8>(count: message.count, repeatedValue: 0)
         
         var cPos:Int = 0
         var mPos:Int = 0
@@ -164,7 +164,7 @@ final public class ChaCha20: BlockCipher {
 
 // MARK: Cipher
 extension ChaCha20: Cipher {
-    public func encrypt(bytes:[UInt8]) throws -> [UInt8] {
+    public func encrypt(bytes:Array<UInt8>) throws -> Array<UInt8> {
         guard context != nil else {
             throw Error.MissingContext
         }
@@ -172,7 +172,7 @@ extension ChaCha20: Cipher {
         return try encryptBytes(bytes)
     }
 
-    public func decrypt(bytes:[UInt8]) throws -> [UInt8] {
+    public func decrypt(bytes:Array<UInt8>) throws -> Array<UInt8> {
         return try encrypt(bytes)
     }
 }

+ 2 - 2
Sources/CryptoSwift/Cipher.swift

@@ -16,11 +16,11 @@ public protocol Cipher {
     ///
     /// - parameter bytes: Plaintext data
     /// - returns: Encrypted data
-    func encrypt(bytes: [UInt8]) throws -> [UInt8]
+    func encrypt(bytes: Array<UInt8>) throws -> Array<UInt8>
 
     /// Decrypt given bytes at once
     ///
     /// - parameter bytes: Ciphertext data
     /// - returns: Plaintext data
-    func decrypt(bytes: [UInt8]) throws -> [UInt8]
+    func decrypt(bytes: Array<UInt8>) throws -> Array<UInt8>
 }

+ 3 - 3
Sources/CryptoSwift/Cryptors.swift

@@ -23,12 +23,12 @@ public protocol Cryptors {
     func makeDecryptor() -> DecryptorType
 
     /// Generate array of random bytes. Helper function.
-    static func randomIV(blockSize:Int) -> [UInt8]
+    static func randomIV(blockSize:Int) -> Array<UInt8>
 }
 
 extension Cryptors {
-    static public func randomIV(blockSize:Int) -> [UInt8] {
-        var randomIV:[UInt8] = [UInt8]();
+    static public func randomIV(blockSize:Int) -> Array<UInt8> {
+        var randomIV:Array<UInt8> = Array<UInt8>();
         for _ in 0..<blockSize {
             randomIV.append(UInt8(truncatingBitPattern: cs_arc4random_uniform(256)));
         }

+ 1 - 1
Sources/CryptoSwift/Foundation/CSArrayType+Foundation.swift

@@ -10,7 +10,7 @@ import Foundation
 
 public extension CSArrayType where Generator.Element == UInt8 {
     public func toBase64() -> String? {
-        guard let bytesArray = self as? [UInt8] else {
+        guard let bytesArray = self as? Array<UInt8> else {
             return nil
         }
 

+ 5 - 5
Sources/CryptoSwift/Foundation/NSData+Extension.swift

@@ -11,7 +11,7 @@ import Foundation
 extension NSMutableData {
     
     /** Convenient way to append bytes */
-    internal func appendBytes(arrayOfBytes: [UInt8]) {
+    internal func appendBytes(arrayOfBytes: Array<UInt8>) {
         self.appendBytes(arrayOfBytes, length: arrayOfBytes.count)
     }
     
@@ -92,18 +92,18 @@ extension NSData {
         return self.arrayOfBytes().toHexString()
     }
     
-    public func arrayOfBytes() -> [UInt8] {
+    public func arrayOfBytes() -> Array<UInt8> {
         let count = self.length / sizeof(UInt8)
-        var bytesArray = [UInt8](count: count, repeatedValue: 0)
+        var bytesArray = Array<UInt8>(count: count, repeatedValue: 0)
         self.getBytes(&bytesArray, length:count * sizeof(UInt8))
         return bytesArray
     }
 
-    public convenience init(bytes: [UInt8]) {
+    public convenience init(bytes: Array<UInt8>) {
         self.init(data: NSData.withBytes(bytes))
     }
     
-    class public func withBytes(bytes: [UInt8]) -> NSData {
+    class public func withBytes(bytes: Array<UInt8>) -> NSData {
         return NSData(bytes: bytes, length: bytes.count)
     }
 }

+ 1 - 1
Sources/CryptoSwift/Foundation/String+FoundationExtension.swift

@@ -25,7 +25,7 @@ extension String {
         throw CipherError.Decrypt
     }
 
-    public func decryptBase64(cipher: Cipher) throws -> [UInt8] {
+    public func decryptBase64(cipher: Cipher) throws -> Array<UInt8> {
         guard let decodedData = NSData(base64EncodedString: self, options: []) else {
             throw CipherError.Decrypt
         }

+ 4 - 4
Sources/CryptoSwift/Generics.swift

@@ -34,12 +34,12 @@ func integerFromBitsArray<T: UnsignedIntegerType>(bits: [Bit]) -> T
 
 /// Initialize integer from array of bytes.
 /// This method may be slow
-func integerWithBytes<T: IntegerType where T:ByteConvertible, T: BitshiftOperationsType>(bytes: [UInt8]) -> T {
+func integerWithBytes<T: IntegerType where T:ByteConvertible, T: BitshiftOperationsType>(bytes: Array<UInt8>) -> T {
     var bytes = bytes.reverse() as Array<UInt8> //FIXME: check it this is equivalent of Array(...)
     if bytes.count < sizeof(T) {
         let paddingCount = sizeof(T) - bytes.count
         if (paddingCount > 0) {
-            bytes += [UInt8](count: paddingCount, repeatedValue: 0)
+            bytes += Array<UInt8>(count: paddingCount, repeatedValue: 0)
         }
     }
     
@@ -56,14 +56,14 @@ func integerWithBytes<T: IntegerType where T:ByteConvertible, T: BitshiftOperati
 
 /// Array of bytes, little-endian representation. Don't use if not necessary.
 /// I found this method slow
-func arrayOfBytes<T>(value:T, length:Int? = nil) -> [UInt8] {
+func arrayOfBytes<T>(value:T, length:Int? = nil) -> Array<UInt8> {
     let totalBytes = length ?? sizeof(T)
     
     let valuePointer = UnsafeMutablePointer<T>.alloc(1)
     valuePointer.memory = value
     
     let bytesPointer = UnsafeMutablePointer<UInt8>(valuePointer)
-    var bytes = [UInt8](count: totalBytes, repeatedValue: 0)
+    var bytes = Array<UInt8>(count: totalBytes, repeatedValue: 0)
     for j in 0..<min(sizeof(T),totalBytes) {
         bytes[totalBytes - 1 - j] = (bytesPointer + j).memory
     }

+ 8 - 8
Sources/CryptoSwift/HMAC.swift

@@ -26,7 +26,7 @@ final public class HMAC {
             }
         }
         
-        func calculateHash(bytes bytes:[UInt8]) -> [UInt8]? {
+        func calculateHash(bytes bytes:Array<UInt8>) -> Array<UInt8>? {
             switch (self) {
             case .sha1:
                 return Hash.sha1(bytes).calculate()
@@ -51,10 +51,10 @@ final public class HMAC {
         }
     }
     
-    var key:[UInt8]
+    var key:Array<UInt8>
     let variant:Variant
 
-    public init? (key: [UInt8], variant:HMAC.Variant = .md5) {
+    public init? (key: Array<UInt8>, variant:HMAC.Variant = .md5) {
         self.variant = variant
         self.key = key
 
@@ -65,21 +65,21 @@ final public class HMAC {
         }
         
         if (key.count < variant.blockSize()) { // keys shorter than blocksize are zero-padded
-            self.key = key + [UInt8](count: variant.blockSize() - key.count, repeatedValue: 0)
+            self.key = key + Array<UInt8>(count: variant.blockSize() - key.count, repeatedValue: 0)
         }
     }
 
-    public func authenticate(message:[UInt8]) -> [UInt8]? {
-        var opad = [UInt8](count: variant.blockSize(), repeatedValue: 0x5c)
+    public func authenticate(message:Array<UInt8>) -> Array<UInt8>? {
+        var opad = Array<UInt8>(count: variant.blockSize(), repeatedValue: 0x5c)
         for (idx, _) in key.enumerate() {
             opad[idx] = key[idx] ^ opad[idx]
         }
-        var ipad = [UInt8](count: variant.blockSize(), repeatedValue: 0x36)
+        var ipad = Array<UInt8>(count: variant.blockSize(), repeatedValue: 0x36)
         for (idx, _) in key.enumerate() {
             ipad[idx] = key[idx] ^ ipad[idx]
         }
 
-        var finalHash:[UInt8]? = nil;
+        var finalHash:Array<UInt8>? = nil;
         if let ipadAndMessageHash = variant.calculateHash(bytes: ipad + message) {
             finalHash = variant.calculateHash(bytes: opad + ipadAndMessageHash);
         }

+ 1 - 1
Sources/CryptoSwift/Hash.swift

@@ -13,7 +13,7 @@ public enum Hash {
     case crc32(Array<UInt8>, seed: UInt32?, reflect: Bool)
     case crc16(Array<UInt8>, seed: UInt16?)
     
-    public func calculate() -> [UInt8] {
+    public func calculate() -> Array<UInt8> {
         switch self {
         case md5(let bytes):
             return MD5(bytes).calculate()

+ 1 - 1
Sources/CryptoSwift/Info.plist

@@ -15,7 +15,7 @@
 	<key>CFBundlePackageType</key>
 	<string>FMWK</string>
 	<key>CFBundleShortVersionString</key>
-	<string>0.5</string>
+	<string>0.5.1</string>
 	<key>CFBundleSignature</key>
 	<string>????</string>
 	<key>CFBundleVersion</key>

+ 2 - 2
Sources/CryptoSwift/IntExtension.swift

@@ -31,7 +31,7 @@ extension Int {
 /* array of bytes */
 extension Int {
     /** Array of bytes with optional padding (little-endian) */
-    public func bytes(totalBytes: Int = sizeof(Int)) -> [UInt8] {
+    public func bytes(totalBytes: Int = sizeof(Int)) -> Array<UInt8> {
         return arrayOfBytes(self, length: totalBytes)
     }
 
@@ -40,7 +40,7 @@ extension Int {
     }
 
     /** Int with array bytes (little-endian) */
-    public static func withBytes(bytes: [UInt8]) -> Int {
+    public static func withBytes(bytes: Array<UInt8>) -> Int {
         return integerWithBytes(bytes)
     }
 }

+ 5 - 5
Sources/CryptoSwift/MD5.swift

@@ -15,13 +15,13 @@ final class MD5 : HashProtocol  {
     }
 
     /** specifies the per-round shift amounts */
-    private let s: [UInt32] = [7, 12, 17, 22,  7, 12, 17, 22,  7, 12, 17, 22,  7, 12, 17, 22,
+    private let s: Array<UInt32> = [7, 12, 17, 22,  7, 12, 17, 22,  7, 12, 17, 22,  7, 12, 17, 22,
                        5,  9, 14, 20,  5,  9, 14, 20,  5,  9, 14, 20,  5,  9, 14, 20,
                        4, 11, 16, 23,  4, 11, 16, 23,  4, 11, 16, 23,  4, 11, 16, 23,
                        6, 10, 15, 21,  6, 10, 15, 21,  6, 10, 15, 21,  6, 10, 15, 21]
     
     /** binary integer part of the sines of integers (Radians) */
-    private let k: [UInt32] = [0xd76aa478,0xe8c7b756,0x242070db,0xc1bdceee,
+    private let k: Array<UInt32> = [0xd76aa478,0xe8c7b756,0x242070db,0xc1bdceee,
                        0xf57c0faf,0x4787c62a,0xa8304613,0xfd469501,
                        0x698098d8,0x8b44f7af,0xffff5bb1,0x895cd7be,
                        0x6b901122,0xfd987193,0xa679438e,0x49b40821,
@@ -38,9 +38,9 @@ final class MD5 : HashProtocol  {
                        0x6fa87e4f,0xfe2ce6e0,0xa3014314,0x4e0811a1,
                        0xf7537e82,0xbd3af235,0x2ad7d2bb,0xeb86d391]
     
-    private let h:[UInt32] = [0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476]
+    private let h:Array<UInt32> = [0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476]
     
-    func calculate() -> [UInt8] {
+    func calculate() -> Array<UInt8> {
         var tmpMessage = prepare(64)
         tmpMessage.reserveCapacity(tmpMessage.count + 4)
 
@@ -105,7 +105,7 @@ final class MD5 : HashProtocol  {
             hh[3] = hh[3] &+ D
         }
 
-        var result = [UInt8]()
+        var result = Array<UInt8>()
         result.reserveCapacity(hh.count / 4)
         
         hh.forEach {

+ 2 - 2
Sources/CryptoSwift/NoPadding.swift

@@ -11,11 +11,11 @@ public struct NoPadding: Padding {
     
     }
     
-    public func add(data: [UInt8], blockSize:Int) -> [UInt8] {
+    public func add(data: Array<UInt8>, blockSize:Int) -> Array<UInt8> {
         return data;
     }
 
-    public func remove(data: [UInt8], blockSize:Int?) -> [UInt8] {
+    public func remove(data: Array<UInt8>, blockSize:Int?) -> Array<UInt8> {
         return data;
     }
 }

+ 4 - 4
Sources/CryptoSwift/PKCS5/PBKDF1.swift

@@ -32,7 +32,7 @@ public extension PKCS5 {
                 }
             }
 
-            private func calculateHash(bytes bytes:[UInt8]) -> [UInt8]? {
+            private func calculateHash(bytes bytes:Array<UInt8>) -> Array<UInt8>? {
                 switch (self) {
                 case .sha1:
                     return Hash.sha1(bytes).calculate()
@@ -45,14 +45,14 @@ public extension PKCS5 {
         private let iterations: Int // c
         private let variant: Variant
         private let keyLength: Int
-        private let t1: [UInt8]
+        private let t1: Array<UInt8>
 
         /// - parameters:
         ///   - salt: salt, an eight-bytes
         ///   - variant: hash variant
         ///   - iterations: iteration count, a positive integer
         ///   - keyLength: intended length of derived key
-        public init(password: [UInt8], salt: [UInt8], variant: Variant = .sha1, iterations: Int = 4096 /* c */, keyLength: Int? = nil /* dkLen */) throws {
+        public init(password: Array<UInt8>, salt: Array<UInt8>, variant: Variant = .sha1, iterations: Int = 4096 /* c */, keyLength: Int? = nil /* dkLen */) throws {
             precondition(iterations > 0)
             precondition(salt.count == 8)
 
@@ -71,7 +71,7 @@ public extension PKCS5 {
         }
 
         /// Apply the underlying hash function Hash for c iterations
-        public func calculate() -> [UInt8] {
+        public func calculate() -> Array<UInt8> {
             var t = t1
             for _ in 2...self.iterations {
                 t = self.variant.calculateHash(bytes: t)!

+ 11 - 10
Sources/CryptoSwift/PKCS5/PBKDF2.swift

@@ -24,9 +24,10 @@ public extension PKCS5 {
             case DerivedKeyTooLong
         }
 
-        private let salt: [UInt8]   // S
+        private let salt: Array<UInt8>   // S
         private let iterations: Int // c
         private let numBlocks: UInt // l
+        private let dkLen: Int;
         private let prf: HMAC
 
         /// - parameters:
@@ -34,14 +35,15 @@ public extension PKCS5 {
         ///   - variant: hash variant
         ///   - iterations: iteration count, a positive integer
         ///   - keyLength: intended length of derived key
-        public init(password: [UInt8], salt: [UInt8], iterations: Int = 4096 /* c */, keyLength: Int? = nil /* dkLen */, variant: HMAC.Variant = .sha256) throws {
+        public init(password: Array<UInt8>, salt: Array<UInt8>, iterations: Int = 4096 /* c */, keyLength: Int? = nil /* dkLen */, variant: HMAC.Variant = .sha256) throws {
             precondition(iterations > 0)
             
             guard let prf = HMAC(key: password, variant: variant) where iterations > 0 && !password.isEmpty && !salt.isEmpty else {
                 throw Error.InvalidInput
             }
 
-            let keyLengthFinal = Double(keyLength ?? variant.size)
+            self.dkLen = keyLength ?? variant.size
+            let keyLengthFinal = Double(self.dkLen)
             let hLen = Double(prf.variant.size)
             if keyLengthFinal > (pow(2,32) - 1) * hLen {
                 throw Error.DerivedKeyTooLong
@@ -51,26 +53,25 @@ public extension PKCS5 {
             self.iterations = iterations
             self.prf = prf
 
-
             self.numBlocks = UInt(ceil(Double(keyLengthFinal) / hLen))  // l = ceil(keyLength / hLen)
         }
 
-        public func calculate() -> [UInt8] {
-            var ret = [UInt8]()
+        public func calculate() -> Array<UInt8> {
+            var ret = Array<UInt8>()
             for i in 1...self.numBlocks {
                 // for each block T_i = U_1 ^ U_2 ^ ... ^ U_iter
                 if let value = calculateBlock(salt: self.salt, blockNum: i) {
                     ret.appendContentsOf(value)
                 }
             }
-            return ret
+            return Array(ret.prefix(self.dkLen))
         }
     }
 }
 
 private extension PKCS5.PBKDF2 {
-    private func INT(i: UInt) -> [UInt8] {
-        var inti = [UInt8](count: 4, repeatedValue: 0)
+    private func INT(i: UInt) -> Array<UInt8> {
+        var inti = Array<UInt8>(count: 4, repeatedValue: 0)
         inti[0] = UInt8((i >> 24) & 0xFF)
         inti[1] = UInt8((i >> 16) & 0xFF)
         inti[2] = UInt8((i >> 8) & 0xFF)
@@ -80,7 +81,7 @@ private extension PKCS5.PBKDF2 {
 
     // F (P, S, c, i) = U_1 \xor U_2 \xor ... \xor U_c
     // U_1 = PRF (P, S || INT (i))
-    private func calculateBlock(salt salt: [UInt8], blockNum: UInt) -> [UInt8]? {
+    private func calculateBlock(salt salt: Array<UInt8>, blockNum: UInt) -> Array<UInt8>? {
         guard let u1 = prf.authenticate(salt + INT(blockNum)) else {
             return nil
         }

+ 2 - 2
Sources/CryptoSwift/PKCS7.swift

@@ -19,7 +19,7 @@ public struct PKCS7: Padding {
         
     }
     
-    public func add(bytes: [UInt8] , blockSize:Int) -> [UInt8] {
+    public func add(bytes: Array<UInt8> , blockSize:Int) -> Array<UInt8> {
         let padding = UInt8(blockSize - (bytes.count % blockSize))
         var withPadding = bytes
         if (padding == 0) {
@@ -36,7 +36,7 @@ public struct PKCS7: Padding {
         return withPadding
     }
 
-    public func remove(bytes: [UInt8], blockSize:Int?) -> [UInt8] {
+    public func remove(bytes: Array<UInt8>, blockSize:Int?) -> Array<UInt8> {
         assert(!bytes.isEmpty, "Need bytes to remove padding")
         guard !bytes.isEmpty, let lastByte = bytes.last else {
             return bytes

+ 2 - 2
Sources/CryptoSwift/Padding.swift

@@ -7,6 +7,6 @@
 //
 
 public protocol Padding {
-    func add(data: [UInt8], blockSize:Int) -> [UInt8]
-    func remove(data: [UInt8], blockSize:Int?) -> [UInt8]
+    func add(data: Array<UInt8>, blockSize:Int) -> Array<UInt8>
+    func remove(data: Array<UInt8>, blockSize:Int?) -> Array<UInt8>
 }

+ 17 - 17
Sources/CryptoSwift/Poly1305.swift

@@ -15,15 +15,15 @@ final public class Poly1305 {
     private var ctx:Context?
     
     private class Context {
-        var r            = [UInt8](count: 17, repeatedValue: 0)
-        var h            = [UInt8](count: 17, repeatedValue: 0)
-        var pad          = [UInt8](count: 17, repeatedValue: 0)
-        var buffer       = [UInt8](count: 16, repeatedValue: 0)
+        var r            = Array<UInt8>(count: 17, repeatedValue: 0)
+        var h            = Array<UInt8>(count: 17, repeatedValue: 0)
+        var pad          = Array<UInt8>(count: 17, repeatedValue: 0)
+        var buffer       = Array<UInt8>(count: 16, repeatedValue: 0)
         
         var final:UInt8   = 0
         var leftover:Int = 0
         
-        init?(_ key: [UInt8]) {
+        init?(_ key: Array<UInt8>) {
             assert(key.count == 32,"Invalid key length");
             if (key.count != 32) {
                 return nil;
@@ -84,7 +84,7 @@ final public class Poly1305 {
 
      - returns: Message Authentication Code
      */
-    public func authenticate(message:[UInt8]) -> [UInt8]? {
+    public func authenticate(message:Array<UInt8>) -> Array<UInt8>? {
         if let ctx = self.ctx {
             update(ctx, message: message)
             return finish(ctx)
@@ -92,7 +92,7 @@ final public class Poly1305 {
         return nil
     }
     
-    public init? (key: [UInt8]) {
+    public init? (key: Array<UInt8>) {
         ctx = Context(key)
         if (ctx == nil) {
             return nil
@@ -108,7 +108,7 @@ final public class Poly1305 {
     - parameter message: message
     - parameter bytes:   length of the message fragment to be processed
     */
-    private func update(context:Context, message:[UInt8], bytes:Int? = nil) {
+    private func update(context:Context, message:Array<UInt8>, bytes:Int? = nil) {
         var bytes = bytes ?? message.count
         var mPos = 0
         
@@ -153,8 +153,8 @@ final public class Poly1305 {
         }
     }
     
-    private func finish(context:Context) -> [UInt8]? {
-        var mac = [UInt8](count: 16, repeatedValue: 0);
+    private func finish(context:Context) -> Array<UInt8>? {
+        var mac = Array<UInt8>(count: 16, repeatedValue: 0);
         
         /* process the remaining block */
         if (context.leftover > 0) {
@@ -183,7 +183,7 @@ final public class Poly1305 {
     
     // MARK: - Utils
     
-    private func add(context:Context, c:[UInt8]) -> Bool {
+    private func add(context:Context, c:Array<UInt8>) -> Bool {
         if (context.h.count != 17 && c.count != 17) {
             return false
         }
@@ -197,7 +197,7 @@ final public class Poly1305 {
         return true
     }
     
-    private func squeeze(context:Context, hr:[UInt32]) -> Bool {
+    private func squeeze(context:Context, hr:Array<UInt32>) -> Bool {
         if (context.h.count != 17 && hr.count != 17) {
             return false
         }
@@ -230,8 +230,8 @@ final public class Poly1305 {
             return false
         }
         
-        let minusp:[UInt8] = [0x05,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xfc]
-        var horig:[UInt8] = [UInt8](count: 17, repeatedValue: 0)
+        let minusp:Array<UInt8> = [0x05,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xfc]
+        var horig:Array<UInt8> = Array<UInt8>(count: 17, repeatedValue: 0)
         
         /* compute h + -p */
         for i in 0..<17 {
@@ -254,15 +254,15 @@ final public class Poly1305 {
         return true;
     }
     
-    private func blocks(context:Context, m:[UInt8], startPos:Int = 0) -> Int {
+    private func blocks(context:Context, m:Array<UInt8>, startPos:Int = 0) -> Int {
         var bytes = m.count
         let hibit = context.final ^ 1 // 1 <<128
         var mPos = startPos
         
         while (bytes >= Int(blockSize)) {
-            var hr:[UInt32] = [UInt32](count: 17, repeatedValue: 0)
+            var hr:Array<UInt32> = Array<UInt32>(count: 17, repeatedValue: 0)
             var u:UInt32 = 0
-            var c:[UInt8] = [UInt8](count: 17, repeatedValue: 0)
+            var c:Array<UInt8> = Array<UInt8>(count: 17, repeatedValue: 0)
             
             /* h += m */
             for i in 0..<16 {

+ 14 - 14
Sources/CryptoSwift/Rabbit.swift

@@ -23,19 +23,19 @@ final public class Rabbit: BlockCipher {
     private let key: Key
     
     /// IV (optional)
-    private let iv: [UInt8]?
+    private let iv: Array<UInt8>?
     
     /// State variables
-    private var x = [UInt32](count: 8, repeatedValue: 0)
+    private var x = Array<UInt32>(count: 8, repeatedValue: 0)
     
     /// Counter variables
-    private var c = [UInt32](count: 8, repeatedValue: 0)
+    private var c = Array<UInt32>(count: 8, repeatedValue: 0)
     
     /// Counter carry
     private var p7: UInt32 = 0
     
     /// 'a' constants
-    private var a: [UInt32] = [
+    private var a: Array<UInt32> = [
         0x4D34D34D,
         0xD34D34D3,
         0x34D34D34,
@@ -47,11 +47,11 @@ final public class Rabbit: BlockCipher {
     ]
     
     // MARK: - Initializers
-    convenience public init?(key:[UInt8]) {
+    convenience public init?(key:Array<UInt8>) {
         self.init(key: key, iv: nil)
     }
     
-    public init?(key:[UInt8], iv:[UInt8]?) {
+    public init?(key:Array<UInt8>, iv:Array<UInt8>?) {
         self.key = Key(bytes: key)
         self.iv = iv
         
@@ -65,7 +65,7 @@ final public class Rabbit: BlockCipher {
         p7 = 0
         
         // Key divided into 8 subkeys
-        var k = [UInt32](count: 8, repeatedValue: 0)
+        var k = Array<UInt32>(count: 8, repeatedValue: 0)
         for j in 0..<8 {
             k[j] = UInt32(key[Rabbit.blockSize - (2*j + 1)]) | (UInt32(key[Rabbit.blockSize - (2*j + 2)]) << 8)
         }
@@ -97,7 +97,7 @@ final public class Rabbit: BlockCipher {
         }
     }
     
-    private func setupIV(iv: [UInt8]) {
+    private func setupIV(iv: Array<UInt8>) {
         // 63...56 55...48 47...40 39...32 31...24 23...16 15...8 7...0 IV bits
         //    0       1       2       3       4       5       6     7   IV bytes in array
         let iv0: UInt32 = integerWithBytes([iv[4], iv[5], iv[6], iv[7]])
@@ -133,7 +133,7 @@ final public class Rabbit: BlockCipher {
         p7 = carry // save last carry bit
         
         // Iteration of the system
-        var newX = [UInt32](count: 8, repeatedValue: 0)
+        var newX = Array<UInt32>(count: 8, repeatedValue: 0)
         newX[0] = g(0) &+ rotateLeft(g(7), 16) &+ rotateLeft(g(6), 16)
         newX[1] = g(1) &+ rotateLeft(g(0), 8)  &+ g(7)
         newX[2] = g(2) &+ rotateLeft(g(1), 16) &+ rotateLeft(g(0), 16)
@@ -151,7 +151,7 @@ final public class Rabbit: BlockCipher {
         return UInt32(truncatingBitPattern: square ^ (square >> 32))
     }
     
-    private func nextOutput() -> [UInt8] {
+    private func nextOutput() -> Array<UInt8> {
         nextState()
         
         var output16 = [UInt16](count: Rabbit.blockSize / 2, repeatedValue: 0)
@@ -164,7 +164,7 @@ final public class Rabbit: BlockCipher {
         output16[1] = UInt16(truncatingBitPattern: x[6]) ^ UInt16(truncatingBitPattern: x[3] >> 16)
         output16[0] = UInt16(truncatingBitPattern: x[6] >> 16) ^ UInt16(truncatingBitPattern: x[1])
         
-        var output8 = [UInt8](count: Rabbit.blockSize, repeatedValue: 0)
+        var output8 = Array<UInt8>(count: Rabbit.blockSize, repeatedValue: 0)
         for j in 0..<output16.count {
             output8[j * 2] = UInt8(truncatingBitPattern: output16[j] >> 8)
             output8[j * 2 + 1] = UInt8(truncatingBitPattern: output16[j])
@@ -175,10 +175,10 @@ final public class Rabbit: BlockCipher {
 
 // MARK: Cipher
 extension Rabbit: Cipher {
-    public func encrypt(bytes: [UInt8]) -> [UInt8] {
+    public func encrypt(bytes: Array<UInt8>) -> Array<UInt8> {
         setup()
 
-        var result = [UInt8](count: bytes.count, repeatedValue: 0)
+        var result = Array<UInt8>(count: bytes.count, repeatedValue: 0)
         var output = nextOutput()
         var byteIdx = 0
         var outputIdx = 0
@@ -196,7 +196,7 @@ extension Rabbit: Cipher {
         return result
     }
 
-    public func decrypt(bytes: [UInt8]) -> [UInt8] {
+    public func decrypt(bytes: Array<UInt8>) -> Array<UInt8> {
         return encrypt(bytes)
     }
 }

+ 6 - 6
Sources/CryptoSwift/SHA1.swift

@@ -8,15 +8,15 @@
 
 final class SHA1 : HashProtocol {
     static let size:Int = 20 // 160 / 8
-    let message: [UInt8]
+    let message: Array<UInt8>
     
-    init(_ message: [UInt8]) {
+    init(_ message: Array<UInt8>) {
         self.message = message
     }
     
-    private let h:[UInt32] = [0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0]
+    private let h:Array<UInt32> = [0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0]
         
-    func calculate() -> [UInt8] {
+    func calculate() -> Array<UInt8> {
         var tmpMessage = self.prepare(64)
         
         // hash values
@@ -30,7 +30,7 @@ final class SHA1 : HashProtocol {
         for chunk in BytesSequence(chunkSize: chunkSizeBytes, data: tmpMessage) {
             // break chunk into sixteen 32-bit words M[j], 0 ≤ j ≤ 15, big-endian
             // Extend the sixteen 32-bit words into eighty 32-bit words:
-            var M:[UInt32] = [UInt32](count: 80, repeatedValue: 0)
+            var M:Array<UInt32> = Array<UInt32>(count: 80, repeatedValue: 0)
             for x in 0..<M.count {
                 switch (x) {
                 case 0...15:
@@ -93,7 +93,7 @@ final class SHA1 : HashProtocol {
         }
         
         // Produce the final hash value (big-endian) as a 160 bit number:
-        var result = [UInt8]()
+        var result = Array<UInt8>()
         result.reserveCapacity(hh.count / 4)
         hh.forEach {
             let item = $0.bigEndian

+ 9 - 9
Sources/CryptoSwift/SHA2.swift

@@ -10,9 +10,9 @@ final class SHA2 : HashProtocol {
     var size:Int { return variant.rawValue }
     let variant:SHA2.Variant
     
-    let message: [UInt8]
+    let message: Array<UInt8>
     
-    init(_ message:[UInt8], variant: SHA2.Variant) {
+    init(_ message:Array<UInt8>, variant: SHA2.Variant) {
         self.variant = variant
         self.message = message
     }
@@ -113,11 +113,11 @@ final class SHA2 : HashProtocol {
     }
     
     //FIXME: I can't do Generic func out of calculate32 and calculate64 (UInt32 vs UInt64), but if you can - please do pull request.
-    func calculate32() -> [UInt8] {
+    func calculate32() -> Array<UInt8> {
         var tmpMessage = self.prepare(64)
         
         // hash values
-        var hh = [UInt32]()
+        var hh = Array<UInt32>()
         variant.h.forEach {(h) -> () in
             hh.append(UInt32(h))
         }
@@ -130,7 +130,7 @@ final class SHA2 : HashProtocol {
         for chunk in BytesSequence(chunkSize: chunkSizeBytes, data: tmpMessage) {
             // break chunk into sixteen 32-bit words M[j], 0 ≤ j ≤ 15, big-endian
             // Extend the sixteen 32-bit words into sixty-four 32-bit words:
-            var M:[UInt32] = [UInt32](count: variant.k.count, repeatedValue: 0)
+            var M:Array<UInt32> = Array<UInt32>(count: variant.k.count, repeatedValue: 0)
             for x in 0..<M.count {
                 switch (x) {
                 case 0...15:
@@ -186,7 +186,7 @@ final class SHA2 : HashProtocol {
         }
         
         // Produce the final hash value (big-endian) as a 160 bit number:
-        var result = [UInt8]()
+        var result = Array<UInt8>()
         result.reserveCapacity(hh.count / 4)
         variant.resultingArray(hh).forEach {
             let item = $0.bigEndian
@@ -195,7 +195,7 @@ final class SHA2 : HashProtocol {
         return result
     }
     
-    func calculate64() -> [UInt8] {
+    func calculate64() -> Array<UInt8> {
         var tmpMessage = self.prepare(128)
         
         // hash values
@@ -269,11 +269,11 @@ final class SHA2 : HashProtocol {
         }
         
         // Produce the final hash value (big-endian)
-        var result = [UInt8]()
+        var result = Array<UInt8>()
         result.reserveCapacity(hh.count / 4)
         variant.resultingArray(hh).forEach {
             let item = $0.bigEndian
-            var partialResult = [UInt8]()
+            var partialResult = Array<UInt8>()
             partialResult.reserveCapacity(8)
             for i in 0..<8 {
                 let shift = UInt64(8 * i)

+ 2 - 2
Sources/CryptoSwift/SecureBytes.swift

@@ -16,10 +16,10 @@
 #endif
 
 class SecureBytes {
-    private let bytes: [UInt8]
+    private let bytes: Array<UInt8>
     let count: Int
 
-    init(bytes: [UInt8]) {
+    init(bytes: Array<UInt8>) {
         self.bytes = bytes
         self.count = bytes.count
         self.bytes.withUnsafeBufferPointer { (pointer) -> Void in

+ 2 - 2
Sources/CryptoSwift/String+Extension.swift

@@ -41,11 +41,11 @@ extension String {
         return self.utf8.lazy.map({ $0 as UInt8 }).crc16(seed).toHexString()
     }
 
-    public func encrypt(cipher: Cipher) throws -> [UInt8] {
+    public func encrypt(cipher: Cipher) throws -> Array<UInt8> {
         return try self.utf8.lazy.map({ $0 as UInt8 }).encrypt(cipher)
     }
 
-    public func decrypt(cipher: Cipher) throws -> [UInt8] {
+    public func decrypt(cipher: Cipher) throws -> Array<UInt8> {
         return try self.utf8.lazy.map({ $0 as UInt8 }).decrypt(cipher)
     }
     

+ 2 - 2
Sources/CryptoSwift/UInt32Extension.swift

@@ -18,7 +18,7 @@ extension UInt32: _UInt32Type {}
 
 /** array of bytes */
 extension UInt32 {
-    public func bytes(totalBytes: Int = sizeof(UInt32)) -> [UInt8] {
+    public func bytes(totalBytes: Int = sizeof(UInt32)) -> Array<UInt8> {
         return arrayOfBytes(self, length: totalBytes)
     }
 
@@ -27,7 +27,7 @@ extension UInt32 {
     }
 
     /** Int with array bytes (little-endian) */
-    public static func withBytes(bytes: [UInt8]) -> UInt32 {
+    public static func withBytes(bytes: Array<UInt8>) -> UInt32 {
         return integerWithBytes(bytes)
     }
 }

+ 2 - 2
Sources/CryptoSwift/UInt64Extension.swift

@@ -8,7 +8,7 @@
 
 /** array of bytes */
 extension UInt64 {
-    public func bytes(totalBytes: Int = sizeof(UInt64)) -> [UInt8] {
+    public func bytes(totalBytes: Int = sizeof(UInt64)) -> Array<UInt8> {
         return arrayOfBytes(self, length: totalBytes)
     }
 
@@ -17,7 +17,7 @@ extension UInt64 {
     }
 
     /** Int with array bytes (little-endian) */
-    public static func withBytes(bytes: [UInt8]) -> UInt64 {
+    public static func withBytes(bytes: Array<UInt8>) -> UInt64 {
         return integerWithBytes(bytes)
     }
 }

+ 7 - 7
Sources/CryptoSwift/UpdatableCryptor.swift

@@ -12,7 +12,7 @@ public protocol UpdatableCryptor {
     /// - parameter bytes: Bytes to process
     /// - parameter isLast: (Optional) Given chunk is the last one. No more updates after this call.
     /// - returns: Processed data or empty array.
-    mutating func update(withBytes bytes:[UInt8], isLast: Bool) throws -> [UInt8]
+    mutating func update(withBytes bytes:Array<UInt8>, isLast: Bool) throws -> Array<UInt8>
 
     /// Encrypt/Decrypt given bytes in chunks.
     ///
@@ -20,33 +20,33 @@ public protocol UpdatableCryptor {
     /// - parameter isLast: (Optional) Given chunk is the last one. No more updates after this call.
     /// - parameter output: Resulting data
     /// - returns: Processed data or empty array.
-    mutating func update(withBytes bytes:[UInt8], isLast: Bool, output: (Array<UInt8>) -> Void) throws
+    mutating func update(withBytes bytes:Array<UInt8>, isLast: Bool, output: (Array<UInt8>) -> Void) throws
 
     /// Finish encryption/decryption. This may apply padding.
     /// - parameter bytes: Bytes to process
     /// - returns: Processed data.
-    mutating func finish(withBytes bytes:[UInt8]) throws -> [UInt8]
+    mutating func finish(withBytes bytes:Array<UInt8>) throws -> Array<UInt8>
 
     /// Finish encryption/decryption. This may apply padding.
     /// - parameter bytes: Bytes to process
     /// - parameter output: Resulting data
     /// - returns: Processed data.
-    mutating func finish(withBytes bytes:[UInt8], output: (Array<UInt8>) -> Void) throws
+    mutating func finish(withBytes bytes:Array<UInt8>, output: (Array<UInt8>) -> Void) throws
 }
 
 extension UpdatableCryptor {
-    mutating public func update(withBytes bytes:[UInt8], isLast: Bool = false, output: (Array<UInt8>) -> Void) throws {
+    mutating public func update(withBytes bytes:Array<UInt8>, isLast: Bool = false, output: (Array<UInt8>) -> Void) throws {
         let processed = try self.update(withBytes: bytes, isLast: isLast)
         if (!processed.isEmpty) {
             output(processed)
         }
     }
 
-    mutating public func finish(withBytes bytes:[UInt8] = []) throws  -> [UInt8] {
+    mutating public func finish(withBytes bytes:Array<UInt8> = []) throws  -> Array<UInt8> {
         return try self.update(withBytes: bytes, isLast: true)
     }
 
-    mutating public func finish(withBytes bytes:[UInt8] = [], output: (Array<UInt8>) -> Void) throws {
+    mutating public func finish(withBytes bytes:Array<UInt8> = [], output: (Array<UInt8>) -> Void) throws {
         let processed = try self.update(withBytes: bytes, isLast: true)
         if (!processed.isEmpty) {
             output(processed)

+ 2 - 2
Sources/CryptoSwift/Utils.swift

@@ -85,8 +85,8 @@ func toUInt64Array(slice: ArraySlice<UInt8>) -> Array<UInt64> {
     return result
 }
 
-func xor(a: [UInt8], _ b:[UInt8]) -> [UInt8] {
-    var xored = [UInt8](count: min(a.count, b.count), repeatedValue: 0)
+func xor(a: Array<UInt8>, _ b:Array<UInt8>) -> Array<UInt8> {
+    var xored = Array<UInt8>(count: min(a.count, b.count), repeatedValue: 0)
     for i in 0..<xored.count {
         xored[i] = a[i] ^ b[i]
     }

部分文件因为文件数量过多而无法显示