Parcourir la source

CFB decrypt is the same as encrypt adjusted to cipher operation

Marcin Krzyżanowski il y a 11 ans
Parent
commit
6aa9e9ffa2
1 fichiers modifiés avec 1 ajouts et 15 suppressions
  1. 1 15
      CryptoSwift/CipherBlockMode.swift

+ 1 - 15
CryptoSwift/CipherBlockMode.swift

@@ -135,22 +135,8 @@ private struct CFBMode: BlockMode {
     }
     
     func decryptBlocks(blocks:[[UInt8]], iv:[UInt8]?, cipherOperation:CipherOperationOnBlock) -> [UInt8]? {
-        assert(iv != nil, "CFB require IV")
-        if (iv == nil) {
-            return nil
-        }
-        
-        var out:[UInt8]?
-        var lastCiphertext:[UInt8] = iv!
-        for ciphertext in blocks {
-            if let decrypted = cipherOperation(block: lastCiphertext) {
-                lastCiphertext = xor(ciphertext, decrypted)
-                out = (out ?? [UInt8]()) + lastCiphertext
-            }
-        }
-        return out;
+        return encryptBlocks(blocks, iv: iv, cipherOperation: cipherOperation)
     }
-
 }