]>
git.ipfire.org Git - thirdparty/openssl.git/blob - crypto/ec/curve448/arch_32/f_impl.h
2 * Copyright 2017-2018 The OpenSSL Project Authors. All Rights Reserved.
3 * Copyright 2014-2016 Cryptography Research, Inc.
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
10 * Originally written by Mike Hamburg
13 #ifndef HEADER_ARCH_32_F_IMPL_H
14 # define HEADER_ARCH_32_F_IMPL_H
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)}}
21 # define LIMB_PLACE_VALUE(i) 28
23 void gf_add_RAW(gf out
, const gf a
, const gf b
)
27 for (i
= 0; i
< NLIMBS
; i
++)
28 out
->limb
[i
] = a
->limb
[i
] + b
->limb
[i
];
31 void gf_sub_RAW(gf out
, const gf a
, const gf b
)
35 for (i
= 0; i
< NLIMBS
; i
++)
36 out
->limb
[i
] = a
->limb
[i
] - b
->limb
[i
];
39 void gf_bias(gf a
, int amt
)
42 uint32_t co1
= ((1 << 28) - 1) * amt
, co2
= co1
- amt
;
44 for (i
= 0; i
< NLIMBS
; i
++)
45 a
->limb
[i
] += (i
== NLIMBS
/ 2) ? co2
: co1
;
48 void gf_weak_reduce(gf a
)
50 uint32_t mask
= (1 << 28) - 1;
51 uint32_t tmp
= a
->limb
[NLIMBS
- 1] >> 28;
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
;
60 #endif /* HEADER_ARCH_32_F_IMPL_H */