From e5b665679603db6a6d054dc394cba52adc1c6196 Mon Sep 17 00:00:00 2001 From: Tony Arcieri Date: Fri, 26 Jun 2026 08:57:06 -0600 Subject: [PATCH] deoxys: enable and fix workspace-level lints --- deoxys/Cargo.toml | 3 +++ deoxys/LICENSE-MIT | 2 +- deoxys/src/deoxys_bc.rs | 8 +++++--- deoxys/src/lib.rs | 28 +++++++++++++++++++--------- deoxys/src/modes.rs | 28 +++++++++++++++++++++++----- 5 files changed, 51 insertions(+), 18 deletions(-) diff --git a/deoxys/Cargo.toml b/deoxys/Cargo.toml index 89287dd4..9322bf85 100644 --- a/deoxys/Cargo.toml +++ b/deoxys/Cargo.toml @@ -35,6 +35,9 @@ bytes = ["aead/bytes"] getrandom = ["aead/getrandom"] rand_core = ["aead/rand_core"] +[lints] +workspace = true + [package.metadata.docs.rs] all-features = true rustdoc-args = ["--cfg", "docsrs"] diff --git a/deoxys/LICENSE-MIT b/deoxys/LICENSE-MIT index c869ada5..11d19168 100644 --- a/deoxys/LICENSE-MIT +++ b/deoxys/LICENSE-MIT @@ -1,4 +1,4 @@ -Copyright (c) 2021 The RustCrypto Project Developers +Copyright (c) 2021-2026 The RustCrypto Project Developers Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated diff --git a/deoxys/src/deoxys_bc.rs b/deoxys/src/deoxys_bc.rs index 2bb76462..0dcad299 100644 --- a/deoxys/src/deoxys_bc.rs +++ b/deoxys/src/deoxys_bc.rs @@ -36,9 +36,11 @@ const RCON: [[u8; 16]; 17] = [ ]; /// Implementation of the Deoxys-BC256 block cipher +#[derive(Clone, Copy, Debug)] pub struct DeoxysBc256; /// Implementation of the Deoxys-BC384 block cipher +#[derive(Clone, Copy, Debug)] pub struct DeoxysBc384; pub trait DeoxysBcInternal { @@ -54,7 +56,7 @@ pub trait DeoxysBcInternal { // First key for (i, (s, t)) in tweak.iter().zip(subkeys[0].iter()).enumerate() { - subtweakeys[0][i] = s ^ t + subtweakeys[0][i] = s ^ t; } // Other keys @@ -165,7 +167,7 @@ fn lfsr2(tk: &mut [u8; 16]) { data = ((data << 1) & 0xFEFEFEFEFEFEFEFEFEFEFEFEFEFEFEFE) | (((data >> 7) ^ (data >> 5)) & 0x01010101010101010101010101010101); - tk.copy_from_slice(&data.to_ne_bytes()) + tk.copy_from_slice(&data.to_ne_bytes()); } fn lfsr3(tk: &mut [u8; 16]) { @@ -173,5 +175,5 @@ fn lfsr3(tk: &mut [u8; 16]) { data = ((data >> 1) & 0x7F7F7F7F7F7F7F7F7F7F7F7F7F7F7F7F) | (((data << 7) ^ (data << 1)) & 0x80808080808080808080808080808080); - tk.copy_from_slice(&data.to_ne_bytes()) + tk.copy_from_slice(&data.to_ne_bytes()); } diff --git a/deoxys/src/lib.rs b/deoxys/src/lib.rs index 7f01484b..94f33e24 100644 --- a/deoxys/src/lib.rs +++ b/deoxys/src/lib.rs @@ -4,7 +4,6 @@ html_logo_url = "https://raw.githubusercontent.com/RustCrypto/meta/master/logo.svg", html_favicon_url = "https://raw.githubusercontent.com/RustCrypto/meta/master/logo.svg" )] -#![warn(missing_docs, rust_2018_idioms)] //! # Usage //! @@ -135,7 +134,7 @@ use aead::{ consts::U16, inout::{InOut, InOutBuf}, }; -use core::marker::PhantomData; +use core::{fmt, marker::PhantomData}; /// Deoxys-I with 128-bit keys pub type DeoxysI128 = Deoxys, deoxys_bc::DeoxysBc256>; @@ -158,9 +157,7 @@ pub type Nonce = Array; pub type Tag = Array; type Block = Array; - type Tweak = Array; - type DeoxysKey = Array; /// Deoxys encryption modes. @@ -172,8 +169,9 @@ where /// The size of the required nonce type NonceSize: ArraySize; - /// Encrypts the data in place with the specified parameters - /// Returns the tag + /// Encrypts the data in place with the specified parameters. + /// + /// Returns the tag. fn encrypt_inout( nonce: &Array, associated_data: &[u8], @@ -181,15 +179,17 @@ where subkeys: &Array, ) -> Tag; - /// Decrypts the data in place with the specified parameters - /// Returns an error if the tag verification fails + /// Decrypts the data in place with the specified parameters. + /// + /// # Errors + /// Returns an error if the tag verification fails. fn decrypt_inout( nonce: &Array, associated_data: &[u8], buffer: InOutBuf<'_, '_, u8>, tag: &Tag, subkeys: &Array, - ) -> Result<(), aead::Error>; + ) -> Result<(), Error>; } /// Deoxys-BC trait. @@ -328,6 +328,16 @@ where } } +impl fmt::Debug for Deoxys +where + M: DeoxysMode, + B: DeoxysBcType, +{ + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("Deoxys").finish_non_exhaustive() + } +} + #[cfg(feature = "zeroize")] impl zeroize::ZeroizeOnDrop for Deoxys where diff --git a/deoxys/src/modes.rs b/deoxys/src/modes.rs index dd56e030..49aa0ccd 100644 --- a/deoxys/src/modes.rs +++ b/deoxys/src/modes.rs @@ -4,7 +4,7 @@ use aead::{ consts::{U8, U15, U16}, inout::InOutBuf, }; -use core::marker::PhantomData; +use core::{fmt, marker::PhantomData}; use subtle::ConstantTimeEq; const TWEAK_AD: u8 = 0x20; @@ -349,7 +349,7 @@ where // XOR in block numbers for (t, i) in tweak[8..].iter_mut().zip(&index_array) { - *t ^= i + *t ^= i; } let mut block = Block::default(); @@ -361,7 +361,7 @@ where // XOR out block numbers for (t, i) in tweak[8..].iter_mut().zip(&index_array) { - *t ^= i + *t ^= i; } } @@ -376,14 +376,14 @@ where let blocks_len = blocks.len(); for (index, mut data) in blocks.into_iter().enumerate() { encrypt_decrypt_block::(index, tweak, subkeys, nonce, |block| { - data.xor_in2out(block) + data.xor_in2out(block); }); } let mut data = tail; let index = blocks_len; encrypt_decrypt_block::(index, tweak, subkeys, nonce, |block| { - data.xor_in2out((block[..data.len()]).into()) + data.xor_in2out((block[..data.len()]).into()); }); } } @@ -461,3 +461,21 @@ where } } } + +impl fmt::Debug for DeoxysI +where + B: DeoxysBcType, +{ + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_struct("DeoxysI").finish_non_exhaustive() + } +} + +impl fmt::Debug for DeoxysII +where + B: DeoxysBcType, +{ + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_struct("DeoxysII").finish_non_exhaustive() + } +}