diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-05-29 16:06:57 +0200 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-05-31 01:24:51 +0200 |
commit | 101b71c192047d5966b3c59dba088957ca51e588 (patch) | |
tree | 1cb72ed6ff1916eb71d038b6b426eef1962f7350 /src/selftest/chacha20poly1305.h | |
parent | 520af047f5b84c92202e3f42f49281f37034d1c0 (diff) |
chacha20poly1305: split up into separate files
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'src/selftest/chacha20poly1305.h')
-rw-r--r-- | src/selftest/chacha20poly1305.h | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/src/selftest/chacha20poly1305.h b/src/selftest/chacha20poly1305.h index a6a5598..efbb76b 100644 --- a/src/selftest/chacha20poly1305.h +++ b/src/selftest/chacha20poly1305.h @@ -1278,19 +1278,18 @@ static inline void chacha20poly1305_selftest_encrypt_bignonce(u8 *dst, const u8 bool have_simd = chacha20poly1305_init_simd(); __le64 len; struct poly1305_ctx poly1305_state; - struct chacha20_ctx chacha20_state = {{ - EXPAND_32_BYTE_K, - le32_to_cpuvp(key + 0), le32_to_cpuvp(key + 4), le32_to_cpuvp(key + 8), le32_to_cpuvp(key + 12), - le32_to_cpuvp(key + 16), le32_to_cpuvp(key + 20), le32_to_cpuvp(key + 24), le32_to_cpuvp(key + 28), - 0, le32_to_cpuvp(nonce + 0), le32_to_cpuvp(nonce + 4), le32_to_cpuvp(nonce + 8) - }}; - u8 block0[CHACHA20_BLOCK_SIZE] = { 0 }; + struct chacha20_ctx chacha20_state; + u8 block0[POLY1305_KEY_SIZE] = { 0 }; - chacha20_crypt(&chacha20_state, block0, block0, sizeof(block0), have_simd); + chacha20_init(&chacha20_state, key, 0); + chacha20_state.counter[1] = le32_to_cpu(*(__le32 *)(nonce + 0)); + chacha20_state.counter[2] = le32_to_cpu(*(__le32 *)(nonce + 4)); + chacha20_state.counter[3] = le32_to_cpu(*(__le32 *)(nonce + 8)); + chacha20(&chacha20_state, block0, block0, sizeof(block0), have_simd); poly1305_init(&poly1305_state, block0, have_simd); poly1305_update(&poly1305_state, ad, ad_len, have_simd); poly1305_update(&poly1305_state, pad0, (0x10 - ad_len) & 0xf, have_simd); - chacha20_crypt(&chacha20_state, dst, src, src_len, have_simd); + chacha20(&chacha20_state, dst, src, src_len, have_simd); poly1305_update(&poly1305_state, dst, src_len, have_simd); poly1305_update(&poly1305_state, pad0, (0x10 - src_len) & 0xf, have_simd); len = cpu_to_le64(ad_len); @@ -1304,7 +1303,7 @@ static inline void chacha20poly1305_selftest_encrypt_bignonce(u8 *dst, const u8 static inline void chacha20poly1305_selftest_encrypt(u8 *dst, const u8 *src, const size_t src_len, const u8 *ad, const size_t ad_len, const u8 *nonce, const size_t nonce_len, const u8 key[CHACHA20POLY1305_KEYLEN]) { if (nonce_len == 8) - chacha20poly1305_encrypt(dst, src, src_len, ad, ad_len, le64_to_cpu(*(__force __le64 *)nonce), key); + chacha20poly1305_encrypt(dst, src, src_len, ad, ad_len, le64_to_cpup((__force __le64 *)nonce), key); else if (nonce_len == 12) chacha20poly1305_selftest_encrypt_bignonce(dst, src, src_len, ad, ad_len, nonce, key); else |