From d26c8adf84a38086e4d31af593513ce6aba5a968 Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Thu, 23 Feb 2017 12:02:56 +0100 Subject: [PATCH] Get rid of core_hchacha20.h --- src/libsodium/Makefile.am | 1 - .../crypto_core/hchacha20/core_hchacha20.c | 17 ++++++++---- .../crypto_core/hchacha20/core_hchacha20.h | 26 ------------------- 3 files changed, 12 insertions(+), 32 deletions(-) delete mode 100644 src/libsodium/crypto_core/hchacha20/core_hchacha20.h diff --git a/src/libsodium/Makefile.am b/src/libsodium/Makefile.am index b8368340..ec22345a 100644 --- a/src/libsodium/Makefile.am +++ b/src/libsodium/Makefile.am @@ -154,7 +154,6 @@ libsodium_la_SOURCES += \ crypto_aead/xchacha20poly1305/sodium/aead_xchacha20poly1305.c \ crypto_box/curve25519xchacha20poly1305/box_curve25519xchacha20poly1305.c \ crypto_core/hchacha20/core_hchacha20.c \ - crypto_core/hchacha20/core_hchacha20.h \ crypto_core/salsa2012/core_salsa2012.c \ crypto_core/salsa2012/ref/core_salsa2012_ref.c \ crypto_core/salsa208/core_salsa208.c \ diff --git a/src/libsodium/crypto_core/hchacha20/core_hchacha20.c b/src/libsodium/crypto_core/hchacha20/core_hchacha20.c index 37d1c94d..39ab26a6 100644 --- a/src/libsodium/crypto_core/hchacha20/core_hchacha20.c +++ b/src/libsodium/crypto_core/hchacha20/core_hchacha20.c @@ -2,10 +2,17 @@ #include #include -#include "core_hchacha20.h" #include "crypto_core_hchacha20.h" #include "private/common.h" +#define QUARTERROUND(A, B, C, D) \ + do { \ + A += B; D = ROTL32(D ^ A, 16); \ + C += D; B = ROTL32(B ^ C, 12); \ + A += B; D = ROTL32(D ^ A, 8); \ + C += D; B = ROTL32(B ^ C, 7); \ + } while(0) + int crypto_core_hchacha20(unsigned char *out, const unsigned char *in, const unsigned char *k, const unsigned char *c) @@ -15,10 +22,10 @@ crypto_core_hchacha20(unsigned char *out, const unsigned char *in, uint32_t x8, x9, x10, x11, x12, x13, x14, x15; if (c == NULL) { - x0 = U32C(0x61707865); - x1 = U32C(0x3320646e); - x2 = U32C(0x79622d32); - x3 = U32C(0x6b206574); + x0 = 0x61707865; + x1 = 0x3320646e; + x2 = 0x79622d32; + x3 = 0x6b206574; } else { x0 = LOAD32_LE(c + 0); x1 = LOAD32_LE(c + 4); diff --git a/src/libsodium/crypto_core/hchacha20/core_hchacha20.h b/src/libsodium/crypto_core/hchacha20/core_hchacha20.h deleted file mode 100644 index 25ca03de..00000000 --- a/src/libsodium/crypto_core/hchacha20/core_hchacha20.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef core_hchacha20_H -#define core_hchacha20_H - -#include -#include -#include - -#define U8C(v) (v##U) -#define U32C(v) (v##U) - -#define U8V(v) ((uint8_t)(v) & U8C(0xFF)) -#define U32V(v) ((uint32_t)(v) & U32C(0xFFFFFFFF)) - -#define ROTATE(v, c) (ROTL32(v, c)) -#define XOR(v, w) ((v) ^ (w)) -#define PLUS(v, w) (U32V((v) + (w))) - -#define QUARTERROUND(a, b, c, d) \ - do { \ - a = PLUS(a, b); d = ROTATE(XOR(d, a), 16); \ - c = PLUS(c, d); b = ROTATE(XOR(b, c), 12); \ - a = PLUS(a, b); d = ROTATE(XOR(d, a), 8); \ - c = PLUS(c, d); b = ROTATE(XOR(b, c), 7); \ - } while(0) - -#endif