tango.util.digest.Ripemd256

License:
BSD style: see doc/license.txt for details

Version:
Initial release: Sep 2009

author:
Kai Nacke

This module implements the Ripemd256 algorithm by Hans Dobbertin, Antoon Bosselaers and Bart Preneel.

See http://homes.esat.kuleuven.be/~bosselae/ripemd160.html for more information.

The implementation is based on: RIPEMD-160 software written by Antoon Bosselaers, available at http://www.esat.kuleuven.ac.be/~cosicart/ps/AB-9601/

class Ripemd256: tango.util.digest.MerkleDamgard.MerkleDamgard;
Examples:
__gshared immutable immutable(char)[][] strings =
[
        "",
        "a",
        "abc",
        "message digest",
        "abcdefghijklmnopqrstuvwxyz",
        "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
        "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
        "12345678901234567890123456789012345678901234567890123456789012345678901234567890"
];

__gshared immutable immutable(char)[][] results =
[
        "02ba4c4e5f8ecd1877fc52d64d30e37a2d9774fb1e5d026380ae0168e3c5522d",
        "f9333e45d857f5d90a91bab70a1eba0cfb1be4b0783c9acfcd883a9134692925",
        "afbd6e228b9d8cbbcef5ca2d03e6dba10ac0bc7dcbe4680e1e42d2e975459b65",
        "87e971759a1ce47a514d5c914c392c9018c7c46bc14465554afcdf54a5070c0e",
        "649d3034751ea216776bf9a18acc81bc7896118a5197968782dd1fd97d8d5133",
        "3843045583aac6c8c8d9128573e7a9809afb2a0f34ccc36ea9e72f16f6368e3f",
        "5740a408ac16b720b84424ae931cbb1fe363d1d0bf4017f1a89f7ea6de77a0b8",
        "06fdcc7a409548aaf91368c06a6275b553e3f099bf0ea4edfd6778df89a890dd"
];

Ripemd256 h = new Ripemd256();

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 = "ac953744e10e31514c150d4d8d7b677342e33399788296e43ae4850ce4f97978";
h.update(cast(ubyte[]) s);
char[] d = h.hexDigest();

assert(d == result,":(1 million times \"a\")("~d~")!=("~result~")");


this();
Construct a Ripemd256

uint digestSize();
The size of a Ripemd256 digest is 32 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 Ripemd256 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 Ripemd256 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().


Page generated by Ddoc. Copyright (c) 2009 Tango. All rights reserved