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

session: expose derive_keys #556

Closed
wants to merge 1 commit into from
Closed
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
10 changes: 4 additions & 6 deletions src/session/securechannel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,19 +182,17 @@ impl SecureChannel {
card_challenge: Challenge,
) -> Self {
let context = Context::from_challenges(host_challenge, card_challenge);
let enc_key = derive_key(authentication_key.enc_key(), 0b100, &context);
let mac_key = derive_key(authentication_key.mac_key(), 0b110, &context);
let rmac_key = derive_key(authentication_key.mac_key(), 0b111, &context);
let session_keys = context.derive_keys(authentication_key);
let mac_chaining_value = [0u8; Mac::BYTE_SIZE * 2];

Self {
id,
counter: 0,
security_level: SecurityLevel::None,
context,
enc_key,
mac_key,
rmac_key,
enc_key: session_keys.enc_key,
mac_key: session_keys.mac_key,
rmac_key: session_keys.rmac_key,
mac_chaining_value,
}
}
Expand Down
16 changes: 15 additions & 1 deletion src/session/securechannel/context.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Derivation context (i.e. concatenated challenges)

use super::{Challenge, CHALLENGE_SIZE};
use super::{derive_key, Challenge, SessionKeys, CHALLENGE_SIZE};
use crate::authentication;

/// Size of a session context
const CONTEXT_SIZE: usize = CHALLENGE_SIZE * 2;
Expand All @@ -21,4 +22,17 @@ impl Context {
pub fn as_slice(&self) -> &[u8] {
&self.0
}

/// Derive session keys from context and authentication key
pub fn derive_keys(&self, authentication_key: &authentication::Key) -> SessionKeys {
let enc_key = derive_key(authentication_key.enc_key(), 0b100, self);
let mac_key = derive_key(authentication_key.mac_key(), 0b110, self);
let rmac_key = derive_key(authentication_key.mac_key(), 0b111, self);

SessionKeys {
enc_key,
mac_key,
rmac_key,
}
}
}
Loading