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 {{LIMB(a), LIMB(b), LIMB(c), LIMB(d), LIMB(e), LIMB(f), LIMB(g), LIMB(h)}}
20
21# define LIMB_PLACE_VALUE(i) 28
22
23void gf_add_RAW(gf out, const gf a, const gf b)
24{
25 unsigned int i;
26
27 for (i = 0; i < NLIMBS; i++)
28 out->limb[i] = a->limb[i] + b->limb[i];
29}
30
31void gf_sub_RAW(gf out, const gf a, const gf b)
32{
33 unsigned int i;
34
35 for (i = 0; i < NLIMBS; i++)
36 out->limb[i] = a->limb[i] - b->limb[i];
37}
38
39void gf_bias(gf a, int amt)
40{
41 unsigned int i;
42 uint32_t co1 = ((1 << 28) - 1) * amt, co2 = co1 - amt;
43
44 for (i = 0; i < NLIMBS; i++)
45 a->limb[i] += (i == NLIMBS / 2) ? co2 : co1;
46}
47
48void gf_weak_reduce(gf a)
49{
50 uint32_t mask = (1 << 28) - 1;
51 uint32_t tmp = a->limb[NLIMBS - 1] >> 28;
52 unsigned int i;
53
54 a->limb[NLIMBS / 2] += tmp;
55 for (i = NLIMBS - 1; i > 0; i--)
56 a->limb[i] = (a->limb[i] & mask) + (a->limb[i - 1] >> 28);
57 a->limb[0] = (a->limb[0] & mask) + tmp;
58}
59
60#endif /* OSSL_CRYPTO_EC_CURVE448_ARCH_32_F_IMPL_H */
61