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 NLIMBS (64/sizeof(word_t))
23 # define X_SER_BYTES 56
27 } __attribute__ ((aligned(32))) gf_s, gf[1];
29 /* RFC 7748 support */
30 # define X_PUBLIC_BYTES X_SER_BYTES
31 # define X_PRIVATE_BYTES X_PUBLIC_BYTES
32 # define X_PRIVATE_BITS 448
34 # define INLINE_UNUSED __inline__ __attribute__((unused,always_inline))
40 /* Defined below in f_impl.h */
41 static INLINE_UNUSED void gf_copy(gf out, const gf a)
46 static INLINE_UNUSED void gf_add_RAW(gf out, const gf a, const gf b);
47 static INLINE_UNUSED void gf_sub_RAW(gf out, const gf a, const gf b);
48 static INLINE_UNUSED void gf_bias(gf inout, int amount);
49 static INLINE_UNUSED void gf_weak_reduce(gf inout);
51 void gf_strong_reduce(gf inout);
52 void gf_add(gf out, const gf a, const gf b);
53 void gf_sub(gf out, const gf a, const gf b);
54 void gf_mul(gf_s * __restrict__ out, const gf a, const gf b);
55 void gf_mulw_unsigned(gf_s * __restrict__ out, const gf a, uint32_t b);
56 void gf_sqr(gf_s * __restrict__ out, const gf a);
57 mask_t gf_isr(gf a, const gf x); /** a^2 x = 1, QNR, or 0 if x=0. Return true if successful */
58 mask_t gf_eq(const gf x, const gf y);
59 mask_t gf_lobit(const gf x);
60 mask_t gf_hibit(const gf x);
62 void gf_serialize(uint8_t *serial, const gf x, int with_highbit);
63 mask_t gf_deserialize(gf x, const uint8_t serial[SER_BYTES], int with_hibit,
71 # include "f_impl.h" /* Bring in the inline implementations */
74 # define LIMBPERM(i) (i)
76 # define LIMB_MASK(i) (((1)<<LIMB_PLACE_VALUE(i))-1)
78 static const gf ZERO = {{{0}}}, ONE = {{{1}}};
80 #endif /* __P448_F_FIELD_H__ */