Skip to content

Commit

Permalink
reduce_hash
Browse files Browse the repository at this point in the history
  • Loading branch information
baloo committed Mar 3, 2025
1 parent a0a9a1f commit c0a9f41
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions dsa/src/components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
use crate::{size::KeySize, two};
use crypto_bigint::{BoxedUint, NonZero, Odd};
use pkcs8::der::{
self, asn1::UintRef, DecodeValue, Encode, EncodeValue, Header, Length, Reader, Sequence, Tag,
Writer,
self, DecodeValue, Encode, EncodeValue, Header, Length, Reader, Sequence, Tag, Writer,
asn1::UintRef,
};
use signature::rand_core::CryptoRng;

Expand Down
10 changes: 5 additions & 5 deletions dsa/src/generate/secret_number.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ use digest::{core_api::BlockSizeUser, Digest, FixedOutputReset};
use signature::rand_core::TryCryptoRng;
use zeroize::Zeroizing;

fn strip_leading_zeros(buffer: &[u8], desired_size: usize) -> &[u8] {
&buffer[(buffer.len() - desired_size)..]
fn reduce_hash(hash: &[u8], desired_size: usize) -> &[u8] {
&hash[(hash.len() - desired_size)..]
}

/// Generate a per-message secret number k deterministically using the method described in RFC 6979
Expand All @@ -34,13 +34,13 @@ where

// Reduce hash mod q
let hash = (hash % q).to_be_bytes();
let hash = strip_leading_zeros(&hash, size);
let hash = reduce_hash(&hash, size);

let q_bytes = q.to_be_bytes();
let q_bytes = strip_leading_zeros(&q_bytes, size);
let q_bytes = reduce_hash(&q_bytes, size);

let x_bytes = Zeroizing::new(signing_key.x().to_be_bytes());
let x_bytes = strip_leading_zeros(&x_bytes, size);
let x_bytes = reduce_hash(&x_bytes, size);

let mut buffer = vec![0; size];
loop {
Expand Down

0 comments on commit c0a9f41

Please sign in to comment.