Expand description
This crate contains generic implementation of block cipher modes of operation defined in GOST R 34.13-2015.
CTR, CFB and OFB modes are implemented in terms of traits from the cipher crate.
MAC function defined in the GOST is implemented in the cmac crate.
§Examples
use gost_modes::{GostCbc, GostPadding, BlockMode, consts::U2};
use kuznyechik::Kuznyechik;
use hex_literal::hex;
let key = hex!("
8899aabbccddeeff0011223344556677
fedcba98765432100123456789abcdef
");
let iv = hex!("
1234567890abcef0a1b2c3d4e5f00112
23344556677889901213141516171819
");
let pt = b"my secret message";
type Cipher = GostCbc<Kuznyechik, GostPadding, U2>;
let cipher = Cipher::new_from_slices(&key, &iv).unwrap();
let ct = cipher.encrypt_vec(pt);
let cipher = Cipher::new_from_slices(&key, &iv).unwrap();
let buf = cipher.decrypt_vec(&ct).unwrap();
assert_eq!(buf, &pt[..]);
// OFB mode example
use gost_modes::{GostOfb, StreamCipher, NewCipher};
let mut cipher = GostOfb::<Kuznyechik, U2>::new_from_slices(&key, &iv).unwrap();
let mut buf = pt.to_vec();
cipher.apply_keystream(&mut buf);
assert_eq!(buf, hex!("fddb196e81812e4174d1c9f741a3457a88"));Re-exports§
pub use block_modes;pub use block_modes::block_padding;pub use cipher;pub use generic_array;
Modules§
Structs§
- Ecb
- Electronic Codebook (ECB) block cipher mode instance.
- GostCbc
- Cipher Block Chaining (CBC) mode of operation as defined in GOST R 34.13-2015
- GostCfb
- Cipher feedback (CFB) mode of operation as defined in GOST R 34.13-2015
- Gost
Ctr64 - Counter (CTR) mode of operation for 64-bit block ciphers as defined in GOST R 34.13-2015
- Gost
Ctr128 - Counter (CTR) mode of operation for 128-bit block ciphers as defined in GOST R 34.13-2015
- GostOfb
- Output feedback (OFB) mode of operation as defined in GOST R 34.13-2015
Traits§
- Async
Stream Cipher - Asynchronous stream cipher core trait.
- Block
Mode - Trait for a block cipher mode of operation that is used to apply a block cipher operation to input data to transform it into a variable-length output message.
- NewCipher
- Cipher creation trait.
- Stream
Cipher - Synchronous stream cipher core trait.
- Stream
Cipher Seek - Trait for seekable stream ciphers.
Type Aliases§
- Gost
Padding - Block padding procedure number 2 as defined in GOST R 34.13-2015