Examples:
__gshared immutable immutable(char)[][] strings =
[
"",
"a",
"abc",
"message digest",
"abcdefghijklmnopqrstuvwxyz",
"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
"12345678901234567890123456789012345678901234567890123456789012345678901234567890"
];
__gshared immutable immutable(char)[][] results =
[
"9c1185a5c5e9fc54612808977ee8f548b2258d31",
"0bdc9d2d256b3ee9daae347be6f4dc835a467ffe",
"8eb208f7e05d987a9b044a8e98c6b087f15a0bfc",
"5d0689ef49d2fae572b881b123a85ffa21595f36",
"f71c27109c692c1b56bbdceb5b9d2865b3708dbc",
"12a053384a9c0c88e405a06c27dcf49ada62eb2b",
"b0e20b6e3116640286ed3a87a5713079b21f5189",
"9b752e45573d4b39f4dbd3323cab82bf63326bfb"
];
Ripemd160 h = new Ripemd160();
foreach (int i, immutable(char)[] s; strings)
{
h.update(cast(ubyte[]) s);
char[] d = h.hexDigest();
assert(d == results[i],":("~s~")("~d~")!=("~results[i]~")");
}
char[] s = new char[1000000];
for (auto i = 0; i < s.length; i++) s[i] = 'a';
immutable(char)[] result = "52783243c1697bdbe16d37f97f68f08325dc1528";
h.update(cast(ubyte[]) s);
char[] d = h.hexDigest();
assert(d == result,":(1 million times \"a\")("~d~")!=("~result~")");
- this();
- Construct a Ripemd160
- uint digestSize();
- The size of a Ripemd160 digest is 20 bytes
- void reset();
- Initialize the cipher
Remarks:
Returns the cipher state to it's initial value
- void createDigest(ubyte[] buf);
- Obtain the digest
Returns:
the digest
Remarks:
Returns a digest of the current cipher state, this may be the
final digest, or a digest of the state between calls to update()
- protected uint blockSize();
- block size
Returns:
the block size
Remarks:
Specifies the size (in bytes) of the block of data to pass to
each call to transform(). For Ripemd160 the blockSize is 64.
- protected uint addSize();
- Length padding size
Returns:
the length padding size
Remarks:
Specifies the size (in bytes) of the padding which uses the
length of the data which has been ciphered, this padding is
carried out by the padLength method. For Ripemd160 the addSize is 8.
- protected void padMessage(ubyte[] at);
- Pads the cipher data
Params:
data |
a slice of the cipher buffer to fill with padding |
Remarks:
Fills the passed buffer slice with the appropriate padding for
the final call to transform(). This padding will fill the cipher
buffer up to blockSize()-addSize().
- protected void padLength(ubyte[] at, ulong length);
- Performs the length padding
Params:
data |
the slice of the cipher buffer to fill with padding |
ulong length |
the length of the data which has been ciphered |
Remarks:
Fills the passed buffer slice with addSize() bytes of padding
based on the length in bytes of the input data which has been
ciphered.
- protected void transform(const(ubyte[]) input);
- Performs the cipher on a block of data
Params:
data |
the block of data to cipher |
Remarks:
The actual cipher 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().