Skip to content

Commit

Permalink
Merge pull request #1154 from 0xPolygonMiden/andrew-hashing-examples
Browse files Browse the repository at this point in the history
Add examples for hashing with `sha256` and `blake3`
  • Loading branch information
Fumuran authored Nov 30, 2023
2 parents 4582326 + ef33131 commit 9d85c41
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 0 deletions.
3 changes: 3 additions & 0 deletions miden/examples/hashing/blake3/blake3.inputs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"operand_stack": ["4294967295", "4294967295", "4294967295", "4294967295", "4294967295", "4294967295", "4294967295", "4294967295", "4294967295", "4294967295", "4294967295", "4294967295", "4294967295", "4294967295", "4294967295", "4294967295"]
}
17 changes: 17 additions & 0 deletions miden/examples/hashing/blake3/blake3.masm
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions miden/examples/hashing/sha256/sha256.inputs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"operand_stack": ["4294967295", "4294967295", "4294967295", "4294967295", "4294967295", "4294967295", "4294967295", "4294967295", "4294967295", "4294967295", "4294967295", "4294967295", "4294967295", "4294967295", "4294967295", "4294967295"]
}
17 changes: 17 additions & 0 deletions miden/examples/hashing/sha256/sha256.masm
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 9d85c41

Please sign in to comment.