diff --git a/src/curve_ed25519/curve_data.inc.c b/src/curve_ed25519/curve_data.inc.c index a9b1a0c..ac8b018 100644 --- a/src/curve_ed25519/curve_data.inc.c +++ b/src/curve_ed25519/curve_data.inc.c @@ -1,9 +1,8 @@ // FIXME move to arch or something #define WBITS DECAF_WORD_BITS +#define LBITS DECAF_255_LIMB_BITS #if WBITS == 64 -#define LBITS 51 -typedef __int128_t decaf_sdword_t; #define LIMB(x) (x##ull) #define SC_LIMB(x) (x##ull) #else diff --git a/src/curve_ed448goldilocks/curve_data.inc.c b/src/curve_ed448goldilocks/curve_data.inc.c index 77ba847..6977044 100644 --- a/src/curve_ed448goldilocks/curve_data.inc.c +++ b/src/curve_ed448goldilocks/curve_data.inc.c @@ -1,15 +1,9 @@ -// FIXME move to arch or something #define WBITS DECAF_WORD_BITS +// #define LBITS DECAF_448_LIMB_BITS // FIXME #if WBITS == 64 -#define LBITS 56 -typedef __int128_t decaf_sdword_t; -#define LIMB(x) (x##ull) #define SC_LIMB(x) (x##ull) #elif WBITS == 32 -typedef int64_t decaf_sdword_t; -#define LBITS 28 -#define LIMB(x) (x##ull)&((1ull<>LBITS #define SC_LIMB(x) (x##ull)&((1ull<<32)-1), (x##ull)>>32 #else #error "Only supporting 32- and 64-bit platforms right now" diff --git a/src/decaf.c b/src/decaf.c index 9b342f2..f0e197f 100644 --- a/src/decaf.c +++ b/src/decaf.c @@ -213,7 +213,7 @@ snv gf_canon ( gf a ) { gf_reduce(a); /* subtract p with borrow */ - decaf_sdword_t carry = 0; + decaf_dsword_t carry = 0; FOR_LIMB(i, { carry = carry + a->limb[i] - P->limb[i]; a->limb[i] = carry & LMASK; @@ -273,7 +273,7 @@ snv decaf_448_subx( const decaf_448_scalar_t p, decaf_word_t extra ) { - decaf_sdword_t chain = 0; + decaf_dsword_t chain = 0; unsigned int i; for (i=0; ilimb[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 ); return accum; } @@ -563,7 +563,7 @@ decaf_bool_t decaf_448_scalar_decode( s->limb[i] = out; } - decaf_sdword_t accum = 0; + decaf_dsword_t accum = 0; for (i=0; ilimb[i] - decaf_448_scalar_p->limb[i]) >> WBITS; } diff --git a/src/decaf_fast.c b/src/decaf_fast.c index 2a19f4f..902eb18 100644 --- a/src/decaf_fast.c +++ b/src/decaf_fast.c @@ -12,6 +12,8 @@ #define __STDC_WANT_LIB_EXT1__ 1 /* for memset_s */ #include #include + +#include "word.h" #include "field.h" #include "decaf_config.h" @@ -183,7 +185,7 @@ snv sc_subx( const scalar_t p, decaf_word_t extra ) { - decaf_sdword_t chain = 0; + dsword_t chain = 0; unsigned int i; for (i=0; ilimb[i]; @@ -710,7 +712,7 @@ decaf_bool_t API_NS(scalar_decode)( ) { unsigned int i; scalar_decode_short(s, ser, SER_BYTES); - decaf_sdword_t accum = 0; + dsword_t accum = 0; for (i=0; ilimb[i] - sc_p->limb[i]) >> WBITS; } diff --git a/src/p25519/arch_ref64/arch_config.h b/src/p25519/arch_ref64/arch_config.h index 58758cc..b9504c3 100644 --- a/src/p25519/arch_ref64/arch_config.h +++ b/src/p25519/arch_ref64/arch_config.h @@ -1 +1,2 @@ #define WORD_BITS 64 +#define DECAF_255_LIMB_BITS 51 \ No newline at end of file diff --git a/src/p25519/arch_x86_64/arch_config.h b/src/p25519/arch_x86_64/arch_config.h index 58758cc..6d2cbd9 100644 --- a/src/p25519/arch_x86_64/arch_config.h +++ b/src/p25519/arch_x86_64/arch_config.h @@ -1 +1,2 @@ #define WORD_BITS 64 +#define DECAF_255_LIMB_BITS 51 diff --git a/src/p25519/arch_x86_64/f_impl.h b/src/p25519/arch_x86_64/f_impl.h index 0276379..a90702d 100644 --- a/src/p25519/arch_x86_64/f_impl.h +++ b/src/p25519/arch_x86_64/f_impl.h @@ -11,7 +11,7 @@ #include "decaf/decaf_255.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 }} /* diff --git a/src/p448/arch_32/arch_config.h b/src/p448/arch_32/arch_config.h index 47bbe3e..d4ada31 100644 --- a/src/p448/arch_32/arch_config.h +++ b/src/p448/arch_32/arch_config.h @@ -1 +1,2 @@ #define WORD_BITS 32 +#define DECAF_448_LIMB_BITS 28 diff --git a/src/p448/arch_arm_32/arch_config.h b/src/p448/arch_arm_32/arch_config.h index 47bbe3e..d4ada31 100644 --- a/src/p448/arch_arm_32/arch_config.h +++ b/src/p448/arch_arm_32/arch_config.h @@ -1 +1,2 @@ #define WORD_BITS 32 +#define DECAF_448_LIMB_BITS 28 diff --git a/src/p448/arch_neon_experimental/arch_config.h b/src/p448/arch_neon_experimental/arch_config.h index 47bbe3e..e65216f 100644 --- a/src/p448/arch_neon_experimental/arch_config.h +++ b/src/p448/arch_neon_experimental/arch_config.h @@ -1 +1,3 @@ #define WORD_BITS 32 +#define DECAF_448_LIMB_BITS 28 + diff --git a/src/p448/arch_ref64/arch_config.h b/src/p448/arch_ref64/arch_config.h index 58758cc..f58980e 100644 --- a/src/p448/arch_ref64/arch_config.h +++ b/src/p448/arch_ref64/arch_config.h @@ -1 +1,3 @@ #define WORD_BITS 64 +#define DECAF_448_LIMB_BITS 56 + diff --git a/src/p448/arch_x86_64/arch_config.h b/src/p448/arch_x86_64/arch_config.h index 58758cc..3f449f4 100644 --- a/src/p448/arch_x86_64/arch_config.h +++ b/src/p448/arch_x86_64/arch_config.h @@ -1 +1,2 @@ #define WORD_BITS 64 +#define DECAF_448_LIMB_BITS 56 diff --git a/src/public_include/decaf/common.h b/src/public_include/decaf/common.h index 2e56c66..1b9c988 100644 --- a/src/public_include/decaf/common.h +++ b/src/public_include/decaf/common.h @@ -32,6 +32,7 @@ /** @endcond */ /* 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)) \ && !defined(DECAF_FORCE_32_BIT) #define DECAF_WORD_BITS 64