Commit a8e38bdf authored by Niels Möller's avatar Niels Möller

* 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
parent a43c6468
2010-03-25 Niels Mller <nisse@lysator.liu.se>
* 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.
2010-03-24 Niels Mller <nisse@lysator.liu.se>
* sha512.c: (sha512_digest): Simplified handling of any final
......
......@@ -65,7 +65,7 @@ nettle_SOURCES = aes-decrypt-internal.c aes-decrypt.c \
md2.c md2-meta.c md4.c md4-meta.c \
md5.c md5-compress.c md5-compat.c md5-meta.c \
sha1.c sha1-compress.c sha1-meta.c sha256.c sha256-compress.c sha256-meta.c \
sha512.c sha512-compress.c sha512-meta.c \
sha512.c sha512-compress.c sha384-meta.c sha512-meta.c \
serpent.c serpent-meta.c \
twofish.c twofish-meta.c \
yarrow256.c yarrow_key_event.c \
......
......@@ -138,6 +138,7 @@ extern const struct nettle_hash nettle_md4;
extern const struct nettle_hash nettle_md5;
extern const struct nettle_hash nettle_sha1;
extern const struct nettle_hash nettle_sha256;
extern const struct nettle_hash nettle_sha384;
extern const struct nettle_hash nettle_sha512;
struct nettle_armor
......
......@@ -39,6 +39,8 @@ extern "C" {
#define sha256_init nettle_sha256_init
#define sha256_update nettle_sha256_update
#define sha256_digest nettle_sha256_digest
#define sha384_init nettle_sha384_init
#define sha384_digest nettle_sha384_digest
#define sha512_init nettle_sha512_init
#define sha512_update nettle_sha512_update
#define sha512_digest nettle_sha512_digest
......@@ -147,6 +149,24 @@ sha512_digest(struct sha512_ctx *ctx,
void
_nettle_sha512_compress(uint64_t *state, const uint8_t *data, const uint64_t *k);
/* SHA384. */
/* This is the same algorithm as SHA512, but with different initial
state and truncated output. */
#define SHA384_DIGEST_SIZE 48
#define SHA384_DATA_SIZE SHA512_DATA_SIZE
#define sha384_ctx sha512_ctx
void
sha384_init(struct sha512_ctx *ctx);
#define sha384_update nettle_sha512_update
void
sha384_digest(struct sha512_ctx *ctx,
unsigned length,
uint8_t *digest);
#ifdef __cplusplus
}
#endif
......
/* sha384-meta.c */
/* nettle, low-level cryptographics library
*
* Copyright (C) 2002, 2010 Niels Möller
*
* The nettle library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
*
* The nettle library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the nettle library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
* MA 02111-1307, USA.
*/
#if HAVE_CONFIG_H
# include "config.h"
#endif
#include "nettle-meta.h"
#include "sha.h"
const struct nettle_hash nettle_sha384
= _NETTLE_HASH(sha384, SHA384);
......@@ -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);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment