summaryrefslogtreecommitdiff
path: root/sha512.c
diff options
context:
space:
mode:
authorNiels Möller <nisse@lysator.liu.se>2010-03-25 12:18:53 +0100
committerNiels Möller <nisse@lysator.liu.se>2010-03-25 12:18:53 +0100
commita8e38bdf161ecd67cecc30c255775ad261aaae9f (patch)
tree7e3c27729c3b9543f783b8d1ccc2300c24315193 /sha512.c
parenta43c646808f4a0f8982ce183cc984c6d5a96760d (diff)
downloadnettle-a8e38bdf161ecd67cecc30c255775ad261aaae9f.tar.gz
* Makefile.in (nettle_SOURCES): Added sha384-meta.c.
* sha384-meta.c: New file. * sha.h: Added declarations for sha384. Some are aliases for the corresponding sha512 definition. * sha512.c (sha512_write_digest): New function. (sha512_digest): Use it. (sha384_init): New function. (sha384_digest): New function. Rev: nettle/ChangeLog:1.59 Rev: nettle/Makefile.in:1.19 Rev: nettle/nettle-meta.h:1.4 Rev: nettle/sha.h:1.5 Rev: nettle/sha384-meta.c:1.1 Rev: nettle/sha512.c:1.4
Diffstat (limited to 'sha512.c')
-rw-r--r--sha512.c60
1 files changed, 54 insertions, 6 deletions
diff --git a/sha512.c b/sha512.c
index ec3c12fd..244ac805 100644
--- a/sha512.c
+++ b/sha512.c
@@ -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);
+}