Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/michaelelliot/noir-sha1
A Noir implementation of the SHA-1 hashing algorithm with variable length input
https://github.com/michaelelliot/noir-sha1
Last synced: 3 months ago
JSON representation
A Noir implementation of the SHA-1 hashing algorithm with variable length input
- Host: GitHub
- URL: https://github.com/michaelelliot/noir-sha1
- Owner: michaelelliot
- License: mit
- Created: 2023-09-27T08:21:17.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-01-18T10:05:54.000Z (about 1 year ago)
- Last Synced: 2024-02-13T00:52:00.769Z (12 months ago)
- Language: Rust
- Homepage:
- Size: 14.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE-MIT
Awesome Lists containing this project
- awesome-noir - SHA-1 - a library for generating hashes using SHA-1 hashing function (Libraries / Cryptography)
README
# Noir SHA-1
[![Noir](https://img.shields.io/badge/Noir-0.16.0-blue.svg)](https://github.com/noir-lang/noir)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![Nargo Test 🌌](https://github.com/michaelelliot/noir-sha1/actions/workflows/test.yml/badge.svg)](https://github.com/michaelelliot/noir-sha1/actions/workflows/test.yml)This library contains an implementation of the SHA-1 hashing algorithm.
While SHA-1 is no longer considered secure for general use, it is still useful on resource-constrained devices for certain use cases.
One example is in smart cards where a random challenge is generated by a verifier and the smart card digitally signs a payload that contains a SHA-1 hash based on the random challenge.
This is still reasonably secure because the time window available for brute-forcing a SHA-1 hash is extremely limited.## Security Notice
SHA-1 is deprecated for most security-sensitive applications but retains utility in specific, time-bound scenarios.
## Usage
In your `Nargo.toml` file, add the following dependency:
```toml
[dependencies]
sha1 = { tag = "v0.0.5", git = "https://github.com/michaelelliot/noir-sha1", directory = "crates/noir-sha1" }
```Then use it in your Noir project like this:
```rust
use dep::sha1::sha1;fn main(input: [u8; 128], input_len: u16, hash: pub [u8; 20]) {
// Generate SHA-1 hash digest of input
let compare_hash = sha1(input, input_len);
assert(hash == compare_hash);
}
```*NOTE:* The `input` parameter must be a `u8` byte array with a length that's a multiple of 64, such as 64, 128, 192, or 256 etc. (currently up to a maximum of 256).
The rest of the byte array can be zero-padded (`0x00`) as shown in the example below, with the `input_len` parameter specifying the number of initial bytes from the `input` to be used for calculating the digest.Here's an example unit test for the `main` entrypoint above:
```rust
#[test]
fn test_main() {
// Hal Finney was a cypherpunk pioneer
let test_msg: [u8; 64] = [
0x48, 0x61, 0x6c, 0x20, 0x46, 0x69, 0x6e, 0x6e,
0x65, 0x79, 0x20, 0x77, 0x61, 0x73, 0x20, 0x61,
0x20, 0x63, 0x79, 0x70, 0x68, 0x65, 0x72, 0x70,
0x75, 0x6e, 0x6b, 0x20, 0x70, 0x69, 0x6f, 0x6e,
0x65, 0x65, 0x72, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00];
let test_hash: [u8; 20] = [
0x3a, 0x93, 0x96, 0x11, 0xee, 0x6e, 0x4d, 0xfb, 0xe2, 0x0e,
0xc2, 0xcb, 0xf2, 0xa3, 0x55, 0x52, 0xbc, 0x47, 0x03, 0x4a];
main(test_msg, 35, test_hash);
}
```## Example
Noir example source code: [`./example/src/main.nr`](./example/src/main.nr)
## Gates
ACIR Opcodes: 23501. Backend Circuit Size: 81495.
## License
MIT License
Copyright (c) 2023 Michael Elliot
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.