瀏覽代碼

Update ChaCha20 to work with [UInt8] input

Marcin Krzyżanowski 10 年之前
父節點
當前提交
7445d18745
共有 2 個文件被更改,包括 6 次插入10 次删除
  1. 4 8
      CryptoSwift/ChaCha20.swift
  2. 2 2
      CryptoSwift/Cipher.swift

+ 4 - 8
CryptoSwift/ChaCha20.swift

@@ -32,20 +32,16 @@ public class ChaCha20 {
         }
         }
     }
     }
     
     
-    func encrypt(message:NSData) -> NSData? {
+    func encrypt(bytes:[UInt8]) -> [UInt8]? {
         if (context == nil) {
         if (context == nil) {
             return nil
             return nil
         }
         }
         
         
-        if let output = encryptBytes(message.bytes()) {
-            return NSData.withBytes(output)
-        }
-        
-        return nil
+        return encryptBytes(bytes)
     }
     }
     
     
-    func decrypt(message:NSData) -> NSData? {
-        return encrypt(message)
+    func decrypt(bytes:[UInt8]) -> [UInt8]? {
+        return encrypt(bytes)
     }
     }
     
     
     private func wordToByte(input:[UInt32] /* 64 */) -> [UInt8]? /* 16 */ {
     private func wordToByte(input:[UInt32] /* 64 */) -> [UInt8]? /* 16 */ {

+ 2 - 2
CryptoSwift/Cipher.swift

@@ -40,7 +40,7 @@ public enum Cipher {
         switch (self) {
         switch (self) {
             case .ChaCha20(let key, let iv):
             case .ChaCha20(let key, let iv):
                 var chacha = CryptoSwift.ChaCha20(key: key, iv: iv)
                 var chacha = CryptoSwift.ChaCha20(key: key, iv: iv)
-                return chacha?.encrypt(NSData.withBytes(bytes))?.bytes() //TODO: [UInt8]
+                return chacha?.encrypt(bytes)
             case .AES(let key, let iv, let blockMode):
             case .AES(let key, let iv, let blockMode):
                 var aes = CryptoSwift.AES(key: key, iv: iv, blockMode: blockMode)
                 var aes = CryptoSwift.AES(key: key, iv: iv, blockMode: blockMode)
                 return aes?.encrypt(bytes)
                 return aes?.encrypt(bytes)
@@ -58,7 +58,7 @@ public enum Cipher {
         switch (self) {
         switch (self) {
             case .ChaCha20(let key, let iv):
             case .ChaCha20(let key, let iv):
                 var chacha = CryptoSwift.ChaCha20(key: key, iv: iv);
                 var chacha = CryptoSwift.ChaCha20(key: key, iv: iv);
-                return chacha?.decrypt(NSData.withBytes(bytes))?.bytes() //TODO: [UInt8]
+                return chacha?.decrypt(bytes)
             case .AES(let key, let iv, let blockMode):
             case .AES(let key, let iv, let blockMode):
                 var aes = CryptoSwift.AES(key: key, iv: iv, blockMode: blockMode);
                 var aes = CryptoSwift.AES(key: key, iv: iv, blockMode: blockMode);
                 return aes?.decrypt(bytes)
                 return aes?.decrypt(bytes)