Mercurial > projects > dcrypt
comparison dcrypt/crypto/macs/HMAC.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 | 5cb17e09d685 |
children | 0de48552be35 |
comparison
equal
deleted
inserted
replaced
13:7ea528b61802 | 14:5ce3012f1def |
---|---|
93 | 93 |
94 uint macSize() { | 94 uint macSize() { |
95 return inner.digestSize; | 95 return inner.digestSize; |
96 } | 96 } |
97 | 97 |
98 ubyte[] finish() { | 98 ubyte[] digest() { |
99 outer.update(inner.digest()); | 99 outer.update(inner.digest()); |
100 ubyte[] r = outer.digest(); | 100 ubyte[] r = outer.digest(); |
101 reset(); | 101 reset(); |
102 return r; | 102 return r; |
103 } | 103 } |
104 | 104 |
105 char[] hexFinish() { | 105 char[] hexDigest() { |
106 return Util.ubytesToHex(finish()); | 106 return Util.ubytesToHex(finish()); |
107 } | 107 } |
108 | 108 |
109 HMAC copy() { | 109 HMAC copy() { |
110 // Ghetto... oh so ghetto :\ | 110 // Ghetto... oh so ghetto :\ |
149 HMAC h = new HMAC(new SHA1()); | 149 HMAC h = new HMAC(new SHA1()); |
150 foreach (uint i, char[] k; test_keys) { | 150 foreach (uint i, char[] k; test_keys) { |
151 h.init(new SymmetricKey(Util.hexToUbytes(k))); | 151 h.init(new SymmetricKey(Util.hexToUbytes(k))); |
152 for (int j = 0; j < test_repeat[i]; j++) | 152 for (int j = 0; j < test_repeat[i]; j++) |
153 h.update(Util.hexToUbytes(test_inputs[i])); | 153 h.update(Util.hexToUbytes(test_inputs[i])); |
154 char[] mac = h.hexFinish(); | 154 char[] mac = h.hexDigest(); |
155 assert(mac == test_results[i], | 155 assert(mac == test_results[i], |
156 h.name~": ("~mac~") != ("~test_results[i]~")"); | 156 h.name~": ("~mac~") != ("~test_results[i]~")"); |
157 } | 157 } |
158 } | 158 } |
159 } | 159 } |