////////////////////
/// HMAC SHA 512 ///
////////////////////
-void crypto_hmac_init(crypto_hmac_ctx *ctx, const u8 *key, size_t key_size)
+void crypto_hmac_sha512_init(crypto_hmac_sha512_ctx *ctx,
+ const u8 *key, size_t key_size)
{
// hash key if it is too long
if (key_size > 128) {
crypto_sha512_update(&ctx->ctx, ctx->key, 128);
}
-void crypto_hmac_update(crypto_hmac_ctx *ctx,
- const u8 *message, size_t message_size)
+void crypto_hmac_sha512_update(crypto_hmac_sha512_ctx *ctx,
+ const u8 *message, size_t message_size)
{
crypto_sha512_update(&ctx->ctx, message, message_size);
}
-void crypto_hmac_final(crypto_hmac_ctx *ctx, u8 hmac[64])
+void crypto_hmac_sha512_final(crypto_hmac_sha512_ctx *ctx, u8 hmac[64])
{
// Finish computing inner hash
crypto_sha512_final(&ctx->ctx, hmac);
WIPE_CTX(ctx);
}
-void crypto_hmac(u8 hmac[64], const u8 *key, size_t key_size,
- const u8 *message, size_t message_size)
+void crypto_hmac_sha512(u8 hmac[64], const u8 *key, size_t key_size,
+ const u8 *message, size_t message_size)
{
- crypto_hmac_ctx ctx;
- crypto_hmac_init (&ctx, key, key_size);
- crypto_hmac_update(&ctx, message, message_size);
- crypto_hmac_final (&ctx, hmac);
+ crypto_hmac_sha512_ctx ctx;
+ crypto_hmac_sha512_init (&ctx, key, key_size);
+ crypto_hmac_sha512_update(&ctx, message, message_size);
+ crypto_hmac_sha512_final (&ctx, hmac);
}
typedef struct {
uint8_t key[128];
crypto_sha512_ctx ctx;
-} crypto_hmac_ctx;
+} crypto_hmac_sha512_ctx;
typedef struct {
crypto_sign_ctx_abstract ctx;
// HMAC SHA 512
// ------------
-void crypto_hmac_init(crypto_hmac_ctx *ctx,
- const uint8_t *key, size_t key_size);
-void crypto_hmac_update(crypto_hmac_ctx *ctx,
- const uint8_t *message, size_t message_size);
-void crypto_hmac_final(crypto_hmac_ctx *ctx, uint8_t hmac[64]);
-void crypto_hmac(uint8_t hmac[64],
- const uint8_t *key , size_t key_size,
- const uint8_t *message, size_t message_size);
+void crypto_hmac_sha512_init(crypto_hmac_sha512_ctx *ctx,
+ const uint8_t *key, size_t key_size);
+void crypto_hmac_sha512_update(crypto_hmac_sha512_ctx *ctx,
+ const uint8_t *message, size_t message_size);
+void crypto_hmac_sha512_final(crypto_hmac_sha512_ctx *ctx, uint8_t hmac[64]);
+void crypto_hmac_sha512(uint8_t hmac[64],
+ const uint8_t *key , size_t key_size,
+ const uint8_t *message, size_t message_size);
// Ed25519
{
const vector *key = in;
const vector *msg = in +1;
- crypto_hmac(out->buf, key->buf, key->size, msg->buf, msg->size);
+ crypto_hmac_sha512(out->buf, key->buf, key->size, msg->buf, msg->size);
}
static void argon2i(const vector in[], vector *out)
RANDOM_INPUT(input, INPUT_SIZE);
// Authenticate bit by bit
- crypto_hmac_ctx ctx;
- crypto_hmac_init(&ctx, key, 32);
- crypto_hmac_update(&ctx, input , i);
- crypto_hmac_update(&ctx, input + i, INPUT_SIZE - i);
- crypto_hmac_final(&ctx, hash_chunk);
+ crypto_hmac_sha512_ctx ctx;
+ crypto_hmac_sha512_init(&ctx, key, 32);
+ crypto_hmac_sha512_update(&ctx, input , i);
+ crypto_hmac_sha512_update(&ctx, input + i, INPUT_SIZE - i);
+ crypto_hmac_sha512_final(&ctx, hash_chunk);
// Authenticate all at once
- crypto_hmac(hash_whole, key, 32, input, INPUT_SIZE);
+ crypto_hmac_sha512(hash_whole, key, 32, input, INPUT_SIZE);
// Compare the results (must be the same)
status |= memcmp(hash_chunk, hash_whole, 64);
u8 hash [64];
RANDOM_INPUT(key , 32);
RANDOM_INPUT(input, INPUT_SIZE);
- crypto_hmac(hash , key, 32, input + 64, SHA_512_BLOCK_SIZE);
- crypto_hmac(input+i, key, 32, input + 64, SHA_512_BLOCK_SIZE);
+ crypto_hmac_sha512(hash , key, 32, input + 64, SHA_512_BLOCK_SIZE);
+ crypto_hmac_sha512(input+i, key, 32, input + 64, SHA_512_BLOCK_SIZE);
status |= memcmp(hash, input + i, 64);
}
printf("%s: HMAC SHA-512 (overlaping i/o)\n", status != 0 ? "FAILED" : "OK");