Propagate the NBYTES constant from Int256 to SecKey

This commit is contained in:
Julien Cretin
2020-06-04 14:32:04 +02:00
parent 3d2de2b02a
commit 0073c153d2
2 changed files with 5 additions and 3 deletions

View File

@@ -22,6 +22,8 @@ use super::{Hash256, HashBlockSize64Bytes};
use alloc::vec::Vec; use alloc::vec::Vec;
use core::marker::PhantomData; use core::marker::PhantomData;
pub use super::ec::int256::NBYTES;
#[derive(Clone, PartialEq)] #[derive(Clone, PartialEq)]
#[cfg_attr(feature = "derive_debug", derive(Debug))] #[cfg_attr(feature = "derive_debug", derive(Debug))]
pub struct SecKey { pub struct SecKey {
@@ -140,7 +142,7 @@ impl SecKey {
} }
} }
pub fn from_bytes(bytes: &[u8; 32]) -> Option<SecKey> { pub fn from_bytes(bytes: &[u8; NBYTES]) -> Option<SecKey> {
let k = NonZeroExponentP256::from_int_checked(Int256::from_bin(bytes)); let k = NonZeroExponentP256::from_int_checked(Int256::from_bin(bytes));
// The branching here is fine because all this reveals is whether the key was invalid. // The branching here is fine because all this reveals is whether the key was invalid.
if bool::from(k.is_none()) { if bool::from(k.is_none()) {
@@ -150,7 +152,7 @@ impl SecKey {
Some(SecKey { k }) Some(SecKey { k })
} }
pub fn to_bytes(&self, bytes: &mut [u8; 32]) { pub fn to_bytes(&self, bytes: &mut [u8; NBYTES]) {
self.k.to_int().to_bin(bytes); self.k.to_int().to_bin(bytes);
} }
} }

View File

@@ -62,7 +62,7 @@ const AAGUID: usize = 7;
const NUM_TAGS: usize = 8; const NUM_TAGS: usize = 8;
const MAX_PIN_RETRIES: u8 = 6; const MAX_PIN_RETRIES: u8 = 6;
const ATTESTATION_PRIVATE_KEY_LENGTH: usize = 32; const ATTESTATION_PRIVATE_KEY_LENGTH: usize = crypto::ecdsa::NBYTES;
const AAGUID_LENGTH: usize = 16; const AAGUID_LENGTH: usize = 16;
#[derive(PartialEq, Eq, PartialOrd, Ord)] #[derive(PartialEq, Eq, PartialOrd, Ord)]