Skip to content

Commit 1266d94

Browse files
committed
gost94: add OID support
Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
1 parent e07cc2d commit 1266d94

6 files changed

Lines changed: 80 additions & 39 deletions

File tree

.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

Cargo.lock

Lines changed: 17 additions & 37 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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/gost94_core.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#![allow(clippy::many_single_char_names)]
22
use core::{convert::TryInto, fmt};
3+
#[cfg(feature = "oid")]
4+
use digest::const_oid::{AssociatedOid, ObjectIdentifier};
35
use digest::{
46
block_buffer::Eager,
57
core_api::{
@@ -196,6 +198,15 @@ impl<P: Gost94Params> Gost94Core<P> {
196198
}
197199
}
198200

201+
#[cfg(feature = "oid")]
202+
#[cfg_attr(docsrs, doc(cfg(feature = "oid")))]
203+
impl<P> AssociatedOid for Gost94Core<P>
204+
where
205+
P: Gost94Params + AssociatedOid,
206+
{
207+
const OID: ObjectIdentifier = P::OID;
208+
}
209+
199210
impl<P: Gost94Params> HashMarker for Gost94Core<P> {}
200211

201212
impl<P: Gost94Params> BlockSizeUser for Gost94Core<P> {

gost94/src/params.rs

Lines changed: 16 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,14 @@ impl Gost94Params for CryptoProParam {
3134
const NAME: &'static str = "Gost94CryptoPro";
3235
}
3336

37+
#[cfg(feature = "oid")]
38+
impl AssociatedOid for CryptoProParam {
39+
/// Per the RFC 4490, this OID is used for the GOST R 34.11-94 hash with CryptoPro params.
40+
/// The OID 1.2.643.2.2.30.1 is used in the PublicKey params to denote CryptoPro paramset, but
41+
/// not the hash function itself.
42+
const OID: ObjectIdentifier = ObjectIdentifier::new_unwrap("1.2.643.2.2.9");
43+
}
44+
3445
/// S-Box defined in GOST R 34.12-2015.
3546
#[derive(Copy, Clone, Default)]
3647
pub struct S2015Param;
@@ -87,3 +98,8 @@ impl Gost94Params for GOST28147UAParam {
8798
const H0: Block = [0; 32];
8899
const NAME: &'static str = "Gost28147UA";
89100
}
101+
102+
#[cfg(feature = "oid")]
103+
impl AssociatedOid for GOST28147UAParam {
104+
const OID: ObjectIdentifier = ObjectIdentifier::new_unwrap("1.2.804.2.1.1.1.1.2.1");
105+
}

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)