Mercurial > projects > dcrypt
comparison dcrypt/crypto/prngs/PRNGFromHash.d @ 16:703901987976
Removed default of SHA256 for PRNGFromHash.
author | Thomas Dixon <reikon@reikon.us> |
---|---|
date | Wed, 19 Nov 2008 19:44:44 -0500 |
parents | 5ce3012f1def |
children | 8b5eaf3c2979 |
comparison
equal
deleted
inserted
replaced
15:0de48552be35 | 16:703901987976 |
---|---|
8 | 8 |
9 module dcrypt.crypto.prngs.PRNGFromHash; | 9 module dcrypt.crypto.prngs.PRNGFromHash; |
10 | 10 |
11 import dcrypt.crypto.PRNG; | 11 import dcrypt.crypto.PRNG; |
12 import dcrypt.crypto.Hash; | 12 import dcrypt.crypto.Hash; |
13 import dcrypt.crypto.hashes.SHA256; | |
14 | 13 |
15 /** Creates a PRNG from a hash function. */ | 14 /** Creates a PRNG from a hash function. */ |
16 class PRNGFromHash : PRNG { | 15 class PRNGFromHash : PRNG { |
17 private { | 16 private { |
18 const uint COUNTER_SIZE = 32; | 17 const uint COUNTER_SIZE = 32; |
29 throw new NotInitializedError(name()~": PRNG not initialized"); | 28 throw new NotInitializedError(name()~": PRNG not initialized"); |
30 | 29 |
31 return hash.name~"PRNG"; | 30 return hash.name~"PRNG"; |
32 } | 31 } |
33 | 32 |
34 this(Hash hash=null) { | 33 this(Hash hash) { |
35 this.hash = (hash is null) ? new SHA256() : hash; | 34 if (hash is null) |
35 throw new InvalidParameterError( | |
36 name()~": Invalid parameter passed to constructor."); | |
37 this.hash = hash; | |
36 this.hash.reset(); | 38 this.hash.reset(); |
37 | 39 |
38 counter = new ubyte[COUNTER_SIZE]; | 40 counter = new ubyte[COUNTER_SIZE]; |
39 seed = new ubyte[this.hash.digestSize]; | 41 seed = new ubyte[this.hash.digestSize]; |
40 state = new ubyte[this.hash.digestSize]; | 42 state = new ubyte[this.hash.digestSize]; |