Mercurial > projects > dcrypt
annotate dcrypt/crypto/Hash.d @ 27:8b5eaf3c2979
Fixed error in hash message padding reported by Glenn Haecker.
author | Thomas Dixon <reikon@reikon.us> |
---|---|
date | Sat, 09 May 2009 23:29:20 -0400 |
parents | 4589f8c5eb3c |
children | ad687db713a4 |
rev | line source |
---|---|
0 | 1 /** |
2 * This file is part of the dcrypt project. | |
3 * | |
4 * Copyright: Copyright (C) dcrypt contributors 2008. All rights reserved. | |
5 * License: MIT | |
6 * Authors: Thomas Dixon | |
7 */ | |
8 | |
9 module dcrypt.crypto.Hash; | |
10 | |
23
4589f8c5eb3c
Replaced dcrypt.crypto.Util with dcrypt.misc.Bitwise and dcrypt.misc.ByteConverter. Altered all dependent files to reflect changes.
Thomas Dixon <reikon@reikon.us>
parents:
14
diff
changeset
|
11 public import dcrypt.misc.ByteConverter; |
4589f8c5eb3c
Replaced dcrypt.crypto.Util with dcrypt.misc.Bitwise and dcrypt.misc.ByteConverter. Altered all dependent files to reflect changes.
Thomas Dixon <reikon@reikon.us>
parents:
14
diff
changeset
|
12 public import dcrypt.misc.Bitwise; |
0 | 13 |
14 /** Base class for all cryptographic hash functions */ | |
27
8b5eaf3c2979
Fixed error in hash message padding reported by Glenn Haecker.
Thomas Dixon <reikon@reikon.us>
parents:
23
diff
changeset
|
15 class Hash |
8b5eaf3c2979
Fixed error in hash message padding reported by Glenn Haecker.
Thomas Dixon <reikon@reikon.us>
parents:
23
diff
changeset
|
16 { |
8b5eaf3c2979
Fixed error in hash message padding reported by Glenn Haecker.
Thomas Dixon <reikon@reikon.us>
parents:
23
diff
changeset
|
17 private const enum |
8b5eaf3c2979
Fixed error in hash message padding reported by Glenn Haecker.
Thomas Dixon <reikon@reikon.us>
parents:
23
diff
changeset
|
18 { |
5
cff9960a019c
Removed update(ubyte x) from Hash class. Rewrote hash function padding. Updated hash functions to use ulong counter for bytes (was previously uint).
Thomas Dixon <reikon@reikon.us>
parents:
2
diff
changeset
|
19 MODE_MD=0, // MDx, RipeMD, etc |
cff9960a019c
Removed update(ubyte x) from Hash class. Rewrote hash function padding. Updated hash functions to use ulong counter for bytes (was previously uint).
Thomas Dixon <reikon@reikon.us>
parents:
2
diff
changeset
|
20 MODE_SHA, |
cff9960a019c
Removed update(ubyte x) from Hash class. Rewrote hash function padding. Updated hash functions to use ulong counter for bytes (was previously uint).
Thomas Dixon <reikon@reikon.us>
parents:
2
diff
changeset
|
21 MODE_TIGER |
cff9960a019c
Removed update(ubyte x) from Hash class. Rewrote hash function padding. Updated hash functions to use ulong counter for bytes (was previously uint).
Thomas Dixon <reikon@reikon.us>
parents:
2
diff
changeset
|
22 } |
2
71aae178f89a
Added copy() to hash functions. Modified some code style.
Thomas Dixon <reikon@reikon.us>
parents:
0
diff
changeset
|
23 |
27
8b5eaf3c2979
Fixed error in hash message padding reported by Glenn Haecker.
Thomas Dixon <reikon@reikon.us>
parents:
23
diff
changeset
|
24 protected |
8b5eaf3c2979
Fixed error in hash message padding reported by Glenn Haecker.
Thomas Dixon <reikon@reikon.us>
parents:
23
diff
changeset
|
25 { |
2
71aae178f89a
Added copy() to hash functions. Modified some code style.
Thomas Dixon <reikon@reikon.us>
parents:
0
diff
changeset
|
26 ubyte[] buffer; |
5
cff9960a019c
Removed update(ubyte x) from Hash class. Rewrote hash function padding. Updated hash functions to use ulong counter for bytes (was previously uint).
Thomas Dixon <reikon@reikon.us>
parents:
2
diff
changeset
|
27 ulong bytes; |
cff9960a019c
Removed update(ubyte x) from Hash class. Rewrote hash function padding. Updated hash functions to use ulong counter for bytes (was previously uint).
Thomas Dixon <reikon@reikon.us>
parents:
2
diff
changeset
|
28 uint index; |
2
71aae178f89a
Added copy() to hash functions. Modified some code style.
Thomas Dixon <reikon@reikon.us>
parents:
0
diff
changeset
|
29 } |
71aae178f89a
Added copy() to hash functions. Modified some code style.
Thomas Dixon <reikon@reikon.us>
parents:
0
diff
changeset
|
30 |
27
8b5eaf3c2979
Fixed error in hash message padding reported by Glenn Haecker.
Thomas Dixon <reikon@reikon.us>
parents:
23
diff
changeset
|
31 this (void[] input_=null) |
8b5eaf3c2979
Fixed error in hash message padding reported by Glenn Haecker.
Thomas Dixon <reikon@reikon.us>
parents:
23
diff
changeset
|
32 { |
5
cff9960a019c
Removed update(ubyte x) from Hash class. Rewrote hash function padding. Updated hash functions to use ulong counter for bytes (was previously uint).
Thomas Dixon <reikon@reikon.us>
parents:
2
diff
changeset
|
33 buffer = new ubyte[blockSize]; |
0 | 34 ubyte[] input = cast(ubyte[]) input_; |
35 if (input) | |
36 update(input); | |
5
cff9960a019c
Removed update(ubyte x) from Hash class. Rewrote hash function padding. Updated hash functions to use ulong counter for bytes (was previously uint).
Thomas Dixon <reikon@reikon.us>
parents:
2
diff
changeset
|
37 } |
cff9960a019c
Removed update(ubyte x) from Hash class. Rewrote hash function padding. Updated hash functions to use ulong counter for bytes (was previously uint).
Thomas Dixon <reikon@reikon.us>
parents:
2
diff
changeset
|
38 |
cff9960a019c
Removed update(ubyte x) from Hash class. Rewrote hash function padding. Updated hash functions to use ulong counter for bytes (was previously uint).
Thomas Dixon <reikon@reikon.us>
parents:
2
diff
changeset
|
39 /** Returns: The block size of the hash function in bytes. */ |
cff9960a019c
Removed update(ubyte x) from Hash class. Rewrote hash function padding. Updated hash functions to use ulong counter for bytes (was previously uint).
Thomas Dixon <reikon@reikon.us>
parents:
2
diff
changeset
|
40 abstract uint blockSize(); |
2
71aae178f89a
Added copy() to hash functions. Modified some code style.
Thomas Dixon <reikon@reikon.us>
parents:
0
diff
changeset
|
41 |
5
cff9960a019c
Removed update(ubyte x) from Hash class. Rewrote hash function padding. Updated hash functions to use ulong counter for bytes (was previously uint).
Thomas Dixon <reikon@reikon.us>
parents:
2
diff
changeset
|
42 /** Returns: The output size of the hash function in bytes. */ |
cff9960a019c
Removed update(ubyte x) from Hash class. Rewrote hash function padding. Updated hash functions to use ulong counter for bytes (was previously uint).
Thomas Dixon <reikon@reikon.us>
parents:
2
diff
changeset
|
43 abstract uint digestSize(); |
cff9960a019c
Removed update(ubyte x) from Hash class. Rewrote hash function padding. Updated hash functions to use ulong counter for bytes (was previously uint).
Thomas Dixon <reikon@reikon.us>
parents:
2
diff
changeset
|
44 |
cff9960a019c
Removed update(ubyte x) from Hash class. Rewrote hash function padding. Updated hash functions to use ulong counter for bytes (was previously uint).
Thomas Dixon <reikon@reikon.us>
parents:
2
diff
changeset
|
45 /** Returns: The name of the algorithm we're implementing. */ |
cff9960a019c
Removed update(ubyte x) from Hash class. Rewrote hash function padding. Updated hash functions to use ulong counter for bytes (was previously uint).
Thomas Dixon <reikon@reikon.us>
parents:
2
diff
changeset
|
46 abstract char[] name(); |
2
71aae178f89a
Added copy() to hash functions. Modified some code style.
Thomas Dixon <reikon@reikon.us>
parents:
0
diff
changeset
|
47 |
71aae178f89a
Added copy() to hash functions. Modified some code style.
Thomas Dixon <reikon@reikon.us>
parents:
0
diff
changeset
|
48 /** Returns: A copy of this hash object. */ |
71aae178f89a
Added copy() to hash functions. Modified some code style.
Thomas Dixon <reikon@reikon.us>
parents:
0
diff
changeset
|
49 abstract Hash copy(); |
71aae178f89a
Added copy() to hash functions. Modified some code style.
Thomas Dixon <reikon@reikon.us>
parents:
0
diff
changeset
|
50 |
5
cff9960a019c
Removed update(ubyte x) from Hash class. Rewrote hash function padding. Updated hash functions to use ulong counter for bytes (was previously uint).
Thomas Dixon <reikon@reikon.us>
parents:
2
diff
changeset
|
51 /** |
cff9960a019c
Removed update(ubyte x) from Hash class. Rewrote hash function padding. Updated hash functions to use ulong counter for bytes (was previously uint).
Thomas Dixon <reikon@reikon.us>
parents:
2
diff
changeset
|
52 * Introduce data into the hash function. |
cff9960a019c
Removed update(ubyte x) from Hash class. Rewrote hash function padding. Updated hash functions to use ulong counter for bytes (was previously uint).
Thomas Dixon <reikon@reikon.us>
parents:
2
diff
changeset
|
53 * |
cff9960a019c
Removed update(ubyte x) from Hash class. Rewrote hash function padding. Updated hash functions to use ulong counter for bytes (was previously uint).
Thomas Dixon <reikon@reikon.us>
parents:
2
diff
changeset
|
54 * Params: |
cff9960a019c
Removed update(ubyte x) from Hash class. Rewrote hash function padding. Updated hash functions to use ulong counter for bytes (was previously uint).
Thomas Dixon <reikon@reikon.us>
parents:
2
diff
changeset
|
55 * input_ = Data to be processed. |
12
8c7f8fecdd75
Added ManagedBlockCipher, changed Crypto to just import everything, made Hash.update() return itself (for chaining) and ditched BlockCipherWrapper.
Thomas Dixon <reikon@reikon.us>
parents:
5
diff
changeset
|
56 * |
8c7f8fecdd75
Added ManagedBlockCipher, changed Crypto to just import everything, made Hash.update() return itself (for chaining) and ditched BlockCipherWrapper.
Thomas Dixon <reikon@reikon.us>
parents:
5
diff
changeset
|
57 * Returns: Self |
5
cff9960a019c
Removed update(ubyte x) from Hash class. Rewrote hash function padding. Updated hash functions to use ulong counter for bytes (was previously uint).
Thomas Dixon <reikon@reikon.us>
parents:
2
diff
changeset
|
58 */ |
27
8b5eaf3c2979
Fixed error in hash message padding reported by Glenn Haecker.
Thomas Dixon <reikon@reikon.us>
parents:
23
diff
changeset
|
59 Hash update(void[] input_) |
8b5eaf3c2979
Fixed error in hash message padding reported by Glenn Haecker.
Thomas Dixon <reikon@reikon.us>
parents:
23
diff
changeset
|
60 { |
5
cff9960a019c
Removed update(ubyte x) from Hash class. Rewrote hash function padding. Updated hash functions to use ulong counter for bytes (was previously uint).
Thomas Dixon <reikon@reikon.us>
parents:
2
diff
changeset
|
61 ubyte[] input = cast(ubyte[]) input_; |
27
8b5eaf3c2979
Fixed error in hash message padding reported by Glenn Haecker.
Thomas Dixon <reikon@reikon.us>
parents:
23
diff
changeset
|
62 foreach (ubyte i; input) |
8b5eaf3c2979
Fixed error in hash message padding reported by Glenn Haecker.
Thomas Dixon <reikon@reikon.us>
parents:
23
diff
changeset
|
63 { |
5
cff9960a019c
Removed update(ubyte x) from Hash class. Rewrote hash function padding. Updated hash functions to use ulong counter for bytes (was previously uint).
Thomas Dixon <reikon@reikon.us>
parents:
2
diff
changeset
|
64 bytes++; |
cff9960a019c
Removed update(ubyte x) from Hash class. Rewrote hash function padding. Updated hash functions to use ulong counter for bytes (was previously uint).
Thomas Dixon <reikon@reikon.us>
parents:
2
diff
changeset
|
65 buffer[index++] = i; |
27
8b5eaf3c2979
Fixed error in hash message padding reported by Glenn Haecker.
Thomas Dixon <reikon@reikon.us>
parents:
23
diff
changeset
|
66 if (index == blockSize) |
8b5eaf3c2979
Fixed error in hash message padding reported by Glenn Haecker.
Thomas Dixon <reikon@reikon.us>
parents:
23
diff
changeset
|
67 { |
5
cff9960a019c
Removed update(ubyte x) from Hash class. Rewrote hash function padding. Updated hash functions to use ulong counter for bytes (was previously uint).
Thomas Dixon <reikon@reikon.us>
parents:
2
diff
changeset
|
68 transform(buffer); |
cff9960a019c
Removed update(ubyte x) from Hash class. Rewrote hash function padding. Updated hash functions to use ulong counter for bytes (was previously uint).
Thomas Dixon <reikon@reikon.us>
parents:
2
diff
changeset
|
69 index = 0; |
cff9960a019c
Removed update(ubyte x) from Hash class. Rewrote hash function padding. Updated hash functions to use ulong counter for bytes (was previously uint).
Thomas Dixon <reikon@reikon.us>
parents:
2
diff
changeset
|
70 } |
cff9960a019c
Removed update(ubyte x) from Hash class. Rewrote hash function padding. Updated hash functions to use ulong counter for bytes (was previously uint).
Thomas Dixon <reikon@reikon.us>
parents:
2
diff
changeset
|
71 } |
27
8b5eaf3c2979
Fixed error in hash message padding reported by Glenn Haecker.
Thomas Dixon <reikon@reikon.us>
parents:
23
diff
changeset
|
72 |
12
8c7f8fecdd75
Added ManagedBlockCipher, changed Crypto to just import everything, made Hash.update() return itself (for chaining) and ditched BlockCipherWrapper.
Thomas Dixon <reikon@reikon.us>
parents:
5
diff
changeset
|
73 return this; |
5
cff9960a019c
Removed update(ubyte x) from Hash class. Rewrote hash function padding. Updated hash functions to use ulong counter for bytes (was previously uint).
Thomas Dixon <reikon@reikon.us>
parents:
2
diff
changeset
|
74 } |
cff9960a019c
Removed update(ubyte x) from Hash class. Rewrote hash function padding. Updated hash functions to use ulong counter for bytes (was previously uint).
Thomas Dixon <reikon@reikon.us>
parents:
2
diff
changeset
|
75 |
cff9960a019c
Removed update(ubyte x) from Hash class. Rewrote hash function padding. Updated hash functions to use ulong counter for bytes (was previously uint).
Thomas Dixon <reikon@reikon.us>
parents:
2
diff
changeset
|
76 /** Hash function's internal transformation. */ |
cff9960a019c
Removed update(ubyte x) from Hash class. Rewrote hash function padding. Updated hash functions to use ulong counter for bytes (was previously uint).
Thomas Dixon <reikon@reikon.us>
parents:
2
diff
changeset
|
77 protected abstract void transform(ubyte[] input); |
0 | 78 |
5
cff9960a019c
Removed update(ubyte x) from Hash class. Rewrote hash function padding. Updated hash functions to use ulong counter for bytes (was previously uint).
Thomas Dixon <reikon@reikon.us>
parents:
2
diff
changeset
|
79 /** |
cff9960a019c
Removed update(ubyte x) from Hash class. Rewrote hash function padding. Updated hash functions to use ulong counter for bytes (was previously uint).
Thomas Dixon <reikon@reikon.us>
parents:
2
diff
changeset
|
80 * Pad message in the respective manner. |
cff9960a019c
Removed update(ubyte x) from Hash class. Rewrote hash function padding. Updated hash functions to use ulong counter for bytes (was previously uint).
Thomas Dixon <reikon@reikon.us>
parents:
2
diff
changeset
|
81 * |
cff9960a019c
Removed update(ubyte x) from Hash class. Rewrote hash function padding. Updated hash functions to use ulong counter for bytes (was previously uint).
Thomas Dixon <reikon@reikon.us>
parents:
2
diff
changeset
|
82 * Params: |
cff9960a019c
Removed update(ubyte x) from Hash class. Rewrote hash function padding. Updated hash functions to use ulong counter for bytes (was previously uint).
Thomas Dixon <reikon@reikon.us>
parents:
2
diff
changeset
|
83 * mode = Mode constant dictating in which manner |
cff9960a019c
Removed update(ubyte x) from Hash class. Rewrote hash function padding. Updated hash functions to use ulong counter for bytes (was previously uint).
Thomas Dixon <reikon@reikon.us>
parents:
2
diff
changeset
|
84 * to pad the message. |
cff9960a019c
Removed update(ubyte x) from Hash class. Rewrote hash function padding. Updated hash functions to use ulong counter for bytes (was previously uint).
Thomas Dixon <reikon@reikon.us>
parents:
2
diff
changeset
|
85 */ |
27
8b5eaf3c2979
Fixed error in hash message padding reported by Glenn Haecker.
Thomas Dixon <reikon@reikon.us>
parents:
23
diff
changeset
|
86 protected void padMessage(uint mode) |
8b5eaf3c2979
Fixed error in hash message padding reported by Glenn Haecker.
Thomas Dixon <reikon@reikon.us>
parents:
23
diff
changeset
|
87 { |
5
cff9960a019c
Removed update(ubyte x) from Hash class. Rewrote hash function padding. Updated hash functions to use ulong counter for bytes (was previously uint).
Thomas Dixon <reikon@reikon.us>
parents:
2
diff
changeset
|
88 ulong bits = bytes << 3; |
cff9960a019c
Removed update(ubyte x) from Hash class. Rewrote hash function padding. Updated hash functions to use ulong counter for bytes (was previously uint).
Thomas Dixon <reikon@reikon.us>
parents:
2
diff
changeset
|
89 |
cff9960a019c
Removed update(ubyte x) from Hash class. Rewrote hash function padding. Updated hash functions to use ulong counter for bytes (was previously uint).
Thomas Dixon <reikon@reikon.us>
parents:
2
diff
changeset
|
90 // Add the pad marker |
cff9960a019c
Removed update(ubyte x) from Hash class. Rewrote hash function padding. Updated hash functions to use ulong counter for bytes (was previously uint).
Thomas Dixon <reikon@reikon.us>
parents:
2
diff
changeset
|
91 buffer[index++] = ((mode == MODE_TIGER) ? 0x01 : 0x80); |
27
8b5eaf3c2979
Fixed error in hash message padding reported by Glenn Haecker.
Thomas Dixon <reikon@reikon.us>
parents:
23
diff
changeset
|
92 if (index == blockSize) |
8b5eaf3c2979
Fixed error in hash message padding reported by Glenn Haecker.
Thomas Dixon <reikon@reikon.us>
parents:
23
diff
changeset
|
93 { |
5
cff9960a019c
Removed update(ubyte x) from Hash class. Rewrote hash function padding. Updated hash functions to use ulong counter for bytes (was previously uint).
Thomas Dixon <reikon@reikon.us>
parents:
2
diff
changeset
|
94 transform(buffer); |
cff9960a019c
Removed update(ubyte x) from Hash class. Rewrote hash function padding. Updated hash functions to use ulong counter for bytes (was previously uint).
Thomas Dixon <reikon@reikon.us>
parents:
2
diff
changeset
|
95 index = 0; |
cff9960a019c
Removed update(ubyte x) from Hash class. Rewrote hash function padding. Updated hash functions to use ulong counter for bytes (was previously uint).
Thomas Dixon <reikon@reikon.us>
parents:
2
diff
changeset
|
96 } |
cff9960a019c
Removed update(ubyte x) from Hash class. Rewrote hash function padding. Updated hash functions to use ulong counter for bytes (was previously uint).
Thomas Dixon <reikon@reikon.us>
parents:
2
diff
changeset
|
97 |
cff9960a019c
Removed update(ubyte x) from Hash class. Rewrote hash function padding. Updated hash functions to use ulong counter for bytes (was previously uint).
Thomas Dixon <reikon@reikon.us>
parents:
2
diff
changeset
|
98 // Pad with null bytes |
27
8b5eaf3c2979
Fixed error in hash message padding reported by Glenn Haecker.
Thomas Dixon <reikon@reikon.us>
parents:
23
diff
changeset
|
99 while ((index & (blockSize - 1)) != (blockSize - long.sizeof)) |
8b5eaf3c2979
Fixed error in hash message padding reported by Glenn Haecker.
Thomas Dixon <reikon@reikon.us>
parents:
23
diff
changeset
|
100 { |
8b5eaf3c2979
Fixed error in hash message padding reported by Glenn Haecker.
Thomas Dixon <reikon@reikon.us>
parents:
23
diff
changeset
|
101 buffer[index++] = 0; |
8b5eaf3c2979
Fixed error in hash message padding reported by Glenn Haecker.
Thomas Dixon <reikon@reikon.us>
parents:
23
diff
changeset
|
102 |
8b5eaf3c2979
Fixed error in hash message padding reported by Glenn Haecker.
Thomas Dixon <reikon@reikon.us>
parents:
23
diff
changeset
|
103 if (index == blockSize) |
8b5eaf3c2979
Fixed error in hash message padding reported by Glenn Haecker.
Thomas Dixon <reikon@reikon.us>
parents:
23
diff
changeset
|
104 { |
8b5eaf3c2979
Fixed error in hash message padding reported by Glenn Haecker.
Thomas Dixon <reikon@reikon.us>
parents:
23
diff
changeset
|
105 transform(buffer); |
8b5eaf3c2979
Fixed error in hash message padding reported by Glenn Haecker.
Thomas Dixon <reikon@reikon.us>
parents:
23
diff
changeset
|
106 index = 0; |
8b5eaf3c2979
Fixed error in hash message padding reported by Glenn Haecker.
Thomas Dixon <reikon@reikon.us>
parents:
23
diff
changeset
|
107 } |
8b5eaf3c2979
Fixed error in hash message padding reported by Glenn Haecker.
Thomas Dixon <reikon@reikon.us>
parents:
23
diff
changeset
|
108 } |
5
cff9960a019c
Removed update(ubyte x) from Hash class. Rewrote hash function padding. Updated hash functions to use ulong counter for bytes (was previously uint).
Thomas Dixon <reikon@reikon.us>
parents:
2
diff
changeset
|
109 |
cff9960a019c
Removed update(ubyte x) from Hash class. Rewrote hash function padding. Updated hash functions to use ulong counter for bytes (was previously uint).
Thomas Dixon <reikon@reikon.us>
parents:
2
diff
changeset
|
110 // Length padding |
27
8b5eaf3c2979
Fixed error in hash message padding reported by Glenn Haecker.
Thomas Dixon <reikon@reikon.us>
parents:
23
diff
changeset
|
111 for (int i = 0; i < 64; i+=8) // little endian |
8b5eaf3c2979
Fixed error in hash message padding reported by Glenn Haecker.
Thomas Dixon <reikon@reikon.us>
parents:
23
diff
changeset
|
112 buffer[index++] = bits >> i; |
8b5eaf3c2979
Fixed error in hash message padding reported by Glenn Haecker.
Thomas Dixon <reikon@reikon.us>
parents:
23
diff
changeset
|
113 |
0 | 114 if (mode == MODE_SHA) |
27
8b5eaf3c2979
Fixed error in hash message padding reported by Glenn Haecker.
Thomas Dixon <reikon@reikon.us>
parents:
23
diff
changeset
|
115 buffer[index-ulong.sizeof..index].reverse; // big endian |
8b5eaf3c2979
Fixed error in hash message padding reported by Glenn Haecker.
Thomas Dixon <reikon@reikon.us>
parents:
23
diff
changeset
|
116 |
8b5eaf3c2979
Fixed error in hash message padding reported by Glenn Haecker.
Thomas Dixon <reikon@reikon.us>
parents:
23
diff
changeset
|
117 transform(buffer); |
8b5eaf3c2979
Fixed error in hash message padding reported by Glenn Haecker.
Thomas Dixon <reikon@reikon.us>
parents:
23
diff
changeset
|
118 index = 0; |
0 | 119 } |
120 | |
121 /** | |
122 * Process all data, pad and finalize. This method will | |
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.
Thomas Dixon <reikon@reikon.us>
parents:
12
diff
changeset
|
123 * reset the digest to its original state for subsequent use. |
0 | 124 * |
125 * Returns: Binary representation of the hash in bytes. | |
126 */ | |
127 abstract ubyte[] digest(); | |
128 | |
129 /** | |
130 * Same as digest() but returns hash value in hex. | |
131 * | |
132 * Returns: Representation of the final hash value in hex. | |
133 */ | |
27
8b5eaf3c2979
Fixed error in hash message padding reported by Glenn Haecker.
Thomas Dixon <reikon@reikon.us>
parents:
23
diff
changeset
|
134 char[] hexDigest() |
8b5eaf3c2979
Fixed error in hash message padding reported by Glenn Haecker.
Thomas Dixon <reikon@reikon.us>
parents:
23
diff
changeset
|
135 { |
23
4589f8c5eb3c
Replaced dcrypt.crypto.Util with dcrypt.misc.Bitwise and dcrypt.misc.ByteConverter. Altered all dependent files to reflect changes.
Thomas Dixon <reikon@reikon.us>
parents:
14
diff
changeset
|
136 return ByteConverter.hexEncode(digest()); |
0 | 137 } |
138 | |
139 /** Reset hash to initial state. */ | |
27
8b5eaf3c2979
Fixed error in hash message padding reported by Glenn Haecker.
Thomas Dixon <reikon@reikon.us>
parents:
23
diff
changeset
|
140 void reset() |
8b5eaf3c2979
Fixed error in hash message padding reported by Glenn Haecker.
Thomas Dixon <reikon@reikon.us>
parents:
23
diff
changeset
|
141 { |
0 | 142 bytes = index = 0; |
143 } | |
144 } |