File tree 2 files changed +13
-4
lines changed
2 files changed +13
-4
lines changed Original file line number Diff line number Diff line change @@ -274,9 +274,12 @@ macro_rules! blake2_mac_impl {
274
274
{
275
275
/// Create new instance using provided key, salt, and persona.
276
276
///
277
- /// Key length should not be bigger than block size, salt and persona
278
- /// length should not be bigger than quarter of block size. If any
279
- /// of those conditions is false the method will return an error.
277
+ /// # Errors
278
+ ///
279
+ /// Key length should not be empty or bigger than the block size and
280
+ /// the salt and persona length should not be bigger than quarter of
281
+ /// block size. If any of those conditions is false the method will
282
+ /// return an error.
280
283
#[ inline]
281
284
pub fn new_with_salt_and_personal(
282
285
key: & [ u8 ] ,
@@ -286,7 +289,7 @@ macro_rules! blake2_mac_impl {
286
289
let kl = key. len( ) ;
287
290
let bs = <$hash as BlockSizeUser >:: BlockSize :: USIZE ;
288
291
let qbs = bs / 4 ;
289
- if kl > bs || salt. len( ) > qbs || persona. len( ) > qbs {
292
+ if kl == 0 || kl > bs || salt. len( ) > qbs || persona. len( ) > qbs {
290
293
return Err ( InvalidLength ) ;
291
294
}
292
295
let mut padded_key = Block :: <$hash>:: default ( ) ;
Original file line number Diff line number Diff line change @@ -27,3 +27,9 @@ fn blake2b_new_test() {
27
27
run :: < blake2:: Blake2sMac256 > ( & [ 0x42 ; 32 ] ) ;
28
28
run :: < blake2:: Blake2bMac512 > ( & [ 0x42 ; 64 ] ) ;
29
29
}
30
+
31
+ #[ test]
32
+ fn mac_refuses_empty_keys ( ) {
33
+ assert ! ( blake2:: Blake2bMac512 :: new_with_salt_and_personal( & [ ] , b"salt" , b"persona" ) . is_err( ) ) ;
34
+ assert ! ( blake2:: Blake2sMac256 :: new_with_salt_and_personal( & [ ] , b"salt" , b"persona" ) . is_err( ) ) ;
35
+ }
You can’t perform that action at this time.
0 commit comments