Эх сурвалжийг харах

Change type Byte to Uint8 (removed in Swift 1.2) #26. ChaCha20 public. Playground cleanup.

Marcin Krzyżanowski 10 жил өмнө
parent
commit
0d68706c13

+ 4 - 4
CryptoSwift.xcodeproj/project.pbxproj

@@ -37,7 +37,7 @@
 		758C764119B61AE500653BC6 /* Generics.swift in Sources */ = {isa = PBXBuildFile; fileRef = 758C764019B61AE500653BC6 /* Generics.swift */; };
 		758C764319B61DE900653BC6 /* UInt16Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 758C764219B61DE900653BC6 /* UInt16Extension.swift */; };
 		758F3F761992E57D0014BBDA /* Playground in Resources */ = {isa = PBXBuildFile; fileRef = 758F3F751992E57D0014BBDA /* Playground */; };
-		758F3F781992F6CE0014BBDA /* ByteExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 758F3F771992F6CE0014BBDA /* ByteExtension.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 */; };
 		75A74B271A1FF6B2004419F1 /* AES.swift in Sources */ = {isa = PBXBuildFile; fileRef = 75A74B261A1FF6B2004419F1 /* AES.swift */; };
@@ -148,7 +148,7 @@
 		758C764019B61AE500653BC6 /* Generics.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Generics.swift; sourceTree = "<group>"; };
 		758C764219B61DE900653BC6 /* UInt16Extension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UInt16Extension.swift; sourceTree = "<group>"; };
 		758F3F751992E57D0014BBDA /* Playground */ = {isa = PBXFileReference; lastKnownFileType = folder; name = Playground; path = CryptoSwift/Playground; sourceTree = "<group>"; };
-		758F3F771992F6CE0014BBDA /* ByteExtension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ByteExtension.swift; sourceTree = "<group>"; };
+		758F3F771992F6CE0014BBDA /* UInt8Extension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UInt8Extension.swift; sourceTree = "<group>"; };
 		7599C9C5199EA28700A3988B /* StringExtension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StringExtension.swift; sourceTree = "<group>"; };
 		759D481019B517BC005FF7FC /* BitExtension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BitExtension.swift; sourceTree = "<group>"; };
 		75A74B261A1FF6B2004419F1 /* AES.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AES.swift; sourceTree = "<group>"; };
@@ -227,7 +227,7 @@
 				75A74B261A1FF6B2004419F1 /* AES.swift */,
 				757DA24E1A4E59F2002BA3EF /* PKCS7.swift */,
 				759D481019B517BC005FF7FC /* BitExtension.swift */,
-				758F3F771992F6CE0014BBDA /* ByteExtension.swift */,
+				758F3F771992F6CE0014BBDA /* UInt8Extension.swift */,
 				7547195019931802002FA5F1 /* IntExtension.swift */,
 				758C764219B61DE900653BC6 /* UInt16Extension.swift */,
 				75D94E2519B60C4F007CB2A4 /* UInt32Extension.swift */,
@@ -418,7 +418,7 @@
 				757DA24F1A4E59F2002BA3EF /* PKCS7.swift in Sources */,
 				754DD76E19A149AF00E52288 /* CryptoHashBase.swift in Sources */,
 				758C764119B61AE500653BC6 /* Generics.swift in Sources */,
-				758F3F781992F6CE0014BBDA /* ByteExtension.swift in Sources */,
+				758F3F781992F6CE0014BBDA /* UInt8Extension.swift in Sources */,
 				75153D4219AA3C7900750381 /* SHA2.swift in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;

+ 31 - 31
CryptoSwift/AES.swift

@@ -30,7 +30,7 @@ public class AES {
     private let key:NSData
     private let iv:NSData?
     
-    private let sBox:[Byte] = [
+    private let sBox:[UInt8] = [
         0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76, 
         0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0, 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 
         0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15, 
@@ -48,7 +48,7 @@ public class AES {
         0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf, 
         0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16]
     
-    private let invSBox:[Byte] = [
+    private let invSBox:[UInt8] = [
         0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3,
         0x9e, 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f,
         0xff, 0x87, 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54,
@@ -75,7 +75,7 @@ public class AES {
         0x21, 0x0c, 0x7d]
     
     // Parameters for Linear Congruence Generators
-    private let Rcon:[Byte] = [
+    private let Rcon:[UInt8] = [
         0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a,
         0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39,
         0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
@@ -156,10 +156,10 @@ public class AES {
         return out == nil ? nil : NSData.withBytes(out!)
     }
     
-    private func encryptBlock(block:[Byte]) -> [Byte] {
+    private func encryptBlock(block:[UInt8]) -> [UInt8] {
         let expandedKey = expandKey()
         
-        var state:[[Byte]] = [[Byte]](count: variant.Nb, repeatedValue: [Byte](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) {
                 state[j][i] = block[i * row.count + j]
@@ -179,7 +179,7 @@ public class AES {
         state = shiftRows(state)
         state = addRoundKey(state, expandedKey, variant.Nr)
         
-        var out:[Byte] = [Byte]()
+        var out:[UInt8] = [UInt8]()
         for i in 0..<state.count {
             for j in 0..<state[0].count {
                 out.append(state[j][i])
@@ -197,7 +197,7 @@ public class AES {
         }
         
         let blocks = message.bytes().chunks(AES.blockSizeBytes())
-        var out:[Byte]?
+        var out:[UInt8]?
         if (blockMode == .CFB) {
             // CFB uses encryptBlock to decrypt
             out = blockMode.decryptBlocks(blocks, iv: self.iv?.bytes(), cipher: encryptBlock)
@@ -212,10 +212,10 @@ public class AES {
         return out == nil ? nil : NSData.withBytes(out!)
     }
     
-    private func decryptBlock(block:[Byte]) -> [Byte] {
+    private func decryptBlock(block:[UInt8]) -> [UInt8] {
         let expandedKey = expandKey()
         
-        var state:[[Byte]] = [[Byte]](count: variant.Nb, repeatedValue: [Byte](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) {
                 state[j][i] = block[i * row.count + j]
@@ -235,7 +235,7 @@ public class AES {
         state = invSubBytes(state)
         state = addRoundKey(state, expandedKey, 0)
         
-        var out:[Byte] = [Byte]()
+        var out:[UInt8] = [UInt8]()
         for i in 0..<state.count {
             for j in 0..<state[0].count {
                 out.append(state[j][i])
@@ -245,14 +245,14 @@ public class AES {
         return out
     }
     
-    public func expandKey() -> [Byte] {
+    public func expandKey() -> [UInt8] {
         
         /*
         * Function used in the Key Expansion routine that takes a four-byte
         * input word and applies an S-box to each of the four bytes to
         * produce an output word.
         */
-        func subWord(word:[Byte]) -> [Byte] {
+        func subWord(word:[UInt8]) -> [UInt8] {
             var result = word
             for i in 0..<4 {
                 result[i] = sBox[Int(word[i])]
@@ -260,8 +260,8 @@ public class AES {
             return result
         }
 
-        var w:[Byte] = [Byte](count: variant.Nb * (variant.Nr + 1) * 4, repeatedValue: 0)
-        let keyBytes:[Byte] = key.bytes()
+        var w:[UInt8] = [UInt8](count: variant.Nb * (variant.Nr + 1) * 4, repeatedValue: 0)
+        let keyBytes:[UInt8] = key.bytes()
         for i in 0..<variant.Nk {
             for wordIdx in 0..<4 {
                 w[(4*i)+wordIdx] = keyBytes[(4*i)+wordIdx]
@@ -270,7 +270,7 @@ public class AES {
         
         var i = variant.Nk
         while (i < variant.Nb * (variant.Nr + 1)) {
-            var tmp:[Byte] = [Byte](count: 4, repeatedValue: 0)
+            var tmp:[UInt8] = [UInt8](count: 4, repeatedValue: 0)
             for wordIdx in 0..<4 {
                 tmp[wordIdx] = w[4*(i-1)+wordIdx]
             }
@@ -296,7 +296,7 @@ public class AES {
 extension AES {
     
     // byte substitution with table (S-box)
-    public func subBytes(state:[[Byte]]) -> [[Byte]] {
+    public func subBytes(state:[[UInt8]]) -> [[UInt8]] {
         var result = state
         for (i,row) in enumerate(state) {
             for (j,value) in enumerate(row) {
@@ -306,7 +306,7 @@ extension AES {
         return result
     }
     
-    public func invSubBytes(state:[[Byte]]) -> [[Byte]] {
+    public func invSubBytes(state:[[UInt8]]) -> [[UInt8]] {
         var result = state
         for (i,row) in enumerate(state) {
             for (j,value) in enumerate(row) {
@@ -317,7 +317,7 @@ extension AES {
     }
     
     // Applies a cyclic shift to the last 3 rows of a state matrix.
-    public func shiftRows(state:[[Byte]]) -> [[Byte]] {
+    public func shiftRows(state:[[UInt8]]) -> [[UInt8]] {
         var result = state
         for r in 1..<4 {
             for c in 0..<variant.Nb {
@@ -327,7 +327,7 @@ extension AES {
         return result
     }
     
-    public func invShiftRows(state:[[Byte]]) -> [[Byte]] {
+    public func invShiftRows(state:[[UInt8]]) -> [[UInt8]] {
         var result = state
         for r in 1..<4 {
             for c in 0..<variant.Nb {
@@ -356,8 +356,8 @@ extension AES {
         return p
     }
     
-    public func matrixMultiplyPolys(matrix:[[Byte]], _ array:[Byte]) -> [Byte] {
-        var returnArray:[Byte] = array.map({ _ in return 0 })
+    public func matrixMultiplyPolys(matrix:[[UInt8]], _ array:[UInt8]) -> [UInt8] {
+        var returnArray:[UInt8] = array.map({ _ in return 0 })
         for (i, row) in enumerate(matrix) {
             for (j, boxVal) in enumerate(row) {
                 returnArray[i] = multiplyPolys(boxVal, array[j]) ^ returnArray[i]
@@ -366,8 +366,8 @@ extension AES {
         return returnArray
     }
 
-    public func addRoundKey(state:[[Byte]], _ expandedKeyW:[Byte], _ round:Int) -> [[Byte]] {
-        var newState = state.map({ val -> [Byte] in return val.map { _ in return 0 } })
+    public func addRoundKey(state:[[UInt8]], _ expandedKeyW:[UInt8], _ round:Int) -> [[UInt8]] {
+        var newState = state.map({ val -> [UInt8] in return val.map { _ in return 0 } })
         for c in 0..<variant.Nb {
             for i in 0..<4 {
                 newState[i][c] = state[i][c] ^ expandedKeyW[(4*variant.Nb*round)+(variant.Nb*c)+i]
@@ -377,11 +377,11 @@ extension AES {
     }
     
     // mixes data (independently of one another)
-    public func mixColumns(state:[[Byte]]) -> [[Byte]] {
+    public func mixColumns(state:[[UInt8]]) -> [[UInt8]] {
         var state = state
-        var colBox:[[Byte]] = [[2,3,1,1],[1,2,3,1],[1,1,2,3],[3,1,1,2]]
+        var colBox:[[UInt8]] = [[2,3,1,1],[1,2,3,1],[1,1,2,3],[3,1,1,2]]
         
-        var rowMajorState = state.map({ val -> [Byte] in return val.map { _ in return 0 } }) // zeroing
+        var rowMajorState = state.map({ val -> [UInt8] in return val.map { _ in return 0 } }) // zeroing
         
         for i in 0..<state.count {
             for j in 0..<state[0].count {
@@ -389,7 +389,7 @@ extension AES {
             }
         }
         
-        var newRowMajorState = state.map({ val -> [Byte] in return val.map { _ in return 0 } })
+        var newRowMajorState = state.map({ val -> [UInt8] in return val.map { _ in return 0 } })
         
         for (i, row) in enumerate(rowMajorState) {
             newRowMajorState[i] = matrixMultiplyPolys(colBox, row)
@@ -404,11 +404,11 @@ extension AES {
         return state
     }
     
-    public func invMixColumns(state:[[Byte]]) -> [[Byte]] {
+    public func invMixColumns(state:[[UInt8]]) -> [[UInt8]] {
         var state = state
-        var invColBox:[[Byte]] = [[14,11,13,9],[9,14,11,13],[13,9,14,11],[11,13,9,14]]
+        var invColBox:[[UInt8]] = [[14,11,13,9],[9,14,11,13],[13,9,14,11],[11,13,9,14]]
         
-        var colOrderState = state.map({ val -> [Byte] in return val.map { _ in return 0 } }) // zeroing
+        var colOrderState = state.map({ val -> [UInt8] in return val.map { _ in return 0 } }) // zeroing
         
         for i in 0..<state.count {
             for j in 0..<state[0].count {
@@ -416,7 +416,7 @@ extension AES {
             }
         }
         
-        var newState = state.map({ val -> [Byte] 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) {
             newState[i] = matrixMultiplyPolys(invColBox, row)

+ 6 - 6
CryptoSwift/ChaCha20.swift

@@ -8,7 +8,7 @@
 
 import Foundation
 
-class ChaCha20 {
+public class ChaCha20 {
     
     private let blockSizeBytes = 512 / 8
     private let stateSize = 16
@@ -48,7 +48,7 @@ class ChaCha20 {
         return encrypt(message)
     }
     
-    private func wordToByte(input:[UInt32] /* 64 */) -> [Byte]? /* 16 */ {
+    private func wordToByte(input:[UInt32] /* 64 */) -> [UInt8]? /* 16 */ {
         if (input.count != stateSize) {
             return nil;
         }
@@ -68,7 +68,7 @@ class ChaCha20 {
             i -= 2
         }
 
-        var output = [Byte]()
+        var output = [UInt8]()
 
         for i in 0..<16 {
             x[i] = x[i] &+ input[i]
@@ -82,7 +82,7 @@ class ChaCha20 {
         return contextSetup(iv: iv.bytes(), key: key.bytes())
     }
     
-    private func contextSetup(# iv:[Byte], key:[Byte]) -> Context? {
+    private func contextSetup(# iv:[UInt8], key:[UInt8]) -> Context? {
         var ctx = Context()
         let kbits = key.count * 8
         
@@ -129,10 +129,10 @@ class ChaCha20 {
         return ctx
     }
     
-    private func encryptBytes(message:[Byte]) -> [Byte]? {
+    private func encryptBytes(message:[UInt8]) -> [UInt8]? {
         
         if let ctx = context {
-            var c:[Byte] = [Byte](count: message.count, repeatedValue: 0)
+            var c:[UInt8] = [UInt8](count: message.count, repeatedValue: 0)
             
             var cPos:Int = 0
             var mPos:Int = 0

+ 2 - 2
CryptoSwift/Cipher.swift

@@ -65,8 +65,8 @@ public enum Cipher {
         }
     }
 
-    static public func randomIV(key: NSData) -> [Byte] {
-        var randomIV:[Byte] = [Byte]();
+    static public func randomIV(key: NSData) -> [UInt8] {
+        var randomIV:[UInt8] = [UInt8]();
         for (var i = 0; i < key.length; i++) {
             randomIV.append(UInt8(truncatingBitPattern: arc4random_uniform(256)));
         }

+ 26 - 26
CryptoSwift/CipherBlockMode.swift

@@ -29,7 +29,7 @@ public enum CipherBlockMode {
     
     :returns: encrypted bytes
     */
-    func encryptBlocks(blocks:[[Byte]], iv:[Byte]?, cipher:(block:[Byte]) -> [Byte]?) -> [Byte]? {
+    func encryptBlocks(blocks:[[UInt8]], iv:[UInt8]?, cipher:(block:[UInt8]) -> [UInt8]?) -> [UInt8]? {
         
         // if IV is not available, fallback to plain
         var finalBlockMode:CipherBlockMode = self
@@ -47,7 +47,7 @@ public enum CipherBlockMode {
         }
     }
     
-    func decryptBlocks(blocks:[[Byte]], iv:[Byte]?, cipher:(block:[Byte]) -> [Byte]?) -> [Byte]? {
+    func decryptBlocks(blocks:[[UInt8]], iv:[UInt8]?, cipher:(block:[UInt8]) -> [UInt8]?) -> [UInt8]? {
         // if IV is not available, fallback to plain
         var finalBlockMode:CipherBlockMode = self
         if (iv == nil) {
@@ -69,19 +69,19 @@ public enum CipherBlockMode {
 *  Cipher-block chaining (CBC)
 */
 private struct CBCMode {
-    static func encryptBlocks(blocks:[[Byte]], iv:[Byte]?, cipher:(block:[Byte]) -> [Byte]?) -> [Byte]? {
+    static func encryptBlocks(blocks:[[UInt8]], iv:[UInt8]?, cipher:(block:[UInt8]) -> [UInt8]?) -> [UInt8]? {
         
         if (iv == nil) {
             assertionFailure("CBC require IV")
             return nil
         }
         
-        var out:[Byte]?
-        var lastCiphertext:[Byte] = iv!
+        var out:[UInt8]?
+        var lastCiphertext:[UInt8] = iv!
         for (idx,plaintext) in enumerate(blocks) {
             // for the first time ciphertext = iv
             // ciphertext = plaintext (+) ciphertext
-            var xoredPlaintext:[Byte] = plaintext
+            var xoredPlaintext:[UInt8] = plaintext
             for i in 0..<plaintext.count {
                 xoredPlaintext[i] = lastCiphertext[i] ^ plaintext[i]
             }
@@ -91,7 +91,7 @@ private struct CBCMode {
                 lastCiphertext = encrypted
                 
                 if (out == nil) {
-                    out = [Byte]()
+                    out = [UInt8]()
                 }
                 
                 out = out! + encrypted
@@ -100,24 +100,24 @@ private struct CBCMode {
         return out;
     }
     
-    static func decryptBlocks(blocks:[[Byte]], iv:[Byte]?, cipher:(block:[Byte]) -> [Byte]?) -> [Byte]? {
+    static func decryptBlocks(blocks:[[UInt8]], iv:[UInt8]?, cipher:(block:[UInt8]) -> [UInt8]?) -> [UInt8]? {
         if (iv == nil) {
             assertionFailure("CBC require IV")
             return nil
         }
 
-        var out:[Byte]?
-        var lastCiphertext:[Byte] = iv!
+        var out:[UInt8]?
+        var lastCiphertext:[UInt8] = iv!
         for (idx,ciphertext) in enumerate(blocks) {
             if let decrypted = cipher(block: ciphertext) { // decrypt
                 
-                var xored:[Byte] = [Byte](count: lastCiphertext.count, repeatedValue: 0)
+                var xored:[UInt8] = [UInt8](count: lastCiphertext.count, repeatedValue: 0)
                 for i in 0..<ciphertext.count {
                     xored[i] = lastCiphertext[i] ^ decrypted[i]
                 }
 
                 if (out == nil) {
-                    out = [Byte]()
+                    out = [UInt8]()
                 }
                 out = out! + xored
             }
@@ -132,18 +132,18 @@ private struct CBCMode {
 *  Cipher feedback (CFB)
 */
 private struct CFBMode {
-    static func encryptBlocks(blocks:[[Byte]], iv:[Byte]?, cipher:(block:[Byte]) -> [Byte]?) -> [Byte]? {
+    static func encryptBlocks(blocks:[[UInt8]], iv:[UInt8]?, cipher:(block:[UInt8]) -> [UInt8]?) -> [UInt8]? {
         
         if (iv == nil) {
             assertionFailure("CFB require IV")
             return nil
         }
         
-        var out:[Byte]?
-        var lastCiphertext:[Byte] = iv!
+        var out:[UInt8]?
+        var lastCiphertext:[UInt8] = iv!
         for (idx,plaintext) in enumerate(blocks) {
             if let encrypted = cipher(block: lastCiphertext) {
-                var xoredPlaintext:[Byte] = [Byte](count: plaintext.count, repeatedValue: 0)
+                var xoredPlaintext:[UInt8] = [UInt8](count: plaintext.count, repeatedValue: 0)
                 for i in 0..<plaintext.count {
                     xoredPlaintext[i] = plaintext[i] ^ encrypted[i]
                 }
@@ -151,7 +151,7 @@ private struct CFBMode {
 
                 
                 if (out == nil) {
-                    out = [Byte]()
+                    out = [UInt8]()
                 }
                 
                 out = out! + xoredPlaintext
@@ -160,17 +160,17 @@ private struct CFBMode {
         return out;
     }
     
-    static func decryptBlocks(blocks:[[Byte]], iv:[Byte]?, cipher:(block:[Byte]) -> [Byte]?) -> [Byte]? {
+    static func decryptBlocks(blocks:[[UInt8]], iv:[UInt8]?, cipher:(block:[UInt8]) -> [UInt8]?) -> [UInt8]? {
         if (iv == nil) {
             assertionFailure("CFB require IV")
             return nil
         }
         
-        var out:[Byte]?
-        var lastCiphertext:[Byte] = iv!
+        var out:[UInt8]?
+        var lastCiphertext:[UInt8] = iv!
         for (idx,ciphertext) in enumerate(blocks) {
             if let decrypted = cipher(block: lastCiphertext) {
-                var xored:[Byte] = [Byte](count: ciphertext.count, repeatedValue: 0)
+                var xored:[UInt8] = [UInt8](count: ciphertext.count, repeatedValue: 0)
                 for i in 0..<ciphertext.count {
                     xored[i] = ciphertext[i] ^ decrypted[i]
                 }
@@ -178,7 +178,7 @@ private struct CFBMode {
                 
                 
                 if (out == nil) {
-                    out = [Byte]()
+                    out = [UInt8]()
                 }
                 
                 out = out! + xored
@@ -194,13 +194,13 @@ private struct CFBMode {
 *  Electronic codebook (ECB)
 */
 private struct ECBMode {
-    static func encryptBlocks(blocks:[[Byte]], cipher:(block:[Byte]) -> [Byte]?) -> [Byte]? {
-        var out:[Byte]?
+    static func encryptBlocks(blocks:[[UInt8]], cipher:(block:[UInt8]) -> [UInt8]?) -> [UInt8]? {
+        var out:[UInt8]?
         for (idx,plaintext) in enumerate(blocks) {
             if let encrypted = cipher(block: plaintext) {
                 
                 if (out == nil) {
-                    out = [Byte]()
+                    out = [UInt8]()
                 }
 
                 out = out! + encrypted
@@ -209,7 +209,7 @@ private struct ECBMode {
         return out
     }
     
-    static func decryptBlocks(blocks:[[Byte]], cipher:(block:[Byte]) -> [Byte]?) -> [Byte]? {
+    static func decryptBlocks(blocks:[[UInt8]], cipher:(block:[UInt8]) -> [UInt8]?) -> [UInt8]? {
         return encryptBlocks(blocks, cipher: cipher)
     }
 }

+ 2 - 2
CryptoSwift/CryptoHashBase.swift

@@ -21,7 +21,7 @@ class HashBase {
         var tmpMessage: NSMutableData = NSMutableData(data: self.message)
         
         // Step 1. Append Padding Bits
-        tmpMessage.appendBytes([0x80]) // append one bit (Byte with one bit) to message
+        tmpMessage.appendBytes([0x80]) // append one bit (UInt8 with one bit) to message
         
         // append "0" bit until message length in bits ≡ 448 (mod 512)
         var msgLength = tmpMessage.length;
@@ -30,7 +30,7 @@ class HashBase {
             counter++
             msgLength++
         }
-        var bufZeros = UnsafeMutablePointer<Byte>(calloc(UInt(counter), UInt(sizeof(Byte))))
+        var bufZeros = UnsafeMutablePointer<UInt8>(calloc(UInt(counter), UInt(sizeof(UInt8))))
         tmpMessage.appendBytes(bufZeros, length: counter)
         
         return tmpMessage

+ 5 - 5
CryptoSwift/Generics.swift

@@ -35,15 +35,15 @@ func integerFromBitsArray<T: UnsignedIntegerType>(bits: [Bit]) -> T
 }
 
 /** initialize integer from array of bytes */
-func integerWithBytes<T: IntegerType>(bytes: [Byte]) -> T {
+func integerWithBytes<T: IntegerType>(bytes: [UInt8]) -> T {
     var totalBytes = Swift.min(bytes.count, sizeof(T))
     // get slice of Int
     var start = Swift.max(bytes.count - sizeof(T),0)
-    var intarr = [Byte](bytes[start..<(start + totalBytes)])
+    var intarr = [UInt8](bytes[start..<(start + totalBytes)])
     
     // pad size if necessary
     while (intarr.count < sizeof(T)) {
-        intarr.insert(0 as Byte, atIndex: 0)
+        intarr.insert(0 as UInt8, atIndex: 0)
     }
     intarr = intarr.reverse()
     
@@ -54,7 +54,7 @@ func integerWithBytes<T: IntegerType>(bytes: [Byte]) -> T {
 }
 
 /** array of bytes, little-endian representation */
-func arrayOfBytes<T>(value:T, length:Int? = nil) -> [Byte] {
+func arrayOfBytes<T>(value:T, length:Int? = nil) -> [UInt8] {
     let totalBytes = length ?? (sizeofValue(value) * 8)
     var v = value
     
@@ -62,7 +62,7 @@ func arrayOfBytes<T>(value:T, length:Int? = nil) -> [Byte] {
     valuePointer.memory = value
     
     var bytesPointer = UnsafeMutablePointer<Byte>(valuePointer)
-    var bytes = [Byte](count: totalBytes, repeatedValue: 0)
+    var bytes = [UInt8](count: totalBytes, repeatedValue: 0)
     for j in 0..<min(sizeof(T),totalBytes) {
         bytes[totalBytes - 1 - j] = (bytesPointer + j).memory
     }

+ 9 - 9
CryptoSwift/HMAC.swift

@@ -13,7 +13,7 @@ public class HMAC {
     public enum Variant {
         case sha1, sha256, md5
         
-        func calculateHash(# bytes:[Byte]) -> [Byte]? {
+        func calculateHash(# bytes:[UInt8]) -> [UInt8]? {
             switch (self) {
             case .sha1:
                 return NSData.withBytes(bytes).sha1()?.bytes()
@@ -29,7 +29,7 @@ public class HMAC {
         }
     }
     
-    let key:[Byte]
+    let key:[UInt8]
     let variant:Variant
     
     class internal func authenticate(# key: NSData, message: NSData, variant:HMAC.Variant = .md5) -> NSData? {
@@ -39,13 +39,13 @@ public class HMAC {
         return nil
     }
     
-    class internal func authenticate(# key: [Byte], message: [Byte], variant:HMAC.Variant = .md5) -> [Byte]? {
+    class internal func authenticate(# key: [UInt8], message: [UInt8], variant:HMAC.Variant = .md5) -> [UInt8]? {
         return HMAC(key, variant: variant)?.authenticate(message: message)
     }
 
     // MARK: - Private
     
-    private init? (_ key: [Byte], variant:HMAC.Variant = .md5) {
+    private init? (_ key: [UInt8], variant:HMAC.Variant = .md5) {
         self.variant = variant
         self.key = key
 
@@ -56,21 +56,21 @@ public class HMAC {
         }
         
         if (key.count < variant.blockSize()) { // keys shorter than blocksize are zero-padded
-            self.key = key + [Byte](count: variant.blockSize() - key.count, repeatedValue: 0)
+            self.key = key + [UInt8](count: variant.blockSize() - key.count, repeatedValue: 0)
         }
     }
     
-    private func authenticate(# message:[Byte]) -> [Byte]? {
-        var opad = [Byte](count: variant.blockSize(), repeatedValue: 0x5c)
+    private func authenticate(# message:[UInt8]) -> [UInt8]? {
+        var opad = [UInt8](count: variant.blockSize(), repeatedValue: 0x5c)
         for (idx, val) in enumerate(key) {
             opad[idx] = key[idx] ^ opad[idx]
         }
-        var ipad = [Byte](count: variant.blockSize(), repeatedValue: 0x36)
+        var ipad = [UInt8](count: variant.blockSize(), repeatedValue: 0x36)
         for (idx, val) in enumerate(key) {
             ipad[idx] = key[idx] ^ ipad[idx]
         }
 
-        var finalHash:[Byte]? = nil;
+        var finalHash:[UInt8]? = nil;
         if let ipadAndMessageHash = variant.calculateHash(bytes: ipad + message) {
             finalHash = variant.calculateHash(bytes: opad + ipadAndMessageHash);
         }

+ 2 - 2
CryptoSwift/IntExtension.swift

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

+ 9 - 9
CryptoSwift/NSDataExtension.swift

@@ -11,7 +11,7 @@ import Foundation
 extension NSMutableData {
     
     /** Convenient way to append bytes */
-    internal func appendBytes(arrayOfBytes: [Byte]) {
+    internal func appendBytes(arrayOfBytes: [UInt8]) {
         self.appendBytes(arrayOfBytes, length: arrayOfBytes.count)
     }
     
@@ -80,9 +80,9 @@ extension NSData {
     }
 
     func toHexString() -> String {
-        let count = self.length / sizeof(Byte)
-        var bytesArray = [Byte](count: count, repeatedValue: 0)
-        self.getBytes(&bytesArray, length:count * sizeof(Byte))
+        let count = self.length / sizeof(UInt8)
+        var bytesArray = [UInt8](count: count, repeatedValue: 0)
+        self.getBytes(&bytesArray, length:count * sizeof(UInt8))
         
         var s:String = "";
         for byte in bytesArray {
@@ -91,14 +91,14 @@ extension NSData {
         return s;
     }
     
-    func bytes() -> [Byte] {
-        let count = self.length / sizeof(Byte)
-        var bytesArray = [Byte](count: count, repeatedValue: 0)
-        self.getBytes(&bytesArray, length:count * sizeof(Byte))
+    func bytes() -> [UInt8] {
+        let count = self.length / sizeof(UInt8)
+        var bytesArray = [UInt8](count: count, repeatedValue: 0)
+        self.getBytes(&bytesArray, length:count * sizeof(UInt8))
         return bytesArray
     }
     
-    class public func withBytes(bytes: [Byte]) -> NSData {
+    class public func withBytes(bytes: [UInt8]) -> NSData {
         return NSData(bytes: bytes, length: bytes.count)
     }
 }

+ 0 - 0
CryptoSwift/Playground/MyPlayground.playground/contents.xcplayground → CryptoSwift/Playground/CryptoPlayground.playground/contents.xcplayground


+ 7 - 0
CryptoSwift/Playground/CryptoPlayground.playground/section-1.swift

@@ -0,0 +1,7 @@
+// Playground - noun: a place where people can play
+
+import Foundation
+import CryptoSwift
+
+let plaintext = "Lorem ipsum"
+let MD5 = plaintext.md5()

+ 1 - 1
CryptoSwift/Playground/MyPlayground.playground/timeline.xctimeline → CryptoSwift/Playground/CryptoPlayground.playground/timeline.xctimeline

@@ -3,7 +3,7 @@
    version = "3.0">
    <TimelineItems>
       <LoggerValueHistoryTimelineItem
-         documentLocation = "#CharacterRangeLen=0&amp;CharacterRangeLoc=206&amp;EndingColumnNumber=6&amp;EndingLineNumber=15&amp;StartingColumnNumber=5&amp;StartingLineNumber=15&amp;Timestamp=442876557.94963">
+         documentLocation = "#CharacterRangeLen=0&amp;CharacterRangeLoc=146&amp;EndingColumnNumber=6&amp;EndingLineNumber=5&amp;StartingColumnNumber=5&amp;StartingLineNumber=5&amp;Timestamp=445557880.049288">
       </LoggerValueHistoryTimelineItem>
    </TimelineItems>
 </Timeline>

+ 0 - 24
CryptoSwift/Playground/MyPlayground.playground/section-1.swift

@@ -1,24 +0,0 @@
-// Playground - noun: a place where people can play
-
-import Foundation
-
-reverse(1..<4)
-
-var arr:[UInt8] = [0x06];
-let repeat = Repeat(count: 5, repeatedValue: 0)
-for a in repeat {
-    arr = arr + [Byte(a)]
-}
-
-arr + [Byte](count: 5, repeatedValue: 0)
-
-
-arr[0..<3]
-
-
-var key:[Byte] = [1,2,3,4,5,6,7,8,9,0]
-var opad = [Byte](count: 64, repeatedValue: 0x5c)
-
-opad.map({ (val:Byte) -> (Byte) in
-    return val ^ 56
-})

+ 23 - 23
CryptoSwift/Poly1305.swift

@@ -17,15 +17,15 @@ public class Poly1305 {
     private var ctx:Context?
     
     private class Context {
-        var r            = [Byte](count: 17, repeatedValue: 0)
-        var h            = [Byte](count: 17, repeatedValue: 0)
-        var pad          = [Byte](count: 17, repeatedValue: 0)
-        var buffer       = [Byte](count: 16, repeatedValue: 0)
+        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 final:Byte   = 0
+        var final:UInt8   = 0
         var leftover:Int = 0
         
-        init?(_ key: [Byte]) {
+        init?(_ key: [UInt8]) {
             assert(key.count == 32,"Invalid key length");
             if (key.count != 32) {
                 return nil;
@@ -95,20 +95,20 @@ public class Poly1305 {
         return nil
     }
 
-    class internal func authenticate(# key: [Byte], message: [Byte]) -> [Byte]? {
+    class internal func authenticate(# key: [UInt8], message: [UInt8]) -> [UInt8]? {
         return Poly1305(key)?.authenticate(message: message)
     }
     
     // MARK: - Private
     
-    private init? (_ key: [Byte]) {
+    private init? (_ key: [UInt8]) {
         ctx = Context(key)
         if (ctx == nil) {
             return nil
         }
     }
     
-    private func authenticate(# message:[Byte]) -> [Byte]? {
+    private func authenticate(# message:[UInt8]) -> [UInt8]? {
         if let ctx = self.ctx {
             update(ctx, message: message)
             return finish(ctx)
@@ -123,7 +123,7 @@ public class Poly1305 {
     :param: message message
     :param: bytes   length of the message fragment to be processed
     */
-    private func update(context:Context, message:[Byte], bytes:Int? = nil) {
+    private func update(context:Context, message:[UInt8], bytes:Int? = nil) {
         var bytes = bytes ?? message.count
         var mPos = 0
         
@@ -168,8 +168,8 @@ public class Poly1305 {
         }
     }
     
-    private func finish(context:Context) -> [Byte]? {
-        var mac = [Byte](count: 16, repeatedValue: 0);
+    private func finish(context:Context) -> [UInt8]? {
+        var mac = [UInt8](count: 16, repeatedValue: 0);
         
         /* process the remaining block */
         if (context.leftover > 0) {
@@ -199,7 +199,7 @@ public class Poly1305 {
     
     // MARK: - Utils
     
-    private func add(context:Context, c:[Byte]) -> Bool {
+    private func add(context:Context, c:[UInt8]) -> Bool {
         if (context.h.count != 17 && c.count != 17) {
             return false
         }
@@ -207,7 +207,7 @@ public class Poly1305 {
         var u:UInt16 = 0
         for i in 0..<17 {
             u += UInt16(context.h[i]) + UInt16(c[i])
-            context.h[i] = Byte.withValue(u)
+            context.h[i] = UInt8.withValue(u)
             u = u >> 8
         }
         return true
@@ -222,20 +222,20 @@ public class Poly1305 {
         
         for i in 0..<16 {
             u += hr[i];
-            context.h[i] = Byte.withValue(u) // crash! h[i] = UInt8(u) & 0xff
+            context.h[i] = UInt8.withValue(u) // crash! h[i] = UInt8(u) & 0xff
             u >>= 8;
         }
         
         u += hr[16]
-        context.h[16] = Byte.withValue(u) & 0x03
+        context.h[16] = UInt8.withValue(u) & 0x03
         u >>= 2
         u += (u << 2); /* u *= 5; */
         for i in 0..<16 {
             u += UInt32(context.h[i])
-            context.h[i] = Byte.withValue(u) // crash! h[i] = UInt8(u) & 0xff
+            context.h[i] = UInt8.withValue(u) // crash! h[i] = UInt8(u) & 0xff
             u >>= 8
         }
-        context.h[16] += Byte.withValue(u);
+        context.h[16] += UInt8.withValue(u);
         
         return true
     }
@@ -246,8 +246,8 @@ public class Poly1305 {
             return false
         }
         
-        let minusp:[Byte] = [0x05,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xfc]
-        var horig:[Byte] = [Byte](count: 17, repeatedValue: 0)
+        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)
         
         /* compute h + -p */
         for i in 0..<17 {
@@ -262,7 +262,7 @@ public class Poly1305 {
             return bit.inverted()
         })
         
-        let negative = Byte(bits: invertedBits)
+        let negative = UInt8(bits: invertedBits)
         for i in 0..<17 {
             context.h[i] ^= negative & (horig[i] ^ context.h[i]);
         }
@@ -270,7 +270,7 @@ public class Poly1305 {
         return true;
     }
     
-    private func blocks(context:Context, m:[Byte], startPos:Int = 0) -> Int {
+    private func blocks(context:Context, m:[UInt8], startPos:Int = 0) -> Int {
         var bytes = m.count
         let hibit = context.final ^ 1 // 1 <<128
         var mPos = startPos
@@ -278,7 +278,7 @@ public class Poly1305 {
         while (bytes >= Int(blockSize)) {
             var hr:[UInt32] = [UInt32](count: 17, repeatedValue: 0)
             var u:UInt32 = 0
-            var c:[Byte] = [Byte](count: 17, repeatedValue: 0)
+            var c:[UInt8] = [UInt8](count: 17, repeatedValue: 0)
             
             /* h += m */
             for i in 0..<16 {

+ 2 - 2
CryptoSwift/UInt32Extension.swift

@@ -10,7 +10,7 @@ import Foundation
 
 /** array of bytes */
 extension UInt32 {
-    public func bytes(_ totalBytes: Int = sizeof(UInt32)) -> [Byte] {
+    public func bytes(_ totalBytes: Int = sizeof(UInt32)) -> [UInt8] {
         return arrayOfBytes(self, length: totalBytes)
     }
 
@@ -19,7 +19,7 @@ extension UInt32 {
     }
 
     /** Int with array bytes (little-endian) */
-    public static func withBytes(bytes: [Byte]) -> UInt32 {
+    public static func withBytes(bytes: [UInt8]) -> UInt32 {
         return integerWithBytes(bytes)
     }
 }

+ 3 - 3
CryptoSwift/UInt64Extension.swift

@@ -10,16 +10,16 @@ import Foundation
 
 /** array of bytes */
 extension UInt64 {
-    public func bytes(_ totalBytes: Int = sizeof(UInt64)) -> [Byte] {
+    public func bytes(_ totalBytes: Int = sizeof(UInt64)) -> [UInt8] {
         return arrayOfBytes(self, length: totalBytes)
     }
 
-    public static func withBytes(bytes: Slice<Byte>) -> UInt64 {
+    public static func withBytes(bytes: Slice<UInt8>) -> UInt64 {
         return UInt64.withBytes(Array(bytes))
     }
 
     /** Int with array bytes (little-endian) */
-    public static func withBytes(bytes: [Byte]) -> UInt64 {
+    public static func withBytes(bytes: [UInt8]) -> UInt64 {
         return integerWithBytes(bytes)
     }
 }

+ 16 - 16
CryptoSwift/ByteExtension.swift → CryptoSwift/UInt8Extension.swift

@@ -9,31 +9,31 @@
 import Foundation
 
 /** casting */
-extension Byte {
+extension UInt8 {
     
     /** cast because UInt8(<UInt32>) because std initializer crash if value is > byte */
-    static func withValue(v:UInt64) -> Byte {
+    static func withValue(v:UInt64) -> UInt8 {
         let tmp = v & 0xFF
-        return Byte(tmp)
+        return UInt8(tmp)
     }
 
-    static func withValue(v:UInt32) -> Byte {
+    static func withValue(v:UInt32) -> UInt8 {
         let tmp = v & 0xFF
-        return Byte(tmp)
+        return UInt8(tmp)
     }
     
-    static func withValue(v:UInt16) -> Byte {
+    static func withValue(v:UInt16) -> UInt8 {
         let tmp = v & 0xFF
-        return Byte(tmp)
+        return UInt8(tmp)
     }
 
 }
 
 /** Bits */
-extension Byte {
+extension UInt8 {
 
     init(bits: [Bit]) {
-        self.init(integerFromBitsArray(bits) as Byte)
+        self.init(integerFromBitsArray(bits) as UInt8)
     }
     
     /** array of bits */
@@ -43,7 +43,7 @@ extension Byte {
         var bitsArray = [Bit](count: totalBitsCount, repeatedValue: Bit.Zero)
         
         for j in 0..<totalBitsCount {
-            let bitVal:Byte = 1 << Byte(totalBitsCount - 1 - j)
+            let bitVal:UInt8 = 1 << UInt8(totalBitsCount - 1 - j)
             let check = self & bitVal
             
             if (check != 0) {
@@ -65,22 +65,22 @@ extension Byte {
 }
 
 /** Shift bits */
-extension Byte {
+extension UInt8 {
     /** Shift bits to the right. All bits are shifted (including sign bit) */
-    mutating func shiftRight(count: Byte) -> Byte {
+    mutating func shiftRight(count: UInt8) -> UInt8 {
         if (self == 0) {
             return self;
         }
 
-        var bitsCount = Byte(sizeof(Byte) * 8)
+        var bitsCount = UInt8(sizeof(UInt8) * 8)
 
         if (count >= bitsCount) {
             return 0
         }
 
-        var maxBitsForValue = Byte(floor(log2(Double(self) + 1)))
+        var maxBitsForValue = UInt8(floor(log2(Double(self) + 1)))
         var shiftCount = Swift.min(count, maxBitsForValue - 1)
-        var shiftedValue:Byte = 0;
+        var shiftedValue:UInt8 = 0;
         
         for bitIdx in 0..<bitsCount {
             var byte = 1 << bitIdx
@@ -94,7 +94,7 @@ extension Byte {
 }
 
 /** shift right and assign with bits truncation */
-func &>> (lhs: Byte, rhs: Byte) -> Byte {
+func &>> (lhs: UInt8, rhs: UInt8) -> UInt8 {
     var l = lhs;
     l.shiftRight(rhs)
     return l

+ 24 - 24
CryptoSwiftTests/AESTests.swift

@@ -12,14 +12,14 @@ import CryptoSwift
 
 class AESTests: XCTestCase {
     // 128 bit key
-    let aesKey:[Byte] = [0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f]
+    let aesKey:[UInt8] = [0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f]
 
     func testAES_encrypt2() {
-        let key:[Byte]   = [0x36, 0x37, 0x39, 0x66, 0x62, 0x31, 0x64, 0x64, 0x66, 0x37, 0x64, 0x38, 0x31, 0x62, 0x65, 0x65];
-        let iv:[Byte]    = [0x6b, 0x64, 0x66, 0x36, 0x37, 0x33, 0x39, 0x38, 0x44, 0x46, 0x37, 0x33, 0x38, 0x33, 0x66, 0x64]
-        let input:[Byte] = [0x62, 0x72, 0x61, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00];
+        let 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 expected:[Byte] = [0xae,0x8c,0x59,0x95,0xb2,0x6f,0x8e,0x3d,0xb0,0x6f,0x0a,0xa5,0xfe,0xc4,0xf0,0xc2];
+        let expected:[UInt8] = [0xae,0x8c,0x59,0x95,0xb2,0x6f,0x8e,0x3d,0xb0,0x6f,0x0a,0xa5,0xfe,0xc4,0xf0,0xc2];
         
         if let aes = AES(key: NSData.withBytes(key), iv: NSData.withBytes(iv), blockMode: .CBC) {
             let encrypted = aes.encrypt(NSData.withBytes(input), addPadding: false)
@@ -32,12 +32,12 @@ class AESTests: XCTestCase {
     }
 
     func testAES_encrypt() {
-        let input:[Byte] = [0x00, 0x11, 0x22, 0x33,
+        let input:[UInt8] = [0x00, 0x11, 0x22, 0x33,
             0x44, 0x55, 0x66, 0x77,
             0x88, 0x99, 0xaa, 0xbb,
             0xcc, 0xdd, 0xee, 0xff];
         
-        let expected:[Byte] = [0x69, 0xc4, 0xe0, 0xd8,
+        let expected:[UInt8] = [0x69, 0xc4, 0xe0, 0xd8,
             0x6a, 0x7b, 0x4, 0x30,
             0xd8, 0xcd, 0xb7, 0x80,
             0x70, 0xb4, 0xc5, 0x5a];
@@ -53,10 +53,10 @@ class AESTests: XCTestCase {
     }
 
     func testAES_encrypt_cbc() {
-        let key:[Byte] = [0x2b,0x7e,0x15,0x16,0x28,0xae,0xd2,0xa6,0xab,0xf7,0x15,0x88,0x09,0xcf,0x4f,0x3c];
-        let iv:[Byte] = [0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F]
-        let plaintext:[Byte] = [0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a]
-        let expected:[Byte] = [0x76,0x49,0xab,0xac,0x81,0x19,0xb2,0x46,0xce,0xe9,0x8e,0x9b,0x12,0xe9,0x19,0x7d];
+        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];
         
         if let aes = AES(key: NSData.withBytes(key), iv:NSData.withBytes(iv), blockMode: .CBC) {
             XCTAssertTrue(aes.blockMode == .CBC, "Invalid block mode")
@@ -70,10 +70,10 @@ class AESTests: XCTestCase {
     }
     
     func testAES_encrypt_cfb() {
-        let key:[Byte] = [0x2b,0x7e,0x15,0x16,0x28,0xae,0xd2,0xa6,0xab,0xf7,0x15,0x88,0x09,0xcf,0x4f,0x3c];
-        let iv:[Byte] = [0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F]
-        let plaintext:[Byte] = [0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a]
-        let expected:[Byte] = [0x3b,0x3f,0xd9,0x2e,0xb7,0x2d,0xad,0x20,0x33,0x34,0x49,0xf8,0xe8,0x3c,0xfb,0x4a];
+        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];
         
         if let aes = AES(key: NSData.withBytes(key), iv:NSData.withBytes(iv), blockMode: .CFB) {
             XCTAssertTrue(aes.blockMode == .CFB, "Invalid block mode")
@@ -87,12 +87,12 @@ class AESTests: XCTestCase {
     }
     
     func testAES_SubBytes() {
-        let input:[[Byte]] = [[0x00, 0x10, 0x20, 0x30],
+        let input:[[UInt8]] = [[0x00, 0x10, 0x20, 0x30],
             [0x40, 0x50, 0x60, 0x70],
             [0x80, 0x90, 0xa0, 0xb0],
             [0xc0, 0xd0, 0xe0, 0xf0]]
         
-        let expected:[[Byte]] = [[0x63, 0xca, 0xb7, 0x04],
+        let expected:[[UInt8]] = [[0x63, 0xca, 0xb7, 0x04],
             [0x09, 0x53, 0xd0, 0x51],
             [0xcd, 0x60, 0xe0, 0xe7],
             [0xba, 0x70, 0xe1, 0x8c]]
@@ -104,12 +104,12 @@ class AESTests: XCTestCase {
     }
     
     func testAES_shiftRows() {
-        let input:[[Byte]] = [[0x63, 0x09, 0xcd, 0xba],
+        let input:[[UInt8]] = [[0x63, 0x09, 0xcd, 0xba],
             [0xca, 0x53, 0x60, 0x70],
             [0xb7, 0xd0, 0xe0, 0xe1],
             [0x04, 0x51, 0xe7, 0x8c]]
         
-        let expected:[[Byte]] = [[0x63, 0x9, 0xcd, 0xba],
+        let expected:[[UInt8]] = [[0x63, 0x9, 0xcd, 0xba],
             [0x53, 0x60, 0x70, 0xca],
             [0xe0, 0xe1, 0xb7, 0xd0],
             [0x8c, 0x4, 0x51, 0xe7]]
@@ -125,7 +125,7 @@ class AESTests: XCTestCase {
     }
     
     func testAES_expandKey() {
-        let expected:[Byte] = [0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf, 0xd6, 0xaa, 0x74, 0xfd, 0xd2, 0xaf, 0x72, 0xfa, 0xda, 0xa6, 0x78, 0xf1, 0xd6, 0xab, 0x76, 0xfe, 0xb6, 0x92, 0xcf, 0xb, 0x64, 0x3d, 0xbd, 0xf1, 0xbe, 0x9b, 0xc5, 0x0, 0x68, 0x30, 0xb3, 0xfe, 0xb6, 0xff, 0x74, 0x4e, 0xd2, 0xc2, 0xc9, 0xbf, 0x6c, 0x59, 0xc, 0xbf, 0x4, 0x69, 0xbf, 0x41, 0x47, 0xf7, 0xf7, 0xbc, 0x95, 0x35, 0x3e, 0x3, 0xf9, 0x6c, 0x32, 0xbc, 0xfd, 0x5, 0x8d, 0xfd, 0x3c, 0xaa, 0xa3, 0xe8, 0xa9, 0x9f, 0x9d, 0xeb, 0x50, 0xf3, 0xaf, 0x57, 0xad, 0xf6, 0x22, 0xaa, 0x5e, 0x39, 0xf, 0x7d, 0xf7, 0xa6, 0x92, 0x96, 0xa7, 0x55, 0x3d, 0xc1, 0xa, 0xa3, 0x1f, 0x6b, 0x14, 0xf9, 0x70, 0x1a, 0xe3, 0x5f, 0xe2, 0x8c, 0x44, 0xa, 0xdf, 0x4d, 0x4e, 0xa9, 0xc0, 0x26, 0x47, 0x43, 0x87, 0x35, 0xa4, 0x1c, 0x65, 0xb9, 0xe0, 0x16, 0xba, 0xf4, 0xae, 0xbf, 0x7a, 0xd2, 0x54, 0x99, 0x32, 0xd1, 0xf0, 0x85, 0x57, 0x68, 0x10, 0x93, 0xed, 0x9c, 0xbe, 0x2c, 0x97, 0x4e, 0x13, 0x11, 0x1d, 0x7f, 0xe3, 0x94, 0x4a, 0x17, 0xf3, 0x7, 0xa7, 0x8b, 0x4d, 0x2b, 0x30, 0xc5]
+        let expected:[UInt8] = [0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf, 0xd6, 0xaa, 0x74, 0xfd, 0xd2, 0xaf, 0x72, 0xfa, 0xda, 0xa6, 0x78, 0xf1, 0xd6, 0xab, 0x76, 0xfe, 0xb6, 0x92, 0xcf, 0xb, 0x64, 0x3d, 0xbd, 0xf1, 0xbe, 0x9b, 0xc5, 0x0, 0x68, 0x30, 0xb3, 0xfe, 0xb6, 0xff, 0x74, 0x4e, 0xd2, 0xc2, 0xc9, 0xbf, 0x6c, 0x59, 0xc, 0xbf, 0x4, 0x69, 0xbf, 0x41, 0x47, 0xf7, 0xf7, 0xbc, 0x95, 0x35, 0x3e, 0x3, 0xf9, 0x6c, 0x32, 0xbc, 0xfd, 0x5, 0x8d, 0xfd, 0x3c, 0xaa, 0xa3, 0xe8, 0xa9, 0x9f, 0x9d, 0xeb, 0x50, 0xf3, 0xaf, 0x57, 0xad, 0xf6, 0x22, 0xaa, 0x5e, 0x39, 0xf, 0x7d, 0xf7, 0xa6, 0x92, 0x96, 0xa7, 0x55, 0x3d, 0xc1, 0xa, 0xa3, 0x1f, 0x6b, 0x14, 0xf9, 0x70, 0x1a, 0xe3, 0x5f, 0xe2, 0x8c, 0x44, 0xa, 0xdf, 0x4d, 0x4e, 0xa9, 0xc0, 0x26, 0x47, 0x43, 0x87, 0x35, 0xa4, 0x1c, 0x65, 0xb9, 0xe0, 0x16, 0xba, 0xf4, 0xae, 0xbf, 0x7a, 0xd2, 0x54, 0x99, 0x32, 0xd1, 0xf0, 0x85, 0x57, 0x68, 0x10, 0x93, 0xed, 0x9c, 0xbe, 0x2c, 0x97, 0x4e, 0x13, 0x11, 0x1d, 0x7f, 0xe3, 0x94, 0x4a, 0x17, 0xf3, 0x7, 0xa7, 0x8b, 0x4d, 0x2b, 0x30, 0xc5]
         
         if let aes = AES(key: NSData.withBytes(aesKey), blockMode: .CBC) {
             XCTAssertEqual(expected, aes.expandKey(), "expandKey failed")
@@ -135,12 +135,12 @@ class AESTests: XCTestCase {
     }
     
     func testAES_addRoundKey() {
-        let input:[[Byte]] = [[0x00, 0x44, 0x88, 0xcc],
+        let input:[[UInt8]] = [[0x00, 0x44, 0x88, 0xcc],
             [0x11, 0x55, 0x99, 0xdd],
             [0x22, 0x66, 0xaa, 0xee],
             [0x33, 0x77, 0xbb, 0xff]]
         
-        let expected:[[Byte]] = [[0, 64, 128, 192],
+        let expected:[[UInt8]] = [[0, 64, 128, 192],
             [16, 80, 144, 208],
             [32, 96, 160, 224],
             [48, 112, 176, 240]]
@@ -154,12 +154,12 @@ class AESTests: XCTestCase {
     }
     
     func testAES_mixColumns() {
-        let input:[[Byte]] = [[0x63, 0x9, 0xcd, 0xba],
+        let input:[[UInt8]] = [[0x63, 0x9, 0xcd, 0xba],
             [0x53, 0x60, 0x70, 0xca],
             [0xe0, 0xe1, 0xb7, 0xd0],
             [0x8c, 0x4, 0x51, 0xe7]]
         
-        let expected:[[Byte]] = [[0x5f, 0x57, 0xf7, 0x1d],
+        let expected:[[UInt8]] = [[0x5f, 0x57, 0xf7, 0x1d],
             [0x72, 0xf5, 0xbe, 0xb9],
             [0x64, 0xbc, 0x3b, 0xf9],
             [0x15, 0x92, 0x29, 0x1a]]

+ 3 - 3
CryptoSwiftTests/ChaCha20Tests.swift

@@ -21,7 +21,7 @@ class ChaCha20Tests: XCTestCase {
     }
 
     func testChaCha20() {
-        let keys:[[Byte]] = [
+        let keys:[[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],
@@ -29,7 +29,7 @@ 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:[[Byte]] = [
+        let ivs:[[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],
@@ -51,7 +51,7 @@ class ChaCha20Tests: XCTestCase {
             
             let expectedHex = expectedHexes[idx]
             //println(countElements(expectedHex) / 2);
-            let message = [Byte](count: (countElements(expectedHex) / 2), repeatedValue: 0)
+            let message = [UInt8](count: (countElements(expectedHex) / 2), repeatedValue: 0)
             let messageData = NSData(bytes: message, length: message.count);
             
             let setup = (key: keyData, iv: ivData)

+ 9 - 9
CryptoSwiftTests/HMACTests.swift

@@ -22,27 +22,27 @@ class HMACTests: XCTestCase {
     
     
     func testMD5() {
-        let key:[Byte] = []
-        let msg:[Byte] = []
-        let expectedMac:[Byte] = [0x74,0xe6,0xf7,0x29,0x8a,0x9c,0x2d,0x16,0x89,0x35,0xf5,0x8c,0x00,0x1b,0xad,0x88]
+        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 hmac = Authenticator.HMAC(key: NSData.withBytes(key), variant: .md5).authenticate(NSData.withBytes(msg))
         XCTAssertEqual(hmac!, NSData.withBytes(expectedMac), "Invalid authentication result")
     }
     
     func testSHA1() {
-        let key:[Byte] = []
-        let msg:[Byte] = []
-        let expectedMac:[Byte] = [0xfb,0xdb,0x1d,0x1b,0x18,0xaa,0x6c,0x08,0x32,0x4b,0x7d,0x64,0xb7,0x1f,0xb7,0x63,0x70,0x69,0x0e,0x1d]
+        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 hmac = Authenticator.HMAC(key: NSData.withBytes(key), variant: .sha1).authenticate(NSData.withBytes(msg))
         XCTAssertEqual(hmac!, NSData.withBytes(expectedMac), "Invalid authentication result")
     }
 
     func testSHA256() {
-        let key:[Byte] = []
-        let msg:[Byte] = []
-        let expectedMac:[Byte] = [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:[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 hmac = Authenticator.HMAC(key: NSData.withBytes(key), variant: .sha256).authenticate(NSData.withBytes(msg))
         XCTAssertEqual(hmac!, NSData.withBytes(expectedMac), "Invalid authentication result")

+ 9 - 9
CryptoSwiftTests/HashTests.swift

@@ -20,7 +20,7 @@ class CryptoSwiftTests: XCTestCase {
     }
     
     func testMD5() {
-        let data1:NSData = NSData(bytes: [0x31, 0x32, 0x33] as [Byte], length: 3) // "1", "2", "3"
+        let data1:NSData = NSData(bytes: [0x31, 0x32, 0x33] as [UInt8], length: 3) // "1", "2", "3"
         if let hash = Hash.md5(data1).calculate() {
             XCTAssertEqual(hash.hexString, "202CB962AC59075B964B07152D234B70", "MD5 calculation failed");
         } else {
@@ -76,7 +76,7 @@ class CryptoSwiftTests: XCTestCase {
     
     func testMD5PerformanceSwift() {
         self.measureMetrics([XCTPerformanceMetric_WallClockTime], automaticallyStartMeasuring: false, forBlock: { () -> Void in
-            let buf = UnsafeMutablePointer<Byte>(calloc(2048, UInt(sizeof(Byte))))
+            let buf = UnsafeMutablePointer<Byte>(calloc(2048, UInt(sizeof(UInt8))))
             let data = NSData(bytes: buf, length: 2048)
             self.startMeasuring()
             for _ in [0...1000] {
@@ -90,7 +90,7 @@ class CryptoSwiftTests: XCTestCase {
     
     func testMD5PerformanceCommonCrypto() {
         self.measureMetrics([XCTPerformanceMetric_WallClockTime], automaticallyStartMeasuring: false, forBlock: { () -> Void in
-            let buf = UnsafeMutablePointer<Byte>(calloc(2048, UInt(sizeof(Byte))))
+            let buf = UnsafeMutablePointer<Byte>(calloc(2048, UInt(sizeof(UInt8))))
             let data = NSData(bytes: buf, length: 2048)
             self.startMeasuring()
             for _ in [0...1000] {
@@ -107,7 +107,7 @@ class CryptoSwiftTests: XCTestCase {
     }
     
     func testSHA1() {
-        var data:NSData = NSData(bytes: [0x31, 0x32, 0x33] as [Byte], length: 3)
+        var data:NSData = NSData(bytes: [0x31, 0x32, 0x33] as [UInt8], length: 3)
         if let hash = data.sha1() {
             XCTAssertEqual(hash.hexString, "40BD001563085FC35165329EA1FF5C5ECBDBBEEF", "SHA1 calculation failed");
         }
@@ -129,14 +129,14 @@ class CryptoSwiftTests: XCTestCase {
     }
     
     func testSHA224() {
-        var data:NSData = NSData(bytes: [0x31, 0x32, 0x33] as [Byte], length: 3)
+        var data:NSData = NSData(bytes: [0x31, 0x32, 0x33] as [UInt8], length: 3)
         if let hash = data.sha224() {
             XCTAssertEqual(hash.hexString, "78D8045D684ABD2EECE923758F3CD781489DF3A48E1278982466017F", "SHA224 calculation failed");
         }
     }
 
     func testSHA256() {
-        var data:NSData = NSData(bytes: [0x31, 0x32, 0x33] as [Byte], length: 3)
+        var data:NSData = NSData(bytes: [0x31, 0x32, 0x33] as [UInt8], length: 3)
         if let hash = data.sha256() {
             XCTAssertEqual(hash.hexString, "A665A45920422F9D417E4867EFDC4FB8A04A1F3FFF1FA07E998E86F7F7A27AE3", "SHA256 calculation failed");
         }
@@ -154,7 +154,7 @@ class CryptoSwiftTests: XCTestCase {
     }
 
     func testSHA384() {
-        var data:NSData = NSData(bytes: [49, 50, 51] as [Byte], length: 3)
+        var data:NSData = NSData(bytes: [49, 50, 51] as [UInt8], length: 3)
         if let hash = data.sha384() {
             XCTAssertEqual(hash.hexString, "9A0A82F0C0CF31470D7AFFEDE3406CC9AA8410671520B727044EDA15B4C25532A9B5CD8AAF9CEC4919D76255B6BFB00F", "SHA384 calculation failed");
         }
@@ -171,7 +171,7 @@ class CryptoSwiftTests: XCTestCase {
     }
 
     func testSHA512() {
-        var data:NSData = NSData(bytes: [49, 50, 51] as [Byte], length: 3)
+        var data:NSData = NSData(bytes: [49, 50, 51] as [UInt8], length: 3)
         if let hash = data.sha512() {
             XCTAssertEqual(hash.hexString, "3C9909AFEC25354D551DAE21590BB26E38D53F2173B8D3DC3EEE4C047E7AB1C1EB8B85103E3BE7BA613B31BB5C9C36214DC9F14A42FD7A2FDB84856BCA5C44C2", "SHA512 calculation failed");
         }
@@ -188,7 +188,7 @@ class CryptoSwiftTests: XCTestCase {
     }
     
     func testCRC32() {
-        var data:NSData = NSData(bytes: [49, 50, 51] as [Byte], length: 3)
+        var data:NSData = NSData(bytes: [49, 50, 51] as [UInt8], length: 3)
         if let crc = data.crc32() {
             XCTAssertEqual(crc.hexString, "884863D2", "CRC32 calculation failed");
         }

+ 1 - 1
CryptoSwiftTests/Helpers.swift

@@ -8,7 +8,7 @@
 
 import Foundation
 
-func compareMatrix(a:[[Byte]], b:[[Byte]]) -> Bool {
+func compareMatrix(a:[[UInt8]], b:[[UInt8]]) -> Bool {
     for (i,arr) in enumerate(a) {
         for (j,val) in enumerate(arr) {
             if (val != b[i][j]) {

+ 6 - 6
CryptoSwiftTests/PaddingTests.swift

@@ -12,8 +12,8 @@ import CryptoSwift
 
 class PaddingTests: XCTestCase {
     func testPKCS7_0() {
-        let input:[Byte]    = [1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6]
-        let expected:[Byte] = [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:[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 padded = PKCS7(data: NSData.withBytes(input)).addPadding(16)
         XCTAssertEqual(padded, NSData.withBytes(expected), "PKCS7 failed")
         let clean = PKCS7(data: padded).removePadding()
@@ -21,8 +21,8 @@ class PaddingTests: XCTestCase {
     }
     
     func testPKCS7_1() {
-        let input:[Byte]    = [1,2,3,4,5,6,7,8,9,0,1,2,3,4,5]
-        let expected:[Byte] = [1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,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 padded = PKCS7(data: NSData.withBytes(input)).addPadding(16)
         XCTAssertEqual(padded, NSData.withBytes(expected), "PKCS7 failed")
         let clean = PKCS7(data: padded).removePadding()
@@ -30,8 +30,8 @@ class PaddingTests: XCTestCase {
     }
     
     func testPKCS7_2() {
-        let input:[Byte]    = [1,2,3,4,5,6,7,8,9,0,1,2,3,4]
-        let expected:[Byte] = [1,2,3,4,5,6,7,8,9,0,1,2,3,4,2,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 padded = PKCS7(data: NSData.withBytes(input)).addPadding(16)
         XCTAssertEqual(padded, NSData.withBytes(expected), "PKCS7 failed")
         let clean = PKCS7(data: padded).removePadding()

+ 3 - 3
CryptoSwiftTests/Poly1305Tests.swift

@@ -22,9 +22,9 @@ class Poly1305Tests: XCTestCase {
     
     
     func testPoly1305() {
-        let key:[Byte] = [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:[Byte] = [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:[Byte] = [0xdd,0xb9,0xda,0x7d,0xdd,0x5e,0x52,0x79,0x27,0x30,0xed,0x5c,0xda,0x5f,0x90,0xa4]
+        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 mac = Authenticator.Poly1305(key: NSData.withBytes(key)).authenticate(NSData.withBytes(msg))
         XCTAssertEqual(mac!, NSData.withBytes(expectedMac), "Invalid authentication result")