From 2cdd37c7b924a2eabf6a1d91412ae2833f68bb79 Mon Sep 17 00:00:00 2001 From: dignifiedquire Date: Mon, 4 Dec 2023 22:22:48 +0100 Subject: [PATCH] update to latest crypto-bigint --- Cargo.lock | 2 +- src/key.rs | 8 ++++---- src/pkcs1v15.rs | 2 +- src/pkcs1v15/signature.rs | 2 +- src/pss.rs | 2 +- src/pss/signature.rs | 2 +- src/traits/keys.rs | 4 ++-- 7 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index cb52c0f4..866cdae8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -125,7 +125,7 @@ dependencies = [ [[package]] name = "crypto-bigint" version = "0.6.0-pre.0" -source = "git+https://github.com/RustCrypto/crypto-bigint?branch=master#0cd01b7a210adfe0e8da7e0c875cc06360f3f934" +source = "git+https://github.com/RustCrypto/crypto-bigint?branch=master#124b8cf79cc4532d0e27805cb390a642784d7ac2" dependencies = [ "rand_core", "serdect", diff --git a/src/key.rs b/src/key.rs index 3f1ee820..30ce80ad 100644 --- a/src/key.rs +++ b/src/key.rs @@ -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(); @@ -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) { @@ -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 diff --git a/src/pkcs1v15.rs b/src/pkcs1v15.rs index 7488dab7..d974537e 100644 --- a/src/pkcs1v15.rs +++ b/src/pkcs1v15.rs @@ -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(), ) } diff --git a/src/pkcs1v15/signature.rs b/src/pkcs1v15/signature.rs index 89017ff1..4e3528bc 100644 --- a/src/pkcs1v15/signature.rs +++ b/src/pkcs1v15/signature.rs @@ -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, }) } diff --git a/src/pss.rs b/src/pss.rs index 454c6426..1ec0447d 100644 --- a/src/pss.rs +++ b/src/pss.rs @@ -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, diff --git a/src/pss/signature.rs b/src/pss/signature.rs index 38d178e5..e135a870 100644 --- a/src/pss/signature.rs +++ b/src/pss/signature.rs @@ -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(), }) } } diff --git a/src/traits/keys.rs b/src/traits/keys.rs index 671d0647..6beb52a6 100644 --- a/src/traits/keys.rs +++ b/src/traits/keys.rs @@ -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 } }