Skip to content

Commit 5dde619

Browse files
committed
Deleted KeyMaterial::concatenate
1 parent 16432f2 commit 5dde619

2 files changed

Lines changed: 0 additions & 104 deletions

File tree

crypto/core/src/key_material.rs

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -202,18 +202,6 @@ pub trait KeyMaterialTrait: KeyMaterialInternalTrait {
202202
/// hold a different key, potentially of a different length.
203203
fn zeroize(&mut self);
204204

205-
/// Adds the other KeyMaterial into this one, assuming there is space.
206-
///
207-
/// Throws [KeyMaterialError::InvalidLength] if this object does not have enough space to add the other one.
208-
///
209-
/// The resulting [KeyType] and security strength will be the lesser of the two keys.
210-
/// In other words, concatenating two 128-bit full entropy keys generated at a 128-bit DRBG security level
211-
/// will result in a 256-bit full entropy key still at the 128-bit DRBG security level.
212-
/// Concatenating a full entropy key with a low entropy key will result in a low entropy key.
213-
///
214-
/// Returns the new key_len.
215-
fn concatenate(&mut self, other: &dyn KeyMaterialTrait) -> Result<usize, KeyMaterialError>;
216-
217205
/// Perform a constant-time comparison between the two key material buffers,
218206
/// ignoring differences in capacity, [KeyType], [SecurityStrength], etc.
219207
fn equals(&self, other: &dyn KeyMaterialTrait) -> bool;
@@ -546,18 +534,6 @@ impl<const KEY_LEN: usize> KeyMaterialTrait for KeyMaterial<KEY_LEN> {
546534
self.key_type = KeyType::Zeroized;
547535
}
548536

549-
fn concatenate(&mut self, other: &dyn KeyMaterialTrait) -> Result<usize, KeyMaterialError> {
550-
let new_key_len = self.key_len() + other.key_len();
551-
if self.key_len() + other.key_len() > KEY_LEN {
552-
return Err(KeyMaterialError::InputDataLongerThanKeyCapacity);
553-
}
554-
self.buf[self.key_len..new_key_len].copy_from_slice(other.ref_to_bytes());
555-
self.key_len += other.key_len();
556-
self.key_type = min(&self.key_type, &other.key_type()).clone();
557-
self.security_strength = min(&self.security_strength, &other.security_strength()).clone();
558-
Ok(self.key_len())
559-
}
560-
561537
fn equals(&self, other: &dyn KeyMaterialTrait) -> bool {
562538
if self.key_len() != other.key_len() {
563539
return false;

crypto/core/tests/key_material_tests.rs

Lines changed: 0 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -655,86 +655,6 @@ mod test_key_material {
655655
.unwrap();
656656
}
657657

658-
#[test]
659-
fn test_concatenate() {
660-
// intentionally half-full
661-
let mut key1 = KeyMaterial256::from_bytes(&[1u8; 16]).unwrap();
662-
let key2 = KeyMaterial256::from_bytes(&[2u8; 16]).unwrap();
663-
assert_eq!(key1.key_len(), 16);
664-
assert_eq!(key2.key_len(), 16);
665-
666-
key1.concatenate(&key2).unwrap();
667-
assert_eq!(key1.key_len(), 32);
668-
assert_eq!(key1.ref_to_bytes()[..16], [1u8; 16]);
669-
assert_eq!(key1.ref_to_bytes()[16..], [2u8; 16]);
670-
671-
let mut zeroized_key = KeyMaterial256::default();
672-
do_hazardous_operations(&mut zeroized_key, |zeroized_key| {
673-
zeroized_key.set_key_len(8).unwrap();
674-
Ok(())
675-
})
676-
.unwrap();
677-
assert_eq!(zeroized_key.key_type(), KeyType::Zeroized);
678-
assert_eq!(zeroized_key.key_len(), 8);
679-
zeroized_key.concatenate(&key2).unwrap();
680-
assert_eq!(zeroized_key.key_len(), 24);
681-
// The result takes the lesser (min) of the two key types: min(Zeroized, BytesLowEntropy).
682-
// Folding in zeroized (uninitialized) bytes taints the whole buffer as Zeroized.
683-
assert_eq!(zeroized_key.key_type(), KeyType::Zeroized);
684-
assert_eq!(zeroized_key.security_strength(), SecurityStrength::None);
685-
686-
// This should be symmetric, so test it in the other direction too.
687-
let mut zeroized_key = KeyMaterial256::default();
688-
do_hazardous_operations(&mut zeroized_key, |zeroized_key| {
689-
zeroized_key.set_key_len(8).unwrap();
690-
Ok(())
691-
})
692-
.unwrap();
693-
assert_eq!(zeroized_key.key_type(), KeyType::Zeroized);
694-
assert_eq!(zeroized_key.key_len(), 8);
695-
let mut key2 = KeyMaterial256::from_bytes(&[1u8; 16]).unwrap();
696-
key2.concatenate(&zeroized_key).unwrap();
697-
assert_eq!(key2.key_len(), 24);
698-
// The result takes the lesser (min) of the two key types: min(BytesLowEntropy, Zeroized).
699-
assert_eq!(key2.key_type(), KeyType::Zeroized);
700-
assert_eq!(key2.security_strength(), SecurityStrength::None);
701-
702-
// now try it with keys of different key types
703-
let mut low_entropy_key =
704-
KeyMaterial256::from_bytes_as_type(&[1u8; 16], KeyType::Unknown).unwrap();
705-
let full_entropy_key =
706-
KeyMaterial256::from_bytes_as_type(&[2u8; 16], KeyType::CryptographicRandom).unwrap();
707-
low_entropy_key.concatenate(&full_entropy_key).unwrap();
708-
// Conservative model: concatenating a full-entropy key with a low-entropy key yields a
709-
// low-entropy key. min(BytesLowEntropy, BytesFullEntropy) == BytesLowEntropy.
710-
assert_eq!(low_entropy_key.key_type(), KeyType::Unknown);
711-
// min(None, _128bit) == None (and BytesLowEntropy keys must have strength None anyway).
712-
assert_eq!(low_entropy_key.security_strength(), SecurityStrength::None);
713-
714-
// and in the other direction too
715-
let low_entropy_key =
716-
KeyMaterial256::from_bytes_as_type(&[1u8; 16], KeyType::Unknown).unwrap();
717-
let mut full_entropy_key =
718-
KeyMaterial256::from_bytes_as_type(&[2u8; 16], KeyType::CryptographicRandom).unwrap();
719-
full_entropy_key.concatenate(&low_entropy_key).unwrap();
720-
// min(BytesFullEntropy, BytesLowEntropy) == BytesLowEntropy.
721-
assert_eq!(full_entropy_key.key_type(), KeyType::Unknown);
722-
// min(_128bit, None) == None.
723-
assert_eq!(full_entropy_key.security_strength(), SecurityStrength::None);
724-
725-
// now with full entropy keys at different security levels
726-
let mut full_entropy_key_112 =
727-
KeyMaterial512::from_bytes_as_type(&[1u8; 16], KeyType::CryptographicRandom).unwrap();
728-
// Now we're gonna explictly tag it at the 112bit security level -- does not require allow_hazardous_operations().
729-
full_entropy_key_112.set_security_strength(SecurityStrength::_112bit).unwrap();
730-
let full_entropy_key =
731-
KeyMaterial256::from_bytes_as_type(&[2u8; 32], KeyType::CryptographicRandom).unwrap();
732-
full_entropy_key_112.concatenate(&full_entropy_key).unwrap();
733-
assert_eq!(full_entropy_key_112.key_type(), KeyType::CryptographicRandom);
734-
// The combined key keeps the lower of the two security strengths: min(_112bit, _256bit).
735-
assert_eq!(full_entropy_key_112.security_strength(), SecurityStrength::_112bit);
736-
}
737-
738658
#[test]
739659
fn eq() {
740660
// For context:

0 commit comments

Comments
 (0)