[libfko] enc key NULL checks with fko-wrapper test support
This commit is contained in:
@@ -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);
|
||||
|
||||
+7
-2
@@ -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)
|
||||
|
||||
@@ -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<FCN_CALLS; i++) {
|
||||
printf("fko_spa_data_final(ENC_KEY, 8, HMAC_KEY, 8): %s\n",
|
||||
printf("fko_spa_data_final(ENC_KEY, 16, HMAC_KEY, 16): %s\n",
|
||||
fko_errstr(fko_spa_data_final(ctx, ENC_KEY, 16, HMAC_KEY, 16)));
|
||||
ctx_update(&ctx, new_ctx_flag, destroy_ctx_flag, DO_PRINT);
|
||||
}
|
||||
@@ -233,6 +237,7 @@ static void ctx_update(fko_ctx_t *ctx, int new_ctx_flag,
|
||||
printf("fko_destroy(): %s\n", fko_errstr(fko_destroy(*ctx)));
|
||||
else
|
||||
fko_destroy(*ctx);
|
||||
spa_calls++;
|
||||
*ctx = NULL;
|
||||
}
|
||||
if (new_ctx_flag == NEW_CTX) {
|
||||
@@ -247,6 +252,7 @@ static void ctx_update(fko_ctx_t *ctx, int new_ctx_flag,
|
||||
printf("fko_new(): %s\n", fko_errstr(fko_new(ctx)));
|
||||
else
|
||||
fko_new(ctx);
|
||||
spa_calls += 2;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user