Add GOST 34.311-95 28147-89 UA version (#377)

This commit is contained in:
IvashchenkoSerhii
2022-05-26 18:08:57 +03:00
committed by GitHub
parent dfcfb21f7f
commit 9125a4bc31
6 changed files with 42 additions and 4 deletions

2
Cargo.lock generated
View File

@@ -89,7 +89,7 @@ dependencies = [
[[package]]
name = "gost94"
version = "0.10.1"
version = "0.10.2"
dependencies = [
"digest",
"hex-literal",

View File

@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## 0.10.2 (2022-05-25)
### Added
- Gost 34.311-95 28147-89 UA version 1.2.804.2.1.1.1.1.2.1 OID ([#377])
[#377]: https://github.com/RustCrypto/hashes/pull/377
## 0.10.1 (2022-02-17)
### Fixed
- Minimal versions build ([#363])

View File

@@ -1,6 +1,6 @@
[package]
name = "gost94"
version = "0.10.1" # Also update html_root_url in lib.rs when bumping this
version = "0.10.2" # Also update html_root_url in lib.rs when bumping this
description = "GOST R 34.11-94 hash function"
authors = ["RustCrypto Developers"]
license = "MIT OR Apache-2.0"

View File

@@ -28,7 +28,7 @@
#![doc(
html_logo_url = "https://raw.githubusercontent.com/RustCrypto/media/6ee8e381/logo.svg",
html_favicon_url = "https://raw.githubusercontent.com/RustCrypto/media/6ee8e381/logo.svg",
html_root_url = "https://docs.rs/gost94/0.10.1"
html_root_url = "https://docs.rs/gost94/0.10.2"
)]
#![warn(missing_docs, rust_2018_idioms)]
#![forbid(unsafe_code)]
@@ -52,3 +52,6 @@ pub type Gost94CryptoPro = CoreWrapper<Gost94Core<params::CryptoProParam>>;
pub type Gost94s2015 = CoreWrapper<Gost94Core<params::S2015Param>>;
/// GOST94 hash function with test parameters.
pub type Gost94Test = CoreWrapper<Gost94Core<params::TestParam>>;
/// GOST94 hash function with UAPKI GOST 34.311-95 parameters
/// (1.2.804.2.1.1.1.1.2.1 OID).
pub type Gost94UA = CoreWrapper<Gost94Core<params::GOST28147UAParam>>;

View File

@@ -68,3 +68,22 @@ impl Gost94Params for TestParam {
const H0: Block = [0; 32];
const NAME: &'static str = "Gost94Test";
}
/// S-Box defined in GOST 34.311-95 & GOST 28147:2009.
#[derive(Copy, Clone, Default)]
pub struct GOST28147UAParam;
impl Gost94Params for GOST28147UAParam {
const S_BOX: SBox = [
[10, 9, 13, 6, 14, 11, 4, 5, 15, 1, 3, 12, 7, 0, 8, 2],
[8, 0, 12, 4, 9, 6, 7, 11, 2, 3, 1, 15, 5, 14, 10, 13],
[15, 6, 5, 8, 14, 11, 10, 4, 12, 0, 3, 7, 2, 9, 1, 13],
[3, 8, 13, 9, 6, 11, 15, 0, 2, 5, 12, 10, 4, 14, 1, 7],
[15, 8, 14, 9, 7, 2, 0, 13, 12, 6, 1, 5, 11, 4, 3, 10],
[2, 8, 9, 7, 5, 15, 0, 11, 12, 1, 13, 14, 10, 3, 6, 4],
[3, 8, 11, 5, 6, 4, 14, 10, 2, 12, 1, 7, 9, 15, 13, 0],
[1, 2, 3, 14, 6, 13, 11, 8, 15, 10, 12, 5, 7, 9, 0, 4],
];
const H0: Block = [0; 32];
const NAME: &'static str = "Gost28147UA";
}

View File

@@ -1,6 +1,6 @@
use digest::dev::{feed_rand_16mib, fixed_reset_test};
use digest::new_test;
use gost94::{Digest, Gost94CryptoPro, Gost94Test};
use gost94::{Digest, Gost94CryptoPro, Gost94Test, Gost94UA};
use hex_literal::hex;
new_test!(gost94_test_main, "test", Gost94Test, fixed_reset_test);
@@ -81,3 +81,13 @@ fn arithmetic_overflow_regression() {
h.update(&include_bytes!("data/arithmetic_overflow.bin")[..]);
h.finalize().as_slice();
}
#[test]
fn gost_ua_engine_tests() {
let mut h = Gost94UA::new();
h.update(b"test");
assert_eq!(
h.finalize_reset().as_slice(),
hex!("7c536414f8b5b9cc649fdf3cccb2685c1a12622956308e34f31c50ed7b3af56c"),
);
}