code wiki / (root) / nx_blake2b_long.nx

nx_blake2b_long.nx

buildroot/runtime/nx_blake2b_long.nx

7254 B192 linesdepth 1pulls 1 transitivereach 110 importersview sourcekind librarytopic blake2b
docsdependenciesstructsconstsfunctions

about

nx_blake2b_long.nx -- RFC 9106 sec 3.4 variable-length BLAKE2b H'. Argon2 needs hash outputs LONGER than BLAKE2b's 64-byte max (each memory block is 1024 bytes). H' chains BLAKE2b calls to extend the output to any T in [1, 2^32 - 1] bytes. Per cardinal feedback-bits-up-exceed-never-match: substrate's own H' chained on substrate's own BLAKE2b; nothing imported from argon2_ref / argon2_optimized. ===== Algorithm (RFC 9106 sec 3.4) ============================== H'(T, A) where T is output length in bytes, A is the input message of arbitrary length. Phase 1: prepend the 4-byte little-endian length T to A: input_prime = le32(T) || A Phase 2: if T <= 64: return BLAKE2b(input_prime, out_len = T) else: V_1 = BLAKE2b(input_prime, out_len = 64) (64 bytes) r = ceil(T / 32) - 2 (number of 32-byte full chunks beyond V_1) output[0..31] = V_1[0..31] for i = 2 .. r + 1: V_i = BLAKE2b(V_{i-1}, out_len = 64) (64 bytes) output[(i-1)*32 .. i*32 - 1] = V_i[0..31] V_last = BLAKE2b(V_{r+1}, out_len = T - 32*r) output[(r+1)*32 .. T - 1] = V_last Note: r counts the number of full V_2..V_{r+1} contributions of 32 bytes; V_1 contributes the FIRST 32 bytes; V_last (variable length T - 32*r) contributes the tail (which is ALSO 32 bytes when T is a multiple of 32, or whatever remainder otherwise). The H' construction is what gives Argon2 its 1024-byte memory

dependencies 1 imports · 3 importers

nx_blake2b.nx nx_blake2b_long.nx nx_argon2id.nx nx_argon2id_b0_bisect.nx nx_blake2b_long_test.nx

imports: nx_blake2b.nx

imported by: nx_argon2id.nxnx_argon2id_b0_bisect.nxnx_blake2b_long_test.nx

structs

none

consts

68const NX_B2BL_OK: i64 = 0
69const NX_B2BL_BAD_OUT: i64 = 1
70const NX_B2BL_BAD_ARG: i64 = 2
71const NX_B2BL_VERDICT_N: i64 = 3

functions

73func nx_b2bl_verdict_name(v: i64) -> *u8
83func _b2bl_write_le32(buf: *u8, off: i64, v: i64) -> i64
called by 1: nx_blake2b_long
91func _b2bl_copy(dst: *u8, doff: i64, src: *u8, soff: i64, n: i64) -> i64
called by 1: nx_blake2b_long
115func nx_blake2b_long(input: *u8, input_len: i64,