https://github.com/zkpersona/noir-hmac
Noir implementation of HMAC(Hash-based Message Authentication Code)
https://github.com/zkpersona/noir-hmac
hmac hmac-sha256 library noir noir-lang zero-knowledge
Last synced: about 1 year ago
JSON representation
Noir implementation of HMAC(Hash-based Message Authentication Code)
- Host: GitHub
- URL: https://github.com/zkpersona/noir-hmac
- Owner: zkpersona
- License: mit
- Created: 2025-04-11T07:35:56.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-04-11T07:47:38.000Z (about 1 year ago)
- Last Synced: 2025-04-11T08:37:03.907Z (about 1 year ago)
- Topics: hmac, hmac-sha256, library, noir, noir-lang, zero-knowledge
- Language: Noir
- Homepage:
- Size: 50.8 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
- awesome-noir - Noir HMAC - hash-based message authentication code (Libraries / Cryptography)
README
# Noir HMAC(Hash-based Message Authentication Code)
Noir implementation of HMAC(Hash-based Message Authentication Code). Currently, the following hash functions are supported:
- SHA256
> Note: SHA512 will be supported in the future as soon as library is reviewed. See [noir-lang/sha512/pull/2](https://github.com/noir-lang/sha512/pull/2)
## Noir version compatibility
This library is tested to work as of Noir version >=1.0.0.beta-2
## Benchmarks
Benchmarks are ignored by `git` and checked on pull-request. As such, benchmarks may be generated
with the following command.
```bash
./scripts/build-gates-report.sh
```
The benchmark will be generated at `./gates_report.json`.
## Installation
In your _Nargo.toml_ file, add the version of this library you would like to install under dependency:
```toml
[dependencies]
noir_hmac = { tag = "v0.1.0", git = "https://github.com/zkpersona/noir-hmac", directory = "lib" }
```
## Usage
### HMAC-SHA256
```noir
use noir_hmac::hmac_sha256::hmac_sha256;
fn hmac_sha256_test() {
let key: BoundedVec = BoundedVec::from_array("secret_key".as_bytes());
let message: BoundedVec = BoundedVec::from_array("hello_world".as_bytes());
let hmac: [u8; 32] = hmac_sha256(key, message);
let expected: [u8; 32] = [
32, 245, 74, 230, 153, 92, 121, 130, 198, 181, 233, 222, 161, 142, 167, 35, 8, 91, 220, 193,
245, 93, 185, 150, 77, 51, 84, 8, 96, 219, 96, 75,
];
assert(hmac == expected);
}
```