From: Niels Möller Date: Wed, 30 Oct 2024 09:20:34 +0000 (+0100) Subject: Revert changes to sha256.c X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1878ab724bb98eedf7bc03d722fc2d64e99e13dd;p=thirdparty%2Fnettle.git Revert changes to sha256.c --- diff --git a/sha2-internal.h b/sha2-internal.h index 58e99b22..93080bee 100644 --- a/sha2-internal.h +++ b/sha2-internal.h @@ -36,9 +36,6 @@ #include "nettle-types.h" -extern const uint32_t _nettle_sha224_iv[_SHA256_DIGEST_LENGTH]; -extern const uint32_t _nettle_sha256_iv[_SHA256_DIGEST_LENGTH]; - /* Internal compression function. STATE points to 8 uint32_t words, DATA points to 64 bytes of input data, possibly unaligned, and K points to the table of constants. */ diff --git a/sha256.c b/sha256.c index d2572947..a2a5d423 100644 --- a/sha256.c +++ b/sha256.c @@ -79,17 +79,19 @@ sha256_compress(uint32_t *state, const uint8_t *input) #define COMPRESS(ctx, data) (sha256_compress((ctx)->state, (data))) -/* Initial values, also generated by the shadata program. */ -const uint32_t _nettle_sha256_iv[_SHA256_DIGEST_LENGTH] = +/* Initialize the SHA values */ + +void +sha256_init(struct sha256_ctx *ctx) +{ + /* Initial values, also generated by the shadata program. */ + static const uint32_t H0[_SHA256_DIGEST_LENGTH] = { 0x6a09e667UL, 0xbb67ae85UL, 0x3c6ef372UL, 0xa54ff53aUL, 0x510e527fUL, 0x9b05688cUL, 0x1f83d9abUL, 0x5be0cd19UL, }; -void -sha256_init(struct sha256_ctx *ctx) -{ - memcpy(ctx->state, _nettle_sha256_iv, sizeof(ctx->state)); + memcpy(ctx->state, H0, sizeof(H0)); /* Initialize bit count */ ctx->count = 0; @@ -154,19 +156,19 @@ sha256_digest(struct sha256_ctx *ctx, sha256_init(ctx); } -/* SHA224 variant. */ +/* sha224 variant. */ -/* Initial values. Low 32 bits of the initial values for sha384. */ -const uint32_t _nettle_sha224_iv[_SHA256_DIGEST_LENGTH] = +void +sha224_init(struct sha256_ctx *ctx) +{ + /* Initial values. Low 32 bits of the initial values for sha384. */ + static const uint32_t H0[_SHA256_DIGEST_LENGTH] = { 0xc1059ed8, 0x367cd507, 0x3070dd17, 0xf70e5939, 0xffc00b31, 0x68581511, 0x64f98fa7, 0xbefa4fa4, }; -void -sha224_init(struct sha256_ctx *ctx) -{ - memcpy(ctx->state, _nettle_sha224_iv, sizeof(ctx->state)); + memcpy(ctx->state, H0, sizeof(H0)); /* Initialize bit count */ ctx->count = 0;