Browse Source

Minor

src/include/barrett_field.h:

- Requires review: corrected failure to cast to (mask_t) prior to negation. (Or, if this is wrong; should cast to needed bitwidth explicitly.)
- Changed type of nwords_out to uint32_t to agree with header.

src/include/intrinsics.h:

- Fixed up various preprocessor statements to check for definition rather than value of built-ins.
- Added macro to use Clang’s __builtin_readcyclecounter on platforms on which it’s available. (Which is most platforms these days.)

src/include/magic.h: Preprocessor “if” versus “if defined”.

src/include/word.h: Fixed ifdefs; enabled support for memset_s on Darwin. Added explicit cast to mask_t.

Added void to function definitions and declarations in the following files (not including void is okay in modern C++, but not modern C, IIRC):

include/goldilocks.h, src/crandom.c, src/goldilocks.c, src/include/api.h, src/include/intrinsics.h, test/bench.c, test/test.c, test/test.h, test/test_arithmetic.c, test/test_goldilocks.c, test/test_pointops.c, test/test_scalarmul.c, test/test_sha512.c
master
David Leon Gil 10 years ago
committed by Mike Hamburg
parent
commit
c699cb29db
16 changed files with 61 additions and 39 deletions
  1. +1
    -1
      include/goldilocks.h
  2. +1
    -1
      src/crandom.c
  3. +2
    -2
      src/goldilocks.c
  4. +3
    -3
      src/include/api.h
  5. +3
    -3
      src/include/barrett_field.h
  6. +10
    -3
      src/include/intrinsics.h
  7. +1
    -1
      src/include/magic.h
  8. +22
    -7
      src/include/word.h
  9. +1
    -1
      test/bench.c
  10. +2
    -2
      test/test.c
  11. +8
    -8
      test/test.h
  12. +1
    -1
      test/test_arithmetic.c
  13. +1
    -1
      test/test_goldilocks.c
  14. +1
    -1
      test/test_pointops.c
  15. +3
    -3
      test/test_scalarmul.c
  16. +1
    -1
      test/test_sha512.c

+ 1
- 1
include/goldilocks.h View File

@@ -100,7 +100,7 @@ static const int GOLDI_EALREADYINIT = 44805;
* @retval Nonzero An error occurred.
*/
int
goldilocks_init ()
goldilocks_init (void)
__attribute__((warn_unused_result,visibility ("default")));




+ 1
- 1
src/crandom.c View File

@@ -14,7 +14,7 @@

volatile unsigned int crandom_features = 0;

unsigned int crandom_detect_features() {
unsigned int crandom_detect_features(void) {
unsigned int out = GEN;
# if (defined(__i386__) || defined(__x86_64__))


+ 2
- 2
src/goldilocks.c View File

@@ -57,7 +57,7 @@ static struct {
} goldilocks_global;

static inline mask_t
goldilocks_check_init() {
goldilocks_check_init(void) {
if (likely(goldilocks_global.state == G_INITED)) {
return MASK_SUCCESS;
} else {
@@ -66,7 +66,7 @@ goldilocks_check_init() {
}

int
goldilocks_init () {
goldilocks_init (void) {
const char *res = compare_and_swap(&goldilocks_global.state, NULL, G_INITING);
if (res == G_INITED) return GOLDI_EALREADYINIT;
else if (res) {


+ 3
- 3
src/include/api.h View File

@@ -43,9 +43,9 @@
#endif
*/

static inline int timingattacks() { return 0; }
static inline int copyrightclaims() { return 0; }
static inline int patentclaims() {
static inline int timingattacks(void) { return 0; }
static inline int copyrightclaims(void) { return 0; }
static inline int patentclaims(void) {
/* Until the end of July 2014, point compression
* is patented. */
return 20;


+ 3
- 3
src/include/barrett_field.h View File

@@ -37,7 +37,7 @@ extern const struct barrett_prime_t curve_prime_order;
/**
* Reduce a number (with optional high carry word) mod p.
*
* @param [inout] a The value to be reduced.
* @param [in,out] a The value to be reduced.
* @param [in] nwords_a The number of words in a.
* @param [in] a_carry A high word to be carried into the computation.
* @param [in] prime The Barrett prime.
@@ -132,7 +132,7 @@ barrett_mul_or_mac(
static inline void
barrett_mul(
word_t *out,
int nwords_out,
uint32_t nwords_out,

const word_t *a,
uint32_t nwords_a,
@@ -158,7 +158,7 @@ barrett_mac(

const struct barrett_prime_t *prime
) {
barrett_mul_or_mac(out,nwords_out,a,nwords_a,b,nwords_b,prime,-1);
barrett_mul_or_mac(out,nwords_out,a,nwords_a,b,nwords_b,prime,-(mask_t)1);
}

mask_t


+ 10
- 3
src/include/intrinsics.h View File

@@ -13,13 +13,13 @@
#include <sys/types.h>
#include "config.h"

#if __i386__ || __x86_64__
#if defined(__i386__) || defined(__x86_64__)
#include <immintrin.h>
#endif

/** @brief Macro to make a function static, forcibly inlined and possibly unused. */
#define INTRINSIC \
static __inline__ __attribute__((__gnu_inline__, __always_inline__, unused))
static inline __attribute__((__gnu_inline__, __always_inline__))

#define GEN 1 /**< @brief Intrinsics field has been generated. */
#define SSE2 2 /**< @brief Machine supports SSE2 */
@@ -33,13 +33,20 @@
/**
* @brief If on x86, read the timestamp counter. Otherwise, return 0.
*/
INTRINSIC u_int64_t rdtsc() {
#ifndef __has_builtin
#define __has_builtin(X) 0
#endif
#if defined(__clang__) && __has_builtin(__builtin_readcyclecounter)
#define rdtsc __builtin_readcyclecounter
#else
INTRINSIC u_int64_t rdtsc(void) {
u_int64_t out = 0;
# if (defined(__i386__) || defined(__x86_64__))
__asm__ __volatile__ ("rdtsc" : "=A"(out));
# endif
return out;
}
#endif

/**
* Return x unchanged, but confuse the compiler.


+ 1
- 1
src/include/magic.h View File

@@ -76,7 +76,7 @@ extern const word_t SCALARMUL_FIXED_WINDOW_ADJUSTMENT[2*SCALAR_WORDS];
* @brief If true, use wider tables for the precomputed combs.
*/
#ifndef USE_BIG_COMBS
#if __ARM_NEON__
#if defined(__ARM_NEON__)
#define USE_BIG_COMBS 1
#else
#define USE_BIG_COMBS (WORD_BITS==64)


+ 22
- 7
src/include/word.h View File

@@ -20,13 +20,16 @@
#include <sys/types.h>
#include <inttypes.h>

#if __ARM_NEON__
#if defined(__ARM_NEON__)
#include <arm_neon.h>
#elif __SSE2__
#elif defined(__SSE2__)
#include <immintrin.h>
#endif

#if (__SIZEOF_INT128__ == 16 && __SIZEOF_SIZE_T__ == 8 && (__SIZEOF_LONG__==8 || __POINTER_WIDTH__==64) && !GOLDI_FORCE_32_BIT)
#if (__SIZEOF_INT128__ == 16 \
&& __SIZEOF_SIZE_T__ == 8 \
&& (__SIZEOF_LONG__==8 || __POINTER_WIDTH__==64) \
&& !defined(GOLDI_FORCE_32_BIT))
/* It's a 64-bit machine if:
* __uint128_t exists
* size_t is 64 bits
@@ -67,7 +70,7 @@ typedef int64_t dsword_t;
#define WORDS_FOR_BITS(_x) (DIV_CEIL((_x),WORD_BITS))

typedef word_t mask_t;
static const mask_t MASK_FAILURE = 0, MASK_SUCCESS = -1;
static const mask_t MASK_FAILURE = 0, MASK_SUCCESS = -(mask_t)1;



@@ -106,7 +109,7 @@ typedef word_t vecmask_t __attribute__((vector_size(32)));

static __inline__ big_register_t
br_set_to_mask(mask_t x) {
uint32_t y = x;
uint32_t y = (uint32_t)x;
big_register_t ret = {y,y,y,y,y,y,y,y};
return ret;
}
@@ -193,10 +196,22 @@ letoh64 (uint64_t x) { return x; }
* @param c The char to set it to (probably zero).
* @param s The size of the object.
*/
#ifdef __STDC_LIB_EXT1__ /* which it won't be, because we're -std=c99 */
#if (defined(__DARWIN_C_LEVEL) \
|| (defined(__STDC_WANT_LIB_EXT1__) && __STDC_WANT_LIB_EXT1__ == 1))
#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 __inline__ void
really_memset(void *p, char c, size_t s) {
memset_s(p,s,c,s);
memset_s(p, s, c, s);
}
#else
static __inline__ void __attribute__((always_inline,unused))


+ 1
- 1
test/bench.c View File

@@ -22,7 +22,7 @@ ignore_result ( int result ) {
(void)result;
}

static double now() {
static double now(void) {
struct timeval tv;
gettimeofday(&tv, NULL);


+ 2
- 2
test/test.c View File

@@ -9,7 +9,7 @@

int failed_tests, n_tests, failed_this_test, running_a_test;

static void end_test() {
static void end_test(void) {
if (!failed_this_test) {
printf("[PASS]\n");
}
@@ -25,7 +25,7 @@ static void begin_test(const char *name) {
running_a_test = 1;
}

void youfail() {
void youfail(void) {
if (failed_this_test) return;
failed_this_test = 1;
failed_tests ++;


+ 8
- 8
test/test.h View File

@@ -29,20 +29,20 @@ void scalar_print (
int nwords
);

void youfail();
void youfail(void);

int test_sha512_monte_carlo();
int test_sha512_monte_carlo(void);

int test_linear_combo ();
int test_linear_combo (void);

int test_scalarmul_compatibility ();
int test_scalarmul_compatibility (void);

int test_scalarmul_commutativity ();
int test_scalarmul_commutativity (void);

int test_arithmetic ();
int test_arithmetic (void);

int test_goldilocks ();
int test_goldilocks (void);

int test_pointops ();
int test_pointops (void);

#endif // __GOLDILOCKS_TEST_H__

+ 1
- 1
test/test_arithmetic.c View File

@@ -148,7 +148,7 @@ static mask_t test_mul_sqr (
return succ;
}

int test_arithmetic () {
int test_arithmetic (void) {
int j, ntests = 100000;
gmp_randstate_t state;


+ 1
- 1
test/test_goldilocks.c View File

@@ -4,7 +4,7 @@
#include <stdlib.h>
#include <string.h>

int test_goldilocks () {
int test_goldilocks (void) {
const char *message1 = "hello world";
const char *message2 = "Jello world";


+ 1
- 1
test/test_pointops.c View File

@@ -249,7 +249,7 @@ single_twisting_test (
return succ ? 0 : -1;
}

int test_pointops () {
int test_pointops (void) {
struct affine_t base, pbase;
struct p448_t ser448;


+ 3
- 3
test/test_scalarmul.c View File

@@ -274,7 +274,7 @@ single_scalarmul_commutativity_test (
}
}

int test_scalarmul_commutativity () {
int test_scalarmul_commutativity (void) {
int i,j,k,got;
struct crandom_state_t crand;
@@ -312,7 +312,7 @@ int test_scalarmul_commutativity () {
return 0;
}

int test_linear_combo () {
int test_linear_combo (void) {
int i,j,k,got;
struct crandom_state_t crand;
@@ -355,7 +355,7 @@ int test_linear_combo () {
return 0;
}

int test_scalarmul_compatibility () {
int test_scalarmul_compatibility (void) {
int i,j,k,got;
struct crandom_state_t crand;


+ 1
- 1
test/test_sha512.c View File

@@ -59,7 +59,7 @@ static int sha512_monte_carlo_core (
return 0;
}

int test_sha512_monte_carlo() {
int test_sha512_monte_carlo(void) {
const char *seed =
"5c337de5caf35d18ed90b5cddfce001ca1b8ee8602f367e7c24ccca6f893802f"
"b1aca7a3dae32dcd60800a59959bc540d63237876b799229ae71a2526fbc52cd";


Loading…
Cancel
Save