Added seeder API. Also overhauled compile-time detection of features.
This commit is contained in:
parent
5b980fb625
commit
af9c79a071
22 changed files with 1183 additions and 399 deletions
|
|
@ -22,6 +22,7 @@
|
|||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
#define BR_ENABLE_INTRINSICS 1
|
||||
#include "inner.h"
|
||||
|
||||
/*
|
||||
|
|
@ -31,22 +32,6 @@
|
|||
|
||||
#if BR_AES_X86NI
|
||||
|
||||
#if BR_AES_X86NI_GCC
|
||||
#if BR_AES_X86NI_GCC_OLD
|
||||
#pragma GCC push_options
|
||||
#pragma GCC target("sse2,sse4.1,aes,pclmul")
|
||||
#endif
|
||||
#include <wmmintrin.h>
|
||||
#include <cpuid.h>
|
||||
#if BR_AES_X86NI_GCC_OLD
|
||||
#pragma GCC pop_options
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if BR_AES_X86NI_MSC
|
||||
#include <intrin.h>
|
||||
#endif
|
||||
|
||||
/* see inner.h */
|
||||
int
|
||||
br_aes_x86ni_supported(void)
|
||||
|
|
@ -56,35 +41,10 @@ br_aes_x86ni_supported(void)
|
|||
* 19 SSE4.1 (used for _mm_insert_epi32(), for AES-CTR)
|
||||
* 25 AES-NI
|
||||
*/
|
||||
#define MASK 0x02080000
|
||||
|
||||
#if BR_AES_X86NI_GCC
|
||||
unsigned eax, ebx, ecx, edx;
|
||||
|
||||
if (__get_cpuid(1, &eax, &ebx, &ecx, &edx)) {
|
||||
return (ecx & MASK) == MASK;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
#elif BR_AES_X86NI_MSC
|
||||
int info[4];
|
||||
|
||||
__cpuid(info, 1);
|
||||
return ((uint32_t)info[2] & MASK) == MASK;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
|
||||
#undef MASK
|
||||
return br_cpuid(0, 0, 0x02080000, 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Per-function attributes appear unreliable on old GCC, so we use the
|
||||
* pragma for all remaining functions in this file.
|
||||
*/
|
||||
#if BR_AES_X86NI_GCC_OLD
|
||||
#pragma GCC target("sse2,sse4.1,aes,pclmul")
|
||||
#endif
|
||||
BR_TARGETS_X86_UP
|
||||
|
||||
BR_TARGET("sse2,aes")
|
||||
static inline __m128i
|
||||
|
|
@ -275,4 +235,6 @@ br_aes_x86ni_keysched_dec(unsigned char *skni, const void *key, size_t len)
|
|||
return num_rounds;
|
||||
}
|
||||
|
||||
BR_TARGETS_X86_DOWN
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -22,20 +22,17 @@
|
|||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
#define BR_ENABLE_INTRINSICS 1
|
||||
#include "inner.h"
|
||||
|
||||
#if BR_AES_X86NI
|
||||
|
||||
#if BR_AES_X86NI_GCC
|
||||
#if BR_AES_X86NI_GCC_OLD
|
||||
#pragma GCC target("sse2,sse4.1,aes,pclmul")
|
||||
#endif
|
||||
#include <wmmintrin.h>
|
||||
#endif
|
||||
|
||||
#if BR_AES_X86NI_MSC
|
||||
#include <intrin.h>
|
||||
#endif
|
||||
/* see bearssl_block.h */
|
||||
const br_block_cbcdec_class *
|
||||
br_aes_x86ni_cbcdec_get_vtable(void)
|
||||
{
|
||||
return br_aes_x86ni_supported() ? &br_aes_x86ni_cbcdec_vtable : NULL;
|
||||
}
|
||||
|
||||
/* see bearssl_block.h */
|
||||
void
|
||||
|
|
@ -46,6 +43,8 @@ br_aes_x86ni_cbcdec_init(br_aes_x86ni_cbcdec_keys *ctx,
|
|||
ctx->num_rounds = br_aes_x86ni_keysched_dec(ctx->skey.skni, key, len);
|
||||
}
|
||||
|
||||
BR_TARGETS_X86_UP
|
||||
|
||||
/* see bearssl_block.h */
|
||||
BR_TARGET("sse2,aes")
|
||||
void
|
||||
|
|
@ -199,6 +198,8 @@ br_aes_x86ni_cbcdec_run(const br_aes_x86ni_cbcdec_keys *ctx,
|
|||
_mm_storeu_si128(iv, ivx);
|
||||
}
|
||||
|
||||
BR_TARGETS_X86_DOWN
|
||||
|
||||
/* see bearssl_block.h */
|
||||
const br_block_cbcdec_class br_aes_x86ni_cbcdec_vtable = {
|
||||
sizeof(br_aes_x86ni_cbcdec_keys),
|
||||
|
|
@ -210,13 +211,6 @@ const br_block_cbcdec_class br_aes_x86ni_cbcdec_vtable = {
|
|||
&br_aes_x86ni_cbcdec_run
|
||||
};
|
||||
|
||||
/* see bearssl_block.h */
|
||||
const br_block_cbcdec_class *
|
||||
br_aes_x86ni_cbcdec_get_vtable(void)
|
||||
{
|
||||
return br_aes_x86ni_supported() ? &br_aes_x86ni_cbcdec_vtable : NULL;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
/* see bearssl_block.h */
|
||||
|
|
|
|||
|
|
@ -22,20 +22,17 @@
|
|||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
#define BR_ENABLE_INTRINSICS 1
|
||||
#include "inner.h"
|
||||
|
||||
#if BR_AES_X86NI
|
||||
|
||||
#if BR_AES_X86NI_GCC
|
||||
#if BR_AES_X86NI_GCC_OLD
|
||||
#pragma GCC target("sse2,sse4.1,aes,pclmul")
|
||||
#endif
|
||||
#include <wmmintrin.h>
|
||||
#endif
|
||||
|
||||
#if BR_AES_X86NI_MSC
|
||||
#include <intrin.h>
|
||||
#endif
|
||||
/* see bearssl_block.h */
|
||||
const br_block_cbcenc_class *
|
||||
br_aes_x86ni_cbcenc_get_vtable(void)
|
||||
{
|
||||
return br_aes_x86ni_supported() ? &br_aes_x86ni_cbcenc_vtable : NULL;
|
||||
}
|
||||
|
||||
/* see bearssl_block.h */
|
||||
void
|
||||
|
|
@ -46,6 +43,8 @@ br_aes_x86ni_cbcenc_init(br_aes_x86ni_cbcenc_keys *ctx,
|
|||
ctx->num_rounds = br_aes_x86ni_keysched_enc(ctx->skey.skni, key, len);
|
||||
}
|
||||
|
||||
BR_TARGETS_X86_UP
|
||||
|
||||
/* see bearssl_block.h */
|
||||
BR_TARGET("sse2,aes")
|
||||
void
|
||||
|
|
@ -98,6 +97,8 @@ br_aes_x86ni_cbcenc_run(const br_aes_x86ni_cbcenc_keys *ctx,
|
|||
_mm_storeu_si128(iv, ivx);
|
||||
}
|
||||
|
||||
BR_TARGETS_X86_DOWN
|
||||
|
||||
/* see bearssl_block.h */
|
||||
const br_block_cbcenc_class br_aes_x86ni_cbcenc_vtable = {
|
||||
sizeof(br_aes_x86ni_cbcenc_keys),
|
||||
|
|
@ -109,13 +110,6 @@ const br_block_cbcenc_class br_aes_x86ni_cbcenc_vtable = {
|
|||
&br_aes_x86ni_cbcenc_run
|
||||
};
|
||||
|
||||
/* see bearssl_block.h */
|
||||
const br_block_cbcenc_class *
|
||||
br_aes_x86ni_cbcenc_get_vtable(void)
|
||||
{
|
||||
return br_aes_x86ni_supported() ? &br_aes_x86ni_cbcenc_vtable : NULL;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
/* see bearssl_block.h */
|
||||
|
|
|
|||
|
|
@ -22,24 +22,17 @@
|
|||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
#define BR_ENABLE_INTRINSICS 1
|
||||
#include "inner.h"
|
||||
|
||||
#if BR_AES_X86NI
|
||||
|
||||
#if BR_AES_X86NI_GCC
|
||||
#if BR_AES_X86NI_GCC_OLD
|
||||
#pragma GCC target("sse2,sse4.1,aes,pclmul")
|
||||
#endif
|
||||
#include <smmintrin.h>
|
||||
#include <wmmintrin.h>
|
||||
#define bswap32 __builtin_bswap32
|
||||
#endif
|
||||
|
||||
#if BR_AES_X86NI_MSC
|
||||
#include <stdlib.h>
|
||||
#include <intrin.h>
|
||||
#define bswap32 _byteswap_ulong
|
||||
#endif
|
||||
/* see bearssl_block.h */
|
||||
const br_block_ctr_class *
|
||||
br_aes_x86ni_ctr_get_vtable(void)
|
||||
{
|
||||
return br_aes_x86ni_supported() ? &br_aes_x86ni_ctr_vtable : NULL;
|
||||
}
|
||||
|
||||
/* see bearssl_block.h */
|
||||
void
|
||||
|
|
@ -50,6 +43,8 @@ br_aes_x86ni_ctr_init(br_aes_x86ni_ctr_keys *ctx,
|
|||
ctx->num_rounds = br_aes_x86ni_keysched_enc(ctx->skey.skni, key, len);
|
||||
}
|
||||
|
||||
BR_TARGETS_X86_UP
|
||||
|
||||
/* see bearssl_block.h */
|
||||
BR_TARGET("sse2,sse4.1,aes")
|
||||
uint32_t
|
||||
|
|
@ -190,6 +185,8 @@ br_aes_x86ni_ctr_run(const br_aes_x86ni_ctr_keys *ctx,
|
|||
return cc;
|
||||
}
|
||||
|
||||
BR_TARGETS_X86_DOWN
|
||||
|
||||
/* see bearssl_block.h */
|
||||
const br_block_ctr_class br_aes_x86ni_ctr_vtable = {
|
||||
sizeof(br_aes_x86ni_ctr_keys),
|
||||
|
|
@ -202,13 +199,6 @@ const br_block_ctr_class br_aes_x86ni_ctr_vtable = {
|
|||
&br_aes_x86ni_ctr_run
|
||||
};
|
||||
|
||||
/* see bearssl_block.h */
|
||||
const br_block_ctr_class *
|
||||
br_aes_x86ni_ctr_get_vtable(void)
|
||||
{
|
||||
return br_aes_x86ni_supported() ? &br_aes_x86ni_ctr_vtable : NULL;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
/* see bearssl_block.h */
|
||||
|
|
|
|||
|
|
@ -22,22 +22,43 @@
|
|||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
#define BR_ENABLE_INTRINSICS 1
|
||||
#include "inner.h"
|
||||
|
||||
#if BR_SSE2
|
||||
|
||||
/*
|
||||
* This file contains a ChaCha20 implementation that leverages SSE2
|
||||
* opcodes for better performance.
|
||||
*/
|
||||
|
||||
#if BR_SSE2
|
||||
/* see bearssl_block.h */
|
||||
br_chacha20_run
|
||||
br_chacha20_sse2_get(void)
|
||||
{
|
||||
/*
|
||||
* If using 64-bit mode, then SSE2 opcodes should be automatically
|
||||
* available, since they are part of the ABI.
|
||||
*
|
||||
* In 32-bit mode, we use CPUID to detect the SSE2 feature.
|
||||
*/
|
||||
|
||||
#if BR_SSE2_GCC
|
||||
#include <emmintrin.h>
|
||||
#include <cpuid.h>
|
||||
#endif
|
||||
#if BR_SSE2_MSC
|
||||
#include <intrin.h>
|
||||
#if BR_amd64
|
||||
return &br_chacha20_sse2_run;
|
||||
#else
|
||||
|
||||
/*
|
||||
* SSE2 support is indicated by bit 26 in EDX.
|
||||
*/
|
||||
if (br_cpuid(0, 0, 0, 0x04000000)) {
|
||||
return &br_chacha20_sse2_run;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
BR_TARGETS_X86_UP
|
||||
|
||||
/* see bearssl_block.h */
|
||||
BR_TARGET("sse2")
|
||||
|
|
@ -202,48 +223,7 @@ br_chacha20_sse2_run(const void *key,
|
|||
| ((uint32_t)_mm_extract_epi16(iw, 1) << 16);
|
||||
}
|
||||
|
||||
/* see bearssl_block.h */
|
||||
br_chacha20_run
|
||||
br_chacha20_sse2_get(void)
|
||||
{
|
||||
/*
|
||||
* If using 64-bit mode, then SSE2 opcodes should be automatically
|
||||
* available, since they are part of the ABI.
|
||||
*
|
||||
* In 32-bit mode, we use CPUID to detect the SSE2 feature.
|
||||
*/
|
||||
|
||||
#if __x86_64__ || _M_X64
|
||||
|
||||
return &br_chacha20_sse2_run;
|
||||
|
||||
#else
|
||||
|
||||
/*
|
||||
* SSE2 support is indicated by bit 26 in EDX.
|
||||
*/
|
||||
#define MASK 0x04000000
|
||||
|
||||
#if BR_SSE2_GCC
|
||||
unsigned eax, ebx, ecx, edx;
|
||||
|
||||
if (__get_cpuid(1, &eax, &ebx, &ecx, &edx)) {
|
||||
if ((edx & MASK) == MASK) {
|
||||
return &br_chacha20_sse2_run;
|
||||
}
|
||||
}
|
||||
#elif BR_SSE2_MSC
|
||||
int info[4];
|
||||
|
||||
__cpuid(info, 1);
|
||||
if (((uint32_t)info[3] & MASK) == MASK) {
|
||||
return &br_chacha20_sse2_run;
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
|
||||
#endif
|
||||
}
|
||||
BR_TARGETS_X86_DOWN
|
||||
|
||||
#else
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue