diff options
author | Andy Polyakov <appro@openssl.org> | 2017-08-10 22:39:40 +0200 |
---|---|---|
committer | Andy Polyakov <appro@openssl.org> | 2017-08-12 12:20:06 +0200 |
commit | cd8d1456c97ad17fb147f4fdcbb5ba8c983b8bb8 (patch) | |
tree | 44b5612ac04d4bae41080a982bc14623259f5744 /test/evp_test.c | |
parent | bbe9c3d51afa33d883abed3700d33c256afff46b (diff) | |
download | openssl-new-cd8d1456c97ad17fb147f4fdcbb5ba8c983b8bb8.tar.gz |
Add EVP_DigestFinalXOF, interface to extendable-output functions, XOFs.
Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/4137)
Diffstat (limited to 'test/evp_test.c')
-rw-r--r-- | test/evp_test.c | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/test/evp_test.c b/test/evp_test.c index 8fd082f30c..3875081c39 100644 --- a/test/evp_test.c +++ b/test/evp_test.c @@ -360,13 +360,18 @@ static int digest_test_run(EVP_TEST *t) { DIGEST_DATA *expected = t->data; EVP_MD_CTX *mctx; - unsigned char got[EVP_MAX_MD_SIZE]; + unsigned char *got = NULL; unsigned int got_len; t->err = "TEST_FAILURE"; if (!TEST_ptr(mctx = EVP_MD_CTX_new())) goto err; + got = OPENSSL_malloc(expected->output_len > EVP_MAX_MD_SIZE ? + expected->output_len : EVP_MAX_MD_SIZE); + if (!TEST_ptr(got)) + goto err; + if (!EVP_DigestInit_ex(mctx, expected->digest, NULL)) { t->err = "DIGESTINIT_ERROR"; goto err; @@ -376,9 +381,17 @@ static int digest_test_run(EVP_TEST *t) goto err; } - if (!EVP_DigestFinal(mctx, got, &got_len)) { - t->err = "DIGESTFINAL_ERROR"; - goto err; + if (EVP_MD_flags(expected->digest) & EVP_MD_FLAG_XOF) { + got_len = expected->output_len; + if (!EVP_DigestFinalXOF(mctx, got, got_len)) { + t->err = "DIGESTFINALXOF_ERROR"; + goto err; + } + } else { + if (!EVP_DigestFinal(mctx, got, &got_len)) { + t->err = "DIGESTFINAL_ERROR"; + goto err; + } } if (!TEST_int_eq(expected->output_len, got_len)) { t->err = "DIGEST_LENGTH_MISMATCH"; @@ -391,6 +404,7 @@ static int digest_test_run(EVP_TEST *t) t->err = NULL; err: + OPENSSL_free(got); EVP_MD_CTX_free(mctx); return 1; } |