Kaynağa Gözat

move (non-hot) add/sub to per_field.c and make them not inline

master
Mike Hamburg 8 yıl önce
ebeveyn
işleme
7b7a27eac8
3 değiştirilmiş dosya ile 20 ekleme ve 34 silme
  1. +6
    -0
      src/gen_headers/f_field_h.py
  2. +1
    -34
      src/include/field.h
  3. +13
    -0
      src/per_field.c

+ 6
- 0
src/gen_headers/f_field_h.py Dosyayı Görüntüle

@@ -28,6 +28,8 @@ typedef struct gf_%(gf_shortname)s_s {
#define gf_s gf_%(gf_shortname)s_s
#define gf_eq gf_%(gf_shortname)s_eq
#define gf_copy gf_%(gf_shortname)s_copy
#define gf_add gf_%(gf_shortname)s_add
#define gf_sub gf_%(gf_shortname)s_sub
#define gf_add_RAW gf_%(gf_shortname)s_add_RAW
#define gf_sub_RAW gf_%(gf_shortname)s_sub_RAW
#define gf_bias gf_%(gf_shortname)s_bias
@@ -58,13 +60,17 @@ static INLINE_UNUSED void gf_bias (gf inout, int amount);
static INLINE_UNUSED void gf_weak_reduce (gf inout);

void gf_strong_reduce (gf inout);
void gf_add (gf out, const gf a, const gf b);
void gf_sub (gf out, const gf a, const gf b);
void gf_mul (gf_s *__restrict__ out, const gf a, const gf b);
void gf_mulw (gf_s *__restrict__ out, const gf a, uint64_t b);
void gf_sqr (gf_s *__restrict__ out, const gf a);
void gf_serialize (uint8_t *serial, const gf x);
void gf_isr(gf a, const gf x); /** a^2 x = 1, QNR, or 0 if x=0 */
mask_t gf_eq (const gf x, const gf y);
mask_t gf_deserialize (gf x, const uint8_t serial[(GF_BITS-1)/8+1]);


#ifdef __cplusplus
} /* extern "C" */
#endif


+ 1
- 34
src/include/field.h Dosyayı Görüntüle

@@ -13,20 +13,8 @@
#include "constant_time.h"
#include "f_field.h"
#include <string.h>

/**
* Returns 1/sqrt(+- x).
*
* The Legendre symbol of the result is the same as that of the
* input.
*
* If x=0, returns 0.
*/
void gf_isr(gf a, const gf x);
/**
* Square x, n times.
*/
/** Square x, n times. */
static INLINE UNUSED void
gf_sqrn (
gf_s *__restrict__ y,
@@ -49,27 +37,6 @@ gf_sqrn (
}
}

static __inline__ void
gf_sub (
gf d,
const gf a,
const gf b
) {
gf_sub_RAW ( d, a, b );
gf_bias( d, 2 );
gf_weak_reduce ( d );
}

static __inline__ void
gf_add (
gf d,
const gf a,
const gf b
) {
gf_add_RAW ( d, a, b );
gf_weak_reduce ( d );
}

#define gf_add_nr gf_add_RAW

/** Subtract mod p. Bias by 2 and don't reduce */


+ 13
- 0
src/per_field.c Dosyayı Görüntüle

@@ -85,6 +85,19 @@ void gf_strong_reduce (gf a) {
assert(word_is_zero(carry + scarry_0));
}

/** Add two gf elements */
void gf_sub (gf d, const gf a, const gf b) {
gf_sub_RAW ( d, a, b );
gf_bias( d, 2 );
gf_weak_reduce ( d );
}

/** Subtract d = a-b */
void gf_add (gf d, const gf a, const gf b) {
gf_add_RAW ( d, a, b );
gf_weak_reduce ( d );
}

/** Compare a==b */
mask_t gf_eq(const gf a, const gf b) {
gf c;


Yükleniyor…
İptal
Kaydet