TreeUtil.hash_stack

Helper struct for treehash algorithm.

template TreeUtil(alias hash_2n_n, H, M)
package
struct hash_stack (
uint height
) {}

Members

Functions

get_authpath
H[height] get_authpath()
Undocumented in source. Be warned that the author may not have intended to support it.
pop
H pop()
Undocumented in source. Be warned that the author may not have intended to support it.
push
void push(H h)
Undocumented in source. Be warned that the author may not have intended to support it.
reduce
void reduce(M mask)

Merge the top two hashes into one.

start_authpath
void start_authpath()

Start creating the authpath for the node on the top.

Properties

empty
bool empty [@property getter]
Undocumented in source. Be warned that the author may not have intended to support it.

Examples

Sanity test for hash_stack.

t {
		import dcrypt.pqc.sphincs.sphincs256: hash_2n_n;

		enum hash_bytes = 32;
		alias ubyte[hash_bytes] hash_t;
		alias TreeUtil!(hash_2n_n, ubyte[hash_bytes], ubyte[2*hash_bytes]) Tree;
		Tree.hash_stack!4 stack;

		hash_t mask1 = 111;
		hash_t mask2 = 222;
		
		ubyte[2*hash_bytes] mask = mask1~mask2;
		
		hash_t[4] l;
		for(uint i = 0; i < l.length; ++i) l[i] = cast(ubyte) (i+1);
		
		assert(stack.empty);
		stack.push(l[0]);
		stack.push(l[1]);
		assert(l[1] == stack.pop());
		assert(l[0] == stack.pop());
		
		stack.push(l[0]);
		stack.push(l[1]);
		
		stack.reduce(mask);
		hash_t hash1 = stack.pop();
		assert(stack.empty);
		
		hash_t hash2 = hash_nodes(l[0], l[1], mask);
		assert(hash1 == hash2)

Meta