Skip to content

Commit d0cc2a0

Browse files
committed
Replace PUBLIC_MODULUS_MAX_LEN with VERIFY_PUBLIC_MODULUS_MAX_LEN.
`VERIFY_PUBLIC_MODULUS_MAX_LEN` is measured in bytes, whereas `PUBLIC_MODULUS_MAX_LEN` was measured in bits.
1 parent 8aae8e0 commit d0cc2a0

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

src/rsa/padding.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ impl Verification for PSS {
290290
}
291291

292292
// Step 7.
293-
let mut db = [0u8; super::PUBLIC_MODULUS_MAX_LEN / 8];
293+
let mut db = [0u8; super::VERIFY_PUBLIC_MODULUS_MAX_LEN];
294294
let db = &mut db[..metrics.db_len];
295295

296296
try!(mgf1(self.digest_alg, h_hash.as_slice_less_safe(), db));

src/rsa/rsa.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ pub use self::padding::{RSA_PKCS1_SHA256, RSA_PKCS1_SHA384, RSA_PKCS1_SHA512,
2424
RSA_PSS_SHA256, RSA_PSS_SHA384, RSA_PSS_SHA512};
2525

2626

27-
// Maximum RSA modulus size supported for signature verification (in bits).
28-
const PUBLIC_MODULUS_MAX_LEN: usize = 8192;
27+
// Maximum RSA modulus size supported for signature verification (in bytes).
28+
const VERIFY_PUBLIC_MODULUS_MAX_LEN: usize = 8192 / 8;
2929

3030
/// Parameters for RSA verification.
3131
pub struct RSAParameters {

src/rsa/verification.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
/// RSA PKCS#1 1.5 signatures.
1616
1717
use {bssl, c, error, private, signature};
18-
use super::{BIGNUM, PositiveInteger, PUBLIC_MODULUS_MAX_LEN, RSAParameters,
19-
parse_public_key};
18+
use super::{BIGNUM, PositiveInteger, VERIFY_PUBLIC_MODULUS_MAX_LEN,
19+
RSAParameters, parse_public_key};
2020
use untrusted;
2121

2222

@@ -110,7 +110,7 @@ pub fn verify_rsa(params: &RSAParameters,
110110
msg: untrusted::Input, signature: untrusted::Input)
111111
-> Result<(), error::Unspecified> {
112112
let signature = signature.as_slice_less_safe();
113-
let mut decoded = [0u8; (PUBLIC_MODULUS_MAX_LEN + 7) / 8];
113+
let mut decoded = [0u8; VERIFY_PUBLIC_MODULUS_MAX_LEN];
114114
if signature.len() > decoded.len() {
115115
return Err(error::Unspecified);
116116
}
@@ -121,7 +121,8 @@ pub fn verify_rsa(params: &RSAParameters,
121121
try!(bssl::map_result(unsafe {
122122
GFp_rsa_public_decrypt(decoded.as_mut_ptr(), decoded.len(), n.as_ref(),
123123
e.as_ref(), signature.as_ptr(), signature.len(),
124-
params.min_bits, PUBLIC_MODULUS_MAX_LEN)
124+
params.min_bits,
125+
VERIFY_PUBLIC_MODULUS_MAX_LEN * 8)
125126
}));
126127

127128
untrusted::Input::from(decoded).read_all(

0 commit comments

Comments
 (0)