Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

EcDSA signatures: follow requested serialization format #37

Merged
merged 2 commits into from
Oct 1, 2024
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
17 changes: 14 additions & 3 deletions src/core_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1782,9 +1782,20 @@ impl<Twi: I2CForT1, D: DelayUs<u32>> Se050Backend<Twi, D> {
error!("Failed to parse DER signature: {_err:?}");
Error::FunctionFailed
})?;
let mut signature = Bytes::new();
assert!(signature.capacity() > 2 * field_byte_size);
signature.extend(signature_der.to_bytes(field_byte_size));

let signature = match req.format {
trussed::types::SignatureSerialization::Asn1Der => Bytes::from_slice(res.signature)
.map_err(|_err| {
error_now!("Failed to write signature to response: {_err:?}");
})
.unwrap(),
trussed::types::SignatureSerialization::Raw => {
let mut signature = Bytes::new();
assert!(signature.capacity() > 2 * field_byte_size);
signature.extend(signature_der.to_bytes(field_byte_size));
signature
}
};

if let Some(key_id) = volatile_key_id {
self.clear_volatile_key(key_id)?;
Expand Down
5 changes: 4 additions & 1 deletion src/trussed_auth_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,10 @@ impl<Twi: I2CForT1, D: DelayUs<u32>> Se050Backend<Twi, D> {
let mut out = Key::default();
#[allow(clippy::expect_used)]
kdf.expand(client_id.as_ref().as_bytes(), &mut *out)
.expect("Out data is always valid");
.map_err(|_err| {
error_now!("Out data is always valid: {_err:?}");
})
.unwrap();
out
}

Expand Down
10 changes: 8 additions & 2 deletions src/trussed_auth_impl/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,10 @@ fn load_app_salt<S: Filestore>(fs: &mut S, location: Location) -> Result<Salt, E
pub fn expand_app_key(salt: &Salt, application_key: &Key, info: &[u8]) -> Key {
#[allow(clippy::expect_used)]
let mut hmac = Hmac::<Sha256>::new_from_slice(&**application_key)
.expect("Slice will always be of acceptable size");
.map_err(|_err| {
error_now!("Slice will always be of acceptable size: {_err:?}");
})
.unwrap();
hmac.update(&**salt);
hmac.update(&(info.len() as u64).to_be_bytes());
hmac.update(info);
Expand All @@ -118,7 +121,10 @@ fn pin_len(pin: &[u8]) -> u8 {
pub fn expand_pin_key(salt: &Salt, application_key: &Key, id: PinId, pin: &[u8]) -> PinKey {
#[allow(clippy::expect_used)]
let mut hmac = Hmac::<Sha256>::new_from_slice(&**application_key)
.expect("Slice will always be of acceptable size");
.map_err(|_err| {
error_now!("Slice will always be of acceptable size: {_err:?}");
})
.unwrap();
hmac.update(&[u8::from(id)]);
hmac.update(&[pin_len(pin)]);
hmac.update(pin);
Expand Down