1 /* Copyright (c) 2014, Intel Corporation.
2  *
3  * Permission to use, copy, modify, and/or distribute this software for any
4  * purpose with or without fee is hereby granted, provided that the above
5  * copyright notice and this permission notice appear in all copies.
6  *
7  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
10  * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
12  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
13  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
14 
15 #ifndef OPENSSL_HEADER_EC_ECP_NISTZ256_H
16 #define OPENSSL_HEADER_EC_ECP_NISTZ256_H
17 
18 #include "../../limbs/limbs.h"
19 
20 // Keep this in sync with p256.rs.
21 #if defined(OPENSSL_AARCH64) || defined(OPENSSL_X86) || defined(OPENSSL_X86_64)
22 #define GFp_USE_LARGE_TABLE
23 #endif
24 
25 #define P256_LIMBS (256u / LIMB_BITS)
26 
27 typedef struct {
28   Limb X[P256_LIMBS];
29   Limb Y[P256_LIMBS];
30   Limb Z[P256_LIMBS];
31 } P256_POINT;
32 
33 #if defined(GFp_USE_LARGE_TABLE)
34 typedef struct {
35   Limb X[P256_LIMBS];
36   Limb Y[P256_LIMBS];
37 } P256_POINT_AFFINE;
38 #endif
39 
40 typedef Limb PRECOMP256_ROW[64 * 2 * P256_LIMBS]; // 64 (x, y) entries.
41 
42 void GFp_nistz256_mul_mont(Limb res[P256_LIMBS], const Limb a[P256_LIMBS],
43                            const Limb b[P256_LIMBS]);
44 void GFp_nistz256_sqr_mont(Limb res[P256_LIMBS], const Limb a[P256_LIMBS]);
45 
46 /* Functions that perform constant time access to the precomputed tables */
47 void GFp_nistz256_select_w5(P256_POINT *out, const P256_POINT table[16],
48                             crypto_word index);
49 
50 #if defined(GFp_USE_LARGE_TABLE)
51 void GFp_nistz256_select_w7(P256_POINT_AFFINE *out, const PRECOMP256_ROW table, crypto_word index);
52 #endif
53 
54 #endif /* OPENSSL_HEADER_EC_ECP_NISTZ256_H */
55