Skip to content

Commit 4a1d33e

Browse files
committed
rsa: enforce 65537 as the only permitted exponent
1 parent 52128cf commit 4a1d33e

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/rsa/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,12 @@ impl PublicKey {
141141
let n = BigUint::from_bytes_be(&bytes[0..256]);
142142
let e = BigUint::from_bytes_be(&bytes[256..264]);
143143

144+
// Whilst the RSA algorithm permits different exponents, every modern
145+
// system only ever uses 65537 and most also enforce this. Might as
146+
// well do the same.
147+
if e != BigUint::from(65537u32) {
148+
return Err(rsa::Error::InvalidExponent);
149+
}
144150
let key = RsaPublicKey::new(n, e)?;
145151
let inner = rsa::pkcs1v15::VerifyingKey::<Sha256>::new(key);
146152
Ok(Self { inner })

0 commit comments

Comments
 (0)