crypto/hmac_drbg: Fix style.

pull/239/head
Andrew Kozlik 5 years ago
parent f677a0f0db
commit d95756ccf3

@ -20,8 +20,8 @@
* OTHER DEALINGS IN THE SOFTWARE. * OTHER DEALINGS IN THE SOFTWARE.
*/ */
#include <string.h>
#include "hmac_drbg.h" #include "hmac_drbg.h"
#include <string.h>
#include "memzero.h" #include "memzero.h"
#include "sha2.h" #include "sha2.h"
@ -83,7 +83,9 @@ static void update_v(HMAC_DRBG_CTX *ctx) {
sha256_Transform(ctx->odig, ctx->v, ctx->v); 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)]; uint32_t h[SHA256_BLOCK_LENGTH / sizeof(uint32_t)];
// Precompute the inner digest and outer digest of K = 0x00 ... 0x00. // 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)); 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_k(ctx, 0, entropy, len, addin, addin_len);
update_v(ctx); update_v(ctx);
if (len == 0) return; if (len == 0) return;

@ -34,8 +34,10 @@ typedef struct _HMAC_DRBG_CTX {
uint32_t v[SHA256_BLOCK_LENGTH / sizeof(uint32_t)]; uint32_t v[SHA256_BLOCK_LENGTH / sizeof(uint32_t)];
} HMAC_DRBG_CTX; } 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_init(HMAC_DRBG_CTX *ctx, const uint8_t *buf, size_t len,
void hmac_drbg_reseed(HMAC_DRBG_CTX *ctx, const uint8_t *buf, size_t len, const uint8_t *addin, size_t addin_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); void hmac_drbg_generate(HMAC_DRBG_CTX *ctx, uint8_t *buf, size_t len);
#endif #endif

@ -4641,13 +4641,15 @@ START_TEST(test_hmac_drbg) {
uint8_t nonce_bytes[16]; uint8_t nonce_bytes[16];
memcpy(nonce_bytes, fromhex(nonce), sizeof(nonce_bytes)); memcpy(nonce_bytes, fromhex(nonce), sizeof(nonce_bytes));
HMAC_DRBG_CTX ctx; 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_reseed(&ctx, fromhex(reseed), strlen(reseed) / 2, NULL, 0);
hmac_drbg_generate(&ctx, result, sizeof(result)); hmac_drbg_generate(&ctx, result, sizeof(result));
hmac_drbg_generate(&ctx, result, sizeof(result)); hmac_drbg_generate(&ctx, result, sizeof(result));
ck_assert_mem_eq(result, fromhex(expected), 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_reseed(&ctx, fromhex(reseed), strlen(reseed) / 2, NULL, 0);
hmac_drbg_generate(&ctx, result, sizeof(result) - 13); hmac_drbg_generate(&ctx, result, sizeof(result) - 13);
hmac_drbg_generate(&ctx, result, sizeof(result) - 17); hmac_drbg_generate(&ctx, result, sizeof(result) - 17);

Loading…
Cancel
Save