Run util/openssl-format-source on the Curve448 code
[openssl.git] / crypto / ec / curve448 / arch_arm_32 / f_impl.h
1 /*
2  * Copyright 2017 The OpenSSL Project Authors. All Rights Reserved.
3  * Copyright 2014-2016 Cryptography Research, Inc.
4  *
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
9  *
10  * Originally written by Mike Hamburg
11  */
12
13 #define GF_HEADROOM 2
14 #define LIMB(x) (x##ull)&((1ull<<28)-1), (x##ull)>>28
15 #define FIELD_LITERAL(a,b,c,d,e,f,g,h) \
16     {{LIMB(a),LIMB(b),LIMB(c),LIMB(d),LIMB(e),LIMB(f),LIMB(g),LIMB(h)}}
17
18 #define LIMB_PLACE_VALUE(i) 28
19
20 void gf_add_RAW(gf out, const gf a, const gf b)
21 {
22     for (unsigned int i = 0; i < sizeof(*out) / sizeof(uint32xn_t); i++) {
23         ((uint32xn_t *) out)[i] =
24             ((const uint32xn_t *)a)[i] + ((const uint32xn_t *)b)[i];
25     }
26     /*
27      * for (unsigned int i=0; i<sizeof(*out)/sizeof(out->limb[0]); i++) {
28      * out->limb[i] = a->limb[i] + b->limb[i]; }
29      */
30 }
31
32 void gf_sub_RAW(gf out, const gf a, const gf b)
33 {
34     for (unsigned int i = 0; i < sizeof(*out) / sizeof(uint32xn_t); i++) {
35         ((uint32xn_t *) out)[i] =
36             ((const uint32xn_t *)a)[i] - ((const uint32xn_t *)b)[i];
37     }
38     /*
39      * for (unsigned int i=0; i<sizeof(*out)/sizeof(out->limb[0]); i++) {
40      * out->limb[i] = a->limb[i] - b->limb[i]; }
41      */
42 }
43
44 void gf_bias(gf a, int amt)
45 {
46     uint32_t co1 = ((1ull << 28) - 1) * amt, co2 = co1 - amt;
47     uint32x4_t lo = { co1, co1, co1, co1 }, hi = {
48     co2, co1, co1, co1};
49     uint32x4_t *aa = (uint32x4_t *) a;
50     aa[0] += lo;
51     aa[1] += lo;
52     aa[2] += hi;
53     aa[3] += lo;
54 }
55
56 void gf_weak_reduce(gf a)
57 {
58     uint64_t mask = (1ull << 28) - 1;
59     uint64_t tmp = a->limb[15] >> 28;
60     a->limb[8] += tmp;
61     for (unsigned int i = 15; i > 0; i--) {
62         a->limb[i] = (a->limb[i] & mask) + (a->limb[i - 1] >> 28);
63     }
64     a->limb[0] = (a->limb[0] & mask) + tmp;
65 }