Browse Source

Apply SwiftFormat (yay)

Marcin Krzyżanowski 8 years ago
parent
commit
5a9bb15403
49 changed files with 1119 additions and 1079 deletions
  1. 13 13
      CryptoSwift.playground/Contents.swift
  2. 1 1
      Package.swift
  3. 4 2
      Sources/CryptoSwift/AES.swift
  4. 13 14
      Sources/CryptoSwift/Array+Extension.swift
  5. 5 0
      Sources/CryptoSwift/BatchedCollection.swift
  6. 2 2
      Sources/CryptoSwift/BlockMode/BlockMode.swift
  7. 1 1
      Sources/CryptoSwift/BlockMode/CBC.swift
  8. 1 1
      Sources/CryptoSwift/BlockMode/CFB.swift
  9. 2 2
      Sources/CryptoSwift/BlockMode/CTR.swift
  10. 1 1
      Sources/CryptoSwift/BlockMode/ECB.swift
  11. 1 1
      Sources/CryptoSwift/BlockMode/OFB.swift
  12. 1 1
      Sources/CryptoSwift/BlockMode/PCBC.swift
  13. 343 320
      Sources/CryptoSwift/Blowfish.swift
  14. 1 1
      Sources/CryptoSwift/CSArrayType+Extensions.swift
  15. 35 35
      Sources/CryptoSwift/ChaCha20.swift
  16. 69 65
      Sources/CryptoSwift/Checksum.swift
  17. 5 5
      Sources/CryptoSwift/Collection+Extension.swift
  18. 0 1
      Sources/CryptoSwift/Digest.swift
  19. 1 1
      Sources/CryptoSwift/Foundation/CSArrayType+Foundation.swift
  20. 15 15
      Sources/CryptoSwift/Foundation/Data+Extension.swift
  21. 1 1
      Sources/CryptoSwift/Generics.swift
  22. 2 2
      Sources/CryptoSwift/HMAC.swift
  23. 46 42
      Sources/CryptoSwift/MD5.swift
  24. 2 2
      Sources/CryptoSwift/NoPadding.swift
  25. 7 7
      Sources/CryptoSwift/PKCS5/PBKDF1.swift
  26. 14 14
      Sources/CryptoSwift/PKCS5/PBKDF2.swift
  27. 5 5
      Sources/CryptoSwift/PKCS7.swift
  28. 6 7
      Sources/CryptoSwift/Poly1305.swift
  29. 15 15
      Sources/CryptoSwift/Rabbit.swift
  30. 25 25
      Sources/CryptoSwift/SHA1.swift
  31. 75 71
      Sources/CryptoSwift/SHA2.swift
  32. 38 36
      Sources/CryptoSwift/SHA3.swift
  33. 7 7
      Sources/CryptoSwift/SecureBytes.swift
  34. 12 13
      Sources/CryptoSwift/String+Extension.swift
  35. 7 7
      Sources/CryptoSwift/UInt8+Extension.swift
  36. 16 17
      Sources/CryptoSwift/Updatable.swift
  37. 7 8
      Sources/CryptoSwift/Utils.swift
  38. 2 2
      Sources/CryptoSwift/ZeroPadding.swift
  39. 37 37
      Tests/CryptoSwiftTests/AESTests.swift
  40. 91 92
      Tests/CryptoSwiftTests/Access.swift
  41. 96 96
      Tests/CryptoSwiftTests/BlowfishTests.swift
  42. 12 14
      Tests/CryptoSwiftTests/ChaCha20Tests.swift
  43. 27 14
      Tests/CryptoSwiftTests/DigestTests.swift
  44. 7 10
      Tests/CryptoSwiftTests/ExtensionsTest.swift
  45. 16 19
      Tests/CryptoSwiftTests/PBKDF.swift
  46. 4 4
      Tests/CryptoSwiftTests/Poly1305Tests.swift
  47. 24 27
      Tests/CryptoSwiftTests/RabbitTests.swift
  48. 1 3
      Tests/CryptoSwiftTests/RandomBytesSequenceTests.swift
  49. 3 0
      scripts/swiftformat.sh

+ 13 - 13
CryptoSwift.playground/Contents.swift

@@ -1,17 +1,17 @@
 /*:
 /*:
  To whom may be concerned: I offer professional support to all my open source projects.
  To whom may be concerned: I offer professional support to all my open source projects.
- 
+
  Contact: [marcin@krzyzanowskim.com](http://krzyzanowskim.com)
  Contact: [marcin@krzyzanowskim.com](http://krzyzanowskim.com)
-*/
+ */
 import CryptoSwift
 import CryptoSwift
 import Foundation
 import Foundation
 /*:
 /*:
  # Data types conversinn
  # Data types conversinn
  */
  */
-let data  = Data(bytes: [0x01, 0x02, 0x03])
+let data = Data(bytes: [0x01, 0x02, 0x03])
 let bytes = data.bytes
 let bytes = data.bytes
-let bytesHex    = Array<UInt8>(hex: "0x010203")
-let hexString   = bytesHex.toHexString()
+let bytesHex = Array<UInt8>(hex: "0x010203")
+let hexString = bytesHex.toHexString()
 
 
 /*:
 /*:
  # Digest
  # Digest
@@ -33,7 +33,7 @@ do {
     let partial1 = try digest.update(withBytes: [0x31, 0x32])
     let partial1 = try digest.update(withBytes: [0x31, 0x32])
     let partial2 = try digest.update(withBytes: [0x33])
     let partial2 = try digest.update(withBytes: [0x33])
     let result = try digest.finish()
     let result = try digest.finish()
-} catch { }
+} catch {}
 
 
 /*:
 /*:
  # CRC
  # CRC
@@ -46,7 +46,7 @@ bytes.crc32()
  */
  */
 
 
 do {
 do {
-    let key:Array<UInt8> = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,23,25,26,27,28,29,30,31,32]
+    let key: Array<UInt8> = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 23, 25, 26, 27, 28, 29, 30, 31, 32]
     try Poly1305(key: key).authenticate(bytes)
     try Poly1305(key: key).authenticate(bytes)
     try HMAC(key: key, variant: .sha256).authenticate(bytes)
     try HMAC(key: key, variant: .sha256).authenticate(bytes)
 } catch {}
 } catch {}
@@ -74,8 +74,8 @@ PKCS7().add(to: bytes, blockSize: AES.blockSize)
  */
  */
 
 
 do {
 do {
-    let key:Array<UInt8> = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32];
-    let iv:Array<UInt8> =  [1, 2, 3, 4, 5, 6, 7, 8]
+    let key: Array<UInt8> = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32]
+    let iv: Array<UInt8> = [1, 2, 3, 4, 5, 6, 7, 8]
     let message = Array<UInt8>(repeating: 7, count: 10)
     let message = Array<UInt8>(repeating: 7, count: 10)
 
 
     let encrypted = try ChaCha20(key: key, iv: iv).encrypt(message)
     let encrypted = try ChaCha20(key: key, iv: iv).encrypt(message)
@@ -143,17 +143,17 @@ do {
     var buffer = Array<UInt8>(repeating: 0, count: 2)
     var buffer = Array<UInt8>(repeating: 0, count: 2)
 
 
     // encrypt input stream data and write encrypted result to output stream
     // encrypt input stream data and write encrypted result to output stream
-    while (inputStream.hasBytesAvailable) {
+    while inputStream.hasBytesAvailable {
         let readCount = inputStream.read(&buffer, maxLength: buffer.count)
         let readCount = inputStream.read(&buffer, maxLength: buffer.count)
-        if (readCount > 0) {
-            try encryptor.update(withBytes: buffer[0..<readCount]) { (bytes) in
+        if readCount > 0 {
+            try encryptor.update(withBytes: buffer[0..<readCount]) { bytes in
                 writeTo(stream: outputStream, bytes: bytes)
                 writeTo(stream: outputStream, bytes: bytes)
             }
             }
         }
         }
     }
     }
 
 
     // finalize encryption
     // finalize encryption
-    try encryptor.finish { (bytes) in
+    try encryptor.finish { bytes in
         writeTo(stream: outputStream, bytes: bytes)
         writeTo(stream: outputStream, bytes: bytes)
     }
     }
 
 

+ 1 - 1
Package.swift

@@ -1,3 +1,3 @@
 import PackageDescription
 import PackageDescription
 
 
-let package = Package(name: "CryptoSwift")
+let package = Package(name: "CryptoSwift")

File diff suppressed because it is too large
+ 4 - 2
Sources/CryptoSwift/AES.swift


+ 13 - 14
Sources/CryptoSwift/Array+Extension.swift

@@ -30,11 +30,11 @@ extension Array {
     /** split in chunks with given chunk size */
     /** split in chunks with given chunk size */
     public func chunks(size chunksize: Int) -> Array<Array<Element>> {
     public func chunks(size chunksize: Int) -> Array<Array<Element>> {
         var words = Array<Array<Element>>()
         var words = Array<Array<Element>>()
-        words.reserveCapacity(self.count / chunksize)
-        for idx in stride(from: chunksize, through: self.count, by: chunksize) {
-            words.append(Array(self[idx - chunksize ..< idx])) // slow for large table
+        words.reserveCapacity(count / chunksize)
+        for idx in stride(from: chunksize, through: count, by: chunksize) {
+            words.append(Array(self[idx - chunksize..<idx])) // slow for large table
         }
         }
-        let remainder = self.suffix(self.count % chunksize)
+        let remainder = suffix(count % chunksize)
         if !remainder.isEmpty {
         if !remainder.isEmpty {
             words.append(Array(remainder))
             words.append(Array(remainder))
         }
         }
@@ -43,10 +43,10 @@ extension Array {
 }
 }
 
 
 extension Array where Element == UInt8 {
 extension Array where Element == UInt8 {
-    
+
     public init(hex: String) {
     public init(hex: String) {
         self.init(reserveCapacity: hex.unicodeScalars.lazy.underestimatedCount)
         self.init(reserveCapacity: hex.unicodeScalars.lazy.underestimatedCount)
-        var buffer:UInt8?
+        var buffer: UInt8?
         var skip = hex.hasPrefix("0x") ? 2 : 0
         var skip = hex.hasPrefix("0x") ? 2 : 0
         for char in hex.unicodeScalars.lazy {
         for char in hex.unicodeScalars.lazy {
             guard skip == 0 else {
             guard skip == 0 else {
@@ -54,12 +54,12 @@ extension Array where Element == UInt8 {
                 continue
                 continue
             }
             }
             guard char.value >= 48 && char.value <= 102 else {
             guard char.value >= 48 && char.value <= 102 else {
-                self.removeAll()
+                removeAll()
                 return
                 return
             }
             }
-            let v:UInt8
-            let c:UInt8 = UInt8(char.value)
-            switch c{
+            let v: UInt8
+            let c: UInt8 = UInt8(char.value)
+            switch c {
             case let c where c <= 57:
             case let c where c <= 57:
                 v = c - 48
                 v = c - 48
             case let c where c >= 65 && c <= 70:
             case let c where c >= 65 && c <= 70:
@@ -67,19 +67,18 @@ extension Array where Element == UInt8 {
             case let c where c >= 97:
             case let c where c >= 97:
                 v = c - 87
                 v = c - 87
             default:
             default:
-                self.removeAll()
+                removeAll()
                 return
                 return
             }
             }
             if let b = buffer {
             if let b = buffer {
-                self.append(b << 4 | v)
+                append(b << 4 | v)
                 buffer = nil
                 buffer = nil
             } else {
             } else {
                 buffer = v
                 buffer = v
             }
             }
         }
         }
         if let b = buffer {
         if let b = buffer {
-            self.append(b)
+            append(b)
         }
         }
     }
     }
-    
 }
 }

+ 5 - 0
Sources/CryptoSwift/BatchedCollection.swift

@@ -22,6 +22,7 @@ extension BatchedCollectionIndex: Comparable {
     static func ==<Base>(lhs: BatchedCollectionIndex<Base>, rhs: BatchedCollectionIndex<Base>) -> Bool {
     static func ==<Base>(lhs: BatchedCollectionIndex<Base>, rhs: BatchedCollectionIndex<Base>) -> Bool {
         return lhs.range.lowerBound == rhs.range.lowerBound
         return lhs.range.lowerBound == rhs.range.lowerBound
     }
     }
+
     static func < <Base>(lhs: BatchedCollectionIndex<Base>, rhs: BatchedCollectionIndex<Base>) -> Bool {
     static func < <Base>(lhs: BatchedCollectionIndex<Base>, rhs: BatchedCollectionIndex<Base>) -> Bool {
         return lhs.range.lowerBound < rhs.range.lowerBound
         return lhs.range.lowerBound < rhs.range.lowerBound
     }
     }
@@ -39,15 +40,19 @@ struct BatchedCollection<Base: Collection>: Collection {
         return base.index(idx, offsetBy: size, limitedBy: base.endIndex)
         return base.index(idx, offsetBy: size, limitedBy: base.endIndex)
             ?? base.endIndex
             ?? base.endIndex
     }
     }
+
     var startIndex: Index {
     var startIndex: Index {
         return Index(range: base.startIndex..<nextBreak(after: base.startIndex))
         return Index(range: base.startIndex..<nextBreak(after: base.startIndex))
     }
     }
+
     var endIndex: Index {
     var endIndex: Index {
         return Index(range: base.endIndex..<base.endIndex)
         return Index(range: base.endIndex..<base.endIndex)
     }
     }
+
     func index(after idx: Index) -> Index {
     func index(after idx: Index) -> Index {
         return Index(range: idx.range.upperBound..<nextBreak(after: idx.range.upperBound))
         return Index(range: idx.range.upperBound..<nextBreak(after: idx.range.upperBound))
     }
     }
+
     subscript(idx: Index) -> Base.SubSequence {
     subscript(idx: Index) -> Base.SubSequence {
         return base[idx.range]
         return base[idx.range]
     }
     }

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

@@ -20,7 +20,7 @@ public enum BlockMode {
     case ECB, CBC, PCBC, CFB, OFB, CTR
     case ECB, CBC, PCBC, CFB, OFB, CTR
 
 
     func worker(_ iv: Array<UInt8>?, cipherOperation: @escaping CipherOperationOnBlock) -> BlockModeWorker {
     func worker(_ iv: Array<UInt8>?, cipherOperation: @escaping CipherOperationOnBlock) -> BlockModeWorker {
-        switch (self) {
+        switch self {
         case .ECB:
         case .ECB:
             return ECBModeWorker(iv: iv ?? [], cipherOperation: cipherOperation)
             return ECBModeWorker(iv: iv ?? [], cipherOperation: cipherOperation)
         case .CBC:
         case .CBC:
@@ -37,7 +37,7 @@ public enum BlockMode {
     }
     }
 
 
     var options: BlockModeOptions {
     var options: BlockModeOptions {
-        switch (self) {
+        switch self {
         case .ECB:
         case .ECB:
             return .PaddingRequired
             return .PaddingRequired
         case .CBC:
         case .CBC:

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

@@ -42,7 +42,7 @@ struct CBCModeWorker: BlockModeWorker {
             return Array(ciphertext)
             return Array(ciphertext)
         }
         }
         let result = xor(prev ?? iv, plaintext)
         let result = xor(prev ?? iv, plaintext)
-        self.prev = Array(ciphertext)
+        prev = Array(ciphertext)
         return result
         return result
     }
     }
 }
 }

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

@@ -42,7 +42,7 @@ struct CFBModeWorker: BlockModeWorker {
             return Array(ciphertext)
             return Array(ciphertext)
         }
         }
         let result = xor(plaintext, ciphertext)
         let result = xor(plaintext, ciphertext)
-        self.prev = Array(ciphertext)
+        prev = Array(ciphertext)
         return result
         return result
     }
     }
 }
 }

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

@@ -47,8 +47,8 @@ struct CTRModeWorker: RandomAccessBlockModeWorker {
 
 
 private func buildNonce(_ iv: Array<UInt8>, counter: UInt64) -> Array<UInt8> {
 private func buildNonce(_ iv: Array<UInt8>, counter: UInt64) -> Array<UInt8> {
     let noncePartLen = AES.blockSize / 2
     let noncePartLen = AES.blockSize / 2
-    let noncePrefix = Array(iv[0 ..< noncePartLen])
-    let nonceSuffix = Array(iv[noncePartLen ..< iv.count])
+    let noncePrefix = Array(iv[0..<noncePartLen])
+    let nonceSuffix = Array(iv[noncePartLen..<iv.count])
     let c = UInt64(bytes: nonceSuffix) + counter
     let c = UInt64(bytes: nonceSuffix) + counter
     return noncePrefix + c.bytes()
     return noncePrefix + c.bytes()
 }
 }

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

@@ -21,7 +21,7 @@ struct ECBModeWorker: BlockModeWorker {
     typealias Element = Array<UInt8>
     typealias Element = Array<UInt8>
     let cipherOperation: CipherOperationOnBlock
     let cipherOperation: CipherOperationOnBlock
 
 
-    init(iv: Array<UInt8>, cipherOperation: @escaping CipherOperationOnBlock) {
+    init(iv _: Array<UInt8>, cipherOperation: @escaping CipherOperationOnBlock) {
         self.cipherOperation = cipherOperation
         self.cipherOperation = cipherOperation
     }
     }
 
 

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

@@ -42,7 +42,7 @@ struct OFBModeWorker: BlockModeWorker {
             return Array(ciphertext)
             return Array(ciphertext)
         }
         }
         let plaintext = xor(decrypted, ciphertext)
         let plaintext = xor(decrypted, ciphertext)
-        self.prev = decrypted
+        prev = decrypted
         return plaintext
         return plaintext
     }
     }
 }
 }

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

@@ -42,7 +42,7 @@ struct PCBCModeWorker: BlockModeWorker {
             return Array(ciphertext)
             return Array(ciphertext)
         }
         }
         let result = xor(prev ?? iv, plaintext)
         let result = xor(prev ?? iv, plaintext)
-        self.prev = xor(plaintext, ciphertext)
+        prev = xor(plaintext, ciphertext)
         return result
         return result
     }
     }
 }
 }

+ 343 - 320
Sources/CryptoSwift/Blowfish.swift

@@ -34,282 +34,293 @@ public final class Blowfish {
     fileprivate let blockMode: BlockMode
     fileprivate let blockMode: BlockMode
     fileprivate let padding: Padding
     fileprivate let padding: Padding
     fileprivate lazy var decryptWorker: BlockModeWorker = {
     fileprivate lazy var decryptWorker: BlockModeWorker = {
-        switch (self.blockMode) {
-            case .CFB, .OFB, .CTR:
-                return self.blockMode.worker(self.iv, cipherOperation: self.encrypt)
-            default:
-                return self.blockMode.worker(self.iv, cipherOperation: self.decrypt)
+        switch self.blockMode {
+        case .CFB, .OFB, .CTR:
+            return self.blockMode.worker(self.iv, cipherOperation: self.encrypt)
+        default:
+            return self.blockMode.worker(self.iv, cipherOperation: self.decrypt)
         }
         }
     }()
     }()
+
     fileprivate lazy var encryptWorker: BlockModeWorker = {
     fileprivate lazy var encryptWorker: BlockModeWorker = {
-        return self.blockMode.worker(self.iv, cipherOperation: self.encrypt)
+        self.blockMode.worker(self.iv, cipherOperation: self.encrypt)
     }()
     }()
 
 
     private let N = 16 // rounds
     private let N = 16 // rounds
     private var P: Array<UInt32>
     private var P: Array<UInt32>
     private var S: Array<Array<UInt32>>
     private var S: Array<Array<UInt32>>
-    private let origP: Array<UInt32> = [0x243f6a88, 0x85a308d3, 0x13198a2e, 0x03707344, 0xa4093822,
-                                0x299f31d0, 0x082efa98, 0xec4e6c89, 0x452821e6, 0x38d01377,
-                                0xbe5466cf, 0x34e90c6c, 0xc0ac29b7, 0xc97c50dd, 0x3f84d5b5,
-                                0xb5470917, 0x9216d5d9, 0x8979fb1b]
+    private let origP: Array<UInt32> = [
+        0x243f6a88, 0x85a308d3, 0x13198a2e, 0x03707344, 0xa4093822,
+        0x299f31d0, 0x082efa98, 0xec4e6c89, 0x452821e6, 0x38d01377,
+        0xbe5466cf, 0x34e90c6c, 0xc0ac29b7, 0xc97c50dd, 0x3f84d5b5,
+        0xb5470917, 0x9216d5d9, 0x8979fb1b,
+    ]
 
 
     private let origS: Array<Array<UInt32>> = [
     private let origS: Array<Array<UInt32>> = [
-        [0xD1310BA6, 0x98DFB5AC, 0x2FFD72DB, 0xD01ADFB7,
-         0xB8E1AFED, 0x6A267E96, 0xBA7C9045, 0xF12C7F99,
-         0x24A19947, 0xB3916CF7, 0x0801F2E2, 0x858EFC16,
-         0x636920D8, 0x71574E69, 0xA458FEA3, 0xF4933D7E,
-         0x0D95748F, 0x728EB658, 0x718BCD58, 0x82154AEE,
-         0x7B54A41D, 0xC25A59B5, 0x9C30D539, 0x2AF26013,
-         0xC5D1B023, 0x286085F0, 0xCA417918, 0xB8DB38EF,
-         0x8E79DCB0, 0x603A180E, 0x6C9E0E8B, 0xB01E8A3E,
-         0xD71577C1, 0xBD314B27, 0x78AF2FDA, 0x55605C60,
-         0xE65525F3, 0xAA55AB94, 0x57489862, 0x63E81440,
-         0x55CA396A, 0x2AAB10B6, 0xB4CC5C34, 0x1141E8CE,
-         0xA15486AF, 0x7C72E993, 0xB3EE1411, 0x636FBC2A,
-         0x2BA9C55D, 0x741831F6, 0xCE5C3E16, 0x9B87931E,
-         0xAFD6BA33, 0x6C24CF5C, 0x7A325381, 0x28958677,
-         0x3B8F4898, 0x6B4BB9AF, 0xC4BFE81B, 0x66282193,
-         0x61D809CC, 0xFB21A991, 0x487CAC60, 0x5DEC8032,
-         0xEF845D5D, 0xE98575B1, 0xDC262302, 0xEB651B88,
-         0x23893E81, 0xD396ACC5, 0x0F6D6FF3, 0x83F44239,
-         0x2E0B4482, 0xA4842004, 0x69C8F04A, 0x9E1F9B5E,
-         0x21C66842, 0xF6E96C9A, 0x670C9C61, 0xABD388F0,
-         0x6A51A0D2, 0xD8542F68, 0x960FA728, 0xAB5133A3,
-         0x6EEF0B6C, 0x137A3BE4, 0xBA3BF050, 0x7EFB2A98,
-         0xA1F1651D, 0x39AF0176, 0x66CA593E, 0x82430E88,
-         0x8CEE8619, 0x456F9FB4, 0x7D84A5C3, 0x3B8B5EBE,
-         0xE06F75D8, 0x85C12073, 0x401A449F, 0x56C16AA6,
-         0x4ED3AA62, 0x363F7706, 0x1BFEDF72, 0x429B023D,
-         0x37D0D724, 0xD00A1248, 0xDB0FEAD3, 0x49F1C09B,
-         0x075372C9, 0x80991B7B, 0x25D479D8, 0xF6E8DEF7,
-         0xE3FE501A, 0xB6794C3B, 0x976CE0BD, 0x04C006BA,
-         0xC1A94FB6, 0x409F60C4, 0x5E5C9EC2, 0x196A2463,
-         0x68FB6FAF, 0x3E6C53B5, 0x1339B2EB, 0x3B52EC6F,
-         0x6DFC511F, 0x9B30952C, 0xCC814544, 0xAF5EBD09,
-         0xBEE3D004, 0xDE334AFD, 0x660F2807, 0x192E4BB3,
-         0xC0CBA857, 0x45C8740F, 0xD20B5F39, 0xB9D3FBDB,
-         0x5579C0BD, 0x1A60320A, 0xD6A100C6, 0x402C7279,
-         0x679F25FE, 0xFB1FA3CC, 0x8EA5E9F8, 0xDB3222F8,
-         0x3C7516DF, 0xFD616B15, 0x2F501EC8, 0xAD0552AB,
-         0x323DB5FA, 0xFD238760, 0x53317B48, 0x3E00DF82,
-         0x9E5C57BB, 0xCA6F8CA0, 0x1A87562E, 0xDF1769DB,
-         0xD542A8F6, 0x287EFFC3, 0xAC6732C6, 0x8C4F5573,
-         0x695B27B0, 0xBBCA58C8, 0xE1FFA35D, 0xB8F011A0,
-         0x10FA3D98, 0xFD2183B8, 0x4AFCB56C, 0x2DD1D35B,
-         0x9A53E479, 0xB6F84565, 0xD28E49BC, 0x4BFB9790,
-         0xE1DDF2DA, 0xA4CB7E33, 0x62FB1341, 0xCEE4C6E8,
-         0xEF20CADA, 0x36774C01, 0xD07E9EFE, 0x2BF11FB4,
-         0x95DBDA4D, 0xAE909198, 0xEAAD8E71, 0x6B93D5A0,
-         0xD08ED1D0, 0xAFC725E0, 0x8E3C5B2F, 0x8E7594B7,
-         0x8FF6E2FB, 0xF2122B64, 0x8888B812, 0x900DF01C,
-         0x4FAD5EA0, 0x688FC31C, 0xD1CFF191, 0xB3A8C1AD,
-         0x2F2F2218, 0xBE0E1777, 0xEA752DFE, 0x8B021FA1,
-         0xE5A0CC0F, 0xB56F74E8, 0x18ACF3D6, 0xCE89E299,
-         0xB4A84FE0, 0xFD13E0B7, 0x7CC43B81, 0xD2ADA8D9,
-         0x165FA266, 0x80957705, 0x93CC7314, 0x211A1477,
-         0xE6AD2065, 0x77B5FA86, 0xC75442F5, 0xFB9D35CF,
-         0xEBCDAF0C, 0x7B3E89A0, 0xD6411BD3, 0xAE1E7E49,
-         0x00250E2D, 0x2071B35E, 0x226800BB, 0x57B8E0AF,
-         0x2464369B, 0xF009B91E, 0x5563911D, 0x59DFA6AA,
-         0x78C14389, 0xD95A537F, 0x207D5BA2, 0x02E5B9C5,
-         0x83260376, 0x6295CFA9, 0x11C81968, 0x4E734A41,
-         0xB3472DCA, 0x7B14A94A, 0x1B510052, 0x9A532915,
-         0xD60F573F, 0xBC9BC6E4, 0x2B60A476, 0x81E67400,
-         0x08BA6FB5, 0x571BE91F, 0xF296EC6B, 0x2A0DD915,
-         0xB6636521, 0xE7B9F9B6, 0xFF34052E, 0xC5855664,
-         0x53B02D5D, 0xA99F8FA1, 0x08BA4799, 0x6E85076A],
-        [0x4B7A70E9, 0xB5B32944, 0xDB75092E, 0xC4192623,
-         0xAD6EA6B0, 0x49A7DF7D, 0x9CEE60B8, 0x8FEDB266,
-         0xECAA8C71, 0x699A17FF, 0x5664526C, 0xC2B19EE1,
-         0x193602A5, 0x75094C29, 0xA0591340, 0xE4183A3E,
-         0x3F54989A, 0x5B429D65, 0x6B8FE4D6, 0x99F73FD6,
-         0xA1D29C07, 0xEFE830F5, 0x4D2D38E6, 0xF0255DC1,
-         0x4CDD2086, 0x8470EB26, 0x6382E9C6, 0x021ECC5E,
-         0x09686B3F, 0x3EBAEFC9, 0x3C971814, 0x6B6A70A1,
-         0x687F3584, 0x52A0E286, 0xB79C5305, 0xAA500737,
-         0x3E07841C, 0x7FDEAE5C, 0x8E7D44EC, 0x5716F2B8,
-         0xB03ADA37, 0xF0500C0D, 0xF01C1F04, 0x0200B3FF,
-         0xAE0CF51A, 0x3CB574B2, 0x25837A58, 0xDC0921BD,
-         0xD19113F9, 0x7CA92FF6, 0x94324773, 0x22F54701,
-         0x3AE5E581, 0x37C2DADC, 0xC8B57634, 0x9AF3DDA7,
-         0xA9446146, 0x0FD0030E, 0xECC8C73E, 0xA4751E41,
-         0xE238CD99, 0x3BEA0E2F, 0x3280BBA1, 0x183EB331,
-         0x4E548B38, 0x4F6DB908, 0x6F420D03, 0xF60A04BF,
-         0x2CB81290, 0x24977C79, 0x5679B072, 0xBCAF89AF,
-         0xDE9A771F, 0xD9930810, 0xB38BAE12, 0xDCCF3F2E,
-         0x5512721F, 0x2E6B7124, 0x501ADDE6, 0x9F84CD87,
-         0x7A584718, 0x7408DA17, 0xBC9F9ABC, 0xE94B7D8C,
-         0xEC7AEC3A, 0xDB851DFA, 0x63094366, 0xC464C3D2,
-         0xEF1C1847, 0x3215D908, 0xDD433B37, 0x24C2BA16,
-         0x12A14D43, 0x2A65C451, 0x50940002, 0x133AE4DD,
-         0x71DFF89E, 0x10314E55, 0x81AC77D6, 0x5F11199B,
-         0x043556F1, 0xD7A3C76B, 0x3C11183B, 0x5924A509,
-         0xF28FE6ED, 0x97F1FBFA, 0x9EBABF2C, 0x1E153C6E,
-         0x86E34570, 0xEAE96FB1, 0x860E5E0A, 0x5A3E2AB3,
-         0x771FE71C, 0x4E3D06FA, 0x2965DCB9, 0x99E71D0F,
-         0x803E89D6, 0x5266C825, 0x2E4CC978, 0x9C10B36A,
-         0xC6150EBA, 0x94E2EA78, 0xA5FC3C53, 0x1E0A2DF4,
-         0xF2F74EA7, 0x361D2B3D, 0x1939260F, 0x19C27960,
-         0x5223A708, 0xF71312B6, 0xEBADFE6E, 0xEAC31F66,
-         0xE3BC4595, 0xA67BC883, 0xB17F37D1, 0x018CFF28,
-         0xC332DDEF, 0xBE6C5AA5, 0x65582185, 0x68AB9802,
-         0xEECEA50F, 0xDB2F953B, 0x2AEF7DAD, 0x5B6E2F84,
-         0x1521B628, 0x29076170, 0xECDD4775, 0x619F1510,
-         0x13CCA830, 0xEB61BD96, 0x0334FE1E, 0xAA0363CF,
-         0xB5735C90, 0x4C70A239, 0xD59E9E0B, 0xCBAADE14,
-         0xEECC86BC, 0x60622CA7, 0x9CAB5CAB, 0xB2F3846E,
-         0x648B1EAF, 0x19BDF0CA, 0xA02369B9, 0x655ABB50,
-         0x40685A32, 0x3C2AB4B3, 0x319EE9D5, 0xC021B8F7,
-         0x9B540B19, 0x875FA099, 0x95F7997E, 0x623D7DA8,
-         0xF837889A, 0x97E32D77, 0x11ED935F, 0x16681281,
-         0x0E358829, 0xC7E61FD6, 0x96DEDFA1, 0x7858BA99,
-         0x57F584A5, 0x1B227263, 0x9B83C3FF, 0x1AC24696,
-         0xCDB30AEB, 0x532E3054, 0x8FD948E4, 0x6DBC3128,
-         0x58EBF2EF, 0x34C6FFEA, 0xFE28ED61, 0xEE7C3C73,
-         0x5D4A14D9, 0xE864B7E3, 0x42105D14, 0x203E13E0,
-         0x45EEE2B6, 0xA3AAABEA, 0xDB6C4F15, 0xFACB4FD0,
-         0xC742F442, 0xEF6ABBB5, 0x654F3B1D, 0x41CD2105,
-         0xD81E799E, 0x86854DC7, 0xE44B476A, 0x3D816250,
-         0xCF62A1F2, 0x5B8D2646, 0xFC8883A0, 0xC1C7B6A3,
-         0x7F1524C3, 0x69CB7492, 0x47848A0B, 0x5692B285,
-         0x095BBF00, 0xAD19489D, 0x1462B174, 0x23820E00,
-         0x58428D2A, 0x0C55F5EA, 0x1DADF43E, 0x233F7061,
-         0x3372F092, 0x8D937E41, 0xD65FECF1, 0x6C223BDB,
-         0x7CDE3759, 0xCBEE7460, 0x4085F2A7, 0xCE77326E,
-         0xA6078084, 0x19F8509E, 0xE8EFD855, 0x61D99735,
-         0xA969A7AA, 0xC50C06C2, 0x5A04ABFC, 0x800BCADC,
-         0x9E447A2E, 0xC3453484, 0xFDD56705, 0x0E1E9EC9,
-         0xDB73DBD3, 0x105588CD, 0x675FDA79, 0xE3674340,
-         0xC5C43465, 0x713E38D8, 0x3D28F89E, 0xF16DFF20,
-         0x153E21E7, 0x8FB03D4A, 0xE6E39F2B, 0xDB83ADF7],
-        [0xE93D5A68, 0x948140F7, 0xF64C261C, 0x94692934,
-         0x411520F7, 0x7602D4F7, 0xBCF46B2E, 0xD4A20068,
-         0xD4082471, 0x3320F46A, 0x43B7D4B7, 0x500061AF,
-         0x1E39F62E, 0x97244546, 0x14214F74, 0xBF8B8840,
-         0x4D95FC1D, 0x96B591AF, 0x70F4DDD3, 0x66A02F45,
-         0xBFBC09EC, 0x03BD9785, 0x7FAC6DD0, 0x31CB8504,
-         0x96EB27B3, 0x55FD3941, 0xDA2547E6, 0xABCA0A9A,
-         0x28507825, 0x530429F4, 0x0A2C86DA, 0xE9B66DFB,
-         0x68DC1462, 0xD7486900, 0x680EC0A4, 0x27A18DEE,
-         0x4F3FFEA2, 0xE887AD8C, 0xB58CE006, 0x7AF4D6B6,
-         0xAACE1E7C, 0xD3375FEC, 0xCE78A399, 0x406B2A42,
-         0x20FE9E35, 0xD9F385B9, 0xEE39D7AB, 0x3B124E8B,
-         0x1DC9FAF7, 0x4B6D1856, 0x26A36631, 0xEAE397B2,
-         0x3A6EFA74, 0xDD5B4332, 0x6841E7F7, 0xCA7820FB,
-         0xFB0AF54E, 0xD8FEB397, 0x454056AC, 0xBA489527,
-         0x55533A3A, 0x20838D87, 0xFE6BA9B7, 0xD096954B,
-         0x55A867BC, 0xA1159A58, 0xCCA92963, 0x99E1DB33,
-         0xA62A4A56, 0x3F3125F9, 0x5EF47E1C, 0x9029317C,
-         0xFDF8E802, 0x04272F70, 0x80BB155C, 0x05282CE3,
-         0x95C11548, 0xE4C66D22, 0x48C1133F, 0xC70F86DC,
-         0x07F9C9EE, 0x41041F0F, 0x404779A4, 0x5D886E17,
-         0x325F51EB, 0xD59BC0D1, 0xF2BCC18F, 0x41113564,
-         0x257B7834, 0x602A9C60, 0xDFF8E8A3, 0x1F636C1B,
-         0x0E12B4C2, 0x02E1329E, 0xAF664FD1, 0xCAD18115,
-         0x6B2395E0, 0x333E92E1, 0x3B240B62, 0xEEBEB922,
-         0x85B2A20E, 0xE6BA0D99, 0xDE720C8C, 0x2DA2F728,
-         0xD0127845, 0x95B794FD, 0x647D0862, 0xE7CCF5F0,
-         0x5449A36F, 0x877D48FA, 0xC39DFD27, 0xF33E8D1E,
-         0x0A476341, 0x992EFF74, 0x3A6F6EAB, 0xF4F8FD37,
-         0xA812DC60, 0xA1EBDDF8, 0x991BE14C, 0xDB6E6B0D,
-         0xC67B5510, 0x6D672C37, 0x2765D43B, 0xDCD0E804,
-         0xF1290DC7, 0xCC00FFA3, 0xB5390F92, 0x690FED0B,
-         0x667B9FFB, 0xCEDB7D9C, 0xA091CF0B, 0xD9155EA3,
-         0xBB132F88, 0x515BAD24, 0x7B9479BF, 0x763BD6EB,
-         0x37392EB3, 0xCC115979, 0x8026E297, 0xF42E312D,
-         0x6842ADA7, 0xC66A2B3B, 0x12754CCC, 0x782EF11C,
-         0x6A124237, 0xB79251E7, 0x06A1BBE6, 0x4BFB6350,
-         0x1A6B1018, 0x11CAEDFA, 0x3D25BDD8, 0xE2E1C3C9,
-         0x44421659, 0x0A121386, 0xD90CEC6E, 0xD5ABEA2A,
-         0x64AF674E, 0xDA86A85F, 0xBEBFE988, 0x64E4C3FE,
-         0x9DBC8057, 0xF0F7C086, 0x60787BF8, 0x6003604D,
-         0xD1FD8346, 0xF6381FB0, 0x7745AE04, 0xD736FCCC,
-         0x83426B33, 0xF01EAB71, 0xB0804187, 0x3C005E5F,
-         0x77A057BE, 0xBDE8AE24, 0x55464299, 0xBF582E61,
-         0x4E58F48F, 0xF2DDFDA2, 0xF474EF38, 0x8789BDC2,
-         0x5366F9C3, 0xC8B38E74, 0xB475F255, 0x46FCD9B9,
-         0x7AEB2661, 0x8B1DDF84, 0x846A0E79, 0x915F95E2,
-         0x466E598E, 0x20B45770, 0x8CD55591, 0xC902DE4C,
-         0xB90BACE1, 0xBB8205D0, 0x11A86248, 0x7574A99E,
-         0xB77F19B6, 0xE0A9DC09, 0x662D09A1, 0xC4324633,
-         0xE85A1F02, 0x09F0BE8C, 0x4A99A025, 0x1D6EFE10,
-         0x1AB93D1D, 0x0BA5A4DF, 0xA186F20F, 0x2868F169,
-         0xDCB7DA83, 0x573906FE, 0xA1E2CE9B, 0x4FCD7F52,
-         0x50115E01, 0xA70683FA, 0xA002B5C4, 0x0DE6D027,
-         0x9AF88C27, 0x773F8641, 0xC3604C06, 0x61A806B5,
-         0xF0177A28, 0xC0F586E0, 0x006058AA, 0x30DC7D62,
-         0x11E69ED7, 0x2338EA63, 0x53C2DD94, 0xC2C21634,
-         0xBBCBEE56, 0x90BCB6DE, 0xEBFC7DA1, 0xCE591D76,
-         0x6F05E409, 0x4B7C0188, 0x39720A3D, 0x7C927C24,
-         0x86E3725F, 0x724D9DB9, 0x1AC15BB4, 0xD39EB8FC,
-         0xED545578, 0x08FCA5B5, 0xD83D7CD3, 0x4DAD0FC4,
-         0x1E50EF5E, 0xB161E6F8, 0xA28514D9, 0x6C51133C,
-         0x6FD5C7E7, 0x56E14EC4, 0x362ABFCE, 0xDDC6C837,
-         0xD79A3234, 0x92638212, 0x670EFA8E, 0x406000E0],
-        [0x3A39CE37, 0xD3FAF5CF, 0xABC27737, 0x5AC52D1B,
-         0x5CB0679E, 0x4FA33742, 0xD3822740, 0x99BC9BBE,
-         0xD5118E9D, 0xBF0F7315, 0xD62D1C7E, 0xC700C47B,
-         0xB78C1B6B, 0x21A19045, 0xB26EB1BE, 0x6A366EB4,
-         0x5748AB2F, 0xBC946E79, 0xC6A376D2, 0x6549C2C8,
-         0x530FF8EE, 0x468DDE7D, 0xD5730A1D, 0x4CD04DC6,
-         0x2939BBDB, 0xA9BA4650, 0xAC9526E8, 0xBE5EE304,
-         0xA1FAD5F0, 0x6A2D519A, 0x63EF8CE2, 0x9A86EE22,
-         0xC089C2B8, 0x43242EF6, 0xA51E03AA, 0x9CF2D0A4,
-         0x83C061BA, 0x9BE96A4D, 0x8FE51550, 0xBA645BD6,
-         0x2826A2F9, 0xA73A3AE1, 0x4BA99586, 0xEF5562E9,
-         0xC72FEFD3, 0xF752F7DA, 0x3F046F69, 0x77FA0A59,
-         0x80E4A915, 0x87B08601, 0x9B09E6AD, 0x3B3EE593,
-         0xE990FD5A, 0x9E34D797, 0x2CF0B7D9, 0x022B8B51,
-         0x96D5AC3A, 0x017DA67D, 0xD1CF3ED6, 0x7C7D2D28,
-         0x1F9F25CF, 0xADF2B89B, 0x5AD6B472, 0x5A88F54C,
-         0xE029AC71, 0xE019A5E6, 0x47B0ACFD, 0xED93FA9B,
-         0xE8D3C48D, 0x283B57CC, 0xF8D56629, 0x79132E28,
-         0x785F0191, 0xED756055, 0xF7960E44, 0xE3D35E8C,
-         0x15056DD4, 0x88F46DBA, 0x03A16125, 0x0564F0BD,
-         0xC3EB9E15, 0x3C9057A2, 0x97271AEC, 0xA93A072A,
-         0x1B3F6D9B, 0x1E6321F5, 0xF59C66FB, 0x26DCF319,
-         0x7533D928, 0xB155FDF5, 0x03563482, 0x8ABA3CBB,
-         0x28517711, 0xC20AD9F8, 0xABCC5167, 0xCCAD925F,
-         0x4DE81751, 0x3830DC8E, 0x379D5862, 0x9320F991,
-         0xEA7A90C2, 0xFB3E7BCE, 0x5121CE64, 0x774FBE32,
-         0xA8B6E37E, 0xC3293D46, 0x48DE5369, 0x6413E680,
-         0xA2AE0810, 0xDD6DB224, 0x69852DFD, 0x09072166,
-         0xB39A460A, 0x6445C0DD, 0x586CDECF, 0x1C20C8AE,
-         0x5BBEF7DD, 0x1B588D40, 0xCCD2017F, 0x6BB4E3BB,
-         0xDDA26A7E, 0x3A59FF45, 0x3E350A44, 0xBCB4CDD5,
-         0x72EACEA8, 0xFA6484BB, 0x8D6612AE, 0xBF3C6F47,
-         0xD29BE463, 0x542F5D9E, 0xAEC2771B, 0xF64E6370,
-         0x740E0D8D, 0xE75B1357, 0xF8721671, 0xAF537D5D,
-         0x4040CB08, 0x4EB4E2CC, 0x34D2466A, 0x0115AF84,
-         0xE1B00428, 0x95983A1D, 0x06B89FB4, 0xCE6EA048,
-         0x6F3F3B82, 0x3520AB82, 0x011A1D4B, 0x277227F8,
-         0x611560B1, 0xE7933FDC, 0xBB3A792B, 0x344525BD,
-         0xA08839E1, 0x51CE794B, 0x2F32C9B7, 0xA01FBAC9,
-         0xE01CC87E, 0xBCC7D1F6, 0xCF0111C3, 0xA1E8AAC7,
-         0x1A908749, 0xD44FBD9A, 0xD0DADECB, 0xD50ADA38,
-         0x0339C32A, 0xC6913667, 0x8DF9317C, 0xE0B12B4F,
-         0xF79E59B7, 0x43F5BB3A, 0xF2D519FF, 0x27D9459C,
-         0xBF97222C, 0x15E6FC2A, 0x0F91FC71, 0x9B941525,
-         0xFAE59361, 0xCEB69CEB, 0xC2A86459, 0x12BAA8D1,
-         0xB6C1075E, 0xE3056A0C, 0x10D25065, 0xCB03A442,
-         0xE0EC6E0E, 0x1698DB3B, 0x4C98A0BE, 0x3278E964,
-         0x9F1F9532, 0xE0D392DF, 0xD3A0342B, 0x8971F21E,
-         0x1B0A7441, 0x4BA3348C, 0xC5BE7120, 0xC37632D8,
-         0xDF359F8D, 0x9B992F2E, 0xE60B6F47, 0x0FE3F11D,
-         0xE54CDA54, 0x1EDAD891, 0xCE6279CF, 0xCD3E7E6F,
-         0x1618B166, 0xFD2C1D05, 0x848FD2C5, 0xF6FB2299,
-         0xF523F357, 0xA6327623, 0x93A83531, 0x56CCCD02,
-         0xACF08162, 0x5A75EBB5, 0x6E163697, 0x88D273CC,
-         0xDE966292, 0x81B949D0, 0x4C50901B, 0x71C65614,
-         0xE6C6C7BD, 0x327A140A, 0x45E1D006, 0xC3F27B9A,
-         0xC9AA53FD, 0x62A80F00, 0xBB25BFE2, 0x35BDD2F6,
-         0x71126905, 0xB2040222, 0xB6CBCF7C, 0xCD769C2B,
-         0x53113EC0, 0x1640E3D3, 0x38ABBD60, 0x2547ADF0,
-         0xBA38209C, 0xF746CE76, 0x77AFA1C5, 0x20756060,
-         0x85CBFE4E, 0x8AE88DD8, 0x7AAAF9B0, 0x4CF9AA7E,
-         0x1948C25C, 0x02FB8A8C, 0x01C36AE4, 0xD6EBE1F9,
-         0x90D4F869, 0xA65CDEA0, 0x3F09252D, 0xC208E69F,
-         0xB74E6132, 0xCE77E25B, 0x578FDFE3, 0x3AC372E6]
+        [
+            0xd1310ba6, 0x98dfb5ac, 0x2ffd72db, 0xd01adfb7,
+            0xb8e1afed, 0x6a267e96, 0xba7c9045, 0xf12c7f99,
+            0x24a19947, 0xb3916cf7, 0x0801f2e2, 0x858efc16,
+            0x636920d8, 0x71574e69, 0xa458fea3, 0xf4933d7e,
+            0x0d95748f, 0x728eb658, 0x718bcd58, 0x82154aee,
+            0x7b54a41d, 0xc25a59b5, 0x9c30d539, 0x2af26013,
+            0xc5d1b023, 0x286085f0, 0xca417918, 0xb8db38ef,
+            0x8e79dcb0, 0x603a180e, 0x6c9e0e8b, 0xb01e8a3e,
+            0xd71577c1, 0xbd314b27, 0x78af2fda, 0x55605c60,
+            0xe65525f3, 0xaa55ab94, 0x57489862, 0x63e81440,
+            0x55ca396a, 0x2aab10b6, 0xb4cc5c34, 0x1141e8ce,
+            0xa15486af, 0x7c72e993, 0xb3ee1411, 0x636fbc2a,
+            0x2ba9c55d, 0x741831f6, 0xce5c3e16, 0x9b87931e,
+            0xafd6ba33, 0x6c24cf5c, 0x7a325381, 0x28958677,
+            0x3b8f4898, 0x6b4bb9af, 0xc4bfe81b, 0x66282193,
+            0x61d809cc, 0xfb21a991, 0x487cac60, 0x5dec8032,
+            0xef845d5d, 0xe98575b1, 0xdc262302, 0xeb651b88,
+            0x23893e81, 0xd396acc5, 0x0f6d6ff3, 0x83f44239,
+            0x2e0b4482, 0xa4842004, 0x69c8f04a, 0x9e1f9b5e,
+            0x21c66842, 0xf6e96c9a, 0x670c9c61, 0xabd388f0,
+            0x6a51a0d2, 0xd8542f68, 0x960fa728, 0xab5133a3,
+            0x6eef0b6c, 0x137a3be4, 0xba3bf050, 0x7efb2a98,
+            0xa1f1651d, 0x39af0176, 0x66ca593e, 0x82430e88,
+            0x8cee8619, 0x456f9fb4, 0x7d84a5c3, 0x3b8b5ebe,
+            0xe06f75d8, 0x85c12073, 0x401a449f, 0x56c16aa6,
+            0x4ed3aa62, 0x363f7706, 0x1bfedf72, 0x429b023d,
+            0x37d0d724, 0xd00a1248, 0xdb0fead3, 0x49f1c09b,
+            0x075372c9, 0x80991b7b, 0x25d479d8, 0xf6e8def7,
+            0xe3fe501a, 0xb6794c3b, 0x976ce0bd, 0x04c006ba,
+            0xc1a94fb6, 0x409f60c4, 0x5e5c9ec2, 0x196a2463,
+            0x68fb6faf, 0x3e6c53b5, 0x1339b2eb, 0x3b52ec6f,
+            0x6dfc511f, 0x9b30952c, 0xcc814544, 0xaf5ebd09,
+            0xbee3d004, 0xde334afd, 0x660f2807, 0x192e4bb3,
+            0xc0cba857, 0x45c8740f, 0xd20b5f39, 0xb9d3fbdb,
+            0x5579c0bd, 0x1a60320a, 0xd6a100c6, 0x402c7279,
+            0x679f25fe, 0xfb1fa3cc, 0x8ea5e9f8, 0xdb3222f8,
+            0x3c7516df, 0xfd616b15, 0x2f501ec8, 0xad0552ab,
+            0x323db5fa, 0xfd238760, 0x53317b48, 0x3e00df82,
+            0x9e5c57bb, 0xca6f8ca0, 0x1a87562e, 0xdf1769db,
+            0xd542a8f6, 0x287effc3, 0xac6732c6, 0x8c4f5573,
+            0x695b27b0, 0xbbca58c8, 0xe1ffa35d, 0xb8f011a0,
+            0x10fa3d98, 0xfd2183b8, 0x4afcb56c, 0x2dd1d35b,
+            0x9a53e479, 0xb6f84565, 0xd28e49bc, 0x4bfb9790,
+            0xe1ddf2da, 0xa4cb7e33, 0x62fb1341, 0xcee4c6e8,
+            0xef20cada, 0x36774c01, 0xd07e9efe, 0x2bf11fb4,
+            0x95dbda4d, 0xae909198, 0xeaad8e71, 0x6b93d5a0,
+            0xd08ed1d0, 0xafc725e0, 0x8e3c5b2f, 0x8e7594b7,
+            0x8ff6e2fb, 0xf2122b64, 0x8888b812, 0x900df01c,
+            0x4fad5ea0, 0x688fc31c, 0xd1cff191, 0xb3a8c1ad,
+            0x2f2f2218, 0xbe0e1777, 0xea752dfe, 0x8b021fa1,
+            0xe5a0cc0f, 0xb56f74e8, 0x18acf3d6, 0xce89e299,
+            0xb4a84fe0, 0xfd13e0b7, 0x7cc43b81, 0xd2ada8d9,
+            0x165fa266, 0x80957705, 0x93cc7314, 0x211a1477,
+            0xe6ad2065, 0x77b5fa86, 0xc75442f5, 0xfb9d35cf,
+            0xebcdaf0c, 0x7b3e89a0, 0xd6411bd3, 0xae1e7e49,
+            0x00250e2d, 0x2071b35e, 0x226800bb, 0x57b8e0af,
+            0x2464369b, 0xf009b91e, 0x5563911d, 0x59dfa6aa,
+            0x78c14389, 0xd95a537f, 0x207d5ba2, 0x02e5b9c5,
+            0x83260376, 0x6295cfa9, 0x11c81968, 0x4e734a41,
+            0xb3472dca, 0x7b14a94a, 0x1b510052, 0x9a532915,
+            0xd60f573f, 0xbc9bc6e4, 0x2b60a476, 0x81e67400,
+            0x08ba6fb5, 0x571be91f, 0xf296ec6b, 0x2a0dd915,
+            0xb6636521, 0xe7b9f9b6, 0xff34052e, 0xc5855664,
+            0x53b02d5d, 0xa99f8fa1, 0x08ba4799, 0x6e85076a,
+        ],
+        [
+            0x4b7a70e9, 0xb5b32944, 0xdb75092e, 0xc4192623,
+            0xad6ea6b0, 0x49a7df7d, 0x9cee60b8, 0x8fedb266,
+            0xecaa8c71, 0x699a17ff, 0x5664526c, 0xc2b19ee1,
+            0x193602a5, 0x75094c29, 0xa0591340, 0xe4183a3e,
+            0x3f54989a, 0x5b429d65, 0x6b8fe4d6, 0x99f73fd6,
+            0xa1d29c07, 0xefe830f5, 0x4d2d38e6, 0xf0255dc1,
+            0x4cdd2086, 0x8470eb26, 0x6382e9c6, 0x021ecc5e,
+            0x09686b3f, 0x3ebaefc9, 0x3c971814, 0x6b6a70a1,
+            0x687f3584, 0x52a0e286, 0xb79c5305, 0xaa500737,
+            0x3e07841c, 0x7fdeae5c, 0x8e7d44ec, 0x5716f2b8,
+            0xb03ada37, 0xf0500c0d, 0xf01c1f04, 0x0200b3ff,
+            0xae0cf51a, 0x3cb574b2, 0x25837a58, 0xdc0921bd,
+            0xd19113f9, 0x7ca92ff6, 0x94324773, 0x22f54701,
+            0x3ae5e581, 0x37c2dadc, 0xc8b57634, 0x9af3dda7,
+            0xa9446146, 0x0fd0030e, 0xecc8c73e, 0xa4751e41,
+            0xe238cd99, 0x3bea0e2f, 0x3280bba1, 0x183eb331,
+            0x4e548b38, 0x4f6db908, 0x6f420d03, 0xf60a04bf,
+            0x2cb81290, 0x24977c79, 0x5679b072, 0xbcaf89af,
+            0xde9a771f, 0xd9930810, 0xb38bae12, 0xdccf3f2e,
+            0x5512721f, 0x2e6b7124, 0x501adde6, 0x9f84cd87,
+            0x7a584718, 0x7408da17, 0xbc9f9abc, 0xe94b7d8c,
+            0xec7aec3a, 0xdb851dfa, 0x63094366, 0xc464c3d2,
+            0xef1c1847, 0x3215d908, 0xdd433b37, 0x24c2ba16,
+            0x12a14d43, 0x2a65c451, 0x50940002, 0x133ae4dd,
+            0x71dff89e, 0x10314e55, 0x81ac77d6, 0x5f11199b,
+            0x043556f1, 0xd7a3c76b, 0x3c11183b, 0x5924a509,
+            0xf28fe6ed, 0x97f1fbfa, 0x9ebabf2c, 0x1e153c6e,
+            0x86e34570, 0xeae96fb1, 0x860e5e0a, 0x5a3e2ab3,
+            0x771fe71c, 0x4e3d06fa, 0x2965dcb9, 0x99e71d0f,
+            0x803e89d6, 0x5266c825, 0x2e4cc978, 0x9c10b36a,
+            0xc6150eba, 0x94e2ea78, 0xa5fc3c53, 0x1e0a2df4,
+            0xf2f74ea7, 0x361d2b3d, 0x1939260f, 0x19c27960,
+            0x5223a708, 0xf71312b6, 0xebadfe6e, 0xeac31f66,
+            0xe3bc4595, 0xa67bc883, 0xb17f37d1, 0x018cff28,
+            0xc332ddef, 0xbe6c5aa5, 0x65582185, 0x68ab9802,
+            0xeecea50f, 0xdb2f953b, 0x2aef7dad, 0x5b6e2f84,
+            0x1521b628, 0x29076170, 0xecdd4775, 0x619f1510,
+            0x13cca830, 0xeb61bd96, 0x0334fe1e, 0xaa0363cf,
+            0xb5735c90, 0x4c70a239, 0xd59e9e0b, 0xcbaade14,
+            0xeecc86bc, 0x60622ca7, 0x9cab5cab, 0xb2f3846e,
+            0x648b1eaf, 0x19bdf0ca, 0xa02369b9, 0x655abb50,
+            0x40685a32, 0x3c2ab4b3, 0x319ee9d5, 0xc021b8f7,
+            0x9b540b19, 0x875fa099, 0x95f7997e, 0x623d7da8,
+            0xf837889a, 0x97e32d77, 0x11ed935f, 0x16681281,
+            0x0e358829, 0xc7e61fd6, 0x96dedfa1, 0x7858ba99,
+            0x57f584a5, 0x1b227263, 0x9b83c3ff, 0x1ac24696,
+            0xcdb30aeb, 0x532e3054, 0x8fd948e4, 0x6dbc3128,
+            0x58ebf2ef, 0x34c6ffea, 0xfe28ed61, 0xee7c3c73,
+            0x5d4a14d9, 0xe864b7e3, 0x42105d14, 0x203e13e0,
+            0x45eee2b6, 0xa3aaabea, 0xdb6c4f15, 0xfacb4fd0,
+            0xc742f442, 0xef6abbb5, 0x654f3b1d, 0x41cd2105,
+            0xd81e799e, 0x86854dc7, 0xe44b476a, 0x3d816250,
+            0xcf62a1f2, 0x5b8d2646, 0xfc8883a0, 0xc1c7b6a3,
+            0x7f1524c3, 0x69cb7492, 0x47848a0b, 0x5692b285,
+            0x095bbf00, 0xad19489d, 0x1462b174, 0x23820e00,
+            0x58428d2a, 0x0c55f5ea, 0x1dadf43e, 0x233f7061,
+            0x3372f092, 0x8d937e41, 0xd65fecf1, 0x6c223bdb,
+            0x7cde3759, 0xcbee7460, 0x4085f2a7, 0xce77326e,
+            0xa6078084, 0x19f8509e, 0xe8efd855, 0x61d99735,
+            0xa969a7aa, 0xc50c06c2, 0x5a04abfc, 0x800bcadc,
+            0x9e447a2e, 0xc3453484, 0xfdd56705, 0x0e1e9ec9,
+            0xdb73dbd3, 0x105588cd, 0x675fda79, 0xe3674340,
+            0xc5c43465, 0x713e38d8, 0x3d28f89e, 0xf16dff20,
+            0x153e21e7, 0x8fb03d4a, 0xe6e39f2b, 0xdb83adf7,
+        ],
+        [
+            0xe93d5a68, 0x948140f7, 0xf64c261c, 0x94692934,
+            0x411520f7, 0x7602d4f7, 0xbcf46b2e, 0xd4a20068,
+            0xd4082471, 0x3320f46a, 0x43b7d4b7, 0x500061af,
+            0x1e39f62e, 0x97244546, 0x14214f74, 0xbf8b8840,
+            0x4d95fc1d, 0x96b591af, 0x70f4ddd3, 0x66a02f45,
+            0xbfbc09ec, 0x03bd9785, 0x7fac6dd0, 0x31cb8504,
+            0x96eb27b3, 0x55fd3941, 0xda2547e6, 0xabca0a9a,
+            0x28507825, 0x530429f4, 0x0a2c86da, 0xe9b66dfb,
+            0x68dc1462, 0xd7486900, 0x680ec0a4, 0x27a18dee,
+            0x4f3ffea2, 0xe887ad8c, 0xb58ce006, 0x7af4d6b6,
+            0xaace1e7c, 0xd3375fec, 0xce78a399, 0x406b2a42,
+            0x20fe9e35, 0xd9f385b9, 0xee39d7ab, 0x3b124e8b,
+            0x1dc9faf7, 0x4b6d1856, 0x26a36631, 0xeae397b2,
+            0x3a6efa74, 0xdd5b4332, 0x6841e7f7, 0xca7820fb,
+            0xfb0af54e, 0xd8feb397, 0x454056ac, 0xba489527,
+            0x55533a3a, 0x20838d87, 0xfe6ba9b7, 0xd096954b,
+            0x55a867bc, 0xa1159a58, 0xcca92963, 0x99e1db33,
+            0xa62a4a56, 0x3f3125f9, 0x5ef47e1c, 0x9029317c,
+            0xfdf8e802, 0x04272f70, 0x80bb155c, 0x05282ce3,
+            0x95c11548, 0xe4c66d22, 0x48c1133f, 0xc70f86dc,
+            0x07f9c9ee, 0x41041f0f, 0x404779a4, 0x5d886e17,
+            0x325f51eb, 0xd59bc0d1, 0xf2bcc18f, 0x41113564,
+            0x257b7834, 0x602a9c60, 0xdff8e8a3, 0x1f636c1b,
+            0x0e12b4c2, 0x02e1329e, 0xaf664fd1, 0xcad18115,
+            0x6b2395e0, 0x333e92e1, 0x3b240b62, 0xeebeb922,
+            0x85b2a20e, 0xe6ba0d99, 0xde720c8c, 0x2da2f728,
+            0xd0127845, 0x95b794fd, 0x647d0862, 0xe7ccf5f0,
+            0x5449a36f, 0x877d48fa, 0xc39dfd27, 0xf33e8d1e,
+            0x0a476341, 0x992eff74, 0x3a6f6eab, 0xf4f8fd37,
+            0xa812dc60, 0xa1ebddf8, 0x991be14c, 0xdb6e6b0d,
+            0xc67b5510, 0x6d672c37, 0x2765d43b, 0xdcd0e804,
+            0xf1290dc7, 0xcc00ffa3, 0xb5390f92, 0x690fed0b,
+            0x667b9ffb, 0xcedb7d9c, 0xa091cf0b, 0xd9155ea3,
+            0xbb132f88, 0x515bad24, 0x7b9479bf, 0x763bd6eb,
+            0x37392eb3, 0xcc115979, 0x8026e297, 0xf42e312d,
+            0x6842ada7, 0xc66a2b3b, 0x12754ccc, 0x782ef11c,
+            0x6a124237, 0xb79251e7, 0x06a1bbe6, 0x4bfb6350,
+            0x1a6b1018, 0x11caedfa, 0x3d25bdd8, 0xe2e1c3c9,
+            0x44421659, 0x0a121386, 0xd90cec6e, 0xd5abea2a,
+            0x64af674e, 0xda86a85f, 0xbebfe988, 0x64e4c3fe,
+            0x9dbc8057, 0xf0f7c086, 0x60787bf8, 0x6003604d,
+            0xd1fd8346, 0xf6381fb0, 0x7745ae04, 0xd736fccc,
+            0x83426b33, 0xf01eab71, 0xb0804187, 0x3c005e5f,
+            0x77a057be, 0xbde8ae24, 0x55464299, 0xbf582e61,
+            0x4e58f48f, 0xf2ddfda2, 0xf474ef38, 0x8789bdc2,
+            0x5366f9c3, 0xc8b38e74, 0xb475f255, 0x46fcd9b9,
+            0x7aeb2661, 0x8b1ddf84, 0x846a0e79, 0x915f95e2,
+            0x466e598e, 0x20b45770, 0x8cd55591, 0xc902de4c,
+            0xb90bace1, 0xbb8205d0, 0x11a86248, 0x7574a99e,
+            0xb77f19b6, 0xe0a9dc09, 0x662d09a1, 0xc4324633,
+            0xe85a1f02, 0x09f0be8c, 0x4a99a025, 0x1d6efe10,
+            0x1ab93d1d, 0x0ba5a4df, 0xa186f20f, 0x2868f169,
+            0xdcb7da83, 0x573906fe, 0xa1e2ce9b, 0x4fcd7f52,
+            0x50115e01, 0xa70683fa, 0xa002b5c4, 0x0de6d027,
+            0x9af88c27, 0x773f8641, 0xc3604c06, 0x61a806b5,
+            0xf0177a28, 0xc0f586e0, 0x006058aa, 0x30dc7d62,
+            0x11e69ed7, 0x2338ea63, 0x53c2dd94, 0xc2c21634,
+            0xbbcbee56, 0x90bcb6de, 0xebfc7da1, 0xce591d76,
+            0x6f05e409, 0x4b7c0188, 0x39720a3d, 0x7c927c24,
+            0x86e3725f, 0x724d9db9, 0x1ac15bb4, 0xd39eb8fc,
+            0xed545578, 0x08fca5b5, 0xd83d7cd3, 0x4dad0fc4,
+            0x1e50ef5e, 0xb161e6f8, 0xa28514d9, 0x6c51133c,
+            0x6fd5c7e7, 0x56e14ec4, 0x362abfce, 0xddc6c837,
+            0xd79a3234, 0x92638212, 0x670efa8e, 0x406000e0,
+        ],
+        [
+            0x3a39ce37, 0xd3faf5cf, 0xabc27737, 0x5ac52d1b,
+            0x5cb0679e, 0x4fa33742, 0xd3822740, 0x99bc9bbe,
+            0xd5118e9d, 0xbf0f7315, 0xd62d1c7e, 0xc700c47b,
+            0xb78c1b6b, 0x21a19045, 0xb26eb1be, 0x6a366eb4,
+            0x5748ab2f, 0xbc946e79, 0xc6a376d2, 0x6549c2c8,
+            0x530ff8ee, 0x468dde7d, 0xd5730a1d, 0x4cd04dc6,
+            0x2939bbdb, 0xa9ba4650, 0xac9526e8, 0xbe5ee304,
+            0xa1fad5f0, 0x6a2d519a, 0x63ef8ce2, 0x9a86ee22,
+            0xc089c2b8, 0x43242ef6, 0xa51e03aa, 0x9cf2d0a4,
+            0x83c061ba, 0x9be96a4d, 0x8fe51550, 0xba645bd6,
+            0x2826a2f9, 0xa73a3ae1, 0x4ba99586, 0xef5562e9,
+            0xc72fefd3, 0xf752f7da, 0x3f046f69, 0x77fa0a59,
+            0x80e4a915, 0x87b08601, 0x9b09e6ad, 0x3b3ee593,
+            0xe990fd5a, 0x9e34d797, 0x2cf0b7d9, 0x022b8b51,
+            0x96d5ac3a, 0x017da67d, 0xd1cf3ed6, 0x7c7d2d28,
+            0x1f9f25cf, 0xadf2b89b, 0x5ad6b472, 0x5a88f54c,
+            0xe029ac71, 0xe019a5e6, 0x47b0acfd, 0xed93fa9b,
+            0xe8d3c48d, 0x283b57cc, 0xf8d56629, 0x79132e28,
+            0x785f0191, 0xed756055, 0xf7960e44, 0xe3d35e8c,
+            0x15056dd4, 0x88f46dba, 0x03a16125, 0x0564f0bd,
+            0xc3eb9e15, 0x3c9057a2, 0x97271aec, 0xa93a072a,
+            0x1b3f6d9b, 0x1e6321f5, 0xf59c66fb, 0x26dcf319,
+            0x7533d928, 0xb155fdf5, 0x03563482, 0x8aba3cbb,
+            0x28517711, 0xc20ad9f8, 0xabcc5167, 0xccad925f,
+            0x4de81751, 0x3830dc8e, 0x379d5862, 0x9320f991,
+            0xea7a90c2, 0xfb3e7bce, 0x5121ce64, 0x774fbe32,
+            0xa8b6e37e, 0xc3293d46, 0x48de5369, 0x6413e680,
+            0xa2ae0810, 0xdd6db224, 0x69852dfd, 0x09072166,
+            0xb39a460a, 0x6445c0dd, 0x586cdecf, 0x1c20c8ae,
+            0x5bbef7dd, 0x1b588d40, 0xccd2017f, 0x6bb4e3bb,
+            0xdda26a7e, 0x3a59ff45, 0x3e350a44, 0xbcb4cdd5,
+            0x72eacea8, 0xfa6484bb, 0x8d6612ae, 0xbf3c6f47,
+            0xd29be463, 0x542f5d9e, 0xaec2771b, 0xf64e6370,
+            0x740e0d8d, 0xe75b1357, 0xf8721671, 0xaf537d5d,
+            0x4040cb08, 0x4eb4e2cc, 0x34d2466a, 0x0115af84,
+            0xe1b00428, 0x95983a1d, 0x06b89fb4, 0xce6ea048,
+            0x6f3f3b82, 0x3520ab82, 0x011a1d4b, 0x277227f8,
+            0x611560b1, 0xe7933fdc, 0xbb3a792b, 0x344525bd,
+            0xa08839e1, 0x51ce794b, 0x2f32c9b7, 0xa01fbac9,
+            0xe01cc87e, 0xbcc7d1f6, 0xcf0111c3, 0xa1e8aac7,
+            0x1a908749, 0xd44fbd9a, 0xd0dadecb, 0xd50ada38,
+            0x0339c32a, 0xc6913667, 0x8df9317c, 0xe0b12b4f,
+            0xf79e59b7, 0x43f5bb3a, 0xf2d519ff, 0x27d9459c,
+            0xbf97222c, 0x15e6fc2a, 0x0f91fc71, 0x9b941525,
+            0xfae59361, 0xceb69ceb, 0xc2a86459, 0x12baa8d1,
+            0xb6c1075e, 0xe3056a0c, 0x10d25065, 0xcb03a442,
+            0xe0ec6e0e, 0x1698db3b, 0x4c98a0be, 0x3278e964,
+            0x9f1f9532, 0xe0d392df, 0xd3a0342b, 0x8971f21e,
+            0x1b0a7441, 0x4ba3348c, 0xc5be7120, 0xc37632d8,
+            0xdf359f8d, 0x9b992f2e, 0xe60b6f47, 0x0fe3f11d,
+            0xe54cda54, 0x1edad891, 0xce6279cf, 0xcd3e7e6f,
+            0x1618b166, 0xfd2c1d05, 0x848fd2c5, 0xf6fb2299,
+            0xf523f357, 0xa6327623, 0x93a83531, 0x56cccd02,
+            0xacf08162, 0x5a75ebb5, 0x6e163697, 0x88d273cc,
+            0xde966292, 0x81b949d0, 0x4c50901b, 0x71c65614,
+            0xe6c6c7bd, 0x327a140a, 0x45e1d006, 0xc3f27b9a,
+            0xc9aa53fd, 0x62a80f00, 0xbb25bfe2, 0x35bdd2f6,
+            0x71126905, 0xb2040222, 0xb6cbcf7c, 0xcd769c2b,
+            0x53113ec0, 0x1640e3d3, 0x38abbd60, 0x2547adf0,
+            0xba38209c, 0xf746ce76, 0x77afa1c5, 0x20756060,
+            0x85cbfe4e, 0x8ae88dd8, 0x7aaaf9b0, 0x4cf9aa7e,
+            0x1948c25c, 0x02fb8a8c, 0x01c36ae4, 0xd6ebe1f9,
+            0x90d4f869, 0xa65cdea0, 0x3f09252d, 0xc208e69f,
+            0xb74e6132, 0xce77e25b, 0x578fdfe3, 0x3ac372e6,
+        ],
     ]
     ]
 
 
     public init(key: Array<UInt8>, iv: Array<UInt8>? = nil, blockMode: BlockMode = .CBC, padding: Padding) throws {
     public init(key: Array<UInt8>, iv: Array<UInt8>? = nil, blockMode: BlockMode = .CBC, padding: Padding) throws {
@@ -318,8 +329,8 @@ public final class Blowfish {
         self.blockMode = blockMode
         self.blockMode = blockMode
         self.padding = padding
         self.padding = padding
 
 
-        self.S = self.origS
-        self.P = self.origP
+        S = origS
+        P = origP
 
 
         if let iv = iv, !iv.isEmpty {
         if let iv = iv, !iv.isEmpty {
             self.iv = iv
             self.iv = iv
@@ -327,48 +338,48 @@ public final class Blowfish {
             self.iv = Array<UInt8>(repeating: 0, count: Blowfish.blockSize)
             self.iv = Array<UInt8>(repeating: 0, count: Blowfish.blockSize)
         }
         }
 
 
-        if (blockMode.options.contains(.InitializationVectorRequired) && self.iv.count != Blowfish.blockSize) {
+        if blockMode.options.contains(.InitializationVectorRequired) && self.iv.count != Blowfish.blockSize {
             assert(false, "Block size and Initialization Vector must be the same length!")
             assert(false, "Block size and Initialization Vector must be the same length!")
             throw Error.invalidInitializationVector
             throw Error.invalidInitializationVector
         }
         }
 
 
-        self.expandKey(key: key)
+        expandKey(key: key)
     }
     }
 
 
     private func reset() {
     private func reset() {
-        self.S = self.origS
-        self.P = self.origP
+        S = origS
+        P = origP
         // todo expand key
         // todo expand key
     }
     }
 
 
     private func expandKey(key: Array<UInt8>) {
     private func expandKey(key: Array<UInt8>) {
         var j = 0
         var j = 0
-        for i in 0 ..< (self.N + 2) {
+        for i in 0..<(N + 2) {
             var data: UInt32 = 0x0
             var data: UInt32 = 0x0
-            for _ in 0 ..< 4 {
+            for _ in 0..<4 {
                 data = (data << 8) | UInt32(key[j])
                 data = (data << 8) | UInt32(key[j])
                 j += 1
                 j += 1
                 if j >= key.count {
                 if j >= key.count {
                     j = 0
                     j = 0
                 }
                 }
             }
             }
-            self.P[i] ^= data
+            P[i] ^= data
         }
         }
 
 
         var datal: UInt32 = 0
         var datal: UInt32 = 0
         var datar: UInt32 = 0
         var datar: UInt32 = 0
 
 
-        for i in stride(from: 0, to: self.N + 2, by: 2) {
-            self.encryptBlowfishBlock(l: &datal, r: &datar)
-            self.P[i] = datal
-            self.P[i + 1] = datar
+        for i in stride(from: 0, to: N + 2, by: 2) {
+            encryptBlowfishBlock(l: &datal, r: &datar)
+            P[i] = datal
+            P[i + 1] = datar
         }
         }
 
 
-        for i in 0 ..< 4 {
+        for i in 0..<4 {
             for j in stride(from: 0, to: 256, by: 2) {
             for j in stride(from: 0, to: 256, by: 2) {
-                self.encryptBlowfishBlock(l: &datal, r: &datar)
-                self.S[i][j] = datal
-                self.S[i][j + 1] = datar
+                encryptBlowfishBlock(l: &datal, r: &datar)
+                S[i][j] = datal
+                S[i][j + 1] = datar
             }
             }
         }
         }
     }
     }
@@ -379,17 +390,25 @@ public final class Blowfish {
         var l = UInt32(bytes: block[0..<4])
         var l = UInt32(bytes: block[0..<4])
         var r = UInt32(bytes: block[4..<8])
         var r = UInt32(bytes: block[4..<8])
 
 
-        self.encryptBlowfishBlock(l: &l, r: &r)
+        encryptBlowfishBlock(l: &l, r: &r)
 
 
         // because everything is too complex to be solved in reasonable time o_O
         // because everything is too complex to be solved in reasonable time o_O
-        result += [UInt8((l >> 24) & 0xFF),
-                   UInt8((l >> 16) & 0xFF)]
-        result += [UInt8((l >> 8)  & 0xFF),
-                   UInt8((l >> 0)  & 0xFF)]
-        result += [UInt8((r >> 24) & 0xFF),
-                   UInt8((r >> 16) & 0xFF)]
-        result += [UInt8((r >> 8)  & 0xFF),
-                   UInt8((r >> 0) & 0xFF)]
+        result += [
+            UInt8((l >> 24) & 0xff),
+            UInt8((l >> 16) & 0xff),
+        ]
+        result += [
+            UInt8((l >> 8) & 0xff),
+            UInt8((l >> 0) & 0xff),
+        ]
+        result += [
+            UInt8((r >> 24) & 0xff),
+            UInt8((r >> 16) & 0xff),
+        ]
+        result += [
+            UInt8((r >> 8) & 0xff),
+            UInt8((r >> 0) & 0xff),
+        ]
 
 
         return result
         return result
     }
     }
@@ -400,17 +419,25 @@ public final class Blowfish {
         var l = UInt32(bytes: block[0..<4])
         var l = UInt32(bytes: block[0..<4])
         var r = UInt32(bytes: block[4..<8])
         var r = UInt32(bytes: block[4..<8])
 
 
-        self.decryptBlowfishBlock(l: &l, r: &r)
+        decryptBlowfishBlock(l: &l, r: &r)
 
 
         // because everything is too complex to be solved in reasonable time o_O
         // because everything is too complex to be solved in reasonable time o_O
-        result += [UInt8((l >> 24) & 0xFF),
-                   UInt8((l >> 16) & 0xFF)]
-        result += [UInt8((l >> 8)  & 0xFF),
-                   UInt8((l >> 0)  & 0xFF)]
-        result += [UInt8((r >> 24) & 0xFF),
-                   UInt8((r >> 16) & 0xFF)]
-        result += [UInt8((r >> 8)  & 0xFF),
-                   UInt8((r >> 0) & 0xFF)]
+        result += [
+            UInt8((l >> 24) & 0xff),
+            UInt8((l >> 16) & 0xff),
+        ]
+        result += [
+            UInt8((l >> 8) & 0xff),
+            UInt8((l >> 0) & 0xff),
+        ]
+        result += [
+            UInt8((r >> 24) & 0xff),
+            UInt8((r >> 16) & 0xff),
+        ]
+        result += [
+            UInt8((r >> 8) & 0xff),
+            UInt8((r >> 0) & 0xff),
+        ]
         return result
         return result
     }
     }
 
 
@@ -423,8 +450,8 @@ public final class Blowfish {
         var Xl = l
         var Xl = l
         var Xr = r
         var Xr = r
 
 
-        for i in 0 ..< self.N {
-            Xl = Xl ^ self.P[i]
+        for i in 0..<N {
+            Xl = Xl ^ P[i]
             Xr = F(x: Xl) ^ Xr
             Xr = F(x: Xl) ^ Xr
 
 
             (Xl, Xr) = (Xr, Xl)
             (Xl, Xr) = (Xr, Xl)
@@ -432,8 +459,8 @@ public final class Blowfish {
 
 
         (Xl, Xr) = (Xr, Xl)
         (Xl, Xr) = (Xr, Xl)
 
 
-        Xr = Xr ^ self.P[self.N]
-        Xl = Xl ^ self.P[self.N + 1]
+        Xr = Xr ^ P[self.N]
+        Xl = Xl ^ P[self.N + 1]
 
 
         l = Xl
         l = Xl
         r = Xr
         r = Xr
@@ -448,8 +475,8 @@ public final class Blowfish {
         var Xl = l
         var Xl = l
         var Xr = r
         var Xr = r
 
 
-        for i in (2 ... self.N + 1).reversed() {
-            Xl = Xl ^ self.P[i]
+        for i in (2...N + 1).reversed() {
+            Xl = Xl ^ P[i]
             Xr = F(x: Xl) ^ Xr
             Xr = F(x: Xl) ^ Xr
 
 
             (Xl, Xr) = (Xr, Xl)
             (Xl, Xr) = (Xr, Xl)
@@ -457,18 +484,18 @@ public final class Blowfish {
 
 
         (Xl, Xr) = (Xr, Xl)
         (Xl, Xr) = (Xr, Xl)
 
 
-        Xr = Xr ^ self.P[1]
-        Xl = Xl ^ self.P[0]
+        Xr = Xr ^ P[1]
+        Xl = Xl ^ P[0]
 
 
         l = Xl
         l = Xl
         r = Xr
         r = Xr
     }
     }
 
 
     private func F(x: UInt32) -> UInt32 {
     private func F(x: UInt32) -> UInt32 {
-        let f1 = self.S[0][Int(x >> 24) & 0xFF];
-        let f2 = self.S[1][Int(x >> 16) & 0xFF];
-        let f3 = self.S[2][Int(x >> 8) & 0xFF];
-        let f4 = self.S[3][Int(x & 0xFF)]
+        let f1 = S[0][Int(x >> 24) & 0xff]
+        let f2 = S[1][Int(x >> 16) & 0xff]
+        let f3 = S[2][Int(x >> 8) & 0xff]
+        let f4 = S[3][Int(x & 0xff)]
         return ((f1 &+ f2) ^ f3) &+ f4
         return ((f1 &+ f2) ^ f3) &+ f4
     }
     }
 }
 }
@@ -481,13 +508,13 @@ extension Blowfish: Cipher {
     /// - Returns: Encrypted data
     /// - Returns: Encrypted data
     public func encrypt<C: Collection>(_ bytes: C) throws -> Array<UInt8> where C.Element == UInt8, C.IndexDistance == Int, C.Index == Int {
     public func encrypt<C: Collection>(_ bytes: C) throws -> Array<UInt8> where C.Element == UInt8, C.IndexDistance == Int, C.Index == Int {
 
 
-        let bytes = padding.add(to: Array(bytes), blockSize: Blowfish.blockSize) //FIXME: Array(bytes) copies
+        let bytes = padding.add(to: Array(bytes), blockSize: Blowfish.blockSize) // FIXME: Array(bytes) copies
 
 
         var out = Array<UInt8>()
         var out = Array<UInt8>()
         out.reserveCapacity(bytes.count)
         out.reserveCapacity(bytes.count)
 
 
         for chunk in bytes.batched(by: Blowfish.blockSize) {
         for chunk in bytes.batched(by: Blowfish.blockSize) {
-            out += self.encryptWorker.encrypt(chunk)
+            out += encryptWorker.encrypt(chunk)
         }
         }
 
 
         if blockMode.options.contains(.PaddingRequired) && (out.count % Blowfish.blockSize != 0) {
         if blockMode.options.contains(.PaddingRequired) && (out.count % Blowfish.blockSize != 0) {
@@ -497,7 +524,6 @@ extension Blowfish: Cipher {
         return out
         return out
     }
     }
 
 
-
     /// Decrypt the 8-byte padded buffer
     /// Decrypt the 8-byte padded buffer
     ///
     ///
     /// - Parameter bytes: Ciphertext data
     /// - Parameter bytes: Ciphertext data
@@ -512,7 +538,7 @@ extension Blowfish: Cipher {
         out.reserveCapacity(bytes.count)
         out.reserveCapacity(bytes.count)
 
 
         for chunk in Array(bytes).batched(by: Blowfish.blockSize) {
         for chunk in Array(bytes).batched(by: Blowfish.blockSize) {
-            out += self.decryptWorker.decrypt(chunk) //FIXME: copying here is innefective
+            out += decryptWorker.decrypt(chunk) // FIXME: copying here is innefective
         }
         }
 
 
         out = padding.remove(from: out, blockSize: Blowfish.blockSize)
         out = padding.remove(from: out, blockSize: Blowfish.blockSize)
@@ -520,6 +546,3 @@ extension Blowfish: Cipher {
         return out
         return out
     }
     }
 }
 }
-
-
-

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

@@ -28,7 +28,7 @@ extension Array: CSArrayType {
 public extension CSArrayType where Iterator.Element == UInt8 {
 public extension CSArrayType where Iterator.Element == UInt8 {
 
 
     public func toHexString() -> String {
     public func toHexString() -> String {
-        return self.lazy.reduce("") {
+        return `lazy`.reduce("") {
             var s = String($1, radix: 16)
             var s = String($1, radix: 16)
             if s.characters.count == 1 {
             if s.characters.count == 1 {
                 s = "0" + s
                 s = "0" + s

+ 35 - 35
Sources/CryptoSwift/ChaCha20.swift

@@ -33,19 +33,19 @@ public final class ChaCha20: BlockCipher {
     public init(key: Array<UInt8>, iv nonce: Array<UInt8>) throws {
     public init(key: Array<UInt8>, iv nonce: Array<UInt8>) throws {
         precondition(nonce.count == 12 || nonce.count == 8)
         precondition(nonce.count == 12 || nonce.count == 8)
 
 
-        if (key.count != 32) {
+        if key.count != 32 {
             throw Error.invalidKeyOrInitializationVector
             throw Error.invalidKeyOrInitializationVector
         }
         }
 
 
         self.key = Key(bytes: key)
         self.key = Key(bytes: key)
 
 
         if nonce.count == 8 {
         if nonce.count == 8 {
-            self.counter = [0,0,0,0,0,0,0,0] + nonce
+            counter = [0, 0, 0, 0, 0, 0, 0, 0] + nonce
         } else {
         } else {
-            self.counter = [0,0,0,0] + nonce
+            counter = [0, 0, 0, 0] + nonce
         }
         }
 
 
-        assert(self.counter.count == 16)
+        assert(counter.count == 16)
     }
     }
 
 
     /// https://tools.ietf.org/html/rfc7539#section-2.3.
     /// https://tools.ietf.org/html/rfc7539#section-2.3.
@@ -77,16 +77,16 @@ public final class ChaCha20: BlockCipher {
         for _ in 0..<10 { // 20 rounds
         for _ in 0..<10 { // 20 rounds
             x0 = x0 &+ x4
             x0 = x0 &+ x4
             x12 ^= x0
             x12 ^= x0
-            x12 = (x12 << 16) | (x12 >> (16))
+            x12 = (x12 << 16) | (x12 >> 16)
             x8 = x8 &+ x12
             x8 = x8 &+ x12
             x4 ^= x8
             x4 ^= x8
-            x4 = (x4 << 12) | (x4 >> (20))
+            x4 = (x4 << 12) | (x4 >> 20)
             x0 = x0 &+ x4
             x0 = x0 &+ x4
             x12 ^= x0
             x12 ^= x0
-            x12 = (x12 << 8) | (x12 >> (24))
+            x12 = (x12 << 8) | (x12 >> 24)
             x8 = x8 &+ x12
             x8 = x8 &+ x12
             x4 ^= x8
             x4 ^= x8
-            x4 = (x4 << 7) | (x4 >> (25))
+            x4 = (x4 << 7) | (x4 >> 25)
             x1 = x1 &+ x5
             x1 = x1 &+ x5
             x13 ^= x1
             x13 ^= x1
             x13 = (x13 << 16) | (x13 >> 16)
             x13 = (x13 << 16) | (x13 >> 16)
@@ -190,9 +190,9 @@ public final class ChaCha20: BlockCipher {
         x14 = x14 &+ j14
         x14 = x14 &+ j14
         x15 = x15 &+ j15
         x15 = x15 &+ j15
 
 
-        block.replaceSubrange(0..<4,   with: x0.bigEndian.bytes())
-        block.replaceSubrange(4..<8,   with: x1.bigEndian.bytes())
-        block.replaceSubrange(8..<12,  with: x2.bigEndian.bytes())
+        block.replaceSubrange(0..<4, with: x0.bigEndian.bytes())
+        block.replaceSubrange(4..<8, with: x1.bigEndian.bytes())
+        block.replaceSubrange(8..<12, with: x2.bigEndian.bytes())
         block.replaceSubrange(12..<16, with: x3.bigEndian.bytes())
         block.replaceSubrange(12..<16, with: x3.bigEndian.bytes())
         block.replaceSubrange(16..<20, with: x4.bigEndian.bytes())
         block.replaceSubrange(16..<20, with: x4.bigEndian.bytes())
         block.replaceSubrange(20..<24, with: x5.bigEndian.bytes())
         block.replaceSubrange(20..<24, with: x5.bigEndian.bytes())
@@ -214,12 +214,12 @@ public final class ChaCha20: BlockCipher {
         precondition(key.count == 32)
         precondition(key.count == 32)
 
 
         var block = Array<UInt8>(repeating: 0, count: ChaCha20.blockSize)
         var block = Array<UInt8>(repeating: 0, count: ChaCha20.blockSize)
-        var bytes = bytes //TODO: check bytes[bytes.indices]
+        var bytes = bytes // TODO: check bytes[bytes.indices]
         var out = Array<UInt8>(reserveCapacity: bytes.count)
         var out = Array<UInt8>(reserveCapacity: bytes.count)
 
 
         while bytes.count >= ChaCha20.blockSize {
         while bytes.count >= ChaCha20.blockSize {
-            self.core(block: &block, counter: counter, key: key)
-            for (i,x) in block.enumerated() {
+            core(block: &block, counter: counter, key: key)
+            for (i, x) in block.enumerated() {
                 out.append(bytes[i] ^ x)
                 out.append(bytes[i] ^ x)
             }
             }
             var u: UInt32 = 1
             var u: UInt32 = 1
@@ -232,7 +232,7 @@ public final class ChaCha20: BlockCipher {
         }
         }
 
 
         if bytes.count > 0 {
         if bytes.count > 0 {
-            self.core(block: &block, counter: counter, key: key)
+            core(block: &block, counter: counter, key: key)
             for (i, v) in bytes.enumerated() {
             for (i, v) in bytes.enumerated() {
                 out.append(v ^ block[i])
                 out.append(v ^ block[i])
             }
             }
@@ -245,7 +245,7 @@ public final class ChaCha20: BlockCipher {
 extension ChaCha20: Cipher {
 extension ChaCha20: Cipher {
 
 
     public func encrypt(_ bytes: ArraySlice<UInt8>) throws -> Array<UInt8> {
     public func encrypt(_ bytes: ArraySlice<UInt8>) throws -> Array<UInt8> {
-        return process(bytes: Array(bytes), counter: &self.counter, key: Array(self.key))
+        return process(bytes: Array(bytes), counter: &counter, key: Array(key))
     }
     }
 
 
     public func decrypt(_ bytes: ArraySlice<UInt8>) throws -> Array<UInt8> {
     public func decrypt(_ bytes: ArraySlice<UInt8>) throws -> Array<UInt8> {
@@ -264,15 +264,15 @@ extension ChaCha20 {
             self.chacha = chacha
             self.chacha = chacha
         }
         }
 
 
-        mutating public func update(withBytes bytes: ArraySlice<UInt8>, isLast: Bool = false) throws -> Array<UInt8> {
-            self.accumulated += bytes
+        public mutating func update(withBytes bytes: ArraySlice<UInt8>, isLast: Bool = false) throws -> Array<UInt8> {
+            accumulated += bytes
 
 
             var encrypted = Array<UInt8>()
             var encrypted = Array<UInt8>()
-            encrypted.reserveCapacity(self.accumulated.count)
-            for chunk in self.accumulated.batched(by: ChaCha20.blockSize) {
-                if (isLast || self.accumulated.count >= ChaCha20.blockSize) {
+            encrypted.reserveCapacity(accumulated.count)
+            for chunk in accumulated.batched(by: ChaCha20.blockSize) {
+                if isLast || accumulated.count >= ChaCha20.blockSize {
                     encrypted += try chacha.encrypt(chunk)
                     encrypted += try chacha.encrypt(chunk)
-                    self.accumulated.removeFirst(chunk.count) //TODO: improve performance
+                    accumulated.removeFirst(chunk.count) // TODO: improve performance
                 }
                 }
             }
             }
             return encrypted
             return encrypted
@@ -294,29 +294,29 @@ extension ChaCha20 {
             self.chacha = chacha
             self.chacha = chacha
         }
         }
 
 
-        mutating public func update(withBytes bytes: ArraySlice<UInt8>, isLast: Bool = true) throws -> Array<UInt8> {
+        public mutating func update(withBytes bytes: ArraySlice<UInt8>, isLast: Bool = true) throws -> Array<UInt8> {
             // prepend "offset" number of bytes at the begining
             // prepend "offset" number of bytes at the begining
-            if self.offset > 0 {
-                self.accumulated += Array<UInt8>(repeating: 0, count: offset) + bytes
-                self.offsetToRemove = offset
-                self.offset = 0
+            if offset > 0 {
+                accumulated += Array<UInt8>(repeating: 0, count: offset) + bytes
+                offsetToRemove = offset
+                offset = 0
             } else {
             } else {
-                self.accumulated += bytes
+                accumulated += bytes
             }
             }
 
 
             var plaintext = Array<UInt8>()
             var plaintext = Array<UInt8>()
-            plaintext.reserveCapacity(self.accumulated.count)
-            for chunk in self.accumulated.batched(by: ChaCha20.blockSize) {
-                if (isLast || self.accumulated.count >= ChaCha20.blockSize) {
+            plaintext.reserveCapacity(accumulated.count)
+            for chunk in accumulated.batched(by: ChaCha20.blockSize) {
+                if isLast || accumulated.count >= ChaCha20.blockSize {
                     plaintext += try chacha.decrypt(chunk)
                     plaintext += try chacha.decrypt(chunk)
 
 
                     // remove "offset" from the beginning of first chunk
                     // remove "offset" from the beginning of first chunk
-                    if self.offsetToRemove > 0 {
-                        plaintext.removeFirst(self.offsetToRemove) //TODO: improve performance
-                        self.offsetToRemove = 0
+                    if offsetToRemove > 0 {
+                        plaintext.removeFirst(offsetToRemove) // TODO: improve performance
+                        offsetToRemove = 0
                     }
                     }
 
 
-                    self.accumulated.removeFirst(chunk.count)
+                    accumulated.removeFirst(chunk.count)
                 }
                 }
             }
             }
 
 

+ 69 - 65
Sources/CryptoSwift/Checksum.swift

@@ -16,71 +16,75 @@
 
 
 /// CRC - cyclic redundancy check code.
 /// CRC - cyclic redundancy check code.
 public final class Checksum {
 public final class Checksum {
-    private static let table32: Array<UInt32> = [0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3,
-                                                0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91,
-                                                0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,
-                                                0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5,
-                                                0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
-                                                0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,
-                                                0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f,
-                                                0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d,
-                                                0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,
-                                                0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
-                                                0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457,
-                                                0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,
-                                                0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb,
-                                                0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9,
-                                                0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
-                                                0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad,
-                                                0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683,
-                                                0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,
-                                                0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7,
-                                                0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
-                                                0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,
-                                                0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79,
-                                                0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f,
-                                                0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,
-                                                0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
-                                                0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21,
-                                                0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,
-                                                0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45,
-                                                0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db,
-                                                0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
-                                                0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf,
-                                                0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d]
+    private static let table32: Array<UInt32> = [
+        0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3,
+        0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91,
+        0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,
+        0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5,
+        0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
+        0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,
+        0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f,
+        0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d,
+        0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,
+        0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
+        0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457,
+        0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,
+        0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb,
+        0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9,
+        0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
+        0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad,
+        0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683,
+        0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,
+        0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7,
+        0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
+        0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,
+        0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79,
+        0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f,
+        0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,
+        0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
+        0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21,
+        0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,
+        0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45,
+        0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db,
+        0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
+        0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf,
+        0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d,
+    ]
 
 
-    private static let table16: [UInt16] = [0x0000, 0xC0C1, 0xC181, 0x0140, 0xC301, 0x03C0, 0x0280, 0xC241,
-                                           0xC601, 0x06C0, 0x0780, 0xC741, 0x0500, 0xC5C1, 0xC481, 0x0440,
-                                           0xCC01, 0x0CC0, 0x0D80, 0xCD41, 0x0F00, 0xCFC1, 0xCE81, 0x0E40,
-                                           0x0A00, 0xCAC1, 0xCB81, 0x0B40, 0xC901, 0x09C0, 0x0880, 0xC841,
-                                           0xD801, 0x18C0, 0x1980, 0xD941, 0x1B00, 0xDBC1, 0xDA81, 0x1A40,
-                                           0x1E00, 0xDEC1, 0xDF81, 0x1F40, 0xDD01, 0x1DC0, 0x1C80, 0xDC41,
-                                           0x1400, 0xD4C1, 0xD581, 0x1540, 0xD701, 0x17C0, 0x1680, 0xD641,
-                                           0xD201, 0x12C0, 0x1380, 0xD341, 0x1100, 0xD1C1, 0xD081, 0x1040,
-                                           0xF001, 0x30C0, 0x3180, 0xF141, 0x3300, 0xF3C1, 0xF281, 0x3240,
-                                           0x3600, 0xF6C1, 0xF781, 0x3740, 0xF501, 0x35C0, 0x3480, 0xF441,
-                                           0x3C00, 0xFCC1, 0xFD81, 0x3D40, 0xFF01, 0x3FC0, 0x3E80, 0xFE41,
-                                           0xFA01, 0x3AC0, 0x3B80, 0xFB41, 0x3900, 0xF9C1, 0xF881, 0x3840,
-                                           0x2800, 0xE8C1, 0xE981, 0x2940, 0xEB01, 0x2BC0, 0x2A80, 0xEA41,
-                                           0xEE01, 0x2EC0, 0x2F80, 0xEF41, 0x2D00, 0xEDC1, 0xEC81, 0x2C40,
-                                           0xE401, 0x24C0, 0x2580, 0xE541, 0x2700, 0xE7C1, 0xE681, 0x2640,
-                                           0x2200, 0xE2C1, 0xE381, 0x2340, 0xE101, 0x21C0, 0x2080, 0xE041,
-                                           0xA001, 0x60C0, 0x6180, 0xA141, 0x6300, 0xA3C1, 0xA281, 0x6240,
-                                           0x6600, 0xA6C1, 0xA781, 0x6740, 0xA501, 0x65C0, 0x6480, 0xA441,
-                                           0x6C00, 0xACC1, 0xAD81, 0x6D40, 0xAF01, 0x6FC0, 0x6E80, 0xAE41,
-                                           0xAA01, 0x6AC0, 0x6B80, 0xAB41, 0x6900, 0xA9C1, 0xA881, 0x6840,
-                                           0x7800, 0xB8C1, 0xB981, 0x7940, 0xBB01, 0x7BC0, 0x7A80, 0xBA41,
-                                           0xBE01, 0x7EC0, 0x7F80, 0xBF41, 0x7D00, 0xBDC1, 0xBC81, 0x7C40,
-                                           0xB401, 0x74C0, 0x7580, 0xB541, 0x7700, 0xB7C1, 0xB681, 0x7640,
-                                           0x7200, 0xB2C1, 0xB381, 0x7340, 0xB101, 0x71C0, 0x7080, 0xB041,
-                                           0x5000, 0x90C1, 0x9181, 0x5140, 0x9301, 0x53C0, 0x5280, 0x9241,
-                                           0x9601, 0x56C0, 0x5780, 0x9741, 0x5500, 0x95C1, 0x9481, 0x5440,
-                                           0x9C01, 0x5CC0, 0x5D80, 0x9D41, 0x5F00, 0x9FC1, 0x9E81, 0x5E40,
-                                           0x5A00, 0x9AC1, 0x9B81, 0x5B40, 0x9901, 0x59C0, 0x5880, 0x9841,
-                                           0x8801, 0x48C0, 0x4980, 0x8941, 0x4B00, 0x8BC1, 0x8A81, 0x4A40,
-                                           0x4E00, 0x8EC1, 0x8F81, 0x4F40, 0x8D01, 0x4DC0, 0x4C80, 0x8C41,
-                                           0x4400, 0x84C1, 0x8581, 0x4540, 0x8701, 0x47C0, 0x4680, 0x8641,
-                                           0x8201, 0x42C0, 0x4380, 0x8341, 0x4100, 0x81C1, 0x8081, 0x4040]
+    private static let table16: [UInt16] = [
+        0x0000, 0xc0c1, 0xc181, 0x0140, 0xc301, 0x03c0, 0x0280, 0xc241,
+        0xc601, 0x06c0, 0x0780, 0xc741, 0x0500, 0xc5c1, 0xc481, 0x0440,
+        0xcc01, 0x0cc0, 0x0d80, 0xcd41, 0x0f00, 0xcfc1, 0xce81, 0x0e40,
+        0x0a00, 0xcac1, 0xcb81, 0x0b40, 0xc901, 0x09c0, 0x0880, 0xc841,
+        0xd801, 0x18c0, 0x1980, 0xd941, 0x1b00, 0xdbc1, 0xda81, 0x1a40,
+        0x1e00, 0xdec1, 0xdf81, 0x1f40, 0xdd01, 0x1dc0, 0x1c80, 0xdc41,
+        0x1400, 0xd4c1, 0xd581, 0x1540, 0xd701, 0x17c0, 0x1680, 0xd641,
+        0xd201, 0x12c0, 0x1380, 0xd341, 0x1100, 0xd1c1, 0xd081, 0x1040,
+        0xf001, 0x30c0, 0x3180, 0xf141, 0x3300, 0xf3c1, 0xf281, 0x3240,
+        0x3600, 0xf6c1, 0xf781, 0x3740, 0xf501, 0x35c0, 0x3480, 0xf441,
+        0x3c00, 0xfcc1, 0xfd81, 0x3d40, 0xff01, 0x3fc0, 0x3e80, 0xfe41,
+        0xfa01, 0x3ac0, 0x3b80, 0xfb41, 0x3900, 0xf9c1, 0xf881, 0x3840,
+        0x2800, 0xe8c1, 0xe981, 0x2940, 0xeb01, 0x2bc0, 0x2a80, 0xea41,
+        0xee01, 0x2ec0, 0x2f80, 0xef41, 0x2d00, 0xedc1, 0xec81, 0x2c40,
+        0xe401, 0x24c0, 0x2580, 0xe541, 0x2700, 0xe7c1, 0xe681, 0x2640,
+        0x2200, 0xe2c1, 0xe381, 0x2340, 0xe101, 0x21c0, 0x2080, 0xe041,
+        0xa001, 0x60c0, 0x6180, 0xa141, 0x6300, 0xa3c1, 0xa281, 0x6240,
+        0x6600, 0xa6c1, 0xa781, 0x6740, 0xa501, 0x65c0, 0x6480, 0xa441,
+        0x6c00, 0xacc1, 0xad81, 0x6d40, 0xaf01, 0x6fc0, 0x6e80, 0xae41,
+        0xaa01, 0x6ac0, 0x6b80, 0xab41, 0x6900, 0xa9c1, 0xa881, 0x6840,
+        0x7800, 0xb8c1, 0xb981, 0x7940, 0xbb01, 0x7bc0, 0x7a80, 0xba41,
+        0xbe01, 0x7ec0, 0x7f80, 0xbf41, 0x7d00, 0xbdc1, 0xbc81, 0x7c40,
+        0xb401, 0x74c0, 0x7580, 0xb541, 0x7700, 0xb7c1, 0xb681, 0x7640,
+        0x7200, 0xb2c1, 0xb381, 0x7340, 0xb101, 0x71c0, 0x7080, 0xb041,
+        0x5000, 0x90c1, 0x9181, 0x5140, 0x9301, 0x53c0, 0x5280, 0x9241,
+        0x9601, 0x56c0, 0x5780, 0x9741, 0x5500, 0x95c1, 0x9481, 0x5440,
+        0x9c01, 0x5cc0, 0x5d80, 0x9d41, 0x5f00, 0x9fc1, 0x9e81, 0x5e40,
+        0x5a00, 0x9ac1, 0x9b81, 0x5b40, 0x9901, 0x59c0, 0x5880, 0x9841,
+        0x8801, 0x48c0, 0x4980, 0x8941, 0x4b00, 0x8bc1, 0x8a81, 0x4a40,
+        0x4e00, 0x8ec1, 0x8f81, 0x4f40, 0x8d01, 0x4dc0, 0x4c80, 0x8c41,
+        0x4400, 0x84c1, 0x8581, 0x4540, 0x8701, 0x47c0, 0x4680, 0x8641,
+        0x8201, 0x42c0, 0x4380, 0x8341, 0x4100, 0x81c1, 0x8081, 0x4040,
+    ]
 
 
     func crc32(_ message: Array<UInt8>, seed: UInt32? = nil, reflect: Bool = true) -> UInt32 {
     func crc32(_ message: Array<UInt8>, seed: UInt32? = nil, reflect: Bool = true) -> UInt32 {
         var crc: UInt32 = seed != nil ? seed! : 0xffffffff
         var crc: UInt32 = seed != nil ? seed! : 0xffffffff
@@ -97,7 +101,7 @@ public final class Checksum {
         var crc: UInt16 = seed != nil ? seed! : 0x0000
         var crc: UInt16 = seed != nil ? seed! : 0x0000
         for chunk in message.batched(by: 256) {
         for chunk in message.batched(by: 256) {
             for b in chunk {
             for b in chunk {
-                crc = (crc >> 8) ^ Checksum.table16[Int((crc ^ UInt16(b)) & 0xFF)]
+                crc = (crc >> 8) ^ Checksum.table16[Int((crc ^ UInt16(b)) & 0xff)]
             }
             }
         }
         }
         return crc
         return crc

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

@@ -19,7 +19,7 @@ extension Collection where Self.Iterator.Element == UInt8, Self.Index == Int {
         let count = self.count
         let count = self.count
         var result = Array<UInt32>()
         var result = Array<UInt32>()
         result.reserveCapacity(16)
         result.reserveCapacity(16)
-        for idx in stride(from: self.startIndex, to: self.endIndex, by: 4) {
+        for idx in stride(from: startIndex, to: endIndex, by: 4) {
             var val: UInt32 = 0
             var val: UInt32 = 0
             val |= count > 3 ? UInt32(self[idx.advanced(by: 3)]) << 24 : 0
             val |= count > 3 ? UInt32(self[idx.advanced(by: 3)]) << 24 : 0
             val |= count > 2 ? UInt32(self[idx.advanced(by: 2)]) << 16 : 0
             val |= count > 2 ? UInt32(self[idx.advanced(by: 2)]) << 16 : 0
@@ -35,7 +35,7 @@ extension Collection where Self.Iterator.Element == UInt8, Self.Index == Int {
         let count = self.count
         let count = self.count
         var result = Array<UInt64>()
         var result = Array<UInt64>()
         result.reserveCapacity(32)
         result.reserveCapacity(32)
-        for idx in stride(from: self.startIndex, to: self.endIndex, by: 8) {
+        for idx in stride(from: startIndex, to: endIndex, by: 8) {
             var val: UInt64 = 0
             var val: UInt64 = 0
             val |= count > 7 ? UInt64(self[idx.advanced(by: 7)]) << 56 : 0
             val |= count > 7 ? UInt64(self[idx.advanced(by: 7)]) << 56 : 0
             val |= count > 6 ? UInt64(self[idx.advanced(by: 6)]) << 48 : 0
             val |= count > 6 ? UInt64(self[idx.advanced(by: 6)]) << 48 : 0
@@ -54,15 +54,15 @@ extension Collection where Self.Iterator.Element == UInt8, Self.Index == Int {
     /// Initialize integer from array of bytes. Caution: may be slow!
     /// Initialize integer from array of bytes. Caution: may be slow!
     @available(*, deprecated: 0.6.0, message: "Dont use it. Too generic to be fast")
     @available(*, deprecated: 0.6.0, message: "Dont use it. Too generic to be fast")
     func toInteger<T>() -> T where T: FixedWidthInteger {
     func toInteger<T>() -> T where T: FixedWidthInteger {
-        if self.count == 0 {
+        if count == 0 {
             return 0
             return 0
         }
         }
 
 
         let size = MemoryLayout<T>.size
         let size = MemoryLayout<T>.size
-        var bytes = self.reversed() // FIXME: check it this is equivalent of Array(...)
+        var bytes = reversed() // FIXME: check it this is equivalent of Array(...)
         if bytes.count < size {
         if bytes.count < size {
             let paddingCount = size - bytes.count
             let paddingCount = size - bytes.count
-            if (paddingCount > 0) {
+            if paddingCount > 0 {
                 bytes += Array<UInt8>(repeating: 0, count: paddingCount)
                 bytes += Array<UInt8>(repeating: 0, count: paddingCount)
             }
             }
         }
         }

+ 0 - 1
Sources/CryptoSwift/Digest.swift

@@ -70,7 +70,6 @@ public struct Digest {
         return SHA2(variant: variant).calculate(for: bytes)
         return SHA2(variant: variant).calculate(for: bytes)
     }
     }
 
 
-
     /// Calculate SHA3 Digest
     /// Calculate SHA3 Digest
     /// - parameter bytes: input message
     /// - parameter bytes: input message
     /// - parameter variant: SHA-3 variant
     /// - parameter variant: SHA-3 variant

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

@@ -33,6 +33,6 @@ public extension CSArrayType where Iterator.Element == UInt8 {
             return
             return
         }
         }
 
 
-        self.append(contentsOf: decodedData.bytes)
+        append(contentsOf: decodedData.bytes)
     }
     }
 }
 }

+ 15 - 15
Sources/CryptoSwift/Foundation/Data+Extension.swift

@@ -21,8 +21,8 @@ extension Data {
     /// Two octet checksum as defined in RFC-4880. Sum of all octets, mod 65536
     /// Two octet checksum as defined in RFC-4880. Sum of all octets, mod 65536
     public func checksum() -> UInt16 {
     public func checksum() -> UInt16 {
         var s: UInt32 = 0
         var s: UInt32 = 0
-        var bytesArray = self.bytes
-        for i in 0 ..< bytesArray.count {
+        var bytesArray = bytes
+        for i in 0..<bytesArray.count {
             s = s + UInt32(bytesArray[i])
             s = s + UInt32(bytesArray[i])
         }
         }
         s = s % 65536
         s = s % 65536
@@ -30,51 +30,51 @@ extension Data {
     }
     }
 
 
     public func md5() -> Data {
     public func md5() -> Data {
-        return Data(bytes: Digest.md5(self.bytes))
+        return Data(bytes: Digest.md5(bytes))
     }
     }
 
 
     public func sha1() -> Data {
     public func sha1() -> Data {
-        return Data(bytes: Digest.sha1(self.bytes))
+        return Data(bytes: Digest.sha1(bytes))
     }
     }
 
 
     public func sha224() -> Data {
     public func sha224() -> Data {
-        return Data(bytes: Digest.sha224(self.bytes))
+        return Data(bytes: Digest.sha224(bytes))
     }
     }
 
 
     public func sha256() -> Data {
     public func sha256() -> Data {
-        return Data(bytes: Digest.sha256(self.bytes))
+        return Data(bytes: Digest.sha256(bytes))
     }
     }
 
 
     public func sha384() -> Data {
     public func sha384() -> Data {
-        return Data(bytes: Digest.sha384(self.bytes))
+        return Data(bytes: Digest.sha384(bytes))
     }
     }
 
 
     public func sha512() -> Data {
     public func sha512() -> Data {
-        return Data(bytes: Digest.sha512(self.bytes))
+        return Data(bytes: Digest.sha512(bytes))
     }
     }
 
 
     public func sha3(_ variant: SHA3.Variant) -> Data {
     public func sha3(_ variant: SHA3.Variant) -> Data {
-        return Data(bytes: Digest.sha3(self.bytes, variant: variant))
+        return Data(bytes: Digest.sha3(bytes, variant: variant))
     }
     }
 
 
     public func crc32(seed: UInt32? = nil, reflect: Bool = true) -> Data {
     public func crc32(seed: UInt32? = nil, reflect: Bool = true) -> Data {
-        return Data(bytes: Checksum.crc32(self.bytes, seed: seed, reflect: reflect).bytes())
+        return Data(bytes: Checksum.crc32(bytes, seed: seed, reflect: reflect).bytes())
     }
     }
 
 
     public func crc16(seed: UInt16? = nil) -> Data {
     public func crc16(seed: UInt16? = nil) -> Data {
-        return Data(bytes: Checksum.crc16(self.bytes, seed: seed).bytes())
+        return Data(bytes: Checksum.crc16(bytes, seed: seed).bytes())
     }
     }
 
 
     public func encrypt(cipher: Cipher) throws -> Data {
     public func encrypt(cipher: Cipher) throws -> Data {
-        return Data(bytes: try cipher.encrypt(self.bytes.slice))
+        return Data(bytes: try cipher.encrypt(bytes.slice))
     }
     }
 
 
     public func decrypt(cipher: Cipher) throws -> Data {
     public func decrypt(cipher: Cipher) throws -> Data {
-        return Data(bytes: try cipher.decrypt(self.bytes.slice))
+        return Data(bytes: try cipher.decrypt(bytes.slice))
     }
     }
 
 
     public func authenticate(with authenticator: Authenticator) throws -> Data {
     public func authenticate(with authenticator: Authenticator) throws -> Data {
-        return Data(bytes: try authenticator.authenticate(self.bytes))
+        return Data(bytes: try authenticator.authenticate(bytes))
     }
     }
 }
 }
 
 
@@ -85,6 +85,6 @@ extension Data {
     }
     }
 
 
     public func toHexString() -> String {
     public func toHexString() -> String {
-        return self.bytes.toHexString()
+        return bytes.toHexString()
     }
     }
 }
 }

+ 1 - 1
Sources/CryptoSwift/Generics.swift

@@ -45,7 +45,7 @@ func arrayOfBytes<T: FixedWidthInteger>(value: T, length totalBytes: Int = Memor
 
 
     let bytesPointer = UnsafeMutablePointer<UInt8>(OpaquePointer(valuePointer))
     let bytesPointer = UnsafeMutablePointer<UInt8>(OpaquePointer(valuePointer))
     var bytes = Array<UInt8>(repeating: 0, count: totalBytes)
     var bytes = Array<UInt8>(repeating: 0, count: totalBytes)
-    for j in 0 ..< min(MemoryLayout<T>.size, totalBytes) {
+    for j in 0..<min(MemoryLayout<T>.size, totalBytes) {
         bytes[totalBytes - 1 - j] = (bytesPointer + j).pointee
         bytes[totalBytes - 1 - j] = (bytesPointer + j).pointee
     }
     }
 
 

+ 2 - 2
Sources/CryptoSwift/HMAC.swift

@@ -25,7 +25,7 @@ public final class HMAC: Authenticator {
         case sha1, sha256, sha384, sha512, md5
         case sha1, sha256, sha384, sha512, md5
 
 
         var digestLength: Int {
         var digestLength: Int {
-            switch (self) {
+            switch self {
             case .sha1:
             case .sha1:
                 return SHA1.digestLength
                 return SHA1.digestLength
             case .sha256:
             case .sha256:
@@ -40,7 +40,7 @@ public final class HMAC: Authenticator {
         }
         }
 
 
         func calculateHash(_ bytes: Array<UInt8>) -> Array<UInt8>? {
         func calculateHash(_ bytes: Array<UInt8>) -> Array<UInt8>? {
-            switch (self) {
+            switch self {
             case .sha1:
             case .sha1:
                 return Digest.sha1(bytes)
                 return Digest.sha1(bytes)
             case .sha256:
             case .sha256:

+ 46 - 42
Sources/CryptoSwift/MD5.swift

@@ -24,35 +24,39 @@ public final class MD5: DigestType {
     fileprivate var accumulatedHash: Array<UInt32> = MD5.hashInitialValue
     fileprivate var accumulatedHash: Array<UInt32> = MD5.hashInitialValue
 
 
     /** specifies the per-round shift amounts */
     /** specifies the per-round shift amounts */
-    private let s: Array<UInt32> = [7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22,
-                                    5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20,
-                                    4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23,
-                                    6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21]
+    private let s: Array<UInt32> = [
+        7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22,
+        5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20,
+        4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23,
+        6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21,
+    ]
 
 
     /** binary integer part of the sines of integers (Radians) */
     /** binary integer part of the sines of integers (Radians) */
-    private let k: Array<UInt32> = [0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee,
-                                    0xf57c0faf, 0x4787c62a, 0xa8304613, 0xfd469501,
-                                    0x698098d8, 0x8b44f7af, 0xffff5bb1, 0x895cd7be,
-                                    0x6b901122, 0xfd987193, 0xa679438e, 0x49b40821,
-                                    0xf61e2562, 0xc040b340, 0x265e5a51, 0xe9b6c7aa,
-                                    0xd62f105d, 0x2441453, 0xd8a1e681, 0xe7d3fbc8,
-                                    0x21e1cde6, 0xc33707d6, 0xf4d50d87, 0x455a14ed,
-                                    0xa9e3e905, 0xfcefa3f8, 0x676f02d9, 0x8d2a4c8a,
-                                    0xfffa3942, 0x8771f681, 0x6d9d6122, 0xfde5380c,
-                                    0xa4beea44, 0x4bdecfa9, 0xf6bb4b60, 0xbebfbc70,
-                                    0x289b7ec6, 0xeaa127fa, 0xd4ef3085, 0x4881d05,
-                                    0xd9d4d039, 0xe6db99e5, 0x1fa27cf8, 0xc4ac5665,
-                                    0xf4292244, 0x432aff97, 0xab9423a7, 0xfc93a039,
-                                    0x655b59c3, 0x8f0ccc92, 0xffeff47d, 0x85845dd1,
-                                    0x6fa87e4f, 0xfe2ce6e0, 0xa3014314, 0x4e0811a1,
-                                    0xf7537e82, 0xbd3af235, 0x2ad7d2bb, 0xeb86d391]
+    private let k: Array<UInt32> = [
+        0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee,
+        0xf57c0faf, 0x4787c62a, 0xa8304613, 0xfd469501,
+        0x698098d8, 0x8b44f7af, 0xffff5bb1, 0x895cd7be,
+        0x6b901122, 0xfd987193, 0xa679438e, 0x49b40821,
+        0xf61e2562, 0xc040b340, 0x265e5a51, 0xe9b6c7aa,
+        0xd62f105d, 0x2441453, 0xd8a1e681, 0xe7d3fbc8,
+        0x21e1cde6, 0xc33707d6, 0xf4d50d87, 0x455a14ed,
+        0xa9e3e905, 0xfcefa3f8, 0x676f02d9, 0x8d2a4c8a,
+        0xfffa3942, 0x8771f681, 0x6d9d6122, 0xfde5380c,
+        0xa4beea44, 0x4bdecfa9, 0xf6bb4b60, 0xbebfbc70,
+        0x289b7ec6, 0xeaa127fa, 0xd4ef3085, 0x4881d05,
+        0xd9d4d039, 0xe6db99e5, 0x1fa27cf8, 0xc4ac5665,
+        0xf4292244, 0x432aff97, 0xab9423a7, 0xfc93a039,
+        0x655b59c3, 0x8f0ccc92, 0xffeff47d, 0x85845dd1,
+        0x6fa87e4f, 0xfe2ce6e0, 0xa3014314, 0x4e0811a1,
+        0xf7537e82, 0xbd3af235, 0x2ad7d2bb, 0xeb86d391,
+    ]
 
 
     public init() {
     public init() {
     }
     }
 
 
     public func calculate(for bytes: Array<UInt8>) -> Array<UInt8> {
     public func calculate(for bytes: Array<UInt8>) -> Array<UInt8> {
         do {
         do {
-            return try self.update(withBytes: bytes.slice, isLast: true)
+            return try update(withBytes: bytes.slice, isLast: true)
         } catch {
         } catch {
             fatalError()
             fatalError()
         }
         }
@@ -71,24 +75,24 @@ public final class MD5: DigestType {
         var dTemp: UInt32 = 0
         var dTemp: UInt32 = 0
 
 
         // Main loop
         // Main loop
-        for j in 0 ..< k.count {
+        for j in 0..<k.count {
             var g = 0
             var g = 0
             var F: UInt32 = 0
             var F: UInt32 = 0
 
 
-            switch (j) {
-            case 0 ... 15:
+            switch j {
+            case 0...15:
                 F = (B & C) | ((~B) & D)
                 F = (B & C) | ((~B) & D)
                 g = j
                 g = j
                 break
                 break
-            case 16 ... 31:
+            case 16...31:
                 F = (D & B) | (~D & C)
                 F = (D & B) | (~D & C)
                 g = (5 * j + 1) % 16
                 g = (5 * j + 1) % 16
                 break
                 break
-            case 32 ... 47:
+            case 32...47:
                 F = B ^ C ^ D
                 F = B ^ C ^ D
                 g = (3 * j + 5) % 16
                 g = (3 * j + 5) % 16
                 break
                 break
-            case 48 ... 63:
+            case 48...63:
                 F = C ^ (B | (~D))
                 F = C ^ (B | (~D))
                 g = (7 * j) % 16
                 g = (7 * j) % 16
                 break
                 break
@@ -102,10 +106,10 @@ public final class MD5: DigestType {
             // break chunk into sixteen 32-bit words M[j], 0 ≤ j ≤ 15 and get M[g] value
             // break chunk into sixteen 32-bit words M[j], 0 ≤ j ≤ 15 and get M[g] value
             let gAdvanced = g << 2
             let gAdvanced = g << 2
 
 
-            var Mg  = UInt32(chunk[chunk.startIndex &+ gAdvanced])
-                Mg |= UInt32(chunk[chunk.startIndex &+ gAdvanced &+ 1]) << 8
-                Mg |= UInt32(chunk[chunk.startIndex &+ gAdvanced &+ 2]) << 16
-                Mg |= UInt32(chunk[chunk.startIndex &+ gAdvanced &+ 3]) << 24
+            var Mg = UInt32(chunk[chunk.startIndex &+ gAdvanced])
+            Mg |= UInt32(chunk[chunk.startIndex &+ gAdvanced &+ 1]) << 8
+            Mg |= UInt32(chunk[chunk.startIndex &+ gAdvanced &+ 2]) << 16
+            Mg |= UInt32(chunk[chunk.startIndex &+ gAdvanced &+ 3]) << 24
 
 
             B = B &+ rotateLeft(A &+ F &+ k[j] &+ Mg, by: s[j])
             B = B &+ rotateLeft(A &+ F &+ k[j] &+ Mg, by: s[j])
             A = dTemp
             A = dTemp
@@ -121,41 +125,41 @@ public final class MD5: DigestType {
 extension MD5: Updatable {
 extension MD5: Updatable {
 
 
     public func update(withBytes bytes: ArraySlice<UInt8>, isLast: Bool = false) throws -> Array<UInt8> {
     public func update(withBytes bytes: ArraySlice<UInt8>, isLast: Bool = false) throws -> Array<UInt8> {
-        self.accumulated += bytes
+        accumulated += bytes
 
 
         if isLast {
         if isLast {
-            let lengthInBits = (self.processedBytesTotalCount + self.accumulated.count) * 8
+            let lengthInBits = (processedBytesTotalCount + accumulated.count) * 8
             let lengthBytes = lengthInBits.bytes(totalBytes: 64 / 8) // A 64-bit representation of b
             let lengthBytes = lengthInBits.bytes(totalBytes: 64 / 8) // A 64-bit representation of b
 
 
             // Step 1. Append padding
             // Step 1. Append padding
-            bitPadding(to: &self.accumulated, blockSize: MD5.blockSize, allowance: 64 / 8)
+            bitPadding(to: &accumulated, blockSize: MD5.blockSize, allowance: 64 / 8)
 
 
             // Step 2. Append Length a 64-bit representation of lengthInBits
             // Step 2. Append Length a 64-bit representation of lengthInBits
-            self.accumulated += lengthBytes.reversed()
+            accumulated += lengthBytes.reversed()
         }
         }
 
 
         var processedBytes = 0
         var processedBytes = 0
-        for chunk in self.accumulated.batched(by: MD5.blockSize) {
-            if (isLast || (self.accumulated.count - processedBytes) >= MD5.blockSize) {
-                self.process(block: chunk, currentHash: &self.accumulatedHash)
+        for chunk in accumulated.batched(by: MD5.blockSize) {
+            if isLast || (accumulated.count - processedBytes) >= MD5.blockSize {
+                process(block: chunk, currentHash: &accumulatedHash)
                 processedBytes += chunk.count
                 processedBytes += chunk.count
             }
             }
         }
         }
-        self.accumulated.removeFirst(processedBytes)
-        self.processedBytesTotalCount += processedBytes
+        accumulated.removeFirst(processedBytes)
+        processedBytesTotalCount += processedBytes
 
 
         // output current hash
         // output current hash
         var result = Array<UInt8>()
         var result = Array<UInt8>()
         result.reserveCapacity(MD5.digestLength)
         result.reserveCapacity(MD5.digestLength)
 
 
-        for hElement in self.accumulatedHash {
+        for hElement in accumulatedHash {
             let hLE = hElement.littleEndian
             let hLE = hElement.littleEndian
             result += [UInt8(hLE & 0xff), UInt8((hLE >> 8) & 0xff), UInt8((hLE >> 16) & 0xff), UInt8((hLE >> 24) & 0xff)]
             result += [UInt8(hLE & 0xff), UInt8((hLE >> 8) & 0xff), UInt8((hLE >> 16) & 0xff), UInt8((hLE >> 24) & 0xff)]
         }
         }
 
 
         // reset hash value for instance
         // reset hash value for instance
         if isLast {
         if isLast {
-            self.accumulatedHash = MD5.hashInitialValue
+            accumulatedHash = MD5.hashInitialValue
         }
         }
 
 
         return result
         return result

+ 2 - 2
Sources/CryptoSwift/NoPadding.swift

@@ -19,11 +19,11 @@ public struct NoPadding: Padding {
     public init() {
     public init() {
     }
     }
 
 
-    public func add(to data: Array<UInt8>, blockSize: Int) -> Array<UInt8> {
+    public func add(to data: Array<UInt8>, blockSize _: Int) -> Array<UInt8> {
         return data
         return data
     }
     }
 
 
-    public func remove(from data: Array<UInt8>, blockSize: Int?) -> Array<UInt8> {
+    public func remove(from data: Array<UInt8>, blockSize _: Int?) -> Array<UInt8> {
         return data
         return data
     }
     }
 }
 }

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

@@ -32,7 +32,7 @@ public extension PKCS5 {
             case md5, sha1
             case md5, sha1
 
 
             var size: Int {
             var size: Int {
-                switch (self) {
+                switch self {
                 case .md5:
                 case .md5:
                     return MD5.digestLength
                     return MD5.digestLength
                 case .sha1:
                 case .sha1:
@@ -41,7 +41,7 @@ public extension PKCS5 {
             }
             }
 
 
             fileprivate func calculateHash(_ bytes: Array<UInt8>) -> Array<UInt8>? {
             fileprivate func calculateHash(_ bytes: Array<UInt8>) -> Array<UInt8>? {
-                switch (self) {
+                switch self {
                 case .sha1:
                 case .sha1:
                     return Digest.sha1(bytes)
                     return Digest.sha1(bytes)
                 case .md5:
                 case .md5:
@@ -60,13 +60,13 @@ public extension PKCS5 {
         ///   - variant: hash variant
         ///   - variant: hash variant
         ///   - iterations: iteration count, a positive integer
         ///   - iterations: iteration count, a positive integer
         ///   - keyLength: intended length of derived key
         ///   - keyLength: intended length of derived key
-        public init(password: Array<UInt8>, salt: Array<UInt8>, variant: Variant = .sha1, iterations: Int = 4096 /* c */ , keyLength: Int? = nil /* dkLen */ ) throws {
+        public init(password: Array<UInt8>, salt: Array<UInt8>, variant: Variant = .sha1, iterations: Int = 4096 /* c */, keyLength: Int? = nil /* dkLen */ ) throws {
             precondition(iterations > 0)
             precondition(iterations > 0)
             precondition(salt.count == 8)
             precondition(salt.count == 8)
 
 
             let keyLength = keyLength ?? variant.size
             let keyLength = keyLength ?? variant.size
 
 
-            if (keyLength > variant.size) {
+            if keyLength > variant.size {
                 throw Error.derivedKeyTooLong
                 throw Error.derivedKeyTooLong
             }
             }
 
 
@@ -83,10 +83,10 @@ public extension PKCS5 {
         /// Apply the underlying hash function Hash for c iterations
         /// Apply the underlying hash function Hash for c iterations
         public func calculate() -> Array<UInt8> {
         public func calculate() -> Array<UInt8> {
             var t = t1
             var t = t1
-            for _ in 2 ... self.iterations {
-                t = self.variant.calculateHash(t)!
+            for _ in 2...iterations {
+                t = variant.calculateHash(t)!
             }
             }
-            return Array(t[0 ..< self.keyLength])
+            return Array(t[0..<self.keyLength])
         }
         }
     }
     }
 }
 }

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

@@ -47,7 +47,7 @@ public extension PKCS5 {
         ///   - variant: hash variant
         ///   - variant: hash variant
         ///   - iterations: iteration count, a positive integer
         ///   - iterations: iteration count, a positive integer
         ///   - keyLength: intended length of derived key
         ///   - keyLength: intended length of derived key
-        public init(password: Array<UInt8>, salt: Array<UInt8>, iterations: Int = 4096 /* c */ , keyLength: Int? = nil /* dkLen */ , variant: HMAC.Variant = .sha256) throws {
+        public init(password: Array<UInt8>, salt: Array<UInt8>, iterations: Int = 4096 /* c */, keyLength: Int? = nil /* dkLen */, variant: HMAC.Variant = .sha256) throws {
             precondition(iterations > 0)
             precondition(iterations > 0)
 
 
             let prf = HMAC(key: password, variant: variant)
             let prf = HMAC(key: password, variant: variant)
@@ -56,8 +56,8 @@ public extension PKCS5 {
                 throw Error.invalidInput
                 throw Error.invalidInput
             }
             }
 
 
-            self.dkLen = keyLength ?? variant.digestLength
-            let keyLengthFinal = Double(self.dkLen)
+            dkLen = keyLength ?? variant.digestLength
+            let keyLengthFinal = Double(dkLen)
             let hLen = Double(prf.variant.digestLength)
             let hLen = Double(prf.variant.digestLength)
             if keyLengthFinal > (pow(2, 32) - 1) * hLen {
             if keyLengthFinal > (pow(2, 32) - 1) * hLen {
                 throw Error.derivedKeyTooLong
                 throw Error.derivedKeyTooLong
@@ -67,19 +67,19 @@ public extension PKCS5 {
             self.iterations = iterations
             self.iterations = iterations
             self.prf = prf
             self.prf = prf
 
 
-            self.numBlocks = Int(ceil(Double(keyLengthFinal) / hLen)) // l = ceil(keyLength / hLen)
+            numBlocks = Int(ceil(Double(keyLengthFinal) / hLen)) // l = ceil(keyLength / hLen)
         }
         }
 
 
         public func calculate() throws -> Array<UInt8> {
         public func calculate() throws -> Array<UInt8> {
             var ret = Array<UInt8>()
             var ret = Array<UInt8>()
-            ret.reserveCapacity(self.numBlocks * self.prf.variant.digestLength)
-            for i in 1 ... self.numBlocks {
+            ret.reserveCapacity(numBlocks * prf.variant.digestLength)
+            for i in 1...numBlocks {
                 // for each block T_i = U_1 ^ U_2 ^ ... ^ U_iter
                 // for each block T_i = U_1 ^ U_2 ^ ... ^ U_iter
                 if let value = try calculateBlock(self.salt, blockNum: i) {
                 if let value = try calculateBlock(self.salt, blockNum: i) {
                     ret.append(contentsOf: value)
                     ret.append(contentsOf: value)
                 }
                 }
             }
             }
-            return Array(ret.prefix(self.dkLen))
+            return Array(ret.prefix(dkLen))
         }
         }
     }
     }
 }
 }
@@ -88,10 +88,10 @@ fileprivate extension PKCS5.PBKDF2 {
 
 
     func ARR(_ i: Int) -> Array<UInt8> {
     func ARR(_ i: Int) -> Array<UInt8> {
         var inti = Array<UInt8>(repeating: 0, count: 4)
         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)
-        inti[3] = UInt8(i & 0xFF)
+        inti[0] = UInt8((i >> 24) & 0xff)
+        inti[1] = UInt8((i >> 16) & 0xff)
+        inti[2] = UInt8((i >> 8) & 0xff)
+        inti[3] = UInt8(i & 0xff)
         return inti
         return inti
     }
     }
 
 
@@ -104,12 +104,12 @@ fileprivate extension PKCS5.PBKDF2 {
 
 
         var u = u1
         var u = u1
         var ret = u
         var ret = u
-        if self.iterations > 1 {
+        if iterations > 1 {
             // U_2 = PRF (P, U_1) ,
             // U_2 = PRF (P, U_1) ,
             // U_c = PRF (P, U_{c-1}) .
             // U_c = PRF (P, U_{c-1}) .
-            for _ in 2 ... self.iterations {
+            for _ in 2...iterations {
                 u = try prf.authenticate(u)
                 u = try prf.authenticate(u)
-                for x in 0 ..< ret.count {
+                for x in 0..<ret.count {
                     ret[x] = ret[x] ^ u[x]
                     ret[x] = ret[x] ^ u[x]
                 }
                 }
             }
             }

+ 5 - 5
Sources/CryptoSwift/PKCS7.swift

@@ -30,21 +30,21 @@ public struct PKCS7: Padding {
     public func add(to bytes: Array<UInt8>, blockSize: Int) -> Array<UInt8> {
     public func add(to bytes: Array<UInt8>, blockSize: Int) -> Array<UInt8> {
         let padding = UInt8(blockSize - (bytes.count % blockSize))
         let padding = UInt8(blockSize - (bytes.count % blockSize))
         var withPadding = bytes
         var withPadding = bytes
-        if (padding == 0) {
+        if padding == 0 {
             // If the original data is a multiple of N bytes, then an extra block of bytes with value N is added.
             // If the original data is a multiple of N bytes, then an extra block of bytes with value N is added.
-            for _ in 0 ..< blockSize {
+            for _ in 0..<blockSize {
                 withPadding += [UInt8(blockSize)]
                 withPadding += [UInt8(blockSize)]
             }
             }
         } else {
         } else {
             // The value of each added byte is the number of bytes that are added
             // The value of each added byte is the number of bytes that are added
-            for _ in 0 ..< padding {
+            for _ in 0..<padding {
                 withPadding += [UInt8(padding)]
                 withPadding += [UInt8(padding)]
             }
             }
         }
         }
         return withPadding
         return withPadding
     }
     }
 
 
-    public func remove(from bytes: Array<UInt8>, blockSize: Int?) -> Array<UInt8> {
+    public func remove(from bytes: Array<UInt8>, blockSize _: Int?) -> Array<UInt8> {
         guard !bytes.isEmpty, let lastByte = bytes.last else {
         guard !bytes.isEmpty, let lastByte = bytes.last else {
             return bytes
             return bytes
         }
         }
@@ -59,7 +59,7 @@ public struct PKCS7: Padding {
         }
         }
 
 
         if padding >= 1 {
         if padding >= 1 {
-            return Array(bytes[0 ..< finalLength])
+            return Array(bytes[0..<finalLength])
         }
         }
         return bytes
         return bytes
     }
     }

+ 6 - 7
Sources/CryptoSwift/Poly1305.swift

@@ -83,7 +83,7 @@ public final class Poly1305: Authenticator {
             hr[i] = u
             hr[i] = u
         }
         }
         h = hr
         h = hr
-        self.squeeze(h: &h)
+        squeeze(h: &h)
     }
     }
 
 
     private func freeze(h: inout Array<UInt32>) {
     private func freeze(h: inout Array<UInt32>) {
@@ -120,7 +120,6 @@ public final class Poly1305: Authenticator {
         r[15] = UInt32(k[15] & 15)
         r[15] = UInt32(k[15] & 15)
         r[16] = 0
         r[16] = 0
 
 
-
         var inlen = input.count
         var inlen = input.count
         var inpos = 0
         var inpos = 0
         while inlen > 0 {
         while inlen > 0 {
@@ -135,11 +134,11 @@ public final class Poly1305: Authenticator {
             c[maxj] = 1
             c[maxj] = 1
             inpos = inpos + maxj
             inpos = inpos + maxj
             inlen = inlen - maxj
             inlen = inlen - maxj
-            self.add(h: &h, c: c)
-            self.mulmod(h: &h, r: r)
+            add(h: &h, c: c)
+            mulmod(h: &h, r: r)
         }
         }
 
 
-        self.freeze(h: &h)
+        freeze(h: &h)
 
 
         for j in 0..<16 {
         for j in 0..<16 {
             c[j] = UInt32(k[j + 16])
             c[j] = UInt32(k[j + 16])
@@ -148,7 +147,7 @@ public final class Poly1305: Authenticator {
         add(h: &h, c: c)
         add(h: &h, c: c)
 
 
         return h[0..<16].map {
         return h[0..<16].map {
-            UInt8($0 & 0xFF)
+            UInt8($0 & 0xff)
         }
         }
     }
     }
 
 
@@ -163,6 +162,6 @@ public final class Poly1305: Authenticator {
      - returns: 16-byte tag that authenticates the message
      - returns: 16-byte tag that authenticates the message
      */
      */
     public func authenticate(_ bytes: Array<UInt8>) throws -> Array<UInt8> {
     public func authenticate(_ bytes: Array<UInt8>) throws -> Array<UInt8> {
-        return onetimeauth(message: bytes, key: Array(self.key))
+        return onetimeauth(message: bytes, key: Array(key))
     }
     }
 }
 }

+ 15 - 15
Sources/CryptoSwift/Rabbit.swift

@@ -48,14 +48,14 @@ public final class Rabbit: BlockCipher {
 
 
     /// 'a' constants
     /// 'a' constants
     private var a: Array<UInt32> = [
     private var a: Array<UInt32> = [
-        0x4D34D34D,
-        0xD34D34D3,
-        0x34D34D34,
-        0x4D34D34D,
-        0xD34D34D3,
-        0x34D34D34,
-        0x4D34D34D,
-        0xD34D34D3,
+        0x4d34d34d,
+        0xd34d34d3,
+        0x34d34d34,
+        0x4d34d34d,
+        0xd34d34d3,
+        0x34d34d34,
+        0x4d34d34d,
+        0xd34d34d3,
     ]
     ]
 
 
     // MARK: - Initializers
     // MARK: - Initializers
@@ -78,12 +78,12 @@ public final class Rabbit: BlockCipher {
 
 
         // Key divided into 8 subkeys
         // Key divided into 8 subkeys
         var k = Array<UInt32>(repeating: 0, count: 8)
         var k = Array<UInt32>(repeating: 0, count: 8)
-        for j in 0 ..< 8 {
+        for j in 0..<8 {
             k[j] = UInt32(key[Rabbit.blockSize - (2 * j + 1)]) | (UInt32(key[Rabbit.blockSize - (2 * j + 2)]) << 8)
             k[j] = UInt32(key[Rabbit.blockSize - (2 * j + 1)]) | (UInt32(key[Rabbit.blockSize - (2 * j + 2)]) << 8)
         }
         }
 
 
         // Initialize state and counter variables from subkeys
         // Initialize state and counter variables from subkeys
-        for j in 0 ..< 8 {
+        for j in 0..<8 {
             if j % 2 == 0 {
             if j % 2 == 0 {
                 x[j] = (k[(j + 1) % 8] << 16) | k[j]
                 x[j] = (k[(j + 1) % 8] << 16) | k[j]
                 c[j] = (k[(j + 4) % 8] << 16) | k[(j + 5) % 8]
                 c[j] = (k[(j + 4) % 8] << 16) | k[(j + 5) % 8]
@@ -100,7 +100,7 @@ public final class Rabbit: BlockCipher {
         nextState()
         nextState()
 
 
         // Reinitialize counter variables
         // Reinitialize counter variables
-        for j in 0 ..< 8 {
+        for j in 0..<8 {
             c[j] = c[j] ^ x[(j + 4) % 8]
             c[j] = c[j] ^ x[(j + 4) % 8]
         }
         }
 
 
@@ -137,7 +137,7 @@ public final class Rabbit: BlockCipher {
     private func nextState() {
     private func nextState() {
         // Before an iteration the counters are incremented
         // Before an iteration the counters are incremented
         var carry = p7
         var carry = p7
-        for j in 0 ..< 8 {
+        for j in 0..<8 {
             let prev = c[j]
             let prev = c[j]
             c[j] = prev &+ a[j] &+ carry
             c[j] = prev &+ a[j] &+ carry
             carry = prev > c[j] ? 1 : 0 // detect overflow
             carry = prev > c[j] ? 1 : 0 // detect overflow
@@ -160,7 +160,7 @@ public final class Rabbit: BlockCipher {
     private func g(_ j: Int) -> UInt32 {
     private func g(_ j: Int) -> UInt32 {
         let sum = x[j] &+ c[j]
         let sum = x[j] &+ c[j]
         let square = UInt64(sum) * UInt64(sum)
         let square = UInt64(sum) * UInt64(sum)
-        return UInt32.init(truncatingIfNeeded: square ^ (square >> 32))
+        return UInt32(truncatingIfNeeded: square ^ (square >> 32))
     }
     }
 
 
     fileprivate func nextOutput() -> Array<UInt8> {
     fileprivate func nextOutput() -> Array<UInt8> {
@@ -177,7 +177,7 @@ public final class Rabbit: BlockCipher {
         output16[0] = UInt16(truncatingIfNeeded: x[6] >> 16) ^ UInt16(truncatingIfNeeded: x[1])
         output16[0] = UInt16(truncatingIfNeeded: x[6] >> 16) ^ UInt16(truncatingIfNeeded: x[1])
 
 
         var output8 = Array<UInt8>(repeating: 0, count: Rabbit.blockSize)
         var output8 = Array<UInt8>(repeating: 0, count: Rabbit.blockSize)
-        for j in 0 ..< output16.count {
+        for j in 0..<output16.count {
             output8[j * 2] = UInt8(truncatingIfNeeded: output16[j] >> 8)
             output8[j * 2] = UInt8(truncatingIfNeeded: output16[j] >> 8)
             output8[j * 2 + 1] = UInt8(truncatingIfNeeded: output16[j])
             output8[j * 2 + 1] = UInt8(truncatingIfNeeded: output16[j])
         }
         }
@@ -196,7 +196,7 @@ extension Rabbit: Cipher {
         var byteIdx = 0
         var byteIdx = 0
         var outputIdx = 0
         var outputIdx = 0
         while byteIdx < bytes.count {
         while byteIdx < bytes.count {
-            if (outputIdx == Rabbit.blockSize) {
+            if outputIdx == Rabbit.blockSize {
                 output = nextOutput()
                 output = nextOutput()
                 outputIdx = 0
                 outputIdx = 0
             }
             }

+ 25 - 25
Sources/CryptoSwift/SHA1.swift

@@ -17,7 +17,7 @@
 public final class SHA1: DigestType {
 public final class SHA1: DigestType {
     static let digestLength: Int = 20 // 160 / 8
     static let digestLength: Int = 20 // 160 / 8
     static let blockSize: Int = 64
     static let blockSize: Int = 64
-    fileprivate static let hashInitialValue: ContiguousArray<UInt32> = [0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0]
+    fileprivate static let hashInitialValue: ContiguousArray<UInt32> = [0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0]
 
 
     fileprivate var accumulated = Array<UInt8>()
     fileprivate var accumulated = Array<UInt8>()
     fileprivate var processedBytesTotalCount: Int = 0
     fileprivate var processedBytesTotalCount: Int = 0
@@ -28,7 +28,7 @@ public final class SHA1: DigestType {
 
 
     public func calculate(for bytes: Array<UInt8>) -> Array<UInt8> {
     public func calculate(for bytes: Array<UInt8>) -> Array<UInt8> {
         do {
         do {
-            return try self.update(withBytes: bytes.slice, isLast: true)
+            return try update(withBytes: bytes.slice, isLast: true)
         } catch {
         } catch {
             return []
             return []
         }
         }
@@ -44,9 +44,9 @@ public final class SHA1: DigestType {
             M.deallocate(capacity: 80)
             M.deallocate(capacity: 80)
         }
         }
 
 
-        for x in 0 ..< 80 {
+        for x in 0..<80 {
             switch x {
             switch x {
-            case 0 ... 15:
+            case 0...15:
                 let start = chunk.startIndex.advanced(by: x * 4) // * MemoryLayout<UInt32>.size
                 let start = chunk.startIndex.advanced(by: x * 4) // * MemoryLayout<UInt32>.size
                 M[x] = UInt32(bytes: chunk, fromIndex: start)
                 M[x] = UInt32(bytes: chunk, fromIndex: start)
                 break
                 break
@@ -63,26 +63,26 @@ public final class SHA1: DigestType {
         var E = hh[4]
         var E = hh[4]
 
 
         // Main loop
         // Main loop
-        for j in 0 ... 79 {
+        for j in 0...79 {
             var f: UInt32 = 0
             var f: UInt32 = 0
             var k: UInt32 = 0
             var k: UInt32 = 0
 
 
             switch j {
             switch j {
-            case 0 ... 19:
+            case 0...19:
                 f = (B & C) | ((~B) & D)
                 f = (B & C) | ((~B) & D)
-                k = 0x5A827999
+                k = 0x5a827999
                 break
                 break
-            case 20 ... 39:
+            case 20...39:
                 f = B ^ C ^ D
                 f = B ^ C ^ D
-                k = 0x6ED9EBA1
+                k = 0x6ed9eba1
                 break
                 break
-            case 40 ... 59:
+            case 40...59:
                 f = (B & C) | (B & D) | (C & D)
                 f = (B & C) | (B & D) | (C & D)
-                k = 0x8F1BBCDC
+                k = 0x8f1bbcdc
                 break
                 break
-            case 60 ... 79:
+            case 60...79:
                 f = B ^ C ^ D
                 f = B ^ C ^ D
-                k = 0xCA62C1D6
+                k = 0xca62c1d6
                 break
                 break
             default:
             default:
                 break
                 break
@@ -107,34 +107,34 @@ public final class SHA1: DigestType {
 extension SHA1: Updatable {
 extension SHA1: Updatable {
 
 
     public func update(withBytes bytes: ArraySlice<UInt8>, isLast: Bool = false) throws -> Array<UInt8> {
     public func update(withBytes bytes: ArraySlice<UInt8>, isLast: Bool = false) throws -> Array<UInt8> {
-        self.accumulated += bytes
+        accumulated += bytes
 
 
         if isLast {
         if isLast {
-            let lengthInBits = (self.processedBytesTotalCount + self.accumulated.count) * 8
+            let lengthInBits = (processedBytesTotalCount + accumulated.count) * 8
             let lengthBytes = lengthInBits.bytes(totalBytes: 64 / 8) // A 64-bit representation of b
             let lengthBytes = lengthInBits.bytes(totalBytes: 64 / 8) // A 64-bit representation of b
 
 
             // Step 1. Append padding
             // Step 1. Append padding
-            bitPadding(to: &self.accumulated, blockSize: SHA1.blockSize, allowance: 64 / 8)
+            bitPadding(to: &accumulated, blockSize: SHA1.blockSize, allowance: 64 / 8)
 
 
             // Step 2. Append Length a 64-bit representation of lengthInBits
             // Step 2. Append Length a 64-bit representation of lengthInBits
-            self.accumulated += lengthBytes
+            accumulated += lengthBytes
         }
         }
 
 
         var processedBytes = 0
         var processedBytes = 0
-        for chunk in self.accumulated.batched(by: SHA1.blockSize) {
-            if (isLast || (self.accumulated.count - processedBytes) >= SHA1.blockSize) {
-                self.process(block: chunk, currentHash: &self.accumulatedHash)
+        for chunk in accumulated.batched(by: SHA1.blockSize) {
+            if isLast || (accumulated.count - processedBytes) >= SHA1.blockSize {
+                process(block: chunk, currentHash: &accumulatedHash)
                 processedBytes += chunk.count
                 processedBytes += chunk.count
             }
             }
         }
         }
-        self.accumulated.removeFirst(processedBytes)
-        self.processedBytesTotalCount += processedBytes
+        accumulated.removeFirst(processedBytes)
+        processedBytesTotalCount += processedBytes
 
 
         // output current hash
         // output current hash
         var result = Array<UInt8>(repeating: 0, count: SHA1.digestLength)
         var result = Array<UInt8>(repeating: 0, count: SHA1.digestLength)
         var pos = 0
         var pos = 0
-        for idx in 0 ..< self.accumulatedHash.count {
-            let h = self.accumulatedHash[idx].bigEndian
+        for idx in 0..<accumulatedHash.count {
+            let h = accumulatedHash[idx].bigEndian
             result[pos] = UInt8(h & 0xff)
             result[pos] = UInt8(h & 0xff)
             result[pos + 1] = UInt8((h >> 8) & 0xff)
             result[pos + 1] = UInt8((h >> 8) & 0xff)
             result[pos + 2] = UInt8((h >> 16) & 0xff)
             result[pos + 2] = UInt8((h >> 16) & 0xff)
@@ -144,7 +144,7 @@ extension SHA1: Updatable {
 
 
         // reset hash value for instance
         // reset hash value for instance
         if isLast {
         if isLast {
-            self.accumulatedHash = SHA1.hashInitialValue
+            accumulatedHash = SHA1.hashInitialValue
         }
         }
 
 
         return result
         return result

+ 75 - 71
Sources/CryptoSwift/SHA2.swift

@@ -33,7 +33,7 @@ public final class SHA2: DigestType {
         case sha224, sha256, sha384, sha512
         case sha224, sha256, sha384, sha512
 
 
         public var digestLength: Int {
         public var digestLength: Int {
-            return self.rawValue / 8
+            return rawValue / 8
         }
         }
 
 
         public var blockSize: Int {
         public var blockSize: Int {
@@ -60,7 +60,7 @@ public final class SHA2: DigestType {
         }
         }
 
 
         public init?(rawValue: RawValue) {
         public init?(rawValue: RawValue) {
-            switch (rawValue) {
+            switch rawValue {
             case 224:
             case 224:
                 self = .sha224
                 self = .sha224
                 break
                 break
@@ -92,7 +92,7 @@ public final class SHA2: DigestType {
         }
         }
 
 
         fileprivate var finalLength: Int {
         fileprivate var finalLength: Int {
-            switch (self) {
+            switch self {
             case .sha224:
             case .sha224:
                 return 7
                 return 7
             case .sha384:
             case .sha384:
@@ -107,45 +107,49 @@ public final class SHA2: DigestType {
         self.variant = variant
         self.variant = variant
         switch self.variant {
         switch self.variant {
         case .sha224, .sha256:
         case .sha224, .sha256:
-            self.accumulatedHash32 = variant.h.map { UInt32($0) } // FIXME: UInt64 for process64
-            self.blockSize = variant.blockSize
-            self.size = variant.rawValue
-            self.digestLength = variant.digestLength
-            self.k = [0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
-                      0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
-                      0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
-                      0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
-                      0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
-                      0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
-                      0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
-                      0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2]
+            accumulatedHash32 = variant.h.map { UInt32($0) } // FIXME: UInt64 for process64
+            blockSize = variant.blockSize
+            size = variant.rawValue
+            digestLength = variant.digestLength
+            k = [
+                0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
+                0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
+                0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
+                0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
+                0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
+                0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
+                0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
+                0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2,
+            ]
         case .sha384, .sha512:
         case .sha384, .sha512:
-            self.accumulatedHash64 = variant.h
-            self.blockSize = variant.blockSize
-            self.size = variant.rawValue
-            self.digestLength = variant.digestLength
-            self.k = [0x428a2f98d728ae22, 0x7137449123ef65cd, 0xb5c0fbcfec4d3b2f, 0xe9b5dba58189dbbc, 0x3956c25bf348b538,
-                      0x59f111f1b605d019, 0x923f82a4af194f9b, 0xab1c5ed5da6d8118, 0xd807aa98a3030242, 0x12835b0145706fbe,
-                      0x243185be4ee4b28c, 0x550c7dc3d5ffb4e2, 0x72be5d74f27b896f, 0x80deb1fe3b1696b1, 0x9bdc06a725c71235,
-                      0xc19bf174cf692694, 0xe49b69c19ef14ad2, 0xefbe4786384f25e3, 0x0fc19dc68b8cd5b5, 0x240ca1cc77ac9c65,
-                      0x2de92c6f592b0275, 0x4a7484aa6ea6e483, 0x5cb0a9dcbd41fbd4, 0x76f988da831153b5, 0x983e5152ee66dfab,
-                      0xa831c66d2db43210, 0xb00327c898fb213f, 0xbf597fc7beef0ee4, 0xc6e00bf33da88fc2, 0xd5a79147930aa725,
-                      0x06ca6351e003826f, 0x142929670a0e6e70, 0x27b70a8546d22ffc, 0x2e1b21385c26c926, 0x4d2c6dfc5ac42aed,
-                      0x53380d139d95b3df, 0x650a73548baf63de, 0x766a0abb3c77b2a8, 0x81c2c92e47edaee6, 0x92722c851482353b,
-                      0xa2bfe8a14cf10364, 0xa81a664bbc423001, 0xc24b8b70d0f89791, 0xc76c51a30654be30, 0xd192e819d6ef5218,
-                      0xd69906245565a910, 0xf40e35855771202a, 0x106aa07032bbd1b8, 0x19a4c116b8d2d0c8, 0x1e376c085141ab53,
-                      0x2748774cdf8eeb99, 0x34b0bcb5e19b48a8, 0x391c0cb3c5c95a63, 0x4ed8aa4ae3418acb, 0x5b9cca4f7763e373,
-                      0x682e6ff3d6b2b8a3, 0x748f82ee5defb2fc, 0x78a5636f43172f60, 0x84c87814a1f0ab72, 0x8cc702081a6439ec,
-                      0x90befffa23631e28, 0xa4506cebde82bde9, 0xbef9a3f7b2c67915, 0xc67178f2e372532b, 0xca273eceea26619c,
-                      0xd186b8c721c0c207, 0xeada7dd6cde0eb1e, 0xf57d4f7fee6ed178, 0x06f067aa72176fba, 0x0a637dc5a2c898a6,
-                      0x113f9804bef90dae, 0x1b710b35131c471b, 0x28db77f523047d84, 0x32caab7b40c72493, 0x3c9ebe0a15c9bebc,
-                      0x431d67c49c100d4c, 0x4cc5d4becb3e42b6, 0x597f299cfc657e2a, 0x5fcb6fab3ad6faec, 0x6c44198c4a475817]
+            accumulatedHash64 = variant.h
+            blockSize = variant.blockSize
+            size = variant.rawValue
+            digestLength = variant.digestLength
+            k = [
+                0x428a2f98d728ae22, 0x7137449123ef65cd, 0xb5c0fbcfec4d3b2f, 0xe9b5dba58189dbbc, 0x3956c25bf348b538,
+                0x59f111f1b605d019, 0x923f82a4af194f9b, 0xab1c5ed5da6d8118, 0xd807aa98a3030242, 0x12835b0145706fbe,
+                0x243185be4ee4b28c, 0x550c7dc3d5ffb4e2, 0x72be5d74f27b896f, 0x80deb1fe3b1696b1, 0x9bdc06a725c71235,
+                0xc19bf174cf692694, 0xe49b69c19ef14ad2, 0xefbe4786384f25e3, 0x0fc19dc68b8cd5b5, 0x240ca1cc77ac9c65,
+                0x2de92c6f592b0275, 0x4a7484aa6ea6e483, 0x5cb0a9dcbd41fbd4, 0x76f988da831153b5, 0x983e5152ee66dfab,
+                0xa831c66d2db43210, 0xb00327c898fb213f, 0xbf597fc7beef0ee4, 0xc6e00bf33da88fc2, 0xd5a79147930aa725,
+                0x06ca6351e003826f, 0x142929670a0e6e70, 0x27b70a8546d22ffc, 0x2e1b21385c26c926, 0x4d2c6dfc5ac42aed,
+                0x53380d139d95b3df, 0x650a73548baf63de, 0x766a0abb3c77b2a8, 0x81c2c92e47edaee6, 0x92722c851482353b,
+                0xa2bfe8a14cf10364, 0xa81a664bbc423001, 0xc24b8b70d0f89791, 0xc76c51a30654be30, 0xd192e819d6ef5218,
+                0xd69906245565a910, 0xf40e35855771202a, 0x106aa07032bbd1b8, 0x19a4c116b8d2d0c8, 0x1e376c085141ab53,
+                0x2748774cdf8eeb99, 0x34b0bcb5e19b48a8, 0x391c0cb3c5c95a63, 0x4ed8aa4ae3418acb, 0x5b9cca4f7763e373,
+                0x682e6ff3d6b2b8a3, 0x748f82ee5defb2fc, 0x78a5636f43172f60, 0x84c87814a1f0ab72, 0x8cc702081a6439ec,
+                0x90befffa23631e28, 0xa4506cebde82bde9, 0xbef9a3f7b2c67915, 0xc67178f2e372532b, 0xca273eceea26619c,
+                0xd186b8c721c0c207, 0xeada7dd6cde0eb1e, 0xf57d4f7fee6ed178, 0x06f067aa72176fba, 0x0a637dc5a2c898a6,
+                0x113f9804bef90dae, 0x1b710b35131c471b, 0x28db77f523047d84, 0x32caab7b40c72493, 0x3c9ebe0a15c9bebc,
+                0x431d67c49c100d4c, 0x4cc5d4becb3e42b6, 0x597f299cfc657e2a, 0x5fcb6fab3ad6faec, 0x6c44198c4a475817,
+            ]
         }
         }
     }
     }
 
 
     public func calculate(for bytes: Array<UInt8>) -> Array<UInt8> {
     public func calculate(for bytes: Array<UInt8>) -> Array<UInt8> {
         do {
         do {
-            return try self.update(withBytes: bytes.slice, isLast: true)
+            return try update(withBytes: bytes.slice, isLast: true)
         } catch {
         } catch {
             return []
             return []
         }
         }
@@ -154,10 +158,10 @@ public final class SHA2: DigestType {
     fileprivate func process64(block chunk: ArraySlice<UInt8>, currentHash hh: inout Array<UInt64>) {
     fileprivate func process64(block chunk: ArraySlice<UInt8>, currentHash hh: inout Array<UInt64>) {
         // break chunk into sixteen 64-bit words M[j], 0 ≤ j ≤ 15, big-endian
         // break chunk into sixteen 64-bit words M[j], 0 ≤ j ≤ 15, big-endian
         // Extend the sixteen 64-bit words into eighty 64-bit words:
         // Extend the sixteen 64-bit words into eighty 64-bit words:
-        var M = Array<UInt64>(repeating: 0, count: self.k.count)
-        for x in 0 ..< M.count {
-            switch (x) {
-            case 0 ... 15:
+        var M = Array<UInt64>(repeating: 0, count: k.count)
+        for x in 0..<M.count {
+            switch x {
+            case 0...15:
                 let start = chunk.startIndex.advanced(by: x * 8) // * MemoryLayout<UInt64>.size
                 let start = chunk.startIndex.advanced(by: x * 8) // * MemoryLayout<UInt64>.size
                 M[x] = UInt64(bytes: chunk, fromIndex: start)
                 M[x] = UInt64(bytes: chunk, fromIndex: start)
                 break
                 break
@@ -179,13 +183,13 @@ public final class SHA2: DigestType {
         var H = hh[7]
         var H = hh[7]
 
 
         // Main loop
         // Main loop
-        for j in 0 ..< self.k.count {
+        for j in 0..<k.count {
             let s0 = rotateRight(A, by: 28) ^ rotateRight(A, by: 34) ^ rotateRight(A, by: 39)
             let s0 = rotateRight(A, by: 28) ^ rotateRight(A, by: 34) ^ rotateRight(A, by: 39)
             let maj = (A & B) ^ (A & C) ^ (B & C)
             let maj = (A & B) ^ (A & C) ^ (B & C)
             let t2 = s0 &+ maj
             let t2 = s0 &+ maj
             let s1 = rotateRight(E, by: 14) ^ rotateRight(E, by: 18) ^ rotateRight(E, by: 41)
             let s1 = rotateRight(E, by: 14) ^ rotateRight(E, by: 18) ^ rotateRight(E, by: 41)
             let ch = (E & F) ^ ((~E) & G)
             let ch = (E & F) ^ ((~E) & G)
-            let t1 = H &+ s1 &+ ch &+ self.k[j] &+ UInt64(M[j])
+            let t1 = H &+ s1 &+ ch &+ k[j] &+ UInt64(M[j])
 
 
             H = G
             H = G
             G = F
             G = F
@@ -211,16 +215,16 @@ public final class SHA2: DigestType {
     fileprivate func process32(block chunk: ArraySlice<UInt8>, currentHash hh: inout Array<UInt32>) {
     fileprivate func process32(block chunk: ArraySlice<UInt8>, currentHash hh: inout Array<UInt32>) {
         // break chunk into sixteen 32-bit words M[j], 0 ≤ j ≤ 15, big-endian
         // 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:
         // Extend the sixteen 32-bit words into sixty-four 32-bit words:
-        let M = UnsafeMutablePointer<UInt32>.allocate(capacity: self.k.count)
-        M.initialize(to: 0, count: self.k.count)
+        let M = UnsafeMutablePointer<UInt32>.allocate(capacity: k.count)
+        M.initialize(to: 0, count: k.count)
         defer {
         defer {
             M.deinitialize(count: self.k.count)
             M.deinitialize(count: self.k.count)
             M.deallocate(capacity: self.k.count)
             M.deallocate(capacity: self.k.count)
         }
         }
-        
-        for x in 0 ..< self.k.count {
-            switch (x) {
-            case 0 ... 15:
+
+        for x in 0..<k.count {
+            switch x {
+            case 0...15:
                 let start = chunk.startIndex.advanced(by: x * 4) // * MemoryLayout<UInt32>.size
                 let start = chunk.startIndex.advanced(by: x * 4) // * MemoryLayout<UInt32>.size
                 M[x] = UInt32(bytes: chunk, fromIndex: start)
                 M[x] = UInt32(bytes: chunk, fromIndex: start)
                 break
                 break
@@ -242,13 +246,13 @@ public final class SHA2: DigestType {
         var H = hh[7]
         var H = hh[7]
 
 
         // Main loop
         // Main loop
-        for j in 0 ..< self.k.count {
+        for j in 0..<k.count {
             let s0 = rotateRight(A, by: 2) ^ rotateRight(A, by: 13) ^ rotateRight(A, by: 22)
             let s0 = rotateRight(A, by: 2) ^ rotateRight(A, by: 13) ^ rotateRight(A, by: 22)
             let maj = (A & B) ^ (A & C) ^ (B & C)
             let maj = (A & B) ^ (A & C) ^ (B & C)
             let t2 = s0 &+ maj
             let t2 = s0 &+ maj
             let s1 = rotateRight(E, by: 6) ^ rotateRight(E, by: 11) ^ rotateRight(E, by: 25)
             let s1 = rotateRight(E, by: 6) ^ rotateRight(E, by: 11) ^ rotateRight(E, by: 25)
             let ch = (E & F) ^ ((~E) & G)
             let ch = (E & F) ^ ((~E) & G)
-            let t1 = H &+ s1 &+ ch &+ UInt32(self.k[j]) &+ M[j]
+            let t1 = H &+ s1 &+ ch &+ UInt32(k[j]) &+ M[j]
 
 
             H = G
             H = G
             G = F
             G = F
@@ -274,41 +278,41 @@ public final class SHA2: DigestType {
 extension SHA2: Updatable {
 extension SHA2: Updatable {
 
 
     public func update(withBytes bytes: ArraySlice<UInt8>, isLast: Bool = false) throws -> Array<UInt8> {
     public func update(withBytes bytes: ArraySlice<UInt8>, isLast: Bool = false) throws -> Array<UInt8> {
-        self.accumulated += bytes
+        accumulated += bytes
 
 
         if isLast {
         if isLast {
-            let lengthInBits = (self.processedBytesTotalCount + self.accumulated.count) * 8
-            let lengthBytes = lengthInBits.bytes(totalBytes: self.blockSize / 8) // A 64-bit/128-bit representation of b. blockSize fit by accident.
+            let lengthInBits = (processedBytesTotalCount + accumulated.count) * 8
+            let lengthBytes = lengthInBits.bytes(totalBytes: blockSize / 8) // A 64-bit/128-bit representation of b. blockSize fit by accident.
 
 
             // Step 1. Append padding
             // Step 1. Append padding
-            bitPadding(to: &self.accumulated, blockSize: self.blockSize, allowance: self.blockSize / 8)
+            bitPadding(to: &accumulated, blockSize: blockSize, allowance: blockSize / 8)
 
 
             // Step 2. Append Length a 64-bit representation of lengthInBits
             // Step 2. Append Length a 64-bit representation of lengthInBits
-            self.accumulated += lengthBytes
+            accumulated += lengthBytes
         }
         }
 
 
         var processedBytes = 0
         var processedBytes = 0
-        for chunk in self.accumulated.batched(by: self.blockSize) {
-            if (isLast || (self.accumulated.count - processedBytes) >= self.blockSize) {
-                switch self.variant {
+        for chunk in accumulated.batched(by: blockSize) {
+            if isLast || (accumulated.count - processedBytes) >= blockSize {
+                switch variant {
                 case .sha224, .sha256:
                 case .sha224, .sha256:
-                    self.process32(block: chunk, currentHash: &self.accumulatedHash32)
+                    process32(block: chunk, currentHash: &accumulatedHash32)
                 case .sha384, .sha512:
                 case .sha384, .sha512:
-                    self.process64(block: chunk, currentHash: &self.accumulatedHash64)
+                    process64(block: chunk, currentHash: &accumulatedHash64)
                 }
                 }
                 processedBytes += chunk.count
                 processedBytes += chunk.count
             }
             }
         }
         }
-        self.accumulated.removeFirst(processedBytes)
-        self.processedBytesTotalCount += processedBytes
+        accumulated.removeFirst(processedBytes)
+        processedBytesTotalCount += processedBytes
 
 
         // output current hash
         // output current hash
-        var result = Array<UInt8>(repeating: 0, count: self.variant.digestLength)
-        switch self.variant {
+        var result = Array<UInt8>(repeating: 0, count: variant.digestLength)
+        switch variant {
         case .sha224, .sha256:
         case .sha224, .sha256:
             var pos = 0
             var pos = 0
-            for idx in 0 ..< self.accumulatedHash32.count where idx < self.variant.finalLength {
-                let h = self.accumulatedHash32[idx].bigEndian
+            for idx in 0..<accumulatedHash32.count where idx < variant.finalLength {
+                let h = accumulatedHash32[idx].bigEndian
                 result[pos] = UInt8(h & 0xff)
                 result[pos] = UInt8(h & 0xff)
                 result[pos + 1] = UInt8((h >> 8) & 0xff)
                 result[pos + 1] = UInt8((h >> 8) & 0xff)
                 result[pos + 2] = UInt8((h >> 16) & 0xff)
                 result[pos + 2] = UInt8((h >> 16) & 0xff)
@@ -317,8 +321,8 @@ extension SHA2: Updatable {
             }
             }
         case .sha384, .sha512:
         case .sha384, .sha512:
             var pos = 0
             var pos = 0
-            for idx in 0 ..< self.accumulatedHash64.count where idx < self.variant.finalLength {
-                let h = self.accumulatedHash64[idx].bigEndian
+            for idx in 0..<accumulatedHash64.count where idx < variant.finalLength {
+                let h = accumulatedHash64[idx].bigEndian
                 result[pos] = UInt8(h & 0xff)
                 result[pos] = UInt8(h & 0xff)
                 result[pos + 1] = UInt8((h >> 8) & 0xff)
                 result[pos + 1] = UInt8((h >> 8) & 0xff)
                 result[pos + 2] = UInt8((h >> 16) & 0xff)
                 result[pos + 2] = UInt8((h >> 16) & 0xff)
@@ -333,11 +337,11 @@ extension SHA2: Updatable {
 
 
         // reset hash value for instance
         // reset hash value for instance
         if isLast {
         if isLast {
-            switch self.variant {
+            switch variant {
             case .sha224, .sha256:
             case .sha224, .sha256:
-                self.accumulatedHash32 = variant.h.lazy.map { UInt32($0) } // FIXME: UInt64 for process64
+                accumulatedHash32 = variant.h.lazy.map { UInt32($0) } // FIXME: UInt64 for process64
             case .sha384, .sha512:
             case .sha384, .sha512:
-                self.accumulatedHash64 = variant.h
+                accumulatedHash64 = variant.h
             }
             }
         }
         }
 
 

+ 38 - 36
Sources/CryptoSwift/SHA3.swift

@@ -25,12 +25,14 @@
 #endif
 #endif
 
 
 public final class SHA3: DigestType {
 public final class SHA3: DigestType {
-    let round_constants: Array<UInt64> = [0x0000000000000001, 0x0000000000008082, 0x800000000000808A, 0x8000000080008000,
-                                          0x000000000000808B, 0x0000000080000001, 0x8000000080008081, 0x8000000000008009,
-                                          0x000000000000008A, 0x0000000000000088, 0x0000000080008009, 0x000000008000000A,
-                                          0x000000008000808B, 0x800000000000008B, 0x8000000000008089, 0x8000000000008003,
-                                          0x8000000000008002, 0x8000000000000080, 0x000000000000800A, 0x800000008000000A,
-                                          0x8000000080008081, 0x8000000000008080, 0x0000000080000001, 0x8000000080008008]
+    let round_constants: Array<UInt64> = [
+        0x0000000000000001, 0x0000000000008082, 0x800000000000808a, 0x8000000080008000,
+        0x000000000000808b, 0x0000000080000001, 0x8000000080008081, 0x8000000000008009,
+        0x000000000000008a, 0x0000000000000088, 0x0000000080008009, 0x000000008000000a,
+        0x000000008000808b, 0x800000000000008b, 0x8000000000008089, 0x8000000000008003,
+        0x8000000000008002, 0x8000000000000080, 0x000000000000800a, 0x800000008000000a,
+        0x8000000080008081, 0x8000000000008080, 0x0000000080000001, 0x8000000080008008,
+    ]
 
 
     public let blockSize: Int
     public let blockSize: Int
     public let digestLength: Int
     public let digestLength: Int
@@ -43,11 +45,11 @@ public final class SHA3: DigestType {
         case sha224, sha256, sha384, sha512
         case sha224, sha256, sha384, sha512
 
 
         var digestLength: Int {
         var digestLength: Int {
-            return 100 - (self.blockSize / 2)
+            return 100 - (blockSize / 2)
         }
         }
 
 
         var blockSize: Int {
         var blockSize: Int {
-            return (1600 - self.rawValue * 2) / 8
+            return (1600 - rawValue * 2) / 8
         }
         }
 
 
         public typealias RawValue = Int
         public typealias RawValue = Int
@@ -65,7 +67,7 @@ public final class SHA3: DigestType {
         }
         }
 
 
         public init?(rawValue: RawValue) {
         public init?(rawValue: RawValue) {
-            switch (rawValue) {
+            switch rawValue {
             case 224:
             case 224:
                 self = .sha224
                 self = .sha224
                 break
                 break
@@ -85,14 +87,14 @@ public final class SHA3: DigestType {
     }
     }
 
 
     public init(variant: SHA3.Variant) {
     public init(variant: SHA3.Variant) {
-        self.blockSize = variant.blockSize
-        self.digestLength = variant.digestLength
-        self.accumulatedHash = Array<UInt64>(repeating: 0, count: self.digestLength)
+        blockSize = variant.blockSize
+        digestLength = variant.digestLength
+        accumulatedHash = Array<UInt64>(repeating: 0, count: digestLength)
     }
     }
 
 
     public func calculate(for bytes: Array<UInt8>) -> Array<UInt8> {
     public func calculate(for bytes: Array<UInt8>) -> Array<UInt8> {
         do {
         do {
-            return try self.update(withBytes: bytes.slice, isLast: true)
+            return try update(withBytes: bytes.slice, isLast: true)
         } catch {
         } catch {
             return []
             return []
         }
         }
@@ -118,7 +120,7 @@ public final class SHA3: DigestType {
             d.deallocate(capacity: 5)
             d.deallocate(capacity: 5)
         }
         }
 
 
-        for i in 0 ..< 5 {
+        for i in 0..<5 {
             c[i] = a[i] ^ a[i &+ 5] ^ a[i &+ 10] ^ a[i &+ 15] ^ a[i &+ 20]
             c[i] = a[i] ^ a[i &+ 5] ^ a[i &+ 10] ^ a[i &+ 15] ^ a[i &+ 20]
         }
         }
 
 
@@ -128,7 +130,7 @@ public final class SHA3: DigestType {
         d[3] = rotateLeft(c[4], by: 1) ^ c[2]
         d[3] = rotateLeft(c[4], by: 1) ^ c[2]
         d[4] = rotateLeft(c[0], by: 1) ^ c[3]
         d[4] = rotateLeft(c[0], by: 1) ^ c[3]
 
 
-        for i in 0 ..< 5 {
+        for i in 0..<5 {
             a[i] ^= d[i]
             a[i] ^= d[i]
             a[i &+ 5] ^= d[i]
             a[i &+ 5] ^= d[i]
             a[i &+ 10] ^= d[i]
             a[i &+ 10] ^= d[i]
@@ -195,20 +197,20 @@ public final class SHA3: DigestType {
         hh[6] ^= chunk[6].littleEndian
         hh[6] ^= chunk[6].littleEndian
         hh[7] ^= chunk[7].littleEndian
         hh[7] ^= chunk[7].littleEndian
         hh[8] ^= chunk[8].littleEndian
         hh[8] ^= chunk[8].littleEndian
-        if self.blockSize > 72 { // 72 / 8, sha-512
+        if blockSize > 72 { // 72 / 8, sha-512
             hh[9] ^= chunk[9].littleEndian
             hh[9] ^= chunk[9].littleEndian
             hh[10] ^= chunk[10].littleEndian
             hh[10] ^= chunk[10].littleEndian
             hh[11] ^= chunk[11].littleEndian
             hh[11] ^= chunk[11].littleEndian
             hh[12] ^= chunk[12].littleEndian
             hh[12] ^= chunk[12].littleEndian
-            if self.blockSize > 104 { // 104 / 8, sha-384
+            if blockSize > 104 { // 104 / 8, sha-384
                 hh[13] ^= chunk[13].littleEndian
                 hh[13] ^= chunk[13].littleEndian
                 hh[14] ^= chunk[14].littleEndian
                 hh[14] ^= chunk[14].littleEndian
                 hh[15] ^= chunk[15].littleEndian
                 hh[15] ^= chunk[15].littleEndian
                 hh[16] ^= chunk[16].littleEndian
                 hh[16] ^= chunk[16].littleEndian
-                if self.blockSize > 136 { // 136 / 8, sha-256
+                if blockSize > 136 { // 136 / 8, sha-256
                     hh[17] ^= chunk[17].littleEndian
                     hh[17] ^= chunk[17].littleEndian
                     // FULL_SHA3_FAMILY_SUPPORT
                     // FULL_SHA3_FAMILY_SUPPORT
-                    if self.blockSize > 144 { // 144 / 8, sha-224
+                    if blockSize > 144 { // 144 / 8, sha-224
                         hh[18] ^= chunk[18].littleEndian
                         hh[18] ^= chunk[18].littleEndian
                         hh[19] ^= chunk[19].littleEndian
                         hh[19] ^= chunk[19].littleEndian
                         hh[20] ^= chunk[20].littleEndian
                         hh[20] ^= chunk[20].littleEndian
@@ -222,7 +224,7 @@ public final class SHA3: DigestType {
         }
         }
 
 
         // Keccak-f
         // Keccak-f
-        for round in 0 ..< 24 {
+        for round in 0..<24 {
             θ(&hh)
             θ(&hh)
 
 
             hh[1] = rotateLeft(hh[1], by: 1)
             hh[1] = rotateLeft(hh[1], by: 1)
@@ -260,41 +262,41 @@ public final class SHA3: DigestType {
 extension SHA3: Updatable {
 extension SHA3: Updatable {
 
 
     public func update(withBytes bytes: ArraySlice<UInt8>, isLast: Bool = false) throws -> Array<UInt8> {
     public func update(withBytes bytes: ArraySlice<UInt8>, isLast: Bool = false) throws -> Array<UInt8> {
-        self.accumulated += bytes
+        accumulated += bytes
 
 
         if isLast {
         if isLast {
             // Add padding
             // Add padding
-            let markByteIndex = self.processedBytesTotalCount &+ self.accumulated.count
-            if self.accumulated.count == 0 || self.accumulated.count % self.blockSize != 0 {
-                let r = self.blockSize * 8
-                let q = (r / 8) - (self.accumulated.count % (r / 8))
-                self.accumulated += Array<UInt8>(repeating: 0, count: q)
+            let markByteIndex = processedBytesTotalCount &+ accumulated.count
+            if accumulated.count == 0 || accumulated.count % blockSize != 0 {
+                let r = blockSize * 8
+                let q = (r / 8) - (accumulated.count % (r / 8))
+                accumulated += Array<UInt8>(repeating: 0, count: q)
             }
             }
 
 
-            self.accumulated[markByteIndex] |= 0x06 // 0x1F for SHAKE
-            self.accumulated[self.accumulated.count - 1] |= 0x80
+            accumulated[markByteIndex] |= 0x06 // 0x1F for SHAKE
+            accumulated[self.accumulated.count - 1] |= 0x80
         }
         }
 
 
         var processedBytes = 0
         var processedBytes = 0
-        for chunk in self.accumulated.batched(by: self.blockSize) {
-            if (isLast || (self.accumulated.count - processedBytes) >= self.blockSize) {
-                self.process(block: chunk.toUInt64Array().slice, currentHash: &self.accumulatedHash)
+        for chunk in accumulated.batched(by: blockSize) {
+            if isLast || (accumulated.count - processedBytes) >= blockSize {
+                process(block: chunk.toUInt64Array().slice, currentHash: &accumulatedHash)
                 processedBytes += chunk.count
                 processedBytes += chunk.count
             }
             }
         }
         }
-        self.accumulated.removeFirst(processedBytes)
-        self.processedBytesTotalCount += processedBytes
+        accumulated.removeFirst(processedBytes)
+        processedBytesTotalCount += processedBytes
 
 
         // TODO: verify performance, reduce vs for..in
         // TODO: verify performance, reduce vs for..in
-        let result = self.accumulatedHash.reduce(Array<UInt8>()) { (result, value) -> Array<UInt8> in
+        let result = accumulatedHash.reduce(Array<UInt8>()) { (result, value) -> Array<UInt8> in
             return result + value.bigEndian.bytes()
             return result + value.bigEndian.bytes()
         }
         }
 
 
         // reset hash value for instance
         // reset hash value for instance
         if isLast {
         if isLast {
-            self.accumulatedHash = Array<UInt64>(repeating: 0, count: self.digestLength)
+            accumulatedHash = Array<UInt64>(repeating: 0, count: digestLength)
         }
         }
 
 
-        return Array(result[0 ..< self.digestLength])
+        return Array(result[0..<self.digestLength])
     }
     }
 }
 }

+ 7 - 7
Sources/CryptoSwift/SecureBytes.swift

@@ -28,7 +28,7 @@ final class SecureBytes {
 
 
     init(bytes: Array<UInt8>) {
     init(bytes: Array<UInt8>) {
         self.bytes = bytes
         self.bytes = bytes
-        self.count = bytes.count
+        count = bytes.count
         self.bytes.withUnsafeBufferPointer { (pointer) -> Void in
         self.bytes.withUnsafeBufferPointer { (pointer) -> Void in
             mlock(pointer.baseAddress, pointer.count)
             mlock(pointer.baseAddress, pointer.count)
         }
         }
@@ -45,27 +45,27 @@ extension SecureBytes: Collection {
     typealias Index = Int
     typealias Index = Int
 
 
     var endIndex: Int {
     var endIndex: Int {
-        return self.bytes.endIndex
+        return bytes.endIndex
     }
     }
 
 
     var startIndex: Int {
     var startIndex: Int {
-        return self.bytes.startIndex
+        return bytes.startIndex
     }
     }
 
 
     subscript(position: Index) -> UInt8 {
     subscript(position: Index) -> UInt8 {
-        return self.bytes[position]
+        return bytes[position]
     }
     }
 
 
     subscript(bounds: Range<Index>) -> ArraySlice<UInt8> {
     subscript(bounds: Range<Index>) -> ArraySlice<UInt8> {
-        return self.bytes[bounds]
+        return bytes[bounds]
     }
     }
 
 
     func formIndex(after i: inout Int) {
     func formIndex(after i: inout Int) {
-        self.bytes.formIndex(after: &i)
+        bytes.formIndex(after: &i)
     }
     }
 
 
     func index(after i: Int) -> Int {
     func index(after i: Int) -> Int {
-        return self.bytes.index(after: i)
+        return bytes.index(after: i)
     }
     }
 }
 }
 
 

+ 12 - 13
Sources/CryptoSwift/String+Extension.swift

@@ -18,51 +18,51 @@
 extension String {
 extension String {
 
 
     public func md5() -> String {
     public func md5() -> String {
-        return self.utf8.lazy.map({ $0 as UInt8 }).md5().toHexString()
+        return utf8.lazy.map({ $0 as UInt8 }).md5().toHexString()
     }
     }
 
 
     public func sha1() -> String {
     public func sha1() -> String {
-        return self.utf8.lazy.map({ $0 as UInt8 }).sha1().toHexString()
+        return utf8.lazy.map({ $0 as UInt8 }).sha1().toHexString()
     }
     }
 
 
     public func sha224() -> String {
     public func sha224() -> String {
-        return self.utf8.lazy.map({ $0 as UInt8 }).sha224().toHexString()
+        return utf8.lazy.map({ $0 as UInt8 }).sha224().toHexString()
     }
     }
 
 
     public func sha256() -> String {
     public func sha256() -> String {
-        return self.utf8.lazy.map({ $0 as UInt8 }).sha256().toHexString()
+        return utf8.lazy.map({ $0 as UInt8 }).sha256().toHexString()
     }
     }
 
 
     public func sha384() -> String {
     public func sha384() -> String {
-        return self.utf8.lazy.map({ $0 as UInt8 }).sha384().toHexString()
+        return utf8.lazy.map({ $0 as UInt8 }).sha384().toHexString()
     }
     }
 
 
     public func sha512() -> String {
     public func sha512() -> String {
-        return self.utf8.lazy.map({ $0 as UInt8 }).sha512().toHexString()
+        return utf8.lazy.map({ $0 as UInt8 }).sha512().toHexString()
     }
     }
 
 
     public func sha3(_ variant: SHA3.Variant) -> String {
     public func sha3(_ variant: SHA3.Variant) -> String {
-        return self.utf8.lazy.map({ $0 as UInt8 }).sha3(variant).toHexString()
+        return utf8.lazy.map({ $0 as UInt8 }).sha3(variant).toHexString()
     }
     }
 
 
     public func crc32(seed: UInt32? = nil, reflect: Bool = true) -> String {
     public func crc32(seed: UInt32? = nil, reflect: Bool = true) -> String {
-        return self.utf8.lazy.map({ $0 as UInt8 }).crc32(seed: seed, reflect: reflect).bytes().toHexString()
+        return utf8.lazy.map({ $0 as UInt8 }).crc32(seed: seed, reflect: reflect).bytes().toHexString()
     }
     }
 
 
     public func crc16(seed: UInt16? = nil) -> String {
     public func crc16(seed: UInt16? = nil) -> String {
-        return self.utf8.lazy.map({ $0 as UInt8 }).crc16(seed: seed).bytes().toHexString()
+        return utf8.lazy.map({ $0 as UInt8 }).crc16(seed: seed).bytes().toHexString()
     }
     }
 
 
     /// - parameter cipher: Instance of `Cipher`
     /// - parameter cipher: Instance of `Cipher`
     /// - returns: hex string of bytes
     /// - returns: hex string of bytes
     public func encrypt(cipher: Cipher) throws -> String {
     public func encrypt(cipher: Cipher) throws -> String {
-        return try Array(self.utf8).encrypt(cipher: cipher).toHexString()
+        return try Array(utf8).encrypt(cipher: cipher).toHexString()
     }
     }
 
 
     /// - parameter cipher: Instance of `Cipher`
     /// - parameter cipher: Instance of `Cipher`
     /// - returns: base64 encoded string of encrypted bytes
     /// - returns: base64 encoded string of encrypted bytes
     public func encryptToBase64(cipher: Cipher) throws -> String? {
     public func encryptToBase64(cipher: Cipher) throws -> String? {
-        return try Array(self.utf8).encrypt(cipher: cipher).toBase64()
+        return try Array(utf8).encrypt(cipher: cipher).toBase64()
     }
     }
 
 
     // decrypt() does not make sense for String
     // decrypt() does not make sense for String
@@ -70,7 +70,6 @@ extension String {
     /// - parameter authenticator: Instance of `Authenticator`
     /// - parameter authenticator: Instance of `Authenticator`
     /// - returns: hex string of string
     /// - returns: hex string of string
     public func authenticate<A: Authenticator>(with authenticator: A) throws -> String {
     public func authenticate<A: Authenticator>(with authenticator: A) throws -> String {
-        return try Array(self.utf8).authenticate(with: authenticator).toHexString()
+        return try Array(utf8).authenticate(with: authenticator).toHexString()
     }
     }
-    
 }
 }

+ 7 - 7
Sources/CryptoSwift/UInt8+Extension.swift

@@ -28,17 +28,17 @@ extension UInt8 {
 
 
     /** cast because UInt8(<UInt32>) because std initializer crash if value is > byte */
     /** cast because UInt8(<UInt32>) because std initializer crash if value is > byte */
     static func with(value: UInt64) -> UInt8 {
     static func with(value: UInt64) -> UInt8 {
-        let tmp = value & 0xFF
+        let tmp = value & 0xff
         return UInt8(tmp)
         return UInt8(tmp)
     }
     }
 
 
     static func with(value: UInt32) -> UInt8 {
     static func with(value: UInt32) -> UInt8 {
-        let tmp = value & 0xFF
+        let tmp = value & 0xff
         return UInt8(tmp)
         return UInt8(tmp)
     }
     }
 
 
     static func with(value: UInt16) -> UInt8 {
     static func with(value: UInt16) -> UInt8 {
-        let tmp = value & 0xFF
+        let tmp = value & 0xff
         return UInt8(tmp)
         return UInt8(tmp)
     }
     }
 }
 }
@@ -56,11 +56,11 @@ extension UInt8 {
 
 
         var bitsArray = [Bit](repeating: Bit.zero, count: totalBitsCount)
         var bitsArray = [Bit](repeating: Bit.zero, count: totalBitsCount)
 
 
-        for j in 0 ..< totalBitsCount {
+        for j in 0..<totalBitsCount {
             let bitVal: UInt8 = 1 << UInt8(totalBitsCount - 1 - j)
             let bitVal: UInt8 = 1 << UInt8(totalBitsCount - 1 - j)
             let check = self & bitVal
             let check = self & bitVal
 
 
-            if (check != 0) {
+            if check != 0 {
                 bitsArray[j] = Bit.one
                 bitsArray[j] = Bit.one
             }
             }
         }
         }
@@ -69,10 +69,10 @@ extension UInt8 {
 
 
     public func bits() -> String {
     public func bits() -> String {
         var s = String()
         var s = String()
-        let arr: [Bit] = self.bits()
+        let arr: [Bit] = bits()
         for idx in arr.indices {
         for idx in arr.indices {
             s += (arr[idx] == Bit.one ? "1" : "0")
             s += (arr[idx] == Bit.one ? "1" : "0")
-            if (idx.advanced(by: 1) % 8 == 0) { s += " " }
+            if idx.advanced(by: 1) % 8 == 0 { s += " " }
         }
         }
         return s
         return s
     }
     }

+ 16 - 17
Sources/CryptoSwift/Updatable.swift

@@ -47,49 +47,48 @@ public protocol Updatable {
 
 
 extension Updatable {
 extension Updatable {
 
 
-    mutating public func update(withBytes bytes: ArraySlice<UInt8>, isLast: Bool = false, output: (_ bytes: Array<UInt8>) -> Void) throws {
-        let processed = try self.update(withBytes: bytes, isLast: isLast)
-        if (!processed.isEmpty) {
+    public mutating func update(withBytes bytes: ArraySlice<UInt8>, isLast: Bool = false, output: (_ bytes: Array<UInt8>) -> Void) throws {
+        let processed = try update(withBytes: bytes, isLast: isLast)
+        if !processed.isEmpty {
             output(processed)
             output(processed)
         }
         }
     }
     }
 
 
-    mutating public func finish(withBytes bytes: ArraySlice<UInt8>) throws -> Array<UInt8> {
-        return try self.update(withBytes: bytes, isLast: true)
+    public mutating func finish(withBytes bytes: ArraySlice<UInt8>) throws -> Array<UInt8> {
+        return try update(withBytes: bytes, isLast: true)
     }
     }
 
 
-    mutating public func finish() throws -> Array<UInt8> {
-        return try self.update(withBytes: [], isLast: true)
+    public mutating func finish() throws -> Array<UInt8> {
+        return try update(withBytes: [], isLast: true)
     }
     }
 
 
-    mutating public func finish(withBytes bytes: ArraySlice<UInt8>, output: (_ bytes: Array<UInt8>) -> Void) throws {
-        let processed = try self.update(withBytes: bytes, isLast: true)
-        if (!processed.isEmpty) {
+    public mutating func finish(withBytes bytes: ArraySlice<UInt8>, output: (_ bytes: Array<UInt8>) -> Void) throws {
+        let processed = try update(withBytes: bytes, isLast: true)
+        if !processed.isEmpty {
             output(processed)
             output(processed)
         }
         }
     }
     }
 
 
-    mutating public func finish(output: (Array<UInt8>) -> Void) throws {
-        try self.finish(withBytes: [], output: output)
+    public mutating func finish(output: (Array<UInt8>) -> Void) throws {
+        try finish(withBytes: [], output: output)
     }
     }
 }
 }
 
 
 extension Updatable {
 extension Updatable {
 
 
-    mutating public func update(withBytes bytes: Array<UInt8>, isLast: Bool = false) throws -> Array<UInt8> {
+    public mutating func update(withBytes bytes: Array<UInt8>, isLast: Bool = false) throws -> Array<UInt8> {
         return try update(withBytes: bytes.slice, isLast: isLast)
         return try update(withBytes: bytes.slice, isLast: isLast)
     }
     }
 
 
-    mutating public func update(withBytes bytes: Array<UInt8>, isLast: Bool = false, output: (_ bytes: Array<UInt8>) -> Void) throws {
+    public mutating func update(withBytes bytes: Array<UInt8>, isLast: Bool = false, output: (_ bytes: Array<UInt8>) -> Void) throws {
         return try update(withBytes: bytes.slice, isLast: isLast, output: output)
         return try update(withBytes: bytes.slice, isLast: isLast, output: output)
     }
     }
 
 
-    mutating public func finish(withBytes bytes: Array<UInt8>) throws -> Array<UInt8> {
+    public mutating func finish(withBytes bytes: Array<UInt8>) throws -> Array<UInt8> {
         return try finish(withBytes: bytes.slice)
         return try finish(withBytes: bytes.slice)
     }
     }
 
 
-    mutating public func finish(withBytes bytes: Array<UInt8>, output: (_ bytes: Array<UInt8>) -> Void) throws {
+    public mutating func finish(withBytes bytes: Array<UInt8>, output: (_ bytes: Array<UInt8>) -> Void) throws {
         return try finish(withBytes: bytes.slice, output: output)
         return try finish(withBytes: bytes.slice, output: output)
     }
     }
-
 }
 }

+ 7 - 8
Sources/CryptoSwift/Utils.swift

@@ -15,15 +15,15 @@
 //
 //
 
 
 func rotateLeft(_ value: UInt8, by: UInt8) -> UInt8 {
 func rotateLeft(_ value: UInt8, by: UInt8) -> UInt8 {
-    return ((value << by) & 0xFF) | (value >> (8 - by))
+    return ((value << by) & 0xff) | (value >> (8 - by))
 }
 }
 
 
 func rotateLeft(_ value: UInt16, by: UInt16) -> UInt16 {
 func rotateLeft(_ value: UInt16, by: UInt16) -> UInt16 {
-    return ((value << by) & 0xFFFF) | (value >> (16 - by))
+    return ((value << by) & 0xffff) | (value >> (16 - by))
 }
 }
 
 
 func rotateLeft(_ value: UInt32, by: UInt32) -> UInt32 {
 func rotateLeft(_ value: UInt32, by: UInt32) -> UInt32 {
-    return ((value << by) & 0xFFFFFFFF) | (value >> (32 - by))
+    return ((value << by) & 0xffffffff) | (value >> (32 - by))
 }
 }
 
 
 func rotateLeft(_ value: UInt64, by: UInt64) -> UInt64 {
 func rotateLeft(_ value: UInt64, by: UInt64) -> UInt64 {
@@ -44,9 +44,9 @@ func rotateRight(_ value: UInt64, by: UInt64) -> UInt64 {
 
 
 func reversed(_ uint8: UInt8) -> UInt8 {
 func reversed(_ uint8: UInt8) -> UInt8 {
     var v = uint8
     var v = uint8
-    v = (v & 0xF0) >> 4 | (v & 0x0F) << 4
-    v = (v & 0xCC) >> 2 | (v & 0x33) << 2
-    v = (v & 0xAA) >> 1 | (v & 0x55) << 1
+    v = (v & 0xf0) >> 4 | (v & 0x0f) << 4
+    v = (v & 0xcc) >> 2 | (v & 0x33) << 2
+    v = (v & 0xaa) >> 1 | (v & 0x55) << 1
     return v
     return v
 }
 }
 
 
@@ -74,13 +74,12 @@ func xor(_ a: ArraySlice<UInt8>, _ b: Array<UInt8>) -> Array<UInt8> {
 
 
 func xor(_ a: ArraySlice<UInt8>, _ b: ArraySlice<UInt8>) -> Array<UInt8> {
 func xor(_ a: ArraySlice<UInt8>, _ b: ArraySlice<UInt8>) -> Array<UInt8> {
     var xored = Array<UInt8>(repeating: 0, count: min(a.count, b.count))
     var xored = Array<UInt8>(repeating: 0, count: min(a.count, b.count))
-    for i in 0 ..< xored.count {
+    for i in 0..<xored.count {
         xored[xored.startIndex.advanced(by: i)] = a[a.startIndex.advanced(by: i)] ^ b[b.startIndex.advanced(by: i)]
         xored[xored.startIndex.advanced(by: i)] = a[a.startIndex.advanced(by: i)] ^ b[b.startIndex.advanced(by: i)]
     }
     }
     return xored
     return xored
 }
 }
 
 
-
 /**
 /**
  ISO/IEC 9797-1 Padding method 2.
  ISO/IEC 9797-1 Padding method 2.
  Add a single bit with value 1 to the end of the data.
  Add a single bit with value 1 to the end of the data.

+ 2 - 2
Sources/CryptoSwift/ZeroPadding.swift

@@ -29,10 +29,10 @@ public struct ZeroPadding: Padding {
         return bytes
         return bytes
     }
     }
 
 
-    public func remove(from bytes: Array<UInt8>, blockSize: Int?) -> Array<UInt8> {
+    public func remove(from bytes: Array<UInt8>, blockSize _: Int?) -> Array<UInt8> {
         for (idx, value) in bytes.reversed().enumerated() {
         for (idx, value) in bytes.reversed().enumerated() {
             if value != 0 {
             if value != 0 {
-                return Array(bytes[0 ..< bytes.count - idx])
+                return Array(bytes[0..<bytes.count - idx])
             }
             }
         }
         }
         return bytes
         return bytes

+ 37 - 37
Tests/CryptoSwiftTests/AESTests.swift

@@ -53,7 +53,7 @@ final class AESTests: XCTestCase {
 
 
     func testAESEncryptCBCNoPadding() {
     func testAESEncryptCBCNoPadding() {
         let key: Array<UInt8> = [0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c]
         let key: Array<UInt8> = [0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c]
-        let iv: Array<UInt8> = [0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F]
+        let iv: Array<UInt8> = [0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f]
         let plaintext: Array<UInt8> = [0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a]
         let plaintext: Array<UInt8> = [0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a]
         let expected: Array<UInt8> = [0x76, 0x49, 0xab, 0xac, 0x81, 0x19, 0xb2, 0x46, 0xce, 0xe9, 0x8e, 0x9b, 0x12, 0xe9, 0x19, 0x7d]
         let expected: Array<UInt8> = [0x76, 0x49, 0xab, 0xac, 0x81, 0x19, 0xb2, 0x46, 0xce, 0xe9, 0x8e, 0x9b, 0x12, 0xe9, 0x19, 0x7d]
 
 
@@ -66,7 +66,7 @@ final class AESTests: XCTestCase {
 
 
     func testAESEncryptCBCWithPadding() {
     func testAESEncryptCBCWithPadding() {
         let key: Array<UInt8> = [0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c]
         let key: Array<UInt8> = [0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c]
-        let iv: Array<UInt8> = [0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F]
+        let iv: Array<UInt8> = [0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f]
         let plaintext: Array<UInt8> = [0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a]
         let plaintext: Array<UInt8> = [0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a]
         let expected: Array<UInt8> = [0x76, 0x49, 0xab, 0xac, 0x81, 0x19, 0xb2, 0x46, 0xce, 0xe9, 0x8e, 0x9b, 0x12, 0xe9, 0x19, 0x7d, 0x89, 0x64, 0xe0, 0xb1, 0x49, 0xc1, 0x0b, 0x7b, 0x68, 0x2e, 0x6e, 0x39, 0xaa, 0xeb, 0x73, 0x1c]
         let expected: Array<UInt8> = [0x76, 0x49, 0xab, 0xac, 0x81, 0x19, 0xb2, 0x46, 0xce, 0xe9, 0x8e, 0x9b, 0x12, 0xe9, 0x19, 0x7d, 0x89, 0x64, 0xe0, 0xb1, 0x49, 0xc1, 0x0b, 0x7b, 0x68, 0x2e, 0x6e, 0x39, 0xaa, 0xeb, 0x73, 0x1c]
 
 
@@ -79,16 +79,16 @@ final class AESTests: XCTestCase {
 
 
     func testAESEncryptCBCWithPaddingPartial() {
     func testAESEncryptCBCWithPaddingPartial() {
         let key: Array<UInt8> = [0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c]
         let key: Array<UInt8> = [0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c]
-        let iv: Array<UInt8> = [0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F]
+        let iv: Array<UInt8> = [0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f]
         let plaintext: Array<UInt8> = [0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a, 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a]
         let plaintext: Array<UInt8> = [0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a, 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a]
 
 
         let aes = try! AES(key: key, iv: iv, blockMode: .CBC, padding: PKCS7())
         let aes = try! AES(key: key, iv: iv, blockMode: .CBC, padding: PKCS7())
 
 
         var ciphertext = Array<UInt8>()
         var ciphertext = Array<UInt8>()
         var encryptor = aes.makeEncryptor()
         var encryptor = aes.makeEncryptor()
-        ciphertext += try! encryptor.update(withBytes: plaintext[0 ..< 8])
-        ciphertext += try! encryptor.update(withBytes: plaintext[8 ..< 16])
-        ciphertext += try! encryptor.update(withBytes: plaintext[16 ..< 32])
+        ciphertext += try! encryptor.update(withBytes: plaintext[0..<8])
+        ciphertext += try! encryptor.update(withBytes: plaintext[8..<16])
+        ciphertext += try! encryptor.update(withBytes: plaintext[16..<32])
         ciphertext += try! encryptor.finish()
         ciphertext += try! encryptor.finish()
         XCTAssertEqual(try! aes.encrypt(plaintext), ciphertext, "encryption failed")
         XCTAssertEqual(try! aes.encrypt(plaintext), ciphertext, "encryption failed")
     }
     }
@@ -110,22 +110,22 @@ final class AESTests: XCTestCase {
 
 
     func testAESDecryptCBCWithPaddingPartial() {
     func testAESDecryptCBCWithPaddingPartial() {
         let key: Array<UInt8> = [0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c]
         let key: Array<UInt8> = [0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c]
-        let iv: Array<UInt8> = [0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F]
+        let iv: Array<UInt8> = [0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f]
         let ciphertext: Array<UInt8> = [118, 73, 171, 172, 129, 25, 178, 70, 206, 233, 142, 155, 18, 233, 25, 125, 76, 187, 200, 88, 117, 107, 53, 129, 37, 82, 158, 150, 152, 163, 143, 68, 169, 105, 137, 234, 93, 98, 239, 215, 41, 45, 51, 254, 138, 92, 251, 17]
         let ciphertext: Array<UInt8> = [118, 73, 171, 172, 129, 25, 178, 70, 206, 233, 142, 155, 18, 233, 25, 125, 76, 187, 200, 88, 117, 107, 53, 129, 37, 82, 158, 150, 152, 163, 143, 68, 169, 105, 137, 234, 93, 98, 239, 215, 41, 45, 51, 254, 138, 92, 251, 17]
 
 
         let aes = try! AES(key: key, iv: iv, blockMode: .CBC, padding: PKCS7())
         let aes = try! AES(key: key, iv: iv, blockMode: .CBC, padding: PKCS7())
         var plaintext = Array<UInt8>()
         var plaintext = Array<UInt8>()
         var decryptor = aes.makeDecryptor()
         var decryptor = aes.makeDecryptor()
-        plaintext += try! decryptor.update(withBytes: ciphertext[0 ..< 8])
-        plaintext += try! decryptor.update(withBytes: ciphertext[8 ..< 16])
-        plaintext += try! decryptor.update(withBytes: ciphertext[16 ..< 32])
+        plaintext += try! decryptor.update(withBytes: ciphertext[0..<8])
+        plaintext += try! decryptor.update(withBytes: ciphertext[8..<16])
+        plaintext += try! decryptor.update(withBytes: ciphertext[16..<32])
         plaintext += try! decryptor.finish()
         plaintext += try! decryptor.finish()
         XCTAssertEqual(try! aes.decrypt(ciphertext), plaintext, "encryption failed")
         XCTAssertEqual(try! aes.decrypt(ciphertext), plaintext, "encryption failed")
     }
     }
 
 
     func testAESEncryptCFB() {
     func testAESEncryptCFB() {
         let key: Array<UInt8> = [0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c]
         let key: Array<UInt8> = [0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c]
-        let iv: Array<UInt8> = [0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F]
+        let iv: Array<UInt8> = [0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f]
         let plaintext: Array<UInt8> = [0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a]
         let plaintext: Array<UInt8> = [0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a]
         let expected: Array<UInt8> = [0x3b, 0x3f, 0xd9, 0x2e, 0xb7, 0x2d, 0xad, 0x20, 0x33, 0x34, 0x49, 0xf8, 0xe8, 0x3c, 0xfb, 0x4a]
         let expected: Array<UInt8> = [0x3b, 0x3f, 0xd9, 0x2e, 0xb7, 0x2d, 0xad, 0x20, 0x33, 0x34, 0x49, 0xf8, 0xe8, 0x3c, 0xfb, 0x4a]
 
 
@@ -148,7 +148,7 @@ final class AESTests: XCTestCase {
 
 
     func testAESEncryptOFB128() {
     func testAESEncryptOFB128() {
         let key: Array<UInt8> = [0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c]
         let key: Array<UInt8> = [0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c]
-        let iv: Array<UInt8> = [0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F]
+        let iv: Array<UInt8> = [0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f]
         let plaintext: Array<UInt8> = [0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a]
         let plaintext: Array<UInt8> = [0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a]
         let expected: Array<UInt8> = [0x3b, 0x3f, 0xd9, 0x2e, 0xb7, 0x2d, 0xad, 0x20, 0x33, 0x34, 0x49, 0xf8, 0xe8, 0x3c, 0xfb, 0x4a]
         let expected: Array<UInt8> = [0x3b, 0x3f, 0xd9, 0x2e, 0xb7, 0x2d, 0xad, 0x20, 0x33, 0x34, 0x49, 0xf8, 0xe8, 0x3c, 0xfb, 0x4a]
 
 
@@ -161,7 +161,7 @@ final class AESTests: XCTestCase {
 
 
     func testAESEncryptOFB256() {
     func testAESEncryptOFB256() {
         let key: Array<UInt8> = [0x60, 0x3d, 0xeb, 0x10, 0x15, 0xca, 0x71, 0xbe, 0x2b, 0x73, 0xae, 0xf0, 0x85, 0x7d, 0x77, 0x81, 0x1f, 0x35, 0x2c, 0x07, 0x3b, 0x61, 0x08, 0xd7, 0x2d, 0x98, 0x10, 0xa3, 0x09, 0x14, 0xdf, 0xf4]
         let key: Array<UInt8> = [0x60, 0x3d, 0xeb, 0x10, 0x15, 0xca, 0x71, 0xbe, 0x2b, 0x73, 0xae, 0xf0, 0x85, 0x7d, 0x77, 0x81, 0x1f, 0x35, 0x2c, 0x07, 0x3b, 0x61, 0x08, 0xd7, 0x2d, 0x98, 0x10, 0xa3, 0x09, 0x14, 0xdf, 0xf4]
-        let iv: Array<UInt8> = [0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F]
+        let iv: Array<UInt8> = [0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f]
         let plaintext: Array<UInt8> = [0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a]
         let plaintext: Array<UInt8> = [0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a]
         let expected: Array<UInt8> = [0xdc, 0x7e, 0x84, 0xbf, 0xda, 0x79, 0x16, 0x4b, 0x7e, 0xcd, 0x84, 0x86, 0x98, 0x5d, 0x38, 0x60]
         let expected: Array<UInt8> = [0xdc, 0x7e, 0x84, 0xbf, 0xda, 0x79, 0x16, 0x4b, 0x7e, 0xcd, 0x84, 0x86, 0x98, 0x5d, 0x38, 0x60]
 
 
@@ -174,7 +174,7 @@ final class AESTests: XCTestCase {
 
 
     func testAESEncryptPCBC256() {
     func testAESEncryptPCBC256() {
         let key: Array<UInt8> = [0x60, 0x3d, 0xeb, 0x10, 0x15, 0xca, 0x71, 0xbe, 0x2b, 0x73, 0xae, 0xf0, 0x85, 0x7d, 0x77, 0x81, 0x1f, 0x35, 0x2c, 0x07, 0x3b, 0x61, 0x08, 0xd7, 0x2d, 0x98, 0x10, 0xa3, 0x09, 0x14, 0xdf, 0xf4]
         let key: Array<UInt8> = [0x60, 0x3d, 0xeb, 0x10, 0x15, 0xca, 0x71, 0xbe, 0x2b, 0x73, 0xae, 0xf0, 0x85, 0x7d, 0x77, 0x81, 0x1f, 0x35, 0x2c, 0x07, 0x3b, 0x61, 0x08, 0xd7, 0x2d, 0x98, 0x10, 0xa3, 0x09, 0x14, 0xdf, 0xf4]
-        let iv: Array<UInt8> = [0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F]
+        let iv: Array<UInt8> = [0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f]
         let plaintext: Array<UInt8> = [0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a]
         let plaintext: Array<UInt8> = [0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a]
         let expected: Array<UInt8> = [0xf5, 0x8c, 0x4c, 0x04, 0xd6, 0xe5, 0xf1, 0xba, 0x77, 0x9e, 0xab, 0xfb, 0x5f, 0x7b, 0xfb, 0xd6]
         let expected: Array<UInt8> = [0xf5, 0x8c, 0x4c, 0x04, 0xd6, 0xe5, 0xf1, 0xba, 0x77, 0x9e, 0xab, 0xfb, 0x5f, 0x7b, 0xfb, 0xd6]
 
 
@@ -194,10 +194,10 @@ final class AESTests: XCTestCase {
 
 
         let aes = try! AES(key: key, iv: iv, blockMode: .CTR, padding: NoPadding())
         let aes = try! AES(key: key, iv: iv, blockMode: .CTR, padding: NoPadding())
         let encrypted = try! aes.encrypt(plaintext)
         let encrypted = try! aes.encrypt(plaintext)
-        XCTAssertEqual(encrypted.count, plaintext.count);
+        XCTAssertEqual(encrypted.count, plaintext.count)
         XCTAssertEqual(encrypted, expected, "encryption failed")
         XCTAssertEqual(encrypted, expected, "encryption failed")
         let decrypted = try! aes.decrypt(encrypted)
         let decrypted = try! aes.decrypt(encrypted)
-        XCTAssertEqual(decrypted.count, plaintext.count);
+        XCTAssertEqual(decrypted.count, plaintext.count)
         XCTAssertEqual(decrypted, plaintext, "decryption failed")
         XCTAssertEqual(decrypted, plaintext, "decryption failed")
     }
     }
 
 
@@ -233,7 +233,7 @@ final class AESTests: XCTestCase {
         let iv: Array<UInt8> = [0x00, 0x01, 0x02, 0x03, 0x00, 0x01, 0x02, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01]
         let iv: Array<UInt8> = [0x00, 0x01, 0x02, 0x03, 0x00, 0x01, 0x02, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01]
         var plaintext: Array<UInt8> = Array<UInt8>(repeating: 0, count: 6000)
         var plaintext: Array<UInt8> = Array<UInt8>(repeating: 0, count: 6000)
 
 
-        for i in 0 ..< plaintext.count / 6 {
+        for i in 0..<plaintext.count / 6 {
             let s = Array(String(format: "%05d", i).utf8)
             let s = Array(String(format: "%05d", i).utf8)
             plaintext[i * 6 + 0] = s[0]
             plaintext[i * 6 + 0] = s[0]
             plaintext[i * 6 + 1] = s[1]
             plaintext[i * 6 + 1] = s[1]
@@ -248,24 +248,24 @@ final class AESTests: XCTestCase {
 
 
         var decryptor = aes.makeDecryptor()
         var decryptor = aes.makeDecryptor()
         decryptor.seek(to: 2)
         decryptor.seek(to: 2)
-        var part1 = try! decryptor.update(withBytes: Array(encrypted[2 ..< 5]))
+        var part1 = try! decryptor.update(withBytes: Array(encrypted[2..<5]))
         part1 += try! decryptor.finish()
         part1 += try! decryptor.finish()
-        XCTAssertEqual(part1, Array(plaintext[2 ..< 5]), "seek decryption failed")
+        XCTAssertEqual(part1, Array(plaintext[2..<5]), "seek decryption failed")
 
 
         decryptor.seek(to: 1000)
         decryptor.seek(to: 1000)
-        var part2 = try! decryptor.update(withBytes: Array(encrypted[1000 ..< 1200]))
+        var part2 = try! decryptor.update(withBytes: Array(encrypted[1000..<1200]))
         part2 += try! decryptor.finish()
         part2 += try! decryptor.finish()
-        XCTAssertEqual(part2, Array(plaintext[1000 ..< 1200]), "seek decryption failed")
+        XCTAssertEqual(part2, Array(plaintext[1000..<1200]), "seek decryption failed")
 
 
         decryptor.seek(to: 5500)
         decryptor.seek(to: 5500)
-        var part3 = try! decryptor.update(withBytes: Array(encrypted[5500 ..< 6000]))
+        var part3 = try! decryptor.update(withBytes: Array(encrypted[5500..<6000]))
         part3 += try! decryptor.finish()
         part3 += try! decryptor.finish()
-        XCTAssertEqual(part3, Array(plaintext[5500 ..< 6000]), "seek decryption failed")
+        XCTAssertEqual(part3, Array(plaintext[5500..<6000]), "seek decryption failed")
 
 
         decryptor.seek(to: 0)
         decryptor.seek(to: 0)
-        var part4 = try! decryptor.update(withBytes: Array(encrypted[0 ..< 80]))
+        var part4 = try! decryptor.update(withBytes: Array(encrypted[0..<80]))
         part4 += try! decryptor.finish()
         part4 += try! decryptor.finish()
-        XCTAssertEqual(part4, Array(plaintext[0 ..< 80]), "seek decryption failed")
+        XCTAssertEqual(part4, Array(plaintext[0..<80]), "seek decryption failed")
     }
     }
 
 
     // https://github.com/krzyzanowskim/CryptoSwift/pull/289
     // https://github.com/krzyzanowskim/CryptoSwift/pull/289
@@ -278,17 +278,17 @@ final class AESTests: XCTestCase {
         let aes = try! AES(key: key, iv: iv, blockMode: .CTR, padding: NoPadding())
         let aes = try! AES(key: key, iv: iv, blockMode: .CTR, padding: NoPadding())
         var encryptor = aes.makeEncryptor()
         var encryptor = aes.makeEncryptor()
         var encrypted = Array<UInt8>()
         var encrypted = Array<UInt8>()
-        encrypted += try! encryptor.update(withBytes: plaintext[0 ..< 5])
-        encrypted += try! encryptor.update(withBytes: plaintext[5 ..< 15])
-        encrypted += try! encryptor.update(withBytes: plaintext[15 ..< plaintext.count])
+        encrypted += try! encryptor.update(withBytes: plaintext[0..<5])
+        encrypted += try! encryptor.update(withBytes: plaintext[5..<15])
+        encrypted += try! encryptor.update(withBytes: plaintext[15..<plaintext.count])
         encrypted += try! encryptor.finish()
         encrypted += try! encryptor.finish()
         XCTAssertEqual(encrypted, expected, "encryption failed")
         XCTAssertEqual(encrypted, expected, "encryption failed")
 
 
         var decryptor = aes.makeDecryptor()
         var decryptor = aes.makeDecryptor()
         var decrypted = Array<UInt8>()
         var decrypted = Array<UInt8>()
-        decrypted += try! decryptor.update(withBytes: expected[0 ..< 5])
-        decrypted += try! decryptor.update(withBytes: expected[5 ..< 15])
-        decrypted += try! decryptor.update(withBytes: expected[15 ..< plaintext.count])
+        decrypted += try! decryptor.update(withBytes: expected[0..<5])
+        decrypted += try! decryptor.update(withBytes: expected[5..<15])
+        decrypted += try! decryptor.update(withBytes: expected[15..<plaintext.count])
         decrypted += try! decryptor.finish()
         decrypted += try! decryptor.finish()
         XCTAssertEqual(decrypted, plaintext, "decryption failed")
         XCTAssertEqual(decrypted, plaintext, "decryption failed")
     }
     }
@@ -296,7 +296,7 @@ final class AESTests: XCTestCase {
     func testAESWithWrongKey() {
     func testAESWithWrongKey() {
         let key: Array<UInt8> = [0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c]
         let key: Array<UInt8> = [0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c]
         let key2: Array<UInt8> = [0x22, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x33]
         let key2: Array<UInt8> = [0x22, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x33]
-        let iv: Array<UInt8> = [0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F]
+        let iv: Array<UInt8> = [0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f]
         let plaintext: Array<UInt8> = [49, 46, 50, 50, 50, 51, 51, 51, 51]
         let plaintext: Array<UInt8> = [49, 46, 50, 50, 50, 51, 51, 51, 51]
 
 
         let aes = try! AES(key: key, iv: iv, blockMode: .CBC, padding: PKCS7())
         let aes = try! AES(key: key, iv: iv, blockMode: .CBC, padding: PKCS7())
@@ -326,7 +326,7 @@ final class AESTests: XCTestCase {
     func testIssue394() {
     func testIssue394() {
         let plaintext = Array("Nullam quis risus eget urna mollis ornare vel eu leo.".utf8)
         let plaintext = Array("Nullam quis risus eget urna mollis ornare vel eu leo.".utf8)
         let key = Array("passwordpassword".utf8).md5() // -md md5
         let key = Array("passwordpassword".utf8).md5() // -md md5
-        let iv  = Array("drowssapdrowssap".utf8) // -iv 64726f777373617064726f7773736170
+        let iv = Array("drowssapdrowssap".utf8) // -iv 64726f777373617064726f7773736170
         let aes = try! AES(key: key, iv: iv, blockMode: .CBC, padding: PKCS7()) // -aes-128-cbc
         let aes = try! AES(key: key, iv: iv, blockMode: .CBC, padding: PKCS7()) // -aes-128-cbc
         let ciphertext = try! aes.encrypt(plaintext) // enc
         let ciphertext = try! aes.encrypt(plaintext) // enc
 
 
@@ -338,9 +338,9 @@ final class AESTests: XCTestCase {
 
 
     // https://github.com/krzyzanowskim/CryptoSwift/issues/411
     // https://github.com/krzyzanowskim/CryptoSwift/issues/411
     func testIssue411() {
     func testIssue411() {
-        let ciphertext: Array<UInt8> = [0x2A,0x3A,0x80,0x05,0xAF,0x46,0x58,0x2D,0x66,0x52,0x10,0xAE,0x86,0xD3,0x8E,0x8F] // test
+        let ciphertext: Array<UInt8> = [0x2a, 0x3a, 0x80, 0x05, 0xaf, 0x46, 0x58, 0x2d, 0x66, 0x52, 0x10, 0xae, 0x86, 0xd3, 0x8e, 0x8f] // test
         let key = Array("passwordpassword".utf8).md5() // -md md5
         let key = Array("passwordpassword".utf8).md5() // -md md5
-        let iv  = Array("drowssapdrowssap".utf8) // -iv 64726f777373617064726f7773736170
+        let iv = Array("drowssapdrowssap".utf8) // -iv 64726f777373617064726f7773736170
         let aes = try! AES(key: key, iv: iv, blockMode: .CBC, padding: PKCS7()) // -aes-128-cbc
         let aes = try! AES(key: key, iv: iv, blockMode: .CBC, padding: PKCS7()) // -aes-128-cbc
         let plaintext = try! ciphertext.decrypt(cipher: aes)
         let plaintext = try! ciphertext.decrypt(cipher: aes)
         XCTAssertEqual("74657374", plaintext.toHexString())
         XCTAssertEqual("74657374", plaintext.toHexString())
@@ -353,7 +353,7 @@ final class AESTests: XCTestCase {
 
 
         func testAESEncryptPerformance() {
         func testAESEncryptPerformance() {
             let key: Array<UInt8> = [0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c]
             let key: Array<UInt8> = [0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c]
-            let iv: Array<UInt8> = [0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F]
+            let iv: Array<UInt8> = [0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f]
             let message = Array<UInt8>(repeating: 7, count: 1024 * 1024)
             let message = Array<UInt8>(repeating: 7, count: 1024 * 1024)
             let aes = try! AES(key: key, iv: iv, blockMode: .CBC, padding: PKCS7())
             let aes = try! AES(key: key, iv: iv, blockMode: .CBC, padding: PKCS7())
             measureMetrics([XCTPerformanceMetric.wallClockTime], automaticallyStartMeasuring: true, for: { () -> Void in
             measureMetrics([XCTPerformanceMetric.wallClockTime], automaticallyStartMeasuring: true, for: { () -> Void in
@@ -363,7 +363,7 @@ final class AESTests: XCTestCase {
 
 
         func testAESDecryptPerformance() {
         func testAESDecryptPerformance() {
             let key: Array<UInt8> = [0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c]
             let key: Array<UInt8> = [0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c]
-            let iv: Array<UInt8> = [0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F]
+            let iv: Array<UInt8> = [0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f]
             let message = Array<UInt8>(repeating: 7, count: 1024 * 1024)
             let message = Array<UInt8>(repeating: 7, count: 1024 * 1024)
             let aes = try! AES(key: key, iv: iv, blockMode: .CBC, padding: PKCS7())
             let aes = try! AES(key: key, iv: iv, blockMode: .CBC, padding: PKCS7())
             measureMetrics([XCTPerformanceMetric.wallClockTime], automaticallyStartMeasuring: true, for: { () -> Void in
             measureMetrics([XCTPerformanceMetric.wallClockTime], automaticallyStartMeasuring: true, for: { () -> Void in

+ 91 - 92
Tests/CryptoSwiftTests/Access.swift

@@ -16,49 +16,49 @@ class Access: XCTestCase {
     let authenticator = HMAC(key: Array<UInt8>(hex: "b1b2b3b3b3b3b3b3b1b2b3b3b3b3b3b3"), variant: .sha1)
     let authenticator = HMAC(key: Array<UInt8>(hex: "b1b2b3b3b3b3b3b3b1b2b3b3b3b3b3b3"), variant: .sha1)
 
 
     func testChecksum() {
     func testChecksum() {
-        let _ = Checksum.crc32([1, 2, 3])
-        let _ = Checksum.crc16([1, 2, 3])
+        _ = Checksum.crc32([1, 2, 3])
+        _ = Checksum.crc16([1, 2, 3])
     }
     }
 
 
     func testRandomIV() {
     func testRandomIV() {
-        let _ = AES.randomIV(AES.blockSize)
-        let _ = ChaCha20.randomIV(ChaCha20.blockSize)
+        _ = AES.randomIV(AES.blockSize)
+        _ = ChaCha20.randomIV(ChaCha20.blockSize)
     }
     }
 
 
     func testDigest() {
     func testDigest() {
-        let _ = Digest.md5([1, 2, 3])
-        let _ = Digest.sha1([1, 2, 3])
-        let _ = Digest.sha224([1, 2, 3])
-        let _ = Digest.sha256([1, 2, 3])
-        let _ = Digest.sha384([1, 2, 3])
-        let _ = Digest.sha512([1, 2, 3])
-        let _ = Digest.sha3([1, 2, 3], variant: .sha224)
-
-        let _ = SHA1().calculate(for: [0])
-        let _ = SHA2(variant: .sha224).calculate(for: [0])
-        let _ = SHA3(variant: .sha256).calculate(for: [0])
-
-        let _ = MD5().calculate(for: [0])
+        _ = Digest.md5([1, 2, 3])
+        _ = Digest.sha1([1, 2, 3])
+        _ = Digest.sha224([1, 2, 3])
+        _ = Digest.sha256([1, 2, 3])
+        _ = Digest.sha384([1, 2, 3])
+        _ = Digest.sha512([1, 2, 3])
+        _ = Digest.sha3([1, 2, 3], variant: .sha224)
+
+        _ = SHA1().calculate(for: [0])
+        _ = SHA2(variant: .sha224).calculate(for: [0])
+        _ = SHA3(variant: .sha256).calculate(for: [0])
+
+        _ = MD5().calculate(for: [0])
     }
     }
 
 
     func testArrayExtension() {
     func testArrayExtension() {
         let array = Array<UInt8>(hex: "b1b2b3b3b3b3b3b3b1b2b3b3b3b3b3b3")
         let array = Array<UInt8>(hex: "b1b2b3b3b3b3b3b3b1b2b3b3b3b3b3b3")
-        let _ = array.toHexString()
-
-        let _ = array.md5()
-        let _ = array.sha1()
-        let _ = array.sha256()
-        let _ = array.sha384()
-        let _ = array.sha512()
-        let _ = array.sha2(.sha224)
-        let _ = array.sha3(.sha224)
-        let _ = array.crc32()
-        let _ = array.crc16()
+        _ = array.toHexString()
+
+        _ = array.md5()
+        _ = array.sha1()
+        _ = array.sha256()
+        _ = array.sha384()
+        _ = array.sha512()
+        _ = array.sha2(.sha224)
+        _ = array.sha3(.sha224)
+        _ = array.crc32()
+        _ = array.crc16()
 
 
         do {
         do {
-            let _ = try array.encrypt(cipher: cipher)
-            let _ = try array.decrypt(cipher: cipher)
-            let _ = try array.authenticate(with: authenticator)
+            _ = try array.encrypt(cipher: cipher)
+            _ = try array.decrypt(cipher: cipher)
+            _ = try array.authenticate(with: authenticator)
         } catch {
         } catch {
             XCTFail(error.localizedDescription)
             XCTFail(error.localizedDescription)
         }
         }
@@ -70,19 +70,19 @@ class Access: XCTestCase {
 
 
     func testStringExtension() {
     func testStringExtension() {
         let string = "foofoobarbar"
         let string = "foofoobarbar"
-        let _ = string.md5()
-        let _ = string.sha1()
-        let _ = string.sha224()
-        let _ = string.sha256()
-        let _ = string.sha384()
-        let _ = string.sha512()
-        let _ = string.sha3(.sha224)
-        let _ = string.crc16()
-        let _ = string.crc32()
+        _ = string.md5()
+        _ = string.sha1()
+        _ = string.sha224()
+        _ = string.sha256()
+        _ = string.sha384()
+        _ = string.sha512()
+        _ = string.sha3(.sha224)
+        _ = string.crc16()
+        _ = string.crc32()
 
 
         do {
         do {
-            let _ = try string.encrypt(cipher: cipher)
-            let _ = try string.authenticate(with: authenticator)
+            _ = try string.encrypt(cipher: cipher)
+            _ = try string.authenticate(with: authenticator)
         } catch {
         } catch {
             XCTFail(error.localizedDescription)
             XCTFail(error.localizedDescription)
         }
         }
@@ -91,8 +91,8 @@ class Access: XCTestCase {
     func testStringFoundationExtension() {
     func testStringFoundationExtension() {
         let string = "aPf/i9th9iX+vf49eR7PYk2q7S5xmm3jkRLejgzHNJs="
         let string = "aPf/i9th9iX+vf49eR7PYk2q7S5xmm3jkRLejgzHNJs="
         do {
         do {
-            let _ = try string.decryptBase64ToString(cipher: cipher)
-            let _ = try string.decryptBase64(cipher: cipher)
+            _ = try string.decryptBase64ToString(cipher: cipher)
+            _ = try string.decryptBase64(cipher: cipher)
         } catch {
         } catch {
             XCTFail(error.localizedDescription)
             XCTFail(error.localizedDescription)
         }
         }
@@ -120,24 +120,24 @@ class Access: XCTestCase {
 
 
     func testDataExtension() {
     func testDataExtension() {
         let data = Data(bytes: [1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8])
         let data = Data(bytes: [1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8])
-        let _ = data.checksum()
-        let _ = data.md5()
-        let _ = data.sha1()
-        let _ = data.sha224()
-        let _ = data.sha256()
-        let _ = data.sha384()
-        let _ = data.sha512()
-        let _ = data.sha3(.sha224)
-        let _ = data.crc16()
-        let _ = data.crc32()
-
-        let _ = data.bytes
-        let _ = data.toHexString()
+        _ = data.checksum()
+        _ = data.md5()
+        _ = data.sha1()
+        _ = data.sha224()
+        _ = data.sha256()
+        _ = data.sha384()
+        _ = data.sha512()
+        _ = data.sha3(.sha224)
+        _ = data.crc16()
+        _ = data.crc32()
+
+        _ = data.bytes
+        _ = data.toHexString()
 
 
         do {
         do {
-            let _ = try data.encrypt(cipher: cipher)
-            let _ = try data.decrypt(cipher: cipher)
-            let _ = try data.authenticate(with: authenticator)
+            _ = try data.encrypt(cipher: cipher)
+            _ = try data.decrypt(cipher: cipher)
+            _ = try data.authenticate(with: authenticator)
         } catch {
         } catch {
             XCTFail(error.localizedDescription)
             XCTFail(error.localizedDescription)
         }
         }
@@ -145,23 +145,23 @@ class Access: XCTestCase {
 
 
     func testPadding() {
     func testPadding() {
         // PKCS7
         // PKCS7
-        let _ = PKCS7().add(to: [1, 2, 3], blockSize: 16)
-        let _ = PKCS7().remove(from: [1, 2, 3], blockSize: 16)
+        _ = PKCS7().add(to: [1, 2, 3], blockSize: 16)
+        _ = PKCS7().remove(from: [1, 2, 3], blockSize: 16)
 
 
         // NoPadding
         // NoPadding
-        let _ = NoPadding().add(to: [1, 2, 3], blockSize: 16)
-        let _ = NoPadding().remove(from: [1, 2, 3], blockSize: 16)
+        _ = NoPadding().add(to: [1, 2, 3], blockSize: 16)
+        _ = NoPadding().remove(from: [1, 2, 3], blockSize: 16)
 
 
         // ZeroPadding
         // ZeroPadding
-        let _ = ZeroPadding().add(to: [1, 2, 3], blockSize: 16)
-        let _ = ZeroPadding().remove(from: [1, 2, 3], blockSize: 16)
+        _ = ZeroPadding().add(to: [1, 2, 3], blockSize: 16)
+        _ = ZeroPadding().remove(from: [1, 2, 3], blockSize: 16)
     }
     }
 
 
     func testPBKDF() {
     func testPBKDF() {
         do {
         do {
-            let _ = PKCS5.PBKDF1.Variant.md5
-            let _ = try PKCS5.PBKDF1(password: [1, 2, 3, 4, 5, 6, 7], salt: [1, 2, 3, 4, 5, 6, 7, 8]).calculate()
-            let _ = try PKCS5.PBKDF2(password: [1, 2, 3, 4, 5, 6, 7], salt: [1, 2, 3, 4]).calculate()
+            _ = PKCS5.PBKDF1.Variant.md5
+            _ = try PKCS5.PBKDF1(password: [1, 2, 3, 4, 5, 6, 7], salt: [1, 2, 3, 4, 5, 6, 7, 8]).calculate()
+            _ = try PKCS5.PBKDF2(password: [1, 2, 3, 4, 5, 6, 7], salt: [1, 2, 3, 4]).calculate()
         } catch {
         } catch {
             XCTFail(error.localizedDescription)
             XCTFail(error.localizedDescription)
         }
         }
@@ -169,8 +169,8 @@ class Access: XCTestCase {
 
 
     func testAuthenticators() {
     func testAuthenticators() {
         do {
         do {
-            let _ = try HMAC(key: Array<UInt8>(hex: "b1b2b3b3b3b3b3b3b1b2b3b3b3b3b3b3"), variant: .sha1).authenticate([1, 2, 3])
-            let _ = try Poly1305(key: [1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2]).authenticate([1, 2, 3])
+            _ = try HMAC(key: Array<UInt8>(hex: "b1b2b3b3b3b3b3b3b1b2b3b3b3b3b3b3"), variant: .sha1).authenticate([1, 2, 3])
+            _ = try Poly1305(key: [1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2]).authenticate([1, 2, 3])
         } catch {
         } catch {
             XCTFail(error.localizedDescription)
             XCTFail(error.localizedDescription)
         }
         }
@@ -180,20 +180,20 @@ class Access: XCTestCase {
         do {
         do {
             let cipher = try AES(key: "secret0key000000", iv: "0123456789012345")
             let cipher = try AES(key: "secret0key000000", iv: "0123456789012345")
             var encryptor = cipher.makeEncryptor()
             var encryptor = cipher.makeEncryptor()
-            let _ = try encryptor.update(withBytes: [1, 2, 3])
-            let _ = try encryptor.finish()
+            _ = try encryptor.update(withBytes: [1, 2, 3])
+            _ = try encryptor.finish()
 
 
             var decryptor = cipher.makeDecryptor()
             var decryptor = cipher.makeDecryptor()
-            let _ = try decryptor.update(withBytes: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16])
-            let _ = try decryptor.finish()
+            _ = try decryptor.update(withBytes: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16])
+            _ = try decryptor.finish()
 
 
             let enc = try cipher.encrypt([1, 2, 3])
             let enc = try cipher.encrypt([1, 2, 3])
-            let _ = try cipher.decrypt(enc)
+            _ = try cipher.decrypt(enc)
 
 
-            let _ = try AES(key: [1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6], iv: [1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6], blockMode: .CBC, padding: NoPadding())
+            _ = try AES(key: [1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6], iv: [1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6], blockMode: .CBC, padding: NoPadding())
 
 
-            let _ = AES.Variant.aes128
-            let _ = AES.blockSize
+            _ = AES.Variant.aes128
+            _ = AES.blockSize
         } catch {
         } catch {
             XCTFail(error.localizedDescription)
             XCTFail(error.localizedDescription)
         }
         }
@@ -203,28 +203,27 @@ class Access: XCTestCase {
         do {
         do {
             let cipher = try Blowfish(key: "secret0key000000", iv: "01234567")
             let cipher = try Blowfish(key: "secret0key000000", iv: "01234567")
             let enc = try cipher.encrypt([1, 2, 3])
             let enc = try cipher.encrypt([1, 2, 3])
-            let _ = try cipher.decrypt(enc)
+            _ = try cipher.decrypt(enc)
 
 
-            let _ = try Blowfish(key: [1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6], iv: [1, 2, 3, 4, 5, 6, 7, 8], blockMode: .CBC, padding: NoPadding())
+            _ = try Blowfish(key: [1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6], iv: [1, 2, 3, 4, 5, 6, 7, 8], blockMode: .CBC, padding: NoPadding())
 
 
-            let _ = Blowfish.blockSize
+            _ = Blowfish.blockSize
         } catch {
         } catch {
             XCTFail(error.localizedDescription)
             XCTFail(error.localizedDescription)
         }
         }
-
     }
     }
 
 
     func testRabbit() {
     func testRabbit() {
         do {
         do {
             let rabbit = try Rabbit(key: [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00])
             let rabbit = try Rabbit(key: [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00])
             let enc = try rabbit.encrypt([1, 2, 3])
             let enc = try rabbit.encrypt([1, 2, 3])
-            let _ = try rabbit.decrypt(enc)
+            _ = try rabbit.decrypt(enc)
 
 
             XCTAssertThrowsError(try Rabbit(key: "123"))
             XCTAssertThrowsError(try Rabbit(key: "123"))
 
 
-            let _ = Rabbit.blockSize
-            let _ = Rabbit.keySize
-            let _ = Rabbit.ivSize
+            _ = Rabbit.blockSize
+            _ = Rabbit.keySize
+            _ = Rabbit.ivSize
         } catch {
         } catch {
             XCTFail(error.localizedDescription)
             XCTFail(error.localizedDescription)
         }
         }
@@ -235,15 +234,15 @@ class Access: XCTestCase {
         let iv: Array<UInt8> = [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]
         let iv: Array<UInt8> = [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]
 
 
         do {
         do {
-            let _ = ChaCha20.blockSize
+            _ = ChaCha20.blockSize
             let chacha20 = try ChaCha20(key: key, iv: iv)
             let chacha20 = try ChaCha20(key: key, iv: iv)
             let enc = try chacha20.encrypt([1, 3, 4])
             let enc = try chacha20.encrypt([1, 3, 4])
-            let _ = try chacha20.decrypt(enc)
+            _ = try chacha20.decrypt(enc)
 
 
             XCTAssertThrowsError(try ChaCha20(key: "123", iv: "12345678"))
             XCTAssertThrowsError(try ChaCha20(key: "123", iv: "12345678"))
 
 
-            let _ = chacha20.makeEncryptor()
-            let _ = chacha20.makeDecryptor()
+            _ = chacha20.makeEncryptor()
+            _ = chacha20.makeDecryptor()
 
 
         } catch {
         } catch {
             XCTFail(error.localizedDescription)
             XCTFail(error.localizedDescription)
@@ -251,7 +250,7 @@ class Access: XCTestCase {
     }
     }
 
 
     func testUpdatable() {
     func testUpdatable() {
-        // TODO: 
+        // TODO:
     }
     }
 
 
     static let allTests = [
     static let allTests = [

+ 96 - 96
Tests/CryptoSwiftTests/BlowfishTests.swift

@@ -22,146 +22,146 @@ class BlowfishTests: XCTestCase {
     let tests = [
     let tests = [
         TestData(key: [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00],
         TestData(key: [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00],
                  input: [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00],
                  input: [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00],
-                 output: [0x4E, 0xF9, 0x97, 0x45, 0x61, 0x98, 0xDD, 0x78]),
-        TestData(key: [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF],
-                 input: [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF],
-                 output: [0x51, 0x86, 0x6F, 0xD5, 0xB8, 0x5E, 0xCB, 0x8A]),
+                 output: [0x4e, 0xf9, 0x97, 0x45, 0x61, 0x98, 0xdd, 0x78]),
+        TestData(key: [0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff],
+                 input: [0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff],
+                 output: [0x51, 0x86, 0x6f, 0xd5, 0xb8, 0x5e, 0xcb, 0x8a]),
         TestData(key: [0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00],
         TestData(key: [0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00],
                  input: [0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01],
                  input: [0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01],
-                 output: [0x7D, 0x85, 0x6F, 0x9A, 0x61, 0x30, 0x63, 0xF2]),
+                 output: [0x7d, 0x85, 0x6f, 0x9a, 0x61, 0x30, 0x63, 0xf2]),
         TestData(key: [0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11],
         TestData(key: [0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11],
                  input: [0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11],
                  input: [0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11],
-                 output: [0x24, 0x66, 0xDD, 0x87, 0x8B, 0x96, 0x3C, 0x9D]),
+                 output: [0x24, 0x66, 0xdd, 0x87, 0x8b, 0x96, 0x3c, 0x9d]),
 
 
-        TestData(key:   [0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF],
+        TestData(key: [0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef],
                  input: [0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11],
                  input: [0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11],
-                 output:[0x61, 0xF9, 0xC3, 0x80, 0x22, 0x81, 0xB0, 0x96]),
+                 output: [0x61, 0xf9, 0xc3, 0x80, 0x22, 0x81, 0xb0, 0x96]),
 
 
-        TestData(key:   [0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11],
-                 input: [0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF],
-                 output:[0x7D, 0x0C, 0xC6, 0x30, 0xAF, 0xDA, 0x1E, 0xC7]),
+        TestData(key: [0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11],
+                 input: [0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef],
+                 output: [0x7d, 0x0c, 0xc6, 0x30, 0xaf, 0xda, 0x1e, 0xc7]),
 
 
-        TestData(key:   [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00],
+        TestData(key: [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00],
                  input: [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00],
                  input: [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00],
-                 output:[0x4E, 0xF9, 0x97, 0x45, 0x61, 0x98, 0xDD, 0x78]),
+                 output: [0x4e, 0xf9, 0x97, 0x45, 0x61, 0x98, 0xdd, 0x78]),
 
 
-        TestData(key:   [0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10],
-                 input: [0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF],
-                 output:[0x0A, 0xCE, 0xAB, 0x0F, 0xC6, 0xA0, 0xA2, 0x8D]),
+        TestData(key: [0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10],
+                 input: [0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef],
+                 output: [0x0a, 0xce, 0xab, 0x0f, 0xc6, 0xa0, 0xa2, 0x8d]),
 
 
-        TestData(key:   [0x7C, 0xA1, 0x10, 0x45, 0x4A, 0x1A, 0x6E, 0x57],
-                 input: [0x01, 0xA1, 0xD6, 0xD0, 0x39, 0x77, 0x67, 0x42],
-                 output:[0x59, 0xC6, 0x82, 0x45, 0xEB, 0x05, 0x28, 0x2B]),
+        TestData(key: [0x7c, 0xa1, 0x10, 0x45, 0x4a, 0x1a, 0x6e, 0x57],
+                 input: [0x01, 0xa1, 0xd6, 0xd0, 0x39, 0x77, 0x67, 0x42],
+                 output: [0x59, 0xc6, 0x82, 0x45, 0xeb, 0x05, 0x28, 0x2b]),
 
 
-        TestData(key:   [0x01, 0x31, 0xD9, 0x61, 0x9D, 0xC1, 0x37, 0x6E],
-                 input: [0x5C, 0xD5, 0x4C, 0xA8, 0x3D, 0xEF, 0x57, 0xDA],
-                 output:[0xB1, 0xB8, 0xCC, 0x0B, 0x25, 0x0F, 0x09, 0xA0]),
+        TestData(key: [0x01, 0x31, 0xd9, 0x61, 0x9d, 0xc1, 0x37, 0x6e],
+                 input: [0x5c, 0xd5, 0x4c, 0xa8, 0x3d, 0xef, 0x57, 0xda],
+                 output: [0xb1, 0xb8, 0xcc, 0x0b, 0x25, 0x0f, 0x09, 0xa0]),
 
 
-        TestData(key:   [0x07, 0xA1, 0x13, 0x3E, 0x4A, 0x0B, 0x26, 0x86],
-                 input: [0x02, 0x48, 0xD4, 0x38, 0x06, 0xF6, 0x71, 0x72],
-                 output:[0x17, 0x30, 0xE5, 0x77, 0x8B, 0xEA, 0x1D, 0xA4]),
+        TestData(key: [0x07, 0xa1, 0x13, 0x3e, 0x4a, 0x0b, 0x26, 0x86],
+                 input: [0x02, 0x48, 0xd4, 0x38, 0x06, 0xf6, 0x71, 0x72],
+                 output: [0x17, 0x30, 0xe5, 0x77, 0x8b, 0xea, 0x1d, 0xa4]),
 
 
-        TestData(key:   [0x38, 0x49, 0x67, 0x4C, 0x26, 0x02, 0x31, 0x9E],
-                 input: [0x51, 0x45, 0x4B, 0x58, 0x2D, 0xDF, 0x44, 0x0A],
-                 output:[0xA2, 0x5E, 0x78, 0x56, 0xCF, 0x26, 0x51, 0xEB]),
+        TestData(key: [0x38, 0x49, 0x67, 0x4c, 0x26, 0x02, 0x31, 0x9e],
+                 input: [0x51, 0x45, 0x4b, 0x58, 0x2d, 0xdf, 0x44, 0x0a],
+                 output: [0xa2, 0x5e, 0x78, 0x56, 0xcf, 0x26, 0x51, 0xeb]),
 
 
-        TestData(key:   [0x04, 0xB9, 0x15, 0xBA, 0x43, 0xFE, 0xB5, 0xB6],
-                 input: [0x42, 0xFD, 0x44, 0x30, 0x59, 0x57, 0x7F, 0xA2],
-                 output:[0x35, 0x38, 0x82, 0xB1, 0x09, 0xCE, 0x8F, 0x1A]),
+        TestData(key: [0x04, 0xb9, 0x15, 0xba, 0x43, 0xfe, 0xb5, 0xb6],
+                 input: [0x42, 0xfd, 0x44, 0x30, 0x59, 0x57, 0x7f, 0xa2],
+                 output: [0x35, 0x38, 0x82, 0xb1, 0x09, 0xce, 0x8f, 0x1a]),
 
 
-        TestData(key:   [0x01, 0x13, 0xB9, 0x70, 0xFD, 0x34, 0xF2, 0xCE],
-                 input: [0x05, 0x9B, 0x5E, 0x08, 0x51, 0xCF, 0x14, 0x3A],
-                 output:[0x48, 0xF4, 0xD0, 0x88, 0x4C, 0x37, 0x99, 0x18]),
+        TestData(key: [0x01, 0x13, 0xb9, 0x70, 0xfd, 0x34, 0xf2, 0xce],
+                 input: [0x05, 0x9b, 0x5e, 0x08, 0x51, 0xcf, 0x14, 0x3a],
+                 output: [0x48, 0xf4, 0xd0, 0x88, 0x4c, 0x37, 0x99, 0x18]),
 
 
-        TestData(key:   [0x01, 0x70, 0xF1, 0x75, 0x46, 0x8F, 0xB5, 0xE6],
-                 input: [0x07, 0x56, 0xD8, 0xE0, 0x77, 0x47, 0x61, 0xD2],
-                 output:[0x43, 0x21, 0x93, 0xB7, 0x89, 0x51, 0xFC, 0x98]),
+        TestData(key: [0x01, 0x70, 0xf1, 0x75, 0x46, 0x8f, 0xb5, 0xe6],
+                 input: [0x07, 0x56, 0xd8, 0xe0, 0x77, 0x47, 0x61, 0xd2],
+                 output: [0x43, 0x21, 0x93, 0xb7, 0x89, 0x51, 0xfc, 0x98]),
 
 
-        TestData(key:   [0x43, 0x29, 0x7F, 0xAD, 0x38, 0xE3, 0x73, 0xFE],
-                 input: [0x76, 0x25, 0x14, 0xB8, 0x29, 0xBF, 0x48, 0x6A],
-                 output:[0x13, 0xF0, 0x41, 0x54, 0xD6, 0x9D, 0x1A, 0xE5]),
+        TestData(key: [0x43, 0x29, 0x7f, 0xad, 0x38, 0xe3, 0x73, 0xfe],
+                 input: [0x76, 0x25, 0x14, 0xb8, 0x29, 0xbf, 0x48, 0x6a],
+                 output: [0x13, 0xf0, 0x41, 0x54, 0xd6, 0x9d, 0x1a, 0xe5]),
 
 
-        TestData(key:   [0x07, 0xA7, 0x13, 0x70, 0x45, 0xDA, 0x2A, 0x16],
-                 input: [0x3B, 0xDD, 0x11, 0x90, 0x49, 0x37, 0x28, 0x02],
-                 output:[0x2E, 0xED, 0xDA, 0x93, 0xFF, 0xD3, 0x9C, 0x79]),
+        TestData(key: [0x07, 0xa7, 0x13, 0x70, 0x45, 0xda, 0x2a, 0x16],
+                 input: [0x3b, 0xdd, 0x11, 0x90, 0x49, 0x37, 0x28, 0x02],
+                 output: [0x2e, 0xed, 0xda, 0x93, 0xff, 0xd3, 0x9c, 0x79]),
 
 
-        TestData(key:   [0x04, 0x68, 0x91, 0x04, 0xC2, 0xFD, 0x3B, 0x2F],
-                 input: [0x26, 0x95, 0x5F, 0x68, 0x35, 0xAF, 0x60, 0x9A],
-                 output:[0xD8, 0x87, 0xE0, 0x39, 0x3C, 0x2D, 0xA6, 0xE3]),
+        TestData(key: [0x04, 0x68, 0x91, 0x04, 0xc2, 0xfd, 0x3b, 0x2f],
+                 input: [0x26, 0x95, 0x5f, 0x68, 0x35, 0xaf, 0x60, 0x9a],
+                 output: [0xd8, 0x87, 0xe0, 0x39, 0x3c, 0x2d, 0xa6, 0xe3]),
 
 
-        TestData(key:   [0x37, 0xD0, 0x6B, 0xB5, 0x16, 0xCB, 0x75, 0x46],
-                 input: [0x16, 0x4D, 0x5E, 0x40, 0x4F, 0x27, 0x52, 0x32],
-                 output:[0x5F, 0x99, 0xD0, 0x4F, 0x5B, 0x16, 0x39, 0x69]),
+        TestData(key: [0x37, 0xd0, 0x6b, 0xb5, 0x16, 0xcb, 0x75, 0x46],
+                 input: [0x16, 0x4d, 0x5e, 0x40, 0x4f, 0x27, 0x52, 0x32],
+                 output: [0x5f, 0x99, 0xd0, 0x4f, 0x5b, 0x16, 0x39, 0x69]),
 
 
-        TestData(key:   [0x1F, 0x08, 0x26, 0x0D, 0x1A, 0xC2, 0x46, 0x5E],
-                 input: [0x6B, 0x05, 0x6E, 0x18, 0x75, 0x9F, 0x5C, 0xCA],
-                 output:[0x4A, 0x05, 0x7A, 0x3B, 0x24, 0xD3, 0x97, 0x7B]),
+        TestData(key: [0x1f, 0x08, 0x26, 0x0d, 0x1a, 0xc2, 0x46, 0x5e],
+                 input: [0x6b, 0x05, 0x6e, 0x18, 0x75, 0x9f, 0x5c, 0xca],
+                 output: [0x4a, 0x05, 0x7a, 0x3b, 0x24, 0xd3, 0x97, 0x7b]),
 
 
-        TestData(key:   [0x58, 0x40, 0x23, 0x64, 0x1A, 0xBA, 0x61, 0x76],
-                 input: [0x00, 0x4B, 0xD6, 0xEF, 0x09, 0x17, 0x60, 0x62],
-                 output:[0x45, 0x20, 0x31, 0xC1, 0xE4, 0xFA, 0xDA, 0x8E]),
+        TestData(key: [0x58, 0x40, 0x23, 0x64, 0x1a, 0xba, 0x61, 0x76],
+                 input: [0x00, 0x4b, 0xd6, 0xef, 0x09, 0x17, 0x60, 0x62],
+                 output: [0x45, 0x20, 0x31, 0xc1, 0xe4, 0xfa, 0xda, 0x8e]),
 
 
-        TestData(key:   [0x02, 0x58, 0x16, 0x16, 0x46, 0x29, 0xB0, 0x07],
-                 input: [0x48, 0x0D, 0x39, 0x00, 0x6E, 0xE7, 0x62, 0xF2],
-                 output:[0x75, 0x55, 0xAE, 0x39, 0xF5, 0x9B, 0x87, 0xBD]),
+        TestData(key: [0x02, 0x58, 0x16, 0x16, 0x46, 0x29, 0xb0, 0x07],
+                 input: [0x48, 0x0d, 0x39, 0x00, 0x6e, 0xe7, 0x62, 0xf2],
+                 output: [0x75, 0x55, 0xae, 0x39, 0xf5, 0x9b, 0x87, 0xbd]),
 
 
-        TestData(key:   [0x49, 0x79, 0x3E, 0xBC, 0x79, 0xB3, 0x25, 0x8F],
-                 input: [0x43, 0x75, 0x40, 0xC8, 0x69, 0x8F, 0x3C, 0xFA],
-                 output:[0x53, 0xC5, 0x5F, 0x9C, 0xB4, 0x9F, 0xC0, 0x19]),
+        TestData(key: [0x49, 0x79, 0x3e, 0xbc, 0x79, 0xb3, 0x25, 0x8f],
+                 input: [0x43, 0x75, 0x40, 0xc8, 0x69, 0x8f, 0x3c, 0xfa],
+                 output: [0x53, 0xc5, 0x5f, 0x9c, 0xb4, 0x9f, 0xc0, 0x19]),
 
 
-        TestData(key:   [0x4F, 0xB0, 0x5E, 0x15, 0x15, 0xAB, 0x73, 0xA7],
-                 input: [0x07, 0x2D, 0x43, 0xA0, 0x77, 0x07, 0x52, 0x92],
-                 output:[0x7A, 0x8E, 0x7B, 0xFA, 0x93, 0x7E, 0x89, 0xA3]),
+        TestData(key: [0x4f, 0xb0, 0x5e, 0x15, 0x15, 0xab, 0x73, 0xa7],
+                 input: [0x07, 0x2d, 0x43, 0xa0, 0x77, 0x07, 0x52, 0x92],
+                 output: [0x7a, 0x8e, 0x7b, 0xfa, 0x93, 0x7e, 0x89, 0xa3]),
 
 
-        TestData(key:   [0x49, 0xE9, 0x5D, 0x6D, 0x4C, 0xA2, 0x29, 0xBF],
-                 input: [0x02, 0xFE, 0x55, 0x77, 0x81, 0x17, 0xF1, 0x2A],
-                 output:[0xCF, 0x9C, 0x5D, 0x7A, 0x49, 0x86, 0xAD, 0xB5]),
+        TestData(key: [0x49, 0xe9, 0x5d, 0x6d, 0x4c, 0xa2, 0x29, 0xbf],
+                 input: [0x02, 0xfe, 0x55, 0x77, 0x81, 0x17, 0xf1, 0x2a],
+                 output: [0xcf, 0x9c, 0x5d, 0x7a, 0x49, 0x86, 0xad, 0xb5]),
 
 
-        TestData(key:   [0x01, 0x83, 0x10, 0xDC, 0x40, 0x9B, 0x26, 0xD6],
-                 input: [0x1D, 0x9D, 0x5C, 0x50, 0x18, 0xF7, 0x28, 0xC2],
-                 output:[0xD1, 0xAB, 0xB2, 0x90, 0x65, 0x8B, 0xC7, 0x78]),
+        TestData(key: [0x01, 0x83, 0x10, 0xdc, 0x40, 0x9b, 0x26, 0xd6],
+                 input: [0x1d, 0x9d, 0x5c, 0x50, 0x18, 0xf7, 0x28, 0xc2],
+                 output: [0xd1, 0xab, 0xb2, 0x90, 0x65, 0x8b, 0xc7, 0x78]),
 
 
-        TestData(key:   [0x1C, 0x58, 0x7F, 0x1C, 0x13, 0x92, 0x4F, 0xEF],
-                 input: [0x30, 0x55, 0x32, 0x28, 0x6D, 0x6F, 0x29, 0x5A],
-                 output:[0x55, 0xCB, 0x37, 0x74, 0xD1, 0x3E, 0xF2, 0x01]),
+        TestData(key: [0x1c, 0x58, 0x7f, 0x1c, 0x13, 0x92, 0x4f, 0xef],
+                 input: [0x30, 0x55, 0x32, 0x28, 0x6d, 0x6f, 0x29, 0x5a],
+                 output: [0x55, 0xcb, 0x37, 0x74, 0xd1, 0x3e, 0xf2, 0x01]),
 
 
-        TestData(key:   [0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01],
-                 input: [0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF],
-                 output:[0xFA, 0x34, 0xEC, 0x48, 0x47, 0xB2, 0x68, 0xB2]),
+        TestData(key: [0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01],
+                 input: [0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef],
+                 output: [0xfa, 0x34, 0xec, 0x48, 0x47, 0xb2, 0x68, 0xb2]),
 
 
-        TestData(key:   [0x1F, 0x1F, 0x1F, 0x1F, 0x0E, 0x0E, 0x0E, 0x0E],
-                 input: [0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF],
-                 output:[0xA7, 0x90, 0x79, 0x51, 0x08, 0xEA, 0x3C, 0xAE]),
+        TestData(key: [0x1f, 0x1f, 0x1f, 0x1f, 0x0e, 0x0e, 0x0e, 0x0e],
+                 input: [0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef],
+                 output: [0xa7, 0x90, 0x79, 0x51, 0x08, 0xea, 0x3c, 0xae]),
 
 
-        TestData(key:   [0xE0, 0xFE, 0xE0, 0xFE, 0xF1, 0xFE, 0xF1, 0xFE],
-                 input: [0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF],
-                 output:[0xC3, 0x9E, 0x07, 0x2D, 0x9F, 0xAC, 0x63, 0x1D]),
+        TestData(key: [0xe0, 0xfe, 0xe0, 0xfe, 0xf1, 0xfe, 0xf1, 0xfe],
+                 input: [0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef],
+                 output: [0xc3, 0x9e, 0x07, 0x2d, 0x9f, 0xac, 0x63, 0x1d]),
 
 
-        TestData(key:   [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00],
-                 input: [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF],
-                 output:[0x01, 0x49, 0x33, 0xE0, 0xCD, 0xAF, 0xF6, 0xE4]),
+        TestData(key: [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00],
+                 input: [0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff],
+                 output: [0x01, 0x49, 0x33, 0xe0, 0xcd, 0xaf, 0xf6, 0xe4]),
 
 
-        TestData(key:   [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF],
+        TestData(key: [0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff],
                  input: [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00],
                  input: [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00],
-                 output:[0xF2, 0x1E, 0x9A, 0x77, 0xB7, 0x1C, 0x49, 0xBC]),
+                 output: [0xf2, 0x1e, 0x9a, 0x77, 0xb7, 0x1c, 0x49, 0xbc]),
 
 
-        TestData(key:   [0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF],
+        TestData(key: [0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef],
                  input: [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00],
                  input: [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00],
-                 output:[0x24, 0x59, 0x46, 0x88, 0x57, 0x54, 0x36, 0x9A]),
+                 output: [0x24, 0x59, 0x46, 0x88, 0x57, 0x54, 0x36, 0x9a]),
 
 
-        TestData(key:   [0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10],
-                 input: [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF],
-                 output:[0x6B, 0x5C, 0x5A, 0x9C, 0x5D, 0x9E, 0x0A, 0x5A]),
-        ]
+        TestData(key: [0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10],
+                 input: [0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff],
+                 output: [0x6b, 0x5c, 0x5a, 0x9c, 0x5d, 0x9e, 0x0a, 0x5a]),
+    ]
 
 
     func testEncrypt() {
     func testEncrypt() {
-        for test in self.tests {
+        for test in tests {
             XCTAssertEqual(try Blowfish(key: test.key, blockMode: .ECB, padding: NoPadding()).encrypt(test.input), test.output)
             XCTAssertEqual(try Blowfish(key: test.key, blockMode: .ECB, padding: NoPadding()).encrypt(test.input), test.output)
         }
         }
     }
     }
 
 
     func testDecrypt() {
     func testDecrypt() {
-        for test in self.tests {
+        for test in tests {
             XCTAssertEqual(try Blowfish(key: test.key, blockMode: .ECB, padding: NoPadding()).decrypt(test.output), test.input)
             XCTAssertEqual(try Blowfish(key: test.key, blockMode: .ECB, padding: NoPadding()).decrypt(test.output), test.input)
         }
         }
     }
     }
@@ -209,7 +209,7 @@ extension BlowfishTests {
             ("testDecrypt", testDecrypt),
             ("testDecrypt", testDecrypt),
             ("testCBCZeroPadding", testCBCZeroPadding),
             ("testCBCZeroPadding", testCBCZeroPadding),
             ("testEncryptDecrypt", testEncryptDecrypt),
             ("testEncryptDecrypt", testEncryptDecrypt),
-            ("testDecryptCFB415",testDecryptCFB415),
+            ("testDecryptCFB415", testDecryptCFB415),
         ]
         ]
         return tests
         return tests
     }
     }

+ 12 - 14
Tests/CryptoSwiftTests/ChaCha20Tests.swift

@@ -17,7 +17,7 @@ final class ChaCha20Tests: XCTestCase {
             [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01],
             [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01],
             [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00],
             [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00],
             [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00],
             [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00],
-            [0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F],
+            [0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f],
         ]
         ]
 
 
         let ivs: [Array<UInt8>] = [
         let ivs: [Array<UInt8>] = [
@@ -36,7 +36,7 @@ final class ChaCha20Tests: XCTestCase {
             "F798A189F195E66982105FFB640BB7757F579DA31602FC93EC01AC56F85AC3C134A4547B733B46413042C9440049176905D3BE59EA1C53F15916155C2BE8241A38008B9A26BC35941E2444177C8ADE6689DE95264986D95889FB60E84629C9BD9A5ACB1CC118BE563EB9B3A4A472F82E09A7E778492B562EF7130E88DFE031C79DB9D4F7C7A899151B9A475032B63FC385245FE054E3DD5A97A5F576FE064025D3CE042C566AB2C507B138DB853E3D6959660996546CC9C4A6EAFDC777C040D70EAF46F76DAD3979E5C5360C3317166A1C894C94A371876A94DF7628FE4EAAF2CCB27D5AAAE0AD7AD0F9D4B6AD3B54098746D4524D38407A6DEB3AB78FAB78C9",
             "F798A189F195E66982105FFB640BB7757F579DA31602FC93EC01AC56F85AC3C134A4547B733B46413042C9440049176905D3BE59EA1C53F15916155C2BE8241A38008B9A26BC35941E2444177C8ADE6689DE95264986D95889FB60E84629C9BD9A5ACB1CC118BE563EB9B3A4A472F82E09A7E778492B562EF7130E88DFE031C79DB9D4F7C7A899151B9A475032B63FC385245FE054E3DD5A97A5F576FE064025D3CE042C566AB2C507B138DB853E3D6959660996546CC9C4A6EAFDC777C040D70EAF46F76DAD3979E5C5360C3317166A1C894C94A371876A94DF7628FE4EAAF2CCB27D5AAAE0AD7AD0F9D4B6AD3B54098746D4524D38407A6DEB3AB78FAB78C9",
         ]
         ]
 
 
-        for idx in 0 ..< keys.count {
+        for idx in 0..<keys.count {
             let expectedHex = expectedHexes[idx]
             let expectedHex = expectedHexes[idx]
             let message = Array<UInt8>(repeating: 0, count: (expectedHex.characters.count / 2))
             let message = Array<UInt8>(repeating: 0, count: (expectedHex.characters.count / 2))
 
 
@@ -57,7 +57,7 @@ final class ChaCha20Tests: XCTestCase {
 
 
     func testCore() {
     func testCore() {
         let key: Array<UInt8> = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31]
         let key: Array<UInt8> = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31]
-        var counter: Array<UInt8> = [1,0,0,0,0,0,0,9,0,0,0,74,0,0,0,0]
+        var counter: Array<UInt8> = [1, 0, 0, 0, 0, 0, 0, 9, 0, 0, 0, 74, 0, 0, 0, 0]
         let input = Array<UInt8>.init(repeating: 0, count: 129)
         let input = Array<UInt8>.init(repeating: 0, count: 129)
         let chacha = try! ChaCha20(key: key, iv: Array(key[4..<16]))
         let chacha = try! ChaCha20(key: key, iv: Array(key[4..<16]))
         let result = chacha.process(bytes: input, counter: &counter, key: key)
         let result = chacha.process(bytes: input, counter: &counter, key: key)
@@ -67,7 +67,7 @@ final class ChaCha20Tests: XCTestCase {
     func testVector1Py() {
     func testVector1Py() {
         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 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, 0x00, 0x00, 0x00, 0x00]
         let iv: Array<UInt8> = [0x00, 0x00, 0x00, 0x00, 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 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>(repeating: 0, count: expected.count)
         let message = Array<UInt8>(repeating: 0, count: expected.count)
 
 
         do {
         do {
@@ -79,7 +79,7 @@ final class ChaCha20Tests: XCTestCase {
     }
     }
 
 
     func testChaCha20EncryptPartial() {
     func testChaCha20EncryptPartial() {
-        let key: Array<UInt8> = [0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F]
+        let key: Array<UInt8> = [0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f]
         let iv: Array<UInt8> = [0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07]
         let iv: Array<UInt8> = [0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07]
         let expectedHex = "F798A189F195E66982105FFB640BB7757F579DA31602FC93EC01AC56F85AC3C134A4547B733B46413042C9440049176905D3BE59EA1C53F15916155C2BE8241A38008B9A26BC35941E2444177C8ADE6689DE95264986D95889FB60E84629C9BD9A5ACB1CC118BE563EB9B3A4A472F82E09A7E778492B562EF7130E88DFE031C79DB9D4F7C7A899151B9A475032B63FC385245FE054E3DD5A97A5F576FE064025D3CE042C566AB2C507B138DB853E3D6959660996546CC9C4A6EAFDC777C040D70EAF46F76DAD3979E5C5360C3317166A1C894C94A371876A94DF7628FE4EAAF2CCB27D5AAAE0AD7AD0F9D4B6AD3B54098746D4524D38407A6DEB3AB78FAB78C9"
         let expectedHex = "F798A189F195E66982105FFB640BB7757F579DA31602FC93EC01AC56F85AC3C134A4547B733B46413042C9440049176905D3BE59EA1C53F15916155C2BE8241A38008B9A26BC35941E2444177C8ADE6689DE95264986D95889FB60E84629C9BD9A5ACB1CC118BE563EB9B3A4A472F82E09A7E778492B562EF7130E88DFE031C79DB9D4F7C7A899151B9A475032B63FC385245FE054E3DD5A97A5F576FE064025D3CE042C566AB2C507B138DB853E3D6959660996546CC9C4A6EAFDC777C040D70EAF46F76DAD3979E5C5360C3317166A1C894C94A371876A94DF7628FE4EAAF2CCB27D5AAAE0AD7AD0F9D4B6AD3B54098746D4524D38407A6DEB3AB78FAB78C9"
         let plaintext: Array<UInt8> = Array<UInt8>(repeating: 0, count: (expectedHex.characters.count / 2))
         let plaintext: Array<UInt8> = Array<UInt8>(repeating: 0, count: (expectedHex.characters.count / 2))
@@ -89,10 +89,10 @@ final class ChaCha20Tests: XCTestCase {
 
 
             var ciphertext = Array<UInt8>()
             var ciphertext = Array<UInt8>()
             var encryptor = cipher.makeEncryptor()
             var encryptor = cipher.makeEncryptor()
-            ciphertext += try encryptor.update(withBytes: Array(plaintext[0 ..< 8]))
-            ciphertext += try encryptor.update(withBytes: Array(plaintext[8 ..< 16]))
-            ciphertext += try encryptor.update(withBytes: Array(plaintext[16 ..< 80]))
-            ciphertext += try encryptor.update(withBytes: Array(plaintext[80 ..< 256]))
+            ciphertext += try encryptor.update(withBytes: Array(plaintext[0..<8]))
+            ciphertext += try encryptor.update(withBytes: Array(plaintext[8..<16]))
+            ciphertext += try encryptor.update(withBytes: Array(plaintext[16..<80]))
+            ciphertext += try encryptor.update(withBytes: Array(plaintext[80..<256]))
             ciphertext += try encryptor.finish()
             ciphertext += try encryptor.finish()
             XCTAssertEqual(Array<UInt8>(hex: expectedHex), ciphertext)
             XCTAssertEqual(Array<UInt8>(hex: expectedHex), ciphertext)
         } catch {
         } catch {
@@ -106,12 +106,12 @@ final class ChaCha20Tests: XCTestCase {
     extension ChaCha20Tests {
     extension ChaCha20Tests {
 
 
         func testChaCha20Performance() {
         func testChaCha20Performance() {
-            let key: Array<UInt8> = [0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F]
+            let key: Array<UInt8> = [0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f]
             let iv: Array<UInt8> = [0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07]
             let iv: Array<UInt8> = [0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07]
             let message = Array<UInt8>(repeating: 7, count: 1024)
             let message = Array<UInt8>(repeating: 7, count: 1024)
             measureMetrics([XCTPerformanceMetric.wallClockTime], automaticallyStartMeasuring: true, for: { () -> Void in
             measureMetrics([XCTPerformanceMetric.wallClockTime], automaticallyStartMeasuring: true, for: { () -> Void in
                 do {
                 do {
-                    let _ = try ChaCha20(key: key, iv: iv).encrypt(message)
+                    _ = try ChaCha20(key: key, iv: iv).encrypt(message)
                 } catch {
                 } catch {
                     XCTFail()
                     XCTFail()
                 }
                 }
@@ -132,9 +132,7 @@ extension ChaCha20Tests {
         ]
         ]
 
 
         #if !CI
         #if !CI
-            tests += [
-                ("testChaCha20Performance", testChaCha20Performance),
-            ]
+            tests += [("testChaCha20Performance", testChaCha20Performance)]
         #endif
         #endif
 
 
         return tests
         return tests

+ 27 - 14
Tests/CryptoSwiftTests/DigestTests.swift

@@ -103,8 +103,8 @@ final class DigestTests: XCTestCase {
     func testMD5Updates() {
     func testMD5Updates() {
         do {
         do {
             var hash = MD5()
             var hash = MD5()
-            let _ = try hash.update(withBytes: [0x31, 0x32])
-            let _ = try hash.update(withBytes: [0x33])
+            _ = try hash.update(withBytes: [0x31, 0x32])
+            _ = try hash.update(withBytes: [0x33])
             let result = try hash.finish()
             let result = try hash.finish()
             XCTAssertEqual(result, [0x20, 0x2c, 0xb9, 0x62, 0xac, 0x59, 0x07, 0x5b, 0x96, 0x4b, 0x07, 0x15, 0x2d, 0x23, 0x4b, 0x70])
             XCTAssertEqual(result, [0x20, 0x2c, 0xb9, 0x62, 0xac, 0x59, 0x07, 0x5b, 0x96, 0x4b, 0x07, 0x15, 0x2d, 0x23, 0x4b, 0x70])
         } catch {
         } catch {
@@ -115,8 +115,8 @@ final class DigestTests: XCTestCase {
     func testSHA1Updatable1() {
     func testSHA1Updatable1() {
         do {
         do {
             var hash = SHA1()
             var hash = SHA1()
-            let _ = try hash.update(withBytes: [0x31, 0x32])
-            let _ = try hash.update(withBytes: [0x33])
+            _ = try hash.update(withBytes: [0x31, 0x32])
+            _ = try hash.update(withBytes: [0x33])
             XCTAssertEqual(try hash.finish().toHexString(), "40bd001563085fc35165329ea1ff5c5ecbdbbeef", "Failed")
             XCTAssertEqual(try hash.finish().toHexString(), "40bd001563085fc35165329ea1ff5c5ecbdbbeef", "Failed")
         } catch {
         } catch {
             XCTFail()
             XCTFail()
@@ -126,9 +126,9 @@ final class DigestTests: XCTestCase {
     func testSHA1Updatable2() {
     func testSHA1Updatable2() {
         do {
         do {
             var hash = SHA1()
             var hash = SHA1()
-            let _ = try hash.update(withBytes: [0x31, 0x32])
-            let _ = try hash.update(withBytes: [0x33])
-            let _ = try hash.update(withBytes: Array<UInt8>(repeating: 0x33, count: 64))
+            _ = try hash.update(withBytes: [0x31, 0x32])
+            _ = try hash.update(withBytes: [0x33])
+            _ = try hash.update(withBytes: Array<UInt8>(repeating: 0x33, count: 64))
             XCTAssertEqual(try hash.finish().toHexString(), "0e659367eff83a6b868a35b96ac305b270025e86", "Failed")
             XCTAssertEqual(try hash.finish().toHexString(), "0e659367eff83a6b868a35b96ac305b270025e86", "Failed")
         } catch {
         } catch {
             XCTFail()
             XCTFail()
@@ -152,7 +152,7 @@ final class DigestTests: XCTestCase {
 
 
     func testCRC16() {
     func testCRC16() {
         let result = Checksum.crc16([49, 50, 51, 52, 53, 54, 55, 56, 57] as Array<UInt8>)
         let result = Checksum.crc16([49, 50, 51, 52, 53, 54, 55, 56, 57] as Array<UInt8>)
-        XCTAssert(result == 0xBB3D, "CRC16 failed")
+        XCTAssert(result == 0xbb3d, "CRC16 failed")
     }
     }
 
 
     func testChecksum() {
     func testChecksum() {
@@ -166,22 +166,35 @@ final class DigestTests: XCTestCase {
     extension DigestTests {
     extension DigestTests {
 
 
         func testMD5Performance() {
         func testMD5Performance() {
-            self.measureMetrics([XCTPerformanceMetric.wallClockTime], automaticallyStartMeasuring: false, for: { () -> Void in
+            measureMetrics([XCTPerformanceMetric.wallClockTime], automaticallyStartMeasuring: false) {
                 let arr = Array<UInt8>(repeating: 200, count: 1024 * 1024)
                 let arr = Array<UInt8>(repeating: 200, count: 1024 * 1024)
                 self.startMeasuring()
                 self.startMeasuring()
                 _ = Digest.md5(arr)
                 _ = Digest.md5(arr)
                 self.stopMeasuring()
                 self.stopMeasuring()
-            })
+            }
         }
         }
 
 
         func testSHA1Performance() {
         func testSHA1Performance() {
-            self.measure {
-                for _ in 0 ..< 10_000 {
-                    let _ = "".sha1()
-                }
+            measureMetrics([XCTPerformanceMetric.wallClockTime], automaticallyStartMeasuring: false) {
+                let arr = Array<UInt8>(repeating: 200, count: 1024 * 1024)
+                self.startMeasuring()
+                _ = Digest.sha1(arr)
+                self.stopMeasuring()
+            }
+        }
+
+        // Keep it to compare
+        func testSHA1PerformanceCC() {
+            measureMetrics([XCTPerformanceMetric.wallClockTime], automaticallyStartMeasuring: false) {
+                let arr = Array<UInt8>(repeating: 200, count: 1024 * 1024)
+                self.startMeasuring()
+                var digest = Array<UInt8>(repeating: 0, count: Int(CC_SHA1_DIGEST_LENGTH))
+                CC_SHA1(arr, CC_LONG(arr.count), &digest)
+                self.stopMeasuring()
             }
             }
         }
         }
     }
     }
+
 #endif
 #endif
 
 
 extension DigestTests {
 extension DigestTests {

+ 7 - 10
Tests/CryptoSwiftTests/ExtensionsTest.swift

@@ -29,8 +29,8 @@ final class ExtensionsTest: XCTestCase {
         let result = chunk.toUInt32Array()
         let result = chunk.toUInt32Array()
 
 
         XCTAssert(result.count == 2, "Invalid conversion")
         XCTAssert(result.count == 2, "Invalid conversion")
-        XCTAssert(result[0] == 117506305, "Invalid conversion")
-        XCTAssert(result[1] == 84148994, "Invalid conversion")
+        XCTAssert(result[0] == 117_506_305, "Invalid conversion")
+        XCTAssert(result[1] == 84_148_994, "Invalid conversion")
     }
     }
 
 
     func testDataInit() {
     func testDataInit() {
@@ -75,17 +75,16 @@ final class ExtensionsTest: XCTestCase {
         let hex = array.toHexString()
         let hex = array.toHexString()
         XCTAssertEqual(str, hex)
         XCTAssertEqual(str, hex)
     }
     }
-    
-    func testArrayInitHexPerformance(){
+
+    func testArrayInitHexPerformance() {
         var str = "b1b2b3b3b3b3b3b3b1b2b3b3b3b3b3b3"
         var str = "b1b2b3b3b3b3b3b3b1b2b3b3b3b3b3b3"
-        for _ in 0...12{
+        for _ in 0...12 {
             str += str
             str += str
         }
         }
         measure {
         measure {
-            let _ = Array<UInt8>(hex: str)
+            _ = Array<UInt8>(hex: str)
         }
         }
     }
     }
-    
 }
 }
 
 
 #if !CI
 #if !CI
@@ -117,9 +116,7 @@ extension ExtensionsTest {
         ]
         ]
 
 
         #if !CI
         #if !CI
-            tests += [
-                ("testArrayChunksPerformance", testArrayChunksPerformance),
-            ]
+            tests += [("testArrayChunksPerformance", testArrayChunksPerformance)]
         #endif
         #endif
         return tests
         return tests
     }
     }

+ 16 - 19
Tests/CryptoSwiftTests/PBKDF.swift

@@ -12,8 +12,8 @@ import XCTest
 class PBKDF: XCTestCase {
 class PBKDF: XCTestCase {
 
 
     func testPBKDF1() {
     func testPBKDF1() {
-        let password: Array<UInt8> = [0x70, 0x61, 0x73, 0x73, 0x77, 0x6F, 0x72, 0x64]
-        let salt: Array<UInt8> = [0x78, 0x57, 0x8E, 0x5A, 0x5D, 0x63, 0xCB, 0x06]
+        let password: Array<UInt8> = [0x70, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64]
+        let salt: Array<UInt8> = [0x78, 0x57, 0x8e, 0x5a, 0x5d, 0x63, 0xcb, 0x06]
         let value = try! PKCS5.PBKDF1(password: password, salt: salt, iterations: 1000, keyLength: 16).calculate()
         let value = try! PKCS5.PBKDF1(password: password, salt: salt, iterations: 1000, keyLength: 16).calculate()
         XCTAssertEqual(value.toHexString(), "dc19847e05c64d2faf10ebfb4a3d2a20")
         XCTAssertEqual(value.toHexString(), "dc19847e05c64d2faf10ebfb4a3d2a20")
     }
     }
@@ -21,15 +21,15 @@ class PBKDF: XCTestCase {
     func testPBKDF2() {
     func testPBKDF2() {
         // P = "password", S = "salt", c = 1, dkLen = 20
         // P = "password", S = "salt", c = 1, dkLen = 20
         XCTAssertEqual([0x0c, 0x60, 0xc8, 0x0f, 0x96, 0x1f, 0x0e, 0x71, 0xf3, 0xa9, 0xb5, 0x24, 0xaf, 0x60, 0x12, 0x06, 0x2f, 0xe0, 0x37, 0xa6],
         XCTAssertEqual([0x0c, 0x60, 0xc8, 0x0f, 0x96, 0x1f, 0x0e, 0x71, 0xf3, 0xa9, 0xb5, 0x24, 0xaf, 0x60, 0x12, 0x06, 0x2f, 0xe0, 0x37, 0xa6],
-                       try PKCS5.PBKDF2(password: [0x70, 0x61, 0x73, 0x73, 0x77, 0x6F, 0x72, 0x64], salt: [0x73, 0x61, 0x6C, 0x74], iterations: 1, keyLength: 20, variant: .sha1).calculate())
+                       try PKCS5.PBKDF2(password: [0x70, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64], salt: [0x73, 0x61, 0x6c, 0x74], iterations: 1, keyLength: 20, variant: .sha1).calculate())
 
 
         // P = "password", S = "salt", c = 2, dkLen = 20
         // P = "password", S = "salt", c = 2, dkLen = 20
         XCTAssertEqual([0xea, 0x6c, 0x01, 0x4d, 0xc7, 0x2d, 0x6f, 0x8c, 0xcd, 0x1e, 0xd9, 0x2a, 0xce, 0x1d, 0x41, 0xf0, 0xd8, 0xde, 0x89, 0x57],
         XCTAssertEqual([0xea, 0x6c, 0x01, 0x4d, 0xc7, 0x2d, 0x6f, 0x8c, 0xcd, 0x1e, 0xd9, 0x2a, 0xce, 0x1d, 0x41, 0xf0, 0xd8, 0xde, 0x89, 0x57],
-                       try PKCS5.PBKDF2(password: [0x70, 0x61, 0x73, 0x73, 0x77, 0x6F, 0x72, 0x64], salt: [0x73, 0x61, 0x6C, 0x74], iterations: 2, keyLength: 20, variant: .sha1).calculate())
+                       try PKCS5.PBKDF2(password: [0x70, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64], salt: [0x73, 0x61, 0x6c, 0x74], iterations: 2, keyLength: 20, variant: .sha1).calculate())
 
 
         // P = "password", S = "salt", c = 4096, dkLen = 20
         // P = "password", S = "salt", c = 4096, dkLen = 20
         XCTAssertEqual([0x4b, 0x00, 0x79, 0x01, 0xb7, 0x65, 0x48, 0x9a, 0xbe, 0xad, 0x49, 0xd9, 0x26, 0xf7, 0x21, 0xd0, 0x65, 0xa4, 0x29, 0xc1],
         XCTAssertEqual([0x4b, 0x00, 0x79, 0x01, 0xb7, 0x65, 0x48, 0x9a, 0xbe, 0xad, 0x49, 0xd9, 0x26, 0xf7, 0x21, 0xd0, 0x65, 0xa4, 0x29, 0xc1],
-                       try PKCS5.PBKDF2(password: [0x70, 0x61, 0x73, 0x73, 0x77, 0x6F, 0x72, 0x64], salt: [0x73, 0x61, 0x6C, 0x74], iterations: 4096, keyLength: 20, variant: .sha1).calculate())
+                       try PKCS5.PBKDF2(password: [0x70, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64], salt: [0x73, 0x61, 0x6c, 0x74], iterations: 4096, keyLength: 20, variant: .sha1).calculate())
 
 
         // P = "password", S = "salt", c = 16777216, dkLen = 20
         // P = "password", S = "salt", c = 16777216, dkLen = 20
         // Commented because it takes a lot of time with Debug build to finish.
         // Commented because it takes a lot of time with Debug build to finish.
@@ -38,11 +38,11 @@ class PBKDF: XCTestCase {
 
 
         // P = "passwordPASSWORDpassword", S = "saltSALTsaltSALTsaltSALTsaltSALTsalt", c = 4096, dkLen = 25
         // P = "passwordPASSWORDpassword", S = "saltSALTsaltSALTsaltSALTsaltSALTsalt", c = 4096, dkLen = 25
         XCTAssertEqual([0x3d, 0x2e, 0xec, 0x4f, 0xe4, 0x1c, 0x84, 0x9b, 0x80, 0xc8, 0xd8, 0x36, 0x62, 0xc0, 0xe4, 0x4a, 0x8b, 0x29, 0x1a, 0x96, 0x4c, 0xf2, 0xf0, 0x70, 0x38],
         XCTAssertEqual([0x3d, 0x2e, 0xec, 0x4f, 0xe4, 0x1c, 0x84, 0x9b, 0x80, 0xc8, 0xd8, 0x36, 0x62, 0xc0, 0xe4, 0x4a, 0x8b, 0x29, 0x1a, 0x96, 0x4c, 0xf2, 0xf0, 0x70, 0x38],
-                       try PKCS5.PBKDF2(password: [0x70, 0x61, 0x73, 0x73, 0x77, 0x6F, 0x72, 0x64, 0x50, 0x41, 0x53, 0x53, 0x57, 0x4F, 0x52, 0x44, 0x70, 0x61, 0x73, 0x73, 0x77, 0x6F, 0x72, 0x64], salt: [0x73, 0x61, 0x6C, 0x74, 0x53, 0x41, 0x4C, 0x54, 0x73, 0x61, 0x6C, 0x74, 0x53, 0x41, 0x4C, 0x54, 0x73, 0x61, 0x6C, 0x74, 0x53, 0x41, 0x4C, 0x54, 0x73, 0x61, 0x6C, 0x74, 0x53, 0x41, 0x4C, 0x54, 0x73, 0x61, 0x6C, 0x74], iterations: 4096, keyLength: 25, variant: .sha1).calculate())
+                       try PKCS5.PBKDF2(password: [0x70, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x50, 0x41, 0x53, 0x53, 0x57, 0x4f, 0x52, 0x44, 0x70, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64], salt: [0x73, 0x61, 0x6c, 0x74, 0x53, 0x41, 0x4c, 0x54, 0x73, 0x61, 0x6c, 0x74, 0x53, 0x41, 0x4c, 0x54, 0x73, 0x61, 0x6c, 0x74, 0x53, 0x41, 0x4c, 0x54, 0x73, 0x61, 0x6c, 0x74, 0x53, 0x41, 0x4c, 0x54, 0x73, 0x61, 0x6c, 0x74], iterations: 4096, keyLength: 25, variant: .sha1).calculate())
 
 
         // P = "pass\0word", S = "sa\0lt", c = 4096, dkLen = 16
         // P = "pass\0word", S = "sa\0lt", c = 4096, dkLen = 16
         XCTAssertEqual([0x56, 0xfa, 0x6a, 0xa7, 0x55, 0x48, 0x09, 0x9d, 0xcc, 0x37, 0xd7, 0xf0, 0x34, 0x25, 0xe0, 0xc3],
         XCTAssertEqual([0x56, 0xfa, 0x6a, 0xa7, 0x55, 0x48, 0x09, 0x9d, 0xcc, 0x37, 0xd7, 0xf0, 0x34, 0x25, 0xe0, 0xc3],
-                       try PKCS5.PBKDF2(password: [0x70, 0x61, 0x73, 0x73, 0x00, 0x77, 0x6F, 0x72, 0x64], salt: [0x73, 0x61, 0x00, 0x6C, 0x74], iterations: 4096, keyLength: 16, variant: .sha1).calculate())
+                       try PKCS5.PBKDF2(password: [0x70, 0x61, 0x73, 0x73, 0x00, 0x77, 0x6f, 0x72, 0x64], salt: [0x73, 0x61, 0x00, 0x6c, 0x74], iterations: 4096, keyLength: 16, variant: .sha1).calculate())
     }
     }
 
 
     func testPBKDF2Length() {
     func testPBKDF2Length() {
@@ -53,29 +53,26 @@ class PBKDF: XCTestCase {
     }
     }
 
 
     #if !CI
     #if !CI
-    func testPerformance() {
-        let password: Array<UInt8> = Array("s33krit".utf8)
-        let salt: Array<UInt8> = Array("nacl".utf8)
-        measureMetrics([XCTPerformanceMetric.wallClockTime], automaticallyStartMeasuring: true, for: { () -> Void in
-            let _ = try! PKCS5.PBKDF2(password: password, salt: salt, iterations: 65536, keyLength: 32, variant: .sha1).calculate()
-        })
-    }
+        func testPerformance() {
+            let password: Array<UInt8> = Array("s33krit".utf8)
+            let salt: Array<UInt8> = Array("nacl".utf8)
+            measureMetrics([XCTPerformanceMetric.wallClockTime], automaticallyStartMeasuring: true, for: { () -> Void in
+                _ = try! PKCS5.PBKDF2(password: password, salt: salt, iterations: 65536, keyLength: 32, variant: .sha1).calculate()
+            })
+        }
     #endif
     #endif
 
 
     static func allTests() -> [(String, (PBKDF) -> () -> Void)] {
     static func allTests() -> [(String, (PBKDF) -> () -> Void)] {
         var tests = [
         var tests = [
             ("testPBKDF1", testPBKDF1),
             ("testPBKDF1", testPBKDF1),
             ("testPBKDF2", testPBKDF2),
             ("testPBKDF2", testPBKDF2),
-            ("testPBKDF2Length", testPBKDF2Length)
+            ("testPBKDF2Length", testPBKDF2Length),
         ]
         ]
 
 
         #if !CI
         #if !CI
-            tests += [
-                ("testPerformance", testPerformance)
-            ]
+            tests += [("testPerformance", testPerformance)]
         #endif
         #endif
 
 
         return tests
         return tests
     }
     }
-
 }
 }

+ 4 - 4
Tests/CryptoSwiftTests/Poly1305Tests.swift

@@ -25,14 +25,14 @@ final class Poly1305Tests: XCTestCase {
 
 
     // https://github.com/krzyzanowskim/CryptoSwift/issues/183
     // https://github.com/krzyzanowskim/CryptoSwift/issues/183
     func testIssue183() {
     func testIssue183() {
-        let key:[UInt8] = [111, 53, 197, 181, 1, 92, 67, 199, 37, 92, 76, 167, 12, 35, 75, 226, 198, 34, 107, 84, 79, 6, 231, 10, 25, 221, 14, 155, 81, 244, 15, 203]
-        let message:[UInt8] = [208, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 162, 210, 40, 78, 3, 161, 87, 187, 96, 253, 104, 187, 87, 87, 249, 56, 5, 156, 122, 121, 196, 192, 254, 58, 98, 22, 47, 151, 205, 201, 108, 143, 197, 99, 182, 109, 59, 63, 172, 111, 120, 185, 175, 129, 59, 126, 68, 140, 237, 126, 175, 49, 224, 249, 245, 37, 75, 252, 69, 215, 171, 27, 163, 16, 185, 239, 184, 144, 37, 131, 242, 12, 90, 134, 24, 237, 209, 127, 71, 86, 122, 173, 238, 73, 186, 58, 102, 112, 90, 217, 243, 251, 110, 85, 106, 18, 172, 167, 179, 173, 73, 125, 9, 129, 132, 80, 70, 4, 254, 178, 211, 200, 207, 231, 232, 17, 176, 127, 153, 120, 71, 164, 139, 56, 106, 71, 96, 79, 11, 213, 243, 66, 53, 167, 108, 233, 250, 136, 69, 190, 191, 12, 136, 24, 157, 202, 49, 158, 152, 150, 34, 88, 132, 112, 74, 168, 153, 116, 31, 7, 61, 60, 22, 199, 108, 187, 209, 114, 234, 185, 247, 41, 68, 184, 95, 169, 60, 126, 73, 59, 54, 126, 162, 90, 18, 32, 230, 123, 2, 40, 74, 177, 127, 219, 93, 186, 22, 75, 251, 101, 95, 160, 68, 235, 77, 2, 10, 202, 2, 0, 0, 0, 0, 0, 0, 0, 208, 0, 0, 0, 0, 0, 0, 0]
-        let expectedMac:[UInt8] = [68, 216, 92, 163, 164, 144, 55, 43, 185, 18, 83, 92, 41, 133, 72, 168]
+        let key: [UInt8] = [111, 53, 197, 181, 1, 92, 67, 199, 37, 92, 76, 167, 12, 35, 75, 226, 198, 34, 107, 84, 79, 6, 231, 10, 25, 221, 14, 155, 81, 244, 15, 203]
+        let message: [UInt8] = [208, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 162, 210, 40, 78, 3, 161, 87, 187, 96, 253, 104, 187, 87, 87, 249, 56, 5, 156, 122, 121, 196, 192, 254, 58, 98, 22, 47, 151, 205, 201, 108, 143, 197, 99, 182, 109, 59, 63, 172, 111, 120, 185, 175, 129, 59, 126, 68, 140, 237, 126, 175, 49, 224, 249, 245, 37, 75, 252, 69, 215, 171, 27, 163, 16, 185, 239, 184, 144, 37, 131, 242, 12, 90, 134, 24, 237, 209, 127, 71, 86, 122, 173, 238, 73, 186, 58, 102, 112, 90, 217, 243, 251, 110, 85, 106, 18, 172, 167, 179, 173, 73, 125, 9, 129, 132, 80, 70, 4, 254, 178, 211, 200, 207, 231, 232, 17, 176, 127, 153, 120, 71, 164, 139, 56, 106, 71, 96, 79, 11, 213, 243, 66, 53, 167, 108, 233, 250, 136, 69, 190, 191, 12, 136, 24, 157, 202, 49, 158, 152, 150, 34, 88, 132, 112, 74, 168, 153, 116, 31, 7, 61, 60, 22, 199, 108, 187, 209, 114, 234, 185, 247, 41, 68, 184, 95, 169, 60, 126, 73, 59, 54, 126, 162, 90, 18, 32, 230, 123, 2, 40, 74, 177, 127, 219, 93, 186, 22, 75, 251, 101, 95, 160, 68, 235, 77, 2, 10, 202, 2, 0, 0, 0, 0, 0, 0, 0, 208, 0, 0, 0, 0, 0, 0, 0]
+        let expectedMac: [UInt8] = [68, 216, 92, 163, 164, 144, 55, 43, 185, 18, 83, 92, 41, 133, 72, 168]
         XCTAssertEqual(try message.authenticate(with: Poly1305(key: key)), expectedMac)
         XCTAssertEqual(try message.authenticate(with: Poly1305(key: key)), expectedMac)
     }
     }
 
 
     static let allTests = [
     static let allTests = [
         ("testPoly1305", testPoly1305),
         ("testPoly1305", testPoly1305),
-        ("testIssue183", testIssue183)
+        ("testIssue183", testIssue183),
     ]
     ]
 }
 }

+ 24 - 27
Tests/CryptoSwiftTests/RabbitTests.swift

@@ -31,32 +31,31 @@ class RabbitTests: XCTestCase {
 
 
     func testRabbitWithoutIV() {
     func testRabbitWithoutIV() {
         // Examples from Appendix A: Test Vectors in http://tools.ietf.org/rfc/rfc4503.txt
         // Examples from Appendix A: Test Vectors in http://tools.ietf.org/rfc/rfc4503.txt
-        let cases: [(Array<UInt8>, Array<UInt8>)] = [
-            // First case
+        let cases: [(Array<UInt8>, Array<UInt8>)] = [ // First case
             (
             (
                 [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],
                 [
                 [
-                    0xB1, 0x57, 0x54, 0xF0, 0x36, 0xA5, 0xD6, 0xEC, 0xF5, 0x6B, 0x45, 0x26, 0x1C, 0x4A, 0xF7, 0x02,
-                    0x88, 0xE8, 0xD8, 0x15, 0xC5, 0x9C, 0x0C, 0x39, 0x7B, 0x69, 0x6C, 0x47, 0x89, 0xC6, 0x8A, 0xA7,
-                    0xF4, 0x16, 0xA1, 0xC3, 0x70, 0x0C, 0xD4, 0x51, 0xDA, 0x68, 0xD1, 0x88, 0x16, 0x73, 0xD6, 0x96,
+                    0xb1, 0x57, 0x54, 0xf0, 0x36, 0xa5, 0xd6, 0xec, 0xf5, 0x6b, 0x45, 0x26, 0x1c, 0x4a, 0xf7, 0x02,
+                    0x88, 0xe8, 0xd8, 0x15, 0xc5, 0x9c, 0x0c, 0x39, 0x7b, 0x69, 0x6c, 0x47, 0x89, 0xc6, 0x8a, 0xa7,
+                    0xf4, 0x16, 0xa1, 0xc3, 0x70, 0x0c, 0xd4, 0x51, 0xda, 0x68, 0xd1, 0x88, 0x16, 0x73, 0xd6, 0x96,
                 ]
                 ]
             ),
             ),
             // Second case
             // Second case
             (
             (
-                [0x91, 0x28, 0x13, 0x29, 0x2E, 0x3D, 0x36, 0xFE, 0x3B, 0xFC, 0x62, 0xF1, 0xDC, 0x51, 0xC3, 0xAC],
+                [0x91, 0x28, 0x13, 0x29, 0x2e, 0x3d, 0x36, 0xfe, 0x3b, 0xfc, 0x62, 0xf1, 0xdc, 0x51, 0xc3, 0xac],
                 [
                 [
-                    0x3D, 0x2D, 0xF3, 0xC8, 0x3E, 0xF6, 0x27, 0xA1, 0xE9, 0x7F, 0xC3, 0x84, 0x87, 0xE2, 0x51, 0x9C,
-                    0xF5, 0x76, 0xCD, 0x61, 0xF4, 0x40, 0x5B, 0x88, 0x96, 0xBF, 0x53, 0xAA, 0x85, 0x54, 0xFC, 0x19,
-                    0xE5, 0x54, 0x74, 0x73, 0xFB, 0xDB, 0x43, 0x50, 0x8A, 0xE5, 0x3B, 0x20, 0x20, 0x4D, 0x4C, 0x5E,
+                    0x3d, 0x2d, 0xf3, 0xc8, 0x3e, 0xf6, 0x27, 0xa1, 0xe9, 0x7f, 0xc3, 0x84, 0x87, 0xe2, 0x51, 0x9c,
+                    0xf5, 0x76, 0xcd, 0x61, 0xf4, 0x40, 0x5b, 0x88, 0x96, 0xbf, 0x53, 0xaa, 0x85, 0x54, 0xfc, 0x19,
+                    0xe5, 0x54, 0x74, 0x73, 0xfb, 0xdb, 0x43, 0x50, 0x8a, 0xe5, 0x3b, 0x20, 0x20, 0x4d, 0x4c, 0x5e,
                 ]
                 ]
             ),
             ),
             // Third case
             // Third case
             (
             (
-                [0x83, 0x95, 0x74, 0x15, 0x87, 0xE0, 0xC7, 0x33, 0xE9, 0xE9, 0xAB, 0x01, 0xC0, 0x9B, 0x00, 0x43,],
+                [0x83, 0x95, 0x74, 0x15, 0x87, 0xe0, 0xc7, 0x33, 0xe9, 0xe9, 0xab, 0x01, 0xc0, 0x9b, 0x00, 0x43],
                 [
                 [
-                    0x0C, 0xB1, 0x0D, 0xCD, 0xA0, 0x41, 0xCD, 0xAC, 0x32, 0xEB, 0x5C, 0xFD, 0x02, 0xD0, 0x60, 0x9B,
-                    0x95, 0xFC, 0x9F, 0xCA, 0x0F, 0x17, 0x01, 0x5A, 0x7B, 0x70, 0x92, 0x11, 0x4C, 0xFF, 0x3E, 0xAD,
-                    0x96, 0x49, 0xE5, 0xDE, 0x8B, 0xFC, 0x7F, 0x3F, 0x92, 0x41, 0x47, 0xAD, 0x3A, 0x94, 0x74, 0x28,
+                    0x0c, 0xb1, 0x0d, 0xcd, 0xa0, 0x41, 0xcd, 0xac, 0x32, 0xeb, 0x5c, 0xfd, 0x02, 0xd0, 0x60, 0x9b,
+                    0x95, 0xfc, 0x9f, 0xca, 0x0f, 0x17, 0x01, 0x5a, 0x7b, 0x70, 0x92, 0x11, 0x4c, 0xff, 0x3e, 0xad,
+                    0x96, 0x49, 0xe5, 0xde, 0x8b, 0xfc, 0x7f, 0x3f, 0x92, 0x41, 0x47, 0xad, 0x3a, 0x94, 0x74, 0x28,
                 ]
                 ]
             ),
             ),
         ]
         ]
@@ -77,25 +76,25 @@ class RabbitTests: XCTestCase {
             (
             (
                 [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00],
                 [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00],
                 [
                 [
-                    0xC6, 0xA7, 0x27, 0x5E, 0xF8, 0x54, 0x95, 0xD8, 0x7C, 0xCD, 0x5D, 0x37, 0x67, 0x05, 0xB7, 0xED,
-                    0x5F, 0x29, 0xA6, 0xAC, 0x04, 0xF5, 0xEF, 0xD4, 0x7B, 0x8F, 0x29, 0x32, 0x70, 0xDC, 0x4A, 0x8D,
-                    0x2A, 0xDE, 0x82, 0x2B, 0x29, 0xDE, 0x6C, 0x1E, 0xE5, 0x2B, 0xDB, 0x8A, 0x47, 0xBF, 0x8F, 0x66,
+                    0xc6, 0xa7, 0x27, 0x5e, 0xf8, 0x54, 0x95, 0xd8, 0x7c, 0xcd, 0x5d, 0x37, 0x67, 0x05, 0xb7, 0xed,
+                    0x5f, 0x29, 0xa6, 0xac, 0x04, 0xf5, 0xef, 0xd4, 0x7b, 0x8f, 0x29, 0x32, 0x70, 0xdc, 0x4a, 0x8d,
+                    0x2a, 0xde, 0x82, 0x2b, 0x29, 0xde, 0x6c, 0x1e, 0xe5, 0x2b, 0xdb, 0x8a, 0x47, 0xbf, 0x8f, 0x66,
                 ]
                 ]
             ),
             ),
             (
             (
-                [0xC3, 0x73, 0xF5, 0x75, 0xC1, 0x26, 0x7E, 0x59],
+                [0xc3, 0x73, 0xf5, 0x75, 0xc1, 0x26, 0x7e, 0x59],
                 [
                 [
-                    0x1F, 0xCD, 0x4E, 0xB9, 0x58, 0x00, 0x12, 0xE2, 0xE0, 0xDC, 0xCC, 0x92, 0x22, 0x01, 0x7D, 0x6D,
-                    0xA7, 0x5F, 0x4E, 0x10, 0xD1, 0x21, 0x25, 0x01, 0x7B, 0x24, 0x99, 0xFF, 0xED, 0x93, 0x6F, 0x2E,
-                    0xEB, 0xC1, 0x12, 0xC3, 0x93, 0xE7, 0x38, 0x39, 0x23, 0x56, 0xBD, 0xD0, 0x12, 0x02, 0x9B, 0xA7,
+                    0x1f, 0xcd, 0x4e, 0xb9, 0x58, 0x00, 0x12, 0xe2, 0xe0, 0xdc, 0xcc, 0x92, 0x22, 0x01, 0x7d, 0x6d,
+                    0xa7, 0x5f, 0x4e, 0x10, 0xd1, 0x21, 0x25, 0x01, 0x7b, 0x24, 0x99, 0xff, 0xed, 0x93, 0x6f, 0x2e,
+                    0xeb, 0xc1, 0x12, 0xc3, 0x93, 0xe7, 0x38, 0x39, 0x23, 0x56, 0xbd, 0xd0, 0x12, 0x02, 0x9b, 0xa7,
                 ]
                 ]
             ),
             ),
             (
             (
-                [0xA6, 0xEB, 0x56, 0x1A, 0xD2, 0xF4, 0x17, 0x27],
+                [0xa6, 0xeb, 0x56, 0x1a, 0xd2, 0xf4, 0x17, 0x27],
                 [
                 [
-                    0x44, 0x5A, 0xD8, 0xC8, 0x05, 0x85, 0x8D, 0xBF, 0x70, 0xB6, 0xAF, 0x23, 0xA1, 0x51, 0x10, 0x4D,
-                    0x96, 0xC8, 0xF2, 0x79, 0x47, 0xF4, 0x2C, 0x5B, 0xAE, 0xAE, 0x67, 0xC6, 0xAC, 0xC3, 0x5B, 0x03,
-                    0x9F, 0xCB, 0xFC, 0x89, 0x5F, 0xA7, 0x1C, 0x17, 0x31, 0x3D, 0xF0, 0x34, 0xF0, 0x15, 0x51, 0xCB,
+                    0x44, 0x5a, 0xd8, 0xc8, 0x05, 0x85, 0x8d, 0xbf, 0x70, 0xb6, 0xaf, 0x23, 0xa1, 0x51, 0x10, 0x4d,
+                    0x96, 0xc8, 0xf2, 0x79, 0x47, 0xf4, 0x2c, 0x5b, 0xae, 0xae, 0x67, 0xc6, 0xac, 0xc3, 0x5b, 0x03,
+                    0x9f, 0xcb, 0xfc, 0x89, 0x5f, 0xa7, 0x1c, 0x17, 0x31, 0x3d, 0xf0, 0x34, 0xf0, 0x15, 0x51, 0xcb,
                 ]
                 ]
             ),
             ),
         ]
         ]
@@ -137,9 +136,7 @@ extension RabbitTests {
         ]
         ]
 
 
         #if !CI
         #if !CI
-            tests += [
-                ("testRabbitPerformance", testRabbitPerformance),
-            ]
+            tests += [("testRabbitPerformance", testRabbitPerformance)]
         #endif
         #endif
         return tests
         return tests
     }
     }

+ 1 - 3
Tests/CryptoSwiftTests/RandomBytesSequenceTests.swift

@@ -19,7 +19,5 @@ class RandomBytesSequenceTests: XCTestCase {
         }
         }
     }
     }
 
 
-    static let allTests = [
-        ("testSequence", testSequence),
-    ]
+    static let allTests = [("testSequence", testSequence)]
 }
 }

+ 3 - 0
scripts/swiftformat.sh

@@ -0,0 +1,3 @@
+#!/bin/bash
+
+swiftformat  --hexliteralcase lowercase --hexgrouping none --ranges nospace --wrapelements beforefirst --self remove $1

Some files were not shown because too many files changed in this diff