gost94/
lib.rs

1//! An implementation of the [GOST R 34.11-94][1] cryptographic hash algorithm.
2//!
3//! # Usage
4//! ```rust
5//! use gost94::{Gost94CryptoPro, Digest};
6//! use hex_literal::hex;
7//!
8//! // create Gost94 hasher instance with CryptoPro params
9//! let mut hasher = Gost94CryptoPro::new();
10//!
11//! // process input message
12//! hasher.update("The quick brown fox jumps over the lazy dog");
13//!
14//! // acquire hash digest in the form of GenericArray,
15//! // which in this case is equivalent to [u8; 32]
16//! let result = hasher.finalize();
17//! assert_eq!(result[..], hex!("
18//!     9004294a361a508c586fe53d1f1b02746765e71b765472786e4770d565830a76
19//! "));
20//! ```
21//!
22//! Also see [RustCrypto/hashes][2] readme.
23//!
24//! # Associated OIDs.
25//! There can be a confusion regarding OIDs associated with declared types. According to the
26//! [RFC 4357][3], the OIDs 1.2.643.2.2.30.1 and 1.2.643.2.2.30.0 are used to identify the hash
27//! function parameter sets (CryptoPro vs Test ones). According to [RFC 4490][4] the OID
28//! 1.2.643.2.2.9 identifies the GOST 34.311-95 (former GOST R 34.11-94) function, but then it
29//! continues that this function MUST be used only with the CryptoPro parameter set.
30//!
31//! [1]: https://en.wikipedia.org/wiki/GOST_(hash_function)
32//! [2]: https://github.com/RustCrypto/hashes
33//! [3]: https://www.rfc-editor.org/rfc/rfc4357
34//! [4]: https://www.rfc-editor.org/rfc/rfc4490
35
36#![no_std]
37#![doc(
38    html_logo_url = "https://raw.githubusercontent.com/RustCrypto/media/6ee8e381/logo.svg",
39    html_favicon_url = "https://raw.githubusercontent.com/RustCrypto/media/6ee8e381/logo.svg"
40)]
41#![warn(missing_docs, rust_2018_idioms)]
42#![forbid(unsafe_code)]
43
44#[cfg(feature = "std")]
45extern crate std;
46
47#[cfg(feature = "oid")]
48use digest::const_oid::{AssociatedOid, ObjectIdentifier};
49use digest::core_api::CoreWrapper;
50
51mod gost94_core;
52/// GOST94 parameters.
53pub mod params;
54
55pub use digest::{self, Digest};
56
57pub use gost94_core::Gost94Core;
58
59#[cfg(feature = "oid")]
60impl AssociatedOid for Gost94Core<params::CryptoProParam> {
61    /// Per RFC 4490
62    const OID: ObjectIdentifier = ObjectIdentifier::new_unwrap("1.2.643.2.2.9");
63}
64
65#[cfg(feature = "oid")]
66impl AssociatedOid for Gost94Core<params::GOST28147UAParam> {
67    const OID: ObjectIdentifier = ObjectIdentifier::new_unwrap("1.2.804.2.1.1.1.1.2.1");
68}
69
70/// GOST94 hash function with CryptoPro parameters.
71pub type Gost94CryptoPro = CoreWrapper<Gost94Core<params::CryptoProParam>>;
72/// GOST94 hash function with S-box defined in GOST R 34.12-2015.
73pub type Gost94s2015 = CoreWrapper<Gost94Core<params::S2015Param>>;
74/// GOST94 hash function with test parameters.
75pub type Gost94Test = CoreWrapper<Gost94Core<params::TestParam>>;
76/// GOST94 hash function with UAPKI GOST 34.311-95 parameters
77/// (1.2.804.2.1.1.1.1.2.1 OID).
78pub type Gost94UA = CoreWrapper<Gost94Core<params::GOST28147UAParam>>;