Skip to content

Commit

Permalink
Add tests for XOF-specific functions squeeze and update called on non…
Browse files Browse the repository at this point in the history
… XOF digests to increase code coverage
  • Loading branch information
manastasova committed Feb 14, 2025
1 parent 41dbf6d commit 8114a9d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
6 changes: 3 additions & 3 deletions crypto/fipsmodule/digest/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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|.
Expand Down
8 changes: 8 additions & 0 deletions crypto/fipsmodule/sha/sha3_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 8114a9d

Please sign in to comment.