Use chacha20_vec if available

This commit is contained in:
Frank Denis 2015-11-25 15:32:25 +01:00
parent fce550257e
commit 8f9faa2229
3 changed files with 24 additions and 0 deletions

View File

@ -2,6 +2,10 @@
#include "stream_chacha20.h"
#include "runtime.h"
#include "ref/stream_chacha20_ref.h"
#if (defined(HAVE_EMMINTRIN_H) && defined(HAVE_TMMINTRIN_H)) || \
(defined(_MSC_VER) && (defined(_M_X64) || defined(_M_AMD64)))
# include "vec/stream_chacha20_vec.h"
#endif
static const crypto_stream_chacha20_implementation *implementation =
&crypto_stream_chacha20_ref_implementation;
@ -68,3 +72,16 @@ crypto_stream_chacha20_ietf_xor(unsigned char *c, const unsigned char *m,
{
return implementation->stream_ietf_xor_ic(c, m, mlen, n, 0U, k);
}
int
_crypto_stream_chacha20_pick_best_implementation(void)
{
implementation = &crypto_stream_chacha20_ref_implementation;
#if (defined(HAVE_EMMINTRIN_H) && defined(HAVE_TMMINTRIN_H)) || \
(defined(_MSC_VER) && (defined(_M_X64) || defined(_M_AMD64)))
if (sodium_runtime_has_ssse3()) {
implementation = &crypto_stream_chacha20_vec_implementation;
}
#endif
return 0;
}

View File

@ -65,6 +65,11 @@ int crypto_stream_chacha20_ietf_xor_ic(unsigned char *c, const unsigned char *m,
unsigned long long mlen,
const unsigned char *n, uint32_t ic,
const unsigned char *k);
/* ------------------------------------------------------------------------- */
int _crypto_stream_chacha20_pick_best_implementation(void);
#ifdef __cplusplus
}
#endif

View File

@ -3,6 +3,7 @@
#include "crypto_generichash.h"
#include "crypto_onetimeauth.h"
#include "crypto_scalarmult.h"
#include "crypto_stream_chacha20.h"
#include "randombytes.h"
#include "runtime.h"
#include "utils.h"
@ -21,6 +22,7 @@ sodium_init(void)
_crypto_generichash_blake2b_pick_best_implementation();
_crypto_onetimeauth_poly1305_pick_best_implementation();
_crypto_scalarmult_curve25519_pick_best_implementation();
_crypto_stream_chacha20_pick_best_implementation();
initialized = 1;
return 0;