Left pad signatures when encoding (#325)

The `SignatureEncoding` impl added in `rsa` v0.9 (or more specifically,
the `From<Signature>` impl for `Box<[u8]>` failed to properly left pad
the signatures so they matched the modulus size.

This adds the appropriate padding to the signature encoder.
This commit is contained in:
Tony Arcieri 2023-05-03 18:34:50 -06:00 committed by GitHub
parent 94856ec765
commit 53bb256451
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 2 deletions

View File

@ -4,6 +4,7 @@ pub use ::signature::{
SignatureEncoding, Signer, Verifier,
};
use crate::algorithms::pad::uint_to_be_pad;
use alloc::{boxed::Box, string::ToString};
use core::fmt::{Debug, Display, Formatter, LowerHex, UpperHex};
use num_bigint::BigUint;
@ -34,7 +35,9 @@ impl TryFrom<&[u8]> for Signature {
impl From<Signature> for Box<[u8]> {
fn from(signature: Signature) -> Box<[u8]> {
signature.inner.to_bytes_be().into_boxed_slice()
uint_to_be_pad(signature.inner, signature.len)
.expect("RSASSA-PKCS1-v1_5 length invariants should've been enforced")
.into_boxed_slice()
}
}

View File

@ -4,6 +4,7 @@ pub use ::signature::{
SignatureEncoding, Signer, Verifier,
};
use crate::algorithms::pad::uint_to_be_pad;
use alloc::{boxed::Box, string::ToString};
use core::fmt::{Debug, Display, Formatter, LowerHex, UpperHex};
use num_bigint::BigUint;
@ -34,7 +35,9 @@ impl TryFrom<&[u8]> for Signature {
impl From<Signature> for Box<[u8]> {
fn from(signature: Signature) -> Box<[u8]> {
signature.inner.to_bytes_be().into_boxed_slice()
uint_to_be_pad(signature.inner, signature.len)
.expect("RSASSA-PKCS1-v1_5 length invariants should've been enforced")
.into_boxed_slice()
}
}