From ef331316d614a8b510575af627e9a49953fabc7d Mon Sep 17 00:00:00 2001 From: Andrey Khmuro Date: Tue, 21 Nov 2023 12:29:36 +0100 Subject: [PATCH] chore: add hashing example --- miden/examples/hashing/blake3/blake3.inputs | 3 +++ miden/examples/hashing/blake3/blake3.masm | 17 +++++++++++++++++ miden/examples/hashing/sha256/sha256.inputs | 3 +++ miden/examples/hashing/sha256/sha256.masm | 17 +++++++++++++++++ 4 files changed, 40 insertions(+) create mode 100644 miden/examples/hashing/blake3/blake3.inputs create mode 100644 miden/examples/hashing/blake3/blake3.masm create mode 100644 miden/examples/hashing/sha256/sha256.inputs create mode 100644 miden/examples/hashing/sha256/sha256.masm diff --git a/miden/examples/hashing/blake3/blake3.inputs b/miden/examples/hashing/blake3/blake3.inputs new file mode 100644 index 0000000000..700e6fb0d5 --- /dev/null +++ b/miden/examples/hashing/blake3/blake3.inputs @@ -0,0 +1,3 @@ +{ + "operand_stack": ["4294967295", "4294967295", "4294967295", "4294967295", "4294967295", "4294967295", "4294967295", "4294967295", "4294967295", "4294967295", "4294967295", "4294967295", "4294967295", "4294967295", "4294967295", "4294967295"] +} diff --git a/miden/examples/hashing/blake3/blake3.masm b/miden/examples/hashing/blake3/blake3.masm new file mode 100644 index 0000000000..9378ca14a3 --- /dev/null +++ b/miden/examples/hashing/blake3/blake3.masm @@ -0,0 +1,17 @@ +use.std::crypto::hashes::blake3 + +begin + # hash_2to1 pops top 16 elements (64 bytes) from the stack, compute their hash and puts the + # resulting 8 elements (32 bytes) back to the stack. + exec.blake3::hash_2to1 + + # Check the correctness of the hashing result by comparing it with precomputed correct values. + # This hash is a result of applying a blake3 hashing function to the binary value consisting of + # only ones. + push.0xD9696D27.0xF209D66E.0xD0DFDEB9.0x7D5992E2.0x44DDA9CB.0xD6FFB5E5.0x8CD0CAA6.0xF0270FA9 + + # compare results + movupw.2 + assert_eqw + assert_eqw +end \ No newline at end of file diff --git a/miden/examples/hashing/sha256/sha256.inputs b/miden/examples/hashing/sha256/sha256.inputs new file mode 100644 index 0000000000..700e6fb0d5 --- /dev/null +++ b/miden/examples/hashing/sha256/sha256.inputs @@ -0,0 +1,3 @@ +{ + "operand_stack": ["4294967295", "4294967295", "4294967295", "4294967295", "4294967295", "4294967295", "4294967295", "4294967295", "4294967295", "4294967295", "4294967295", "4294967295", "4294967295", "4294967295", "4294967295", "4294967295"] +} diff --git a/miden/examples/hashing/sha256/sha256.masm b/miden/examples/hashing/sha256/sha256.masm new file mode 100644 index 0000000000..ccde47a3fb --- /dev/null +++ b/miden/examples/hashing/sha256/sha256.masm @@ -0,0 +1,17 @@ +use.std::crypto::hashes::sha256 + +begin + # hash_2to1 pops top 16 elements (64 bytes) from the stack, compute their hash and puts the + # resulting 8 elements (32 bytes) back to the stack. + exec.sha256::hash_2to1 + + # Check the correctness of the hashing result by comparing it with precomputed correct values. + # This hash is a result of applying a sha256 hashing function to the binary value consisting of + # only ones. + push.0x85E1D1F7.0x8643E4A2.0x2DAD7274.0x1F764AAD.0xBA3EEB20.0xF1D30600.0x294E9E0D.0x8667E718 + + # compare results + movupw.2 + assert_eqw + assert_eqw +end \ No newline at end of file