sha2/
lib.rs

1#![no_std]
2#![doc = include_str!("../README.md")]
3#![doc(
4    html_logo_url = "https://raw.githubusercontent.com/RustCrypto/media/6ee8e381/logo.svg",
5    html_favicon_url = "https://raw.githubusercontent.com/RustCrypto/media/6ee8e381/logo.svg"
6)]
7#![cfg_attr(docsrs, feature(doc_auto_cfg))]
8#![warn(missing_docs)]
9#![cfg_attr(
10    any(sha2_backend = "riscv-zknh", sha2_backend = "riscv-zknh-compact"),
11    feature(riscv_ext_intrinsics)
12)]
13#![allow(clippy::needless_range_loop)]
14
15#[cfg(all(
16    any(sha2_backend = "riscv-zknh", sha2_backend = "riscv-zknh-compact"),
17    not(any(any(target_arch = "riscv32", target_arch = "riscv64")))
18))]
19compile_error!("The Zknh backends can be enabled only for RISC-V targets");
20
21pub use digest::{self, Digest};
22
23#[cfg(feature = "oid")]
24use digest::const_oid::{AssociatedOid, ObjectIdentifier};
25use digest::{
26    consts::{U28, U32, U48, U64},
27    core_api::{CoreWrapper, CtVariableCoreWrapper},
28    impl_oid_carrier,
29};
30
31#[rustfmt::skip]
32mod consts;
33mod core_api;
34mod sha256;
35mod sha512;
36
37pub use sha256::compress256;
38pub use sha512::compress512;
39
40pub use core_api::{Sha256VarCore, Sha512VarCore};
41
42impl_oid_carrier!(OidSha256, "2.16.840.1.101.3.4.2.1");
43impl_oid_carrier!(OidSha384, "2.16.840.1.101.3.4.2.2");
44impl_oid_carrier!(OidSha512, "2.16.840.1.101.3.4.2.3");
45impl_oid_carrier!(OidSha224, "2.16.840.1.101.3.4.2.4");
46impl_oid_carrier!(OidSha512_224, "2.16.840.1.101.3.4.2.5");
47impl_oid_carrier!(OidSha512_256, "2.16.840.1.101.3.4.2.6");
48
49/// SHA-224 hasher.
50pub type Sha224 = CoreWrapper<CtVariableCoreWrapper<Sha256VarCore, U28, OidSha224>>;
51/// SHA-256 hasher.
52pub type Sha256 = CoreWrapper<CtVariableCoreWrapper<Sha256VarCore, U32, OidSha256>>;
53/// SHA-512/224 hasher.
54pub type Sha512_224 = CoreWrapper<CtVariableCoreWrapper<Sha512VarCore, U28, OidSha512_224>>;
55/// SHA-512/256 hasher.
56pub type Sha512_256 = CoreWrapper<CtVariableCoreWrapper<Sha512VarCore, U32, OidSha512_256>>;
57/// SHA-384 hasher.
58pub type Sha384 = CoreWrapper<CtVariableCoreWrapper<Sha512VarCore, U48, OidSha384>>;
59/// SHA-512 hasher.
60pub type Sha512 = CoreWrapper<CtVariableCoreWrapper<Sha512VarCore, U64, OidSha512>>;