#ifndef __WORD_H__
#define __WORD_H__
-/* for posix_memalign */
-#define _XOPEN_SOURCE 600
-#define __STDC_WANT_LIB_EXT1__ 1 /* for memset_s */
#include <string.h>
-#if defined(__sun) && defined(__SVR4)
-extern int posix_memalign(void **, size_t, size_t);
-#endif
#include <assert.h>
#include <stdint.h>
#include "arch_intrinsics.h"
-#include <decaf/common.h>
+#include "curve448utils.h"
#ifndef _BSD_SOURCE
#define _BSD_SOURCE 1
typedef uint64x4_t uint64xn_t;
typedef uint32x8_t uint32xn_t;
- static DECAF_INLINE big_register_t
+ static ossl_inline big_register_t
br_set_to_mask(mask_t x) {
uint32_t y = (uint32_t)x;
big_register_t ret = {y,y,y,y,y,y,y,y};
typedef uint64x2_t uint64xn_t;
typedef uint32x4_t uint32xn_t;
- static DECAF_INLINE big_register_t
+ static ossl_inline big_register_t
br_set_to_mask(mask_t x) {
uint32_t y = x;
big_register_t ret = {y,y,y,y};
typedef uint64x2_t uint64xn_t;
typedef uint32x4_t uint32xn_t;
- static DECAF_INLINE big_register_t
+ static ossl_inline big_register_t
br_set_to_mask(mask_t x) {
return vdupq_n_u32(x);
}
typedef uint64_t big_register_t, uint64xn_t;
typedef uint32_t uint32xn_t;
- static DECAF_INLINE big_register_t
+ static ossl_inline big_register_t
br_set_to_mask(mask_t x) {
return (big_register_t)x;
}
typedef uint32_t uint32xn_t;
typedef uint32_t big_register_t;
- static DECAF_INLINE big_register_t
+ static ossl_inline big_register_t
br_set_to_mask(mask_t x) {
return (big_register_t)x;
}
#endif
-typedef struct {
- uint64xn_t unaligned;
-} __attribute__((packed)) unaligned_uint64xn_t;
-
-typedef struct {
- uint32xn_t unaligned;
-} __attribute__((packed)) unaligned_uint32xn_t;
-
#if __AVX2__
- static DECAF_INLINE big_register_t
+ static ossl_inline big_register_t
br_is_zero(big_register_t x) {
return (big_register_t)(x == br_set_to_mask(0));
}
#elif __SSE2__
- static DECAF_INLINE big_register_t
+ static ossl_inline big_register_t
br_is_zero(big_register_t x) {
return (big_register_t)_mm_cmpeq_epi32((__m128i)x, _mm_setzero_si128());
//return (big_register_t)(x == br_set_to_mask(0));
}
#elif __ARM_NEON__
- static DECAF_INLINE big_register_t
+ static ossl_inline big_register_t
br_is_zero(big_register_t x) {
return vceqq_u32(x,x^x);
}
#define br_is_zero word_is_zero
#endif
-/**
- * Really call memset, in a way that prevents the compiler from optimizing it out.
- * @param p The object to zeroize.
- * @param c The char to set it to (probably zero).
- * @param s The size of the object.
- */
-#if defined(__DARWIN_C_LEVEL) || defined(__STDC_LIB_EXT1__)
-#define HAS_MEMSET_S
-#endif
-
-#if !defined(__STDC_WANT_LIB_EXT1__) || __STDC_WANT_LIB_EXT1__ != 1
-#define NEED_MEMSET_S_EXTERN
-#endif
-
-#ifdef HAS_MEMSET_S
- #ifdef NEED_MEMSET_S_EXTERN
- extern int memset_s(void *, size_t, int, size_t);
- #endif
- static DECAF_INLINE void
- really_memset(void *p, char c, size_t s) {
- memset_s(p, s, c, s);
- }
-#else
- /* PERF: use words? */
- static DECAF_INLINE void
- really_memset(void *p, char c, size_t s) {
- volatile char *pv = (volatile char *)p;
- size_t i;
- for (i=0; i<s; i++) pv[i] = c;
- }
-#endif
-
-/**
- * Allocate memory which is sufficiently aligned to be used for the
- * largest vector on the system (for now that's a big_register_t).
- *
- * Man malloc says that it does this, but at least for AVX2 on MacOS X,
- * it's lying.
- *
- * @param size The size of the region to allocate.
- * @return A suitable pointer, which can be free'd with free(),
- * or NULL if no memory can be allocated.
- */
-static DECAF_INLINE void *
-malloc_vector(size_t size) {
- void *out = NULL;
-
- int ret = posix_memalign(&out, sizeof(big_register_t), size);
-
- if (ret) {
- return NULL;
- } else {
- return out;
- }
-}
-
/* PERF: vectorize vs unroll */
#ifdef __clang__
#if 100*__clang_major__ + __clang_minor__ > 305
* On the third hand, we have success vs boolean types, but that's handled in
* common.h: it converts between decaf_bool_t and decaf_error_t.
*/
-static DECAF_INLINE decaf_bool_t mask_to_bool (mask_t m) {
+static ossl_inline decaf_bool_t mask_to_bool (mask_t m) {
return (decaf_sword_t)(sword_t)m;
}
-static DECAF_INLINE mask_t bool_to_mask (decaf_bool_t m) {
+static ossl_inline mask_t bool_to_mask (decaf_bool_t m) {
/* On most arches this will be optimized to a simple cast. */
mask_t ret = 0;
unsigned int limit = sizeof(decaf_bool_t)/sizeof(mask_t);
return ret;
}
-static DECAF_INLINE void ignore_result ( decaf_bool_t boo ) {
+static ossl_inline void ignore_result ( decaf_bool_t boo ) {
(void)boo;
}