Skip to content

Commit

Permalink
Merge pull request #43 from ryankurte/hc128-reduce-stack
Browse files Browse the repository at this point in the history
reduce stack allocation in `Hc128Core::init` for embedded use
  • Loading branch information
dhardy committed Apr 15, 2023
2 parents 13ec794 + d811814 commit 0b59b21
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
3 changes: 3 additions & 0 deletions rand_hc/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.3.2] - 2023-04-15
- Reduce stack use in `Hc128Core::init`

## [0.3.1] - 2021-06-15
- Adjust crate links

Expand Down
2 changes: 1 addition & 1 deletion rand_hc/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rand_hc"
version = "0.3.1"
version = "0.3.2"
authors = ["The Rand Project Developers"]
license = "MIT OR Apache-2.0"
readme = "README.md"
Expand Down
5 changes: 2 additions & 3 deletions rand_hc/src/hc128.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,8 @@ impl Hc128Core {
x.rotate_right(17) ^ x.rotate_right(19) ^ (x >> 10)
}

let mut t = [0u32; 1024];
let mut core = Self { t: [0u32; 1024], counter1024: 0 };
let t = &mut core.t;

// Expand the key and iv into P and Q
let (key, iv) = seed.split_at(4);
Expand Down Expand Up @@ -331,8 +332,6 @@ impl Hc128Core {
.wrapping_add(256 + i as u32);
}

let mut core = Self { t, counter1024: 0 };

// run the cipher 1024 steps
for _ in 0..64 {
core.sixteen_steps()
Expand Down

0 comments on commit 0b59b21

Please sign in to comment.