Skip to main content

SeedEngine

Struct SeedEngine 

Source
pub struct SeedEngine { /* private fields */ }
Expand description

SEED with a 16-byte key and a 16-byte block.

Variable time: key setup and block processing use secret-dependent SS0-SS3 S-box lookups. Use only where cache-timing leakage is outside the threat model; this crate provides no constant-time alternative.

The stored working key is wiped on replacement and drop. This does not wipe caller buffers or guarantee erasure of every temporary copy in registers or on the stack.

§Example

Import both traits and reinitialize the engine to change direction.

use tc_block_cipher::{BlockCipher, BlockCipherInit, CipherDirection, KeyRef};
use tc_seed::{BLOCK_BYTES, KEY_BYTES, SeedEngine};

let key = [0x42; KEY_BYTES];
let plaintext = [0x11; BLOCK_BYTES];
let mut engine = SeedEngine::new();
engine.init(CipherDirection::Encrypt, &KeyRef::new(&key))?;
let mut encrypted = [0; BLOCK_BYTES];
engine.process_block(&plaintext, &mut encrypted)?;
engine.init(CipherDirection::Decrypt, &KeyRef::new(&key))?;
let mut recovered = [0; BLOCK_BYTES];
engine.process_block(&encrypted, &mut recovered)?;
assert_eq!(recovered, plaintext);

Implementations§

Source§

impl SeedEngine

Source

pub const fn new() -> Self

Creates an uninitialised engine. Constant time: no key is inspected.

Trait Implementations§

Source§

impl BlockCipher for SeedEngine

Source§

fn block_size(&self) -> usize

Returns the 16-byte block size. Constant time.

Source§

fn process_block( &mut self, input: &[u8], output: &mut [u8], ) -> Result<usize, BlockError>

Transforms the first block and returns 16, leaving any output tail untouched.

Returns NotInitialised before successful initialization, or BufferTooShort when either buffer is shorter than 16 bytes. Both errors leave output untouched. Variable time: secret-dependent S-box lookups can leak key information.

Source§

type Error = BlockError

The engine’s processing error, such as crate::BlockError.
Source§

impl<P: KeyParams + ?Sized> BlockCipherInit<P> for SeedEngine

Source§

fn init( &mut self, direction: CipherDirection, params: &P, ) -> Result<(), InitError>

Installs a 16-byte key for the selected direction, without borrowing it.

An invalid length leaves the previous key, direction and initialization state unchanged. Variable time: key expansion uses secret-dependent S-box lookups.

Source§

type Error = InitError

The engine’s initialization error, such as crate::InitError.
Source§

impl Default for SeedEngine

Source§

fn default() -> Self

Creates an uninitialised engine. Constant time: no key is inspected.

Source§

impl Display for SeedEngine

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Writes the algorithm name without inspecting key material. Constant time with respect to the key; output timing depends on the formatter.

Source§

impl Drop for SeedEngine

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.