mirror of
https://github.com/jedisct1/libsodium.git
synced 2026-08-25 08:37:13 +09:00
Relax crypto_auth_hmacsha{256,512}_init to accept NULL pointers
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "core.h"
|
||||
#include "crypto_auth_hmacsha256.h"
|
||||
#include "crypto_hash_sha256.h"
|
||||
#include "crypto_verify_32.h"
|
||||
@@ -47,6 +48,10 @@ crypto_auth_hmacsha256_init(crypto_auth_hmacsha256_state *state,
|
||||
crypto_hash_sha256_final(&state->ictx, khash);
|
||||
key = khash;
|
||||
keylen = 32;
|
||||
} else if (key == NULL) {
|
||||
if (keylen > 0) {
|
||||
sodium_misuse();
|
||||
}
|
||||
}
|
||||
crypto_hash_sha256_init(&state->ictx);
|
||||
memset(pad, 0x36, 64);
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "core.h"
|
||||
#include "crypto_auth_hmacsha512.h"
|
||||
#include "crypto_hash_sha512.h"
|
||||
#include "crypto_verify_64.h"
|
||||
@@ -47,6 +48,10 @@ crypto_auth_hmacsha512_init(crypto_auth_hmacsha512_state *state,
|
||||
crypto_hash_sha512_final(&state->ictx, khash);
|
||||
key = khash;
|
||||
keylen = 64;
|
||||
} else if (key == NULL) {
|
||||
if (keylen > 0) {
|
||||
sodium_misuse();
|
||||
}
|
||||
}
|
||||
crypto_hash_sha512_init(&state->ictx);
|
||||
memset(pad, 0x36, 128);
|
||||
|
||||
@@ -46,7 +46,7 @@ size_t crypto_auth_hmacsha256_statebytes(void);
|
||||
SODIUM_EXPORT
|
||||
int crypto_auth_hmacsha256_init(crypto_auth_hmacsha256_state *state,
|
||||
const unsigned char *key,
|
||||
size_t keylen) __attribute__ ((nonnull));
|
||||
size_t keylen) __attribute__ ((nonnull(1)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_auth_hmacsha256_update(crypto_auth_hmacsha256_state *state,
|
||||
|
||||
@@ -46,7 +46,7 @@ size_t crypto_auth_hmacsha512_statebytes(void);
|
||||
SODIUM_EXPORT
|
||||
int crypto_auth_hmacsha512_init(crypto_auth_hmacsha512_state *state,
|
||||
const unsigned char *key,
|
||||
size_t keylen) __attribute__ ((nonnull));
|
||||
size_t keylen) __attribute__ ((nonnull(1)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_auth_hmacsha512_update(crypto_auth_hmacsha512_state *state,
|
||||
|
||||
Reference in New Issue
Block a user