Skip to content
This repository has been archived by the owner on Jul 29, 2024. It is now read-only.

Commit

Permalink
add assert for curve check to stop API misuse.
Browse files Browse the repository at this point in the history
Signed-off-by: Yang, Longlong <[email protected]>
  • Loading branch information
longlongyang committed Dec 25, 2023
1 parent 05c41c6 commit 1a78c6f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
6 changes: 5 additions & 1 deletion spdmlib/src/crypto/spdm_ring/asym_verify_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,11 @@ fn asym_verify(
// add ASN.1 for the ECDSA binary signature
fn ecc_signature_bin_to_der(signature: &[u8], der_signature: &mut [u8]) -> SpdmResult<usize> {
let sign_size = signature.len();
assert_eq!(sign_size % 2, 0);
assert!(
// prevent API misuse
sign_size == crate::protocol::ECDSA_ECC_NIST_P256_KEY_SIZE
|| sign_size == crate::protocol::ECDSA_ECC_NIST_P384_KEY_SIZE
);
let half_size = sign_size / 2;

let mut r_index = half_size;
Expand Down
4 changes: 4 additions & 0 deletions spdmlib_crypto_mbedtls/src/asym_verify_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ fn asym_verify(
// add ASN.1 for the ECDSA binary signature
fn ecc_signature_bin_to_der(signature: &[u8], der_signature: &mut [u8]) -> SpdmResult<usize> {
let sign_size = signature.len();
assert!(
sign_size == spdmlib::protocol::ECDSA_ECC_NIST_P256_KEY_SIZE
|| sign_size == spdmlib::protocol::ECDSA_ECC_NIST_P384_KEY_SIZE
);
let half_size = sign_size / 2;

let mut r_index = half_size;
Expand Down

0 comments on commit 1a78c6f

Please sign in to comment.