diff --git a/crypto/hmac_drbg.c b/crypto/hmac_drbg.c index c8772ead2..fa4569f49 100644 --- a/crypto/hmac_drbg.c +++ b/crypto/hmac_drbg.c @@ -20,8 +20,8 @@ * OTHER DEALINGS IN THE SOFTWARE. */ -#include #include "hmac_drbg.h" +#include #include "memzero.h" #include "sha2.h" @@ -83,7 +83,9 @@ static void update_v(HMAC_DRBG_CTX *ctx) { sha256_Transform(ctx->odig, ctx->v, ctx->v); } -void hmac_drbg_init(HMAC_DRBG_CTX *ctx, const uint8_t *entropy, size_t entropy_len, const uint8_t *nonce, size_t nonce_len) { +void hmac_drbg_init(HMAC_DRBG_CTX *ctx, const uint8_t *entropy, + size_t entropy_len, const uint8_t *nonce, + size_t nonce_len) { uint32_t h[SHA256_BLOCK_LENGTH / sizeof(uint32_t)]; // Precompute the inner digest and outer digest of K = 0x00 ... 0x00. @@ -103,7 +105,8 @@ void hmac_drbg_init(HMAC_DRBG_CTX *ctx, const uint8_t *entropy, size_t entropy_l memzero(h, sizeof(h)); } -void hmac_drbg_reseed(HMAC_DRBG_CTX *ctx, const uint8_t *entropy, size_t len, const uint8_t *addin, size_t addin_len) { +void hmac_drbg_reseed(HMAC_DRBG_CTX *ctx, const uint8_t *entropy, size_t len, + const uint8_t *addin, size_t addin_len) { update_k(ctx, 0, entropy, len, addin, addin_len); update_v(ctx); if (len == 0) return; diff --git a/crypto/hmac_drbg.h b/crypto/hmac_drbg.h index 32d3d6fdc..4b969dedb 100644 --- a/crypto/hmac_drbg.h +++ b/crypto/hmac_drbg.h @@ -34,8 +34,10 @@ typedef struct _HMAC_DRBG_CTX { uint32_t v[SHA256_BLOCK_LENGTH / sizeof(uint32_t)]; } HMAC_DRBG_CTX; -void hmac_drbg_init(HMAC_DRBG_CTX *ctx, const uint8_t *buf, size_t len, const uint8_t *nonce, size_t nonce_len); -void hmac_drbg_reseed(HMAC_DRBG_CTX *ctx, const uint8_t *buf, size_t len, const uint8_t *addin, size_t addin_len); +void hmac_drbg_init(HMAC_DRBG_CTX *ctx, const uint8_t *buf, size_t len, + const uint8_t *nonce, size_t nonce_len); +void hmac_drbg_reseed(HMAC_DRBG_CTX *ctx, const uint8_t *buf, size_t len, + const uint8_t *addin, size_t addin_len); void hmac_drbg_generate(HMAC_DRBG_CTX *ctx, uint8_t *buf, size_t len); #endif diff --git a/crypto/tests/test_check.c b/crypto/tests/test_check.c index 2080520b7..ff4256239 100644 --- a/crypto/tests/test_check.c +++ b/crypto/tests/test_check.c @@ -4641,13 +4641,15 @@ START_TEST(test_hmac_drbg) { uint8_t nonce_bytes[16]; memcpy(nonce_bytes, fromhex(nonce), sizeof(nonce_bytes)); HMAC_DRBG_CTX ctx; - hmac_drbg_init(&ctx, fromhex(entropy), strlen(entropy) / 2, nonce_bytes, strlen(nonce) / 2); + hmac_drbg_init(&ctx, fromhex(entropy), strlen(entropy) / 2, nonce_bytes, + strlen(nonce) / 2); hmac_drbg_reseed(&ctx, fromhex(reseed), strlen(reseed) / 2, NULL, 0); hmac_drbg_generate(&ctx, result, sizeof(result)); hmac_drbg_generate(&ctx, result, sizeof(result)); ck_assert_mem_eq(result, fromhex(expected), sizeof(result)); - hmac_drbg_init(&ctx, fromhex(entropy), strlen(entropy) / 2, nonce_bytes, strlen(nonce) / 2); + hmac_drbg_init(&ctx, fromhex(entropy), strlen(entropy) / 2, nonce_bytes, + strlen(nonce) / 2); hmac_drbg_reseed(&ctx, fromhex(reseed), strlen(reseed) / 2, NULL, 0); hmac_drbg_generate(&ctx, result, sizeof(result) - 13); hmac_drbg_generate(&ctx, result, sizeof(result) - 17);