Skip to content

Commit 7277282

Browse files
authored
sm3: add AssociatedOid implementation (#706)
The implementation uses the GM/T OID. SM3 also has an alternative ISO OID assigned to it (and IIRC several others), but we have to select one. If necessary, in future we may introduce different wrappers (e.g. `Sm3Iso`).
1 parent bf1b257 commit 7277282

File tree

4 files changed

+17
-1
lines changed

4 files changed

+17
-1
lines changed

sm3/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88
## 0.5.0 (UNRELEASED)
99
### Added
1010
- `alloc` crate feature ([#678])
11+
- `oid` crate feature and `AssociatedOid` trait implementation ([#706])
1112

1213
### Changed
1314
- Edition changed to 2024 and MSRV bumped to 1.85 ([#652])
@@ -20,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2021

2122
[#652]: https://github.com/RustCrypto/hashes/pull/652
2223
[#678]: https://github.com/RustCrypto/hashes/pull/678
24+
[#706]: https://github.com/RustCrypto/hashes/pull/706
2325

2426
## 0.4.2 (2023-05-16)
2527
### Changed

sm3/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ hex-literal = "1"
2121
base16ct = { version = "0.2", features = ["alloc"] }
2222

2323
[features]
24-
default = ["alloc"]
24+
default = ["alloc", "oid"]
2525
alloc = ["digest/alloc"]
26+
oid = ["digest/oid"] # Enable OID support
2627
zeroize = ["digest/zeroize"]
2728

2829
[package.metadata.docs.rs]

sm3/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,8 @@ pub use block_api::Sm3Core;
2020
digest::buffer_fixed!(
2121
/// ShangMi 3 (SM3) hasher.
2222
pub struct Sm3(block_api::Sm3Core);
23+
// Note that we use the GM/T OID here.
24+
// SM3 has also an alternative ISO OID assigned to it.
25+
oid: "1.2.156.10197.1.401";
2326
impl: FixedHashTraits;
2427
);

sm3/tests/mod.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,13 @@ fn sm3_rand() {
2929
hex!("ad154967b08d636a148dd4c688a6df7add1ed1946af18eb358a9b320de2aca86"),
3030
);
3131
}
32+
33+
#[cfg(feature = "oid")]
34+
#[test]
35+
fn sm3_oid() {
36+
use sm3::digest::const_oid::{AssociatedOid, ObjectIdentifier};
37+
assert_eq!(
38+
Sm3::OID,
39+
ObjectIdentifier::new_unwrap("1.2.156.10197.1.401")
40+
);
41+
}

0 commit comments

Comments
 (0)