Selaa lähdekoodia

Swift 3 - it compile #stage1

Marcin Krzyżanowski 9 vuotta sitten
vanhempi
commit
280a3d3308
46 muutettua tiedostoa jossa 355 lisäystä ja 358 poistoa
  1. 1 1
      CryptoSwift.playground/Contents.swift
  2. 2 2
      CryptoSwiftTests/ChaCha20Tests.swift
  3. 10 10
      CryptoSwiftTests/RabbitTests.swift
  4. 63 63
      Sources/CryptoSwift/AES.swift
  5. 2 2
      Sources/CryptoSwift/Array+Extension.swift
  6. 3 3
      Sources/CryptoSwift/Authenticator.swift
  7. 1 1
      Sources/CryptoSwift/BlockMode/BlockModeOptions.swift
  8. 2 2
      Sources/CryptoSwift/BlockMode/CBC.swift
  9. 2 2
      Sources/CryptoSwift/BlockMode/CFB.swift
  10. 6 6
      Sources/CryptoSwift/BlockMode/CTR.swift
  11. 1 1
      Sources/CryptoSwift/BlockMode/ECB.swift
  12. 2 2
      Sources/CryptoSwift/BlockMode/OFB.swift
  13. 4 4
      Sources/CryptoSwift/BlockMode/PCBC.swift
  14. 5 7
      Sources/CryptoSwift/BytesSequence.swift
  15. 2 2
      Sources/CryptoSwift/CRC.swift
  16. 19 19
      Sources/CryptoSwift/CSArrayType+Extensions.swift
  17. 25 25
      Sources/CryptoSwift/ChaCha20.swift
  18. 1 1
      Sources/CryptoSwift/Cipher.swift
  19. 1 1
      Sources/CryptoSwift/Cryptors.swift
  20. 1 1
      Sources/CryptoSwift/Foundation/AES+Foundation.swift
  21. 1 1
      Sources/CryptoSwift/Foundation/ArrayUInt8+Foundation.swift
  22. 4 4
      Sources/CryptoSwift/Foundation/CSArrayType+Foundation.swift
  23. 1 1
      Sources/CryptoSwift/Foundation/ChaCha20+Foundation.swift
  24. 17 17
      Sources/CryptoSwift/Foundation/NSData+Extension.swift
  25. 3 3
      Sources/CryptoSwift/Foundation/Rabbit+Foundation.swift
  26. 4 4
      Sources/CryptoSwift/Foundation/String+FoundationExtension.swift
  27. 1 1
      Sources/CryptoSwift/Foundation/Utils+Foundation.swift
  28. 24 24
      Sources/CryptoSwift/Generics.swift
  29. 5 5
      Sources/CryptoSwift/HMAC.swift
  30. 2 2
      Sources/CryptoSwift/Hash.swift
  31. 1 1
      Sources/CryptoSwift/HashProtocol.swift
  32. 11 11
      Sources/CryptoSwift/IntExtension.swift
  33. 2 2
      Sources/CryptoSwift/IntegerConvertible.swift
  34. 5 5
      Sources/CryptoSwift/MD5.swift
  35. 2 2
      Sources/CryptoSwift/PKCS5/PBKDF1.swift
  36. 6 6
      Sources/CryptoSwift/PKCS5/PBKDF2.swift
  37. 5 5
      Sources/CryptoSwift/PKCS7.swift
  38. 23 23
      Sources/CryptoSwift/Poly1305.swift
  39. 21 21
      Sources/CryptoSwift/Rabbit.swift
  40. 7 7
      Sources/CryptoSwift/SHA1.swift
  41. 22 22
      Sources/CryptoSwift/SHA2.swift
  42. 5 5
      Sources/CryptoSwift/String+Extension.swift
  43. 9 9
      Sources/CryptoSwift/UInt32Extension.swift
  44. 3 3
      Sources/CryptoSwift/UInt64Extension.swift
  45. 4 4
      Sources/CryptoSwift/UInt8Extension.swift
  46. 14 15
      Sources/CryptoSwift/Utils.swift

+ 1 - 1
CryptoSwift.playground/Contents.swift

@@ -58,7 +58,7 @@ do {
     inputStream.open()
     outputStream.open()
 
-    var buffer = Array<UInt8>(count: 2, repeatedValue: 0)
+    var buffer = Array<UInt8>(repeating: 0, count: 2)
 
     // encrypt input stream data and write encrypted result to output stream
     while (inputStream.hasBytesAvailable) {

+ 2 - 2
CryptoSwiftTests/ChaCha20Tests.swift

@@ -45,7 +45,7 @@ final class ChaCha20Tests: XCTestCase {
 
         for idx in 0..<keys.count {            
             let expectedHex = expectedHexes[idx]
-            let message = Array<UInt8>(count: (expectedHex.characters.count / 2), repeatedValue: 0)
+            let message = Array<UInt8>(repeating: 0, count: (expectedHex.characters.count / 2))
             
             do {
                 let encrypted = try ChaCha20(key: keys[idx], iv: ivs[idx])!.encrypt(message)
@@ -71,7 +71,7 @@ final class ChaCha20Tests: XCTestCase {
         let key:Array<UInt8> = [0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00]
         let iv:Array<UInt8>  = [0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00]
         let expected:Array<UInt8> = [0x76,0xB8,0xE0,0xAD,0xA0,0xF1,0x3D,0x90,0x40,0x5D,0x6A,0xE5,0x53,0x86,0xBD,0x28,0xBD,0xD2,0x19,0xB8,0xA0,0x8D,0xED,0x1A,0xA8,0x36,0xEF,0xCC,0x8B,0x77,0x0D,0xC7,0xDA,0x41,0x59,0x7C,0x51,0x57,0x48,0x8D,0x77,0x24,0xE0,0x3F,0xB8,0xD8,0x4A,0x37,0x6A,0x43,0xB8,0xF4,0x15,0x18,0xA1,0x1C,0xC3,0x87,0xB6,0x69,0xB2,0xEE,0x65,0x86]
-        let message = Array<UInt8>(count: expected.count, repeatedValue: 0)
+        let message = Array<UInt8>(repeating: 0, count: expected.count)
 
         print(message.count)
 

+ 10 - 10
CryptoSwiftTests/RabbitTests.swift

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

+ 63 - 63
Sources/CryptoSwift/AES.swift

@@ -11,7 +11,7 @@
 private typealias Key = SecureBytes
 
 final public class AES: BlockCipher {
-    public enum Error: ErrorType {
+    public enum Error: ErrorProtocol {
         case DataPaddingRequired
         case InvalidKeyOrInitializationVector
         case InvalidInitializationVector
@@ -51,8 +51,8 @@ final public class AES: BlockCipher {
     private let key: Key
     private let iv:Array<UInt8>
     private let padding:Padding
-    private lazy var expandedKey:Array<Array<UInt32>> = self.expandKey(self.key, variant: self.variant)
-    private lazy var expandedKeyInv:Array<Array<UInt32>> = self.expandKeyInv(self.key, variant: self.variant)
+    private lazy var expandedKey:Array<Array<UInt32>> = self.expandKey(key: self.key, variant: self.variant)
+    private lazy var expandedKeyInv:Array<Array<UInt32>> = self.expandKeyInv(key: self.key, variant: self.variant)
     
     private lazy var sBoxes:(sBox:Array<UInt32>, invSBox:Array<UInt32>) = self.calculateSBox()
     private lazy var sBox:Array<UInt32> = self.sBoxes.sBox
@@ -98,7 +98,7 @@ final public class AES: BlockCipher {
         if let iv = iv where !iv.isEmpty {
             self.iv = iv
         } else {
-            let defaultIV = Array<UInt8>(count: AES.blockSize, repeatedValue: 0)
+            let defaultIV = Array<UInt8>(repeating: 0, count: AES.blockSize)
             self.iv = defaultIV
         }
 
@@ -114,9 +114,9 @@ extension AES {
     private func encryptBlock(block:Array<UInt8>) -> Array<UInt8>? {
         let rounds = self.variant.Nr
         let rk = self.expandedKey
-        var b = toUInt32Array(block[block.startIndex..<block.endIndex])
+        var b = toUInt32Array(slice: block[block.startIndex..<block.endIndex])
 
-        var t = Array<UInt32>(count: 4, repeatedValue: 0)
+        var t = Array<UInt32>(repeating: 0, count: 4)
 
         for r in 0..<rounds - 1 {
             t[0] = b[0] ^ rk[r][0]
@@ -158,10 +158,10 @@ extension AES {
         t[3] = b[3] ^ rk[r][3]
 
         // rounds
-        b[0] = F1(t[0], t[1], t[2], t[3]) ^ rk[rounds][0]
-        b[1] = F1(t[1], t[2], t[3], t[0]) ^ rk[rounds][1]
-        b[2] = F1(t[2], t[3], t[0], t[1]) ^ rk[rounds][2]
-        b[3] = F1(t[3], t[0], t[1], t[2]) ^ rk[rounds][3]
+        b[0] = F1(x0: t[0], t[1], t[2], t[3]) ^ rk[rounds][0]
+        b[1] = F1(x0: t[1], t[2], t[3], t[0]) ^ rk[rounds][1]
+        b[2] = F1(x0: t[2], t[3], t[0], t[1]) ^ rk[rounds][2]
+        b[3] = F1(x0: t[3], t[0], t[1], t[2]) ^ rk[rounds][3]
 
         var out = Array<UInt8>()
         out.reserveCapacity(b.count * 4)
@@ -178,11 +178,11 @@ extension AES {
     private func decryptBlock(block:Array<UInt8>) -> Array<UInt8>? {
         let rounds = self.variant.Nr
         let rk = expandedKeyInv
-        var b = toUInt32Array(block[block.startIndex..<block.endIndex])
+        var b = toUInt32Array(slice: block[block.startIndex..<block.endIndex])
 
-        var t = Array<UInt32>(count: 4, repeatedValue: 0)
+        var t = Array<UInt32>(repeating: 0, count: 4)
 
-        for r in (2...rounds).reverse() {
+        for r in (2...rounds).reversed() {
             t[0] = b[0] ^ rk[r][0]
             t[1] = b[1] ^ rk[r][1]
             t[2] = b[2] ^ rk[r][2]
@@ -221,28 +221,28 @@ extension AES {
 
         // rounds
 
-        let lb00 = sBoxInv[Int(B0(t[0]))]
-        let lb01 = (sBoxInv[Int(B1(t[3]))] << 8)
-        let lb02 = (sBoxInv[Int(B2(t[2]))] << 16)
-        let lb03 = (sBoxInv[Int(B3(t[1]))] << 24)
+        let lb00 = sBoxInv[Int(B0(x: t[0]))]
+        let lb01 = (sBoxInv[Int(B1(x: t[3]))] << 8)
+        let lb02 = (sBoxInv[Int(B2(x: t[2]))] << 16)
+        let lb03 = (sBoxInv[Int(B3(x: t[1]))] << 24)
         b[0] = lb00 | lb01 | lb02 | lb03 ^ rk[0][0]
 
-        let lb10 = sBoxInv[Int(B0(t[1]))]
-        let lb11 = (sBoxInv[Int(B1(t[0]))] << 8)
-        let lb12 = (sBoxInv[Int(B2(t[3]))] << 16)
-        let lb13 = (sBoxInv[Int(B3(t[2]))] << 24)
+        let lb10 = sBoxInv[Int(B0(x: t[1]))]
+        let lb11 = (sBoxInv[Int(B1(x: t[0]))] << 8)
+        let lb12 = (sBoxInv[Int(B2(x: t[3]))] << 16)
+        let lb13 = (sBoxInv[Int(B3(x: t[2]))] << 24)
         b[1] = lb10 | lb11 | lb12 | lb13 ^ rk[0][1]
 
-        let lb20 = sBoxInv[Int(B0(t[2]))]
-        let lb21 = (sBoxInv[Int(B1(t[1]))] << 8)
-        let lb22 = (sBoxInv[Int(B2(t[0]))] << 16)
-        let lb23 = (sBoxInv[Int(B3(t[3]))] << 24)
+        let lb20 = sBoxInv[Int(B0(x: t[2]))]
+        let lb21 = (sBoxInv[Int(B1(x: t[1]))] << 8)
+        let lb22 = (sBoxInv[Int(B2(x: t[0]))] << 16)
+        let lb23 = (sBoxInv[Int(B3(x: t[3]))] << 24)
         b[2] = lb20 | lb21 | lb22 | lb23 ^ rk[0][2]
 
-        let lb30 = sBoxInv[Int(B0(t[3]))]
-        let lb31 = (sBoxInv[Int(B1(t[2]))] << 8)
-        let lb32 = (sBoxInv[Int(B2(t[1]))] << 16)
-        let lb33 = (sBoxInv[Int(B3(t[0]))] << 24)
+        let lb30 = sBoxInv[Int(B0(x: t[3]))]
+        let lb31 = (sBoxInv[Int(B1(x: t[2]))] << 8)
+        let lb32 = (sBoxInv[Int(B2(x: t[1]))] << 16)
+        let lb33 = (sBoxInv[Int(B3(x: t[0]))] << 24)
         b[3] = lb30 | lb31 | lb32 | lb33 ^ rk[0][3]
 
         var out = Array<UInt8>()
@@ -259,22 +259,22 @@ extension AES {
 
     private func expandKeyInv(key: Key, variant: AESVariant) -> Array<Array<UInt32>> {
         let rounds = variant.Nr
-        var rk2:Array<Array<UInt32>> = expandKey(key, variant: variant)
+        var rk2:Array<Array<UInt32>> = expandKey(key: key, variant: variant)
 
         for r in 1..<rounds {
             var w:UInt32
 
             w = rk2[r][0];
-            rk2[r][0] = U1[Int(B0(w))] ^ U2[Int(B1(w))] ^ U3[Int(B2(w))] ^ U4[Int(B3(w))]
+            rk2[r][0] = U1[Int(B0(x: w))] ^ U2[Int(B1(x: w))] ^ U3[Int(B2(x: w))] ^ U4[Int(B3(x: w))]
 
             w = rk2[r][1];
-            rk2[r][1] = U1[Int(B0(w))] ^ U2[Int(B1(w))] ^ U3[Int(B2(w))] ^ U4[Int(B3(w))]
+            rk2[r][1] = U1[Int(B0(x: w))] ^ U2[Int(B1(x: w))] ^ U3[Int(B2(x: w))] ^ U4[Int(B3(x: w))]
 
             w = rk2[r][2];
-            rk2[r][2] = U1[Int(B0(w))] ^ U2[Int(B1(w))] ^ U3[Int(B2(w))] ^ U4[Int(B3(w))]
+            rk2[r][2] = U1[Int(B0(x: w))] ^ U2[Int(B1(x: w))] ^ U3[Int(B2(x: w))] ^ U4[Int(B3(x: w))]
 
             w = rk2[r][3];
-            rk2[r][3] = U1[Int(B0(w))] ^ U2[Int(B1(w))] ^ U3[Int(B2(w))] ^ U4[Int(B3(w))]
+            rk2[r][3] = U1[Int(B0(x: w))] ^ U2[Int(B1(x: w))] ^ U3[Int(B2(x: w))] ^ U4[Int(B3(x: w))]
         }
 
         return rk2
@@ -284,15 +284,15 @@ extension AES {
 
         func convertExpandedKey(expanded:Array<UInt8>) -> Array<Array<UInt32>> {
             var arr = Array<UInt32>()
-            for idx in expanded.startIndex.stride(to: expanded.endIndex, by: 4) {
-                let four = Array(expanded[idx..<idx.advancedBy(4)].reverse())
-                let num = UInt32.withBytes(four)
+            for idx in stride(from: expanded.startIndex, to: expanded.endIndex, by: 4) {
+                let four = Array(expanded[idx..<idx.advanced(by: 4)].reversed())
+                let num = UInt32.withBytes(bytes: four)
                 arr.append(num)
             }
 
             var allarr = Array<Array<UInt32>>()
-            for idx in arr.startIndex.stride(to: arr.endIndex, by: 4) {
-                allarr.append(Array(arr[idx..<idx.advancedBy(4)]))
+            for idx in stride(from: arr.startIndex, to: arr.endIndex, by: 4) {
+                allarr.append(Array(arr[idx..<idx.advanced(by: 4)]))
             }
             return allarr
         }
@@ -310,7 +310,7 @@ extension AES {
             return result
         }
 
-        var w = Array<UInt8>(count: variant.Nb * (variant.Nr + 1) * 4, repeatedValue: 0)
+        var w = Array<UInt8>(repeating: 0, count: variant.Nb * (variant.Nr + 1) * 4)
         for i in 0..<variant.Nk {
             for wordIdx in 0..<4 {
                 w[(4*i)+wordIdx] = key[(4*i)+wordIdx]
@@ -320,16 +320,16 @@ extension AES {
         var tmp:Array<UInt8>
 
         for i in variant.Nk..<variant.Nb * (variant.Nr + 1) {
-            tmp = Array<UInt8>(count: 4, repeatedValue: 0)
+            tmp = Array<UInt8>(repeating: 0, count: 4)
 
             for wordIdx in 0..<4 {
                 tmp[wordIdx] = w[4*(i-1)+wordIdx]
             }
             if ((i % variant.Nk) == 0) {
-                tmp = subWord(rotateLeft(UInt32.withBytes(tmp), 8).bytes(sizeof(UInt32)))
+                tmp = subWord(word: rotateLeft(v: UInt32.withBytes(bytes: tmp), 8).bytes(totalBytes: sizeof(UInt32)))
                 tmp[0] = tmp.first! ^ Rcon[i/variant.Nk]
             } else if (variant.Nk > 6 && (i % variant.Nk) == 4) {
-                tmp = subWord(tmp)
+                tmp = subWord(word: tmp)
             }
 
             // xor array of bytes
@@ -337,7 +337,7 @@ extension AES {
                 w[4*i+wordIdx] = w[4*(i-variant.Nk)+wordIdx]^tmp[wordIdx];
             }
         }
-        return convertExpandedKey(w)
+        return convertExpandedKey(expanded: w)
     }
 
     private func B0(x: UInt32) -> UInt32 {
@@ -358,15 +358,15 @@ extension AES {
     
     private func F1(x0: UInt32, _ x1: UInt32, _ x2: UInt32, _ x3: UInt32) -> UInt32 {
         var result:UInt32 = 0
-        result |= UInt32(B1(T0[Int(x0 & 255)]))
-        result |= UInt32(B1(T0[Int((x1 >> 8) & 255)])) << 8
-        result |= UInt32(B1(T0[Int((x2 >> 16) & 255)])) << 16
-        result |= UInt32(B1(T0[Int(x3 >> 24)])) << 24
+        result |= UInt32(B1(x: T0[Int(x0 & 255)]))
+        result |= UInt32(B1(x: T0[Int((x1 >> 8) & 255)])) << 8
+        result |= UInt32(B1(x: T0[Int((x2 >> 16) & 255)])) << 16
+        result |= UInt32(B1(x: T0[Int(x3 >> 24)])) << 24
         return result
     }
     
     private func calculateSBox() -> (sBox:Array<UInt32>, invSBox:Array<UInt32>) {
-        var sbox = Array<UInt32>(count: 256, repeatedValue: 0)
+        var sbox = Array<UInt32>(repeating: 0, count: 256)
         var invsbox = sbox
         sbox[0] = 0x63
         
@@ -379,7 +379,7 @@ extension AES {
             q ^= q << 4
             q ^= (q & 0x80) == 0x80 ? 0x09 : 0
             
-            let s = 0x63 ^ q ^ rotateLeft(q, 1) ^ rotateLeft(q, 2) ^ rotateLeft(q, 3) ^ rotateLeft(q, 4)
+            let s = 0x63 ^ q ^ rotateLeft(v: q, 1) ^ rotateLeft(v: q, 2) ^ rotateLeft(v: q, 3) ^ rotateLeft(v: q, 4)
             
             sbox[Int(p)] = UInt32(s)
             invsbox[Int(s)] = UInt32(p)
@@ -399,7 +399,7 @@ extension AES {
 
         init(aes: AES) {
             self.padding = aes.padding;
-            self.worker = aes.blockMode.worker(aes.iv, cipherOperation: aes.encryptBlock)
+            self.worker = aes.blockMode.worker(iv: aes.iv, cipherOperation: aes.encryptBlock)
             self.paddingRequired = aes.blockMode.options.contains(.PaddingRequired)
         }
 
@@ -407,15 +407,15 @@ extension AES {
             self.accumulated += bytes
 
             if (isLast) {
-                self.accumulated = padding.add(self.accumulated, blockSize: AES.blockSize)
+                self.accumulated = padding.add(data: self.accumulated, blockSize: AES.blockSize)
             }
 
             //CTR does not require full block therefore work with anything
             var encrypted = Array<UInt8>()
             encrypted.reserveCapacity(self.accumulated.count)
-            for chunk in self.accumulated.chunks(AES.blockSize) {
+            for chunk in self.accumulated.chunks(chunksize: AES.blockSize) {
                 if (!self.paddingRequired || self.accumulated.count >= AES.blockSize) {
-                    encrypted += worker.encrypt(chunk)
+                    encrypted += worker.encrypt(plaintext: chunk)
                     self.accumulated.removeFirst(chunk.count)
                 }
             }
@@ -438,9 +438,9 @@ extension AES {
             switch (aes.blockMode) {
             case .CFB, .OFB, .CTR:
                 // CFB, OFB, CTR uses encryptBlock to decrypt
-                self.worker = aes.blockMode.worker(aes.iv, cipherOperation: aes.encryptBlock)
+                self.worker = aes.blockMode.worker(iv: aes.iv, cipherOperation: aes.encryptBlock)
             default:
-                self.worker = aes.blockMode.worker(aes.iv, cipherOperation: aes.decryptBlock)
+                self.worker = aes.blockMode.worker(iv: aes.iv, cipherOperation: aes.decryptBlock)
             }
 
             self.paddingRequired = aes.blockMode.options.contains(.PaddingRequired);
@@ -451,15 +451,15 @@ extension AES {
 
             var plaintext = Array<UInt8>()
             plaintext.reserveCapacity(self.accumulated.count)
-            for chunk in self.accumulated.chunks(AES.blockSize) {
+            for chunk in self.accumulated.chunks(chunksize: AES.blockSize) {
                 if (!self.paddingRequired || self.accumulated.count >= AES.blockSize) {
-                    plaintext += worker.decrypt(chunk)
+                    plaintext += worker.decrypt(ciphertext: chunk)
                     self.accumulated.removeFirst(chunk.count)
                 }
             }
 
             if (isLast) {
-                plaintext = padding.remove(plaintext, blockSize: AES.blockSize)
+                plaintext = padding.remove(data: plaintext, blockSize: AES.blockSize)
             }
 
             return plaintext
@@ -482,12 +482,12 @@ extension AES: Cryptors {
 // MARK: Cipher
 extension AES: Cipher {
     public func encrypt(bytes:Array<UInt8>) throws -> Array<UInt8> {
-        let chunks = bytes.chunks(AES.blockSize)
+        let chunks = bytes.chunks(chunksize: AES.blockSize)
 
         var oneTimeCryptor = self.makeEncryptor()
         var out = Array<UInt8>()
         out.reserveCapacity(bytes.count)
-        for (idx, block) in chunks.enumerate() {
+        for (idx, block) in chunks.enumerated() {
             out += try oneTimeCryptor.update(withBytes: block, isLast: idx == max(0,chunks.count - 1))
         }
 
@@ -504,10 +504,10 @@ extension AES: Cipher {
         }
 
         var oneTimeCryptor = self.makeDecryptor()
-        let chunks = bytes.chunks(AES.blockSize)
+        let chunks = bytes.chunks(chunksize: AES.blockSize)
         var out = Array<UInt8>()
         out.reserveCapacity(bytes.count)
-        for (idx,chunk) in chunks.enumerate() {
+        for (idx,chunk) in chunks.enumerated() {
             out += try oneTimeCryptor.update(withBytes: chunk, isLast: idx == max(0,chunks.count - 1))
         }
         return out

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

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

+ 3 - 3
Sources/CryptoSwift/Authenticator.swift

@@ -11,7 +11,7 @@
 */
 public enum Authenticator {
     
-    public enum Error: ErrorType {
+    public enum Error: ErrorProtocol {
         case AuthenticateError
     }
     
@@ -31,12 +31,12 @@ public enum Authenticator {
     public func authenticate(message: Array<UInt8>) throws -> Array<UInt8> {
         switch (self) {
         case .Poly1305(let key):
-            guard let auth = CryptoSwift.Poly1305(key: key)?.authenticate(message) else {
+            guard let auth = CryptoSwift.Poly1305(key: key)?.authenticate(message: message) else {
                 throw Error.AuthenticateError
             }
             return auth
         case .HMAC(let key, let variant):
-            guard let auth = CryptoSwift.HMAC(key: key, variant: variant)?.authenticate(message) else {
+            guard let auth = CryptoSwift.HMAC(key: key, variant: variant)?.authenticate(message: message) else {
                 throw Error.AuthenticateError
             }
             return auth

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

@@ -6,7 +6,7 @@
 //  Copyright © 2016 Marcin Krzyzanowski. All rights reserved.
 //
 
-struct BlockModeOptions: OptionSetType {
+struct BlockModeOptions: OptionSet {
     let rawValue: Int
 
     static let None = BlockModeOptions(rawValue: 0)

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

@@ -21,7 +21,7 @@ struct CBCModeWorker: BlockModeWorker {
     }
 
     mutating func encrypt(plaintext: Array<UInt8>) -> Array<UInt8> {
-        guard let ciphertext = cipherOperation(block: xor(prev ?? iv, plaintext)) else {
+        guard let ciphertext = cipherOperation(block: xor(a: prev ?? iv, plaintext)) else {
             return plaintext
         }
         prev = ciphertext
@@ -32,7 +32,7 @@ struct CBCModeWorker: BlockModeWorker {
         guard let plaintext = cipherOperation(block: ciphertext) else {
             return ciphertext
         }
-        let result = xor(prev ?? iv, plaintext)
+        let result = xor(a: prev ?? iv, plaintext)
         self.prev = ciphertext
         return result
     }

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

@@ -24,7 +24,7 @@ struct CFBModeWorker: BlockModeWorker {
         guard let ciphertext = cipherOperation(block: prev ?? iv) else {
             return plaintext
         }
-        prev = xor(plaintext, ciphertext)
+        prev = xor(a: plaintext, ciphertext)
         return prev ?? []
     }
 
@@ -32,7 +32,7 @@ struct CFBModeWorker: BlockModeWorker {
         guard let plaintext = cipherOperation(block: prev ?? iv) else {
             return ciphertext
         }
-        let result = xor(plaintext, ciphertext)
+        let result = xor(a: plaintext, ciphertext)
         self.prev = ciphertext
         return result
     }

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

@@ -21,24 +21,24 @@ struct CTRModeWorker: BlockModeWorker {
     }
 
     mutating func encrypt(plaintext: Array<UInt8>) -> Array<UInt8> {
-        let nonce = buildNonce(iv, counter: UInt64(counter))
+        let nonce = buildNonce(iv: iv, counter: UInt64(counter))
         counter = counter + 1
 
         guard let ciphertext = cipherOperation(block: nonce) else {
             return plaintext
         }
 
-        return xor(plaintext, ciphertext)
+        return xor(a: plaintext, ciphertext)
     }
 
     mutating func decrypt(ciphertext: Array<UInt8>) -> Array<UInt8> {
-        let nonce = buildNonce(iv, counter: UInt64(counter))
+        let nonce = buildNonce(iv: iv, counter: UInt64(counter))
         counter = counter + 1
 
         guard let plaintext = cipherOperation(block: nonce) else {
             return ciphertext
         }
-        return xor(plaintext, ciphertext)
+        return xor(a: plaintext, ciphertext)
     }
 }
 
@@ -46,6 +46,6 @@ private func buildNonce(iv: Array<UInt8>, counter: UInt64) -> Array<UInt8> {
     let noncePartLen = AES.blockSize / 2
     let noncePrefix = Array(iv[0..<noncePartLen])
     let nonceSuffix = Array(iv[noncePartLen..<iv.count])
-    let c = UInt64.withBytes(nonceSuffix) + counter
-    return noncePrefix + arrayOfBytes(c)
+    let c = UInt64.withBytes(bytes: nonceSuffix) + counter
+    return noncePrefix + arrayOfBytes(value: c)
 }

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

@@ -24,6 +24,6 @@ struct ECBModeWorker: BlockModeWorker {
     }
 
     mutating func decrypt(ciphertext: Array<UInt8>) -> Array<UInt8> {
-        return encrypt(ciphertext)
+        return encrypt(plaintext: ciphertext)
     }
 }

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

@@ -25,14 +25,14 @@ struct OFBModeWorker: BlockModeWorker {
             return plaintext
         }
         prev = ciphertext
-        return xor(plaintext, ciphertext)
+        return xor(a: plaintext, ciphertext)
     }
 
     mutating func decrypt(ciphertext: Array<UInt8>) -> Array<UInt8> {
         guard let decrypted = cipherOperation(block: prev ?? iv) else {
             return ciphertext
         }
-        let plaintext = xor(decrypted, ciphertext)
+        let plaintext = xor(a: decrypted, ciphertext)
         self.prev = decrypted
         return plaintext
     }

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

@@ -21,10 +21,10 @@ struct PCBCModeWorker: BlockModeWorker {
     }
 
     mutating func encrypt(plaintext: Array<UInt8>) -> Array<UInt8> {
-        guard let ciphertext = cipherOperation(block: xor(prev ?? iv, plaintext)) else {
+        guard let ciphertext = cipherOperation(block: xor(a: prev ?? iv, plaintext)) else {
             return plaintext
         }
-        prev = xor(plaintext, ciphertext)
+        prev = xor(a: plaintext, ciphertext)
         return ciphertext ?? []
     }
 
@@ -32,8 +32,8 @@ struct PCBCModeWorker: BlockModeWorker {
         guard let plaintext = cipherOperation(block: ciphertext) else {
             return ciphertext
         }
-        let result = xor(prev ?? iv, plaintext)
-        self.prev = xor(plaintext, ciphertext)
+        let result = xor(a: prev ?? iv, plaintext)
+        self.prev = xor(a: plaintext, ciphertext)
         return result
     }
 }

+ 5 - 7
Sources/CryptoSwift/BytesSequence.swift

@@ -6,16 +6,14 @@
 //  Copyright © 2015 Marcin Krzyzanowski. All rights reserved.
 //
 
-struct BytesSequence: SequenceType {
+struct BytesSequence: Sequence {
     let chunkSize: Int
     let data: Array<UInt8>
-    
-    func generate() -> AnyGenerator<ArraySlice<UInt8>> {
-        
+
+    func makeIterator() -> AnyIterator<ArraySlice<UInt8>> {
         var offset:Int = 0
-        
-        return AnyGenerator {
-            let end = min(self.chunkSize, self.data.count - offset)
+        return AnyIterator {
+            let end = Swift.min(self.chunkSize, self.data.count - offset)
             let result = self.data[offset..<offset + end]
             offset += result.count
             return !result.isEmpty ? result : nil

+ 2 - 2
Sources/CryptoSwift/CRC.swift

@@ -78,11 +78,11 @@ final class CRC {
         var crc:UInt32 = seed != nil ? seed! : 0xffffffff
         for chunk in BytesSequence(chunkSize: 256, data: message) {
             for b in chunk {
-                let idx = Int((crc ^ UInt32(reflect ? b : reverseUInt8(b))) & 0xff)
+                let idx = Int((crc ^ UInt32(reflect ? b : reverseUInt8(uint8: b))) & 0xff)
                 crc = (crc >> 8) ^ CRC.table32[idx]
             }
         }
-        return (reflect ? crc : reverseUInt32(crc)) ^ 0xffffffff
+        return (reflect ? crc : reverseUInt32(uint32: crc)) ^ 0xffffffff
     }
     
     func crc16(message:Array<UInt8>, seed: UInt16? = nil) -> UInt16 {

+ 19 - 19
Sources/CryptoSwift/CSArrayType+Extensions.swift

@@ -6,64 +6,64 @@
 //  Copyright © 2015 Marcin Krzyzanowski. All rights reserved.
 //
 
-public protocol CSArrayType: _ArrayType {
-    func cs_arrayValue() -> [Generator.Element]
+public protocol CSArrayType: Collection, RangeReplaceableCollection {
+    func cs_arrayValue() -> [Iterator.Element]
 }
 
 extension Array: CSArrayType {
-    public func cs_arrayValue() -> [Generator.Element] {
+    public func cs_arrayValue() -> [Iterator.Element] {
         return self
     }
 }
 
-public extension CSArrayType where Generator.Element == UInt8 {
+public extension CSArrayType where Iterator.Element == UInt8 {
     public func toHexString() -> String {
         return self.lazy.reduce("") { $0 + String(format:"%02x", $1) }
     }
 }
 
-public extension CSArrayType where Generator.Element == UInt8 {
-    public func md5() -> [Generator.Element] {
+public extension CSArrayType where Iterator.Element == UInt8 {
+    public func md5() -> [Iterator.Element] {
         return Hash.md5(cs_arrayValue()).calculate()
     }
     
-    public func sha1() -> [Generator.Element] {
+    public func sha1() -> [Iterator.Element] {
         return Hash.sha1(cs_arrayValue()).calculate()
     }
     
-    public func sha224() -> [Generator.Element] {
+    public func sha224() -> [Iterator.Element] {
         return Hash.sha224(cs_arrayValue()).calculate()
     }
     
-    public func sha256() -> [Generator.Element] {
+    public func sha256() -> [Iterator.Element] {
         return Hash.sha256(cs_arrayValue()).calculate()
     }
     
-    public func sha384() -> [Generator.Element] {
+    public func sha384() -> [Iterator.Element] {
         return Hash.sha384(cs_arrayValue()).calculate()
     }
     
-    public func sha512() -> [Generator.Element] {
+    public func sha512() -> [Iterator.Element] {
         return Hash.sha512(cs_arrayValue()).calculate()
     }
     
-    public func crc32(seed: UInt32? = nil, reflect : Bool = true) -> [Generator.Element] {
+    public func crc32(seed: UInt32? = nil, reflect : Bool = true) -> [Iterator.Element] {
         return Hash.crc32(cs_arrayValue(), seed: seed, reflect: reflect).calculate()
     }
     
-    public func crc16(seed: UInt16? = nil) -> [Generator.Element] {
+    public func crc16(seed: UInt16? = nil) -> [Iterator.Element] {
         return Hash.crc16(cs_arrayValue(), seed: seed).calculate()
     }
     
-    public func encrypt(cipher: Cipher) throws -> [Generator.Element] {
-        return try cipher.encrypt(cs_arrayValue())
+    public func encrypt(cipher: Cipher) throws -> [Iterator.Element] {
+        return try cipher.encrypt(bytes: cs_arrayValue())
     }
 
-    public func decrypt(cipher: Cipher) throws -> [Generator.Element] {
-        return try cipher.decrypt(cs_arrayValue())
+    public func decrypt(cipher: Cipher) throws -> [Iterator.Element] {
+        return try cipher.decrypt(bytes: cs_arrayValue())
     }
     
-    public func authenticate(authenticator: Authenticator) throws -> [Generator.Element] {
-        return try authenticator.authenticate(cs_arrayValue())
+    public func authenticate(authenticator: Authenticator) throws -> [Iterator.Element] {
+        return try authenticator.authenticate(message: cs_arrayValue())
     }
 }

+ 25 - 25
Sources/CryptoSwift/ChaCha20.swift

@@ -8,7 +8,7 @@
 
 final public class ChaCha20: BlockCipher {
     
-    public enum Error: ErrorType {
+    public enum Error: ErrorProtocol {
         case MissingContext
     }
     
@@ -17,7 +17,7 @@ final public class ChaCha20: BlockCipher {
     private var context:Context?
     
     final private class Context {
-        var input:Array<UInt32> = Array<UInt32>(count: 16, repeatedValue: 0)
+        var input:Array<UInt32> = Array<UInt32>(repeating: 0, count: 16)
         
         deinit {
             for i in 0..<input.count {
@@ -42,14 +42,14 @@ final public class ChaCha20: BlockCipher {
         var x = input
 
         for _ in 0..<10 {
-            quarterround(&x[0], &x[4], &x[8], &x[12])
-            quarterround(&x[1], &x[5], &x[9],  &x[13])
-            quarterround(&x[2], &x[6], &x[10], &x[14])
-            quarterround(&x[3], &x[7], &x[11], &x[15])
-            quarterround(&x[0], &x[5], &x[10], &x[15])
-            quarterround(&x[1], &x[6], &x[11], &x[12])
-            quarterround(&x[2], &x[7], &x[8],  &x[13])
-            quarterround(&x[3], &x[4], &x[9],  &x[14])
+            quarterround(a: &x[0], &x[4], &x[8], &x[12])
+            quarterround(a: &x[1], &x[5], &x[9],  &x[13])
+            quarterround(a: &x[2], &x[6], &x[10], &x[14])
+            quarterround(a: &x[3], &x[7], &x[11], &x[15])
+            quarterround(a: &x[0], &x[5], &x[10], &x[15])
+            quarterround(a: &x[1], &x[6], &x[11], &x[12])
+            quarterround(a: &x[2], &x[7], &x[8],  &x[13])
+            quarterround(a: &x[3], &x[4], &x[9],  &x[14])
         }
 
         var output = Array<UInt8>()
@@ -57,13 +57,13 @@ final public class ChaCha20: BlockCipher {
 
         for i in 0..<16 {
             x[i] = x[i] &+ input[i]
-            output.appendContentsOf(x[i].bytes().reverse())
+            output.append(contentsOf: x[i].bytes().reversed())
         }
 
         return output;
     }
         
-    private func contextSetup(iv  iv:Array<UInt8>, key:Array<UInt8>) -> Context? {
+    private func contextSetup(iv:Array<UInt8>, key:Array<UInt8>) -> Context? {
         let ctx = Context()
         let kbits = key.count * 8
         
@@ -74,7 +74,7 @@ final public class ChaCha20: BlockCipher {
         // 4 - 8
         for i in 0..<4 {
             let start = i * 4
-            ctx.input[i + 4] = wordNumber(key[start..<(start + 4)])
+            ctx.input[i + 4] = wordNumber(bytes: key[start..<(start + 4)])
         }
         
         var addPos = 0;
@@ -100,14 +100,14 @@ final public class ChaCha20: BlockCipher {
             let start = addPos + (i*4)
             
             let bytes = key[start..<(start + 4)]
-            ctx.input[i + 8] = wordNumber(bytes)
+            ctx.input[i + 8] = wordNumber(bytes: bytes)
         }
 
         // iv
         ctx.input[12] = 0
         ctx.input[13] = 0
-        ctx.input[14] = wordNumber(iv[0..<4])
-        ctx.input[15] = wordNumber(iv[4..<8])
+        ctx.input[14] = wordNumber(bytes: iv[0..<4])
+        ctx.input[15] = wordNumber(bytes: iv[4..<8])
         
         return ctx
     }
@@ -118,14 +118,14 @@ final public class ChaCha20: BlockCipher {
             throw Error.MissingContext
         }
         
-        var c:Array<UInt8> = Array<UInt8>(count: message.count, repeatedValue: 0)
+        var c:Array<UInt8> = Array<UInt8>(repeating: 0, count: message.count)
         
         var cPos:Int = 0
         var mPos:Int = 0
         var bytes = message.count
         
         while (true) {
-            if let output = wordToByte(ctx.input) {
+            if let output = wordToByte(input: ctx.input) {
                 ctx.input[12] = ctx.input[12] &+ 1
                 if (ctx.input[12] == 0) {
                     ctx.input[13] = ctx.input[13] &+ 1
@@ -147,18 +147,18 @@ final public class ChaCha20: BlockCipher {
         }
     }
     
-    private final func quarterround(inout a:UInt32, inout _ b:UInt32, inout _ c:UInt32, inout _ d:UInt32) {
+    private final func quarterround(a:inout UInt32, _ b:inout UInt32, _ c:inout UInt32, _ d:inout UInt32) {
         a = a &+ b
-        d = rotateLeft((d ^ a), 16) //FIXME: WAT? n:
+        d = rotateLeft(v: (d ^ a), 16) //FIXME: WAT? n:
         
         c = c &+ d
-        b = rotateLeft((b ^ c), 12);
+        b = rotateLeft(v: (b ^ c), 12);
         
         a = a &+ b
-        d = rotateLeft((d ^ a), 8);
+        d = rotateLeft(v: (d ^ a), 8);
 
         c = c &+ d
-        b = rotateLeft((b ^ c), 7);
+        b = rotateLeft(v: (b ^ c), 7);
     }
 }
 
@@ -169,11 +169,11 @@ extension ChaCha20: Cipher {
             throw Error.MissingContext
         }
 
-        return try encryptBytes(bytes)
+        return try encryptBytes(message: bytes)
     }
 
     public func decrypt(bytes:Array<UInt8>) throws -> Array<UInt8> {
-        return try encrypt(bytes)
+        return try encrypt(bytes: bytes)
     }
 }
 

+ 1 - 1
Sources/CryptoSwift/Cipher.swift

@@ -6,7 +6,7 @@
 //  Copyright © 2016 Marcin Krzyzanowski. All rights reserved.
 //
 
-public enum CipherError: ErrorType {
+public enum CipherError: ErrorProtocol {
     case Encrypt
     case Decrypt
 }

+ 1 - 1
Sources/CryptoSwift/Cryptors.swift

@@ -30,7 +30,7 @@ extension Cryptors {
     static public func randomIV(blockSize:Int) -> Array<UInt8> {
         var randomIV:Array<UInt8> = Array<UInt8>();
         for _ in 0..<blockSize {
-            randomIV.append(UInt8(truncatingBitPattern: cs_arc4random_uniform(256)));
+            randomIV.append(UInt8(truncatingBitPattern: cs_arc4random_uniform(upperBound: 256)));
         }
         return randomIV
     }

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

@@ -10,7 +10,7 @@ import Foundation
 
 extension AES {
     convenience public init(key:String, iv:String, blockMode:BlockMode = .CBC, padding: Padding = PKCS7()) throws {
-        guard let kkey = key.bridge().dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)?.arrayOfBytes(), let iiv = iv.bridge().dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)?.arrayOfBytes() else {
+        guard let kkey = key.bridge().data(using: NSUTF8StringEncoding, allowLossyConversion: false)?.arrayOfBytes(), let iiv = iv.bridge().data(using: NSUTF8StringEncoding, allowLossyConversion: false)?.arrayOfBytes() else {
             throw Error.InvalidKeyOrInitializationVector
         }
         

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

@@ -10,7 +10,7 @@ import Foundation
 
 extension Array where Element: _UInt8Type {
     public init(_ data: NSData) {
-        self = Array<Element>(count: data.length, repeatedValue: Element.Zero())
+        self = Array<Element>(repeating: Element.Zero(), count: data.length)
         data.getBytes(&self, length: self.count)
     }
 }

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

@@ -8,22 +8,22 @@
 
 import Foundation
 
-public extension CSArrayType where Generator.Element == UInt8 {
+public extension CSArrayType where Iterator.Element == UInt8 {
     public func toBase64() -> String? {
         guard let bytesArray = self as? Array<UInt8> else {
             return nil
         }
 
-        return NSData(bytes: bytesArray).base64EncodedStringWithOptions([])
+        return NSData(bytes: bytesArray).base64EncodedString([])
     }
 
     public init(base64: String) {
         self.init()
 
-        guard let decodedData = NSData(base64EncodedString: base64, options: []) else {
+        guard let decodedData = NSData(base64Encoded: base64, options: []) else {
             return
         }
 
-        self.appendContentsOf(decodedData.arrayOfBytes())
+        self.append(contentsOf: decodedData.arrayOfBytes())
     }
 }

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

@@ -10,7 +10,7 @@ import Foundation
 
 extension ChaCha20 {
     convenience public init?(key:String, iv:String) {
-        guard let kkey = key.bridge().dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)?.arrayOfBytes(), let iiv = iv.bridge().dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)?.arrayOfBytes() else {
+        guard let kkey = key.bridge().data(using: NSUTF8StringEncoding, allowLossyConversion: false)?.arrayOfBytes(), let iiv = iv.bridge().data(using: NSUTF8StringEncoding, allowLossyConversion: false)?.arrayOfBytes() else {
             return nil
         }
         self.init(key: kkey, iv: iiv)

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

@@ -12,7 +12,7 @@ extension NSMutableData {
     
     /** Convenient way to append bytes */
     internal func appendBytes(arrayOfBytes: Array<UInt8>) {
-        self.appendBytes(arrayOfBytes, length: arrayOfBytes.count)
+        self.append(arrayOfBytes, length: arrayOfBytes.count)
     }
     
 }
@@ -32,57 +32,57 @@ extension NSData {
     
     @nonobjc public func md5() -> NSData {
         let result = Hash.md5(self.arrayOfBytes()).calculate()
-        return NSData.withBytes(result)
+        return NSData.withBytes(bytes: result)
     }
 
     public func sha1() -> NSData? {
         let result = Hash.sha1(self.arrayOfBytes()).calculate()
-        return NSData.withBytes(result)
+        return NSData.withBytes(bytes: result)
     }
 
     public func sha224() -> NSData? {
         let result = Hash.sha224(self.arrayOfBytes()).calculate()
-        return NSData.withBytes(result)
+        return NSData.withBytes(bytes: result)
     }
 
     public func sha256() -> NSData? {
         let result = Hash.sha256(self.arrayOfBytes()).calculate()
-        return NSData.withBytes(result)
+        return NSData.withBytes(bytes: result)
     }
 
     public func sha384() -> NSData? {
         let result = Hash.sha384(self.arrayOfBytes()).calculate()
-        return NSData.withBytes(result)
+        return NSData.withBytes(bytes: result)
     }
 
     public func sha512() -> NSData? {
         let result = Hash.sha512(self.arrayOfBytes()).calculate()
-        return NSData.withBytes(result)
+        return NSData.withBytes(bytes: result)
     }
 
     public func crc32(seed: UInt32? = nil, reflect : Bool = true) -> NSData? {
         let result = Hash.crc32(self.arrayOfBytes(), seed: seed, reflect: reflect).calculate()
-        return NSData.withBytes(result)
+        return NSData.withBytes(bytes: result)
     }
 
     public func crc16(seed: UInt16? = nil) -> NSData? {
         let result = Hash.crc16(self.arrayOfBytes(), seed: seed).calculate()
-        return NSData.withBytes(result)
+        return NSData.withBytes(bytes: result)
     }
 
     public func encrypt(cipher: Cipher) throws -> NSData {
-        let encrypted = try cipher.encrypt(self.arrayOfBytes())
-        return NSData.withBytes(encrypted)
+        let encrypted = try cipher.encrypt(bytes: self.arrayOfBytes())
+        return NSData.withBytes(bytes: encrypted)
     }
 
     public func decrypt(cipher: Cipher) throws -> NSData {
-        let decrypted = try cipher.decrypt(self.arrayOfBytes())
-        return NSData.withBytes(decrypted)
+        let decrypted = try cipher.decrypt(bytes: self.arrayOfBytes())
+        return NSData.withBytes(bytes: decrypted)
     }
     
     public func authenticate(authenticator: Authenticator) throws -> NSData {
-        let result = try authenticator.authenticate(self.arrayOfBytes())
-        return NSData.withBytes(result)
+        let result = try authenticator.authenticate(message: self.arrayOfBytes())
+        return NSData.withBytes(bytes: result)
     }
 }
 
@@ -94,13 +94,13 @@ extension NSData {
     
     public func arrayOfBytes() -> Array<UInt8> {
         let count = self.length / sizeof(UInt8)
-        var bytesArray = Array<UInt8>(count: count, repeatedValue: 0)
+        var bytesArray = Array<UInt8>(repeating: 0, count: count)
         self.getBytes(&bytesArray, length:count * sizeof(UInt8))
         return bytesArray
     }
 
     public convenience init(bytes: Array<UInt8>) {
-        self.init(data: NSData.withBytes(bytes))
+        self.init(data: NSData.withBytes(bytes: bytes))
     }
     
     class public func withBytes(bytes: Array<UInt8>) -> NSData {

+ 3 - 3
Sources/CryptoSwift/Foundation/Rabbit+Foundation.swift

@@ -10,7 +10,7 @@ import Foundation
 
 extension Rabbit {
     convenience public init?(key: String) {
-        guard let kkey = key.bridge().dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)?.arrayOfBytes() else {
+        guard let kkey = key.bridge().data(using: NSUTF8StringEncoding, allowLossyConversion: false)?.arrayOfBytes() else {
             return nil
         }
         self.init(key: kkey)
@@ -18,8 +18,8 @@ extension Rabbit {
     }
     
     convenience public init?(key: String, iv: String) {
-        guard let kkey = key.bridge().dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)?.arrayOfBytes(),
-            let iiv = iv.bridge().dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)?.arrayOfBytes()
+        guard let kkey = key.bridge().data(using: NSUTF8StringEncoding, allowLossyConversion: false)?.arrayOfBytes(),
+            let iiv = iv.bridge().data(using: NSUTF8StringEncoding, allowLossyConversion: false)?.arrayOfBytes()
             else {
                 return nil
         }

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

@@ -12,11 +12,11 @@ extension String {
 
     /// Return Base64 back to String
     public func decryptBase64ToString(cipher: Cipher) throws -> String {
-        guard let decodedData = NSData(base64EncodedString: self, options: []) else {
+        guard let decodedData = NSData(base64Encoded: self, options: []) else {
             throw CipherError.Decrypt
         }
 
-        let decrypted = try decodedData.decrypt(cipher)
+        let decrypted = try decodedData.decrypt(cipher: cipher)
 
         if let decryptedString = String(data: decrypted, encoding: NSUTF8StringEncoding) {
             return decryptedString
@@ -26,11 +26,11 @@ extension String {
     }
 
     public func decryptBase64(cipher: Cipher) throws -> Array<UInt8> {
-        guard let decodedData = NSData(base64EncodedString: self, options: []) else {
+        guard let decodedData = NSData(base64Encoded: self, options: []) else {
             throw CipherError.Decrypt
         }
 
-        return try decodedData.decrypt(cipher).arrayOfBytes()
+        return try decodedData.decrypt(cipher: cipher).arrayOfBytes()
     }
 
 }

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

@@ -14,7 +14,7 @@ func perf(text: String, closure: () -> ()) {
     closure()
     
     let measurementStop = NSDate();
-    let executionTime = measurementStop.timeIntervalSinceDate(measurementStart)
+    let executionTime = measurementStop.timeIntervalSince(measurementStart)
     
     print("\(text) \(executionTime)");
 }

+ 24 - 24
Sources/CryptoSwift/Generics.swift

@@ -20,10 +20,10 @@ extension UInt32:Initiable {}
 extension UInt64:Initiable {}
 
 /** build bit pattern from array of bits */
-func integerFromBitsArray<T: UnsignedIntegerType>(bits: [Bit]) -> T
+func integerFromBitsArray<T: UnsignedInteger>(bits: [Bit]) -> T
 {
     var bitPattern:T = 0
-    for (idx,b) in bits.enumerate() {
+    for (idx,b) in bits.enumerated() {
         if (b == Bit.One) {
             let bit = T(UIntMax(1) << UIntMax(idx))
             bitPattern = bitPattern | bit
@@ -34,12 +34,12 @@ func integerFromBitsArray<T: UnsignedIntegerType>(bits: [Bit]) -> T
 
 /// Initialize integer from array of bytes.
 /// This method may be slow
-func integerWithBytes<T: IntegerType where T:ByteConvertible, T: BitshiftOperationsType>(bytes: Array<UInt8>) -> T {
-    var bytes = bytes.reverse() as Array<UInt8> //FIXME: check it this is equivalent of Array(...)
+func integerWithBytes<T:Integer where T:ByteConvertible, T: BitshiftOperationsType>(bytes: Array<UInt8>) -> T {
+    var bytes = bytes.reversed() as Array<UInt8> //FIXME: check it this is equivalent of Array(...)
     if bytes.count < sizeof(T) {
         let paddingCount = sizeof(T) - bytes.count
         if (paddingCount > 0) {
-            bytes += Array<UInt8>(count: paddingCount, repeatedValue: 0)
+            bytes += Array<UInt8>(repeating: 0, count: paddingCount)
         }
     }
     
@@ -48,7 +48,7 @@ func integerWithBytes<T: IntegerType where T:ByteConvertible, T: BitshiftOperati
     }
     
     var result: T = 0
-    for byte in bytes.reverse() {
+    for byte in bytes.reversed() {
         result = result << 8 | T(byte)
     }
     return result
@@ -59,17 +59,17 @@ func integerWithBytes<T: IntegerType where T:ByteConvertible, T: BitshiftOperati
 func arrayOfBytes<T>(value:T, length:Int? = nil) -> Array<UInt8> {
     let totalBytes = length ?? sizeof(T)
     
-    let valuePointer = UnsafeMutablePointer<T>.alloc(1)
-    valuePointer.memory = value
+    let valuePointer = UnsafeMutablePointer<T>(allocatingCapacity: 1)
+    valuePointer.pointee = value
     
     let bytesPointer = UnsafeMutablePointer<UInt8>(valuePointer)
-    var bytes = Array<UInt8>(count: totalBytes, repeatedValue: 0)
+    var bytes = Array<UInt8>(repeating: 0, count: totalBytes)
     for j in 0..<min(sizeof(T),totalBytes) {
-        bytes[totalBytes - 1 - j] = (bytesPointer + j).memory
+        bytes[totalBytes - 1 - j] = (bytesPointer + j).pointee
     }
     
-    valuePointer.destroy()
-    valuePointer.dealloc(1)
+    valuePointer.deinitialize()
+    valuePointer.deallocateCapacity(1)
     
     return bytes
 }
@@ -77,13 +77,13 @@ func arrayOfBytes<T>(value:T, length:Int? = nil) -> Array<UInt8> {
 // MARK: - shiftLeft
 
 // helper to be able tomake shift operation on T
-func << <T:SignedIntegerType>(lhs: T, rhs: Int) -> Int {
+func << <T:SignedInteger>(lhs: T, rhs: Int) -> Int {
     let a = lhs as! Int
     let b = rhs
     return a << b
 }
 
-func << <T:UnsignedIntegerType>(lhs: T, rhs: Int) -> UInt {
+func << <T:UnsignedInteger>(lhs: T, rhs: Int) -> UInt {
     let a = lhs as! UInt
     let b = rhs
     return a << b
@@ -91,7 +91,7 @@ func << <T:UnsignedIntegerType>(lhs: T, rhs: Int) -> UInt {
 
 // Generic function itself
 // FIXME: this generic function is not as generic as I would. It crashes for smaller types
-func shiftLeft<T: SignedIntegerType where T: Initiable>(value: T, count: Int) -> T {
+func shiftLeft<T: SignedInteger where T: Initiable>(value: T, count: Int) -> T {
     if (value == 0) {
         return 0;
     }
@@ -116,38 +116,38 @@ func shiftLeft<T: SignedIntegerType where T: Initiable>(value: T, count: Int) ->
 
 // for any f*** other Integer type - this part is so non-Generic
 func shiftLeft(value: UInt, count: Int) -> UInt {
-    return UInt(shiftLeft(Int(value), count: count)) //FIXME: count:
+    return UInt(shiftLeft(value: Int(value), count: count)) //FIXME: count:
 }
 
 func shiftLeft(value: UInt8, count: Int) -> UInt8 {
-    return UInt8(shiftLeft(UInt(value), count: count))
+    return UInt8(shiftLeft(value: UInt(value), count: count))
 }
 
 func shiftLeft(value: UInt16, count: Int) -> UInt16 {
-    return UInt16(shiftLeft(UInt(value), count: count))
+    return UInt16(shiftLeft(value: UInt(value), count: count))
 }
 
 func shiftLeft(value: UInt32, count: Int) -> UInt32 {
-    return UInt32(shiftLeft(UInt(value), count: count))
+    return UInt32(shiftLeft(value: UInt(value), count: count))
 }
 
 func shiftLeft(value: UInt64, count: Int) -> UInt64 {
-    return UInt64(shiftLeft(UInt(value), count: count))
+    return UInt64(shiftLeft(value: UInt(value), count: count))
 }
 
 func shiftLeft(value: Int8, count: Int) -> Int8 {
-    return Int8(shiftLeft(Int(value), count: count))
+    return Int8(shiftLeft(value: Int(value), count: count))
 }
 
 func shiftLeft(value: Int16, count: Int) -> Int16 {
-    return Int16(shiftLeft(Int(value), count: count))
+    return Int16(shiftLeft(value: Int(value), count: count))
 }
 
 func shiftLeft(value: Int32, count: Int) -> Int32 {
-    return Int32(shiftLeft(Int(value), count: count))
+    return Int32(shiftLeft(value: Int(value), count: count))
 }
 
 func shiftLeft(value: Int64, count: Int) -> Int64 {
-    return Int64(shiftLeft(Int(value), count: count))
+    return Int64(shiftLeft(value: Int(value), count: count))
 }
 

+ 5 - 5
Sources/CryptoSwift/HMAC.swift

@@ -65,17 +65,17 @@ final public class HMAC {
         }
         
         if (key.count < variant.blockSize()) { // keys shorter than blocksize are zero-padded
-            self.key = key + Array<UInt8>(count: variant.blockSize() - key.count, repeatedValue: 0)
+            self.key = key + Array<UInt8>(repeating: 0, count: variant.blockSize() - key.count)
         }
     }
 
     public func authenticate(message:Array<UInt8>) -> Array<UInt8>? {
-        var opad = Array<UInt8>(count: variant.blockSize(), repeatedValue: 0x5c)
-        for (idx, _) in key.enumerate() {
+        var opad = Array<UInt8>(repeating: 0x5c, count: variant.blockSize())
+        for (idx, _) in key.enumerated() {
             opad[idx] = key[idx] ^ opad[idx]
         }
-        var ipad = Array<UInt8>(count: variant.blockSize(), repeatedValue: 0x36)
-        for (idx, _) in key.enumerate() {
+        var ipad = Array<UInt8>(repeating: 0x36, count: variant.blockSize())
+        for (idx, _) in key.enumerated() {
             ipad[idx] = key[idx] ^ ipad[idx]
         }
 

+ 2 - 2
Sources/CryptoSwift/Hash.swift

@@ -28,9 +28,9 @@ public enum Hash {
         case sha512(let bytes):
             return SHA2(bytes, variant: .sha512).calculate64()
         case crc32(let bytes):
-            return CRC().crc32(bytes.0, seed: bytes.seed, reflect: bytes.reflect).bytes()
+            return CRC().crc32(message: bytes.0, seed: bytes.seed, reflect: bytes.reflect).bytes()
         case crc16(let bytes):
-            return UInt32(CRC().crc16(bytes.0, seed: bytes.seed)).bytes(2)
+            return UInt32(CRC().crc16(message: bytes.0, seed: bytes.seed)).bytes(totalBytes: 2)
         }
     }
 }

+ 1 - 1
Sources/CryptoSwift/HashProtocol.swift

@@ -30,7 +30,7 @@ extension HashProtocol {
             msgLength += 1
         }
 
-        tmpMessage += Array<UInt8>(count: counter, repeatedValue: 0)
+        tmpMessage += Array<UInt8>(repeating: 0, count: counter)
         return tmpMessage
     }
 }

+ 11 - 11
Sources/CryptoSwift/IntExtension.swift

@@ -24,7 +24,7 @@
 /* array of bits */
 extension Int {
     init(bits: [Bit]) {
-        self.init(bitPattern: integerFromBitsArray(bits) as UInt)
+        self.init(bitPattern: integerFromBitsArray(bits: bits) as UInt)
     }
 }
 
@@ -32,16 +32,16 @@ extension Int {
 extension Int {
     /** Array of bytes with optional padding (little-endian) */
     public func bytes(totalBytes: Int = sizeof(Int)) -> Array<UInt8> {
-        return arrayOfBytes(self, length: totalBytes)
+        return arrayOfBytes(value: self, length: totalBytes)
     }
 
     public static func withBytes(bytes: ArraySlice<UInt8>) -> Int {
-        return Int.withBytes(Array(bytes))
+        return Int.withBytes(bytes: Array(bytes))
     }
 
     /** Int with array bytes (little-endian) */
     public static func withBytes(bytes: Array<UInt8>) -> Int {
-        return integerWithBytes(bytes)
+        return integerWithBytes(bytes: bytes)
     }
 }
 
@@ -52,7 +52,7 @@ extension Int {
     
     /** Shift bits to the left. All bits are shifted (including sign bit) */
     private mutating func shiftLeft(count: Int) -> Int {
-        self = CryptoSwift.shiftLeft(self, count: count) //FIXME: count:
+        self = CryptoSwift.shiftLeft(value: self, count: count) //FIXME: count:
         return self
     }
     
@@ -87,27 +87,27 @@ extension Int {
 // Left operator
 
 /** shift left and assign with bits truncation */
-public func &<<= (inout lhs: Int, rhs: Int) {
-    lhs.shiftLeft(rhs)
+public func &<<= (lhs: inout Int, rhs: Int) {
+    lhs.shiftLeft(count: rhs)
 }
 
 /** shift left with bits truncation */
 public func &<< (lhs: Int, rhs: Int) -> Int {
     var l = lhs;
-    l.shiftLeft(rhs)
+    l.shiftLeft(count: rhs)
     return l
 }
 
 // Right operator
 
 /** shift right and assign with bits truncation */
-func &>>= (inout lhs: Int, rhs: Int) {
-    lhs.shiftRight(rhs)
+func &>>= (lhs: inout Int, rhs: Int) {
+    lhs.shiftRight(count: rhs)
 }
 
 /** shift right and assign with bits truncation */
 func &>> (lhs: Int, rhs: Int) -> Int {
     var l = lhs;
-    l.shiftRight(rhs)
+    l.shiftRight(count: rhs)
     return l
 }

+ 2 - 2
Sources/CryptoSwift/IntegerConvertible.swift

@@ -9,8 +9,8 @@
 protocol BitshiftOperationsType {
     func <<(lhs: Self, rhs: Self) -> Self
     func >>(lhs: Self, rhs: Self) -> Self
-    func <<=(inout lhs: Self, rhs: Self)
-    func >>=(inout lhs: Self, rhs: Self)
+    func <<=(lhs: inout Self, rhs: Self)
+    func >>=(lhs: inout Self, rhs: Self)
 }
 
 protocol ByteConvertible {

+ 5 - 5
Sources/CryptoSwift/MD5.swift

@@ -41,7 +41,7 @@ final class MD5 : HashProtocol  {
     private let h:Array<UInt32> = [0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476]
     
     func calculate() -> Array<UInt8> {
-        var tmpMessage = prepare(64)
+        var tmpMessage = prepare(len: 64)
         tmpMessage.reserveCapacity(tmpMessage.count + 4)
 
         // initialize hh with hash values
@@ -49,14 +49,14 @@ final class MD5 : HashProtocol  {
         
         // Step 2. Append Length a 64-bit representation of lengthInBits
         let lengthInBits = (message.count * 8)
-        let lengthBytes = lengthInBits.bytes(64 / 8)
-        tmpMessage += lengthBytes.reverse()
+        let lengthBytes = lengthInBits.bytes(totalBytes: 64 / 8)
+        tmpMessage += lengthBytes.reversed()
 
         // Process the message in successive 512-bit chunks:
         let chunkSizeBytes = 512 / 8 // 64
         for chunk in BytesSequence(chunkSize: chunkSizeBytes, data: tmpMessage) {
             // break chunk into sixteen 32-bit words M[j], 0 ≤ j ≤ 15
-            var M = toUInt32Array(chunk)
+            var M = toUInt32Array(slice: chunk)
             assert(M.count == 16, "Invalid array")
             
             // Initialize hash value for this chunk:
@@ -95,7 +95,7 @@ final class MD5 : HashProtocol  {
                 dTemp = D
                 D = C
                 C = B
-                B = B &+ rotateLeft((A &+ F &+ k[j] &+ M[g]), s[j])
+                B = B &+ rotateLeft(v: (A &+ F &+ k[j] &+ M[g]), s[j])
                 A = dTemp    
             }
             

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

@@ -15,7 +15,7 @@ public extension PKCS5 {
     /// some applications.
     public struct PBKDF1 {
 
-        public enum Error: ErrorType {
+        public enum Error: ErrorProtocol {
             case InvalidInput
             case DerivedKeyTooLong
         }
@@ -32,7 +32,7 @@ public extension PKCS5 {
                 }
             }
 
-            private func calculateHash(bytes bytes:Array<UInt8>) -> Array<UInt8>? {
+            private func calculateHash(bytes:Array<UInt8>) -> Array<UInt8>? {
                 switch (self) {
                 case .sha1:
                     return Hash.sha1(bytes).calculate()

+ 6 - 6
Sources/CryptoSwift/PKCS5/PBKDF2.swift

@@ -19,7 +19,7 @@ public extension PKCS5 {
     ///          DK = PBKDF2(PRF, Password, Salt, c, dkLen)
     public struct PBKDF2 {
 
-        public enum Error: ErrorType {
+        public enum Error: ErrorProtocol {
             case InvalidInput
             case DerivedKeyTooLong
         }
@@ -60,7 +60,7 @@ public extension PKCS5 {
             for i in 1...self.numBlocks {
                 // for each block T_i = U_1 ^ U_2 ^ ... ^ U_iter
                 if let value = calculateBlock(salt: self.salt, blockNum: i) {
-                    ret.appendContentsOf(value)
+                    ret.append(contentsOf: value)
                 }
             }
             return ret
@@ -70,7 +70,7 @@ public extension PKCS5 {
 
 private extension PKCS5.PBKDF2 {
     private func INT(i: UInt) -> Array<UInt8> {
-        var inti = Array<UInt8>(count: 4, repeatedValue: 0)
+        var inti = Array<UInt8>(repeating: 0, count: 4)
         inti[0] = UInt8((i >> 24) & 0xFF)
         inti[1] = UInt8((i >> 16) & 0xFF)
         inti[2] = UInt8((i >> 8) & 0xFF)
@@ -80,8 +80,8 @@ private extension PKCS5.PBKDF2 {
 
     // F (P, S, c, i) = U_1 \xor U_2 \xor ... \xor U_c
     // U_1 = PRF (P, S || INT (i))
-    private func calculateBlock(salt salt: Array<UInt8>, blockNum: UInt) -> Array<UInt8>? {
-        guard let u1 = prf.authenticate(salt + INT(blockNum)) else {
+    private func calculateBlock(salt: Array<UInt8>, blockNum: UInt) -> Array<UInt8>? {
+        guard let u1 = prf.authenticate(message: salt + INT(i: blockNum)) else {
             return nil
         }
 
@@ -91,7 +91,7 @@ private extension PKCS5.PBKDF2 {
             // U_2 = PRF (P, U_1) ,
             // U_c = PRF (P, U_{c-1}) .
             for _ in 2...self.iterations {
-                u = prf.authenticate(u)!
+                u = prf.authenticate(message: u)!
                 for x in 0..<ret.count {
                     ret[x] = ret[x] ^ u[x]
                 }

+ 5 - 5
Sources/CryptoSwift/PKCS7.swift

@@ -11,7 +11,7 @@
 
 public struct PKCS7: Padding {
 
-    public enum Error: ErrorType {
+    public enum Error: ErrorProtocol {
         case InvalidPaddingValue
     }
     
@@ -19,24 +19,24 @@ public struct PKCS7: Padding {
         
     }
     
-    public func add(bytes: Array<UInt8> , blockSize:Int) -> Array<UInt8> {
+    public func add(data bytes: Array<UInt8> , blockSize:Int) -> Array<UInt8> {
         let padding = UInt8(blockSize - (bytes.count % blockSize))
         var withPadding = bytes
         if (padding == 0) {
             // If the original data is a multiple of N bytes, then an extra block of bytes with value N is added.
             for _ in 0..<blockSize {
-                withPadding.appendContentsOf([UInt8(blockSize)])
+                withPadding += [UInt8(blockSize)]
             }
         } else {
             // The value of each added byte is the number of bytes that are added
             for _ in 0..<padding {
-                withPadding.appendContentsOf([UInt8(padding)])
+                withPadding += [UInt8(padding)]
             }
         }
         return withPadding
     }
 
-    public func remove(bytes: Array<UInt8>, blockSize:Int?) -> Array<UInt8> {
+    public func remove(data bytes: Array<UInt8>, blockSize:Int?) -> Array<UInt8> {
         assert(!bytes.isEmpty, "Need bytes to remove padding")
         guard !bytes.isEmpty, let lastByte = bytes.last else {
             return bytes

+ 23 - 23
Sources/CryptoSwift/Poly1305.swift

@@ -15,10 +15,10 @@ final public class Poly1305 {
     private var ctx:Context?
     
     private class Context {
-        var r            = Array<UInt8>(count: 17, repeatedValue: 0)
-        var h            = Array<UInt8>(count: 17, repeatedValue: 0)
-        var pad          = Array<UInt8>(count: 17, repeatedValue: 0)
-        var buffer       = Array<UInt8>(count: 16, repeatedValue: 0)
+        var r            = Array<UInt8>(repeating: 0, count: 17)
+        var h            = Array<UInt8>(repeating: 0, count: 17)
+        var pad          = Array<UInt8>(repeating: 0, count: 17)
+        var buffer       = Array<UInt8>(repeating: 0, count: 16)
         
         var final:UInt8   = 0
         var leftover:Int = 0
@@ -86,8 +86,8 @@ final public class Poly1305 {
      */
     public func authenticate(message:Array<UInt8>) -> Array<UInt8>? {
         if let ctx = self.ctx {
-            update(ctx, message: message)
-            return finish(ctx)
+            update(context: ctx, message: message)
+            return finish(context: ctx)
         }
         return nil
     }
@@ -131,14 +131,14 @@ final public class Poly1305 {
                 return
             }
             
-            blocks(context, m: context.buffer)
+            blocks(context: context, m: context.buffer)
             context.leftover = 0
         }
         
         /* process full blocks */
         if (bytes >= blockSize) {
             let want = bytes & ~(blockSize - 1)
-            blocks(context, m: message, startPos: mPos)
+            blocks(context: context, m: message, startPos: mPos)
             mPos += want
             bytes -= want;
         }
@@ -154,7 +154,7 @@ final public class Poly1305 {
     }
     
     private func finish(context:Context) -> Array<UInt8>? {
-        var mac = Array<UInt8>(count: 16, repeatedValue: 0);
+        var mac = Array<UInt8>(repeating: 0, count: 16);
         
         /* process the remaining block */
         if (context.leftover > 0) {
@@ -165,15 +165,15 @@ final public class Poly1305 {
             }
             context.final = 1
             
-            blocks(context, m: context.buffer)
+            blocks(context: context, m: context.buffer)
         }
         
         
         /* fully reduce h */
-        freeze(context)
+        freeze(context: context)
         
         /* h = (h + pad) % (1 << 128) */
-        add(context, c: context.pad)
+        add(context: context, c: context.pad)
         for i in 0..<mac.count {
             mac[i] = context.h[i]
         }
@@ -191,7 +191,7 @@ final public class Poly1305 {
         var u:UInt16 = 0
         for i in 0..<17 {
             u += UInt16(context.h[i]) + UInt16(c[i])
-            context.h[i] = UInt8.withValue(u)
+            context.h[i] = UInt8.withValue(v: u)
             u = u >> 8
         }
         return true
@@ -206,20 +206,20 @@ final public class Poly1305 {
         
         for i in 0..<16 {
             u += hr[i];
-            context.h[i] = UInt8.withValue(u) // crash! h[i] = UInt8(u) & 0xff
+            context.h[i] = UInt8.withValue(v: u) // crash! h[i] = UInt8(u) & 0xff
             u >>= 8;
         }
         
         u += hr[16]
-        context.h[16] = UInt8.withValue(u) & 0x03
+        context.h[16] = UInt8.withValue(v: u) & 0x03
         u >>= 2
         u += (u << 2); /* u *= 5; */
         for i in 0..<16 {
             u += UInt32(context.h[i])
-            context.h[i] = UInt8.withValue(u) // crash! h[i] = UInt8(u) & 0xff
+            context.h[i] = UInt8.withValue(v: u) // crash! h[i] = UInt8(u) & 0xff
             u >>= 8
         }
-        context.h[16] += UInt8.withValue(u);
+        context.h[16] += UInt8.withValue(v: u);
         
         return true
     }
@@ -231,14 +231,14 @@ final public class Poly1305 {
         }
         
         let minusp:Array<UInt8> = [0x05,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xfc]
-        var horig:Array<UInt8> = Array<UInt8>(count: 17, repeatedValue: 0)
+        var horig:Array<UInt8> = Array<UInt8>(repeating: 0, count: 17)
         
         /* compute h + -p */
         for i in 0..<17 {
             horig[i] = context.h[i]
         }
         
-        add(context, c: minusp)
+        add(context: context, c: minusp)
         
         /* select h if h < p, or h + -p if h >= p */
         let bits:[Bit] = (context.h[16] >> 7).bits()
@@ -260,9 +260,9 @@ final public class Poly1305 {
         var mPos = startPos
         
         while (bytes >= Int(blockSize)) {
-            var hr:Array<UInt32> = Array<UInt32>(count: 17, repeatedValue: 0)
+            var hr:Array<UInt32> = Array<UInt32>(repeating: 0, count: 17)
             var u:UInt32 = 0
-            var c:Array<UInt8> = Array<UInt8>(count: 17, repeatedValue: 0)
+            var c:Array<UInt8> = Array<UInt8>(repeating: 0, count: 17)
             
             /* h += m */
             for i in 0..<16 {
@@ -270,7 +270,7 @@ final public class Poly1305 {
             }
             c[16] = hibit
             
-            add(context, c: c)
+            add(context: context, c: c)
             
             /* h *= r */
             for i in 0..<17 {
@@ -286,7 +286,7 @@ final public class Poly1305 {
                 hr[i] = u
             }
             
-            squeeze(context, hr: hr)
+            squeeze(context: context, hr: hr)
             
             mPos += blockSize
             bytes -= blockSize

+ 21 - 21
Sources/CryptoSwift/Rabbit.swift

@@ -26,10 +26,10 @@ final public class Rabbit: BlockCipher {
     private let iv: Array<UInt8>?
     
     /// State variables
-    private var x = Array<UInt32>(count: 8, repeatedValue: 0)
+    private var x = Array<UInt32>(repeating: 0, count: 8)
     
     /// Counter variables
-    private var c = Array<UInt32>(count: 8, repeatedValue: 0)
+    private var c = Array<UInt32>(repeating: 0, count: 8)
     
     /// Counter carry
     private var p7: UInt32 = 0
@@ -65,7 +65,7 @@ final public class Rabbit: BlockCipher {
         p7 = 0
         
         // Key divided into 8 subkeys
-        var k = Array<UInt32>(count: 8, repeatedValue: 0)
+        var k = Array<UInt32>(repeating: 0, count: 8)
         for j in 0..<8 {
             k[j] = UInt32(key[Rabbit.blockSize - (2*j + 1)]) | (UInt32(key[Rabbit.blockSize - (2*j + 2)]) << 8)
         }
@@ -93,17 +93,17 @@ final public class Rabbit: BlockCipher {
         }
         
         if let iv = iv {
-            setupIV(iv)
+            setupIV(iv: iv)
         }
     }
     
     private func setupIV(iv: Array<UInt8>) {
         // 63...56 55...48 47...40 39...32 31...24 23...16 15...8 7...0 IV bits
         //    0       1       2       3       4       5       6     7   IV bytes in array
-        let iv0: UInt32 = integerWithBytes([iv[4], iv[5], iv[6], iv[7]])
-        let iv1: UInt32 = integerWithBytes([iv[0], iv[1], iv[4], iv[5]])
-        let iv2: UInt32 = integerWithBytes([iv[0], iv[1], iv[2], iv[3]])
-        let iv3: UInt32 = integerWithBytes([iv[2], iv[3], iv[6], iv[7]])
+        let iv0: UInt32 = integerWithBytes(bytes: [iv[4], iv[5], iv[6], iv[7]])
+        let iv1: UInt32 = integerWithBytes(bytes: [iv[0], iv[1], iv[4], iv[5]])
+        let iv2: UInt32 = integerWithBytes(bytes: [iv[0], iv[1], iv[2], iv[3]])
+        let iv3: UInt32 = integerWithBytes(bytes: [iv[2], iv[3], iv[6], iv[7]])
         
         // Modify the counter state as function of the IV
         c[0] = c[0] ^ iv0
@@ -133,15 +133,15 @@ final public class Rabbit: BlockCipher {
         p7 = carry // save last carry bit
         
         // Iteration of the system
-        var newX = Array<UInt32>(count: 8, repeatedValue: 0)
-        newX[0] = g(0) &+ rotateLeft(g(7), 16) &+ rotateLeft(g(6), 16)
-        newX[1] = g(1) &+ rotateLeft(g(0), 8)  &+ g(7)
-        newX[2] = g(2) &+ rotateLeft(g(1), 16) &+ rotateLeft(g(0), 16)
-        newX[3] = g(3) &+ rotateLeft(g(2), 8)  &+ g(1)
-        newX[4] = g(4) &+ rotateLeft(g(3), 16) &+ rotateLeft(g(2), 16)
-        newX[5] = g(5) &+ rotateLeft(g(4), 8)  &+ g(3)
-        newX[6] = g(6) &+ rotateLeft(g(5), 16) &+ rotateLeft(g(4), 16)
-        newX[7] = g(7) &+ rotateLeft(g(6), 8)  &+ g(5)
+        var newX = Array<UInt32>(repeating: 0, count: 8)
+        newX[0] = g(j: 0) &+ rotateLeft(v: g(j: 7), 16) &+ rotateLeft(v: g(j: 6), 16)
+        newX[1] = g(j: 1) &+ rotateLeft(v: g(j: 0), 8)  &+ g(j: 7)
+        newX[2] = g(j: 2) &+ rotateLeft(v: g(j: 1), 16) &+ rotateLeft(v: g(j: 0), 16)
+        newX[3] = g(j: 3) &+ rotateLeft(v: g(j: 2), 8)  &+ g(j: 1)
+        newX[4] = g(j: 4) &+ rotateLeft(v: g(j: 3), 16) &+ rotateLeft(v: g(j: 2), 16)
+        newX[5] = g(j: 5) &+ rotateLeft(v: g(j: 4), 8)  &+ g(j: 3)
+        newX[6] = g(j: 6) &+ rotateLeft(v: g(j: 5), 16) &+ rotateLeft(v: g(j: 4), 16)
+        newX[7] = g(j: 7) &+ rotateLeft(v: g(j: 6), 8)  &+ g(j: 5)
         x = newX
     }
     
@@ -154,7 +154,7 @@ final public class Rabbit: BlockCipher {
     private func nextOutput() -> Array<UInt8> {
         nextState()
         
-        var output16 = [UInt16](count: Rabbit.blockSize / 2, repeatedValue: 0)
+        var output16 = [UInt16](repeating: 0, count: Rabbit.blockSize / 2)
         output16[7] = UInt16(truncatingBitPattern: x[0]) ^ UInt16(truncatingBitPattern: x[5] >> 16)
         output16[6] = UInt16(truncatingBitPattern: x[0] >> 16) ^ UInt16(truncatingBitPattern: x[3])
         output16[5] = UInt16(truncatingBitPattern: x[2]) ^ UInt16(truncatingBitPattern: x[7] >> 16)
@@ -164,7 +164,7 @@ final public class Rabbit: BlockCipher {
         output16[1] = UInt16(truncatingBitPattern: x[6]) ^ UInt16(truncatingBitPattern: x[3] >> 16)
         output16[0] = UInt16(truncatingBitPattern: x[6] >> 16) ^ UInt16(truncatingBitPattern: x[1])
         
-        var output8 = Array<UInt8>(count: Rabbit.blockSize, repeatedValue: 0)
+        var output8 = Array<UInt8>(repeating: 0, count: Rabbit.blockSize)
         for j in 0..<output16.count {
             output8[j * 2] = UInt8(truncatingBitPattern: output16[j] >> 8)
             output8[j * 2 + 1] = UInt8(truncatingBitPattern: output16[j])
@@ -178,7 +178,7 @@ extension Rabbit: Cipher {
     public func encrypt(bytes: Array<UInt8>) -> Array<UInt8> {
         setup()
 
-        var result = Array<UInt8>(count: bytes.count, repeatedValue: 0)
+        var result = Array<UInt8>(repeating: 0, count: bytes.count)
         var output = nextOutput()
         var byteIdx = 0
         var outputIdx = 0
@@ -197,6 +197,6 @@ extension Rabbit: Cipher {
     }
 
     public func decrypt(bytes: Array<UInt8>) -> Array<UInt8> {
-        return encrypt(bytes)
+        return encrypt(bytes: bytes)
     }
 }

+ 7 - 7
Sources/CryptoSwift/SHA1.swift

@@ -17,30 +17,30 @@ final class SHA1 : HashProtocol {
     private let h:Array<UInt32> = [0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0]
         
     func calculate() -> Array<UInt8> {
-        var tmpMessage = self.prepare(64)
+        var tmpMessage = self.prepare(len: 64)
         
         // hash values
         var hh = h
         
         // append message length, in a 64-bit big-endian integer. So now the message length is a multiple of 512 bits.
-        tmpMessage += (self.message.count * 8).bytes(64 / 8)
+        tmpMessage += (self.message.count * 8).bytes(totalBytes: 64 / 8)
         
         // Process the message in successive 512-bit chunks:
         let chunkSizeBytes = 512 / 8 // 64
         for chunk in BytesSequence(chunkSize: chunkSizeBytes, data: tmpMessage) {
             // break chunk into sixteen 32-bit words M[j], 0 ≤ j ≤ 15, big-endian
             // Extend the sixteen 32-bit words into eighty 32-bit words:
-            var M:Array<UInt32> = Array<UInt32>(count: 80, repeatedValue: 0)
+            var M:Array<UInt32> = Array<UInt32>(repeating: 0, count: 80)
             for x in 0..<M.count {
                 switch (x) {
                 case 0...15:
                     let start = chunk.startIndex + (x * sizeofValue(M[x]))
                     let end = start + sizeofValue(M[x])
-                    let le = toUInt32Array(chunk[start..<end])[0]
+                    let le = toUInt32Array(slice: chunk[start..<end])[0]
                     M[x] = le.bigEndian
                     break
                 default:
-                    M[x] = rotateLeft(M[x-3] ^ M[x-8] ^ M[x-14] ^ M[x-16], 1) //FIXME: n:
+                    M[x] = rotateLeft(v: M[x-3] ^ M[x-8] ^ M[x-14] ^ M[x-16], 1) //FIXME: n:
                     break
                 }
             }
@@ -77,10 +77,10 @@ final class SHA1 : HashProtocol {
                     break
                 }
                 
-                let temp = (rotateLeft(A,5) &+ f &+ E &+ M[j] &+ k) & 0xffffffff
+                let temp = (rotateLeft(v: A,5) &+ f &+ E &+ M[j] &+ k) & 0xffffffff
                 E = D
                 D = C
-                C = rotateLeft(B, 30)
+                C = rotateLeft(v: B, 30)
                 B = A
                 A = temp
             }

+ 22 - 22
Sources/CryptoSwift/SHA2.swift

@@ -8,7 +8,7 @@
 
 final class SHA2 : HashProtocol {
     var size:Int { return variant.rawValue }
-    let variant:SHA2.Variant
+    let variant: Variant
     
     let message: Array<UInt8>
     
@@ -55,7 +55,7 @@ final class SHA2 : HashProtocol {
         
         var size:Int { return self.rawValue }
         
-        private var h:[UInt64] {
+        private var h:Array<UInt64> {
             switch (self) {
             case .sha224:
                 return [0xc1059ed8, 0x367cd507, 0x3070dd17, 0xf70e5939, 0xffc00b31, 0x68581511, 0x64f98fa7, 0xbefa4fa4]
@@ -68,7 +68,7 @@ final class SHA2 : HashProtocol {
             }
         }
         
-        private var k:[UInt64] {
+        private var k:Array<UInt64> {
             switch (self) {
             case .sha224, .sha256:
                 return [0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
@@ -114,7 +114,7 @@ final class SHA2 : HashProtocol {
     
     //FIXME: I can't do Generic func out of calculate32 and calculate64 (UInt32 vs UInt64), but if you can - please do pull request.
     func calculate32() -> Array<UInt8> {
-        var tmpMessage = self.prepare(64)
+        var tmpMessage = self.prepare(len: 64)
         
         // hash values
         var hh = Array<UInt32>()
@@ -123,25 +123,25 @@ final class SHA2 : HashProtocol {
         }
 		
         // append message length, in a 64-bit big-endian integer. So now the message length is a multiple of 512 bits.
-        tmpMessage += (message.count * 8).bytes(64 / 8)
+        tmpMessage += (message.count * 8).bytes(totalBytes: 64 / 8)
         
         // Process the message in successive 512-bit chunks:
         let chunkSizeBytes = 512 / 8 // 64
         for chunk in BytesSequence(chunkSize: chunkSizeBytes, data: tmpMessage) {
             // break chunk into sixteen 32-bit words M[j], 0 ≤ j ≤ 15, big-endian
             // Extend the sixteen 32-bit words into sixty-four 32-bit words:
-            var M:Array<UInt32> = Array<UInt32>(count: variant.k.count, repeatedValue: 0)
+            var M:Array<UInt32> = Array<UInt32>(repeating: 0, count: variant.k.count)
             for x in 0..<M.count {
                 switch (x) {
                 case 0...15:
                     let start = chunk.startIndex + (x * sizeofValue(M[x]))
                     let end = start + sizeofValue(M[x])
-                    let le = toUInt32Array(chunk[start..<end])[0]
+                    let le = toUInt32Array(slice: chunk[start..<end])[0]
                     M[x] = le.bigEndian
                     break
                 default:
-                    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)
+                    let s0 = rotateRight(x: M[x-15], n: 7) ^ rotateRight(x: M[x-15], n: 18) ^ (M[x-15] >> 3) //FIXME: n
+                    let s1 = rotateRight(x: M[x-2], n: 17) ^ rotateRight(x: M[x-2], n: 19) ^ (M[x-2] >> 10)
                     M[x] = M[x-16] &+ s0 &+ M[x-7] &+ s1
                     break
                 }
@@ -158,10 +158,10 @@ final class SHA2 : HashProtocol {
             
             // Main loop
             for j in 0..<variant.k.count {
-                let s0 = rotateRight(A,n: 2) ^ rotateRight(A,n: 13) ^ rotateRight(A,n: 22)
+                let s0 = rotateRight(x: A,n: 2) ^ rotateRight(x: A,n: 13) ^ rotateRight(x: A,n: 22)
                 let maj = (A & B) ^ (A & C) ^ (B & C)
                 let t2 = s0 &+ maj
-                let s1 = rotateRight(E,n: 6) ^ rotateRight(E,n: 11) ^ rotateRight(E,n: 25)
+                let s1 = rotateRight(x: E,n: 6) ^ rotateRight(x: E,n: 11) ^ rotateRight(x: E,n: 25)
                 let ch = (E & F) ^ ((~E) & G)
                 let t1 = H &+ s1 &+ ch &+ UInt32(variant.k[j]) &+ M[j]
                 
@@ -188,7 +188,7 @@ final class SHA2 : HashProtocol {
         // Produce the final hash value (big-endian) as a 160 bit number:
         var result = Array<UInt8>()
         result.reserveCapacity(hh.count / 4)
-        variant.resultingArray(hh).forEach {
+        variant.resultingArray(hh: hh).forEach {
             let item = $0.bigEndian
             result += [UInt8(item & 0xff), UInt8((item >> 8) & 0xff), UInt8((item >> 16) & 0xff), UInt8((item >> 24) & 0xff)]
         }
@@ -196,35 +196,35 @@ final class SHA2 : HashProtocol {
     }
     
     func calculate64() -> Array<UInt8> {
-        var tmpMessage = self.prepare(128)
+        var tmpMessage = self.prepare(len: 128)
         
         // hash values
-        var hh = [UInt64]()
+        var hh = Array<UInt64>()
         variant.h.forEach {(h) -> () in
             hh.append(h)
         }
 		
   
         // append message length, in a 64-bit big-endian integer. So now the message length is a multiple of 512 bits.
-        tmpMessage += (message.count * 8).bytes(64 / 8)
+        tmpMessage += (message.count * 8).bytes(totalBytes: 64 / 8)
         
         // Process the message in successive 1024-bit chunks:
         let chunkSizeBytes = 1024 / 8 // 128
         for chunk in BytesSequence(chunkSize: chunkSizeBytes, data: tmpMessage) {
             // 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:
-            var M = [UInt64](count: variant.k.count, repeatedValue: 0)
+            var M = Array<UInt64>(repeating: 0, count: variant.k.count)
             for x in 0..<M.count {
                 switch (x) {
                 case 0...15:
                     let start = chunk.startIndex + (x * sizeofValue(M[x]))
                     let end = start + sizeofValue(M[x])
-                    let le = toUInt64Array(chunk[start..<end])[0]
+                    let le = toUInt64Array(slice: chunk[start..<end])[0]
                     M[x] = le.bigEndian
                     break
                 default:
-                    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)
+                    let s0 = rotateRight(x: M[x-15], n: 1) ^ rotateRight(x: M[x-15], n: 8) ^ (x: M[x-15] >> 7)
+                    let s1 = rotateRight(x: M[x-2], n: 19) ^ rotateRight(x: M[x-2], n: 61) ^ (x: M[x-2] >> 6)
                     M[x] = M[x-16] &+ s0 &+ M[x-7] &+ s1
                     break
                 }
@@ -241,10 +241,10 @@ final class SHA2 : HashProtocol {
             
             // Main loop
             for j in 0..<variant.k.count {
-                let s0 = rotateRight(A,n: 28) ^ rotateRight(A,n: 34) ^ rotateRight(A,n: 39) //FIXME: n:
+                let s0 = rotateRight(x: A,n: 28) ^ rotateRight(x: A,n: 34) ^ rotateRight(x: A,n: 39) //FIXME: n:
                 let maj = (A & B) ^ (A & C) ^ (B & C)
                 let t2 = s0 &+ maj
-                let s1 = rotateRight(E,n: 14) ^ rotateRight(E,n: 18) ^ rotateRight(E,n: 41)
+                let s1 = rotateRight(x: E,n: 14) ^ rotateRight(x: E,n: 18) ^ rotateRight(x: E,n: 41)
                 let ch = (E & F) ^ ((~E) & G)
                 let t1 = H &+ s1 &+ ch &+ variant.k[j] &+ UInt64(M[j])
                 
@@ -271,7 +271,7 @@ final class SHA2 : HashProtocol {
         // Produce the final hash value (big-endian)
         var result = Array<UInt8>()
         result.reserveCapacity(hh.count / 4)
-        variant.resultingArray(hh).forEach {
+        variant.resultingArray(hh: hh).forEach {
             let item = $0.bigEndian
             var partialResult = Array<UInt8>()
             partialResult.reserveCapacity(8)

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

@@ -34,23 +34,23 @@ extension String {
     }
 
     public func crc32(seed: UInt32? = nil, reflect : Bool = true) -> String {
-        return self.utf8.lazy.map({ $0 as UInt8 }).crc32(seed, reflect: reflect).toHexString()
+        return self.utf8.lazy.map({ $0 as UInt8 }).crc32(seed: seed, reflect: reflect).toHexString()
     }
 
     public func crc16(seed: UInt16? = nil) -> String {
-        return self.utf8.lazy.map({ $0 as UInt8 }).crc16(seed).toHexString()
+        return self.utf8.lazy.map({ $0 as UInt8 }).crc16(seed: seed).toHexString()
     }
 
     public func encrypt(cipher: Cipher) throws -> Array<UInt8> {
-        return try self.utf8.lazy.map({ $0 as UInt8 }).encrypt(cipher)
+        return try self.utf8.lazy.map({ $0 as UInt8 }).encrypt(cipher: cipher)
     }
 
     public func decrypt(cipher: Cipher) throws -> Array<UInt8> {
-        return try self.utf8.lazy.map({ $0 as UInt8 }).decrypt(cipher)
+        return try self.utf8.lazy.map({ $0 as UInt8 }).decrypt(cipher: cipher)
     }
     
     /// Returns hex string of bytes.
     public func authenticate(authenticator: Authenticator) throws -> String {
-        return  try self.utf8.lazy.map({ $0 as UInt8 }).authenticate(authenticator).toHexString()
+        return  try self.utf8.lazy.map({ $0 as UInt8 }).authenticate(authenticator: authenticator).toHexString()
     }
 }

+ 9 - 9
Sources/CryptoSwift/UInt32Extension.swift

@@ -19,16 +19,16 @@ extension UInt32: _UInt32Type {}
 /** array of bytes */
 extension UInt32 {
     public func bytes(totalBytes: Int = sizeof(UInt32)) -> Array<UInt8> {
-        return arrayOfBytes(self, length: totalBytes)
+        return arrayOfBytes(value: self, length: totalBytes)
     }
 
     public static func withBytes(bytes: ArraySlice<UInt8>) -> UInt32 {
-        return UInt32.withBytes(Array(bytes))
+        return UInt32.withBytes(bytes: Array(bytes))
     }
 
     /** Int with array bytes (little-endian) */
     public static func withBytes(bytes: Array<UInt8>) -> UInt32 {
-        return integerWithBytes(bytes)
+        return integerWithBytes(bytes: bytes)
     }
 }
 
@@ -92,25 +92,25 @@ extension UInt32 {
 }
 
 /** shift left and assign with bits truncation */
-public func &<<= (inout lhs: UInt32, rhs: UInt32) {
-    lhs.shiftLeft(rhs)
+public func &<<= (lhs: inout UInt32, rhs: UInt32) {
+    lhs.shiftLeft(count: rhs)
 }
 
 /** shift left with bits truncation */
 public func &<< (lhs: UInt32, rhs: UInt32) -> UInt32 {
     var l = lhs;
-    l.shiftLeft(rhs)
+    l.shiftLeft(count: rhs)
     return l
 }
 
 /** shift right and assign with bits truncation */
-func &>>= (inout lhs: UInt32, rhs: UInt32) {
-    lhs.shiftRight(rhs)
+func &>>= (lhs: inout UInt32, rhs: UInt32) {
+    lhs.shiftRight(count: rhs)
 }
 
 /** shift right and assign with bits truncation */
 func &>> (lhs: UInt32, rhs: UInt32) -> UInt32 {
     var l = lhs;
-    l.shiftRight(rhs)
+    l.shiftRight(count: rhs)
     return l
 }

+ 3 - 3
Sources/CryptoSwift/UInt64Extension.swift

@@ -9,15 +9,15 @@
 /** array of bytes */
 extension UInt64 {
     public func bytes(totalBytes: Int = sizeof(UInt64)) -> Array<UInt8> {
-        return arrayOfBytes(self, length: totalBytes)
+        return arrayOfBytes(value: self, length: totalBytes)
     }
 
     public static func withBytes(bytes: ArraySlice<UInt8>) -> UInt64 {
-        return UInt64.withBytes(Array(bytes))
+        return UInt64.withBytes(bytes: Array(bytes))
     }
 
     /** Int with array bytes (little-endian) */
     public static func withBytes(bytes: Array<UInt8>) -> UInt64 {
-        return integerWithBytes(bytes)
+        return integerWithBytes(bytes: bytes)
     }
 }

+ 4 - 4
Sources/CryptoSwift/UInt8Extension.swift

@@ -48,14 +48,14 @@ extension UInt8 {
 extension UInt8 {
 
     init(bits: [Bit]) {
-        self.init(integerFromBitsArray(bits) as UInt8)
+        self.init(integerFromBitsArray(bits: bits) as UInt8)
     }
     
     /** array of bits */
     func bits() -> [Bit] {
         let totalBitsCount = sizeofValue(self) * 8
         
-        var bitsArray = [Bit](count: totalBitsCount, repeatedValue: Bit.Zero)
+        var bitsArray = [Bit](repeating: Bit.Zero, count: totalBitsCount)
         
         for j in 0..<totalBitsCount {
             let bitVal:UInt8 = 1 << UInt8(totalBitsCount - 1 - j)
@@ -71,7 +71,7 @@ extension UInt8 {
     func bits() -> String {
         var s = String()
         let arr:[Bit] = self.bits()
-        for (idx,b) in arr.enumerate() {
+        for (idx,b) in arr.enumerated() {
             s += (b == Bit.One ? "1" : "0")
             if ((idx + 1) % 8 == 0) { s += " " }
         }
@@ -111,6 +111,6 @@ extension UInt8 {
 /** shift right and assign with bits truncation */
 func &>> (lhs: UInt8, rhs: UInt8) -> UInt8 {
     var l = lhs;
-    l.shiftRight(rhs)
+    l.shiftRight(count: rhs)
     return l
 }

+ 14 - 15
Sources/CryptoSwift/Utils.swift

@@ -55,11 +55,10 @@ func reverseUInt32(uint32 : UInt32) -> UInt32 {
 func toUInt32Array(slice: ArraySlice<UInt8>) -> Array<UInt32> {
     var result = Array<UInt32>()
     result.reserveCapacity(16)
-    
-    for idx in slice.startIndex.stride(to: slice.endIndex, by: sizeof(UInt32)) {
-        let val1:UInt32 = (UInt32(slice[idx.advancedBy(3)]) << 24)
-        let val2:UInt32 = (UInt32(slice[idx.advancedBy(2)]) << 16)
-        let val3:UInt32 = (UInt32(slice[idx.advancedBy(1)]) << 8)
+    for idx in stride(from: slice.startIndex, to: slice.endIndex, by: sizeof(UInt32)) {
+        let val1:UInt32 = (UInt32(slice[idx.advanced(by: 3)]) << 24)
+        let val2:UInt32 = (UInt32(slice[idx.advanced(by: 2)]) << 16)
+        let val3:UInt32 = (UInt32(slice[idx.advanced(by: 1)]) << 8)
         let val4:UInt32 = UInt32(slice[idx])
         let val:UInt32 = val1 | val2 | val3 | val4
         result.append(val)
@@ -70,23 +69,23 @@ func toUInt32Array(slice: ArraySlice<UInt8>) -> Array<UInt32> {
 func toUInt64Array(slice: ArraySlice<UInt8>) -> Array<UInt64> {
     var result = Array<UInt64>()
     result.reserveCapacity(32)
-    for idx in slice.startIndex.stride(to: slice.endIndex, by: sizeof(UInt64)) {
+    for idx in stride(from: slice.startIndex, to: slice.endIndex, by: sizeof(UInt64)) {
         var val:UInt64 = 0
-        val |= UInt64(slice[idx.advancedBy(7)]) << 56
-        val |= UInt64(slice[idx.advancedBy(6)]) << 48
-        val |= UInt64(slice[idx.advancedBy(5)]) << 40
-        val |= UInt64(slice[idx.advancedBy(4)]) << 32
-        val |= UInt64(slice[idx.advancedBy(3)]) << 24
-        val |= UInt64(slice[idx.advancedBy(2)]) << 16
-        val |= UInt64(slice[idx.advancedBy(1)]) << 8
-        val |= UInt64(slice[idx.advancedBy(0)]) << 0
+        val |= UInt64(slice[idx.advanced(by: 7)]) << 56
+        val |= UInt64(slice[idx.advanced(by: 6)]) << 48
+        val |= UInt64(slice[idx.advanced(by: 5)]) << 40
+        val |= UInt64(slice[idx.advanced(by: 4)]) << 32
+        val |= UInt64(slice[idx.advanced(by: 3)]) << 24
+        val |= UInt64(slice[idx.advanced(by: 2)]) << 16
+        val |= UInt64(slice[idx.advanced(by: 1)]) << 8
+        val |= UInt64(slice[idx.advanced(by: 0)]) << 0
         result.append(val)
     }
     return result
 }
 
 func xor(a: Array<UInt8>, _ b:Array<UInt8>) -> Array<UInt8> {
-    var xored = Array<UInt8>(count: min(a.count, b.count), repeatedValue: 0)
+    var xored = Array<UInt8>(repeating: 0, count: min(a.count, b.count))
     for i in 0..<xored.count {
         xored[i] = a[i] ^ b[i]
     }