From 297d7d00fe4d6e6b6fd9aa3b8b1a042e1571bd2d Mon Sep 17 00:00:00 2001 From: Michael Rash Date: Sun, 29 Dec 2013 22:44:16 -0500 Subject: [PATCH] [libfko] enc key NULL checks with fko-wrapper test support --- lib/fko_encryption.c | 4 ++++ lib/fko_funcs.c | 9 +++++++-- test/fko-wrapper/fko_wrapper.c | 8 +++++++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/lib/fko_encryption.c b/lib/fko_encryption.c index 69b353fc..315ccd0e 100644 --- a/lib/fko_encryption.c +++ b/lib/fko_encryption.c @@ -580,7 +580,11 @@ fko_encrypt_spa_data(fko_ctx_t ctx, const char * const enc_key, /* Encrypt according to type and return... */ if(ctx->encryption_type == FKO_ENCRYPTION_RIJNDAEL) + { + if(enc_key == NULL) + return(FKO_ERROR_INVALID_KEY_LEN); res = _rijndael_encrypt(ctx, enc_key, enc_key_len); + } else if(ctx->encryption_type == FKO_ENCRYPTION_GPG) #if HAVE_LIBGPGME res = gpg_encrypt(ctx, enc_key); diff --git a/lib/fko_funcs.c b/lib/fko_funcs.c index afb9ff8e..f84b155c 100644 --- a/lib/fko_funcs.c +++ b/lib/fko_funcs.c @@ -188,6 +188,9 @@ fko_new_with_data(fko_ctx_t *r_ctx, const char * const enc_msg, if(enc_msg == NULL) return(FKO_ERROR_INVALID_DATA_FUNCS_NEW_ENCMSG_MISSING); + if(dec_key_len < 0 || hmac_key_len < 0) + return(FKO_ERROR_INVALID_KEY_LEN); + ctx = calloc(1, sizeof *ctx); if(ctx == NULL) return(FKO_ERROR_MEMORY_ALLOCATION); @@ -483,12 +486,14 @@ fko_spa_data_final(fko_ctx_t ctx, /* Now calculate hmac if so configured */ - if (res == FKO_SUCCESS && - ctx->hmac_type != FKO_HMAC_UNKNOWN && hmac_key != NULL) + if (res == FKO_SUCCESS && ctx->hmac_type != FKO_HMAC_UNKNOWN) { if(hmac_key_len < 0) return(FKO_ERROR_INVALID_KEY_LEN); + if(hmac_key == NULL) + return(FKO_ERROR_INVALID_KEY_LEN); + res = fko_set_spa_hmac(ctx, hmac_key, hmac_key_len); if (res == FKO_SUCCESS) diff --git a/test/fko-wrapper/fko_wrapper.c b/test/fko-wrapper/fko_wrapper.c index eac69bef..f81c1802 100644 --- a/test/fko-wrapper/fko_wrapper.c +++ b/test/fko-wrapper/fko_wrapper.c @@ -159,12 +159,16 @@ test_loop(int new_ctx_flag, int destroy_ctx_flag) for (i=-100; i < 200; i += 10) { for (j=-100; j < 200; j += 10) { fko_spa_data_final(ctx, ENC_KEY, i, HMAC_KEY, j); + fko_spa_data_final(ctx, NULL, i, HMAC_KEY, j); + fko_spa_data_final(ctx, ENC_KEY, i, NULL, j); + fko_spa_data_final(ctx, NULL, i, NULL, j); ctx_update(&ctx, new_ctx_flag, destroy_ctx_flag, NO_PRINT); + spa_calls += 4; } } for (i=0; i