gost-crypto 0.2.1

GOST 28147-89 block cipher and GOST R 34.11-94 hash — no_std, RustCrypto compatible
Documentation

gost-crypto

Pure-Rust реализация российских криптографических стандартов, совместимая с экосистемой RustCrypto.

Pure-Rust implementation of Russian cryptographic standards, compatible with the RustCrypto ecosystem.


Алгоритмы / Algorithms

Алгоритм Тип Feature
GOST 28147-89 (RFC 5830) Блочный шифр, 64-бит блок, 256-бит ключ всегда
GOST R 34.11-94 (RFC 5831) Хэш 256-бит, параметры CryptoPro и Test всегда
CMAC / OMAC MAC поверх GOST 28147-89 mac
GOST R 34.11-2012 Стрибог (RFC 6986) Хэш 256 / 512-бит streebog
  • no_std
  • Нет unsafe кода / No unsafe code
  • Нет зависимостей времени выполнения / No runtime dependencies

Cargo.toml

[dependencies]
gost-crypto = "0.2"

# Опционально / Optional:
gost-crypto = { version = "0.2", features = ["mac"] }
gost-crypto = { version = "0.2", features = ["streebog"] }

Примеры / Examples

GOST 28147-89 — шифрование блока / block encryption

use gost_crypto::{Gost28147, SBOX_CRYPTOPRO};

let key = [0x42u8; 32];
let cipher = Gost28147::with_sbox(&key, &SBOX_CRYPTOPRO);

let plaintext = [1u8, 2, 3, 4, 5, 6, 7, 8];
let ciphertext = cipher.encrypt_block_raw(&plaintext);
let recovered = cipher.decrypt_block_raw(&ciphertext);

assert_eq!(plaintext, recovered);

Для режимов CBC / CFB / OFB используйте внешние крейты из RustCrypto (cbc, cfb-mode, ofb) — Gost28147 реализует cipher::BlockCipherEncrypt + BlockCipherDecrypt + KeyInit.

For CBC / CFB / OFB modes use RustCrypto mode crates (cbc, cfb-mode, ofb) — Gost28147 implements cipher::BlockCipherEncrypt + BlockCipherDecrypt + KeyInit.

GOST R 34.11-94 — хэш / hash

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

let mut h = Gost341194::new_with_sbox(&SBOX_CRYPTOPRO);
h.update(b"hello");
let digest: [u8; 32] = h.finalize_bytes();

CMAC (feature mac)

use gost_crypto::mac::Gost28147Mac;
use digest::Mac;

let mut mac = Gost28147Mac::new(&[0x42u8; 32].into());
mac.update(b"message");
let tag = mac.finalize().into_bytes();

S-боксы / S-boxes

Два встроенных параметра:

Константа Назначение
SBOX_CRYPTOPRO КриптоПро CSP, RFC 4357 §11.2
SBOX_TEST RFC 5831 тестовые векторы

KeyInit::new использует SBOX_CRYPTOPRO. Для другого S-бокса — Gost28147::with_sbox.

KeyInit::new defaults to SBOX_CRYPTOPRO. Use Gost28147::with_sbox for a custom S-box.


Лицензия / License

WTFPL