cargo clippy + inline
This commit is contained in:
@@ -27,6 +27,7 @@ pub const TEA1_SBOX: [u8; 256] = [
|
|||||||
0x99, 0x43, 0x13, 0x0B, 0xE0, 0xA5, 0x12, 0x77, 0x5D, 0xB3, 0x38, 0xD9, 0xEF, 0x5A, 0x01, 0x70,
|
0x99, 0x43, 0x13, 0x0B, 0xE0, 0xA5, 0x12, 0x77, 0x5D, 0xB3, 0x38, 0xD9, 0xEF, 0x5A, 0x01, 0x70,
|
||||||
];
|
];
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn expand_iv(short_iv: u32) -> u64 {
|
pub fn expand_iv(short_iv: u32) -> u64 {
|
||||||
let xorred = short_iv ^ 0x9672_4FA1;
|
let xorred = short_iv ^ 0x9672_4FA1;
|
||||||
let xorred = xorred.rotate_left(8);
|
let xorred = xorred.rotate_left(8);
|
||||||
@@ -34,6 +35,7 @@ pub fn expand_iv(short_iv: u32) -> u64 {
|
|||||||
iv.rotate_right(8)
|
iv.rotate_right(8)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn state_word_to_newbyte(wst: u16, lut: &[u16; 8]) -> u8 {
|
pub fn state_word_to_newbyte(wst: u16, lut: &[u16; 8]) -> u8 {
|
||||||
let mut st0 = (wst & 0x00FF) as u8;
|
let mut st0 = (wst & 0x00FF) as u8;
|
||||||
let mut st1 = (wst >> 8) as u8;
|
let mut st1 = (wst >> 8) as u8;
|
||||||
@@ -53,6 +55,7 @@ pub fn state_word_to_newbyte(wst: u16, lut: &[u16; 8]) -> u8 {
|
|||||||
out
|
out
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn reorder_state_byte(b: u8) -> u8 {
|
pub fn reorder_state_byte(b: u8) -> u8 {
|
||||||
let mut out = 0u8;
|
let mut out = 0u8;
|
||||||
out |= (b.wrapping_shl(6)) & 0x40;
|
out |= (b.wrapping_shl(6)) & 0x40;
|
||||||
@@ -65,6 +68,7 @@ pub fn reorder_state_byte(b: u8) -> u8 {
|
|||||||
out
|
out
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn init_key_register(key: &[u8; 10]) -> u32 {
|
pub fn init_key_register(key: &[u8; 10]) -> u32 {
|
||||||
let mut reg: u32 = 0;
|
let mut reg: u32 = 0;
|
||||||
|
|
||||||
@@ -82,6 +86,7 @@ pub fn tea1_keystream(frame_number: u32, key: &[u8; 10], num_bytes: usize) -> Ve
|
|||||||
out
|
out
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn tea1_into(frame_number: u32, key: &[u8; 10], out: &mut [u8]) {
|
pub fn tea1_into(frame_number: u32, key: &[u8; 10], out: &mut [u8]) {
|
||||||
let mut iv_reg = expand_iv(frame_number);
|
let mut iv_reg = expand_iv(frame_number);
|
||||||
let mut key_reg = init_key_register(key);
|
let mut key_reg = init_key_register(key);
|
||||||
|
|||||||
+2
-4
@@ -1,12 +1,12 @@
|
|||||||
// tea1_attack.rs
|
// tea1_attack.rs
|
||||||
// Implementation of the Midnight Blue Labs TEA1 attack (CVE-2022-24402)
|
// Implementation of the Midnight Blue Labs TEA1 attack (CVE-2022-24402)
|
||||||
use crate::tea1::*;
|
use crate::tea1::*;
|
||||||
use rayon::prelude::*;
|
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
|
use rayon::prelude::*;
|
||||||
|
|
||||||
/// Returns true if the candidate key_reg produces the exact known keystream prefix
|
/// Returns true if the candidate key_reg produces the exact known keystream prefix
|
||||||
/// Early aborts on the first mismatch
|
/// Early aborts on the first mismatch
|
||||||
#[inline]
|
#[inline(always)]
|
||||||
pub fn keyreg_matches_prefix(frame_number: u32, mut key_reg: u32, known_prefix: &[u8]) -> bool {
|
pub fn keyreg_matches_prefix(frame_number: u32, mut key_reg: u32, known_prefix: &[u8]) -> bool {
|
||||||
if known_prefix.is_empty() {
|
if known_prefix.is_empty() {
|
||||||
return true;
|
return true;
|
||||||
@@ -54,8 +54,6 @@ pub fn recover_tea1_keyreg(frame_number: u32, known_keystream: &[u8]) -> Option<
|
|||||||
let known_prefix = &known_keystream[0..check_len];
|
let known_prefix = &known_keystream[0..check_len];
|
||||||
|
|
||||||
(0u32..=u32::MAX).into_par_iter().find_any({
|
(0u32..=u32::MAX).into_par_iter().find_any({
|
||||||
let frame_number = frame_number;
|
|
||||||
|
|
||||||
move |&candidate| keyreg_matches_prefix(frame_number, candidate, known_prefix)
|
move |&candidate| keyreg_matches_prefix(frame_number, candidate, known_prefix)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user