blake2-d 0.2.0

BLAKE2 implementation.


To use this package, run the following command in your project's root directory:

Manual usage
Put the following dependency into your project's dependences section:

blake2-d

BLAKE2 library written in D implementing the BLAKE2b and BLAKE2s hashing algorithms and is compatible with the Phobos Digest API (std.digest).

BLAKE2 was introduced in 2015 as IETF RFC 7693. You can visit the website for more information.

This module:

  • [x] Supports BLAKE2b-512 and BLAKE2s-256.
  • [x] Supports custom digest sizes.
  • [x] Supports keying.
  • [ ] Supports BLAKE2bp and BLAKE2sp.

NOTE: May be incompatible with HMAC.

Compatible and tested with DMD, GDC, and LDC.

Pull Requests accepted.

If you would like to disclose a vulnerability, please consult [SECURITY.md](../master/.github/SECURITY.md).

Usage

To include it in your project, simply import the blake2d package.

Digest API

If you are unfamiliar with the Digest API, here is a quick summary.

Two APIs are available: Template API and OOP API.

Template API

The template API uses a structure template and is a good choice if your application only plans to support one digest algorithm.

// NOTE: hexString is from std.conv
BLAKE2b512 b2b512;
b2b512.put("abc");
assert(b2b512.finish() == cast(ubyte[]) hexString!(
	"ba80a53f981c4d0d6a2797b69f12f6e94c212f14685ac4b74b12bb6fdbffa2d1"~
        "7d87c5392aab792dc252d5de4533cc9518d38aa8dbf1925ab92386edd4009923"));
b2b512.start(); // reset
b2b512.put("abcdef");
assert(b2b512.finish() == cast(ubyte[]) hexString!(
	"dde410524e3569b303e494aa82a3afb3e426f9df24c1398e9ff87aafbc2f5b7b"~
	"3c1a4c9400409de3b45d37a00e5eae2a93cc9c4a108b00f05217d41a424d2b8a"));

OOP API

The OOP API uses a class (object) implementation and is a good choice if your application plans to support one or more digest algorithms.

// NOTE: hexString is from std.conv
Digest dgst = new BLAKE2b512Digest();
dgst.put("abc");
assert(dgst.finish() == cast(ubyte[]) hexString!(
	"ba80a53f981c4d0d6a2797b69f12f6e94c212f14685ac4b74b12bb6fdbffa2d1"~
        "7d87c5392aab792dc252d5de4533cc9518d38aa8dbf1925ab92386edd4009923"));
dgst.start(); // reset
dgst.put("abcdef");
assert(dgst.finish() == cast(ubyte[]) hexString!(
	"dde410524e3569b303e494aa82a3afb3e426f9df24c1398e9ff87aafbc2f5b7b"~
	"3c1a4c9400409de3b45d37a00e5eae2a93cc9c4a108b00f05217d41a424d2b8a"));

There are numerous ways to avoid GC allocation. For example when only using a digest for a one-time use in a short scope, there's std.typecons.scoped.

Keying

Currently, the only way to supply a key is with the key function:

import std.string : representation;
import std.conv : hexString;

auto secret2s = hexString!(
    "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f")
    .representation;
auto data = hexString!("000102").representation;

BLAKE2s256 b2s;
b2s.key(secret);

License

Published under the Boost License 1.0.

Authors:
Dependencies:
none
Versions:
0.3.0 2022-Aug-26
0.2.0 2022-Jan-01
0.1.0 2021-Dec-23
~master 2023-Dec-18
Show all 4 versions
Download Stats:
  • 0 downloads today

  • 0 downloads this week

  • 0 downloads this month

  • 76 downloads total

Score:
0.1
Short URL:
blake2-d.dub.pm