Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions src/pkcs1v15.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ pub use self::{
use alloc::{boxed::Box, vec::Vec};
use const_oid::AssociatedOid;
use core::fmt::Debug;
use crypto_bigint::BoxedUint;
use digest::Digest;
use rand_core::TryCryptoRng;

Expand Down Expand Up @@ -207,7 +206,7 @@ fn sign<R: TryCryptoRng + ?Sized>(
) -> Result<Vec<u8>> {
let em = pkcs1v15_sign_pad(prefix, hashed, priv_key.size())?;

let em = BoxedUint::from_be_slice(&em, priv_key.n_bits_precision())?;
let em = os2ip(&em, priv_key.n_bits_precision())?;
// The signature itself is public; only the computation is secret
Ok(i2osp(
rsa_decrypt_and_check(priv_key, rng, &em)?,
Expand All @@ -222,8 +221,7 @@ fn verify(pub_key: &RsaPublicKey, prefix: &[u8], hashed: &[u8], sig: &[u8]) -> R
if sig.len() != pub_key.size() {
return Err(Error::Verification);
}
let s = BoxedUint::from_be_slice(sig, pub_key.n_bits_precision())
.map_err(|_| Error::Verification)?;
let s = os2ip(sig, pub_key.n_bits_precision()).map_err(|_| Error::Verification)?;
if s >= *pub_key.n().as_ref() {
return Err(Error::Verification);
}
Expand Down Expand Up @@ -284,6 +282,7 @@ mod tests {
SignatureEncoding, Signer, Verifier,
};
use base64ct::{Base64, Encoding};
use crypto_bigint::BoxedUint;
use hex_literal::hex;
use rand::rngs::ChaCha8Rng;
use rand_core::{Rng, SeedableRng};
Expand Down
13 changes: 5 additions & 8 deletions src/pss.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,11 @@ pub use self::{

use alloc::vec::Vec;
use core::fmt::{self, Debug};
use crypto_bigint::BoxedUint;

use digest::{Digest, FixedOutputReset};
use rand_core::TryCryptoRng;

use crate::algorithms::pad::i2osp;
use crate::algorithms::pad::{i2osp, os2ip};
use crate::algorithms::pss::*;
use crate::algorithms::rsa::{rsa_decrypt_and_check, rsa_encrypt};
use crate::errors::{Error, Result};
Expand Down Expand Up @@ -148,8 +147,7 @@ where
if sig.len() != pub_key.size() {
return Err(Error::Verification);
}
let s = BoxedUint::from_be_slice(sig, pub_key.n_bits_precision())
.map_err(|_| Error::Verification)?;
let s = os2ip(sig, pub_key.n_bits_precision()).map_err(|_| Error::Verification)?;
let raw = rsa_encrypt(pub_key, &s)?;
let mut em = i2osp(raw, pub_key.size());

Expand All @@ -168,8 +166,7 @@ where
if sig.len() != pub_key.size() {
return Err(Error::Verification);
}
let s = BoxedUint::from_be_slice(sig, pub_key.n_bits_precision())
.map_err(|_| Error::Verification)?;
let s = os2ip(sig, pub_key.n_bits_precision()).map_err(|_| Error::Verification)?;
if s >= *pub_key.n().as_ref() {
return Err(Error::Verification);
}
Expand Down Expand Up @@ -239,7 +236,7 @@ where

let em = emsa_pss_encode(hashed, em_bits as _, salt, digest)?;

let em = BoxedUint::from_be_slice(&em, priv_key.n_bits_precision())?;
let em = os2ip(&em, priv_key.n_bits_precision())?;
let raw = rsa_decrypt_and_check(priv_key, blind_rng, &em)?;
Ok(i2osp(raw, priv_key.size()))
}
Expand All @@ -257,7 +254,7 @@ where
let em_bits = priv_key.n().bits() - 1;
let em = emsa_pss_encode_digest::<D>(hashed, em_bits as _, salt)?;

let em = BoxedUint::from_be_slice(&em, priv_key.n_bits_precision())?;
let em = os2ip(&em, priv_key.n_bits_precision())?;
Ok(i2osp(
rsa_decrypt_and_check(priv_key, blind_rng, &em)?,
priv_key.size(),
Expand Down
Loading