From 8114a9d6dffab29899096840c0ab2163e9f2cc7f Mon Sep 17 00:00:00 2001 From: manastasova Date: Fri, 14 Feb 2025 17:56:32 +0000 Subject: [PATCH] Add tests for XOF-specific functions squeeze and update called on non XOF digests to increase code coverage --- crypto/fipsmodule/digest/internal.h | 6 +++--- crypto/fipsmodule/sha/sha3_test.cc | 8 ++++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/crypto/fipsmodule/digest/internal.h b/crypto/fipsmodule/digest/internal.h index 07dad9940f..b06359a9f0 100644 --- a/crypto/fipsmodule/digest/internal.h +++ b/crypto/fipsmodule/digest/internal.h @@ -80,9 +80,9 @@ struct env_md_st { // update hashes |len| bytes of |data| into the state in |ctx->md_data|. // Digest update functions always return 1. update calls after |final| are - // restricted via |ctx| check (|final| cleanses the |ctx|). Digest XOF update - // function propagates the return value from |SHAKE_Absorb|, that is 1 on - // success and 0 on failure, to restrict update calls after |squeezeXOF|. + // restricted via |ctx| check (|final| cleanses the |ctx|). Returns 1 + // on success and 0 on failure. Failures can only occur on a + // digest XOF update if called after |squeezeXOF| or |finalXOF|. int (*update)(EVP_MD_CTX *ctx, const void *data, size_t count); // final completes the hash and writes |md_size| bytes of digest to |out|. diff --git a/crypto/fipsmodule/sha/sha3_test.cc b/crypto/fipsmodule/sha/sha3_test.cc index d4f4d8da02..e6c874e1f4 100644 --- a/crypto/fipsmodule/sha/sha3_test.cc +++ b/crypto/fipsmodule/sha/sha3_test.cc @@ -74,6 +74,14 @@ class SHA3TestVector { ASSERT_EQ(Bytes(digest.get(), EVP_MD_size(algorithm)), Bytes(digest_.data(), EVP_MD_size(algorithm))); + + // Test XOF-specific Digest functions with non XOF algorithms + // Assert failure when |EVP_DigestSqueeze| or |EVP_DigestFinalXOF| + // are called with digests different from XOF digests + ASSERT_TRUE(EVP_DigestInit(ctx.get(), algorithm)); + ASSERT_TRUE(EVP_DigestUpdate(ctx.get(), msg_.data(), msg_.size())); + ASSERT_FALSE(EVP_DigestSqueeze(ctx.get(), digest.get(), digest_length)); + ASSERT_FALSE(EVP_DigestFinalXOF(ctx.get(), digest.get(), digest_length)); } void NISTTestVectors_SingleShot(const EVP_MD *algorithm) const {