BLAKE2s256Digest

OOP API BLAKE2 implementation aliases.

alias BLAKE2s256Digest = WrapperDigest!BLAKE2s256

Examples

Of course they correspond to the digest API!

assert(isDigest!BLAKE2b512);
assert(isDigest!BLAKE2s256);

Testing "Of" wrappers against digest wrappers.

enum TEXT = "abc";

ubyte[64] b2b = blake2b_Of(TEXT);
assert(b2b == digest!BLAKE2b512(TEXT));

ubyte[32] b2s = blake2s_Of(TEXT);
assert(b2s == digest!BLAKE2s256(TEXT));

Testing template API

import std.conv : hexString;

ubyte[] s = [ 'a', 'b', 'c' ];

BLAKE2s256 b2s;
b2s.put(s);
assert(b2s.finish() == cast(ubyte[])hexString!(
    "508c5e8c327c14e2e1a72ba34eeb452f37458b209ed63a294d999b4c86675982"));

Test against empty input

assert(toHexString!(LetterCase.lower)(blake2b_Of("")) ==
    "786a02f742015903c6c6fd852552d272912f4740e15847618a86e217f71f5419"~
    "d25e1031afee585313896444934eb04b903a685b1448b755d56f701afe9be2ce");
assert(toHexString!(LetterCase.lower)(blake2s_Of("")) ==
    "69217a3079908094e11121d042354a7c1f55b6482ca1a51e1b250dfd1ed0eef9");

Test against "abc"

assert(toHexString!(LetterCase.lower)(blake2b_Of("abc")) ==
    "ba80a53f981c4d0d6a2797b69f12f6e94c212f14685ac4b74b12bb6fdbffa2d1"~
    "7d87c5392aab792dc252d5de4533cc9518d38aa8dbf1925ab92386edd4009923");
assert(toHexString!(LetterCase.lower)(blake2s_Of("abc")) ==
    "508c5e8c327c14e2e1a72ba34eeb452f37458b209ed63a294d999b4c86675982");

Testing template API against one million 'a'

import std.conv : hexString;

ubyte[] onemilliona = new ubyte[1_000_000];
onemilliona[] = 'a';

BLAKE2b512 b2b;
b2b.put(onemilliona);
assert(b2b.finish() == cast(ubyte[]) hexString!(
    "98fb3efb7206fd19ebf69b6f312cf7b64e3b94dbe1a17107913975a793f177e1"~
    "d077609d7fba363cbba00d05f7aa4e4fa8715d6428104c0a75643b0ff3fd3eaf"));

BLAKE2s256 b2s;
b2s.put(onemilliona);
assert(b2s.finish() == cast(ubyte[]) hexString!(
    "bec0c0e6cde5b67acb73b81f79a67a4079ae1c60dac9d2661af18e9f8b50dfa5"));

Testing OOP API

import std.conv : hexString;

ubyte[] s = ['a', 'b', 'c'];

BLAKE2b512Digest b2b = new BLAKE2b512Digest();
b2b.put(s);
assert(b2b.finish() == cast(ubyte[]) hexString!(
    "ba80a53f981c4d0d6a2797b69f12f6e94c212f14685ac4b74b12bb6fdbffa2d1"~
    "7d87c5392aab792dc252d5de4533cc9518d38aa8dbf1925ab92386edd4009923"));

BLAKE2s256Digest b2s = new BLAKE2s256Digest();
b2s.put(s);
assert(b2s.finish() == cast(ubyte[]) hexString!(
    "508c5e8c327c14e2e1a72ba34eeb452f37458b209ed63a294d999b4c86675982"));

BLAKE2s Template usage

import std.conv : hexString;

// Let's use the template features:
// NOTE: When passing a digest to a function, it must be passed by reference!
void doSomething(T)(ref T hash)
    if (isDigest!T)
    {
        hash.put([ 'a', 'b', 'c' ]);
    }
BLAKE2b512 b2b;
b2b.start();
doSomething(b2b);
assert(b2b.finish() == cast(ubyte[]) hexString!(
    "ba80a53f981c4d0d6a2797b69f12f6e94c212f14685ac4b74b12bb6fdbffa2d1"~
    "7d87c5392aab792dc252d5de4533cc9518d38aa8dbf1925ab92386edd4009923"));
BLAKE2s256 b2s;
b2s.start();
doSomething(b2s);
assert(b2s.finish() == cast(ubyte[]) hexString!(
    "508c5e8c327c14e2e1a72ba34eeb452f37458b209ed63a294d999b4c86675982"));

Meta