Add SHA256_TransformBlocks.

Rather than expose a (potentially) assembly function directly, wrap it
in a C function to make visibility control easier.

Change-Id: I4a2dfeb8999ff021b2e10fbc54850eeadabbefff
Reviewed-on: https://boringssl-review.googlesource.com/27724
Commit-Queue: David Benjamin <davidben@google.com>
Reviewed-by: David Benjamin <davidben@google.com>
CQ-Verified: CQ bot account: commit-bot@chromium.org <commit-bot@chromium.org>
This commit is contained in:
Adam Langley 2018-04-25 10:30:02 -07:00 committed by CQ bot account: commit-bot@chromium.org
parent ec4f0ddafc
commit cece32610b
3 changed files with 30 additions and 0 deletions

View File

@ -258,3 +258,20 @@ TEST(DigestTest, ASN1) {
CBS_init(&cbs, kSHA256GarbageParam, sizeof(kSHA256GarbageParam)); CBS_init(&cbs, kSHA256GarbageParam, sizeof(kSHA256GarbageParam));
EXPECT_FALSE(EVP_parse_digest_algorithm(&cbs)); EXPECT_FALSE(EVP_parse_digest_algorithm(&cbs));
} }
TEST(DigestTest, TransformBlocks) {
uint8_t blocks[SHA256_CBLOCK * 10];
for (size_t i = 0; i < sizeof(blocks); i++) {
blocks[i] = i*3;
}
SHA256_CTX ctx1;
SHA256_Init(&ctx1);
SHA256_Update(&ctx1, blocks, sizeof(blocks));
SHA256_CTX ctx2;
SHA256_Init(&ctx2);
SHA256_TransformBlocks(ctx2.h, blocks, sizeof(blocks) / SHA256_CBLOCK);
EXPECT_TRUE(0 == OPENSSL_memcmp(ctx1.h, ctx2.h, sizeof(ctx1.h)));
}

View File

@ -316,6 +316,11 @@ static void sha256_block_data_order(uint32_t *state, const uint8_t *data,
#endif // !SHA256_ASM #endif // !SHA256_ASM
void SHA256_TransformBlocks(uint32_t state[8], const uint8_t *data,
size_t num_blocks) {
sha256_block_data_order(state, data, num_blocks);
}
#undef DATA_ORDER_IS_BIG_ENDIAN #undef DATA_ORDER_IS_BIG_ENDIAN
#undef HASH_CTX #undef HASH_CTX
#undef HASH_CBLOCK #undef HASH_CBLOCK

View File

@ -171,6 +171,14 @@ OPENSSL_EXPORT uint8_t *SHA256(const uint8_t *data, size_t len, uint8_t *out);
// from |block|. // from |block|.
OPENSSL_EXPORT void SHA256_Transform(SHA256_CTX *sha, const uint8_t *block); OPENSSL_EXPORT void SHA256_Transform(SHA256_CTX *sha, const uint8_t *block);
// SHA256_TransformBlocks is a low-level function that takes |num_blocks| *
// |SHA256_CBLOCK| bytes of data and performs SHA-256 transforms on it to update
// |state|. You should not use this function unless you are implementing a
// derivative of SHA-256.
OPENSSL_EXPORT void SHA256_TransformBlocks(uint32_t state[8],
const uint8_t *data,
size_t num_blocks);
struct sha256_state_st { struct sha256_state_st {
uint32_t h[8]; uint32_t h[8];
uint32_t Nl, Nh; uint32_t Nl, Nh;