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
impl SeedEngine
Trait Implementations§
Source§impl BlockCipher for SeedEngine
impl BlockCipher for SeedEngine
Source§fn block_size(&self) -> usize
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>
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
type Error = BlockError
crate::BlockError.Source§impl<P: KeyParams + ?Sized> BlockCipherInit<P> for SeedEngine
impl<P: KeyParams + ?Sized> BlockCipherInit<P> for SeedEngine
Source§fn init(
&mut self,
direction: CipherDirection,
params: &P,
) -> Result<(), InitError>
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
type Error = InitError
crate::InitError.