1 /*
2 * Copyright 2017-2018 The OpenSSL Project Authors. All Rights Reserved.
3 * Copyright 2014-2016 Cryptography Research, Inc.
4 *
5 * Licensed under the Apache License 2.0 (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 #ifndef OSSL_CRYPTO_EC_CURVE448_ARCH_32_F_IMPL_H
14 #define OSSL_CRYPTO_EC_CURVE448_ARCH_32_F_IMPL_H
15
16 #define GF_HEADROOM 2
17 #define LIMB(x) ((x) & ((1 << 28) - 1)), ((x) >> 28)
18 #define FIELD_LITERAL(a, b, c, d, e, f, g, h) \
19 { \
20 { \
21 LIMB(a), LIMB(b), LIMB(c), LIMB(d), LIMB(e), LIMB(f), LIMB(g), LIMB(h) \
22 } \
23 }
24
25 #define LIMB_PLACE_VALUE(i) 28
26
gf_add_RAW(gf out,const gf a,const gf b)27 void gf_add_RAW(gf out, const gf a, const gf b)
28 {
29 unsigned int i;
30
31 for (i = 0; i < NLIMBS; i++)
32 out->limb[i] = a->limb[i] + b->limb[i];
33 }
34
gf_sub_RAW(gf out,const gf a,const gf b)35 void gf_sub_RAW(gf out, const gf a, const gf b)
36 {
37 unsigned int i;
38
39 for (i = 0; i < NLIMBS; i++)
40 out->limb[i] = a->limb[i] - b->limb[i];
41 }
42
gf_bias(gf a,int amt)43 void gf_bias(gf a, int amt)
44 {
45 unsigned int i;
46 uint32_t co1 = ((1 << 28) - 1) * amt, co2 = co1 - amt;
47
48 for (i = 0; i < NLIMBS; i++)
49 a->limb[i] += (i == NLIMBS / 2) ? co2 : co1;
50 }
51
gf_weak_reduce(gf a)52 void gf_weak_reduce(gf a)
53 {
54 uint32_t mask = (1 << 28) - 1;
55 uint32_t tmp = a->limb[NLIMBS - 1] >> 28;
56 unsigned int i;
57
58 a->limb[NLIMBS / 2] += tmp;
59 for (i = NLIMBS - 1; i > 0; i--)
60 a->limb[i] = (a->limb[i] & mask) + (a->limb[i - 1] >> 28);
61 a->limb[0] = (a->limb[0] & mask) + tmp;
62 }
63
64 #endif /* OSSL_CRYPTO_EC_CURVE448_ARCH_32_F_IMPL_H */
65