Skip to content

Commit

Permalink
update to latest crypto-bigint
Browse files Browse the repository at this point in the history
  • Loading branch information
dignifiedquire committed Dec 4, 2023
1 parent 57d6f95 commit 2cdd37c
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 11 deletions.
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.

8 changes: 4 additions & 4 deletions src/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ impl RsaPublicKey {
}
}

fn needed_bits(n: &BigUint) -> usize {
fn needed_bits(n: &BigUint) -> u32 {
// widen to the max size bits
let n_bits = n.bits();

Expand Down Expand Up @@ -625,7 +625,7 @@ pub(crate) fn to_biguint(uint: &BoxedUint) -> BigUint {
BigUint::from_bytes_be(&uint.to_be_bytes())
}

pub(crate) fn to_uint_exact(big_uint: BigUint, nbits: usize) -> BoxedUint {
pub(crate) fn to_uint_exact(big_uint: BigUint, nbits: u32) -> BoxedUint {
let res = inner_to_uint(big_uint);

match res.bits_precision().cmp(&nbits) {
Expand All @@ -643,13 +643,13 @@ fn inner_to_uint(big_uint: BigUint) -> BoxedUint {
let mut padded_bytes = vec![0u8; pad_count];
padded_bytes.extend_from_slice(&bytes);

BoxedUint::from_be_slice(&padded_bytes, padded_bytes.len() * 8).unwrap()
BoxedUint::from_be_slice(&padded_bytes, padded_bytes.len() as u32 * 8).unwrap()
}

pub(crate) fn to_uint(big_uint: BigUint) -> BoxedUint {
let nbits = needed_bits(&big_uint);
let res = inner_to_uint(big_uint);
if res.bits_precision() < nbits {
if (res.bits_precision() as u32) < nbits {
return res.widen(nbits);
}
res
Expand Down
2 changes: 1 addition & 1 deletion src/pkcs1v15.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ impl SignatureScheme for Pkcs1v15Sign {
pub_key,
self.prefix.as_ref(),
hashed,
&BoxedUint::from_be_slice(sig, sig.len() * 8)?,
&BoxedUint::from_be_slice(sig, sig.len() as u32 * 8)?,
sig.len(),
)
}
Expand Down
2 changes: 1 addition & 1 deletion src/pkcs1v15/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl TryFrom<&[u8]> for Signature {
let len = bytes.len();
Ok(Self {
// TODO: how to convert error?
inner: BoxedUint::from_be_slice(bytes, len * 8).unwrap(),
inner: BoxedUint::from_be_slice(bytes, len as u32 * 8).unwrap(),
len,
})
}
Expand Down
2 changes: 1 addition & 1 deletion src/pss.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ impl SignatureScheme for Pss {
verify(
pub_key,
hashed,
&BoxedUint::from_be_slice(sig, sig.len() * 8)?,
&BoxedUint::from_be_slice(sig, sig.len() as u32 * 8)?,
sig.len(),
&mut *self.digest,
self.salt_len,
Expand Down
2 changes: 1 addition & 1 deletion src/pss/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl TryFrom<&[u8]> for Signature {
Ok(Self {
len,
// TODO: how to convert the error?
inner: BoxedUint::from_be_slice(bytes, len * 8).unwrap(),
inner: BoxedUint::from_be_slice(bytes, len as u32 * 8).unwrap(),
})
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/traits/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ pub trait PublicKeyPartsNew {

fn n_params(&self) -> BoxedResidueParams;

fn n_bits_precision(&self) -> usize {
fn n_bits_precision(&self) -> u32 {
self.n().bits_precision()
}

/// Returns the modulus size in bytes. Raw signatures and ciphertexts for
/// or by this public key will have the same size.
fn size(&self) -> usize {
(self.n().bits() + 7) / 8
(self.n().bits() as usize + 7) / 8
}
}

Expand Down

0 comments on commit 2cdd37c

Please sign in to comment.