@@ -1,9 +1,8 @@ | |||||
// FIXME move to arch or something | // FIXME move to arch or something | ||||
#define WBITS DECAF_WORD_BITS | #define WBITS DECAF_WORD_BITS | ||||
#define LBITS DECAF_255_LIMB_BITS | |||||
#if WBITS == 64 | #if WBITS == 64 | ||||
#define LBITS 51 | |||||
typedef __int128_t decaf_sdword_t; | |||||
#define LIMB(x) (x##ull) | #define LIMB(x) (x##ull) | ||||
#define SC_LIMB(x) (x##ull) | #define SC_LIMB(x) (x##ull) | ||||
#else | #else | ||||
@@ -1,15 +1,9 @@ | |||||
// FIXME move to arch or something | |||||
#define WBITS DECAF_WORD_BITS | #define WBITS DECAF_WORD_BITS | ||||
// #define LBITS DECAF_448_LIMB_BITS // FIXME | |||||
#if WBITS == 64 | #if WBITS == 64 | ||||
#define LBITS 56 | |||||
typedef __int128_t decaf_sdword_t; | |||||
#define LIMB(x) (x##ull) | |||||
#define SC_LIMB(x) (x##ull) | #define SC_LIMB(x) (x##ull) | ||||
#elif WBITS == 32 | #elif WBITS == 32 | ||||
typedef int64_t decaf_sdword_t; | |||||
#define LBITS 28 | |||||
#define LIMB(x) (x##ull)&((1ull<<LBITS)-1), (x##ull)>>LBITS | |||||
#define SC_LIMB(x) (x##ull)&((1ull<<32)-1), (x##ull)>>32 | #define SC_LIMB(x) (x##ull)&((1ull<<32)-1), (x##ull)>>32 | ||||
#else | #else | ||||
#error "Only supporting 32- and 64-bit platforms right now" | #error "Only supporting 32- and 64-bit platforms right now" | ||||
@@ -213,7 +213,7 @@ snv gf_canon ( gf a ) { | |||||
gf_reduce(a); | gf_reduce(a); | ||||
/* subtract p with borrow */ | /* subtract p with borrow */ | ||||
decaf_sdword_t carry = 0; | |||||
decaf_dsword_t carry = 0; | |||||
FOR_LIMB(i, { | FOR_LIMB(i, { | ||||
carry = carry + a->limb[i] - P->limb[i]; | carry = carry + a->limb[i] - P->limb[i]; | ||||
a->limb[i] = carry & LMASK; | a->limb[i] = carry & LMASK; | ||||
@@ -273,7 +273,7 @@ snv decaf_448_subx( | |||||
const decaf_448_scalar_t p, | const decaf_448_scalar_t p, | ||||
decaf_word_t extra | decaf_word_t extra | ||||
) { | ) { | ||||
decaf_sdword_t chain = 0; | |||||
decaf_dsword_t chain = 0; | |||||
unsigned int i; | unsigned int i; | ||||
for (i=0; i<DECAF_448_SCALAR_LIMBS; i++) { | for (i=0; i<DECAF_448_SCALAR_LIMBS; i++) { | ||||
chain = (chain + accum[i]) - sub->limb[i]; | chain = (chain + accum[i]) - sub->limb[i]; | ||||
@@ -458,7 +458,7 @@ static decaf_bool_t gf_deser(gf s, const unsigned char ser[DECAF_448_SER_BYTES]) | |||||
} | } | ||||
} | } | ||||
decaf_sdword_t accum = 0; | |||||
decaf_dsword_t accum = 0; | |||||
FOR_LIMB(i, accum = (accum + s->limb[i] - P->limb[i]) >> WBITS ); | FOR_LIMB(i, accum = (accum + s->limb[i] - P->limb[i]) >> WBITS ); | ||||
return accum; | return accum; | ||||
} | } | ||||
@@ -563,7 +563,7 @@ decaf_bool_t decaf_448_scalar_decode( | |||||
s->limb[i] = out; | s->limb[i] = out; | ||||
} | } | ||||
decaf_sdword_t accum = 0; | |||||
decaf_dsword_t accum = 0; | |||||
for (i=0; i<DECAF_448_SCALAR_LIMBS; i++) { | for (i=0; i<DECAF_448_SCALAR_LIMBS; i++) { | ||||
accum = (accum + s->limb[i] - decaf_448_scalar_p->limb[i]) >> WBITS; | accum = (accum + s->limb[i] - decaf_448_scalar_p->limb[i]) >> WBITS; | ||||
} | } | ||||
@@ -12,6 +12,8 @@ | |||||
#define __STDC_WANT_LIB_EXT1__ 1 /* for memset_s */ | #define __STDC_WANT_LIB_EXT1__ 1 /* for memset_s */ | ||||
#include <decaf.h> | #include <decaf.h> | ||||
#include <string.h> | #include <string.h> | ||||
#include "word.h" | |||||
#include "field.h" | #include "field.h" | ||||
#include "decaf_config.h" | #include "decaf_config.h" | ||||
@@ -183,7 +185,7 @@ snv sc_subx( | |||||
const scalar_t p, | const scalar_t p, | ||||
decaf_word_t extra | decaf_word_t extra | ||||
) { | ) { | ||||
decaf_sdword_t chain = 0; | |||||
dsword_t chain = 0; | |||||
unsigned int i; | unsigned int i; | ||||
for (i=0; i<SCALAR_LIMBS; i++) { | for (i=0; i<SCALAR_LIMBS; i++) { | ||||
chain = (chain + accum[i]) - sub->limb[i]; | chain = (chain + accum[i]) - sub->limb[i]; | ||||
@@ -710,7 +712,7 @@ decaf_bool_t API_NS(scalar_decode)( | |||||
) { | ) { | ||||
unsigned int i; | unsigned int i; | ||||
scalar_decode_short(s, ser, SER_BYTES); | scalar_decode_short(s, ser, SER_BYTES); | ||||
decaf_sdword_t accum = 0; | |||||
dsword_t accum = 0; | |||||
for (i=0; i<SCALAR_LIMBS; i++) { | for (i=0; i<SCALAR_LIMBS; i++) { | ||||
accum = (accum + s->limb[i] - sc_p->limb[i]) >> WBITS; | accum = (accum + s->limb[i] - sc_p->limb[i]) >> WBITS; | ||||
} | } | ||||
@@ -1 +1,2 @@ | |||||
#define WORD_BITS 64 | #define WORD_BITS 64 | ||||
#define DECAF_255_LIMB_BITS 51 |
@@ -1 +1,2 @@ | |||||
#define WORD_BITS 64 | #define WORD_BITS 64 | ||||
#define DECAF_255_LIMB_BITS 51 |
@@ -11,7 +11,7 @@ | |||||
#include "decaf/decaf_255.h" | #include "decaf/decaf_255.h" | ||||
#include "word.h" | #include "word.h" | ||||
#define LBITS 51 | |||||
#define DECAF_255_LIMB_BITS 51 | |||||
#define FIELD_LITERAL(a,b,c,d,e) {{ a,b,c,d,e }} | #define FIELD_LITERAL(a,b,c,d,e) {{ a,b,c,d,e }} | ||||
/* | /* | ||||
@@ -1 +1,2 @@ | |||||
#define WORD_BITS 32 | #define WORD_BITS 32 | ||||
#define DECAF_448_LIMB_BITS 28 |
@@ -1 +1,2 @@ | |||||
#define WORD_BITS 32 | #define WORD_BITS 32 | ||||
#define DECAF_448_LIMB_BITS 28 |
@@ -1 +1,3 @@ | |||||
#define WORD_BITS 32 | #define WORD_BITS 32 | ||||
#define DECAF_448_LIMB_BITS 28 | |||||
@@ -1 +1,3 @@ | |||||
#define WORD_BITS 64 | #define WORD_BITS 64 | ||||
#define DECAF_448_LIMB_BITS 56 | |||||
@@ -1 +1,2 @@ | |||||
#define WORD_BITS 64 | #define WORD_BITS 64 | ||||
#define DECAF_448_LIMB_BITS 56 |
@@ -32,6 +32,7 @@ | |||||
/** @endcond */ | /** @endcond */ | ||||
/* Internal word types */ | /* Internal word types */ | ||||
/* TODO: decide this internally, per curve, based on how it was built! */ | |||||
#if (defined(__ILP64__) || defined(__amd64__) || defined(__x86_64__) || (((__UINT_FAST32_MAX__)>>30)>>30)) \ | #if (defined(__ILP64__) || defined(__amd64__) || defined(__x86_64__) || (((__UINT_FAST32_MAX__)>>30)>>30)) \ | ||||
&& !defined(DECAF_FORCE_32_BIT) | && !defined(DECAF_FORCE_32_BIT) | ||||
#define DECAF_WORD_BITS 64 | #define DECAF_WORD_BITS 64 | ||||