libdecaf
f_field.h
Go to the documentation of this file.
1
15#ifndef __P448_F_FIELD_H__
16#define __P448_F_FIELD_H__ 1
17
18#include "constant_time.h"
19#include <string.h>
20#include <assert.h>
21
22#include "word.h"
23
24#define __DECAF_448_GF_DEFINED__ 1
25#define NLIMBS (64/sizeof(word_t))
26#define SER_BYTES 56
27typedef struct gf_448_s {
28 word_t limb[NLIMBS];
29} __attribute__((aligned(32))) gf_448_s, gf_448_t[1];
30
31#define GF_LIT_LIMB_BITS 56
32#define GF_BITS 448
33#define ZERO gf_448_ZERO
34#define ONE gf_448_ONE
35#define MODULUS gf_448_MODULUS
36#define gf gf_448_t
37#define gf_s gf_448_s
38#define gf_eq gf_448_eq
39#define gf_lobit gf_448_lobit
40#define gf_copy gf_448_copy
41#define gf_add gf_448_add
42#define gf_sub gf_448_sub
43#define gf_add_RAW gf_448_add_RAW
44#define gf_sub_RAW gf_448_sub_RAW
45#define gf_bias gf_448_bias
46#define gf_weak_reduce gf_448_weak_reduce
47#define gf_strong_reduce gf_448_strong_reduce
48#define gf_mul gf_448_mul
49#define gf_sqr gf_448_sqr
50#define gf_mulw_unsigned gf_448_mulw_unsigned
51#define gf_isr gf_448_isr
52#define gf_serialize gf_448_serialize
53#define gf_deserialize gf_448_deserialize
54
55/* RFC 7748 support */
56#define X_PUBLIC_BYTES SER_BYTES
57#define X_PRIVATE_BYTES X_PUBLIC_BYTES
58#define X_PRIVATE_BITS 448
59
60#define SQRT_MINUS_ONE P448_SQRT_MINUS_ONE /* might not be defined */
61
62#define INLINE_UNUSED __inline__ __attribute__((unused,always_inline))
63
64#ifdef __cplusplus
65extern "C" {
66#endif
67
68/* Defined below in f_impl.h */
69static INLINE_UNUSED void gf_copy (gf out, const gf a) { *out = *a; }
70static INLINE_UNUSED void gf_add_RAW (gf out, const gf a, const gf b);
71static INLINE_UNUSED void gf_sub_RAW (gf out, const gf a, const gf b);
72static INLINE_UNUSED void gf_bias (gf inout, int amount);
73static INLINE_UNUSED void gf_weak_reduce (gf inout);
74
75void gf_strong_reduce (gf inout);
76void gf_add (gf out, const gf a, const gf b);
77void gf_sub (gf out, const gf a, const gf b);
78void gf_mul (gf_s *__restrict__ out, const gf a, const gf b);
79void gf_mulw_unsigned (gf_s *__restrict__ out, const gf a, uint32_t b);
80void gf_sqr (gf_s *__restrict__ out, const gf a);
81mask_t gf_isr(gf a, const gf x);
82mask_t gf_eq (const gf x, const gf y);
83mask_t gf_lobit (const gf x);
84
85void gf_serialize (uint8_t serial[SER_BYTES], const gf x);
86mask_t gf_deserialize (gf x, const uint8_t serial[SER_BYTES],uint8_t hi_nmask);
87
88
89#ifdef __cplusplus
90} /* extern "C" */
91#endif
92
93#include "f_impl.h" /* Bring in the inline implementations */
94
95#define P_MOD_8 7
96#if P_MOD_8 == 5
97 extern const gf SQRT_MINUS_ONE;
98#endif
99
100#ifndef LIMBPERM
101 #define LIMBPERM(i) (i)
102#endif
103#define LIMB_MASK(i) (((1ull)<<LIMB_PLACE_VALUE(i))-1)
104
105static const gf ZERO = {{{0}}}, ONE = {{{ [LIMBPERM(0)] = 1 }}};
106
107#endif /* __P448_F_FIELD_H__ */
void gf_sub(gf out, const gf a, const gf b)
Subtract two gf elements d=a-b.
Definition: f_generic.c:110
mask_t gf_lobit(const gf x)
Return high bit of x = low bit of 2x mod p.
Definition: f_generic.c:47
void gf_serialize(uint8_t serial[SER_BYTES], const gf x)
Serialize to wire format.
Definition: f_generic.c:27
mask_t gf_eq(const gf x, const gf y)
a^2 x = 1, QNR, or 0 if x=0.
Definition: f_generic.c:123
void gf_add(gf out, const gf a, const gf b)
Add two field elements d = a+b.
Definition: f_generic.c:117
mask_t gf_deserialize(gf x, const uint8_t serial[SER_BYTES], uint8_t hi_nmask)
Deserialize from wire format; return -1 on success and 0 on failure.
Definition: f_generic.c:55
void gf_strong_reduce(gf inout)
Reduce to canonical form.
Definition: f_generic.c:76
Definition: f_field.h:27