aboutsummaryrefslogtreecommitdiff
path: root/src/lib.rs
diff options
context:
space:
mode:
authorDaniel Schadt <kingdread@gmx.de>2025-06-22 11:09:56 +0200
committerDaniel Schadt <kingdread@gmx.de>2025-06-22 11:09:56 +0200
commit6fd36ebffafc5ab749003a645ba254007f6deec2 (patch)
tree570a12ef7c592e7dde75e90f73e5c58cd43844dd /src/lib.rs
parent942f522a68adfb9c436a05e736bdaf07c8aa7db8 (diff)
downloadzears-6fd36ebffafc5ab749003a645ba254007f6deec2.tar.gz
zears-6fd36ebffafc5ab749003a645ba254007f6deec2.tar.bz2
zears-6fd36ebffafc5ab749003a645ba254007f6deec2.zip
fix some lintsHEADmaster
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs88
1 files changed, 57 insertions, 31 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 6407cb5..5759046 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -147,6 +147,7 @@ impl Aez {
let key = extract(key);
let (key_i, key_j, key_l) = split_key(&key);
let aes = aesround::AesImpl::new(key_i, key_j, key_l);
+ #[allow(clippy::erasing_op)]
let key_l_multiples = [
key_l * 0,
key_l * 1,
@@ -214,7 +215,7 @@ impl Aez {
data: &mut Vec<u8>,
) {
data.resize(data.len() + tau as usize, 0);
- encrypt(&self, nonce, associated_data, tau, data);
+ encrypt(self, nonce, associated_data, tau, data);
}
/// Encrypts the data inplace.
@@ -233,7 +234,7 @@ impl Aez {
assert!(buffer.len() >= tau as usize);
let data_len = buffer.len() - tau as usize;
append_auth(data_len, buffer);
- encrypt(&self, nonce, associated_data, tau as u32, buffer);
+ encrypt(self, nonce, associated_data, tau, buffer);
}
/// Encrypts the data in the given buffer, writing the output to the given output buffer.
@@ -253,7 +254,7 @@ impl Aez {
let tau = output.len() - input.len();
output[..input.len()].copy_from_slice(input);
append_auth(input.len(), output);
- encrypt(&self, nonce, associated_data, tau as u32, output);
+ encrypt(self, nonce, associated_data, tau as u32, output);
}
/// Decrypts the given ciphertext.
@@ -276,7 +277,7 @@ impl Aez {
data: &[u8],
) -> Option<Vec<u8>> {
let mut buffer = Vec::from(data);
- let len = match decrypt(&self, nonce, associated_data, tau, &mut buffer) {
+ let len = match decrypt(self, nonce, associated_data, tau, &mut buffer) {
None => return None,
Some(m) => m.len(),
};
@@ -296,7 +297,7 @@ impl Aez {
tau: u32,
data: &'a mut [u8],
) -> Option<&'a [u8]> {
- decrypt(&self, nonce, associated_data, tau, data)
+ decrypt(self, nonce, associated_data, tau, data)
}
}
@@ -342,9 +343,9 @@ fn encrypt(aez: &Aez, nonce: &[u8], ad: &[&[u8]], tau: u32, buffer: &mut [u8]) {
if buffer.len() == tau as usize {
// As aez_prf only xor's the input in, we have to clear the buffer first
buffer.fill(0);
- aez_prf(aez, &tweaks, buffer);
+ aez_prf(aez, tweaks, buffer);
} else {
- encipher(aez, &tweaks, buffer);
+ encipher(aez, tweaks, buffer);
}
}
@@ -373,19 +374,19 @@ fn decrypt<'a>(
};
if ciphertext.len() == tau as usize {
- aez_prf(aez, &tweaks, ciphertext);
- if is_zeroes(&ciphertext) {
+ aez_prf(aez, tweaks, ciphertext);
+ if is_zeroes(ciphertext) {
return Some(&[]);
} else {
return None;
}
}
- decipher(aez, &tweaks, ciphertext);
+ decipher(aez, tweaks, ciphertext);
let (m, auth) = ciphertext.split_at(ciphertext.len() - tau as usize);
assert!(auth.len() == tau as usize);
- if is_zeroes(&auth) { Some(m) } else { None }
+ if is_zeroes(auth) { Some(m) } else { None }
}
fn is_zeroes(data: &[u8]) -> bool {
@@ -474,7 +475,7 @@ fn cipher_aez_tiny(mode: Mode, aez: &Aez, tweaks: Tweak, message: &mut [u8]) {
}
if mode == Mode::Encipher && mu < 128 {
- let mut c = Block::from_slice(&message);
+ let mut c = Block::from_slice(message);
c = c ^ (e(0, 3, aez, delta ^ (c | Block::one())) & Block::one());
message.copy_from_slice(&c.bytes()[..mu / 8]);
}
@@ -543,11 +544,11 @@ fn cipher_aez_core(mode: Mode, aez: &Aez, tweaks: Tweak, message: &mut [u8]) {
match d {
0 => (),
_ if d <= 127 => {
- x = x ^ e(0, 4, aez, m_u.pad(d.into()));
+ x = x ^ e(0, 4, aez, m_u.pad(d));
}
_ => {
x = x ^ e(0, 4, aez, m_u);
- x = x ^ e(0, 5, aez, m_v.pad(len_v.into()));
+ x = x ^ e(0, 5, aez, m_v.pad(len_v));
}
}
@@ -572,14 +573,14 @@ fn cipher_aez_core(mode: Mode, aez: &Aez, tweaks: Tweak, message: &mut [u8]) {
match d {
0 => (),
_ if d <= 127 => {
- c_u = (m_u ^ e(-1, 4, aez, s)).clip(d.into());
- y = y ^ e(0, 4, aez, c_u.pad(d.into()));
+ c_u = (m_u ^ e(-1, 4, aez, s)).clip(d);
+ y = y ^ e(0, 4, aez, c_u.pad(d));
}
_ => {
c_u = m_u ^ e(-1, 4, aez, s);
- c_v = (m_v ^ e(-1, 5, aez, s)).clip(len_v.into());
+ c_v = (m_v ^ e(-1, 5, aez, s)).clip(len_v);
y = y ^ e(0, 4, aez, c_u);
- y = y ^ e(0, 5, aez, c_v.pad(len_v.into()));
+ y = y ^ e(0, 5, aez, c_v.pad(len_v));
}
}
@@ -601,13 +602,14 @@ fn cipher_aez_core(mode: Mode, aez: &Aez, tweaks: Tweak, message: &mut [u8]) {
blocks.set_m_y(c_y);
}
-fn pad_to_blocks(value: &[u8]) -> impl Iterator<Item=Block> {
- value.chunks(16)
- .map(|chunk| if chunk.len() == 16 {
+fn pad_to_blocks(value: &[u8]) -> impl Iterator<Item = Block> {
+ value.chunks(16).map(|chunk| {
+ if chunk.len() == 16 {
Block::from_slice(chunk)
} else {
Block::from_slice(chunk).pad(chunk.len() * 8)
- })
+ }
+ })
}
fn aez_hash(aez: &Aez, tweaks: Tweak) -> Block {
@@ -690,7 +692,7 @@ impl<'a> E<'a> {
self.aez.aes.aes4(block ^ delta)
}
- fn evals_for(self, block: Block) -> impl Iterator<Item=Block> {
+ fn evals_for(self, block: Block) -> impl Iterator<Item = Block> {
Eiter::new(self, block)
}
@@ -730,14 +732,38 @@ impl<'a> Eiter<'a> {
self.e.ki_p_i = self.e.ki_p_i * 2;
let pre_xored = self.value ^ self.e.kj_t_j ^ self.e.ki_p_i;
self.blocks = [
- self.e.aez.aes.aes4(pre_xored ^ self.e.aez.key_l_multiples[1]),
- self.e.aez.aes.aes4(pre_xored ^ self.e.aez.key_l_multiples[2]),
- self.e.aez.aes.aes4(pre_xored ^ self.e.aez.key_l_multiples[3]),
- self.e.aez.aes.aes4(pre_xored ^ self.e.aez.key_l_multiples[4]),
- self.e.aez.aes.aes4(pre_xored ^ self.e.aez.key_l_multiples[5]),
- self.e.aez.aes.aes4(pre_xored ^ self.e.aez.key_l_multiples[6]),
- self.e.aez.aes.aes4(pre_xored ^ self.e.aez.key_l_multiples[7]),
- self.e.aez.aes.aes4(pre_xored ^ self.e.aez.key_l_multiples[0]),
+ self.e
+ .aez
+ .aes
+ .aes4(pre_xored ^ self.e.aez.key_l_multiples[1]),
+ self.e
+ .aez
+ .aes
+ .aes4(pre_xored ^ self.e.aez.key_l_multiples[2]),
+ self.e
+ .aez
+ .aes
+ .aes4(pre_xored ^ self.e.aez.key_l_multiples[3]),
+ self.e
+ .aez
+ .aes
+ .aes4(pre_xored ^ self.e.aez.key_l_multiples[4]),
+ self.e
+ .aez
+ .aes
+ .aes4(pre_xored ^ self.e.aez.key_l_multiples[5]),
+ self.e
+ .aez
+ .aes
+ .aes4(pre_xored ^ self.e.aez.key_l_multiples[6]),
+ self.e
+ .aez
+ .aes
+ .aes4(pre_xored ^ self.e.aez.key_l_multiples[7]),
+ self.e
+ .aez
+ .aes
+ .aes4(pre_xored ^ self.e.aez.key_l_multiples[0]),
];
self.len = 8;
}