Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Left pad signatures when encoding #325

Merged
merged 1 commit into from
May 4, 2023
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
5 changes: 4 additions & 1 deletion src/pkcs1v15/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
}
}

Expand Down
5 changes: 4 additions & 1 deletion src/pss/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
}
}

Expand Down