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 2d53f48
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 13 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" }
1 change: 1 addition & 0 deletions sha1/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ hex-literal = "0.2.2"
[features]
default = ["std"]
std = ["digest/std"]
oid = ["digest/oid"]
asm = ["sha1-asm"] # WARNING: this feature SHOULD NOT be enabled by library crates
compress = [] # Expose compress function
force-soft = [] # Force software implementation
Expand Down
8 changes: 8 additions & 0 deletions sha1/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ use digest::{
typenum::{Unsigned, U20, U64},
HashMarker, Output,
};
#[cfg(feature = "oid")]
use digest::const_oid::{AssociatedOid, ObjectIdentifier};

mod compress;

Expand Down Expand Up @@ -142,5 +144,11 @@ impl fmt::Debug for Sha1Core {
}
}

#[cfg(feature = "oid")]
#[cfg_attr(docsrs, doc(cfg(feature = "oid")))]
impl AssociatedOid for Sha1Core {
const OID: ObjectIdentifier = ObjectIdentifier::new_unwrap("1.3.14.3.2.26");
}

/// SHA-1 hasher state.
pub type Sha1 = CoreWrapper<Sha1Core>;
1 change: 1 addition & 0 deletions sha2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ hex-literal = "0.2.2"
[features]
default = ["std"]
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
20 changes: 15 additions & 5 deletions sha2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ pub use digest::{self, Digest};
use digest::{
consts::{U28, U32, U48, U64},
core_api::{CoreWrapper, CtVariableCoreWrapper},
impl_oid_carrier,
};
#[cfg(feature = "oid")]
use digest::const_oid::{AssociatedOid, ObjectIdentifier};

#[rustfmt::skip]
mod consts;
Expand All @@ -71,15 +74,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>>;
1 change: 1 addition & 0 deletions streebog/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ hex-literal = "0.2.2"
[features]
default = ["std"]
std = ["digest/std"]
oid = ["digest/oid"]
10 changes: 8 additions & 2 deletions streebog/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ extern crate std;
use digest::{
consts::{U32, U64},
core_api::{CoreWrapper, CtVariableCoreWrapper},
impl_oid_carrier,
};
#[cfg(feature = "oid")]
use digest::const_oid::{AssociatedOid, ObjectIdentifier};

mod consts;
mod core_api;
Expand All @@ -56,7 +59,10 @@ mod table;
pub use core_api::StreebogVarCore;
pub use digest::{self, Digest};

impl_oid_carrier!(Oid256, "1.2.643.7.1.1.2.2");
impl_oid_carrier!(Oid512, "1.2.643.7.1.1.2.3");

/// Streebog256 hasher.
pub type Streebog256 = CoreWrapper<CtVariableCoreWrapper<StreebogVarCore, U32>>;
pub type Streebog256 = CoreWrapper<CtVariableCoreWrapper<StreebogVarCore, U32, Oid256>>;
/// Streebog512 hasher.
pub type Streebog512 = CoreWrapper<CtVariableCoreWrapper<StreebogVarCore, U64>>;
pub type Streebog512 = CoreWrapper<CtVariableCoreWrapper<StreebogVarCore, U64, Oid512>>;

0 comments on commit 2d53f48

Please sign in to comment.