diff dcrypt/crypto/ciphers/RC6.d @ 12:8c7f8fecdd75

Added ManagedBlockCipher, changed Crypto to just import everything, made Hash.update() return itself (for chaining) and ditched BlockCipherWrapper.
author Thomas Dixon <reikon@reikon.us>
date Sat, 30 Aug 2008 14:38:23 -0400
parents 23c62e28b3a4
children 5ce3012f1def
line wrap: on
line diff
--- a/dcrypt/crypto/ciphers/RC6.d	Wed Aug 20 23:33:02 2008 -0400
+++ b/dcrypt/crypto/ciphers/RC6.d	Sat Aug 30 14:38:23 2008 -0400
@@ -65,14 +65,18 @@
         initialized = true;
     }
     
-    ubyte[] process(void[] input_) {
+    uint update(void[] input_, void[] output_) {
         if (!initialized)
             throw new NotInitializedError(name()~": Cipher not initialized");
             
-        ubyte[] input = cast(ubyte[]) input_;
+        ubyte[] input = cast(ubyte[]) input_,
+                output = cast(ubyte[]) output_;
                     
-        if (input.length > blockSize)
+        if (input.length < BLOCK_SIZE)
             throw new ShortBufferError(name()~": Input buffer too short");
+            
+        if (output.length < BLOCK_SIZE)
+            throw new ShortBufferError(name()~": Output buffer too short");
         
         uint A = Util.ubytesToUintLittle(input, 0),
              B = Util.ubytesToUintLittle(input, 4),
@@ -115,13 +119,12 @@
             B -= S[0];
         }
 
-        ubyte[] output = new ubyte[blockSize];
         Util.uintToUbytesLittle(A, output, 0);
         Util.uintToUbytesLittle(B, output, 4);
         Util.uintToUbytesLittle(C, output, 8);
         Util.uintToUbytesLittle(D, output, 12);
         
-        return output;
+        return BLOCK_SIZE;
     }
     
     void reset() {
@@ -192,14 +195,14 @@
                 
                 // Encryption
                 t.init(true, key);
-                buffer = t.process(Util.hexToUbytes(test_plaintexts[i]));
+                t.update(Util.hexToUbytes(test_plaintexts[i]), buffer);
                 result = Util.ubytesToHex(buffer);
                 assert(result == test_ciphertexts[i],
                         t.name~": ("~result~") != ("~test_ciphertexts[i]~")");
             
                 // Decryption
                 t.init(false, key);
-                buffer = t.process(Util.hexToUbytes(test_ciphertexts[i]));
+                t.update(Util.hexToUbytes(test_ciphertexts[i]), buffer);
                 result = Util.ubytesToHex(buffer);
                 assert(result == test_plaintexts[i],
                         t.name~": ("~result~") != ("~test_plaintexts[i]~")");