diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-09-24 21:25:13 +0200 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-09-25 03:01:21 +0200 |
commit | 56c4ea978af3991a404c72d4358d40483922cd09 (patch) | |
tree | c2c586e488272b324541c0805bd9e05118f32aa3 /src/crypto/zinc/chacha20 | |
parent | chacha20-arm: remove unused preambles (diff) | |
download | wireguard-monolithic-historical-56c4ea978af3991a404c72d4358d40483922cd09.tar.xz wireguard-monolithic-historical-56c4ea978af3991a404c72d4358d40483922cd09.zip |
hchacha20: keep in native endian in words
Diffstat (limited to 'src/crypto/zinc/chacha20')
-rw-r--r-- | src/crypto/zinc/chacha20/chacha20-arm-glue.h | 8 | ||||
-rw-r--r-- | src/crypto/zinc/chacha20/chacha20-arm.S | 4 | ||||
-rw-r--r-- | src/crypto/zinc/chacha20/chacha20-mips-glue.h | 7 | ||||
-rw-r--r-- | src/crypto/zinc/chacha20/chacha20-x86_64-glue.h | 8 | ||||
-rw-r--r-- | src/crypto/zinc/chacha20/chacha20.c | 33 |
5 files changed, 30 insertions, 30 deletions
diff --git a/src/crypto/zinc/chacha20/chacha20-arm-glue.h b/src/crypto/zinc/chacha20/chacha20-arm-glue.h index 1f1add0..86cce85 100644 --- a/src/crypto/zinc/chacha20/chacha20-arm-glue.h +++ b/src/crypto/zinc/chacha20/chacha20-arm-glue.h @@ -57,8 +57,10 @@ static inline bool chacha20_arch(struct chacha20_ctx *state, u8 *dst, return true; } -static inline bool hchacha20_arch(u8 *derived_key, const u8 *nonce, - const u8 *key, simd_context_t *simd_context) +static inline bool hchacha20_arch(u32 derived_key[CHACHA20_KEY_WORDS], + const u8 nonce[HCHACHA20_NONCE_SIZE], + const u8 key[HCHACHA20_KEY_SIZE], + simd_context_t *simd_context) { #if defined(CONFIG_ARM) u32 x[] = { CHACHA20_CONSTANT_EXPA, @@ -78,7 +80,7 @@ static inline bool hchacha20_arch(u8 *derived_key, const u8 *nonce, get_unaligned_le32(nonce + 8), get_unaligned_le32(nonce + 12) }; - hchacha20_arm(x, (u32 *)derived_key); + hchacha20_arm(x, derived_key); return true; #else return false; diff --git a/src/crypto/zinc/chacha20/chacha20-arm.S b/src/crypto/zinc/chacha20/chacha20-arm.S index 7fbb631..5abedaf 100644 --- a/src/crypto/zinc/chacha20/chacha20-arm.S +++ b/src/crypto/zinc/chacha20/chacha20-arm.S @@ -457,9 +457,7 @@ ENTRY(hchacha20_arm) ror X14, X14, #drot ror X15, X15, #drot - // Store (x0-x3,x12-x15) to 'out' after byte swapping - _le32_bswap_4x X0, X1, X2, X3, X4, X5, X6 - _le32_bswap_4x X12, X13, X14, X15, X4, X5, X6 + // Store (x0-x3,x12-x15) to 'out' stm r4, {X0,X1,X2,X3,X12,X13,X14,X15} pop {r4-r11,pc} diff --git a/src/crypto/zinc/chacha20/chacha20-mips-glue.h b/src/crypto/zinc/chacha20/chacha20-mips-glue.h index 929ca12..6e70dd6 100644 --- a/src/crypto/zinc/chacha20/chacha20-mips-glue.h +++ b/src/crypto/zinc/chacha20/chacha20-mips-glue.h @@ -17,8 +17,11 @@ static inline bool chacha20_arch(struct chacha20_ctx *state, u8 *dst, return true; } -static inline bool hchacha20_arch(u8 *derived_key, const u8 *nonce, - const u8 *key, simd_context_t *simd_context) + +static inline bool hchacha20_arch(u32 derived_key[CHACHA20_KEY_WORDS], + const u8 nonce[HCHACHA20_NONCE_SIZE], + const u8 key[HCHACHA20_KEY_SIZE], + simd_context_t *simd_context) { return false; } diff --git a/src/crypto/zinc/chacha20/chacha20-x86_64-glue.h b/src/crypto/zinc/chacha20/chacha20-x86_64-glue.h index 77dacf6..1b7fc05 100644 --- a/src/crypto/zinc/chacha20/chacha20-x86_64-glue.h +++ b/src/crypto/zinc/chacha20/chacha20-x86_64-glue.h @@ -9,7 +9,7 @@ #include <asm/intel-family.h> #ifdef CONFIG_AS_SSSE3 -asmlinkage void hchacha20_ssse3(u8 *derived_key, const u8 *nonce, +asmlinkage void hchacha20_ssse3(u32 *derived_key, const u8 *nonce, const u8 *key); asmlinkage void chacha20_ssse3(u8 *out, const u8 *in, const size_t len, const u32 key[8], const u32 counter[4]); @@ -92,8 +92,10 @@ success: return true; } -static inline bool hchacha20_arch(u8 *derived_key, const u8 *nonce, - const u8 *key, simd_context_t *simd_context) +static inline bool hchacha20_arch(u32 derived_key[CHACHA20_KEY_WORDS], + const u8 nonce[HCHACHA20_NONCE_SIZE], + const u8 key[HCHACHA20_KEY_SIZE], + simd_context_t *simd_context) { #if defined(CONFIG_AS_SSSE3) if (chacha20_use_ssse3 && simd_use(simd_context)) { diff --git a/src/crypto/zinc/chacha20/chacha20.c b/src/crypto/zinc/chacha20/chacha20.c index ca50d0e..dc9770b 100644 --- a/src/crypto/zinc/chacha20/chacha20.c +++ b/src/crypto/zinc/chacha20/chacha20.c @@ -30,8 +30,10 @@ static inline bool chacha20_arch(struct chacha20_ctx *state, u8 *out, { return false; } -static inline bool hchacha20_arch(u8 *derived_key, const u8 *nonce, - const u8 *key, simd_context_t *simd_context) +static inline bool hchacha20_arch(u32 derived_key[CHACHA20_KEY_WORDS], + const u8 nonce[HCHACHA20_NONCE_SIZE], + const u8 key[HCHACHA20_KEY_SIZE], + simd_context_t *simd_context) { return false; } @@ -118,43 +120,36 @@ void chacha20(struct chacha20_ctx *state, u8 *dst, const u8 *src, u32 len, } EXPORT_SYMBOL(chacha20); -static void hchacha20_generic(u8 derived_key[CHACHA20_KEY_SIZE], +static void hchacha20_generic(u32 derived_key[CHACHA20_KEY_WORDS], const u8 nonce[HCHACHA20_NONCE_SIZE], const u8 key[HCHACHA20_KEY_SIZE]) { - __le32 *out = (__force __le32 *)derived_key; u32 x[] = { CHACHA20_CONSTANT_EXPA, CHACHA20_CONSTANT_ND_3, CHACHA20_CONSTANT_2_BY, CHACHA20_CONSTANT_TE_K, - get_unaligned_le32(key + 0), - get_unaligned_le32(key + 4), - get_unaligned_le32(key + 8), + get_unaligned_le32(key + 0), + get_unaligned_le32(key + 4), + get_unaligned_le32(key + 8), get_unaligned_le32(key + 12), get_unaligned_le32(key + 16), get_unaligned_le32(key + 20), get_unaligned_le32(key + 24), get_unaligned_le32(key + 28), - get_unaligned_le32(nonce + 0), - get_unaligned_le32(nonce + 4), - get_unaligned_le32(nonce + 8), + get_unaligned_le32(nonce + 0), + get_unaligned_le32(nonce + 4), + get_unaligned_le32(nonce + 8), get_unaligned_le32(nonce + 12) }; TWENTY_ROUNDS(x); - out[0] = cpu_to_le32(x[0]); - out[1] = cpu_to_le32(x[1]); - out[2] = cpu_to_le32(x[2]); - out[3] = cpu_to_le32(x[3]); - out[4] = cpu_to_le32(x[12]); - out[5] = cpu_to_le32(x[13]); - out[6] = cpu_to_le32(x[14]); - out[7] = cpu_to_le32(x[15]); + memcpy(derived_key + 0, x + 0, sizeof(u32) * 4); + memcpy(derived_key + 4, x + 12, sizeof(u32) * 4); } /* Derived key should be 32-bit aligned */ -void hchacha20(u8 derived_key[CHACHA20_KEY_SIZE], +void hchacha20(u32 derived_key[CHACHA20_KEY_WORDS], const u8 nonce[HCHACHA20_NONCE_SIZE], const u8 key[HCHACHA20_KEY_SIZE], simd_context_t *simd_context) { |