@@ -28,20 +28,10 @@ macro_rules! blake2_impl {
28
28
/// make sure to compare codes in constant time! It can be done
29
29
/// for example by using `subtle` crate.
30
30
pub fn new_keyed( key: & [ u8 ] , output_size: usize ) -> Self {
31
- Self :: with_params( key, & [ ] , & [ ] , output_size)
32
- }
33
-
34
- /// Creates a new hashing context with the full set of sequential-mode parameters.
35
- pub fn with_params( key: & [ u8 ] , salt: & [ u8 ] , persona: & [ u8 ] , output_size: usize ) -> Self {
36
31
let mut upstream_params = <$upstream_params>:: new( ) ;
37
- upstream_params
38
- . key( key)
39
- . salt( salt)
40
- . personal( persona)
41
- . hash_length( output_size) ;
42
-
32
+ upstream_params. key( key) ;
33
+ upstream_params. hash_length( output_size) ;
43
34
let upstream_state = upstream_params. to_state( ) ;
44
-
45
35
Self { upstream_params, upstream_state, output_size }
46
36
}
47
37
@@ -98,24 +88,11 @@ macro_rules! blake2_impl {
98
88
upstream_state: $upstream_state,
99
89
}
100
90
101
- impl $fix_state {
102
- /// Creates a new hashing context with the full set of sequential-mode parameters.
103
- pub fn with_params( key: & [ u8 ] , salt: & [ u8 ] , persona: & [ u8 ] ) -> Self {
104
- let mut upstream_params = <$upstream_params>:: new( ) ;
105
- upstream_params
106
- . key( key)
107
- . salt( salt)
108
- . personal( persona) ;
109
-
110
- let upstream_state = upstream_params. to_state( ) ;
111
-
112
- Self { upstream_params, upstream_state }
113
- }
114
- }
115
-
116
91
impl Default for $fix_state {
117
92
fn default ( ) -> Self {
118
- Self :: with_params( & [ ] , & [ ] , & [ ] )
93
+ let upstream_params = <$upstream_params>:: new( ) ;
94
+ let upstream_state = upstream_params. to_state( ) ;
95
+ Self { upstream_params, upstream_state }
119
96
}
120
97
}
121
98
@@ -147,14 +124,20 @@ macro_rules! blake2_impl {
147
124
type KeySize = $key_bytes_typenum;
148
125
149
126
fn new( key: & GenericArray <u8 , $key_bytes_typenum>) -> Self {
150
- Self :: with_params( & key[ ..] , & [ ] , & [ ] )
127
+ let mut upstream_params = <$upstream_params>:: new( ) ;
128
+ upstream_params. key( & key[ ..] ) ;
129
+ let upstream_state = upstream_params. to_state( ) ;
130
+ Self { upstream_params, upstream_state }
151
131
}
152
132
153
133
fn new_varkey( key: & [ u8 ] ) -> Result <Self , InvalidKeyLength > {
154
134
if key. len( ) > <$key_bytes_typenum>:: to_usize( ) {
155
135
Err ( InvalidKeyLength )
156
136
} else {
157
- Ok ( Self :: with_params( key, & [ ] , & [ ] ) )
137
+ let mut upstream_params = <$upstream_params>:: new( ) ;
138
+ upstream_params. key( key) ;
139
+ let upstream_state = upstream_params. to_state( ) ;
140
+ Ok ( Self { upstream_params, upstream_state } )
158
141
}
159
142
}
160
143
}
0 commit comments