1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
//! Less common block ciphers on the [`tc_block_cipher`] traits, ported from
//! Bouncy Castle, one Cargo feature each and none on by default. Each feature
//! adds a module of the same name:
//!
//! - `idea`: IDEA, with a 128-bit key and a 64-bit block.
//! - `noekeon`: Noekeon in direct-key mode, with a 128-bit key and block.
//! - `rijndael`: Rijndael with 128- to 256-bit blocks and keys.
//! - `skipjack`: SKIPJACK, with an 80-bit key and a 64-bit block.
//! - `tea`: TEA and XTEA, with a 128-bit key and a 64-bit block.
//!
//! # Timing
//!
//! Noekeon, TEA and XTEA are constant time with respect to key and block
//! contents: they use only additions, bitwise operations and fixed shifts or
//! rotations.
//! IDEA, Rijndael and SKIPJACK are variable time: IDEA's multiplication branches
//! on secret values and its decryption key setup runs a key-dependent Euclidean
//! loop, Rijndael and SKIPJACK look up tables with secret data, and Rijndael's
//! field multiplication branches on it. Use them only where timing leakage is
//! outside the threat model.
//!
//! Stored schedules are wiped on replacement and drop, but caller buffers and
//! every register or stack copy are not. No mode, padding or authentication is
//! provided.
//!
//! # Example
//!
//! XTEA, with the `tea` feature:
//!
//! ```
//! # #[cfg(feature = "tea")]
//! # {
//! use tc_block_cipher::{BlockCipher, BlockCipherInit, CipherDirection, KeyRef};
//! use tc_misc_block_cipher::tea::{BLOCK_BYTES, KEY_BYTES, XteaEngine};
//!
//! let key = [0x42; KEY_BYTES];
//! let mut engine = XteaEngine::new();
//! engine.init(CipherDirection::Encrypt, &KeyRef::new(&key)).unwrap();
//! let mut ciphertext = [0; BLOCK_BYTES];
//! assert_eq!(
//! engine.process_block(&[0x11; BLOCK_BYTES], &mut ciphertext),
//! Ok(BLOCK_BYTES)
//! );
//! # }
//! ```