#blake2 #message-authentication #hash #blake2b

blake2ya

The BLAKE2 cryptographic hash and message authentication code

8 releases (2 stable)

new 1.0.1 Dec 19, 2024
1.0.0 Dec 16, 2024
0.9.5 Dec 6, 2024

#526 in Cryptography

Download history 298/week @ 2024-11-28 286/week @ 2024-12-05 142/week @ 2024-12-12

726 downloads per month
Used in ckbes

MIT license

36KB
545 lines

Blake2 Yet Another

The BLAKE2 cryptographic hash and message authentication code. It is implemented in pure rust, achieves the best performance without using unsafe code, and supports no_std systems.

[dependencies]
blake2ya = "1.0"

Based on benchmarks, it performs slightly better than the official C implementation of BLAKE2 at -Os, and slightly worse than -O3.

Example

BLAKE2b

let mut p = blake2ya::blake2b_params();
p.digest(64);
let mut h = blake2ya::blake2b(p);
h.update(b"abc");
let mut r = [0; 64];
h.digest(&mut r);
let e = [
    0xba, 0x80, 0xa5, 0x3f, 0x98, 0x1c, 0x4d, 0x0d, 0x6a, 0x27, 0x97, 0xb6, 0x9f, 0x12, 0xf6, 0xe9,
    0x4c, 0x21, 0x2f, 0x14, 0x68, 0x5a, 0xc4, 0xb7, 0x4b, 0x12, 0xbb, 0x6f, 0xdb, 0xff, 0xa2, 0xd1,
    0x7d, 0x87, 0xc5, 0x39, 0x2a, 0xab, 0x79, 0x2d, 0xc2, 0x52, 0xd5, 0xde, 0x45, 0x33, 0xcc, 0x95,
    0x18, 0xd3, 0x8a, 0xa8, 0xdb, 0xf1, 0x92, 0x5a, 0xb9, 0x23, 0x86, 0xed, 0xd4, 0x00, 0x99, 0x23,
];
assert_eq!(r, e);

BLAKE2s

let mut p = blake2ya::blake2s_params();
p.digest(32);
let mut h = blake2ya::blake2s(p);
h.update(b"abc");
let mut r = [0; 32];
h.digest(&mut r);
let e = [
    0x50, 0x8c, 0x5e, 0x8c, 0x32, 0x7c, 0x14, 0xe2, 0xe1, 0xa7, 0x2b, 0xa3, 0x4e, 0xeb, 0x45, 0x2f,
    0x37, 0x45, 0x8b, 0x20, 0x9e, 0xd6, 0x3a, 0x29, 0x4d, 0x99, 0x9b, 0x4c, 0x86, 0x67, 0x59, 0x82,
];
assert_eq!(r, e);

License

MIT

No runtime deps