From cba6e55323c3361d6435e9c63c3be305dae488d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Pedro=20Sousa?= Date: Mon, 5 Jun 2023 09:54:32 +0100 Subject: [PATCH] updating keccak for message_size --- .../cryptographic_primitives/00_hashes.mdx | 41 +++++++++---------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/docs/standard_library/cryptographic_primitives/00_hashes.mdx b/docs/standard_library/cryptographic_primitives/00_hashes.mdx index c373f10..fbcbf59 100644 --- a/docs/standard_library/cryptographic_primitives/00_hashes.mdx +++ b/docs/standard_library/cryptographic_primitives/00_hashes.mdx @@ -1,21 +1,13 @@ --- title: Hash methods description: - Learn about the cryptographic primitives ready to use for any Noir project, including sha256, blake2s, pedersen, mimc_bn254 and mimc + Learn about the cryptographic primitives ready to use for any Noir project, including sha256, + blake2s, pedersen, mimc_bn254 and mimc keywords: - [ - cryptographic primitives, - Noir project, - sha256, - blake2s, - pedersen, - mimc_bn254, - mimc, - hash - ] + [cryptographic primitives, Noir project, sha256, blake2s, pedersen, mimc_bn254, mimc, hash] --- -import BlackBoxInfo from './common/\_blackbox.mdx'; +import BlackBoxInfo from './common/_blackbox.mdx'; ## sha256 @@ -34,7 +26,7 @@ fn main() { } ``` - + ## blake2s @@ -53,7 +45,7 @@ fn main() { } ``` - + ## pedersen @@ -72,14 +64,16 @@ fn main() { } ``` - + ## keccak256 -Given an array of bytes (`u8`), returns the resulting keccak hash as an array of 32 bytes (`[u8; 32]`). +Given an array of bytes (`u8`), returns the resulting keccak hash as an array of 32 bytes +(`[u8; 32]`). You can optionally specify a message_size to hash only the first `message_size` bytes +of the input. ```rust -fn keccak256(_input : [u8; N]) -> [u8; 32] +fn keccak256(_input : [u8; N], _message_size: u32) -> [u8; 32] ``` example: @@ -87,15 +81,17 @@ example: ```rust fn main() { let x = [163, 117, 178, 149] // some random bytes - let hash = std::hash::keccak256(x); + let message_size = 4; + let hash = std::hash::keccak256(x, message_size); } ``` - + ## poseidon -Given an array of Fields, returns a new Field with the Poseidon Hash. Mind that you need to specify how many inputs are there to your Poseidon function. +Given an array of Fields, returns a new Field with the Poseidon Hash. Mind that you need to specify +how many inputs are there to your Poseidon function. ```rust // example for hash_1, hash_2 accepts an array of length 2, etc @@ -144,6 +140,7 @@ fn main() { fn hash_to_field(_input : [Field; N]) -> Field {} ``` -Calculates the `blake2s` hash of the inputs and returns the hash modulo the field modulus to return a value which can be represented as a `Field`. +Calculates the `blake2s` hash of the inputs and returns the hash modulo the field modulus to return +a value which can be represented as a `Field`. - +