--- /dev/null
+C arm/fat/chacha-3core.asm
+
+
+ifelse(<
+ Copyright (C) 2020 Niels Möller
+
+ This file is part of GNU Nettle.
+
+ GNU Nettle is free software: you can redistribute it and/or
+ modify it under the terms of either:
+
+ * the GNU Lesser General Public License as published by the Free
+ Software Foundation; either version 3 of the License, or (at your
+ option) any later version.
+
+ or
+
+ * the GNU General Public License as published by the Free
+ Software Foundation; either version 2 of the License, or (at your
+ option) any later version.
+
+ or both in parallel, as here.
+
+ GNU Nettle 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
+ General Public License for more details.
+
+ You should have received copies of the GNU General Public License and
+ the GNU Lesser General Public License along with this program. If
+ not, see http://www.gnu.org/licenses/.
+>)
+
+dnl PROLOGUE(_nettle_fat_chacha_3core) picked up by configure
+
+include_src(<arm/neon/chacha-3core.asm>)
#define CHACHA_ROUNDS 20
#if HAVE_NATIVE_chacha_3core
+#undef _chacha_crypt_3core
+#undef _chacha_crypt32_3core
+#define _chacha_crypt_3core chacha_crypt
+#define _chacha_crypt32_3core chacha_crypt32
+#elif !HAVE_NATIVE_fat_chacha_3core
+#undef _chacha_crypt_1core
+#undef _chacha_crypt32_1core
+#define _chacha_crypt_1core chacha_crypt
+#define _chacha_crypt32_1core chacha_crypt32
+#endif
+
+#if HAVE_NATIVE_chacha_3core || HAVE_NATIVE_fat_chacha_3core
void
-chacha_crypt(struct chacha_ctx *ctx,
- size_t length,
- uint8_t *dst,
- const uint8_t *src)
+_chacha_crypt_3core(struct chacha_ctx *ctx,
+ size_t length,
+ uint8_t *dst,
+ const uint8_t *src)
{
uint32_t x[3*_CHACHA_STATE_LENGTH];
}
memxor3 (dst, src, x, length);
}
-#else
+#endif
+
+#if !HAVE_NATIVE_chacha_3core
void
-chacha_crypt(struct chacha_ctx *ctx,
- size_t length,
- uint8_t *c,
- const uint8_t *m)
+_chacha_crypt_1core(struct chacha_ctx *ctx,
+ size_t length,
+ uint8_t *dst,
+ const uint8_t *src)
{
if (!length)
return;
if (length <= CHACHA_BLOCK_SIZE)
{
- memxor3 (c, m, x, length);
+ memxor3 (dst, src, x, length);
return;
}
- memxor3 (c, m, x, CHACHA_BLOCK_SIZE);
+ memxor3 (dst, src, x, CHACHA_BLOCK_SIZE);
length -= CHACHA_BLOCK_SIZE;
- c += CHACHA_BLOCK_SIZE;
- m += CHACHA_BLOCK_SIZE;
+ dst += CHACHA_BLOCK_SIZE;
+ src += CHACHA_BLOCK_SIZE;
}
}
#endif
+#if HAVE_NATIVE_chacha_3core || HAVE_NATIVE_fat_chacha_3core
void
-chacha_crypt32(struct chacha_ctx *ctx,
- size_t length,
- uint8_t *c,
- const uint8_t *m)
+_chacha_crypt32_3core(struct chacha_ctx *ctx,
+ size_t length,
+ uint8_t *dst,
+ const uint8_t *src)
+{
+ uint32_t x[3*_CHACHA_STATE_LENGTH];
+
+ if (!length)
+ return;
+
+ while (length > 2*CHACHA_BLOCK_SIZE)
+ {
+ _chacha_3core32 (x, ctx->state, CHACHA_ROUNDS);
+ ctx->state[12] += 3;
+ ctx->state[13] += (ctx->state[12] < 3);
+ if (length <= 3*CHACHA_BLOCK_SIZE)
+ {
+ memxor3 (dst, src, x, length);
+ return;
+ }
+ memxor3 (dst, src, x, 3*CHACHA_BLOCK_SIZE);
+
+ length -= 3*CHACHA_BLOCK_SIZE;
+ dst += 3*CHACHA_BLOCK_SIZE;
+ src += 3*CHACHA_BLOCK_SIZE;
+ }
+ if (length <= CHACHA_BLOCK_SIZE)
+ {
+ _chacha_core (x, ctx->state, CHACHA_ROUNDS);
+ ctx->state[13] += (++ctx->state[12] == 0);
+ }
+ else
+ {
+ _chacha_3core32 (x, ctx->state, CHACHA_ROUNDS);
+ ctx->state[12] += 2;
+ ctx->state[13] += (ctx->state[12] < 2);
+ }
+ memxor3 (dst, src, x, length);
+}
+#endif
+
+#if !HAVE_NATIVE_chacha_3core
+void
+_chacha_crypt32_1core(struct chacha_ctx *ctx,
+ size_t length,
+ uint8_t *dst,
+ const uint8_t *src)
{
if (!length)
return;
if (length <= CHACHA_BLOCK_SIZE)
{
- memxor3 (c, m, x, length);
+ memxor3 (dst, src, x, length);
return;
}
- memxor3 (c, m, x, CHACHA_BLOCK_SIZE);
+ memxor3 (dst, src, x, CHACHA_BLOCK_SIZE);
length -= CHACHA_BLOCK_SIZE;
- c += CHACHA_BLOCK_SIZE;
- m += CHACHA_BLOCK_SIZE;
+ dst += CHACHA_BLOCK_SIZE;
+ src += CHACHA_BLOCK_SIZE;
}
}
+#endif
#define NETTLE_CHACHA_INTERNAL_H_INCLUDED
#include "nettle-types.h"
+#include "chacha.h"
#define _chacha_core _nettle_chacha_core
#define _chacha_3core _nettle_chacha_3core
+#define _chacha_3core32 _nettle_chacha_3core32
+#define _chacha_crypt_1core _nettle_chacha_crypt_1core
+#define _chacha_crypt_3core _nettle_chacha_crypt_3core
+#define _chacha_crypt32_1core _nettle_chacha_crypt32_1core
+#define _chacha_crypt32_3core _nettle_chacha_crypt32_3core
void
_chacha_core(uint32_t *dst, const uint32_t *src, unsigned rounds);
void
_chacha_3core(uint32_t *dst, const uint32_t *src, unsigned rounds);
+void
+_chacha_3core32(uint32_t *dst, const uint32_t *src, unsigned rounds);
+
+void
+_chacha_crypt_1core(struct chacha_ctx *ctx,
+ size_t length,
+ uint8_t *dst,
+ const uint8_t *src);
+
+void
+_chacha_crypt_3core(struct chacha_ctx *ctx,
+ size_t length,
+ uint8_t *dst,
+ const uint8_t *src);
+
+void
+_chacha_crypt32_1core(struct chacha_ctx *ctx,
+ size_t length,
+ uint8_t *dst,
+ const uint8_t *src);
+
+void
+_chacha_crypt32_3core(struct chacha_ctx *ctx,
+ size_t length,
+ uint8_t *dst,
+ const uint8_t *src);
+
#endif /* NETTLE_CHACHA_INTERNAL_H_INCLUDED */
implementation of the corresponding routine exists. */
#undef HAVE_NATIVE_chacha_core
#undef HAVE_NATIVE_chacha_3core
+#undef HAVE_NATIVE_fat_chacha_3core
#undef HAVE_NATIVE_ecc_curve25519_modp
#undef HAVE_NATIVE_ecc_curve448_modp
#undef HAVE_NATIVE_ecc_secp192r1_modp
#include "nettle-types.h"
#include "aes-internal.h"
+#include "chacha-internal.h"
#include "salsa20-internal.h"
#include "fat-setup.h"
DECLARE_FAT_FUNC_VAR(chacha_core, chacha_core_func, c);
DECLARE_FAT_FUNC_VAR(chacha_core, chacha_core_func, neon);
+DECLARE_FAT_FUNC(nettle_chacha_crypt, chacha_crypt_func)
+DECLARE_FAT_FUNC_VAR(chacha_crypt, chacha_crypt_func, 1core)
+DECLARE_FAT_FUNC_VAR(chacha_crypt, chacha_crypt_func, 3core)
+
+DECLARE_FAT_FUNC(nettle_chacha_crypt32, chacha_crypt_func)
+DECLARE_FAT_FUNC_VAR(chacha_crypt32, chacha_crypt_func, 1core)
+DECLARE_FAT_FUNC_VAR(chacha_crypt32, chacha_crypt_func, 3core)
+
static void CONSTRUCTOR
fat_init (void)
{
_nettle_umac_nh_vec = _nettle_umac_nh_neon;
_nettle_umac_nh_n_vec = _nettle_umac_nh_n_neon;
_nettle_chacha_core_vec = _nettle_chacha_core_neon;
+ nettle_chacha_crypt_vec = _nettle_chacha_crypt_3core;
+ nettle_chacha_crypt32_vec = _nettle_chacha_crypt32_3core;
}
else
{
_nettle_umac_nh_vec = _nettle_umac_nh_c;
_nettle_umac_nh_n_vec = _nettle_umac_nh_n_c;
_nettle_chacha_core_vec = _nettle_chacha_core_c;
+ nettle_chacha_crypt_vec = _nettle_chacha_crypt_1core;
+ nettle_chacha_crypt32_vec = _nettle_chacha_crypt32_1core;
}
}
(uint32_t *dst, const uint32_t *src, unsigned rounds),
(dst, src, rounds))
+DEFINE_FAT_FUNC(nettle_chacha_crypt, void,
+ (struct chacha_ctx *ctx,
+ size_t length,
+ uint8_t *dst,
+ const uint8_t *src),
+ (ctx, length, dst, src))
+
+DEFINE_FAT_FUNC(nettle_chacha_crypt32, void,
+ (struct chacha_ctx *ctx,
+ size_t length,
+ uint8_t *dst,
+ const uint8_t *src),
+ (ctx, length, dst, src))
#define ENV_VERBOSE "NETTLE_FAT_VERBOSE"
#define ENV_OVERRIDE "NETTLE_FAT_OVERRIDE"
+struct chacha_ctx;
struct salsa20_ctx;
/* DECLARE_FAT_FUNC(name, ftype)
unsigned length, const uint8_t *msg);
typedef void chacha_core_func(uint32_t *dst, const uint32_t *src, unsigned rounds);
+
+typedef void chacha_crypt_func(struct chacha_ctx *ctx,
+ size_t length,
+ uint8_t *dst,
+ const uint8_t *src);