Skip to main content

Crate gost_crypto

Crate gost_crypto 

Source
Expand description

Pure-Rust GOST cryptography, compatible with the RustCrypto ecosystem.

§Algorithms

AlgorithmTypeFeature
GOST 28147-89Block cipher (64-bit block, 256-bit key)always
GOST R 34.11-94Hash (256-bit, CryptoPro / Test param sets)always
CMAC / OMACMAC over GOST 28147-89mac
GOST R 34.11-2012 (Streebog)Hash 256 / 512-bitstreebog

§Block cipher modes

Gost28147 implements [cipher::BlockCipherEncrypt] + [cipher::BlockCipherDecrypt]

# Cargo.toml
[dependencies]
gost-crypto = "0.2"
cbc         = "0.1"
cfb-mode    = "0.8"
ofb         = "0.6"
use gost_crypto::Gost28147;
use cbc::Encryptor;
use cipher::{KeyIvInit, BlockEncryptMut, block_padding::Pkcs7};

let enc = Encryptor::<Gost28147>::new(&key.into(), &iv.into());
let ct = enc.encrypt_padded_vec_mut::<Pkcs7>(plaintext);

§CMAC (feature mac)

gost-crypto = { version = "0.2", features = ["mac"] }
use gost_crypto::mac::Gost28147Mac;
use digest::Mac;
let mut mac = Gost28147Mac::new(&key.into());
mac.update(b"message");
let tag = mac.finalize().into_bytes();

§Streebog (feature streebog)

gost-crypto = { version = "0.2", features = ["streebog"] }
use gost_crypto::streebog::{Streebog256, Streebog512};
use digest::Digest;
let hash = Streebog256::digest(b"hello");

§Example

use gost_crypto::{Gost341194, SBOX_CRYPTOPRO};
use digest::Update;

let mut h = Gost341194::new_with_sbox(&SBOX_CRYPTOPRO);
Update::update(&mut h, b"hello");
let result = h.finalize_bytes();
assert_eq!(result.len(), 32);

Structs§

Gost28147
GOST 28147-89 block cipher.
Gost341194
GOST R 34.11-94 hash function.

Constants§

SBOX_CRYPTOPRO
S-box for id-GostR3411-94-CryptoProParamSet (RFC 4357 §11.2). Used by КриптоПро CSP for GOST R 34.11-94 hashing.
SBOX_TEST
S-box for id-GostR3411-94-TestParamSet (RFC 5831 test vectors).

Type Aliases§

Sbox
S-box type: 8 rows × 16 columns.