BSD style: see doc/license.txt for details
Initial release: Feb 2006
Regan Heath, Oskar Linde
This module implements a generic Merkle-Damgard hash function
- class MerkleDamgard : Digest [package] ¶
-
Extending MerkleDamgard to create a custom hash function requires
the implementation of a number of abstract methods. These include:
1
2
3
4
5
6
7
|
public uint digestSize();
protected void reset();
protected void createDigest(ubyte[] buf);
protected uint blockSize();
protected uint addSize();
protected void padMessage(ubyte[] data);
protected void transform(ubyte[] data);
|
In addition there exist two further abstract methods; these methods
have empty default implementations since in some cases they are not
required:
1
2
|
protected abstract void padLength(ubyte[] data, ulong length);
protected abstract void extend();
|
The method padLength() is required to implement the SHA series of
Hash functions and also the Tiger algorithm. Method extend() is
required only to implement the MD2 digest.
The basic sequence of internal events is as follows:
- transform(), 0 or more times
- padMessage()
- padLength()
- transform()
- extend()
- createDigest()
- reset()
- void createDigest(ubyte[] buf) [protected, abstract] ¶
-
buf | a buffer with enough space to hold the digest |
Constructs the digest.
- uint blockSize() [protected, abstract] ¶
-
the block size
Specifies the size (in bytes) of the block of data to pass to
each call to transform().
- uint addSize() [protected, @property, abstract] ¶
-
the length padding size
Specifies the size (in bytes) of the padding which
uses the length of the data which has been fed to the
algorithm, this padding is carried out by the
padLength method.
- void padMessage(ubyte[] data) [protected, abstract] ¶
-
data | a slice of the digest buffer to fill with padding |
Fills the passed buffer slice with the appropriate
padding for the final call to transform(). This
padding will fill the message data buffer up to
blockSize()-addSize().
- void padLength(ubyte[] data, ulong length) [protected] ¶
-
Performs the length padding
data | the slice of the digest buffer to fill with padding |
length | the length of the data which has been processed |
Fills the passed buffer slice with addSize() bytes of padding
based on the length in bytes of the input data which has been
processed.
- void transform(const(ubyte[]) data) [protected, abstract] ¶
-
Performs the digest on a block of data
data | the block of data to digest |
The actual digest algorithm is carried out by this method on
the passed block of data. This method is called for every
blockSize() bytes of input data and once more with the remaining
data padded to blockSize().
- void extend() [protected] ¶
-
Final processing of digest.
This method is called after the final transform just prior to
the creation of the final digest. The MD2 algorithm requires
an additional step at this stage. Future digests may or may not
require this method.
- this() ¶
-
Constructs the internal buffer for use by the digest, the buffer
size (in bytes) is defined by the abstract method blockSize().
- void reset() [protected] ¶
-
Returns the digest state to its initial value
- MerkleDamgard update(const(void[]) input) [override] ¶
-
Continues the digest operation on the additional data.
- ubyte[] binaryDigest(ubyte[] buf = null) [override] ¶
-
the completed digest
Concludes the algorithm producing the final digest.
- void littleEndian32(const(ubyte[]) input, uint[] output) [protected, static, final] ¶
-
Converts 8 bit to 32 bit Little Endian
input | the source array |
output | the destination array |
Converts an array of ubyte[] into uint[] in Little Endian byte order.
- void bigEndian32(const(ubyte[]) input, uint[] output) [protected, static, final] ¶
-
Converts 8 bit to 32 bit Big Endian
input | the source array |
output | the destination array |
Converts an array of ubyte[] into uint[] in Big Endian byte order.
- void littleEndian64(const(ubyte[]) input, ulong[] output) [protected, static, final] ¶
-
Converts 8 bit to 64 bit Little Endian
input | the source array |
output | the destination array |
Converts an array of ubyte[] into ulong[] in Little Endian byte order.
- void bigEndian64(const(ubyte[]) input, ulong[] output) [protected, static, final] ¶
-
Converts 8 bit to 64 bit Big Endian
input | the source array |
output | the destination array |
Converts an array of ubyte[] into ulong[] in Big Endian byte order.
- uint rotateLeft(uint x, uint n) [protected, static, final] ¶
-
x | the value to rotate |
n | the amount to rotate by |
Rotates a 32 bit value by the specified amount.