Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions deoxys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
2 changes: 1 addition & 1 deletion deoxys/LICENSE-MIT
Original file line number Diff line number Diff line change
@@ -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
Expand Down
8 changes: 5 additions & 3 deletions deoxys/src/deoxys_bc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down Expand Up @@ -165,13 +167,13 @@ 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]) {
let mut data = u128::from_ne_bytes(*tk);
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());
}
28 changes: 19 additions & 9 deletions deoxys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
//!
Expand Down Expand Up @@ -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<modes::DeoxysI<deoxys_bc::DeoxysBc256>, deoxys_bc::DeoxysBc256>;
Expand All @@ -158,9 +157,7 @@ pub type Nonce<NonceSize> = Array<u8, NonceSize>;
pub type Tag = Array<u8, U16>;

type Block = Array<u8, U16>;

type Tweak = Array<u8, U16>;

type DeoxysKey = Array<u8, U16>;

/// Deoxys encryption modes.
Expand All @@ -172,24 +169,27 @@ 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<u8, Self::NonceSize>,
associated_data: &[u8],
buffer: InOutBuf<'_, '_, u8>,
subkeys: &Array<DeoxysKey, B::SubkeysSize>,
) -> 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<u8, Self::NonceSize>,
associated_data: &[u8],
buffer: InOutBuf<'_, '_, u8>,
tag: &Tag,
subkeys: &Array<DeoxysKey, B::SubkeysSize>,
) -> Result<(), aead::Error>;
) -> Result<(), Error>;
}

/// Deoxys-BC trait.
Expand Down Expand Up @@ -328,6 +328,16 @@ where
}
}

impl<M, B> fmt::Debug for Deoxys<M, B>
where
M: DeoxysMode<B>,
B: DeoxysBcType,
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Deoxys").finish_non_exhaustive()
}
}

#[cfg(feature = "zeroize")]
impl<M, B> zeroize::ZeroizeOnDrop for Deoxys<M, B>
where
Expand Down
28 changes: 23 additions & 5 deletions deoxys/src/modes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -361,7 +361,7 @@ where

// XOR out block numbers
for (t, i) in tweak[8..].iter_mut().zip(&index_array) {
*t ^= i
*t ^= i;
}
}

Expand All @@ -376,14 +376,14 @@ where
let blocks_len = blocks.len();
for (index, mut data) in blocks.into_iter().enumerate() {
encrypt_decrypt_block::<B, _>(index, tweak, subkeys, nonce, |block| {
data.xor_in2out(block)
data.xor_in2out(block);
});
}
let mut data = tail;
let index = blocks_len;

encrypt_decrypt_block::<B, _>(index, tweak, subkeys, nonce, |block| {
data.xor_in2out((block[..data.len()]).into())
data.xor_in2out((block[..data.len()]).into());
});
}
}
Expand Down Expand Up @@ -461,3 +461,21 @@ where
}
}
}

impl<B> fmt::Debug for DeoxysI<B>
where
B: DeoxysBcType,
{
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("DeoxysI").finish_non_exhaustive()
}
}

impl<B> fmt::Debug for DeoxysII<B>
where
B: DeoxysBcType,
{
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("DeoxysII").finish_non_exhaustive()
}
}