Skip to content

Commit

Permalink
removed final explicit aead logic from nts_record
Browse files Browse the repository at this point in the history
  • Loading branch information
squell authored and davidv1992 committed Nov 30, 2023
1 parent 36deafc commit 3029a0d
Showing 1 changed file with 7 additions and 22 deletions.
29 changes: 7 additions & 22 deletions ntp-proto/src/nts_record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ use std::{
sync::Arc,
};

use aead::KeySizeUser;
use aes_siv::{Aes128SivAead, Aes256SivAead};

use crate::{
cookiestash::CookieStash,
keyset::{DecodedServerCookie, KeySet},
Expand Down Expand Up @@ -740,29 +737,17 @@ impl AeadAlgorithm {
) -> Result<NtsKeys, rustls::Error> {
match self {
AeadAlgorithm::AeadAesSivCmac256 => {
let c2s = extract_nts_key::<Aes128SivAead, _>(
tls_connection,
self.c2s_context(protocol),
)?;
let s2c = extract_nts_key::<Aes128SivAead, _>(
tls_connection,
self.s2c_context(protocol),
)?;
let c2s = extract_nts_key(tls_connection, self.c2s_context(protocol))?;
let s2c = extract_nts_key(tls_connection, self.s2c_context(protocol))?;

let c2s = Box::new(AesSivCmac256::new(c2s));
let s2c = Box::new(AesSivCmac256::new(s2c));

Ok(NtsKeys { c2s, s2c })
}
AeadAlgorithm::AeadAesSivCmac512 => {
let c2s = extract_nts_key::<Aes256SivAead, _>(
tls_connection,
self.c2s_context(protocol),
)?;
let s2c = extract_nts_key::<Aes256SivAead, _>(
tls_connection,
self.s2c_context(protocol),
)?;
let c2s = extract_nts_key(tls_connection, self.c2s_context(protocol))?;
let s2c = extract_nts_key(tls_connection, self.s2c_context(protocol))?;

let c2s = Box::new(AesSivCmac512::new(c2s));
let s2c = Box::new(AesSivCmac512::new(s2c));
Expand Down Expand Up @@ -804,11 +789,11 @@ pub struct NtsKeys {
s2c: Box<dyn Cipher>,
}

fn extract_nts_key<T: KeySizeUser, ConnectionData>(
fn extract_nts_key<T: Default + AsMut<[u8]>, ConnectionData>(
tls_connection: &rustls::ConnectionCommon<ConnectionData>,
context: [u8; 5],
) -> Result<aead::Key<T>, rustls::Error> {
let mut key: aead::Key<T> = Default::default();
) -> Result<T, rustls::Error> {
let mut key = T::default();
tls_connection.export_keying_material(
&mut key,
b"EXPORTER-network-time-security",
Expand Down

0 comments on commit 3029a0d

Please sign in to comment.