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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
0e08791a1418 Initial import.
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
1 /**
0e08791a1418 Initial import.
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
2 * This file is part of the dcrypt project.
0e08791a1418 Initial import.
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
3 *
0e08791a1418 Initial import.
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
4 * Copyright: Copyright (C) dcrypt contributors 2008. All rights reserved.
0e08791a1418 Initial import.
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
5 * License: MIT
0e08791a1418 Initial import.
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
6 * Authors: Thomas Dixon
0e08791a1418 Initial import.
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
7 */
0e08791a1418 Initial import.
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
8
0e08791a1418 Initial import.
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
9 module dcrypt.crypto.Hash;
0e08791a1418 Initial import.
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
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
0e08791a1418 Initial import.
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
13
0e08791a1418 Initial import.
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
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
0e08791a1418 Initial import.
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
34 ubyte[] input = cast(ubyte[]) input_;
0e08791a1418 Initial import.
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
35 if (input)
0e08791a1418 Initial import.
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
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
0e08791a1418 Initial import.
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
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
0e08791a1418 Initial import.
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
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
0e08791a1418 Initial import.
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
119 }
0e08791a1418 Initial import.
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
120
0e08791a1418 Initial import.
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
121 /**
0e08791a1418 Initial import.
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
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
0e08791a1418 Initial import.
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
124 *
0e08791a1418 Initial import.
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
125 * Returns: Binary representation of the hash in bytes.
0e08791a1418 Initial import.
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
126 */
0e08791a1418 Initial import.
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
127 abstract ubyte[] digest();
0e08791a1418 Initial import.
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
128
0e08791a1418 Initial import.
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
129 /**
0e08791a1418 Initial import.
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
130 * Same as digest() but returns hash value in hex.
0e08791a1418 Initial import.
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
131 *
0e08791a1418 Initial import.
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
132 * Returns: Representation of the final hash value in hex.
0e08791a1418 Initial import.
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
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
0e08791a1418 Initial import.
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
137 }
0e08791a1418 Initial import.
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
138
0e08791a1418 Initial import.
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
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
0e08791a1418 Initial import.
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
142 bytes = index = 0;
0e08791a1418 Initial import.
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
143 }
0e08791a1418 Initial import.
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
144 }