X-Git-Url: https://git.openssl.org/?a=blobdiff_plain;f=test%2Fhmactest.c;h=2ceec5fa6d9bfaaf6bd4e1ef662901be3bbb291f;hb=0b2fc9286f84d12f2f103b0d29c9e6e1e2a6bf87;hp=fc168de581622c575656be4281c3edfce73954b3;hpb=eda34e4bef33a3b8f1e207bf04769007c70cbd1e;p=openssl.git diff --git a/test/hmactest.c b/test/hmactest.c index fc168de581..2ceec5fa6d 100644 --- a/test/hmactest.c +++ b/test/hmactest.c @@ -1,4 +1,3 @@ -/* crypto/hmac/hmactest.c */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -63,6 +62,7 @@ #include "../e_os.h" # include +# include # ifndef OPENSSL_NO_MD5 # include # endif @@ -193,7 +193,16 @@ int main(int argc, char *argv[]) } printf("test 4 ok\n"); test5: - HMAC_CTX_init(ctx); + /* Test 5 has empty key; test that single-shot accepts a NULL key. */ + p = pt(HMAC(EVP_sha1(), NULL, 0, test[4].data, test[4].data_len, + NULL, NULL), SHA_DIGEST_LENGTH); + if (strcmp(p, (char *)test[4].digest) != 0) { + printf("Error calculating HMAC on %d entry'\n", i); + printf("got %s instead of %s\n", p, test[4].digest); + err++; + } + + HMAC_CTX_reset(ctx); if (HMAC_Init_ex(ctx, test[4].key, test[4].key_len, NULL, NULL)) { printf("Should fail to initialise HMAC with empty MD (test 5)\n"); err++; @@ -236,7 +245,7 @@ test5: err++; goto test6; } - if (!HMAC_Init_ex(ctx, test[4].key, test[4].key_len, EVP_sha256(), NULL)) { + if (!HMAC_Init_ex(ctx, test[5].key, test[5].key_len, EVP_sha256(), NULL)) { printf("Failed to reinitialise HMAC (test 5)\n"); err++; goto test6; @@ -282,7 +291,7 @@ test5: printf("test 5 ok\n"); } test6: - HMAC_CTX_init(ctx); + HMAC_CTX_reset(ctx); ctx2 = HMAC_CTX_new(); if (ctx2 == NULL) { printf("HMAC malloc failure (test 6)\n");