Flatten the Curve 448 source structure
[openssl.git] / crypto / ec / curve448 / f_arithmetic.c
1 /**
2  * @cond internal
3  * @file f_arithmetic.c
4  * @copyright
5  *   Copyright (c) 2014 Cryptography Research, Inc.  \n
6  *   Released under the MIT License.  See LICENSE.txt for license information.
7  * @author Mike Hamburg
8  * @brief Field-specific arithmetic.
9  */
10
11 #include "field.h"
12
13 mask_t gf_isr (
14     gf a,
15     const gf x
16 ) {
17     gf L0, L1, L2;
18     gf_sqr  (L1,     x );
19     gf_mul  (L2,     x,   L1 );
20     gf_sqr  (L1,   L2 );
21     gf_mul  (L2,     x,   L1 );
22     gf_sqrn (L1,   L2,     3 );
23     gf_mul  (L0,   L2,   L1 );
24     gf_sqrn (L1,   L0,     3 );
25     gf_mul  (L0,   L2,   L1 );
26     gf_sqrn (L2,   L0,     9 );
27     gf_mul  (L1,   L0,   L2 );
28     gf_sqr  (L0,   L1 );
29     gf_mul  (L2,     x,   L0 );
30     gf_sqrn (L0,   L2,    18 );
31     gf_mul  (L2,   L1,   L0 );
32     gf_sqrn (L0,   L2,    37 );
33     gf_mul  (L1,   L2,   L0 );
34     gf_sqrn (L0,   L1,    37 );
35     gf_mul  (L1,   L2,   L0 );
36     gf_sqrn (L0,   L1,   111 );
37     gf_mul  (L2,   L1,   L0 );
38     gf_sqr  (L0,   L2 );
39     gf_mul  (L1,     x,   L0 );
40     gf_sqrn (L0,   L1,   223 );
41     gf_mul  (L1,   L2,   L0 );
42     gf_sqr  (L2, L1);
43     gf_mul  (L0, L2, x);
44     gf_copy(a,L1);
45     return gf_eq(L0,ONE);
46 }