1#![forbid(unsafe_code)]
38#![allow(private_bounds)]
39
40mod sha256;
41mod sha512;
42
43pub use self::sha256::SHA256Internal;
44pub use self::sha512::Sha512Internal;
45use bouncycastle_core::traits::{Algorithm, HashAlgParams, SecurityStrength};
46
47pub const SHA224_NAME: &str = "SHA224";
49pub const SHA256_NAME: &str = "SHA256";
50pub const SHA384_NAME: &str = "SHA384";
51pub const SHA512_NAME: &str = "SHA512";
52
53pub type SHA224 = SHA256Internal<SHA224Params>;
55pub type SHA256 = SHA256Internal<SHA256Params>;
56pub type SHA384 = Sha512Internal<SHA384Params>;
57pub type SHA512 = Sha512Internal<SHA512Params>;
58
59trait SHA2Params: HashAlgParams {}
62
63impl Algorithm for SHA224 {
64 const ALG_NAME: &'static str = SHA224_NAME;
65 const MAX_SECURITY_STRENGTH: SecurityStrength = SecurityStrength::_112bit;
66}
67impl HashAlgParams for SHA224 {
68 const OUTPUT_LEN: usize = 28;
69 const BLOCK_LEN: usize = 64;
70}
71pub struct SHA224Params;
72impl Algorithm for SHA224Params {
73 const ALG_NAME: &'static str = SHA224_NAME;
74 const MAX_SECURITY_STRENGTH: SecurityStrength = SecurityStrength::_112bit;
75}
76impl HashAlgParams for SHA224Params {
77 const OUTPUT_LEN: usize = 28;
78 const BLOCK_LEN: usize = 64;
79}
80impl SHA2Params for SHA224Params {}
81
82impl Algorithm for SHA256 {
83 const ALG_NAME: &'static str = SHA256_NAME;
84 const MAX_SECURITY_STRENGTH: SecurityStrength = SecurityStrength::_128bit;
85}
86impl HashAlgParams for SHA256 {
87 const OUTPUT_LEN: usize = 32;
88 const BLOCK_LEN: usize = 64;
89}
90pub struct SHA256Params;
91impl Algorithm for SHA256Params {
92 const ALG_NAME: &'static str = SHA256_NAME;
93 const MAX_SECURITY_STRENGTH: SecurityStrength = SecurityStrength::_128bit;
94}
95impl HashAlgParams for SHA256Params {
96 const OUTPUT_LEN: usize = 32;
97 const BLOCK_LEN: usize = 64;
98}
99impl SHA2Params for SHA256Params {}
100
101impl Algorithm for SHA384 {
102 const ALG_NAME: &'static str = SHA384_NAME;
103 const MAX_SECURITY_STRENGTH: SecurityStrength = SecurityStrength::_192bit;
104}
105impl HashAlgParams for SHA384 {
106 const OUTPUT_LEN: usize = 48;
107 const BLOCK_LEN: usize = 128;
108}
109pub struct SHA384Params;
110impl Algorithm for SHA384Params {
111 const ALG_NAME: &'static str = SHA384_NAME;
112 const MAX_SECURITY_STRENGTH: SecurityStrength = SecurityStrength::_192bit;
113}
114impl HashAlgParams for SHA384Params {
115 const OUTPUT_LEN: usize = 48;
116 const BLOCK_LEN: usize = 128;
117}
118impl SHA2Params for SHA384Params {}
119
120pub struct SHA512Params;
121impl Algorithm for SHA512 {
122 const ALG_NAME: &'static str = SHA512_NAME;
123 const MAX_SECURITY_STRENGTH: SecurityStrength = SecurityStrength::_256bit;
124}
125impl HashAlgParams for SHA512 {
126 const OUTPUT_LEN: usize = 64;
127 const BLOCK_LEN: usize = 128;
128}
129impl Algorithm for SHA512Params {
130 const ALG_NAME: &'static str = SHA512_NAME;
131 const MAX_SECURITY_STRENGTH: SecurityStrength = SecurityStrength::_256bit;
132}
133impl HashAlgParams for SHA512Params {
134 const OUTPUT_LEN: usize = 64;
135 const BLOCK_LEN: usize = 128;
136}
137impl SHA2Params for SHA512Params {}