1#![forbid(unsafe_code)]
69#![forbid(missing_docs)]
70#![allow(private_bounds)]
71
72mod sha256;
73mod sha512;
74
75pub use self::sha256::SHA256Internal;
76pub use self::sha512::SHA512Internal;
77use bouncycastle_core::traits::{Algorithm, AlgorithmOID, HashAlgParams, SecurityStrength};
78
79#[allow(unused_imports)]
81use bouncycastle_core::traits::Suspendable;
82
83pub const SHA224_NAME: &str = "SHA224";
86pub const SHA256_NAME: &str = "SHA256";
88pub const SHA384_NAME: &str = "SHA384";
90pub const SHA512_NAME: &str = "SHA512";
92
93pub type SHA224 = SHA256Internal<SHA224Params>;
96pub type SHA256 = SHA256Internal<SHA256Params>;
98pub type SHA384 = SHA512Internal<SHA384Params>;
100pub type SHA512 = SHA512Internal<SHA512Params>;
102
103trait SHA2Params: HashAlgParams {}
106
107impl HashAlgParams for SHA224 {
109 const OUTPUT_LEN: usize = 28;
110 const BLOCK_LEN: usize = 64;
111}
112#[derive(Clone)]
114pub struct SHA224Params;
115impl Algorithm for SHA224Params {
116 const ALG_NAME: &'static str = SHA224_NAME;
117 const MAX_SECURITY_STRENGTH: SecurityStrength = SecurityStrength::_112bit;
118}
119impl HashAlgParams for SHA224Params {
120 const OUTPUT_LEN: usize = 28;
121 const BLOCK_LEN: usize = 64;
122}
123impl AlgorithmOID for SHA224 {
125 const OID: &'static [u32] = &[2, 16, 840, 1, 101, 3, 4, 2, 4];
126 const OID_DER: &'static [u8] =
127 &[0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x04];
128}
129impl SHA2Params for SHA224Params {}
130
131impl HashAlgParams for SHA256 {
133 const OUTPUT_LEN: usize = 32;
134 const BLOCK_LEN: usize = 64;
135}
136#[derive(Clone)]
138pub struct SHA256Params;
139impl Algorithm for SHA256Params {
140 const ALG_NAME: &'static str = SHA256_NAME;
141 const MAX_SECURITY_STRENGTH: SecurityStrength = SecurityStrength::_128bit;
142}
143impl AlgorithmOID for SHA256 {
145 const OID: &'static [u32] = &[2, 16, 840, 1, 101, 3, 4, 2, 1];
146 const OID_DER: &'static [u8] =
147 &[0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01];
148}
149impl HashAlgParams for SHA256Params {
150 const OUTPUT_LEN: usize = 32;
151 const BLOCK_LEN: usize = 64;
152}
153impl SHA2Params for SHA256Params {}
154
155impl HashAlgParams for SHA384 {
157 const OUTPUT_LEN: usize = 48;
158 const BLOCK_LEN: usize = 128;
159}
160#[derive(Clone)]
162pub struct SHA384Params;
163impl Algorithm for SHA384Params {
164 const ALG_NAME: &'static str = SHA384_NAME;
165 const MAX_SECURITY_STRENGTH: SecurityStrength = SecurityStrength::_192bit;
166}
167impl AlgorithmOID for SHA384 {
169 const OID: &'static [u32] = &[2, 16, 840, 1, 101, 3, 4, 2, 2];
170 const OID_DER: &'static [u8] =
171 &[0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x02];
172}
173impl HashAlgParams for SHA384Params {
174 const OUTPUT_LEN: usize = 48;
175 const BLOCK_LEN: usize = 128;
176}
177impl SHA2Params for SHA384Params {}
178
179#[derive(Clone)]
182pub struct SHA512Params;
183impl HashAlgParams for SHA512 {
184 const OUTPUT_LEN: usize = 64;
185 const BLOCK_LEN: usize = 128;
186}
187impl Algorithm for SHA512Params {
188 const ALG_NAME: &'static str = SHA512_NAME;
189 const MAX_SECURITY_STRENGTH: SecurityStrength = SecurityStrength::_256bit;
190}
191impl HashAlgParams for SHA512Params {
192 const OUTPUT_LEN: usize = 64;
193 const BLOCK_LEN: usize = 128;
194}
195impl AlgorithmOID for SHA512 {
197 const OID: &'static [u32] = &[2, 16, 840, 1, 101, 3, 4, 2, 3];
198 const OID_DER: &'static [u8] =
199 &[0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x03];
200}
201impl SHA2Params for SHA512Params {}
202
203pub use sha256::SUSPENDED_SHA256_STATE_LEN;
204pub use sha512::SUSPENDED_SHA512_STATE_LEN;