2 * Copyright 2017 The OpenSSL Project Authors. All Rights Reserved.
3 * Copyright 2014 Cryptography Research, Inc.
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
10 * Originally written by Mike Hamburg
16 # include "constant_time.h"
20 /* Square x, n times. */
21 static ossl_inline void gf_sqrn(gf_s * __restrict__ y, const gf x, int n)
39 # define gf_add_nr gf_add_RAW
41 /* Subtract mod p. Bias by 2 and don't reduce */
42 static ossl_inline void gf_sub_nr(gf c, const gf a, const gf b)
50 /* Subtract mod p. Bias by amt but don't reduce. */
51 static ossl_inline void gf_subx_nr(gf c, const gf a, const gf b, int amt)
55 if (GF_HEADROOM < amt + 1)
59 /* Mul by signed int. Not constant-time WRT the sign of that int. */
60 static ossl_inline void gf_mulw(gf c, const gf a, int32_t w)
63 gf_mulw_unsigned(c, a, w);
65 gf_mulw_unsigned(c, a, -w);
70 /* Constant time, x = is_z ? z : y */
71 static ossl_inline void gf_cond_sel(gf x, const gf y, const gf z, mask_t is_z)
73 constant_time_select(x, y, z, sizeof(gf), is_z, 0);
76 /* Constant time, if (neg) x=-x; */
77 static ossl_inline void gf_cond_neg(gf x, mask_t neg)
81 gf_cond_sel(x, x, y, neg);
84 /* Constant time, if (swap) (x,y) = (y,x); */
85 static ossl_inline void gf_cond_swap(gf x, gf_s * __restrict__ y, mask_t swap)
87 constant_time_cond_swap(x, y, sizeof(gf_s), swap);
90 static ossl_inline void gf_mul_qnr(gf_s * __restrict__ out, const gf x)
95 static ossl_inline void gf_div_qnr(gf_s * __restrict__ out, const gf x)
100 #endif /* __GF_H__ */