Skip to content

Commit

Permalink
Add OID support
Browse files Browse the repository at this point in the history
  • Loading branch information
newpavlov committed Sep 9, 2022
1 parent cc52373 commit 52e9220
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 12 deletions.
17 changes: 11 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,6 @@ members = [

[profile.dev]
opt-level = 2

[patch.crates-io]
digest = { git = "https://github.com/RustCrypto/traits", branch = "digest/const-oid-impl" }
3 changes: 2 additions & 1 deletion sha2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ digest = { version = "0.10.3", features = ["dev"] }
hex-literal = "0.2.2"

[features]
default = ["std"]
default = ["std", "oid"]
std = ["digest/std"]
oid = ["digest/oid"]
asm = ["sha2-asm"] # WARNING: this feature SHOULD NOT be enabled by library crates
compress = [] # Expose compress functions
force-soft = [] # Force software implementation
Expand Down
22 changes: 17 additions & 5 deletions sha2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ use digest::{
consts::{U28, U32, U48, U64},
core_api::{CoreWrapper, CtVariableCoreWrapper},
};
#[cfg(feature = "oid")]
use digest::{
const_oid::{AssociatedOid, ObjectIdentifier},
impl_oid_carrier,
};

#[rustfmt::skip]
mod consts;
Expand All @@ -71,15 +76,22 @@ pub use sha512::compress512;

pub use core_api::{Sha256VarCore, Sha512VarCore};

impl_oid_carrier!(OidSha256, "2.16.840.1.101.3.4.2.1");
impl_oid_carrier!(OidSha384, "2.16.840.1.101.3.4.2.2");
impl_oid_carrier!(OidSha512, "2.16.840.1.101.3.4.2.3");
impl_oid_carrier!(OidSha224, "2.16.840.1.101.3.4.2.4");
impl_oid_carrier!(OidSha512_224, "2.16.840.1.101.3.4.2.5");
impl_oid_carrier!(OidSha512_256, "2.16.840.1.101.3.4.2.6");

/// SHA-224 hasher.
pub type Sha224 = CoreWrapper<CtVariableCoreWrapper<Sha256VarCore, U28>>;
pub type Sha224 = CoreWrapper<CtVariableCoreWrapper<Sha256VarCore, U28, OidSha224>>;
/// SHA-256 hasher.
pub type Sha256 = CoreWrapper<CtVariableCoreWrapper<Sha256VarCore, U32>>;
/// SHA-512/224 hasher.
pub type Sha512_224 = CoreWrapper<CtVariableCoreWrapper<Sha512VarCore, U28>>;
pub type Sha512_224 = CoreWrapper<CtVariableCoreWrapper<Sha512VarCore, U28, OidSha512_224>>;
/// SHA-512/256 hasher.
pub type Sha512_256 = CoreWrapper<CtVariableCoreWrapper<Sha512VarCore, U32>>;
pub type Sha512_256 = CoreWrapper<CtVariableCoreWrapper<Sha512VarCore, U32, OidSha512_256>>;
/// SHA-384 hasher.
pub type Sha384 = CoreWrapper<CtVariableCoreWrapper<Sha512VarCore, U48>>;
pub type Sha384 = CoreWrapper<CtVariableCoreWrapper<Sha512VarCore, U48, OidSha384>>;
/// SHA-512 hasher.
pub type Sha512 = CoreWrapper<CtVariableCoreWrapper<Sha512VarCore, U64>>;
pub type Sha512 = CoreWrapper<CtVariableCoreWrapper<Sha512VarCore, U64, OidSha512>>;

0 comments on commit 52e9220

Please sign in to comment.