Skip to content

Commit 184d29d

Browse files
ifranzkit8m
authored andcommitted
speed: Fix regression of measuring shake with -evp
After commit b911fef speed with shake128 or shake256 does not run anymore: # openssl speed -seconds 1 -evp shake128 -bytes 256 Doing shake128 ops for 1s on 256 size blocks: shake128 error! 000003FF9B7F2080:error:1C8000A6:Provider routines:keccak_final:invalid digest length:providers/implementations/digests/sha3_prov.c:117: version: 3.4.0-dev ... type 256 bytes shake128 0.00 Function EVP_Digest_loop() must use EVP_DigestInit_ex2(), EVP_DigestUpdate(), and EVP_DigestFinalXOF() in case of shake instead of just EVP_Digest() to get around this. Signed-off-by: Ingo Franzki <[email protected]> Reviewed-by: Paul Dale <[email protected]> Reviewed-by: Tomas Mraz <[email protected]> (Merged from openssl#24462)
1 parent 05faa4f commit 184d29d

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

apps/speed.c

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -613,17 +613,37 @@ static int EVP_Digest_loop(const char *mdname, ossl_unused int algindex, void *a
613613
unsigned char digest[EVP_MAX_MD_SIZE];
614614
int count;
615615
EVP_MD *md = NULL;
616+
EVP_MD_CTX *ctx = NULL;
616617

617618
if (!opt_md_silent(mdname, &md))
618619
return -1;
619-
for (count = 0; COND(c[algindex][testnum]); count++) {
620-
if (!EVP_Digest(buf, (size_t)lengths[testnum], digest, NULL, md,
621-
NULL)) {
620+
if (EVP_MD_get_flags(md) & EVP_MD_FLAG_XOF) {
621+
ctx = EVP_MD_CTX_new();
622+
if (ctx == NULL) {
622623
count = -1;
623-
break;
624+
goto out;
625+
}
626+
627+
for (count = 0; COND(c[algindex][testnum]); count++) {
628+
if (!EVP_DigestInit_ex2(ctx, md, NULL)
629+
|| !EVP_DigestUpdate(ctx, buf, (size_t)lengths[testnum])
630+
|| !EVP_DigestFinalXOF(ctx, digest, sizeof(digest))) {
631+
count = -1;
632+
break;
633+
}
634+
}
635+
} else {
636+
for (count = 0; COND(c[algindex][testnum]); count++) {
637+
if (!EVP_Digest(buf, (size_t)lengths[testnum], digest, NULL, md,
638+
NULL)) {
639+
count = -1;
640+
break;
641+
}
624642
}
625643
}
644+
out:
626645
EVP_MD_free(md);
646+
EVP_MD_CTX_free(ctx);
627647
return count;
628648
}
629649

0 commit comments

Comments
 (0)