1 /*
2 * Copyright 2017-2022 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_64_F_IMPL_H
14 #define OSSL_CRYPTO_EC_CURVE448_ARCH_64_F_IMPL_H
15
16 #define GF_HEADROOM 9999 /* Everything is reduced anyway */
17 #define FIELD_LITERAL(a, b, c, d, e, f, g, h) \
18 { \
19 { \
20 a, b, c, d, e, f, g, h \
21 } \
22 }
23
24 #define LIMB_PLACE_VALUE(i) 56
25
gf_add_RAW(gf out,const gf a,const gf b)26 void gf_add_RAW(gf out, const gf a, const gf b)
27 {
28 unsigned int i;
29
30 for (i = 0; i < NLIMBS; i++)
31 out->limb[i] = a->limb[i] + b->limb[i];
32
33 gf_weak_reduce(out);
34 }
35
gf_sub_RAW(gf out,const gf a,const gf b)36 void gf_sub_RAW(gf out, const gf a, const gf b)
37 {
38 uint64_t co1 = ((1ULL << 56) - 1) * 2, co2 = co1 - 2;
39 unsigned int i;
40
41 for (i = 0; i < NLIMBS; i++)
42 out->limb[i] = a->limb[i] - b->limb[i] + ((i == NLIMBS / 2) ? co2 : co1);
43
44 gf_weak_reduce(out);
45 }
46
gf_bias(gf a,int amt)47 void gf_bias(gf a, int amt)
48 {
49 }
50
gf_weak_reduce(gf a)51 void gf_weak_reduce(gf a)
52 {
53 uint64_t mask = (1ULL << 56) - 1;
54 uint64_t tmp = a->limb[NLIMBS - 1] >> 56;
55 unsigned int i;
56
57 a->limb[NLIMBS / 2] += tmp;
58 for (i = NLIMBS - 1; i > 0; i--)
59 a->limb[i] = (a->limb[i] & mask) + (a->limb[i - 1] >> 56);
60 a->limb[0] = (a->limb[0] & mask) + tmp;
61 }
62
63 #endif /* OSSL_CRYPTO_EC_CURVE448_ARCH_64_F_IMPL_H */
64