Skip to content

Commit

Permalink
sumhash512core: use unique cell to have singleton lookup table
Browse files Browse the repository at this point in the history
Signed-off-by: Ignacio Hagopian <[email protected]>
  • Loading branch information
jsign committed Aug 13, 2022
1 parent 9c51d4a commit cda197a
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/sumhash512core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use digest::{
};

use byteorder::{ByteOrder, LittleEndian};
use once_cell::sync::Lazy;

use crate::compress::{Compressor, LookupTable, Matrix};

Expand All @@ -31,23 +32,25 @@ impl AlgorandSumhash512Core {
}
}

static LOOKUP_TABLE: Lazy<LookupTable> =
Lazy::new(|| Matrix::random_from_seed("Algorand".as_bytes(), 8, 1024).lookup_table());

impl Default for AlgorandSumhash512Core {
fn default() -> Self {
let c = Matrix::random_from_seed("Algorand".as_bytes(), 8, 1024);
Sumhash512Core::new(c.lookup_table(), None)
Sumhash512Core::new(&LOOKUP_TABLE, None)
}
}

/// Sumhash512Core returns a core implementation for sumhash cryptographic hash function.
pub struct Sumhash512Core<C: Compressor> {
c: C,
pub struct Sumhash512Core<C: Compressor + 'static> {
c: &'static C,
h: [u8; DIGEST_SIZE], // hash chain (from last compression, or IV)
len: u64,
salt: Option<[u8; DIGEST_BLOCK_SIZE]>,
}

impl<C: Compressor> Sumhash512Core<C> {
fn new(c: C, salt: Option<[u8; DIGEST_BLOCK_SIZE]>) -> Self {
fn new(c: &'static C, salt: Option<[u8; DIGEST_BLOCK_SIZE]>) -> Self {
Self {
c,
h: [0; DIGEST_SIZE],
Expand Down

0 comments on commit cda197a

Please sign in to comment.