test attack against random key

This commit is contained in:
2026-04-28 10:03:49 +02:00
parent 179036642e
commit 82b50463d1
3 changed files with 376 additions and 4 deletions
+8 -4
View File
@@ -2,6 +2,7 @@
// Implementation of the Midnight Blue Labs TEA1 attack (CVE-2022-24402)
use crate::tea1::*;
use rayon::prelude::*;
use rand::Rng;
/// Returns true if the candidate key_reg produces the exact known keystream prefix
/// Early aborts on the first mismatch
@@ -60,9 +61,12 @@ pub fn recover_tea1_keyreg(frame_number: u32, known_keystream: &[u8]) -> Option<
}
pub fn tea1_attack_example() {
let key0 = [0x00u8; 10];
let reduced0 = init_key_register(&key0); // 0xc24e273b
assert_eq!(reduced0, 0xc24e273b);
let mut rng = rand::rng();
let mut key0 = [0u8; 10];
rng.fill_bytes(&mut key0);
let reduced0 = init_key_register(&key0);
let frame0 = 0x1111_1111u32;
let ks0 = tea1_keystream(frame0, &key0, 4);
@@ -71,5 +75,5 @@ pub fn tea1_attack_example() {
assert_eq!(recovered0, Some(reduced0));
println!("Recovered key successfully (0x{:08x})", recovered0.unwrap());
println!("original key (0x{:08x})", reduced0);
println!("original key register (0x{:08x})", reduced0);
}