Mercurial > projects > dcrypt
diff dcrypt/crypto/ciphers/XTEA.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/XTEA.d Wed Aug 20 23:33:02 2008 -0400 +++ b/dcrypt/crypto/ciphers/XTEA.d Sat Aug 30 14:38:23 2008 -0400 @@ -64,14 +64,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 v0 = Util.ubytesToUintBig(input, 0), v1 = Util.ubytesToUintBig(input, 4); @@ -88,11 +92,10 @@ } } - ubyte[] output = new ubyte[blockSize]; Util.uintToUbytesBig(v0, output, 0); Util.uintToUbytesBig(v1, output, 4); - return output; + return BLOCK_SIZE; } /** Some XTEA test vectors. */ @@ -145,14 +148,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]~")");