Browse Source

Update ChaCha20 to work with [UInt8] input

Marcin Krzyżanowski 10 years ago
parent
commit
7445d18745
2 changed files with 6 additions and 10 deletions
  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) {
             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 */ {

+ 2 - 2
CryptoSwift/Cipher.swift

@@ -40,7 +40,7 @@ public enum Cipher {
         switch (self) {
             case .ChaCha20(let key, let 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):
                 var aes = CryptoSwift.AES(key: key, iv: iv, blockMode: blockMode)
                 return aes?.encrypt(bytes)
@@ -58,7 +58,7 @@ public enum Cipher {
         switch (self) {
             case .ChaCha20(let key, let 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):
                 var aes = CryptoSwift.AES(key: key, iv: iv, blockMode: blockMode);
                 return aes?.decrypt(bytes)