Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SHAKE Incremental Byte Squeezes && EVP_ Tests (#2155)
### Issues: Resolves #CryptoAlg-2835 && Resolves #CryptoAlg-2836 ### Description of changes: AWS-LC supports SHA3 and SHAKE algorithms. SHAKE, as defined in FIPS202, is an extendible output function, where the output data could be generated by multiple calls to "squeeze" function. Currently, there are two main features (internal and external APIs support) that are not supported by AWS-LC: - (Internal APIs) Currently, AWS-LC supports incremental XOF output (internal only via SHAKE_Squeeze) generation when the requested data is a multiple of the |block_size|. I.e., ceil(requested_output_bytes/block_size) full blocks will be generated and directly outputted without internal buffering. Thus, it is the user's (other algorithm) responsibility to manage output data when the request is not a multiple of the |block_size|. - Currently, AWS-LC does not support external (EVP_Digest) APIs for incremental squeezes. This PR add both features for incremental squeezes in arbitrary length output requests (up to a byte): - Internal APIs (SHAKE_) changes: - Add support for incremental |SHAKE_Squeeze| with arbitrary size (up to a byte) output requests via internal buffer. - Add KECCAK600_CTX struct |state| field updates and checks yo ensure functions are called only in the corresponding bitstate, e.g., |KECCAK1600_STATE_SQUEEZE| allows further bitstate squeezes, |KECCAK1600_STATE_FINAL| does not allow further squeezes, etc. - External APIs (EVP_Digest) changes: - Add external API support for incremental |SHAKE_Squeeze| with arbitrary size (up to a byte) output requests via |EVP_DigestSqueeze|. - Restrict the number of calls to |EVP_DigestFinalXOF| to only one. For incremental squeeze functionality |EVP_DigestSqueeze| should be used. - Restrict the use of |EVP_DigestFinal| to hash algorithms only. For XOF algorithms |EVP_DigestFinalXOF| and |EVP_DigestSqueeze| should be used. This PR adds more tests for EVP_Digest XOF functionality (all test are running through the entire NIST Test Vector list): - External APIs (EVP_Digest) additional tests: - Test Final - Assert fail when |EVP_DigestFinal| is called for XOF algorithms - Test Absorb - Assert success when |EVP_DigestUpdate| is called byte-by-byte - Test Squeeze - Assert success when |EVP_DigestSqueeze| is called byte-by-byte - Test Squeeze - Assert success when |EVP_DigestSqueeze| is called in set byte increments - Test Squeeze with random Input - Assert success when |EVP_DigestSqueeze| is called on a random message - Test Squeeze with random Input - Assert success when |EVP_DigestSqueeze| is called on a random message in set byte increments - Test Final XOF without Update - Assert fail when |EVP_DigestFinalXOF| is called as a streaming API ### Call-outs: Service indicator is updated: - Inside SHAKE_Squeeze (Streaming XOF Squeezes output generation **does not update** the service indicator after each extendable output update); ### Testing: _./crypto/crypto_test --gtest_filter="SHAKETest.*"_ By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license and the ISC license. --------- Co-authored-by: Jake Massimo <jakemas@amazon.com>
- Loading branch information