Skip to content

Commit

Permalink
Merge pull request #5 from LFDT-Lockness/discord
Browse files Browse the repository at this point in the history
Add info about our discord
  • Loading branch information
survived authored Sep 26, 2024
2 parents 8482035 + bf066ce commit 0d70142
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 94 deletions.
24 changes: 0 additions & 24 deletions .github/workflows/readme.yml

This file was deleted.

5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## v0.1.1
* Update links in crate settings, update readme [#5]

[#5]: https://github.com/LFDT-Lockness/rand_hash/pull/5

## v0.1.0

The first release!
14 changes: 11 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@

Thanks for taking interest to contributing to our project!

## Join us in Discord!
We welcome all contributors to communicate with us [in Discord]! Please, reach out to us
in `#lockness-contribute` room.

## Pull Requests
Prior to making a PR, we ask you to communicate it with us, preferably by opening an issue.
This would help to keep your work aligned with the maintainers view and get insights from
them.
Prior to making a PR, we ask you to communicate it with us, either [in Discord] or, if you
prefer, by opening an issue in the repo. This would help to keep your work aligned with the
maintainers view and avoid situations in which we can't accept your contribution.

All commits are required to be signed via verified GPG key. You can read about commit signing
in [this series of articles](https://docs.github.com/en/authentication/managing-commit-signature-verification)
Expand Down Expand Up @@ -62,3 +66,7 @@ communicate with us for other reasons.
However, if you want to report something that you believe might be a security
vulnerability or a security flaw in this or any upstream project, please report
it following the procedure described in [SECURITY.md](./SECURITY.md).

Feel free to reach out to us [in Discord] as well.

[in Discord]: https://discordapp.com/channels/905194001349627914/1285268686147424388
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[package]
name = "rand_hash"
version = "0.1.0"
version = "0.1.1"
edition = "2021"
license = "Apache-2.0"
repository = "https://github.com/dfns/rand_hash"
repository = "https://github.com/LFDT-Lockness/rand_hash"
description = "Cryptographically-secure pseudo-random generator based on cryptographic hash function"

categories = ["cryptography", "no-std", "no-std::no-alloc"]
Expand Down
5 changes: 0 additions & 5 deletions Makefile

This file was deleted.

26 changes: 18 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
Cryptographically-secure pseudo-random generator based on cryptographic hash function
![License](https://img.shields.io/crates/l/rand_hash.svg)
[![Docs](https://docs.rs/rand_hash/badge.svg)](https://docs.rs/rand_hash)
[![Crates io](https://img.shields.io/crates/v/rand_hash.svg)](https://crates.io/crates/rand_hash)
[![Discord](https://img.shields.io/discord/905194001349627914?logo=discord&logoColor=ffffff&label=Discord)][in Discord]

# Cryptographically-secure pseudo-random generator based on cryptographic hash function

`HashRng` is CSPRNG that takes any hashable data as seed and produces a stream
of randomness that has the same entropy as the seed. It uses `udigest` crate to
of randomness that has the same entropy as the seed. It uses [`udigest`](https://docs.rs/udigest) crate to
unambiguously hash the seed.

### Motivation
## Motivation
Usually, CSPRNGs have a fixed-size seed. For instance, [`ChaCha20Rng`](https://docs.rs/rand_chacha/latest/rand_chacha/struct.ChaCha20Rng.html)
has seed of 32 bytes. That means that when you want to derive randomness from data which
has entropy exceeding 32 bytes, you'll have to truncate the seed to 32 bytes (e.g. by hashing it),
Expand All @@ -14,24 +19,24 @@ parameter and make it less secure than desired.
`HashRng`, on other hand, takes advantage of full entropy of the seed. It does so by
hashing a counter and then the seed for each block, i.e. the output randomness is:

```
```text
HashRng(seed) = H(0, seed) || H(1, seed) || ...
```

### Security and performance considerations
## Security and performance considerations
`HashRng` internally uses u64 counter, which means that the period of the sequence is
2<sup>64</sup> times `Digest::OutputSize` (size of hash output).

Although we did not perform benchmarks, intuitively, `HashRng` is expected to be noticeably
slower than other CSPRNG based on permutations (such as `ChaCha20Rng`)

### Example
## Example
```rust
use rand::RngCore;

#[derive(udigest::Digestable)]
pub struct Seed<'a> {
nonce: &'a u8,
nonce: &'a [u8],
param_a: &'a str,
param_b: &'a str,
// ...
Expand All @@ -45,6 +50,11 @@ let seed = Seed {
};
let mut rng = rand_hash::HashRng::<sha2::Sha256, _>::from_seed(&seed);

let mut randomness = 0u8; 256;
let mut randomness = [0u8; 256];
rng.fill_bytes(&mut randomness);
```

## Join us in Discord!
Feel free to reach out to us [in Discord]!

[in Discord]: https://discordapp.com/channels/905194001349627914/1285268686147424388
52 changes: 1 addition & 51 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,54 +1,4 @@
//! Cryptographically-secure pseudo-random generator based on cryptographic hash function
//!
//! [`HashRng`] is CSPRNG that takes any hashable data as seed and produces a stream
//! of randomness that has the same entropy as the seed. It uses [`udigest`] crate to
//! unambiguously hash the seed.
//!
//! ## Motivation
//! Usually, CSPRNGs have a fixed-size seed. For instance, [`ChaCha20Rng`](https://docs.rs/rand_chacha/latest/rand_chacha/struct.ChaCha20Rng.html)
//! has seed of 32 bytes. That means that when you want to derive randomness from data which
//! has entropy exceeding 32 bytes, you'll have to truncate the seed to 32 bytes (e.g. by hashing it),
//! so you won't be able to take advantage of exceeding entropy. This may influence security
//! parameter and make it less secure than desired.
//!
//! [`HashRng`], on other hand, takes advantage of full entropy of the seed. It does so by
//! hashing a counter and then the seed for each block, i.e. the output randomness is:
//!
//! ```text
//! HashRng(seed) = H(0, seed) || H(1, seed) || ...
//! ```
//!
//! ## Security and performance considerations
//! `HashRng` internally uses u64 counter, which means that the period of the sequence is
//! 2<sup>64</sup> times `Digest::OutputSize` (size of hash output).
//!
//! Although we did not perform benchmarks, intuitively, `HashRng` is expected to be noticeably
//! slower than other CSPRNG based on permutations (such as `ChaCha20Rng`)
//!
//! ## Example
//! ```rust
//! use rand::RngCore;
//!
//! #[derive(udigest::Digestable)]
//! pub struct Seed<'a> {
//! nonce: &'a [u8],
//! param_a: &'a str,
//! param_b: &'a str,
//! // ...
//! }
//!
//! let seed = Seed {
//! nonce: b"very unpredictable string",
//! param_a: "some other data containing entropy",
//! param_b: "something else",
//! // ...
//! };
//! let mut rng = rand_hash::HashRng::<sha2::Sha256, _>::from_seed(&seed);
//!
//! let mut randomness = [0u8; 256];
//! rng.fill_bytes(&mut randomness);
//! ```

#![doc = include_str!("../README.md")]
#![no_std]
#![forbid(unused_crate_dependencies, missing_docs)]
#![cfg_attr(
Expand Down

0 comments on commit 0d70142

Please sign in to comment.