]>
Commit | Line | Data |
---|---|---|
927e704e | 1 | /* |
3c2bdd7d | 2 | * Copyright 2017-2021 The OpenSSL Project Authors. All Rights Reserved. |
927e704e AI |
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 | ||
70fd5110 AI |
13 | #ifndef OSSL_CRYPTO_EC_CURVE448_ARCH_64_F_IMPL_H |
14 | # define OSSL_CRYPTO_EC_CURVE448_ARCH_64_F_IMPL_H | |
927e704e | 15 | |
70fd5110 AI |
16 | # define GF_HEADROOM 9999 /* Everything is reduced anyway */ |
17 | # define FIELD_LITERAL(a,b,c,d,e,f,g,h) {{a,b,c,d,e,f,g,h}} | |
18 | ||
19 | # define LIMB_PLACE_VALUE(i) 56 | |
927e704e AI |
20 | |
21 | void gf_add_RAW(gf out, const gf a, const gf b) | |
22 | { | |
70fd5110 AI |
23 | unsigned int i; |
24 | ||
eacc1806 | 25 | for (i = 0; i < NLIMBS; i++) |
927e704e | 26 | out->limb[i] = a->limb[i] + b->limb[i]; |
70fd5110 | 27 | |
927e704e AI |
28 | gf_weak_reduce(out); |
29 | } | |
30 | ||
31 | void gf_sub_RAW(gf out, const gf a, const gf b) | |
32 | { | |
70fd5110 AI |
33 | uint64_t co1 = ((1ULL << 56) - 1) * 2, co2 = co1 - 2; |
34 | unsigned int i; | |
927e704e | 35 | |
eacc1806 AI |
36 | for (i = 0; i < NLIMBS; i++) |
37 | out->limb[i] = a->limb[i] - b->limb[i] + ((i == NLIMBS / 2) ? co2 : co1); | |
70fd5110 | 38 | |
927e704e AI |
39 | gf_weak_reduce(out); |
40 | } | |
41 | ||
42 | void gf_bias(gf a, int amt) | |
43 | { | |
927e704e AI |
44 | } |
45 | ||
46 | void gf_weak_reduce(gf a) | |
47 | { | |
70fd5110 | 48 | uint64_t mask = (1ULL << 56) - 1; |
eacc1806 | 49 | uint64_t tmp = a->limb[NLIMBS - 1] >> 56; |
70fd5110 | 50 | unsigned int i; |
927e704e | 51 | |
eacc1806 AI |
52 | a->limb[NLIMBS / 2] += tmp; |
53 | for (i = NLIMBS - 1; i > 0; i--) | |
927e704e AI |
54 | a->limb[i] = (a->limb[i] & mask) + (a->limb[i - 1] >> 56); |
55 | a->limb[0] = (a->limb[0] & mask) + tmp; | |
56 | } | |
70fd5110 AI |
57 | |
58 | #endif /* OSSL_CRYPTO_EC_CURVE448_ARCH_64_F_IMPL_H */ |