From 7b7a27eac8b6c2610c1e08ca8ba8d288302419ff Mon Sep 17 00:00:00 2001 From: Mike Hamburg Date: Fri, 15 Jan 2016 15:22:47 -0800 Subject: [PATCH] move (non-hot) add/sub to per_field.c and make them not inline --- src/gen_headers/f_field_h.py | 6 ++++++ src/include/field.h | 35 +---------------------------------- src/per_field.c | 13 +++++++++++++ 3 files changed, 20 insertions(+), 34 deletions(-) diff --git a/src/gen_headers/f_field_h.py b/src/gen_headers/f_field_h.py index 44fbcee..0c75137 100644 --- a/src/gen_headers/f_field_h.py +++ b/src/gen_headers/f_field_h.py @@ -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 diff --git a/src/include/field.h b/src/include/field.h index 9850f1c..0846a47 100644 --- a/src/include/field.h +++ b/src/include/field.h @@ -13,20 +13,8 @@ #include "constant_time.h" #include "f_field.h" #include - -/** - * 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 */ diff --git a/src/per_field.c b/src/per_field.c index b1453dd..16030a6 100644 --- a/src/per_field.c +++ b/src/per_field.c @@ -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;