Skip to content
This repository has been archived by the owner on Oct 17, 2023. It is now read-only.

updating keccak for message_size #180

Merged
merged 1 commit into from
Jun 5, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 19 additions & 22 deletions docs/standard_library/cryptographic_primitives/00_hashes.mdx
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -34,7 +26,7 @@ fn main() {
}
```

<BlackBoxInfo/>
<BlackBoxInfo />

## blake2s

Expand All @@ -53,7 +45,7 @@ fn main() {
}
```

<BlackBoxInfo/>
<BlackBoxInfo />

## pedersen

Expand All @@ -72,30 +64,34 @@ fn main() {
}
```

<BlackBoxInfo/>
<BlackBoxInfo />

## 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<N>(_input : [u8; N]) -> [u8; 32]
fn keccak256<N>(_input : [u8; N], _message_size: u32) -> [u8; 32]
```

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);
}
```

<BlackBoxInfo/>
<BlackBoxInfo />

## 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
Expand Down Expand Up @@ -144,6 +140,7 @@ fn main() {
fn hash_to_field<N>(_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`.

<BlackBoxInfo/>
<BlackBoxInfo />