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