Преглед на файлове

Swift 2.0 beta2 compatible

Marcin Krzyżanowski преди 10 години
родител
ревизия
875cc81f63

+ 13 - 14
CryptoSwift.xcodeproj/project.pbxproj

@@ -21,14 +21,16 @@
 /* End PBXAggregateTarget section */
 /* End PBXAggregateTarget section */
 
 
 /* Begin PBXBuildFile section */
 /* Begin PBXBuildFile section */
-		750A54601992D2680017DA75 /* MD5.swift in Sources */ = {isa = PBXBuildFile; fileRef = 750A545F1992D2680017DA75 /* MD5.swift */; };
 		75100F8F19B0BC890005C5F5 /* Poly1305Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 75100F8E19B0BC890005C5F5 /* Poly1305Tests.swift */; };
 		75100F8F19B0BC890005C5F5 /* Poly1305Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 75100F8E19B0BC890005C5F5 /* Poly1305Tests.swift */; };
-		75153D4219AA3C7900750381 /* SHA2.swift in Sources */ = {isa = PBXBuildFile; fileRef = 75153D4119AA3C7900750381 /* SHA2.swift */; };
 		75164E4919AD30AC00737F30 /* Utils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 75164E4819AD30AC00737F30 /* Utils.swift */; };
 		75164E4919AD30AC00737F30 /* Utils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 75164E4819AD30AC00737F30 /* Utils.swift */; };
 		751C5C3D19B26B000094C75D /* Poly1305.swift in Sources */ = {isa = PBXBuildFile; fileRef = 751C5C3C19B26B000094C75D /* Poly1305.swift */; };
 		751C5C3D19B26B000094C75D /* Poly1305.swift in Sources */ = {isa = PBXBuildFile; fileRef = 751C5C3C19B26B000094C75D /* Poly1305.swift */; };
-		752DEF7719693EA000E17557 /* NSDataExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 752DEF7619693EA000E17557 /* NSDataExtension.swift */; };
-		752E087B199FF27C005B0EA0 /* SHA1.swift in Sources */ = {isa = PBXBuildFile; fileRef = 752E087A199FF27C005B0EA0 /* SHA1.swift */; };
 		753988211AB72E4100FAF3FC /* ArrayExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 754C8FEC19979F94005AD904 /* ArrayExtension.swift */; };
 		753988211AB72E4100FAF3FC /* ArrayExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 754C8FEC19979F94005AD904 /* ArrayExtension.swift */; };
+		7539E3291B3B4A530037F4E1 /* MD5.swift in Sources */ = {isa = PBXBuildFile; fileRef = 750A545F1992D2680017DA75 /* MD5.swift */; };
+		7539E32A1B3B4C480037F4E1 /* NSDataExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 752DEF7619693EA000E17557 /* NSDataExtension.swift */; };
+		7539E32B1B3B4C6B0037F4E1 /* HMAC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 758A94251A65AEB100E46135 /* HMAC.swift */; };
+		7539E32C1B3B4C750037F4E1 /* StringExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7599C9C5199EA28700A3988B /* StringExtension.swift */; };
+		7539E32D1B3B4E950037F4E1 /* SHA1.swift in Sources */ = {isa = PBXBuildFile; fileRef = 752E087A199FF27C005B0EA0 /* SHA1.swift */; };
+		7539E32E1B3B4E970037F4E1 /* SHA2.swift in Sources */ = {isa = PBXBuildFile; fileRef = 75153D4119AA3C7900750381 /* SHA2.swift */; };
 		75445821196AA2A5002FF20E /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 75445820196AA2A5002FF20E /* Security.framework */; settings = {ATTRIBUTES = (Required, ); }; };
 		75445821196AA2A5002FF20E /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 75445820196AA2A5002FF20E /* Security.framework */; settings = {ATTRIBUTES = (Required, ); }; };
 		7547195119931802002FA5F1 /* IntExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7547195019931802002FA5F1 /* IntExtension.swift */; };
 		7547195119931802002FA5F1 /* IntExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7547195019931802002FA5F1 /* IntExtension.swift */; };
 		754BE45B19693E190098E6F3 /* CryptoSwift.h in Headers */ = {isa = PBXBuildFile; fileRef = 754BE45A19693E190098E6F3 /* CryptoSwift.h */; settings = {ATTRIBUTES = (Public, ); }; };
 		754BE45B19693E190098E6F3 /* CryptoSwift.h in Headers */ = {isa = PBXBuildFile; fileRef = 754BE45A19693E190098E6F3 /* CryptoSwift.h */; settings = {ATTRIBUTES = (Public, ); }; };
@@ -45,13 +47,11 @@
 		757DA2571A4ED47B002BA3EF /* Helpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 757DA2561A4ED47B002BA3EF /* Helpers.swift */; };
 		757DA2571A4ED47B002BA3EF /* Helpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 757DA2561A4ED47B002BA3EF /* Helpers.swift */; };
 		757DA2591A4ED4D7002BA3EF /* ChaCha20Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 757DA2581A4ED4D7002BA3EF /* ChaCha20Tests.swift */; };
 		757DA2591A4ED4D7002BA3EF /* ChaCha20Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 757DA2581A4ED4D7002BA3EF /* ChaCha20Tests.swift */; };
 		757EF7F519AAA82400586276 /* CRC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 757EF7F419AAA82400586276 /* CRC.swift */; };
 		757EF7F519AAA82400586276 /* CRC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 757EF7F419AAA82400586276 /* CRC.swift */; };
-		758A94261A65AEB100E46135 /* HMAC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 758A94251A65AEB100E46135 /* HMAC.swift */; };
 		758A94281A65C59200E46135 /* HMACTests.swift in Resources */ = {isa = PBXBuildFile; fileRef = 758A94271A65C59200E46135 /* HMACTests.swift */; };
 		758A94281A65C59200E46135 /* HMACTests.swift in Resources */ = {isa = PBXBuildFile; fileRef = 758A94271A65C59200E46135 /* HMACTests.swift */; };
 		758A94291A65C67400E46135 /* HMACTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 758A94271A65C59200E46135 /* HMACTests.swift */; };
 		758A94291A65C67400E46135 /* HMACTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 758A94271A65C59200E46135 /* HMACTests.swift */; };
 		758C764119B61AE500653BC6 /* Generics.swift in Sources */ = {isa = PBXBuildFile; fileRef = 758C764019B61AE500653BC6 /* Generics.swift */; };
 		758C764119B61AE500653BC6 /* Generics.swift in Sources */ = {isa = PBXBuildFile; fileRef = 758C764019B61AE500653BC6 /* Generics.swift */; };
 		758C764319B61DE900653BC6 /* UInt16Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 758C764219B61DE900653BC6 /* UInt16Extension.swift */; };
 		758C764319B61DE900653BC6 /* UInt16Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 758C764219B61DE900653BC6 /* UInt16Extension.swift */; };
 		758F3F781992F6CE0014BBDA /* UInt8Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 758F3F771992F6CE0014BBDA /* UInt8Extension.swift */; };
 		758F3F781992F6CE0014BBDA /* UInt8Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 758F3F771992F6CE0014BBDA /* UInt8Extension.swift */; };
-		7599C9C6199EA28700A3988B /* StringExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7599C9C5199EA28700A3988B /* StringExtension.swift */; };
 		759D481119B517BC005FF7FC /* BitExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 759D481019B517BC005FF7FC /* BitExtension.swift */; };
 		759D481119B517BC005FF7FC /* BitExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 759D481019B517BC005FF7FC /* BitExtension.swift */; };
 		75A663A61AA0CAD00052110B /* Padding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 75A663A51AA0CAD00052110B /* Padding.swift */; };
 		75A663A61AA0CAD00052110B /* Padding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 75A663A51AA0CAD00052110B /* Padding.swift */; };
 		75A74B271A1FF6B2004419F1 /* AES.swift in Sources */ = {isa = PBXBuildFile; fileRef = 75A74B261A1FF6B2004419F1 /* AES.swift */; };
 		75A74B271A1FF6B2004419F1 /* AES.swift in Sources */ = {isa = PBXBuildFile; fileRef = 75A74B261A1FF6B2004419F1 /* AES.swift */; };
@@ -357,6 +357,7 @@
 		754BE44C19693E190098E6F3 /* Project object */ = {
 		754BE44C19693E190098E6F3 /* Project object */ = {
 			isa = PBXProject;
 			isa = PBXProject;
 			attributes = {
 			attributes = {
+				LastSwiftUpdateCheck = 0700;
 				LastUpgradeCheck = 0600;
 				LastUpgradeCheck = 0600;
 				ORGANIZATIONNAME = "Marcin Krzyzanowski";
 				ORGANIZATIONNAME = "Marcin Krzyzanowski";
 				TargetAttributes = {
 				TargetAttributes = {
@@ -434,21 +435,22 @@
 				751C5C3D19B26B000094C75D /* Poly1305.swift in Sources */,
 				751C5C3D19B26B000094C75D /* Poly1305.swift in Sources */,
 				7552614E1993051E000D2B20 /* Hash.swift in Sources */,
 				7552614E1993051E000D2B20 /* Hash.swift in Sources */,
 				75BC3AE31A4E412000ADF343 /* CipherBlockMode.swift in Sources */,
 				75BC3AE31A4E412000ADF343 /* CipherBlockMode.swift in Sources */,
-				7599C9C6199EA28700A3988B /* StringExtension.swift in Sources */,
 				75BE4EB11B1E4A9F007A2B57 /* IntegerConvertible.swift in Sources */,
 				75BE4EB11B1E4A9F007A2B57 /* IntegerConvertible.swift in Sources */,
+				7539E32E1B3B4E970037F4E1 /* SHA2.swift in Sources */,
+				7539E32C1B3B4C750037F4E1 /* StringExtension.swift in Sources */,
 				7563B2E819B14D4300B152CD /* Cipher.swift in Sources */,
 				7563B2E819B14D4300B152CD /* Cipher.swift in Sources */,
-				752E087B199FF27C005B0EA0 /* SHA1.swift in Sources */,
+				7539E32B1B3B4C6B0037F4E1 /* HMAC.swift in Sources */,
+				7539E32A1B3B4C480037F4E1 /* NSDataExtension.swift in Sources */,
 				75EB380119ABDD710002375A /* ChaCha20.swift in Sources */,
 				75EB380119ABDD710002375A /* ChaCha20.swift in Sources */,
 				75A663A61AA0CAD00052110B /* Padding.swift in Sources */,
 				75A663A61AA0CAD00052110B /* Padding.swift in Sources */,
-				750A54601992D2680017DA75 /* MD5.swift in Sources */,
 				75164E4919AD30AC00737F30 /* Utils.swift in Sources */,
 				75164E4919AD30AC00737F30 /* Utils.swift in Sources */,
-				758A94261A65AEB100E46135 /* HMAC.swift in Sources */,
-				752DEF7719693EA000E17557 /* NSDataExtension.swift in Sources */,
 				759D481119B517BC005FF7FC /* BitExtension.swift in Sources */,
 				759D481119B517BC005FF7FC /* BitExtension.swift in Sources */,
 				754C8FED19979F94005AD904 /* ArrayExtension.swift in Sources */,
 				754C8FED19979F94005AD904 /* ArrayExtension.swift in Sources */,
+				7539E3291B3B4A530037F4E1 /* MD5.swift in Sources */,
 				7547195119931802002FA5F1 /* IntExtension.swift in Sources */,
 				7547195119931802002FA5F1 /* IntExtension.swift in Sources */,
 				758C764319B61DE900653BC6 /* UInt16Extension.swift in Sources */,
 				758C764319B61DE900653BC6 /* UInt16Extension.swift in Sources */,
 				75D94E2419B60C08007CB2A4 /* Operators.swift in Sources */,
 				75D94E2419B60C08007CB2A4 /* Operators.swift in Sources */,
+				7539E32D1B3B4E950037F4E1 /* SHA1.swift in Sources */,
 				75B0A5701AB1A1BB000BD8D2 /* PKCS5.swift in Sources */,
 				75B0A5701AB1A1BB000BD8D2 /* PKCS5.swift in Sources */,
 				757EF7F519AAA82400586276 /* CRC.swift in Sources */,
 				757EF7F519AAA82400586276 /* CRC.swift in Sources */,
 				75D94E2619B60C4F007CB2A4 /* UInt32Extension.swift in Sources */,
 				75D94E2619B60C4F007CB2A4 /* UInt32Extension.swift in Sources */,
@@ -458,7 +460,6 @@
 				754DD76E19A149AF00E52288 /* HashBase.swift in Sources */,
 				754DD76E19A149AF00E52288 /* HashBase.swift in Sources */,
 				758C764119B61AE500653BC6 /* Generics.swift in Sources */,
 				758C764119B61AE500653BC6 /* Generics.swift in Sources */,
 				758F3F781992F6CE0014BBDA /* UInt8Extension.swift in Sources */,
 				758F3F781992F6CE0014BBDA /* UInt8Extension.swift in Sources */,
-				75153D4219AA3C7900750381 /* SHA2.swift in Sources */,
 			);
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 			runOnlyForDeploymentPostprocessing = 0;
 		};
 		};
@@ -573,7 +574,6 @@
 				ONLY_ACTIVE_ARCH = YES;
 				ONLY_ACTIVE_ARCH = YES;
 				SDKROOT = iphoneos;
 				SDKROOT = iphoneos;
 				SWIFT_OPTIMIZATION_LEVEL = "-Onone";
 				SWIFT_OPTIMIZATION_LEVEL = "-Onone";
-				SWIFT_WHOLE_MODULE_OPTIMIZATION = YES;
 				TARGETED_DEVICE_FAMILY = "1,2";
 				TARGETED_DEVICE_FAMILY = "1,2";
 				VERSIONING_SYSTEM = "apple-generic";
 				VERSIONING_SYSTEM = "apple-generic";
 				VERSION_INFO_PREFIX = "";
 				VERSION_INFO_PREFIX = "";
@@ -612,7 +612,6 @@
 				IPHONEOS_DEPLOYMENT_TARGET = 8.0;
 				IPHONEOS_DEPLOYMENT_TARGET = 8.0;
 				METAL_ENABLE_DEBUG_INFO = NO;
 				METAL_ENABLE_DEBUG_INFO = NO;
 				SDKROOT = iphoneos;
 				SDKROOT = iphoneos;
-				SWIFT_WHOLE_MODULE_OPTIMIZATION = YES;
 				TARGETED_DEVICE_FAMILY = "1,2";
 				TARGETED_DEVICE_FAMILY = "1,2";
 				VALIDATE_PRODUCT = YES;
 				VALIDATE_PRODUCT = YES;
 				VERSIONING_SYSTEM = "apple-generic";
 				VERSIONING_SYSTEM = "apple-generic";

+ 19 - 19
CryptoSwift/AES.swift

@@ -137,9 +137,9 @@ final public class AES {
     /**
     /**
     Encrypt message. If padding is necessary, then PKCS7 padding is added and needs to be removed after decryption.
     Encrypt message. If padding is necessary, then PKCS7 padding is added and needs to be removed after decryption.
     
     
-    :param: message Plaintext data
+    - parameter message: Plaintext data
     
     
-    :returns: Encrypted data
+    - returns: Encrypted data
     */
     */
 
 
     public func encrypt(bytes:[UInt8], padding:Padding? = PKCS7()) -> [UInt8]? {
     public func encrypt(bytes:[UInt8], padding:Padding? = PKCS7()) -> [UInt8]? {
@@ -161,8 +161,8 @@ final public class AES {
         
         
         autoreleasepool { () -> () in
         autoreleasepool { () -> () in
             var state:[[UInt8]] = [[UInt8]](count: variant.Nb, repeatedValue: [UInt8](count: variant.Nb, repeatedValue: 0))
             var state:[[UInt8]] = [[UInt8]](count: variant.Nb, repeatedValue: [UInt8](count: variant.Nb, repeatedValue: 0))
-            for (i, row) in enumerate(state) {
-                for (j, val) in enumerate(row) {
+            for (i, row) in state.enumerate() {
+                for (j, _) in row.enumerate() {
                     state[j][i] = block[i * row.count + j]
                     state[j][i] = block[i * row.count + j]
                 }
                 }
             }
             }
@@ -215,15 +215,15 @@ final public class AES {
     
     
     private func decryptBlock(block:[UInt8]) -> [UInt8]? {
     private func decryptBlock(block:[UInt8]) -> [UInt8]? {
         var state:[[UInt8]] = [[UInt8]](count: variant.Nb, repeatedValue: [UInt8](count: variant.Nb, repeatedValue: 0))
         var state:[[UInt8]] = [[UInt8]](count: variant.Nb, repeatedValue: [UInt8](count: variant.Nb, repeatedValue: 0))
-        for (i, row) in enumerate(state) {
-            for (j, val) in enumerate(row) {
+        for (i, row) in state.enumerate() {
+            for (j, _) in row.enumerate() {
                 state[j][i] = block[i * row.count + j]
                 state[j][i] = block[i * row.count + j]
             }
             }
         }
         }
         
         
         state = addRoundKey(state,expandedKey, variant.Nr)
         state = addRoundKey(state,expandedKey, variant.Nr)
         
         
-        for roundCount in reverse(1..<variant.Nr) {
+        for roundCount in Array((1..<variant.Nr).reverse()) { //FIXME: WAT?
             state = invShiftRows(state)
             state = invShiftRows(state)
             state = invSubBytes(state)
             state = invSubBytes(state)
             state = addRoundKey(state, expandedKey, roundCount)
             state = addRoundKey(state, expandedKey, roundCount)
@@ -274,7 +274,7 @@ final public class AES {
                 tmp[wordIdx] = w[4*(i-1)+wordIdx]
                 tmp[wordIdx] = w[4*(i-1)+wordIdx]
             }
             }
             if ((i % variant.Nk) == 0) {
             if ((i % variant.Nk) == 0) {
-                let rotWord = rotateLeft(UInt32.withBytes(tmp), 8).bytes(sizeof(UInt32)) // RotWord
+                let rotWord = rotateLeft(UInt32.withBytes(tmp), n: 8).bytes(sizeof(UInt32)) // RotWord
                 tmp = subWord(rotWord)
                 tmp = subWord(rotWord)
                 tmp[0] = tmp[0] ^ Rcon[i/variant.Nk]
                 tmp[0] = tmp[0] ^ Rcon[i/variant.Nk]
             } else if (variant.Nk > 6 && (i % variant.Nk) == 4) {
             } else if (variant.Nk > 6 && (i % variant.Nk) == 4) {
@@ -294,8 +294,8 @@ extension AES {
     
     
     // byte substitution with table (S-box)
     // byte substitution with table (S-box)
     public func subBytes(inout state:[[UInt8]]) {
     public func subBytes(inout state:[[UInt8]]) {
-        for (i,row) in enumerate(state) {
-            for (j,value) in enumerate(row) {
+        for (i,row) in state.enumerate() {
+            for (j,value) in row.enumerate() {
                 state[i][j] = AES.sBox[Int(value)]
                 state[i][j] = AES.sBox[Int(value)]
             }
             }
         }
         }
@@ -303,8 +303,8 @@ extension AES {
     
     
     public func invSubBytes(state:[[UInt8]]) -> [[UInt8]] {
     public func invSubBytes(state:[[UInt8]]) -> [[UInt8]] {
         var result = state
         var result = state
-        for (i,row) in enumerate(state) {
-            for (j,value) in enumerate(row) {
+        for (i,row) in state.enumerate() {
+            for (j,value) in row.enumerate() {
                 result[i][j] = AES.invSBox[Int(value)]
                 result[i][j] = AES.invSBox[Int(value)]
             }
             }
         }
         }
@@ -337,7 +337,7 @@ extension AES {
         var a = a, b = b
         var a = a, b = b
         var p:UInt8 = 0, hbs:UInt8 = 0
         var p:UInt8 = 0, hbs:UInt8 = 0
         
         
-        for i in 0..<8 {
+        for _ in 0..<8 {
             if (b & 1 == 1) {
             if (b & 1 == 1) {
                 p ^= a
                 p ^= a
             }
             }
@@ -353,8 +353,8 @@ extension AES {
     
     
     public func matrixMultiplyPolys(matrix:[[UInt8]], _ array:[UInt8]) -> [UInt8] {
     public func matrixMultiplyPolys(matrix:[[UInt8]], _ array:[UInt8]) -> [UInt8] {
         var returnArray:[UInt8] = [UInt8](count: array.count, repeatedValue: 0)
         var returnArray:[UInt8] = [UInt8](count: array.count, repeatedValue: 0)
-        for (i, row) in enumerate(matrix) {
-            for (j, boxVal) in enumerate(row) {
+        for (i, row) in matrix.enumerate() {
+            for (j, boxVal) in row.enumerate() {
                 returnArray[i] = multiplyPolys(boxVal, array[j]) ^ returnArray[i]
                 returnArray[i] = multiplyPolys(boxVal, array[j]) ^ returnArray[i]
             }
             }
         }
         }
@@ -377,7 +377,7 @@ extension AES {
     // mixes data (independently of one another)
     // mixes data (independently of one another)
     public func mixColumns(state:[[UInt8]]) -> [[UInt8]] {
     public func mixColumns(state:[[UInt8]]) -> [[UInt8]] {
         var state = state
         var state = state
-        var colBox:[[UInt8]] = [[2,3,1,1],[1,2,3,1],[1,1,2,3],[3,1,1,2]]
+        let colBox:[[UInt8]] = [[2,3,1,1],[1,2,3,1],[1,1,2,3],[3,1,1,2]]
         
         
         var rowMajorState = [[UInt8]](count: state.count, repeatedValue: [UInt8](count: state.first!.count, repeatedValue: 0)) //state.map({ val -> [UInt8] in return val.map { _ in return 0 } }) // zeroing
         var rowMajorState = [[UInt8]](count: state.count, repeatedValue: [UInt8](count: state.first!.count, repeatedValue: 0)) //state.map({ val -> [UInt8] in return val.map { _ in return 0 } }) // zeroing
         var newRowMajorState = rowMajorState
         var newRowMajorState = rowMajorState
@@ -388,7 +388,7 @@ extension AES {
             }
             }
         }
         }
         
         
-        for (i, row) in enumerate(rowMajorState) {
+        for (i, row) in rowMajorState.enumerate() {
             newRowMajorState[i] = matrixMultiplyPolys(colBox, row)
             newRowMajorState[i] = matrixMultiplyPolys(colBox, row)
         }
         }
         
         
@@ -403,7 +403,7 @@ extension AES {
     
     
     public func invMixColumns(state:[[UInt8]]) -> [[UInt8]] {
     public func invMixColumns(state:[[UInt8]]) -> [[UInt8]] {
         var state = state
         var state = state
-        var invColBox:[[UInt8]] = [[14,11,13,9],[9,14,11,13],[13,9,14,11],[11,13,9,14]]
+        let invColBox:[[UInt8]] = [[14,11,13,9],[9,14,11,13],[13,9,14,11],[11,13,9,14]]
         
         
         var colOrderState = state.map({ val -> [UInt8] in return val.map { _ in return 0 } }) // zeroing
         var colOrderState = state.map({ val -> [UInt8] in return val.map { _ in return 0 } }) // zeroing
         
         
@@ -415,7 +415,7 @@ extension AES {
         
         
         var newState = state.map({ val -> [UInt8] in return val.map { _ in return 0 } })
         var newState = state.map({ val -> [UInt8] in return val.map { _ in return 0 } })
         
         
-        for (i, row) in enumerate(colOrderState) {
+        for (i, row) in colOrderState.enumerate() {
             newState[i] = matrixMultiplyPolys(invColBox, row)
             newState[i] = matrixMultiplyPolys(invColBox, row)
         }
         }
         
         

+ 2 - 2
CryptoSwift/Authenticator.swift

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

+ 3 - 3
CryptoSwift/CRC.swift

@@ -46,14 +46,14 @@ final class CRC {
     func crc32(message:NSData) -> NSData {
     func crc32(message:NSData) -> NSData {
         var crc:UInt32 = 0xffffffff
         var crc:UInt32 = 0xffffffff
         for b in message.arrayOfBytes() {
         for b in message.arrayOfBytes() {
-            var idx = Int((crc ^ UInt32(b)) & 0xff)
+            let idx = Int((crc ^ UInt32(b)) & 0xff)
             crc = (crc >> 8) ^ table[idx]
             crc = (crc >> 8) ^ table[idx]
         }
         }
         crc = crc ^ 0xffffffff
         crc = crc ^ 0xffffffff
         
         
         // reverse bytes
         // reverse bytes
-        let bytes = NSMutableData(bytes: &crc, length: 4).arrayOfBytes().reverse()
-        var data = NSData(bytes: bytes, length: bytes.count)
+        let bytes = Array(NSMutableData(bytes: &crc, length: 4).arrayOfBytes().reverse()) //FIXME: Array ??
+        let data = NSData(bytes: bytes, length: bytes.count)
         return data
         return data
     }
     }
     
     

+ 9 - 9
CryptoSwift/ChaCha20.swift

@@ -78,18 +78,18 @@ final public class ChaCha20 {
         output.reserveCapacity(16)
         output.reserveCapacity(16)
 
 
         for i in 0..<16 {
         for i in 0..<16 {
-            x[i] = x[i] &+ input[i]
-            output += [UInt8((x[i] & 0xFFFFFFFF) >> 24),
+            x[i] = x[i] &+ input[i]            
+            output.extend([UInt8((x[i] & 0xFFFFFFFF) >> 24),
                        UInt8((x[i] & 0xFFFFFF) >> 16),
                        UInt8((x[i] & 0xFFFFFF) >> 16),
                        UInt8((x[i] & 0xFFFF) >> 8),
                        UInt8((x[i] & 0xFFFF) >> 8),
-                       UInt8((x[i] & 0xFF) >> 0)]
+                       UInt8((x[i] & 0xFF) >> 0)])
         }
         }
 
 
         return output;
         return output;
     }
     }
         
         
-    private func contextSetup(# iv:[UInt8], key:[UInt8]) -> Context? {
-        var ctx = Context()
+    private func contextSetup(iv  iv:[UInt8], key:[UInt8]) -> Context? {
+        let ctx = Context()
         let kbits = key.count * 8
         let kbits = key.count * 8
         
         
         if (kbits != 128 && kbits != 256) {
         if (kbits != 128 && kbits != 256) {
@@ -173,16 +173,16 @@ final public class ChaCha20 {
     
     
     private final func quarterround(inout a:UInt32, inout _ b:UInt32, inout _ c:UInt32, inout _ d:UInt32) {
     private final func quarterround(inout a:UInt32, inout _ b:UInt32, inout _ c:UInt32, inout _ d:UInt32) {
         a = a &+ b
         a = a &+ b
-        d = rotateLeft((d ^ a), 16)
+        d = rotateLeft((d ^ a), n: 16) //FIXME: WAT? n:
         
         
         c = c &+ d
         c = c &+ d
-        b = rotateLeft((b ^ c), 12);
+        b = rotateLeft((b ^ c), n: 12);
         
         
         a = a &+ b
         a = a &+ b
-        d = rotateLeft((d ^ a), 8);
+        d = rotateLeft((d ^ a), n: 8);
 
 
         c = c &+ d
         c = c &+ d
-        b = rotateLeft((b ^ c), 7);
+        b = rotateLeft((b ^ c), n: 7);
     }
     }
 }
 }
 
 

+ 15 - 15
CryptoSwift/Cipher.swift

@@ -12,37 +12,37 @@ public enum Cipher {
     /**
     /**
     ChaCha20
     ChaCha20
     
     
-    :param: key Encryption key
-    :param: iv  Initialization Vector
+    - parameter key: Encryption key
+    - parameter iv:  Initialization Vector
     
     
-    :returns: Value of Cipher
+    - returns: Value of Cipher
     */
     */
     case ChaCha20(key: [UInt8], iv: [UInt8])
     case ChaCha20(key: [UInt8], iv: [UInt8])
     /**
     /**
     AES
     AES
     
     
-    :param: key       Encryption key
-    :param: iv        Initialization Vector
-    :param: blockMode Block mode (CBC by default)
+    - parameter key:       Encryption key
+    - parameter iv:        Initialization Vector
+    - parameter blockMode: Block mode (CBC by default)
     
     
-    :returns: Value of Cipher
+    - returns: Value of Cipher
     */
     */
     case AES(key: [UInt8], iv: [UInt8], blockMode: CipherBlockMode)
     case AES(key: [UInt8], iv: [UInt8], blockMode: CipherBlockMode)
     
     
     /**
     /**
     Encrypt message
     Encrypt message
     
     
-    :param: message Plaintext message
+    - parameter message: Plaintext message
     
     
-    :returns: encrypted message
+    - returns: encrypted message
     */
     */
     public func encrypt(bytes: [UInt8]) -> [UInt8]? {
     public func encrypt(bytes: [UInt8]) -> [UInt8]? {
         switch (self) {
         switch (self) {
             case .ChaCha20(let key, let iv):
             case .ChaCha20(let key, let iv):
-                var chacha = CryptoSwift.ChaCha20(key: key, iv: iv)
+                let chacha = CryptoSwift.ChaCha20(key: key, iv: iv)
                 return chacha?.encrypt(bytes)
                 return chacha?.encrypt(bytes)
             case .AES(let key, let iv, let blockMode):
             case .AES(let key, let iv, let blockMode):
-                var aes = CryptoSwift.AES(key: key, iv: iv, blockMode: blockMode)
+                let aes = CryptoSwift.AES(key: key, iv: iv, blockMode: blockMode)
                 return aes?.encrypt(bytes)
                 return aes?.encrypt(bytes)
         }
         }
     }
     }
@@ -50,17 +50,17 @@ public enum Cipher {
     /**
     /**
     Decrypt message
     Decrypt message
     
     
-    :param: message Message data
+    - parameter message: Message data
     
     
-    :returns: Plaintext message
+    - returns: Plaintext message
     */
     */
     public func decrypt(bytes: [UInt8]) -> [UInt8]? {
     public func decrypt(bytes: [UInt8]) -> [UInt8]? {
         switch (self) {
         switch (self) {
             case .ChaCha20(let key, let iv):
             case .ChaCha20(let key, let iv):
-                var chacha = CryptoSwift.ChaCha20(key: key, iv: iv);
+                let chacha = CryptoSwift.ChaCha20(key: key, iv: iv);
                 return chacha?.decrypt(bytes)
                 return chacha?.decrypt(bytes)
             case .AES(let key, let iv, let blockMode):
             case .AES(let key, let iv, let blockMode):
-                var aes = CryptoSwift.AES(key: key, iv: iv, blockMode: blockMode);
+                let aes = CryptoSwift.AES(key: key, iv: iv, blockMode: blockMode);
                 return aes?.decrypt(bytes)
                 return aes?.decrypt(bytes)
         }
         }
     }
     }

+ 7 - 7
CryptoSwift/CipherBlockMode.swift

@@ -38,11 +38,11 @@ public enum CipherBlockMode {
     /**
     /**
     Process input blocks with given block cipher mode. With fallback to plain mode.
     Process input blocks with given block cipher mode. With fallback to plain mode.
     
     
-    :param: blocks cipher block size blocks
-    :param: iv     IV
-    :param: cipher single block encryption closure
+    - parameter blocks: cipher block size blocks
+    - parameter iv:     IV
+    - parameter cipher: single block encryption closure
     
     
-    :returns: encrypted bytes
+    - returns: encrypted bytes
     */
     */
     func encryptBlocks(blocks:[[UInt8]], iv:[UInt8]?, cipherOperation:CipherOperationOnBlock) -> [UInt8]? {
     func encryptBlocks(blocks:[[UInt8]], iv:[UInt8]?, cipherOperation:CipherOperationOnBlock) -> [UInt8]? {
         
         
@@ -84,7 +84,7 @@ private struct CBCMode: BlockMode {
         out.reserveCapacity(blocks.count * blocks[0].count)
         out.reserveCapacity(blocks.count * blocks[0].count)
         var prevCiphertext = iv! // for the first time prevCiphertext = iv
         var prevCiphertext = iv! // for the first time prevCiphertext = iv
         for plaintext in blocks {
         for plaintext in blocks {
-            if let encrypted = cipherOperation(block: xor(prevCiphertext, plaintext)) {
+            if let encrypted = cipherOperation(block: xor(prevCiphertext, b: plaintext)) {
                 out.extend(encrypted)
                 out.extend(encrypted)
                 prevCiphertext = encrypted
                 prevCiphertext = encrypted
             }
             }
@@ -104,7 +104,7 @@ private struct CBCMode: BlockMode {
         var prevCiphertext = iv! // for the first time prevCiphertext = iv
         var prevCiphertext = iv! // for the first time prevCiphertext = iv
         for ciphertext in blocks {
         for ciphertext in blocks {
             if let decrypted = cipherOperation(block: ciphertext) { // decrypt
             if let decrypted = cipherOperation(block: ciphertext) { // decrypt
-                out.extend(xor(prevCiphertext, decrypted))
+                out.extend(xor(prevCiphertext, b: decrypted)) //FIXME: b:
             }
             }
             prevCiphertext = ciphertext
             prevCiphertext = ciphertext
         }
         }
@@ -131,7 +131,7 @@ private struct CFBMode: BlockMode {
         var lastCiphertext = iv!
         var lastCiphertext = iv!
         for plaintext in blocks {
         for plaintext in blocks {
             if let encrypted = cipherOperation(block: lastCiphertext) {
             if let encrypted = cipherOperation(block: lastCiphertext) {
-                lastCiphertext = xor(plaintext,encrypted)
+                lastCiphertext = xor(plaintext,b: encrypted)
                 out.extend(lastCiphertext)
                 out.extend(lastCiphertext)
             }
             }
         }
         }

+ 17 - 18
CryptoSwift/Generics.swift

@@ -25,7 +25,7 @@ extension UInt64:Initiable {}
 func integerFromBitsArray<T: UnsignedIntegerType>(bits: [Bit]) -> T
 func integerFromBitsArray<T: UnsignedIntegerType>(bits: [Bit]) -> T
 {
 {
     var bitPattern:T = 0
     var bitPattern:T = 0
-    for (idx,b) in enumerate(bits) {
+    for (idx,b) in bits.enumerate() {
         if (b == Bit.One) {
         if (b == Bit.One) {
             let bit = T(UIntMax(1) << UIntMax(idx))
             let bit = T(UIntMax(1) << UIntMax(idx))
             bitPattern = bitPattern | bit
             bitPattern = bitPattern | bit
@@ -37,7 +37,7 @@ func integerFromBitsArray<T: UnsignedIntegerType>(bits: [Bit]) -> T
 /// Initialize integer from array of bytes.
 /// Initialize integer from array of bytes.
 /// This method may be slow
 /// 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: [UInt8]) -> T {
-    var bytes = bytes.reverse()
+    var bytes = Array(bytes.reverse()) //FIXME: Array?
     if bytes.count < sizeof(T) {
     if bytes.count < sizeof(T) {
         let paddingCount = sizeof(T) - bytes.count
         let paddingCount = sizeof(T) - bytes.count
         if (paddingCount > 0) {
         if (paddingCount > 0) {
@@ -50,7 +50,7 @@ func integerWithBytes<T: IntegerType where T:ByteConvertible, T: BitshiftOperati
     }
     }
     
     
     var result: T = 0
     var result: T = 0
-    for byte in bytes.reverse() {
+    for byte in Array(bytes.reverse()) { //FIXME: Array??
         result = result << 8 | T(byte)
         result = result << 8 | T(byte)
     }
     }
     return result
     return result
@@ -60,12 +60,11 @@ func integerWithBytes<T: IntegerType where T:ByteConvertible, T: BitshiftOperati
 /// I found this method slow
 /// I found this method slow
 func arrayOfBytes<T>(value:T, length:Int? = nil) -> [UInt8] {
 func arrayOfBytes<T>(value:T, length:Int? = nil) -> [UInt8] {
     let totalBytes = length ?? sizeof(T)
     let totalBytes = length ?? sizeof(T)
-    var v = value
     
     
-    var valuePointer = UnsafeMutablePointer<T>.alloc(1)
+    let valuePointer = UnsafeMutablePointer<T>.alloc(1)
     valuePointer.memory = value
     valuePointer.memory = value
     
     
-    var bytesPointer = UnsafeMutablePointer<UInt8>(valuePointer)
+    let bytesPointer = UnsafeMutablePointer<UInt8>(valuePointer)
     var bytes = [UInt8](count: totalBytes, repeatedValue: 0)
     var bytes = [UInt8](count: totalBytes, repeatedValue: 0)
     for j in 0..<min(sizeof(T),totalBytes) {
     for j in 0..<min(sizeof(T),totalBytes) {
         bytes[totalBytes - 1 - j] = (bytesPointer + j).memory
         bytes[totalBytes - 1 - j] = (bytesPointer + j).memory
@@ -99,12 +98,12 @@ func shiftLeft<T: SignedIntegerType where T: Initiable>(value: T, count: Int) ->
         return 0;
         return 0;
     }
     }
     
     
-    var bitsCount = (sizeofValue(value) * 8)
-    var shiftCount = Int(Swift.min(count, bitsCount - 1))
+    let bitsCount = (sizeofValue(value) * 8)
+    let shiftCount = Int(Swift.min(count, bitsCount - 1))
     
     
     var shiftedValue:T = 0;
     var shiftedValue:T = 0;
     for bitIdx in 0..<bitsCount {
     for bitIdx in 0..<bitsCount {
-        var bit = T(IntMax(1 << bitIdx))
+        let bit = T(IntMax(1 << bitIdx))
         if ((value & bit) == bit) {
         if ((value & bit) == bit) {
             shiftedValue = shiftedValue | T(bit << shiftCount)
             shiftedValue = shiftedValue | T(bit << shiftCount)
         }
         }
@@ -119,38 +118,38 @@ func shiftLeft<T: SignedIntegerType where T: Initiable>(value: T, count: Int) ->
 
 
 // for any f*** other Integer type - this part is so non-Generic
 // for any f*** other Integer type - this part is so non-Generic
 func shiftLeft(value: UInt, count: Int) -> UInt {
 func shiftLeft(value: UInt, count: Int) -> UInt {
-    return UInt(shiftLeft(Int(value), count))
+    return UInt(shiftLeft(Int(value), count: count)) //FIXME: count:
 }
 }
 
 
 func shiftLeft(value: UInt8, count: Int) -> UInt8 {
 func shiftLeft(value: UInt8, count: Int) -> UInt8 {
-    return UInt8(shiftLeft(UInt(value), count))
+    return UInt8(shiftLeft(UInt(value), count: count))
 }
 }
 
 
 func shiftLeft(value: UInt16, count: Int) -> UInt16 {
 func shiftLeft(value: UInt16, count: Int) -> UInt16 {
-    return UInt16(shiftLeft(UInt(value), count))
+    return UInt16(shiftLeft(UInt(value), count: count))
 }
 }
 
 
 func shiftLeft(value: UInt32, count: Int) -> UInt32 {
 func shiftLeft(value: UInt32, count: Int) -> UInt32 {
-    return UInt32(shiftLeft(UInt(value), count))
+    return UInt32(shiftLeft(UInt(value), count: count))
 }
 }
 
 
 func shiftLeft(value: UInt64, count: Int) -> UInt64 {
 func shiftLeft(value: UInt64, count: Int) -> UInt64 {
-    return UInt64(shiftLeft(UInt(value), count))
+    return UInt64(shiftLeft(UInt(value), count: count))
 }
 }
 
 
 func shiftLeft(value: Int8, count: Int) -> Int8 {
 func shiftLeft(value: Int8, count: Int) -> Int8 {
-    return Int8(shiftLeft(Int(value), count))
+    return Int8(shiftLeft(Int(value), count: count))
 }
 }
 
 
 func shiftLeft(value: Int16, count: Int) -> Int16 {
 func shiftLeft(value: Int16, count: Int) -> Int16 {
-    return Int16(shiftLeft(Int(value), count))
+    return Int16(shiftLeft(Int(value), count: count))
 }
 }
 
 
 func shiftLeft(value: Int32, count: Int) -> Int32 {
 func shiftLeft(value: Int32, count: Int) -> Int32 {
-    return Int32(shiftLeft(Int(value), count))
+    return Int32(shiftLeft(Int(value), count: count))
 }
 }
 
 
 func shiftLeft(value: Int64, count: Int) -> Int64 {
 func shiftLeft(value: Int64, count: Int) -> Int64 {
-    return Int64(shiftLeft(Int(value), count))
+    return Int64(shiftLeft(Int(value), count: count))
 }
 }
 
 

+ 5 - 5
CryptoSwift/HMAC.swift

@@ -28,7 +28,7 @@ final public class HMAC {
             }
             }
         }
         }
         
         
-        func calculateHash(# bytes:[UInt8]) -> [UInt8]? {
+        func calculateHash(bytes  bytes:[UInt8]) -> [UInt8]? {
             switch (self) {
             switch (self) {
             case .sha1:
             case .sha1:
                 return NSData.withBytes(bytes).sha1()?.arrayOfBytes()
                 return NSData.withBytes(bytes).sha1()?.arrayOfBytes()
@@ -56,7 +56,7 @@ final public class HMAC {
     var key:[UInt8]
     var key:[UInt8]
     let variant:Variant
     let variant:Variant
     
     
-    class internal func authenticate(# key: [UInt8], message: [UInt8], variant:HMAC.Variant = .md5) -> [UInt8]? {
+    class internal func authenticate(key  key: [UInt8], message: [UInt8], variant:HMAC.Variant = .md5) -> [UInt8]? {
         return HMAC(key, variant: variant)?.authenticate(message: message)
         return HMAC(key, variant: variant)?.authenticate(message: message)
     }
     }
 
 
@@ -77,13 +77,13 @@ final public class HMAC {
         }
         }
     }
     }
     
     
-    internal func authenticate(# message:[UInt8]) -> [UInt8]? {
+    internal func authenticate(message  message:[UInt8]) -> [UInt8]? {
         var opad = [UInt8](count: variant.blockSize(), repeatedValue: 0x5c)
         var opad = [UInt8](count: variant.blockSize(), repeatedValue: 0x5c)
-        for (idx, val) in enumerate(key) {
+        for (idx, _) in key.enumerate() {
             opad[idx] = key[idx] ^ opad[idx]
             opad[idx] = key[idx] ^ opad[idx]
         }
         }
         var ipad = [UInt8](count: variant.blockSize(), repeatedValue: 0x36)
         var ipad = [UInt8](count: variant.blockSize(), repeatedValue: 0x36)
-        for (idx, val) in enumerate(key) {
+        for (idx, _) in key.enumerate() {
             ipad[idx] = key[idx] ^ ipad[idx]
             ipad[idx] = key[idx] ^ ipad[idx]
         }
         }
 
 

+ 0 - 2
CryptoSwift/Hash.swift

@@ -30,8 +30,6 @@ public enum Hash {
             return SHA2(data, variant: .sha512).calculate64()
             return SHA2(data, variant: .sha512).calculate64()
         case crc32(let data):
         case crc32(let data):
             return CRC().crc32(data);
             return CRC().crc32(data);
-        default:
-            return nil
         }
         }
     }
     }
 }
 }

+ 4 - 4
CryptoSwift/HashBase.swift

@@ -10,7 +10,7 @@ import Foundation
 
 
 protocol _Hash {
 protocol _Hash {
     var size:Int { get }
     var size:Int { get }
-    func prepare(len:Int) -> NSMutableData;
+    func prepare(len:Int) -> NSMutableData
 }
 }
 
 
 internal class HashBase {
 internal class HashBase {
@@ -22,8 +22,8 @@ internal class HashBase {
     }
     }
     
     
     /** Common part for hash calculation. Prepare header data. */
     /** Common part for hash calculation. Prepare header data. */
-    internal func prepare(_ len:Int = 64) -> NSMutableData {
-        var tmpMessage: NSMutableData = NSMutableData(data: self.message)
+    internal func prepare(len:Int) -> NSMutableData {
+        let tmpMessage: NSMutableData = NSMutableData(data: self.message)
         
         
         // Step 1. Append Padding Bits
         // Step 1. Append Padding Bits
         tmpMessage.appendBytes([0x80]) // append one bit (UInt8 with one bit) to message
         tmpMessage.appendBytes([0x80]) // append one bit (UInt8 with one bit) to message
@@ -37,7 +37,7 @@ internal class HashBase {
             msgLength++
             msgLength++
         }
         }
       
       
-        var bufZeros = UnsafeMutablePointer<UInt8>(calloc(counter, sizeof(UInt8)))
+        let bufZeros = UnsafeMutablePointer<UInt8>(calloc(counter, sizeof(UInt8)))
       
       
         tmpMessage.appendBytes(bufZeros, length: counter)
         tmpMessage.appendBytes(bufZeros, length: counter)
       
       

+ 6 - 6
CryptoSwift/IntExtension.swift

@@ -26,7 +26,7 @@ extension Int {
 /* array of bytes */
 /* array of bytes */
 extension Int {
 extension Int {
     /** Array of bytes with optional padding (little-endian) */
     /** Array of bytes with optional padding (little-endian) */
-    public func bytes(_ totalBytes: Int = sizeof(Int)) -> [UInt8] {
+    public func bytes(totalBytes: Int = sizeof(Int)) -> [UInt8] {
         return arrayOfBytes(self, length: totalBytes)
         return arrayOfBytes(self, length: totalBytes)
     }
     }
 
 
@@ -47,7 +47,7 @@ extension Int {
     
     
     /** Shift bits to the left. All bits are shifted (including sign bit) */
     /** Shift bits to the left. All bits are shifted (including sign bit) */
     private mutating func shiftLeft(count: Int) -> Int {
     private mutating func shiftLeft(count: Int) -> Int {
-        self = CryptoSwift.shiftLeft(self, count)
+        self = CryptoSwift.shiftLeft(self, count: count) //FIXME: count:
         return self
         return self
     }
     }
     
     
@@ -57,19 +57,19 @@ extension Int {
             return self;
             return self;
         }
         }
         
         
-        var bitsCount = sizeofValue(self) * 8
+        let bitsCount = sizeofValue(self) * 8
 
 
         if (count >= bitsCount) {
         if (count >= bitsCount) {
             return 0
             return 0
         }
         }
 
 
-        var maxBitsForValue = Int(floor(log2(Double(self)) + 1))
-        var shiftCount = Swift.min(count, maxBitsForValue - 1)
+        let maxBitsForValue = Int(floor(log2(Double(self)) + 1))
+        let shiftCount = Swift.min(count, maxBitsForValue - 1)
         var shiftedValue:Int = 0;
         var shiftedValue:Int = 0;
         
         
         for bitIdx in 0..<bitsCount {
         for bitIdx in 0..<bitsCount {
             // if bit is set then copy to result and shift left 1
             // if bit is set then copy to result and shift left 1
-            var bit = 1 << bitIdx
+            let bit = 1 << bitIdx
             if ((self & bit) == bit) {
             if ((self & bit) == bit) {
                 shiftedValue = shiftedValue | (bit >> shiftCount)
                 shiftedValue = shiftedValue | (bit >> shiftCount)
             }
             }

+ 8 - 9
CryptoSwift/MD5.swift

@@ -8,7 +8,7 @@
 
 
 import Foundation
 import Foundation
 
 
-final class MD5 : CryptoSwift.HashBase, _Hash {
+final class MD5 : CryptoSwift.HashBase, _Hash  {
     var size:Int = 16 // 128 / 8
     var size:Int = 16 // 128 / 8
     
     
     /** specifies the per-round shift amounts */
     /** specifies the per-round shift amounts */
@@ -38,22 +38,21 @@ final class MD5 : CryptoSwift.HashBase, _Hash {
     private let h:[UInt32] = [0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476]
     private let h:[UInt32] = [0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476]
     
     
     func calculate() -> NSData {
     func calculate() -> NSData {
-        var tmpMessage = prepare()
+        let tmpMessage = prepare(64)
 
 
         // hash values
         // hash values
         var hh = h
         var hh = h
         
         
         // Step 2. Append Length a 64-bit representation of lengthInBits
         // Step 2. Append Length a 64-bit representation of lengthInBits
-        var lengthInBits = (message.length * 8)
-        var lengthBytes = lengthInBits.bytes(64 / 8)
-        tmpMessage.appendBytes(reverse(lengthBytes));
+        let lengthInBits = (message.length * 8)
+        let lengthBytes = lengthInBits.bytes(64 / 8)
+        tmpMessage.appendBytes(Array(lengthBytes.reverse())); //FIXME: Array?
 
 
         // Process the message in successive 512-bit chunks:
         // Process the message in successive 512-bit chunks:
         let chunkSizeBytes = 512 / 8 // 64
         let chunkSizeBytes = 512 / 8 // 64
         var leftMessageBytes = tmpMessage.length
         var leftMessageBytes = tmpMessage.length
         for (var i = 0; i < tmpMessage.length; i = i + chunkSizeBytes, leftMessageBytes -= chunkSizeBytes) {
         for (var i = 0; i < tmpMessage.length; i = i + chunkSizeBytes, leftMessageBytes -= chunkSizeBytes) {
             let chunk = tmpMessage.subdataWithRange(NSRange(location: i, length: min(chunkSizeBytes,leftMessageBytes)))
             let chunk = tmpMessage.subdataWithRange(NSRange(location: i, length: min(chunkSizeBytes,leftMessageBytes)))
-            let bytes = tmpMessage.bytes;
             
             
             // break chunk into sixteen 32-bit words M[j], 0 ≤ j ≤ 15
             // break chunk into sixteen 32-bit words M[j], 0 ≤ j ≤ 15
             var M:[UInt32] = [UInt32](count: 16, repeatedValue: 0)
             var M:[UInt32] = [UInt32](count: 16, repeatedValue: 0)
@@ -96,7 +95,7 @@ final class MD5 : CryptoSwift.HashBase, _Hash {
                 dTemp = D
                 dTemp = D
                 D = C
                 D = C
                 C = B
                 C = B
-                B = B &+ rotateLeft((A &+ F &+ k[j] &+ M[g]), s[j])
+                B = B &+ rotateLeft((A &+ F &+ k[j] &+ M[g]), n: s[j])
                 A = dTemp    
                 A = dTemp    
             }
             }
             
             
@@ -106,13 +105,13 @@ final class MD5 : CryptoSwift.HashBase, _Hash {
             hh[3] = hh[3] &+ D
             hh[3] = hh[3] &+ D
         }
         }
 
 
-        var buf: NSMutableData = NSMutableData();
+        let buf: NSMutableData = NSMutableData();
         hh.map({ (item) -> () in
         hh.map({ (item) -> () in
             var i:UInt32 = item.littleEndian
             var i:UInt32 = item.littleEndian
             buf.appendBytes(&i, length: sizeofValue(i))
             buf.appendBytes(&i, length: sizeofValue(i))
         })
         })
         
         
-        return buf.copy() as! NSData;
+        return buf.copy() as! NSData
     }
     }
 }
 }
 
 

+ 1 - 1
CryptoSwift/NSDataExtension.swift

@@ -25,7 +25,7 @@ extension NSData {
         var bytesArray = self.arrayOfBytes()
         var bytesArray = self.arrayOfBytes()
         
         
         for (var i = 0; i < bytesArray.count; i++) {
         for (var i = 0; i < bytesArray.count; i++) {
-            var b = bytesArray[i]
+            _ = bytesArray[i]
             s = s + UInt32(bytesArray[i])
             s = s + UInt32(bytesArray[i])
         }
         }
         s = s % 65536;
         s = s % 65536;

+ 5 - 5
CryptoSwift/PKCS7.swift

@@ -18,25 +18,25 @@ public struct PKCS7: Padding {
     }
     }
     
     
     public func add(bytes: [UInt8] , blockSize:Int) -> [UInt8] {
     public func add(bytes: [UInt8] , blockSize:Int) -> [UInt8] {
-        var padding = UInt8(blockSize - (bytes.count % blockSize))
+        let padding = UInt8(blockSize - (bytes.count % blockSize))
         var withPadding = bytes
         var withPadding = bytes
         if (padding == 0) {
         if (padding == 0) {
             // If the original data is a multiple of N bytes, then an extra block of bytes with value N is added.
             // If the original data is a multiple of N bytes, then an extra block of bytes with value N is added.
-            for i in 0..<blockSize {
+            for _ in 0..<blockSize {
                 withPadding.extend([UInt8(blockSize)])
                 withPadding.extend([UInt8(blockSize)])
             }
             }
         } else {
         } else {
             // The value of each added byte is the number of bytes that are added
             // The value of each added byte is the number of bytes that are added
-            for i in 0..<padding {
+            for _ in 0..<padding {
                 withPadding.extend([UInt8(padding)])
                 withPadding.extend([UInt8(padding)])
             }
             }
         }
         }
         return withPadding
         return withPadding
     }
     }
     
     
-    public func remove(bytes: [UInt8], blockSize:Int? = nil) -> [UInt8] {
+    public func remove(bytes: [UInt8], blockSize:Int?) -> [UInt8] {
         let lastByte = bytes.last!
         let lastByte = bytes.last!
-        var padding = Int(lastByte) // last byte
+        let padding = Int(lastByte) // last byte
         
         
         if padding >= 1 { //TODO: need test for that, what about empty padding
         if padding >= 1 { //TODO: need test for that, what about empty padding
             return Array(bytes[0..<(bytes.count - padding)])
             return Array(bytes[0..<(bytes.count - padding)])

+ 2 - 2
CryptoSwift/Padding.swift

@@ -9,6 +9,6 @@
 import Foundation
 import Foundation
 
 
 public protocol Padding {
 public protocol Padding {
-    func add(data: [UInt8], blockSize:Int) -> [UInt8];
-    func remove(data: [UInt8], blockSize:Int?) -> [UInt8];
+    func add(data: [UInt8], blockSize:Int) -> [UInt8]
+    func remove(data: [UInt8], blockSize:Int?) -> [UInt8]
 }
 }

+ 9 - 9
CryptoSwift/Poly1305.swift

@@ -83,12 +83,12 @@ final public class Poly1305 {
     Calculate Message Authentication Code (MAC) for message.
     Calculate Message Authentication Code (MAC) for message.
     Calculation context is discarder on instance deallocation.
     Calculation context is discarder on instance deallocation.
     
     
-    :param: key     256-bit key
-    :param: message Message
+    - parameter key:     256-bit key
+    - parameter message: Message
     
     
-    :returns: Message Authentication Code
+    - returns: Message Authentication Code
     */
     */
-    class internal func authenticate(# key: [UInt8], message: [UInt8]) -> [UInt8]? {
+    class internal func authenticate(key  key: [UInt8], message: [UInt8]) -> [UInt8]? {
         return Poly1305(key)?.authenticate(message: message)
         return Poly1305(key)?.authenticate(message: message)
     }
     }
     
     
@@ -101,7 +101,7 @@ final public class Poly1305 {
         }
         }
     }
     }
     
     
-    private func authenticate(# message:[UInt8]) -> [UInt8]? {
+    private func authenticate(message  message:[UInt8]) -> [UInt8]? {
         if let ctx = self.ctx {
         if let ctx = self.ctx {
             update(ctx, message: message)
             update(ctx, message: message)
             return finish(ctx)
             return finish(ctx)
@@ -112,9 +112,9 @@ final public class Poly1305 {
     /**
     /**
     Add message to be processed
     Add message to be processed
     
     
-    :param: context Context
-    :param: message message
-    :param: bytes   length of the message fragment to be processed
+    - parameter context: Context
+    - 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:[UInt8], bytes:Int? = nil) {
         var bytes = bytes ?? message.count
         var bytes = bytes ?? message.count
@@ -145,7 +145,7 @@ final public class Poly1305 {
         
         
         /* process full blocks */
         /* process full blocks */
         if (bytes >= blockSize) {
         if (bytes >= blockSize) {
-            var want = bytes & ~(blockSize - 1)
+            let want = bytes & ~(blockSize - 1)
             blocks(context, m: message, startPos: mPos)
             blocks(context, m: message, startPos: mPos)
             mPos += want
             mPos += want
             bytes -= want;
             bytes -= want;

+ 5 - 5
CryptoSwift/SHA1.swift

@@ -18,7 +18,7 @@ final class SHA1 : CryptoSwift.HashBase, _Hash {
     private let h:[UInt32] = [0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0]
     private let h:[UInt32] = [0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0]
         
         
     func calculate() -> NSData {
     func calculate() -> NSData {
-        var tmpMessage = self.prepare()
+        let tmpMessage = self.prepare(64)
         
         
         // hash values
         // hash values
         var hh = h
         var hh = h
@@ -42,7 +42,7 @@ final class SHA1 : CryptoSwift.HashBase, _Hash {
                     M[x] = le.bigEndian
                     M[x] = le.bigEndian
                     break
                     break
                 default:
                 default:
-                    M[x] = rotateLeft(M[x-3] ^ M[x-8] ^ M[x-14] ^ M[x-16], 1)
+                    M[x] = rotateLeft(M[x-3] ^ M[x-8] ^ M[x-14] ^ M[x-16], n: 1) //FIXME: n:
                     break
                     break
                 }
                 }
             }
             }
@@ -79,10 +79,10 @@ final class SHA1 : CryptoSwift.HashBase, _Hash {
                     break
                     break
                 }
                 }
                 
                 
-                var temp = (rotateLeft(A,5) &+ f &+ E &+ M[j] &+ k) & 0xffffffff
+                let temp = (rotateLeft(A,n: 5) &+ f &+ E &+ M[j] &+ k) & 0xffffffff
                 E = D
                 E = D
                 D = C
                 D = C
-                C = rotateLeft(B, 30)
+                C = rotateLeft(B, n: 30)
                 B = A
                 B = A
                 A = temp
                 A = temp
             }
             }
@@ -95,7 +95,7 @@ final class SHA1 : CryptoSwift.HashBase, _Hash {
         }
         }
         
         
         // Produce the final hash value (big-endian) as a 160 bit number:
         // Produce the final hash value (big-endian) as a 160 bit number:
-        var buf: NSMutableData = NSMutableData();
+        let buf: NSMutableData = NSMutableData();
         for item in hh {
         for item in hh {
             var i:UInt32 = item.bigEndian
             var i:UInt32 = item.bigEndian
             buf.appendBytes(&i, length: sizeofValue(i))
             buf.appendBytes(&i, length: sizeofValue(i))

+ 13 - 13
CryptoSwift/SHA2.swift

@@ -118,7 +118,7 @@ final class SHA2 : HashBase, _Hash {
     
     
     //FIXME: I can't do Generic func out of calculate32 and calculate64 (UInt32 vs UInt64), but if you can - please do pull request.
     //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() -> NSData {
     func calculate32() -> NSData {
-        var tmpMessage = self.prepare()
+        let tmpMessage = self.prepare(64)
         
         
         // hash values
         // hash values
         var hh = [UInt32]()
         var hh = [UInt32]()
@@ -145,8 +145,8 @@ final class SHA2 : HashBase, _Hash {
                     M[x] = le.bigEndian
                     M[x] = le.bigEndian
                     break
                     break
                 default:
                 default:
-                    let s0 = rotateRight(M[x-15], 7) ^ rotateRight(M[x-15], 18) ^ (M[x-15] >> 3)
-                    let s1 = rotateRight(M[x-2], 17) ^ rotateRight(M[x-2], 19) ^ (M[x-2] >> 10)
+                    let s0 = rotateRight(M[x-15], n: 7) ^ rotateRight(M[x-15], n: 18) ^ (M[x-15] >> 3) //FIXME: n
+                    let s1 = rotateRight(M[x-2], n: 17) ^ rotateRight(M[x-2], n: 19) ^ (M[x-2] >> 10)
                     M[x] = M[x-16] &+ s0 &+ M[x-7] &+ s1
                     M[x] = M[x-16] &+ s0 &+ M[x-7] &+ s1
                     break
                     break
                 }
                 }
@@ -163,10 +163,10 @@ final class SHA2 : HashBase, _Hash {
             
             
             // Main loop
             // Main loop
             for j in 0..<variant.k.count {
             for j in 0..<variant.k.count {
-                let s0 = rotateRight(A,2) ^ rotateRight(A,13) ^ rotateRight(A,22)
+                let s0 = rotateRight(A,n: 2) ^ rotateRight(A,n: 13) ^ rotateRight(A,n: 22)
                 let maj = (A & B) ^ (A & C) ^ (B & C)
                 let maj = (A & B) ^ (A & C) ^ (B & C)
                 let t2 = s0 &+ maj
                 let t2 = s0 &+ maj
-                let s1 = rotateRight(E,6) ^ rotateRight(E,11) ^ rotateRight(E,25)
+                let s1 = rotateRight(E,n: 6) ^ rotateRight(E,n: 11) ^ rotateRight(E,n: 25)
                 let ch = (E & F) ^ ((~E) & G)
                 let ch = (E & F) ^ ((~E) & G)
                 let t1 = H &+ s1 &+ ch &+ UInt32(variant.k[j]) &+ M[j]
                 let t1 = H &+ s1 &+ ch &+ UInt32(variant.k[j]) &+ M[j]
                 
                 
@@ -191,7 +191,7 @@ final class SHA2 : HashBase, _Hash {
         }
         }
         
         
         // Produce the final hash value (big-endian) as a 160 bit number:
         // Produce the final hash value (big-endian) as a 160 bit number:
-        var buf: NSMutableData = NSMutableData();
+        let buf: NSMutableData = NSMutableData();
         
         
         variant.resultingArray(hh).map({ (item) -> () in
         variant.resultingArray(hh).map({ (item) -> () in
             var i:UInt32 = UInt32(item.bigEndian)
             var i:UInt32 = UInt32(item.bigEndian)
@@ -202,7 +202,7 @@ final class SHA2 : HashBase, _Hash {
     }
     }
     
     
     func calculate64() -> NSData {
     func calculate64() -> NSData {
-        var tmpMessage = self.prepare(128)
+        let tmpMessage = self.prepare(128)
         
         
         // hash values
         // hash values
         var hh = [UInt64]()
         var hh = [UInt64]()
@@ -217,7 +217,7 @@ final class SHA2 : HashBase, _Hash {
         let chunkSizeBytes = 1024 / 8 // 128
         let chunkSizeBytes = 1024 / 8 // 128
         var leftMessageBytes = tmpMessage.length
         var leftMessageBytes = tmpMessage.length
         for var i = 0; i < tmpMessage.length; i = i + chunkSizeBytes, leftMessageBytes -= chunkSizeBytes {
         for var i = 0; i < tmpMessage.length; i = i + chunkSizeBytes, leftMessageBytes -= chunkSizeBytes {
-            var chunk = tmpMessage.subdataWithRange(NSRange(location: i, length: min(chunkSizeBytes,leftMessageBytes)))
+            let chunk = tmpMessage.subdataWithRange(NSRange(location: i, length: min(chunkSizeBytes,leftMessageBytes)))
             // break chunk into sixteen 64-bit words M[j], 0 ≤ j ≤ 15, big-endian
             // break chunk into sixteen 64-bit words M[j], 0 ≤ j ≤ 15, big-endian
             // Extend the sixteen 64-bit words into eighty 64-bit words:
             // Extend the sixteen 64-bit words into eighty 64-bit words:
             var M = [UInt64](count: variant.k.count, repeatedValue: 0)
             var M = [UInt64](count: variant.k.count, repeatedValue: 0)
@@ -229,8 +229,8 @@ final class SHA2 : HashBase, _Hash {
                     M[x] = le.bigEndian
                     M[x] = le.bigEndian
                     break
                     break
                 default:
                 default:
-                    let s0 = rotateRight(M[x-15], 1) ^ rotateRight(M[x-15], 8) ^ (M[x-15] >> 7)
-                    let s1 = rotateRight(M[x-2], 19) ^ rotateRight(M[x-2], 61) ^ (M[x-2] >> 6)
+                    let s0 = rotateRight(M[x-15], n: 1) ^ rotateRight(M[x-15], n: 8) ^ (M[x-15] >> 7)
+                    let s1 = rotateRight(M[x-2], n: 19) ^ rotateRight(M[x-2], n: 61) ^ (M[x-2] >> 6)
                     M[x] = M[x-16] &+ s0 &+ M[x-7] &+ s1
                     M[x] = M[x-16] &+ s0 &+ M[x-7] &+ s1
                     break
                     break
                 }
                 }
@@ -247,10 +247,10 @@ final class SHA2 : HashBase, _Hash {
             
             
             // Main loop
             // Main loop
             for j in 0..<variant.k.count {
             for j in 0..<variant.k.count {
-                let s0 = rotateRight(A,28) ^ rotateRight(A,34) ^ rotateRight(A,39)
+                let s0 = rotateRight(A,n: 28) ^ rotateRight(A,n: 34) ^ rotateRight(A,n: 39) //FIXME: n:
                 let maj = (A & B) ^ (A & C) ^ (B & C)
                 let maj = (A & B) ^ (A & C) ^ (B & C)
                 let t2 = s0 &+ maj
                 let t2 = s0 &+ maj
-                let s1 = rotateRight(E,14) ^ rotateRight(E,18) ^ rotateRight(E,41)
+                let s1 = rotateRight(E,n: 14) ^ rotateRight(E,n: 18) ^ rotateRight(E,n: 41)
                 let ch = (E & F) ^ ((~E) & G)
                 let ch = (E & F) ^ ((~E) & G)
                 let t1 = H &+ s1 &+ ch &+ variant.k[j] &+ UInt64(M[j])
                 let t1 = H &+ s1 &+ ch &+ variant.k[j] &+ UInt64(M[j])
                 
                 
@@ -275,7 +275,7 @@ final class SHA2 : HashBase, _Hash {
         }
         }
         
         
         // Produce the final hash value (big-endian)
         // Produce the final hash value (big-endian)
-        var buf: NSMutableData = NSMutableData();
+        let buf: NSMutableData = NSMutableData();
         
         
         variant.resultingArray(hh).map({ (item) -> () in
         variant.resultingArray(hh).map({ (item) -> () in
             var i = item.bigEndian
             var i = item.bigEndian

+ 4 - 4
CryptoSwift/UInt16Extension.swift

@@ -16,18 +16,18 @@ extension UInt16 {
             return self;
             return self;
         }
         }
 
 
-        var bitsCount = UInt16(sizeofValue(self) * 8)
+        let bitsCount = UInt16(sizeofValue(self) * 8)
 
 
         if (count >= bitsCount) {
         if (count >= bitsCount) {
             return 0
             return 0
         }
         }
 
 
-        var maxBitsForValue = UInt16(floor(log2(Double(self) + 1)))
-        var shiftCount = Swift.min(count, maxBitsForValue - 1)
+        let maxBitsForValue = UInt16(floor(log2(Double(self) + 1)))
+        let shiftCount = Swift.min(count, maxBitsForValue - 1)
         var shiftedValue:UInt16 = 0;
         var shiftedValue:UInt16 = 0;
         
         
         for bitIdx in 0..<bitsCount {
         for bitIdx in 0..<bitsCount {
-            var byte = 1 << bitIdx
+            let byte = 1 << bitIdx
             if ((self & byte) == byte) {
             if ((self & byte) == byte) {
                 shiftedValue = shiftedValue | (byte >> shiftCount)
                 shiftedValue = shiftedValue | (byte >> shiftCount)
             }
             }

+ 8 - 8
CryptoSwift/UInt32Extension.swift

@@ -10,7 +10,7 @@ import Foundation
 
 
 /** array of bytes */
 /** array of bytes */
 extension UInt32 {
 extension UInt32 {
-    public func bytes(_ totalBytes: Int = sizeof(UInt32)) -> [UInt8] {
+    public func bytes(totalBytes: Int = sizeof(UInt32)) -> [UInt8] {
         return arrayOfBytes(self, length: totalBytes)
         return arrayOfBytes(self, length: totalBytes)
     }
     }
 
 
@@ -33,13 +33,13 @@ extension UInt32 {
             return self;
             return self;
         }
         }
         
         
-        var bitsCount = UInt32(sizeof(UInt32) * 8)
-        var shiftCount = Swift.min(count, bitsCount - 1)
+        let bitsCount = UInt32(sizeof(UInt32) * 8)
+        let shiftCount = Swift.min(count, bitsCount - 1)
         var shiftedValue:UInt32 = 0;
         var shiftedValue:UInt32 = 0;
         
         
         for bitIdx in 0..<bitsCount {
         for bitIdx in 0..<bitsCount {
             // if bit is set then copy to result and shift left 1
             // if bit is set then copy to result and shift left 1
-            var bit = 1 << bitIdx
+            let bit = 1 << bitIdx
             if ((self & bit) == bit) {
             if ((self & bit) == bit) {
                 shiftedValue = shiftedValue | (bit << shiftCount)
                 shiftedValue = shiftedValue | (bit << shiftCount)
             }
             }
@@ -60,19 +60,19 @@ extension UInt32 {
             return self;
             return self;
         }
         }
         
         
-        var bitsCount = UInt32(sizeofValue(self) * 8)
+        let bitsCount = UInt32(sizeofValue(self) * 8)
 
 
         if (count >= bitsCount) {
         if (count >= bitsCount) {
             return 0
             return 0
         }
         }
 
 
-        var maxBitsForValue = UInt32(floor(log2(Double(self)) + 1))
-        var shiftCount = Swift.min(count, maxBitsForValue - 1)
+        let maxBitsForValue = UInt32(floor(log2(Double(self)) + 1))
+        let shiftCount = Swift.min(count, maxBitsForValue - 1)
         var shiftedValue:UInt32 = 0;
         var shiftedValue:UInt32 = 0;
         
         
         for bitIdx in 0..<bitsCount {
         for bitIdx in 0..<bitsCount {
             // if bit is set then copy to result and shift left 1
             // if bit is set then copy to result and shift left 1
-            var bit = 1 << bitIdx
+            let bit = 1 << bitIdx
             if ((self & bit) == bit) {
             if ((self & bit) == bit) {
                 shiftedValue = shiftedValue | (bit >> shiftCount)
                 shiftedValue = shiftedValue | (bit >> shiftCount)
             }
             }

+ 1 - 1
CryptoSwift/UInt64Extension.swift

@@ -10,7 +10,7 @@ import Foundation
 
 
 /** array of bytes */
 /** array of bytes */
 extension UInt64 {
 extension UInt64 {
-    public func bytes(_ totalBytes: Int = sizeof(UInt64)) -> [UInt8] {
+    public func bytes(totalBytes: Int = sizeof(UInt64)) -> [UInt8] {
         return arrayOfBytes(self, length: totalBytes)
         return arrayOfBytes(self, length: totalBytes)
     }
     }
 
 

+ 5 - 5
CryptoSwift/UInt8Extension.swift

@@ -56,7 +56,7 @@ extension UInt8 {
     func bits() -> String {
     func bits() -> String {
         var s = String()
         var s = String()
         let arr:[Bit] = self.bits()
         let arr:[Bit] = self.bits()
-        for (idx,b) in enumerate(arr) {
+        for (idx,b) in arr.enumerate() {
             s += (b == Bit.One ? "1" : "0")
             s += (b == Bit.One ? "1" : "0")
             if ((idx + 1) % 8 == 0) { s += " " }
             if ((idx + 1) % 8 == 0) { s += " " }
         }
         }
@@ -72,18 +72,18 @@ extension UInt8 {
             return self;
             return self;
         }
         }
 
 
-        var bitsCount = UInt8(sizeof(UInt8) * 8)
+        let bitsCount = UInt8(sizeof(UInt8) * 8)
 
 
         if (count >= bitsCount) {
         if (count >= bitsCount) {
             return 0
             return 0
         }
         }
 
 
-        var maxBitsForValue = UInt8(floor(log2(Double(self) + 1)))
-        var shiftCount = Swift.min(count, maxBitsForValue - 1)
+        let maxBitsForValue = UInt8(floor(log2(Double(self) + 1)))
+        let shiftCount = Swift.min(count, maxBitsForValue - 1)
         var shiftedValue:UInt8 = 0;
         var shiftedValue:UInt8 = 0;
         
         
         for bitIdx in 0..<bitsCount {
         for bitIdx in 0..<bitsCount {
-            var byte = 1 << bitIdx
+            let byte = 1 << bitIdx
             if ((self & byte) == byte) {
             if ((self & byte) == byte) {
                 shiftedValue = shiftedValue | (byte >> shiftCount)
                 shiftedValue = shiftedValue | (byte >> shiftCount)
             }
             }

+ 3 - 3
CryptoSwift/Utils.swift

@@ -41,8 +41,8 @@ func reverseBytes(value: UInt32) -> UInt32 {
     // return = ((value & 0x000000FF) << 24) | ((value & 0x0000FF00) << 8) | ((value & 0x00FF0000) >> 8)  | ((value & 0xFF000000) >> 24);
     // return = ((value & 0x000000FF) << 24) | ((value & 0x0000FF00) << 8) | ((value & 0x00FF0000) >> 8)  | ((value & 0xFF000000) >> 24);
     
     
     // workaround
     // workaround
-    var tmp1 = ((value & 0x000000FF) << 24) | ((value & 0x0000FF00) << 8)
-    var tmp2 = ((value & 0x00FF0000) >> 8)  | ((value & 0xFF000000) >> 24)
+    let tmp1 = ((value & 0x000000FF) << 24) | ((value & 0x0000FF00) << 8)
+    let tmp2 = ((value & 0x00FF0000) >> 8)  | ((value & 0xFF000000) >> 24)
     return tmp1 | tmp2
     return tmp1 | tmp2
 }
 }
 
 
@@ -62,5 +62,5 @@ func perf(text: String, closure: () -> ()) {
     let measurementStop = NSDate();
     let measurementStop = NSDate();
     let executionTime = measurementStop.timeIntervalSinceDate(measurementStart)
     let executionTime = measurementStop.timeIntervalSinceDate(measurementStart)
     
     
-    println("\(text) \(executionTime)");
+    print("\(text) \(executionTime)");
 }
 }

+ 10 - 10
CryptoSwiftTests/AESTests.swift

@@ -99,9 +99,9 @@ final class AESTests: XCTestCase {
         
         
         var substituted = input
         var substituted = input
         AES(key: aesKey, blockMode: .CBC)!.subBytes(&substituted)
         AES(key: aesKey, blockMode: .CBC)!.subBytes(&substituted)
-        XCTAssertTrue(compareMatrix(expected, substituted), "subBytes failed")
+        XCTAssertTrue(compareMatrix(expected, b: substituted), "subBytes failed")
         let inverted = AES(key: aesKey, blockMode: .CBC)!.invSubBytes(substituted)
         let inverted = AES(key: aesKey, blockMode: .CBC)!.invSubBytes(substituted)
-        XCTAssertTrue(compareMatrix(input, inverted), "invSubBytes failed")
+        XCTAssertTrue(compareMatrix(input, b: inverted), "invSubBytes failed")
     }
     }
     
     
     func testAES_shiftRows() {
     func testAES_shiftRows() {
@@ -116,9 +116,9 @@ final class AESTests: XCTestCase {
             [0x8c, 0x4, 0x51, 0xe7]]
             [0x8c, 0x4, 0x51, 0xe7]]
         
         
         let shifted = AES(key: aesKey, blockMode: .CBC)!.shiftRows(input)
         let shifted = AES(key: aesKey, blockMode: .CBC)!.shiftRows(input)
-        XCTAssertTrue(compareMatrix(expected, shifted), "shiftRows failed")
+        XCTAssertTrue(compareMatrix(expected, b: shifted), "shiftRows failed")
         let inverted = AES(key: aesKey, blockMode: .CBC)!.invShiftRows(shifted)
         let inverted = AES(key: aesKey, blockMode: .CBC)!.invShiftRows(shifted)
-        XCTAssertTrue(compareMatrix(input, inverted), "invShiftRows failed")
+        XCTAssertTrue(compareMatrix(input, b: inverted), "invShiftRows failed")
     }
     }
     
     
     func testAES_multiply() {
     func testAES_multiply() {
@@ -148,7 +148,7 @@ final class AESTests: XCTestCase {
         
         
         if let aes = AES(key: aesKey, blockMode: .CBC) {
         if let aes = AES(key: aesKey, blockMode: .CBC) {
             let result = aes.addRoundKey(input, aes.expandedKey, 0)
             let result = aes.addRoundKey(input, aes.expandedKey, 0)
-            XCTAssertTrue(compareMatrix(expected, result), "addRoundKey failed")
+            XCTAssertTrue(compareMatrix(expected, b: result), "addRoundKey failed")
         } else {
         } else {
             XCTAssert(false, "")
             XCTAssert(false, "")
         }
         }
@@ -167,9 +167,9 @@ final class AESTests: XCTestCase {
         
         
         if let aes = AES(key: aesKey, blockMode: .CBC) {
         if let aes = AES(key: aesKey, blockMode: .CBC) {
             let mixed = aes.mixColumns(input)
             let mixed = aes.mixColumns(input)
-            XCTAssertTrue(compareMatrix(expected, mixed), "mixColumns failed")
+            XCTAssertTrue(compareMatrix(expected, b: mixed), "mixColumns failed")
             let inverted = aes.invMixColumns(mixed)
             let inverted = aes.invMixColumns(mixed)
-            XCTAssertTrue(compareMatrix(input, inverted), "invMixColumns failed")
+            XCTAssertTrue(compareMatrix(input, b: inverted), "invMixColumns failed")
         } else {
         } else {
             XCTAssert(false, "")
             XCTAssert(false, "")
         }
         }
@@ -180,7 +180,7 @@ final class AESTests: XCTestCase {
         let iv:[UInt8] = [0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F]
         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 message = [UInt8](count: 1024 * 1024, repeatedValue: 7)
         measureMetrics([XCTPerformanceMetric_WallClockTime], automaticallyStartMeasuring: true, forBlock: { () -> Void in
         measureMetrics([XCTPerformanceMetric_WallClockTime], automaticallyStartMeasuring: true, forBlock: { () -> Void in
-            let encrypted = AES(key: key, iv: iv, blockMode: .CBC)?.encrypt(message, padding: PKCS7())
+            AES(key: key, iv: iv, blockMode: .CBC)?.encrypt(message, padding: PKCS7())
         })
         })
     }
     }
     
     
@@ -200,14 +200,14 @@ final class AESTests: XCTestCase {
             let dataBytes     = UnsafePointer<Void>(data.bytes)
             let dataBytes     = UnsafePointer<Void>(data.bytes)
             
             
             let cryptData    = NSMutableData(length: Int(dataLength) + kCCBlockSizeAES128)
             let cryptData    = NSMutableData(length: Int(dataLength) + kCCBlockSizeAES128)
-            var cryptPointer = UnsafeMutablePointer<Void>(cryptData!.mutableBytes)
+            let cryptPointer = UnsafeMutablePointer<Void>(cryptData!.mutableBytes)
             let cryptLength  = cryptData!.length
             let cryptLength  = cryptData!.length
             
             
             var numBytesEncrypted:Int = 0
             var numBytesEncrypted:Int = 0
             
             
             self.startMeasuring()
             self.startMeasuring()
             
             
-            var cryptStatus = CCCrypt(
+            CCCrypt(
                 UInt32(kCCEncrypt),
                 UInt32(kCCEncrypt),
                 UInt32(kCCAlgorithmAES128),
                 UInt32(kCCAlgorithmAES128),
                 UInt32(kCCOptionPKCS7Padding),
                 UInt32(kCCOptionPKCS7Padding),

+ 3 - 3
CryptoSwiftTests/ChaCha20Tests.swift

@@ -48,13 +48,13 @@ final class ChaCha20Tests: XCTestCase {
         for (var idx = 0; idx < keys.count; idx++) {
         for (var idx = 0; idx < keys.count; idx++) {
             
             
             let expectedHex = expectedHexes[idx]
             let expectedHex = expectedHexes[idx]
-            let message = [UInt8](count: (count(expectedHex) / 2), repeatedValue: 0)
+            let message = [UInt8](count: (expectedHex.characters.count / 2), repeatedValue: 0)
             
             
             let setup = (key: keys[idx], iv: ivs[idx])
             let setup = (key: keys[idx], iv: ivs[idx])
-            var encrypted = Cipher.ChaCha20(setup).encrypt(message)
+            let encrypted = Cipher.ChaCha20(setup).encrypt(message)
             XCTAssert(encrypted != nil, "missing")
             XCTAssert(encrypted != nil, "missing")
             if let encrypted = encrypted {
             if let encrypted = encrypted {
-                var decrypted = Cipher.ChaCha20(setup).decrypt(encrypted)
+                let decrypted = Cipher.ChaCha20(setup).decrypt(encrypted)
                 XCTAssert(decrypted != nil, "missing")
                 XCTAssert(decrypted != nil, "missing")
                 if let decrypted = decrypted {
                 if let decrypted = decrypted {
                     XCTAssertEqual(message, decrypted, "ChaCha20 decryption failed");
                     XCTAssertEqual(message, decrypted, "ChaCha20 decryption failed");

+ 5 - 5
CryptoSwiftTests/ExtensionsTest.swift

@@ -24,7 +24,7 @@ final class ExtensionsTest: XCTestCase {
         measureMetrics([XCTPerformanceMetric_WallClockTime], automaticallyStartMeasuring: false, forBlock: { () -> Void in
         measureMetrics([XCTPerformanceMetric_WallClockTime], automaticallyStartMeasuring: false, forBlock: { () -> Void in
             let message = [UInt8](count: 1024 * 1024, repeatedValue: 7)
             let message = [UInt8](count: 1024 * 1024, repeatedValue: 7)
             self.startMeasuring()
             self.startMeasuring()
-            let blocks = message.chunks(AES.blockSize)
+            message.chunks(AES.blockSize)
             self.stopMeasuring()
             self.stopMeasuring()
         })
         })
     }
     }
@@ -39,7 +39,7 @@ final class ExtensionsTest: XCTestCase {
         
         
         let i2:Int = 1024
         let i2:Int = 1024
         let i2Array = i2.bytes(160 / 8) // 160 bit
         let i2Array = i2.bytes(160 / 8) // 160 bit
-        let i2recovered = Int.withBytes(i1Array)
+        let i2recovered = Int.withBytes(i2Array)
         
         
         XCTAssertEqual(i2, i2recovered, "Bytes conversion failed")
         XCTAssertEqual(i2, i2recovered, "Bytes conversion failed")
     }
     }
@@ -59,20 +59,20 @@ final class ExtensionsTest: XCTestCase {
     
     
     func testShiftLeft() {
     func testShiftLeft() {
         // Unsigned
         // Unsigned
-        var i:UInt32 = 1
+        let i:UInt32 = 1
         XCTAssert(i &<< 1 == 2, "shift left failed")
         XCTAssert(i &<< 1 == 2, "shift left failed")
         XCTAssert(i &<< 8 == 256, "shift left failed")
         XCTAssert(i &<< 8 == 256, "shift left failed")
         XCTAssert(i &<< 31 == i << 31, "shift left failed")
         XCTAssert(i &<< 31 == i << 31, "shift left failed")
         XCTAssert(i &<< 32 == 0, "shift left failed")
         XCTAssert(i &<< 32 == 0, "shift left failed")
 
 
         // Signed
         // Signed
-        var ii:Int = 21
+        let ii:Int = 21
         XCTAssert(ii &<< 1 == ii << 1, "shift left failed")
         XCTAssert(ii &<< 1 == ii << 1, "shift left failed")
         XCTAssert(ii &<< 8 == ii << 8, "shift left failed")
         XCTAssert(ii &<< 8 == ii << 8, "shift left failed")
         XCTAssert(ii &<< ((sizeofValue(ii) * 8) - 1) == ii << ((sizeofValue(ii) * 8) - 1), "shift left failed")
         XCTAssert(ii &<< ((sizeofValue(ii) * 8) - 1) == ii << ((sizeofValue(ii) * 8) - 1), "shift left failed")
         XCTAssert(ii &<< ((sizeofValue(ii) * 8)) == 0, "shift left failed")
         XCTAssert(ii &<< ((sizeofValue(ii) * 8)) == 0, "shift left failed")
         
         
-        var iii:UInt32 = 21
+        let iii:UInt32 = 21
         XCTAssert(iii &<< 1 == iii << 1, "shift left failed")
         XCTAssert(iii &<< 1 == iii << 1, "shift left failed")
         XCTAssert(iii &<< 8 == iii << 8, "shift left failed")
         XCTAssert(iii &<< 8 == iii << 8, "shift left failed")
         XCTAssert((iii &<< 32) == 0, "shift left failed")
         XCTAssert((iii &<< 32) == 0, "shift left failed")

+ 10 - 10
CryptoSwiftTests/HashTests.swift

@@ -27,8 +27,8 @@ final class CryptoSwiftTests: XCTestCase {
             XCTAssert(false, "Missing result")
             XCTAssert(false, "Missing result")
         }
         }
         
         
-        var string:NSString = ""
-        var data:NSData = string.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)!
+        let string:NSString = ""
+        let data:NSData = string.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)!
         if let hashData = Hash.md5(data).calculate() {
         if let hashData = Hash.md5(data).calculate() {
             XCTAssertEqual(hashData.hexString, "D41D8CD98F00B204E9800998ECF8427E", "MD5 calculation failed")
             XCTAssertEqual(hashData.hexString, "D41D8CD98F00B204E9800998ECF8427E", "MD5 calculation failed")
         } else {
         } else {
@@ -91,9 +91,9 @@ final class CryptoSwiftTests: XCTestCase {
             let buf = UnsafeMutablePointer<UInt8>(calloc(2048, sizeof(UInt8)))
             let buf = UnsafeMutablePointer<UInt8>(calloc(2048, sizeof(UInt8)))
             let data = NSData(bytes: buf, length: 2048)
             let data = NSData(bytes: buf, length: 2048)
             self.startMeasuring()
             self.startMeasuring()
-            var outbuf = UnsafeMutablePointer<UInt8>.alloc(Int(CC_MD5_DIGEST_LENGTH))
+            let outbuf = UnsafeMutablePointer<UInt8>.alloc(Int(CC_MD5_DIGEST_LENGTH))
             CC_MD5(data.bytes, CC_LONG(data.length), outbuf)
             CC_MD5(data.bytes, CC_LONG(data.length), outbuf)
-            let output = NSData(bytes: outbuf, length: Int(CC_MD5_DIGEST_LENGTH));
+            //let output = NSData(bytes: outbuf, length: Int(CC_MD5_DIGEST_LENGTH));
             outbuf.dealloc(Int(CC_MD5_DIGEST_LENGTH))
             outbuf.dealloc(Int(CC_MD5_DIGEST_LENGTH))
             outbuf.destroy()
             outbuf.destroy()
             self.stopMeasuring()
             self.stopMeasuring()
@@ -103,7 +103,7 @@ final class CryptoSwiftTests: XCTestCase {
     }
     }
     
     
     func testSHA1() {
     func testSHA1() {
-        var data:NSData = NSData(bytes: [0x31, 0x32, 0x33] as [UInt8], length: 3)
+        let data:NSData = NSData(bytes: [0x31, 0x32, 0x33] as [UInt8], length: 3)
         if let hash = data.sha1() {
         if let hash = data.sha1() {
             XCTAssertEqual(hash.hexString, "40BD001563085FC35165329EA1FF5C5ECBDBBEEF", "SHA1 calculation failed");
             XCTAssertEqual(hash.hexString, "40BD001563085FC35165329EA1FF5C5ECBDBBEEF", "SHA1 calculation failed");
         }
         }
@@ -125,14 +125,14 @@ final class CryptoSwiftTests: XCTestCase {
     }
     }
     
     
     func testSHA224() {
     func testSHA224() {
-        var data:NSData = NSData(bytes: [0x31, 0x32, 0x33] as [UInt8], length: 3)
+        let data:NSData = NSData(bytes: [0x31, 0x32, 0x33] as [UInt8], length: 3)
         if let hash = data.sha224() {
         if let hash = data.sha224() {
             XCTAssertEqual(hash.hexString, "78D8045D684ABD2EECE923758F3CD781489DF3A48E1278982466017F", "SHA224 calculation failed");
             XCTAssertEqual(hash.hexString, "78D8045D684ABD2EECE923758F3CD781489DF3A48E1278982466017F", "SHA224 calculation failed");
         }
         }
     }
     }
 
 
     func testSHA256() {
     func testSHA256() {
-        var data:NSData = NSData(bytes: [0x31, 0x32, 0x33] as [UInt8], length: 3)
+        let data:NSData = NSData(bytes: [0x31, 0x32, 0x33] as [UInt8], length: 3)
         if let hash = data.sha256() {
         if let hash = data.sha256() {
             XCTAssertEqual(hash.hexString, "A665A45920422F9D417E4867EFDC4FB8A04A1F3FFF1FA07E998E86F7F7A27AE3", "SHA256 calculation failed");
             XCTAssertEqual(hash.hexString, "A665A45920422F9D417E4867EFDC4FB8A04A1F3FFF1FA07E998E86F7F7A27AE3", "SHA256 calculation failed");
         }
         }
@@ -150,7 +150,7 @@ final class CryptoSwiftTests: XCTestCase {
     }
     }
 
 
     func testSHA384() {
     func testSHA384() {
-        var data:NSData = NSData(bytes: [49, 50, 51] as [UInt8], length: 3)
+        let data:NSData = NSData(bytes: [49, 50, 51] as [UInt8], length: 3)
         if let hash = data.sha384() {
         if let hash = data.sha384() {
             XCTAssertEqual(hash.hexString, "9A0A82F0C0CF31470D7AFFEDE3406CC9AA8410671520B727044EDA15B4C25532A9B5CD8AAF9CEC4919D76255B6BFB00F", "SHA384 calculation failed");
             XCTAssertEqual(hash.hexString, "9A0A82F0C0CF31470D7AFFEDE3406CC9AA8410671520B727044EDA15B4C25532A9B5CD8AAF9CEC4919D76255B6BFB00F", "SHA384 calculation failed");
         }
         }
@@ -167,7 +167,7 @@ final class CryptoSwiftTests: XCTestCase {
     }
     }
 
 
     func testSHA512() {
     func testSHA512() {
-        var data:NSData = NSData(bytes: [49, 50, 51] as [UInt8], length: 3)
+        let data:NSData = NSData(bytes: [49, 50, 51] as [UInt8], length: 3)
         if let hash = data.sha512() {
         if let hash = data.sha512() {
             XCTAssertEqual(hash.hexString, "3C9909AFEC25354D551DAE21590BB26E38D53F2173B8D3DC3EEE4C047E7AB1C1EB8B85103E3BE7BA613B31BB5C9C36214DC9F14A42FD7A2FDB84856BCA5C44C2", "SHA512 calculation failed");
             XCTAssertEqual(hash.hexString, "3C9909AFEC25354D551DAE21590BB26E38D53F2173B8D3DC3EEE4C047E7AB1C1EB8B85103E3BE7BA613B31BB5C9C36214DC9F14A42FD7A2FDB84856BCA5C44C2", "SHA512 calculation failed");
         }
         }
@@ -184,7 +184,7 @@ final class CryptoSwiftTests: XCTestCase {
     }
     }
     
     
     func testCRC32() {
     func testCRC32() {
-        var data:NSData = NSData(bytes: [49, 50, 51] as [UInt8], length: 3)
+        let data:NSData = NSData(bytes: [49, 50, 51] as [UInt8], length: 3)
         if let crc = data.crc32() {
         if let crc = data.crc32() {
             XCTAssertEqual(crc.hexString, "884863D2", "CRC32 calculation failed");
             XCTAssertEqual(crc.hexString, "884863D2", "CRC32 calculation failed");
         }
         }

+ 3 - 3
CryptoSwiftTests/Helpers.swift

@@ -9,10 +9,10 @@
 import Foundation
 import Foundation
 
 
 func compareMatrix(a:[[UInt8]], b:[[UInt8]]) -> Bool {
 func compareMatrix(a:[[UInt8]], b:[[UInt8]]) -> Bool {
-    for (i,arr) in enumerate(a) {
-        for (j,val) in enumerate(arr) {
+    for (i,arr) in a.enumerate() {
+        for (j,val) in arr.enumerate() {
             if (val != b[i][j]) {
             if (val != b[i][j]) {
-                println("Not equal: \(val) vs \(b[i][j])")
+                print("Not equal: \(val) vs \(b[i][j])") //FIXME: remove verbose
                 return false
                 return false
             }
             }
         }
         }

+ 3 - 3
CryptoSwiftTests/PaddingTests.swift

@@ -16,7 +16,7 @@ final class PaddingTests: XCTestCase {
         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 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 padded = PKCS7().add(input, blockSize: 16)
         let padded = PKCS7().add(input, blockSize: 16)
         XCTAssertEqual(padded, expected, "PKCS7 failed")
         XCTAssertEqual(padded, expected, "PKCS7 failed")
-        let clean = PKCS7().remove(padded)
+        let clean = PKCS7().remove(padded, blockSize: nil)
         XCTAssertEqual(clean, input, "PKCS7 failed")
         XCTAssertEqual(clean, input, "PKCS7 failed")
     }
     }
     
     
@@ -25,7 +25,7 @@ final class PaddingTests: XCTestCase {
         let expected:[UInt8] = [1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,1]
         let expected:[UInt8] = [1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,1]
         let padded = PKCS7().add(input, blockSize: 16)
         let padded = PKCS7().add(input, blockSize: 16)
         XCTAssertEqual(padded, expected, "PKCS7 failed")
         XCTAssertEqual(padded, expected, "PKCS7 failed")
-        let clean = PKCS7().remove(padded)
+        let clean = PKCS7().remove(padded, blockSize: nil)
         XCTAssertEqual(clean, input, "PKCS7 failed")
         XCTAssertEqual(clean, input, "PKCS7 failed")
     }
     }
     
     
@@ -34,7 +34,7 @@ final class PaddingTests: XCTestCase {
         let expected:[UInt8] = [1,2,3,4,5,6,7,8,9,0,1,2,3,4,2,2]
         let expected:[UInt8] = [1,2,3,4,5,6,7,8,9,0,1,2,3,4,2,2]
         let padded = PKCS7().add(input, blockSize: 16)
         let padded = PKCS7().add(input, blockSize: 16)
         XCTAssertEqual(padded, expected, "PKCS7 failed")
         XCTAssertEqual(padded, expected, "PKCS7 failed")
-        let clean = PKCS7().remove(padded)
+        let clean = PKCS7().remove(padded, blockSize: nil)
         XCTAssertEqual(clean, input, "PKCS7 failed")
         XCTAssertEqual(clean, input, "PKCS7 failed")
     }
     }
 }
 }