diff options
Diffstat (limited to 'sha512.c')
-rw-r--r-- | sha512.c | 60 |
1 files changed, 54 insertions, 6 deletions
@@ -216,17 +216,15 @@ sha512_final(struct sha512_ctx *ctx) _nettle_sha512_compress(ctx->state, ctx->block, K); } -void -sha512_digest(struct sha512_ctx *ctx, - unsigned length, - uint8_t *digest) +static void +sha512_write_digest(struct sha512_ctx *ctx, + unsigned length, + uint8_t *digest) { unsigned i; unsigned words; unsigned leftover; - assert(length <= SHA512_DIGEST_SIZE); - sha512_final(ctx); words = length / 8; @@ -245,6 +243,56 @@ sha512_digest(struct sha512_ctx *ctx, word >>= 8; } while (leftover); } +} +void +sha512_digest(struct sha512_ctx *ctx, + unsigned length, + uint8_t *digest) +{ + assert(length <= SHA512_DIGEST_SIZE); + + sha512_write_digest(ctx, length, digest); sha512_init(ctx); } + +/* sha384 variant. FIXME: Move to separate file? */ +void +sha384_init(struct sha512_ctx *ctx) +{ + /* Initial values, generated by the gp script + { + for (i = 9,16, + root = prime(i)^(1/2); + fraction = root - floor(root); + print(floor(2^64 * fraction)); + ); + } +. */ + static const uint64_t H0[_SHA512_DIGEST_LENGTH] = + { + 0xCBBB9D5DC1059ED8ULL, 0x629A292A367CD507ULL, + 0x9159015A3070DD17ULL, 0x152FECD8F70E5939ULL, + 0x67332667FFC00B31ULL, 0x8EB44A8768581511ULL, + 0xDB0C2E0D64F98FA7ULL, 0x47B5481DBEFA4FA4ULL, + }; + + memcpy(ctx->state, H0, sizeof(H0)); + + /* Initialize bit count */ + ctx->count_low = ctx->count_high = 0; + + /* Initialize buffer */ + ctx->index = 0; +} + +void +sha384_digest(struct sha512_ctx *ctx, + unsigned length, + uint8_t *digest) +{ + assert(length <= SHA384_DIGEST_SIZE); + + sha512_write_digest(ctx, length, digest); + sha384_init(ctx); +} |