Commit 9cf94512 authored by Niels Möller's avatar Niels Möller

Added sha3 variants with other digest sizes.

parent aec8a13d
2012-12-30 Niels Möller <nisse@lysator.liu.se>
* sha3-224.c, sha3-224-meta.c: New files.
* sha3-384.c, sha3-384-meta.c: New files.
* sha3-512.c, sha3-512-meta.c: New files.
* sha3.h: Prototypes for sha3 with sizes 224, 384 and 512.
* nettle-meta.h: Declare nettle_sha3_224, nettle_sha3_384 and
nettle_sha3_512.
* Makefile.in (nettle_SOURCES): Added new sha3 files.
* testsuite/sha3-224-test.c: New file.
* testsuite/sha3-384-test.c: New file.
* testsuite/sha3-512-test.c: New file.
* testsuite/Makefile.in (TS_NETTLE_SOURCES): Added new sha3 test files.
* configure.ac: Disabled use of sha3-permute.asm.
2012-12-20 Niels Möller <nisse@lysator.liu.se>
......
......@@ -88,7 +88,9 @@ nettle_SOURCES = aes-decrypt-internal.c aes-decrypt.c \
sha1.c sha1-compress.c sha1-meta.c \
sha256.c sha256-compress.c sha224-meta.c sha256-meta.c \
sha512.c sha512-compress.c sha384-meta.c sha512-meta.c \
sha3.c sha3-permute.c sha3-256.c sha3-256-meta.c \
sha3.c sha3-permute.c \
sha3-224.c sha3-224-meta.c sha3-256.c sha3-256-meta.c \
sha3-384.c sha3-384-meta.c sha3-512.c sha3-512-meta.c\
serpent-set-key.c serpent-encrypt.c serpent-decrypt.c \
serpent-meta.c \
twofish.c twofish-meta.c \
......
......@@ -165,7 +165,10 @@ extern const struct nettle_hash nettle_sha224;
extern const struct nettle_hash nettle_sha256;
extern const struct nettle_hash nettle_sha384;
extern const struct nettle_hash nettle_sha512;
extern const struct nettle_hash nettle_sha3_224;
extern const struct nettle_hash nettle_sha3_256;
extern const struct nettle_hash nettle_sha3_384;
extern const struct nettle_hash nettle_sha3_512;
struct nettle_armor
{
......
/* sha3-224-meta.c */
/* nettle, low-level cryptographics library
*
* Copyright (C) 2012 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., 51 Franklin Street, Fifth Floor, Boston,
* MA 02111-1301, USA.
*/
#if HAVE_CONFIG_H
# include "config.h"
#endif
#include "nettle-meta.h"
#include "sha3.h"
const struct nettle_hash nettle_sha3_224
= _NETTLE_HASH(sha3_224, SHA3_224);
/* sha3-224.c
*
* The sha3 hash function, 224 bit output.
*/
/* nettle, low-level cryptographics library
*
* Copyright (C) 2012 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., 51 Franklin Street, Fifth Floor, Boston,
* MA 02111-1301, USA.
*/
#if HAVE_CONFIG_H
# include "config.h"
#endif
#include <stddef.h>
#include <string.h>
#include "sha3.h"
#include "nettle-write.h"
void
sha3_224_init (struct sha3_224_ctx *ctx)
{
memset (&ctx->state, 0, offsetof (struct sha3_224_ctx, block));
}
void
sha3_224_update (struct sha3_224_ctx *ctx,
unsigned length,
const uint8_t *data)
{
ctx->index = _sha3_update (&ctx->state, SHA3_224_DATA_SIZE, ctx->block,
ctx->index, length, data);
}
void
sha3_224_digest(struct sha3_224_ctx *ctx,
unsigned length,
uint8_t *digest)
{
_sha3_pad (&ctx->state, SHA3_224_DATA_SIZE, ctx->block, ctx->index);
_nettle_write_le64 (length, digest, ctx->state.a);
sha3_224_init (ctx);
}
/* sha3-384-meta.c */
/* nettle, low-level cryptographics library
*
* Copyright (C) 2012 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., 51 Franklin Street, Fifth Floor, Boston,
* MA 02111-1301, USA.
*/
#if HAVE_CONFIG_H
# include "config.h"
#endif
#include "nettle-meta.h"
#include "sha3.h"
const struct nettle_hash nettle_sha3_384
= _NETTLE_HASH(sha3_384, SHA3_384);
/* sha3-384.c
*
* The sha3 hash function, 384 bit output.
*/
/* nettle, low-level cryptographics library
*
* Copyright (C) 2012 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., 51 Franklin Street, Fifth Floor, Boston,
* MA 02111-1301, USA.
*/
#if HAVE_CONFIG_H
# include "config.h"
#endif
#include <stddef.h>
#include <string.h>
#include "sha3.h"
#include "nettle-write.h"
void
sha3_384_init (struct sha3_384_ctx *ctx)
{
memset (&ctx->state, 0, offsetof (struct sha3_384_ctx, block));
}
void
sha3_384_update (struct sha3_384_ctx *ctx,
unsigned length,
const uint8_t *data)
{
ctx->index = _sha3_update (&ctx->state, SHA3_384_DATA_SIZE, ctx->block,
ctx->index, length, data);
}
void
sha3_384_digest(struct sha3_384_ctx *ctx,
unsigned length,
uint8_t *digest)
{
_sha3_pad (&ctx->state, SHA3_384_DATA_SIZE, ctx->block, ctx->index);
_nettle_write_le64 (length, digest, ctx->state.a);
sha3_384_init (ctx);
}
/* sha3-512-meta.c */
/* nettle, low-level cryptographics library
*
* Copyright (C) 2012 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., 51 Franklin Street, Fifth Floor, Boston,
* MA 02111-1301, USA.
*/
#if HAVE_CONFIG_H
# include "config.h"
#endif
#include "nettle-meta.h"
#include "sha3.h"
const struct nettle_hash nettle_sha3_512
= _NETTLE_HASH(sha3_512, SHA3_512);
/* sha3-512.c
*
* The sha3 hash function, 512 bit output.
*/
/* nettle, low-level cryptographics library
*
* Copyright (C) 2012 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., 51 Franklin Street, Fifth Floor, Boston,
* MA 02111-1301, USA.
*/
#if HAVE_CONFIG_H
# include "config.h"
#endif
#include <stddef.h>
#include <string.h>
#include "sha3.h"
#include "nettle-write.h"
void
sha3_512_init (struct sha3_512_ctx *ctx)
{
memset (&ctx->state, 0, offsetof (struct sha3_512_ctx, block));
}
void
sha3_512_update (struct sha3_512_ctx *ctx,
unsigned length,
const uint8_t *data)
{
ctx->index = _sha3_update (&ctx->state, SHA3_512_DATA_SIZE, ctx->block,
ctx->index, length, data);
}
void
sha3_512_digest(struct sha3_512_ctx *ctx,
unsigned length,
uint8_t *digest)
{
_sha3_pad (&ctx->state, SHA3_512_DATA_SIZE, ctx->block, ctx->index);
_nettle_write_le64 (length, digest, ctx->state.a);
sha3_512_init (ctx);
}
......@@ -35,9 +35,18 @@ extern "C" {
#define sha3_permute nettle_sha3_permute
#define _sha3_update _nettle_sha3_update
#define _sha3_pad _nettle_sha3_pad
#define sha3_224_init nettle_sha3_224_init
#define sha3_224_update nettle_sha3_224_update
#define sha3_224_digest nettle_sha3_224_digest
#define sha3_256_init nettle_sha3_256_init
#define sha3_256_update nettle_sha3_256_update
#define sha3_256_digest nettle_sha3_256_digest
#define sha3_384_init nettle_sha3_384_init
#define sha3_384_update nettle_sha3_384_update
#define sha3_384_digest nettle_sha3_384_digest
#define sha3_512_init nettle_sha3_512_init
#define sha3_512_update nettle_sha3_512_update
#define sha3_512_digest nettle_sha3_512_digest
/* The sha3 state is a 5x5 matrix of 64-bit words. In the notation of
Keccak description, S[x,y] is element x + 5*y, so if x is
......@@ -87,6 +96,19 @@ struct sha3_224_ctx
uint8_t block[SHA3_224_DATA_SIZE];
};
void
sha3_224_init (struct sha3_224_ctx *ctx);
void
sha3_224_update (struct sha3_224_ctx *ctx,
unsigned length,
const uint8_t *data);
void
sha3_224_digest(struct sha3_224_ctx *ctx,
unsigned length,
uint8_t *digest);
struct sha3_256_ctx
{
struct sha3_state state;
......@@ -114,6 +136,19 @@ struct sha3_384_ctx
uint8_t block[SHA3_384_DATA_SIZE];
};
void
sha3_384_init (struct sha3_384_ctx *ctx);
void
sha3_384_update (struct sha3_384_ctx *ctx,
unsigned length,
const uint8_t *data);
void
sha3_384_digest(struct sha3_384_ctx *ctx,
unsigned length,
uint8_t *digest);
struct sha3_512_ctx
{
struct sha3_state state;
......@@ -121,6 +156,19 @@ struct sha3_512_ctx
uint8_t block[SHA3_512_DATA_SIZE];
};
void
sha3_512_init (struct sha3_512_ctx *ctx);
void
sha3_512_update (struct sha3_512_ctx *ctx,
unsigned length,
const uint8_t *data);
void
sha3_512_digest(struct sha3_512_ctx *ctx,
unsigned length,
uint8_t *digest);
#ifdef __cplusplus
}
#endif
......
......@@ -73,9 +73,18 @@ sha512-test$(EXEEXT): sha512-test.$(OBJEXT)
sha3-permute-test$(EXEEXT): sha3-permute-test.$(OBJEXT)
$(LINK) sha3-permute-test.$(OBJEXT) $(TEST_OBJS) -o sha3-permute-test$(EXEEXT)
sha3-224-test$(EXEEXT): sha3-224-test.$(OBJEXT)
$(LINK) sha3-224-test.$(OBJEXT) $(TEST_OBJS) -o sha3-224-test$(EXEEXT)
sha3-256-test$(EXEEXT): sha3-256-test.$(OBJEXT)
$(LINK) sha3-256-test.$(OBJEXT) $(TEST_OBJS) -o sha3-256-test$(EXEEXT)
sha3-384-test$(EXEEXT): sha3-384-test.$(OBJEXT)
$(LINK) sha3-384-test.$(OBJEXT) $(TEST_OBJS) -o sha3-384-test$(EXEEXT)
sha3-512-test$(EXEEXT): sha3-512-test.$(OBJEXT)
$(LINK) sha3-512-test.$(OBJEXT) $(TEST_OBJS) -o sha3-512-test$(EXEEXT)
serpent-test$(EXEEXT): serpent-test.$(OBJEXT)
$(LINK) serpent-test.$(OBJEXT) $(TEST_OBJS) -o serpent-test$(EXEEXT)
......
......@@ -21,7 +21,8 @@ TS_NETTLE_SOURCES = aes-test.c arcfour-test.c arctwo-test.c \
salsa20-test.c \
sha1-test.c sha224-test.c sha256-test.c \
sha384-test.c sha512-test.c \
sha3-permute-test.c sha3-256-test.c \
sha3-permute-test.c sha3-224-test.c sha3-256-test.c \
sha3-384-test.c sha3-512-test.c \
serpent-test.c twofish-test.c \
knuth-lfib-test.c \
cbc-test.c ctr-test.c gcm-test.c hmac-test.c \
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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