Browse Source

normalize some of the word and limb size declarations, still not entirely happy on that front

master
Michael Hamburg 10 years ago
parent
commit
bdf4375b52
13 changed files with 21 additions and 16 deletions
  1. +1
    -2
      src/curve_ed25519/curve_data.inc.c
  2. +1
    -7
      src/curve_ed448goldilocks/curve_data.inc.c
  3. +4
    -4
      src/decaf.c
  4. +4
    -2
      src/decaf_fast.c
  5. +1
    -0
      src/p25519/arch_ref64/arch_config.h
  6. +1
    -0
      src/p25519/arch_x86_64/arch_config.h
  7. +1
    -1
      src/p25519/arch_x86_64/f_impl.h
  8. +1
    -0
      src/p448/arch_32/arch_config.h
  9. +1
    -0
      src/p448/arch_arm_32/arch_config.h
  10. +2
    -0
      src/p448/arch_neon_experimental/arch_config.h
  11. +2
    -0
      src/p448/arch_ref64/arch_config.h
  12. +1
    -0
      src/p448/arch_x86_64/arch_config.h
  13. +1
    -0
      src/public_include/decaf/common.h

+ 1
- 2
src/curve_ed25519/curve_data.inc.c View File

@@ -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


+ 1
- 7
src/curve_ed448goldilocks/curve_data.inc.c View File

@@ -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)-1), (x##ull)>>LBITS
#define SC_LIMB(x) (x##ull)&((1ull<<32)-1), (x##ull)>>32
#else
#error "Only supporting 32- and 64-bit platforms right now"


+ 4
- 4
src/decaf.c View File

@@ -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; i<DECAF_448_SCALAR_LIMBS; 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 );
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; i<DECAF_448_SCALAR_LIMBS; i++) {
accum = (accum + s->limb[i] - decaf_448_scalar_p->limb[i]) >> WBITS;
}


+ 4
- 2
src/decaf_fast.c View File

@@ -12,6 +12,8 @@
#define __STDC_WANT_LIB_EXT1__ 1 /* for memset_s */
#include <decaf.h>
#include <string.h>

#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; i<SCALAR_LIMBS; i++) {
chain = (chain + accum[i]) - sub->limb[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; i<SCALAR_LIMBS; i++) {
accum = (accum + s->limb[i] - sc_p->limb[i]) >> WBITS;
}


+ 1
- 0
src/p25519/arch_ref64/arch_config.h View File

@@ -1 +1,2 @@
#define WORD_BITS 64
#define DECAF_255_LIMB_BITS 51

+ 1
- 0
src/p25519/arch_x86_64/arch_config.h View File

@@ -1 +1,2 @@
#define WORD_BITS 64
#define DECAF_255_LIMB_BITS 51

+ 1
- 1
src/p25519/arch_x86_64/f_impl.h View File

@@ -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 }}

/*


+ 1
- 0
src/p448/arch_32/arch_config.h View File

@@ -1 +1,2 @@
#define WORD_BITS 32
#define DECAF_448_LIMB_BITS 28

+ 1
- 0
src/p448/arch_arm_32/arch_config.h View File

@@ -1 +1,2 @@
#define WORD_BITS 32
#define DECAF_448_LIMB_BITS 28

+ 2
- 0
src/p448/arch_neon_experimental/arch_config.h View File

@@ -1 +1,3 @@
#define WORD_BITS 32
#define DECAF_448_LIMB_BITS 28


+ 2
- 0
src/p448/arch_ref64/arch_config.h View File

@@ -1 +1,3 @@
#define WORD_BITS 64
#define DECAF_448_LIMB_BITS 56


+ 1
- 0
src/p448/arch_x86_64/arch_config.h View File

@@ -1 +1,2 @@
#define WORD_BITS 64
#define DECAF_448_LIMB_BITS 56

+ 1
- 0
src/public_include/decaf/common.h View File

@@ -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


Loading…
Cancel
Save