Skip to content
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
2 changes: 1 addition & 1 deletion kbkdf/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ where
/// - Prf - the Pseudorandom Function to derive keys from
/// - K - the expected output length of the newly derived key
/// - R - An integer (1 <= r <= 32) that indicates the length of the binary encoding of the counter i
/// as an integer in the interval [1, 2r − 1].
/// as an integer in the interval [1, 2r − 1].
pub trait Kbkdf<Prf, K, R: sealed::R>
where
Prf: Mac + KeyInit,
Expand Down
29 changes: 19 additions & 10 deletions kbkdf/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ fn test_static_values_counter() {
.with_context(v.context)
.build()
),
Ok(Array::<_, _>::try_from(v.expected).unwrap().clone()),
Ok(Array::<_, _>::try_from(v.expected).unwrap()),
"key derivation failed for (index: {i}):\n{v:x?}"
);
}
Expand All @@ -97,13 +97,22 @@ fn test_counter_kbkdfvs() {
let counter = Counter::<HmacSha256, MockOutput>::default();
// KDFCTR_gen.txt count 15
assert_eq!(
counter.derive(Params::builder(
&hex!("43eef6d824fd820405626ab9b6d79f1fd04e126ab8e17729e3afc7cb5af794f8")).use_l(false).use_separator(
false).with_label(
&hex!("5e269b5a7bdedcc3e875e2725693a257fc60011af7dcd68a3358507fe29b0659ca66951daa05a15032033650bc58a27840f8fbe9f4088b9030738f68")).build()
),
Ok(Array::<u8, U32>::from(hex!("f0a339ecbcae6add1afb27da3ba40a1320c6427a58afb9dc366b219b7eb29ecf")).clone()),
);
counter.derive(
Params::builder(&hex!(
"43eef6d824fd820405626ab9b6d79f1fd04e126ab8e17729e3afc7cb5af794f8"
))
.use_l(false)
.use_separator(false)
.with_label(&hex!(
"5e269b5a7bdedcc3e875e2725693a257fc60011af7dcd68a3358507fe29b0659"
"ca66951daa05a15032033650bc58a27840f8fbe9f4088b9030738f68"
))
.build()
),
Ok(Array::<u8, U32>::from(hex!(
"f0a339ecbcae6add1afb27da3ba40a1320c6427a58afb9dc366b219b7eb29ecf"
))),
);
}

static KNOWN_VALUES_FEEDBACK_HMAC_SHA256: &[KnownValue] = &[
Expand Down Expand Up @@ -172,7 +181,7 @@ fn test_static_values_feedback() {
.with_context(v.context)
.build()
),
Ok(Array::<_, _>::try_from(v.expected).unwrap().clone()),
Ok(Array::<_, _>::try_from(v.expected).unwrap()),
"key derivation failed for (index: {i}):\n{v:x?}"
);
}
Expand Down Expand Up @@ -215,7 +224,7 @@ fn test_static_values_double_pipeline() {
.with_context(v.context)
.build(),
),
Ok(Array::<_, _>::try_from(v.expected).unwrap().clone()),
Ok(Array::<_, _>::try_from(v.expected).unwrap()),
"key derivation failed for (index: {i}):\n{v:x?}"
);
}
Expand Down
16 changes: 5 additions & 11 deletions kbkdf/tests/kbkdf/parser.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use digest::consts::*;
use hex;
use kbkdf::{Kbkdf, Params};

use core::{convert::TryInto, ops::Mul};
Expand Down Expand Up @@ -43,10 +42,8 @@ impl Prf {
}

fn is_supported(&self) -> bool {
match self {
Self::CmacTdes2 | Self::CmacTdes3 => false,
_ => true,
}
let not_supported = matches!(self, Self::CmacTdes2 | Self::CmacTdes3);
!not_supported
}
}

Expand All @@ -72,10 +69,7 @@ impl CounterLocation {
}

fn is_supported(&self) -> bool {
match self {
Self::Before | Self::AfterIter => true,
_ => false,
}
matches!(self, Self::Before | Self::AfterIter)
}
}

Expand Down Expand Up @@ -431,11 +425,11 @@ fn eval_test_vectors<T: TestData>(data: &str, use_counter: bool) -> Option<()> {
}

// Read and parse KBKDF configuration.
let prf = Prf::from_str(&l);
let prf = Prf::from_str(l);
let (counter_location, r_len) = if use_counter {
(
CounterLocation::from_str(data.next().unwrap()),
Rlen::from_str(&data.next().unwrap()),
Rlen::from_str(data.next().unwrap()),
)
} else {
// Counter location and r-len are not needed and do not present in a test file.
Expand Down