2014-03-04 Niels Möller <nisse@lysator.liu.se>
+ * Makefile.in (nettle_SOURCES): Deleted chacha128-set-key.c and
+ chacha256-set-key.c.
+
+ * chacha.h (CHACHA256_KEY_SIZE): Deleted.
+ (chacha_set_key): Updated prototype.
+ * chacha256-set-key.c (chacha256_set_key): Deleted file and
+ function, moved to...
+ * chacha-set-key.c (chacha_set_key): Do 256-bit keys only. Deleted
+ length argument. Updated all callers.
+
* chacha128-set-key.c (chacha128_set_key): Deleted file and
function. Support for 128-bit chacha keys may be reintroduced
later, if really needed.
chacha-crypt.c chacha-core-internal.c \
chacha-poly1305.c chacha-poly1305-meta.c \
chacha-set-key.c chacha-set-nonce.c \
- chacha256-set-key.c \
ctr.c des.c des3.c des-compat.c \
eax.c eax-aes128.c eax-aes128-meta.c \
gcm.c gcm-aes.c \
chacha_poly1305_set_key (struct chacha_poly1305_ctx *ctx,
const uint8_t *key)
{
- chacha256_set_key (&ctx->chacha, key);
+ chacha_set_key (&ctx->chacha, key);
}
void
#include "chacha.h"
+#include "macros.h"
+
void
-chacha_set_key(struct chacha_ctx *ctx, size_t length, const uint8_t *key)
+chacha_set_key(struct chacha_ctx *ctx, const uint8_t *key)
{
- switch (length)
- {
- default:
- abort ();
- case CHACHA256_KEY_SIZE:
- chacha256_set_key (ctx, key);
- break;
- }
+ static const uint32_t sigma[4] = {
+ /* "expand 32-byte k" */
+ 0x61707865, 0x3320646e, 0x79622d32, 0x6b206574
+ };
+ ctx->state[4] = LE_READ_UINT32(key + 0);
+ ctx->state[5] = LE_READ_UINT32(key + 4);
+ ctx->state[6] = LE_READ_UINT32(key + 8);
+ ctx->state[7] = LE_READ_UINT32(key + 12);
+
+ ctx->state[8] = LE_READ_UINT32(key + 16);
+ ctx->state[9] = LE_READ_UINT32(key + 20);
+ ctx->state[10] = LE_READ_UINT32(key + 24);
+ ctx->state[11] = LE_READ_UINT32(key + 28);
+
+ memcpy (ctx->state, sigma, sizeof(sigma));
}
/* Name mangling */
#define chacha_set_key nettle_chacha_set_key
-#define chacha256_set_key nettle_chacha256_set_key
#define chacha_set_nonce nettle_chacha_set_nonce
#define chacha_crypt nettle_chacha_crypt
#define _chacha_core _nettle_chacha_core
-/* Possible keysizes, and a reasonable default. In octets. */
-#define CHACHA256_KEY_SIZE 32
+/* Currently, only 256-bit keys are supported. */
#define CHACHA_KEY_SIZE 32
-
#define CHACHA_BLOCK_SIZE 64
-
#define CHACHA_NONCE_SIZE 8
#define _CHACHA_STATE_LENGTH 16
};
void
-chacha256_set_key(struct chacha_ctx *ctx, const uint8_t *key);
-
-void
-chacha_set_key(struct chacha_ctx *ctx,
- size_t length, const uint8_t *key);
+chacha_set_key(struct chacha_ctx *ctx, const uint8_t *key);
void
chacha_set_nonce(struct chacha_ctx *ctx, const uint8_t *nonce);
+++ /dev/null
-/* chacha256-set-key.c
- *
- * ChaCha key setup for 256-bit keys.
- * Based on the Salsa20 implementation in Nettle.
- */
-
-/* nettle, low-level cryptographics library
- *
- * Copyright (C) 2013 Joachim Strömbergon
- * Copyright (C) 2012 Simon Josefsson
- * Copyright (C) 2012, 2014 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.
- */
-
-/* Based on:
- ChaCha specification (doc id: 4027b5256e17b9796842e6d0f68b0b5e) and reference
- implementation dated 2008.01.20
- D. J. Bernstein
- Public domain.
-*/
-
-#if HAVE_CONFIG_H
-# include "config.h"
-#endif
-
-#include <assert.h>
-#include <string.h>
-
-#include "chacha.h"
-
-#include "macros.h"
-
-void
-chacha256_set_key(struct chacha_ctx *ctx, const uint8_t *key)
-{
- static const uint32_t sigma[4] = {
- /* "expand 32-byte k" */
- 0x61707865, 0x3320646e, 0x79622d32, 0x6b206574
- };
- ctx->state[4] = LE_READ_UINT32(key + 0);
- ctx->state[5] = LE_READ_UINT32(key + 4);
- ctx->state[6] = LE_READ_UINT32(key + 8);
- ctx->state[7] = LE_READ_UINT32(key + 12);
-
- ctx->state[8] = LE_READ_UINT32(key + 16);
- ctx->state[9] = LE_READ_UINT32(key + 20);
- ctx->state[10] = LE_READ_UINT32(key + 24);
- ctx->state[11] = LE_READ_UINT32(key + 28);
-
- memcpy (ctx->state, sigma, sizeof(sigma));
-}
chacha_set_key_hack(void *ctx, const uint8_t *key)
{
static const uint8_t nonce[CHACHA_NONCE_SIZE];
- chacha256_set_key (ctx, key);
+ chacha_set_key (ctx, key);
chacha_set_nonce (ctx, nonce);
}
const struct nettle_cipher
nettle_chacha = {
"chacha", sizeof(struct chacha_ctx),
- 0, CHACHA256_KEY_SIZE,
+ 0, CHACHA_KEY_SIZE,
chacha_set_key_hack, chacha_set_key_hack,
(nettle_crypt_func *) chacha_crypt,
(nettle_crypt_func *) chacha_crypt
{
struct chacha_ctx ctx;
- chacha_set_key (&ctx, key->length, key->data);
+ ASSERT (key->length == CHACHA_KEY_SIZE);
+ chacha_set_key (&ctx, key->data);
ASSERT (nonce->length == CHACHA_NONCE_SIZE);
if (rounds == 20)