2 * Copyright 2017 The OpenSSL Project Authors. All Rights Reserved.
3 * Copyright 2015-2016 Cryptography Research, Inc.
5 * Licensed under the OpenSSL license (the "License"). You may not use
6 * this file except in compliance with the License. You can obtain a copy
7 * in the file LICENSE in the source distribution or at
8 * https://www.openssl.org/source/license.html
10 * Originally written by Mike Hamburg
13 #ifndef __P448_F_FIELD_H__
14 # define __P448_F_FIELD_H__ 1
16 # include "constant_time.h"
22 # define __DECAF_448_GF_DEFINED__ 1
23 # define NLIMBS (64/sizeof(word_t))
24 # define X_SER_BYTES 56
26 typedef struct gf_448_s {
28 } __attribute__ ((aligned(32))) gf_448_s, gf_448_t[1];
30 # define GF_LIT_LIMB_BITS 56
32 # define ZERO gf_448_ZERO
33 # define ONE gf_448_ONE
34 # define MODULUS gf_448_MODULUS
36 # define gf_s gf_448_s
37 # define gf_eq gf_448_eq
38 # define gf_hibit gf_448_hibit
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
55 /* RFC 7748 support */
56 # define X_PUBLIC_BYTES X_SER_BYTES
57 # define X_PRIVATE_BYTES X_PUBLIC_BYTES
58 # define X_PRIVATE_BITS 448
60 # define INLINE_UNUSED __inline__ __attribute__((unused,always_inline))
66 /* Defined below in f_impl.h */
67 static INLINE_UNUSED void gf_copy(gf out, const gf a)
72 static INLINE_UNUSED void gf_add_RAW(gf out, const gf a, const gf b);
73 static INLINE_UNUSED void gf_sub_RAW(gf out, const gf a, const gf b);
74 static INLINE_UNUSED void gf_bias(gf inout, int amount);
75 static INLINE_UNUSED void gf_weak_reduce(gf inout);
77 void gf_strong_reduce(gf inout);
78 void gf_add(gf out, const gf a, const gf b);
79 void gf_sub(gf out, const gf a, const gf b);
80 void gf_mul(gf_s * __restrict__ out, const gf a, const gf b);
81 void gf_mulw_unsigned(gf_s * __restrict__ out, const gf a, uint32_t b);
82 void gf_sqr(gf_s * __restrict__ out, const gf a);
83 mask_t gf_isr(gf a, const gf x); /** a^2 x = 1, QNR, or 0 if x=0. Return true if successful */
84 mask_t gf_eq(const gf x, const gf y);
85 mask_t gf_lobit(const gf x);
86 mask_t gf_hibit(const gf x);
88 void gf_serialize(uint8_t *serial, const gf x, int with_highbit);
89 mask_t gf_deserialize(gf x, const uint8_t serial[SER_BYTES], int with_hibit,
97 # include "f_impl.h" /* Bring in the inline implementations */
100 # define LIMBPERM(i) (i)
102 # define LIMB_MASK(i) (((1)<<LIMB_PLACE_VALUE(i))-1)
104 static const gf ZERO = { {{0}} }, ONE = { { {
107 #endif /* __P448_F_FIELD_H__ */