silk.crypto.camellia.
Encrypt with the Camellia block cipher (RFC 3713, ISO/IEC 18033-3).
When to use#
Use Camellia when a format names Camellia, such as camellia-256-cbc in OpenSSL or Node.js.
Run it in a mode from silk.crypto.block_cipher, such as Cbc<Camellia>.
Details#
The key is 16, 24, or 32 bytes and the block is 16 bytes: 18 rounds for a 16-byte key and 24
for the others. Camellia conforms to BlockCipher. Nothing allocates.
Gotchas#
The S-boxes are table lookups, so the time of a block can depend on the key and the data through the cache, as in OpenSSL's portable code. The value holds key material and is not erased when it is dropped.
Examples#
Encrypt one block#
import silk.crypto.block_cipher { BlockCipher, BlockCipherError }
import silk.crypto.camellia { Camellia }
import silk.core.result { Result }
pub fn main() -> i32 {
// RFC 3713 appendix A, 128-bit key: the key is also the plaintext.
let key: [u8; 16] = [0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10]
let cipher = match Camellia.make(&key) {
Result<Camellia, BlockCipherError>.Success { value } => move value
Result<Camellia, BlockCipherError>.Failure { error: _ } => {
return 1
}
}
let mut block = key
cipher.encryptBlock(&mut block)
if block[0] != 0x67 || block[1] != 0x67 || block[15] != 0x43 {
return 1
}
cipher.decryptBlock(&mut block)
if block[0] != 0x01 || block[15] != 0x10 {
return 1
}
return 0
}Import as Camellia with import silk.crypto.camellia { Camellia }.
Public declarations: 1.
Camellia#
pub struct CamelliaA Camellia key schedule.
Details#
Make one with Camellia.make and run it in a mode from silk.crypto.block_cipher, or call
encryptBlock and decryptBlock of BlockCipher on one 16-byte block.
Implementation Camellia#
impl CamelliaAssociated function make#
pub fn make(key: &[u8]) -> Result<Camellia, BlockCipherError>Returns the key schedule of key, which is 16, 24, or 32 bytes.
Errors#
InvalidKeyLengthifkeyis not 16, 24, or 32 bytes.
Implementation BlockCipher for Camellia#
impl BlockCipher for CamelliaOperation blockLength#
fn blockLength(self: &Self) -> usizeReturns 16.
Operation encryptBlock#
fn encryptBlock(self: &Self, block: &mut [u8; 16]) -> ()Encrypts the 16 bytes of block in place.
Operation decryptBlock#
fn decryptBlock(self: &Self, block: &mut [u8; 16]) -> ()Decrypts the 16 bytes of block in place.
Category: Cryptography.
Profiles: aarch64-apple-darwin, aarch64-unknown-linux-gnu, aarch64-unknown-linux-gnu-no-libc, x86_64-unknown-linux-gnu, x86_64-unknown-linux-gnu-no-libc, wasm32-unknown-unknown, wasm32-wasip1, wasm32-wasip2, x86_64-pc-windows-msvc, wasm64-unknown-unknown.