comparison dcrypt/crypto/prngs/PRNGFromHash.d @ 32:2b4bccdc8387

Added version() statements to play nice with D2's current feelings about const. Changed a few methods (addEntropy and read in the base PRNG class, and the constructor for ParametersWithIV) to accept void[] in place of ubyte[].
author Thomas Dixon <reikon@reikon.us>
date Tue, 12 May 2009 22:09:33 -0400
parents ad687db713a4
children
comparison
equal deleted inserted replaced
31:f429c5e9dd69 32:2b4bccdc8387
26 } 26 }
27 27
28 string name() 28 string name()
29 { 29 {
30 if (hash is null) 30 if (hash is null)
31 throw new NotInitializedError(name()~": PRNG not initialized"); 31 throw new NotInitializedError(name()~": PRNG not initialized.");
32 32
33 return hash.name~"PRNG"; 33 return hash.name~"PRNG";
34 } 34 }
35 35
36 this(Hash hash) 36 this(Hash hash)
47 state = new ubyte[this.hash.digestSize]; 47 state = new ubyte[this.hash.digestSize];
48 48
49 index = this.hash.digestSize; // to force updating of the state 49 index = this.hash.digestSize; // to force updating of the state
50 } 50 }
51 51
52 void addEntropy(ubyte[] input) 52 void addEntropy(void[] input)
53 { 53 {
54 if (!_initialized) 54 if (!_initialized)
55 { 55 {
56 hash.update(input); 56 hash.update(input);
57 seed = hash.digest(); 57 seed = hash.digest();
58 _initialized = true; 58 _initialized = true;
59 } else 59 } else
60 throw new NotSupportedError(name()~": state is immutable once initialized"); 60 throw new NotSupportedError(name()~": state is immutable once initialized.");
61 } 61 }
62 62
63 uint read(ubyte[] output) 63 uint read(void[] output_)
64 { 64 {
65 if (!_initialized) 65 if (!_initialized)
66 throw new NotInitializedError(name()~": PRNG not initialized"); 66 throw new NotInitializedError(name()~": PRNG not initialized.");
67
68 ubyte[] output = cast(ubyte[])output_;
67 69
68 for (uint i = 0; i < output.length; i++) 70 for (uint i = 0; i < output.length; i++)
69 { 71 {
70 if (index == state.length) 72 if (index == state.length)
71 { 73 {