vendor/libsodium/src/libsodium/crypto_stream/chacha20/stream_chacha20.c in rbnacl-libsodium-1.0.11 vs vendor/libsodium/src/libsodium/crypto_stream/chacha20/stream_chacha20.c in rbnacl-libsodium-1.0.13

- old
+ new

@@ -1,12 +1,19 @@ #include "crypto_stream_chacha20.h" -#include "stream_chacha20.h" +#include "private/common.h" +#include "randombytes.h" #include "runtime.h" -#include "ref/stream_chacha20_ref.h" -#if (defined(HAVE_EMMINTRIN_H) && defined(HAVE_TMMINTRIN_H) && defined(__GNUC__)) -# include "vec/stream_chacha20_vec.h" +#include "stream_chacha20.h" + +#include "ref/chacha20_ref.h" +#if defined(HAVE_AVX2INTRIN_H) && defined(HAVE_EMMINTRIN_H) && \ + defined(HAVE_TMMINTRIN_H) && defined(HAVE_SMMINTRIN_H) +# include "dolbeau/chacha20_dolbeau-avx2.h" #endif +#if defined(HAVE_EMMINTRIN_H) && defined(HAVE_TMMINTRIN_H) +# include "dolbeau/chacha20_dolbeau-ssse3.h" +#endif static const crypto_stream_chacha20_implementation *implementation = &crypto_stream_chacha20_ref_implementation; size_t @@ -18,12 +25,17 @@ crypto_stream_chacha20_noncebytes(void) { return crypto_stream_chacha20_NONCEBYTES; } size_t +crypto_stream_chacha20_ietf_keybytes(void) { + return crypto_stream_chacha20_ietf_KEYBYTES; +} + +size_t crypto_stream_chacha20_ietf_noncebytes(void) { - return crypto_stream_chacha20_IETF_NONCEBYTES; + return crypto_stream_chacha20_ietf_NONCEBYTES; } int crypto_stream_chacha20(unsigned char *c, unsigned long long clen, const unsigned char *n, const unsigned char *k) @@ -70,16 +82,36 @@ const unsigned char *k) { return implementation->stream_ietf_xor_ic(c, m, mlen, n, 0U, k); } +void +crypto_stream_chacha20_ietf_keygen(unsigned char k[crypto_stream_chacha20_ietf_KEYBYTES]) +{ + randombytes_buf(k, crypto_stream_chacha20_ietf_KEYBYTES); +} + +void +crypto_stream_chacha20_keygen(unsigned char k[crypto_stream_chacha20_KEYBYTES]) +{ + randombytes_buf(k, crypto_stream_chacha20_KEYBYTES); +} + int _crypto_stream_chacha20_pick_best_implementation(void) { implementation = &crypto_stream_chacha20_ref_implementation; -#if (defined(HAVE_EMMINTRIN_H) && defined(HAVE_TMMINTRIN_H) && defined(__GNUC__)) +#if defined(HAVE_AVX2INTRIN_H) && defined(HAVE_EMMINTRIN_H) && \ + defined(HAVE_TMMINTRIN_H) && defined(HAVE_SMMINTRIN_H) + if (sodium_runtime_has_avx2()) { + implementation = &crypto_stream_chacha20_dolbeau_avx2_implementation; + return 0; + } +#endif +#if defined(HAVE_EMMINTRIN_H) && defined(HAVE_TMMINTRIN_H) if (sodium_runtime_has_ssse3()) { - implementation = &crypto_stream_chacha20_vec_implementation; + implementation = &crypto_stream_chacha20_dolbeau_ssse3_implementation; + return 0; } #endif return 0; }