Mercurial > projects > dcrypt
diff dcrypt/crypto/ciphers/TEA.d @ 14:5ce3012f1def
Removed some redundancy in code. Added NotSupportedError, a base PRNG class and a class which creates a PRNG from a hash function. Changed the MAC class' finalization methods to digest and hexDigest instead of finish and hexFinish respectively. Also added a base Checksum class, crc32 and adler32 in dcrypt.misc as per request.
author | Thomas Dixon <reikon@reikon.us> |
---|---|
date | Tue, 18 Nov 2008 18:03:40 -0500 |
parents | 8c7f8fecdd75 |
children | 4589f8c5eb3c |
line wrap: on
line diff
--- a/dcrypt/crypto/ciphers/TEA.d Fri Sep 12 05:20:43 2008 -0400 +++ b/dcrypt/crypto/ciphers/TEA.d Tue Nov 18 18:03:40 2008 -0500 @@ -21,8 +21,6 @@ DELTA = 0x9e3779b9, DECRYPT_SUM = 0xc6ef3720; uint sk0, sk1, sk2, sk3, sum; - bool initialized, - encrypt; } void reset(){} @@ -40,7 +38,7 @@ if (!keyParams) throw new InvalidParameterError( name()~": Invalid parameter passed to init"); - this.encrypt = encrypt; + _encrypt = encrypt; if (keyParams.key.length != KEY_SIZE) throw new InvalidKeyError( @@ -51,11 +49,11 @@ sk2 = Util.ubytesToUintBig(keyParams.key, 8); sk3 = Util.ubytesToUintBig(keyParams.key, 12); - initialized = true; + _initialized = true; } uint update(void[] input_, void[] output_) { - if (!initialized) + if (!_initialized) throw new NotInitializedError(name()~": Cipher not initialized"); ubyte[] input = cast(ubyte[]) input_, @@ -70,9 +68,9 @@ uint v0 = Util.ubytesToUintBig(input, 0), v1 = Util.ubytesToUintBig(input, 4); - sum = encrypt ? 0 : DECRYPT_SUM; + sum = _encrypt ? 0 : DECRYPT_SUM; for (int i = 0; i < ROUNDS; i++) { - if (encrypt) { + if (_encrypt) { sum += DELTA; v0 += ((v1 << 4) + sk0) ^ (v1 + sum) ^ ((v1 >> 5) + sk1); v1 += ((v0 << 4) + sk2) ^ (v0 + sum) ^ ((v0 >> 5) + sk3);