Commit 4218223d authored by Michael Hamburg's avatar Michael Hamburg

generate most of f_impl.h. Not tested on most arches yet :-(

parent 294eabae
......@@ -9,22 +9,52 @@ f_field_h = gen_file(
#include "constant_time.h"
#include <string.h>
#include "f_impl.h"
#include "decaf/decaf_%(gf_bits)s.h" /* HACK in genheader */
#include "word.h"
#define GF_LIT_LIMB_BITS %(gf_lit_limb_bits)d
#define GF_BITS %(gf_bits)d
#define gf gf_%(gf_shortname)s_t
#define gf_s gf_%(gf_shortname)s_s
#define gf_mul gf_%(gf_shortname)s_mul
#define gf_sqr gf_%(gf_shortname)s_sqr
#define gf_copy gf_%(gf_shortname)s_copy
#define gf_add_RAW gf_%(gf_shortname)s_add_RAW
#define gf_sub_RAW gf_%(gf_shortname)s_sub_RAW
#define gf_mulw gf_%(gf_shortname)s_mulw
#define gf_bias gf_%(gf_shortname)s_bias
#define gf_isr gf_%(gf_shortname)s_isr
#define gf_weak_reduce gf_%(gf_shortname)s_weak_reduce
#define gf_strong_reduce gf_%(gf_shortname)s_strong_reduce
#define gf_mul gf_%(gf_shortname)s_mul
#define gf_sqr gf_%(gf_shortname)s_sqr
#define gf_mulw gf_%(gf_shortname)s_mulw
#define gf_isr gf_%(gf_shortname)s_isr
#define gf_serialize gf_%(gf_shortname)s_serialize
#define gf_deserialize gf_%(gf_shortname)s_deserialize
#define SQRT_MINUS_ONE P%(gf_shortname)s_SQRT_MINUS_ONE /* might not be defined */
#define INLINE_UNUSED __inline__ __attribute__((unused,always_inline))
#ifdef __cplusplus
extern "C" {
#endif
/* Defined below in f_impl.h */
static INLINE_UNUSED void gf_copy (gf out, const gf a) { *out = *a; }
static INLINE_UNUSED void gf_add_RAW (gf out, const gf a, const gf b);
static INLINE_UNUSED void gf_sub_RAW (gf out, const gf a, const gf b);
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_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);
mask_t gf_deserialize (gf x, const uint8_t serial[(GF_BITS-1)/8+1]);
#ifdef __cplusplus
} /* extern "C" */
#endif
#include "f_impl.h" /* Bring in the inline implementations */
""")
\ No newline at end of file
......@@ -2,7 +2,7 @@
* Released under the MIT License. See LICENSE.txt for license information.
*/
#include "f_impl.h"
#include "f_field.h"
static __inline__ __uint128_t widemul(
const uint64_t a,
......
......@@ -14,88 +14,10 @@
#define LBITS 51
#define FIELD_LITERAL(a,b,c,d,e) {{ a,b,c,d,e }}
/*
#define FIELD_LITERAL(a,b,c,d) {{ \
(a##ull) & LMASK, \
((a##ull)>>51 | (b##ull)<<13) & LMASK, \
((b##ull)>>38 | (c##ull)<<26) & LMASK, \
((c##ull)>>25 | (d##ull)<<39) & LMASK, \
(d##ull)>>12 \
}}
*/
#ifdef __cplusplus
extern "C" {
#endif
static __inline__ void
gf_25519_add_RAW (
gf_25519_t out,
const gf_25519_t a,
const gf_25519_t b
) __attribute__((unused));
static __inline__ void
gf_25519_sub_RAW (
gf_25519_t out,
const gf_25519_t a,
const gf_25519_t b
) __attribute__((unused));
static __inline__ void
gf_25519_copy (
gf_25519_t out,
const gf_25519_t a
) __attribute__((unused));
static __inline__ void
gf_25519_weak_reduce (
gf_25519_t inout
) __attribute__((unused));
void
gf_25519_strong_reduce (
gf_25519_t inout
);
static __inline__ void
gf_25519_bias (
gf_25519_t inout,
int amount
) __attribute__((unused));
void
gf_25519_mul (
gf_25519_s *__restrict__ out,
const gf_25519_t a,
const gf_25519_t b
);
void
gf_25519_mulw (
gf_25519_s *__restrict__ out,
const gf_25519_t a,
uint64_t b
);
void
gf_25519_sqr (
gf_25519_s *__restrict__ out,
const gf_25519_t a
);
void
gf_25519_serialize (
uint8_t serial[32],
const gf_25519_t x
);
mask_t
gf_25519_deserialize (
gf_25519_t x,
const uint8_t serial[32]
);
/* -------------- Inline functions begin here -------------- */
void
......
......@@ -2,7 +2,7 @@
* Released under the MIT License. See LICENSE.txt for license information.
*/
#include "f_impl.h"
#include "f_field.h"
#include "x86-64-arith.h"
static inline uint64_t shr(__uint128_t x, int n) {
......
......@@ -14,88 +14,6 @@
#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) {{ \
(a##ull) & LMASK, \
((a##ull)>>51 | (b##ull)<<13) & LMASK, \
((b##ull)>>38 | (c##ull)<<26) & LMASK, \
((c##ull)>>25 | (d##ull)<<39) & LMASK, \
(d##ull)>>12 \
}}
*/
#ifdef __cplusplus
extern "C" {
#endif
static __inline__ void
gf_25519_add_RAW (
gf_25519_t out,
const gf_25519_t a,
const gf_25519_t b
) __attribute__((unused));
static __inline__ void
gf_25519_sub_RAW (
gf_25519_t out,
const gf_25519_t a,
const gf_25519_t b
) __attribute__((unused));
static __inline__ void
gf_25519_copy (
gf_25519_t out,
const gf_25519_t a
) __attribute__((unused));
static __inline__ void
gf_25519_weak_reduce (
gf_25519_t inout
) __attribute__((unused));
void
gf_25519_strong_reduce (
gf_25519_t inout
);
static __inline__ void
gf_25519_bias (
gf_25519_t inout,
int amount
) __attribute__((unused));
void
gf_25519_mul (
gf_25519_s *__restrict__ out,
const gf_25519_t a,
const gf_25519_t b
);
void
gf_25519_mulw (
gf_25519_s *__restrict__ out,
const gf_25519_t a,
uint64_t b
);
void
gf_25519_sqr (
gf_25519_s *__restrict__ out,
const gf_25519_t a
);
void
gf_25519_serialize (
uint8_t serial[32],
const gf_25519_t x
);
mask_t
gf_25519_deserialize (
gf_25519_t x,
const uint8_t serial[32]
);
/* -------------- Inline functions begin here -------------- */
void
......@@ -123,14 +41,6 @@ gf_25519_sub_RAW (
}
}
void
gf_25519_copy (
gf_25519_t out,
const gf_25519_t a
) {
memcpy(out,a,sizeof(*a));
}
void
gf_25519_bias (
gf_25519_t a,
......
......@@ -2,8 +2,7 @@
* Released under the MIT License. See LICENSE.txt for license information.
*/
#include "word.h"
#include "f_impl.h"
#include "f_field.h"
static inline mask_t __attribute__((always_inline))
is_zero (
......
......@@ -22,74 +22,6 @@ typedef struct gf_448_s {
extern "C" {
#endif
static __inline__ void
gf_448_add_RAW (
gf_448_t out,
const gf_448_t a,
const gf_448_t b
) __attribute__((unused,always_inline));
static __inline__ void
gf_448_sub_RAW (
gf_448_t out,
const gf_448_t a,
const gf_448_t b
) __attribute__((unused,always_inline));
static __inline__ void
gf_448_copy (
gf_448_t out,
const gf_448_t a
) __attribute__((unused,always_inline));
static __inline__ void
gf_448_weak_reduce (
gf_448_t inout
) __attribute__((unused,always_inline));
void
gf_448_strong_reduce (
gf_448_t inout
);
static __inline__ void
gf_448_bias (
gf_448_t inout,
int amount
) __attribute__((unused,always_inline));
void
gf_448_mul (
gf_448_s *__restrict__ out,
const gf_448_t a,
const gf_448_t b
);
void
gf_448_mulw (
gf_448_s *__restrict__ out,
const gf_448_t a,
uint64_t b
);
void
gf_448_sqr (
gf_448_s *__restrict__ out,
const gf_448_t a
);
void
gf_448_serialize (
uint8_t *serial,
const gf_448_t x
);
mask_t
gf_448_deserialize (
gf_448_t x,
const uint8_t serial[56]
);
/* -------------- Inline functions begin here -------------- */
void
......@@ -128,14 +60,6 @@ gf_448_sub_RAW (
*/
}
void
gf_448_copy (
gf_448_t out,
const gf_448_t a
) {
*out = *a;
}
void
gf_448_bias (
gf_448_t a,
......
......@@ -2,8 +2,7 @@
* Released under the MIT License. See LICENSE.txt for license information.
*/
#include "word.h"
#include "f_impl.h"
#include "f_field.h"
static inline mask_t __attribute__((always_inline))
is_zero (
......
......@@ -22,74 +22,6 @@ typedef struct gf_448_s {
extern "C" {
#endif
static __inline__ void
gf_448_add_RAW (
gf_448_t out,
const gf_448_t a,
const gf_448_t b
) __attribute__((unused,always_inline));
static __inline__ void
gf_448_sub_RAW (
gf_448_t out,
const gf_448_t a,
const gf_448_t b
) __attribute__((unused,always_inline));
static __inline__ void
gf_448_copy (
gf_448_t out,
const gf_448_t a
) __attribute__((unused,always_inline));
static __inline__ void
gf_448_weak_reduce (
gf_448_t inout
) __attribute__((unused,always_inline));
void
gf_448_strong_reduce (
gf_448_t inout
);
static __inline__ void
gf_448_bias (
gf_448_t inout,
int amount
) __attribute__((unused,always_inline));
void
gf_448_mul (
gf_448_s *__restrict__ out,
const gf_448_t a,
const gf_448_t b
);
void
gf_448_mulw (
gf_448_s *__restrict__ out,
const gf_448_t a,
uint64_t b
);
void
gf_448_sqr (
gf_448_s *__restrict__ out,
const gf_448_t a
);
void
gf_448_serialize (
uint8_t *serial,
const gf_448_t x
);
mask_t
gf_448_deserialize (
gf_448_t x,
const uint8_t serial[56]
);
/* -------------- Inline functions begin here -------------- */
void
......@@ -128,14 +60,6 @@ gf_448_sub_RAW (
*/
}
void
gf_448_copy (
gf_448_t out,
const gf_448_t a
) {
*out = *a;
}
void
gf_448_bias (
gf_448_t a,
......
......@@ -2,8 +2,7 @@
* Released under the MIT License. See LICENSE.txt for license information.
*/
#include "word.h"
#include "f_impl.h"
#include "f_field.h"
static inline mask_t __attribute__((always_inline))
is_zero (
......
......@@ -27,75 +27,7 @@ typedef struct gf_448_s {
#ifdef __cplusplus
extern "C" {
#endif
static __inline__ void
gf_448_add_RAW (
gf_448_t out,
const gf_448_t a,
const gf_448_t b
) __attribute__((unused,always_inline));
static __inline__ void
gf_448_sub_RAW (
gf_448_t out,
const gf_448_t a,
const gf_448_t b
) __attribute__((unused,always_inline));
static __inline__ void
gf_448_copy (
gf_448_t out,
const gf_448_t a
) __attribute__((unused,always_inline));
static __inline__ void
gf_448_weak_reduce (
gf_448_t inout
) __attribute__((unused,always_inline));
void
gf_448_strong_reduce (
gf_448_t inout
);
static __inline__ void
gf_448_bias (
gf_448_t inout,
int amount
) __attribute__((unused,always_inline));
void
gf_448_mul (
gf_448_s *__restrict__ out,
const gf_448_t a,
const gf_448_t b
);
void
gf_448_mulw (
gf_448_s *__restrict__ out,
const gf_448_t a,
uint64_t b
);
void
gf_448_sqr (
gf_448_s *__restrict__ out,
const gf_448_t a
);
void
gf_448_serialize (
uint8_t *serial,
const gf_448_t x
);
mask_t
gf_448_deserialize (
gf_448_t x,
const uint8_t serial[56]
);
/* -------------- Inline functions begin here -------------- */
void
......@@ -128,14 +60,6 @@ gf_448_sub_RAW (
*/
}
void
gf_448_copy (
gf_448_t out,
const gf_448_t a
) {
*out = *a;
}
void
gf_448_bias (
gf_448_t a,
......
......@@ -2,7 +2,7 @@
* Released under the MIT License. See LICENSE.txt for license information.
*/
#include "f_impl.h"
#include "f_field.h"
static __inline__ __uint128_t widemul(
const uint64_t a,
......
......@@ -21,74 +21,6 @@ typedef struct gf_448_s {
extern "C" {
#endif
static __inline__ void
gf_448_add_RAW (
gf_448_t out,
const gf_448_t a,
const gf_448_t b
) __attribute__((unused));
static __inline__ void
gf_448_sub_RAW (
gf_448_t out,
const gf_448_t a,
const gf_448_t b
) __attribute__((unused));
static __inline__ void
gf_448_copy (
gf_448_t out,
const gf_448_t a
) __attribute__((unused));
static __inline__ void
gf_448_weak_reduce (
gf_448_t inout
) __attribute__((unused));
void
gf_448_strong_reduce (
gf_448_t inout
);
static __inline__ void
gf_448_bias (
gf_448_t inout,
int amount
) __attribute__((unused));
void
gf_448_mul (
gf_448_s *__restrict__ out,
const gf_448_t a,
const gf_448_t b
);
void
gf_448_mulw (
gf_448_s *__restrict__ out,
const gf_448_t a,
uint64_t b
);
void
gf_448_sqr (
gf_448_s *__restrict__ out,
const gf_448_t a
);
void
gf_448_serialize (
uint8_t *serial,
const gf_448_t x
);
mask_t
gf_448_deserialize (
gf_448_t x,
const uint8_t serial[56]
);
/* -------------- Inline functions begin here -------------- */
void
......@@ -118,14 +50,6 @@ gf_448_sub_RAW (
gf_448_weak_reduce(out);
}
void
gf_448_copy (
gf_448_t out,
const gf_448_t a
) {
memcpy(out,a,sizeof(*a));
}
void
gf_448_bias (
gf_448_t a,
......
......@@ -2,7 +2,7 @@
* Released under the MIT License. See LICENSE.txt for license information.
*/
#include "f_impl.h"
#include "f_field.h"
#include "x86-64-arith.h"
void
......
......@@ -17,74 +17,6 @@
extern "C" {
#endif
static __inline__ void
gf_448_add_RAW (
gf_448_t out,
const gf_448_t a,
const gf_448_t b
) __attribute__((unused,always_inline));
static __inline__ void
gf_448_sub_RAW (
gf_448_t out,
const gf_448_t a,
const gf_448_t b
) __attribute__((unused,always_inline));
static __inline__ void
gf_448_copy (
gf_448_t out,
const gf_448_t a
) __attribute__((unused,always_inline));
static __inline__ void
gf_448_weak_reduce (
gf_448_t inout
) __attribute__((unused,always_inline));
void
gf_448_strong_reduce (
gf_448_t inout
);
static __inline__ void
gf_448_bias (
gf_448_t inout,
int amount
) __attribute__((unused,always_inline));
void
gf_448_mul (
gf_448_s *__restrict__ out,
const gf_448_t a,
const gf_448_t b
);
void
gf_448_mulw (
gf_448_s *__restrict__ out,
const gf_448_t a,
uint64_t b
);
void
gf_448_sqr (
gf_448_s *__restrict__ out,
const gf_448_t a
);
void
gf_448_serialize (
uint8_t *serial,
const gf_448_t x
);
mask_t
gf_448_deserialize (
gf_448_t x,
const uint8_t serial[56]
);
/* -------------- Inline functions begin here -------------- */