Skip to content

Commit 5b67e73

Browse files
authored
gost94: add OID support (#417)
1 parent b501735 commit 5b67e73

File tree

5 files changed

+73
-2
lines changed

5 files changed

+73
-2
lines changed

.github/workflows/gost94.yml

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ jobs:
4949
strategy:
5050
matrix:
5151
rust:
52-
- 1.41.0 # MSRV
52+
- 1.57.0 # MSRV
5353
- stable
5454
steps:
5555
- uses: actions/checkout@v3
@@ -63,3 +63,21 @@ jobs:
6363
- run: cargo test --no-default-features
6464
- run: cargo test
6565
- run: cargo test --all-features
66+
67+
# TODO: merge with test on MSRV bump to 1.57 or higher
68+
test-msrv-41:
69+
runs-on: ubuntu-latest
70+
strategy:
71+
matrix:
72+
rust:
73+
- 1.41.0 # MSRV
74+
steps:
75+
- uses: actions/checkout@v3
76+
- uses: RustCrypto/actions/cargo-cache@master
77+
- uses: actions-rs/toolchain@v1
78+
with:
79+
profile: minimal
80+
toolchain: ${{ matrix.rust }}
81+
override: true
82+
- run: cargo test
83+
- run: cargo test --no-default-features

gost94/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@ categories = ["cryptography", "no-std"]
1515
digest = "0.10.3"
1616

1717
[dev-dependencies]
18-
digest = { version = "0.10.3", features = ["dev"] }
18+
digest = { version = "0.10.4", features = ["dev"] }
1919
hex-literal = "0.2.2"
2020

2121
[features]
2222
default = ["std"]
2323
std = ["digest/std"]
24+
oid = ["digest/oid"] # Enable OID support. WARNING: Bumps MSRV to 1.57

gost94/src/lib.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,17 @@
2121
//!
2222
//! Also see [RustCrypto/hashes][2] readme.
2323
//!
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+
//!
2431
//! [1]: https://en.wikipedia.org/wiki/GOST_(hash_function)
2532
//! [2]: https://github.com/RustCrypto/hashes
33+
//! [3]: https://www.rfc-editor.org/rfc/rfc4357
34+
//! [4]: https://www.rfc-editor.org/rfc/rfc4490
2635
2736
#![no_std]
2837
#![doc(
@@ -35,6 +44,8 @@
3544
#[cfg(feature = "std")]
3645
extern crate std;
3746

47+
#[cfg(feature = "oid")]
48+
use digest::const_oid::{AssociatedOid, ObjectIdentifier};
3849
use digest::core_api::CoreWrapper;
3950

4051
mod gost94_core;
@@ -45,6 +56,17 @@ pub use digest::{self, Digest};
4556

4657
pub use gost94_core::Gost94Core;
4758

59+
#[cfg(feature = "oid")]
60+
impl 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")]
66+
impl AssociatedOid for Gost94Core<params::GOST28147UAParam> {
67+
const OID: ObjectIdentifier = ObjectIdentifier::new_unwrap("1.2.804.2.1.1.1.1.2.1");
68+
}
69+
4870
/// GOST94 hash function with CryptoPro parameters.
4971
pub type Gost94CryptoPro = CoreWrapper<Gost94Core<params::CryptoProParam>>;
5072
/// GOST94 hash function with S-box defined in GOST R 34.12-2015.

gost94/src/params.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#[cfg(feature = "oid")]
2+
use digest::const_oid::{AssociatedOid, ObjectIdentifier};
3+
14
pub(crate) type Block = [u8; 32];
25
pub(crate) type SBox = [[u8; 16]; 8];
36

@@ -31,6 +34,12 @@ impl Gost94Params for CryptoProParam {
3134
const NAME: &'static str = "Gost94CryptoPro";
3235
}
3336

37+
#[cfg(feature = "oid")]
38+
impl AssociatedOid for CryptoProParam {
39+
/// Per RFC 4357
40+
const OID: ObjectIdentifier = ObjectIdentifier::new_unwrap("1.2.643.2.2.30.1");
41+
}
42+
3443
/// S-Box defined in GOST R 34.12-2015.
3544
#[derive(Copy, Clone, Default)]
3645
pub struct S2015Param;
@@ -69,6 +78,12 @@ impl Gost94Params for TestParam {
6978
const NAME: &'static str = "Gost94Test";
7079
}
7180

81+
#[cfg(feature = "oid")]
82+
impl AssociatedOid for TestParam {
83+
/// Per RFC 4357
84+
const OID: ObjectIdentifier = ObjectIdentifier::new_unwrap("1.2.643.2.2.30.0");
85+
}
86+
7287
/// S-Box defined in GOST 34.311-95 & GOST 28147:2009.
7388
#[derive(Copy, Clone, Default)]
7489
pub struct GOST28147UAParam;

gost94/tests/mod.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#[cfg(feature = "oid")]
2+
use digest::const_oid::{AssociatedOid, ObjectIdentifier};
13
use digest::dev::{feed_rand_16mib, fixed_reset_test};
24
use digest::new_test;
35
use gost94::{Digest, Gost94CryptoPro, Gost94Test, Gost94UA};
@@ -91,3 +93,16 @@ fn gost_ua_engine_tests() {
9193
hex!("7c536414f8b5b9cc649fdf3cccb2685c1a12622956308e34f31c50ed7b3af56c"),
9294
);
9395
}
96+
97+
#[cfg(feature = "oid")]
98+
#[test]
99+
fn gost_oid_tests() {
100+
assert_eq!(
101+
Gost94CryptoPro::OID,
102+
ObjectIdentifier::new_unwrap("1.2.643.2.2.9")
103+
);
104+
assert_eq!(
105+
Gost94UA::OID,
106+
ObjectIdentifier::new_unwrap("1.2.804.2.1.1.1.1.2.1")
107+
);
108+
}

0 commit comments

Comments
 (0)