Skip to content

Commit 8ffe68c

Browse files
committed
attempt delocator fix
1 parent 17967f5 commit 8ffe68c

File tree

2 files changed

+47
-6
lines changed

2 files changed

+47
-6
lines changed

crypto/fipsmodule/ec/p384.c

+23-3
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,26 @@ static p384_limb_t p384_felem_nz(const p384_limb_t in1[P384_NLIMBS]) {
8383

8484
#endif // EC_NISTP_USE_S2N_BIGNUM
8585

86+
// The wrapper functions are needed for FIPS static build.
87+
// Otherwise, initializing ec_nistp_meth with pointers to s2n-bignum
88+
// functions directly generates :got: references that are also thought
89+
// to be local_target by the delocator.
90+
static inline void p384_felem_add_wrapper(ec_nistp_felem_limb *c,
91+
const ec_nistp_felem_limb *a,
92+
const ec_nistp_felem_limb *b) {
93+
p384_felem_add(c, a, b);
94+
}
95+
96+
static inline void p384_felem_sub_wrapper(ec_nistp_felem_limb *c,
97+
const ec_nistp_felem_limb *a,
98+
const ec_nistp_felem_limb *b) {
99+
p384_felem_sub(c, a, b);
100+
}
101+
102+
static inline void p384_felem_neg_wrapper(ec_nistp_felem_limb *c,
103+
const ec_nistp_felem_limb *a) {
104+
p384_felem_opp(c, a);
105+
}
86106

87107
static void p384_from_generic(p384_felem out, const EC_FELEM *in) {
88108
#ifdef OPENSSL_BIG_ENDIAN
@@ -273,11 +293,11 @@ static void p384_point_add(p384_felem x3, p384_felem y3, p384_felem z3,
273293
DEFINE_METHOD_FUNCTION(ec_nistp_meth, p384_methods) {
274294
out->felem_num_limbs = P384_NLIMBS;
275295
out->felem_num_bits = 384;
276-
out->felem_add = bignum_add_p384;
277-
out->felem_sub = bignum_sub_p384;
296+
out->felem_add = p384_felem_add_wrapper;
297+
out->felem_sub = p384_felem_sub_wrapper;
278298
out->felem_mul = bignum_montmul_p384_selector;
279299
out->felem_sqr = bignum_montsqr_p384_selector;
280-
out->felem_neg = bignum_neg_p384;
300+
out->felem_neg = p384_felem_neg_wrapper;
281301
out->felem_nz = p384_felem_nz;
282302
out->felem_one = p384_felem_one;
283303
out->point_dbl = p384_point_double;

crypto/fipsmodule/ec/p521.c

+24-3
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,27 @@ static const p521_limb_t p521_felem_p[P521_NLIMBS] = {
126126

127127
#endif // EC_NISTP_USE_S2N_BIGNUM
128128

129+
// The wrapper functions are needed for FIPS static build.
130+
// Otherwise, initializing ec_nistp_meth with pointers to s2n-bignum
131+
// functions directly generates :got: references that are also thought
132+
// to be local_target by the delocator.
133+
static inline void p521_felem_add_wrapper(ec_nistp_felem_limb *c,
134+
const ec_nistp_felem_limb *a,
135+
const ec_nistp_felem_limb *b) {
136+
p521_felem_add(c, a, b);
137+
}
138+
139+
static inline void p521_felem_sub_wrapper(ec_nistp_felem_limb *c,
140+
const ec_nistp_felem_limb *a,
141+
const ec_nistp_felem_limb *b) {
142+
p521_felem_sub(c, a, b);
143+
}
144+
145+
static inline void p521_felem_neg_wrapper(ec_nistp_felem_limb *c,
146+
const ec_nistp_felem_limb *a) {
147+
p521_felem_opp(c, a);
148+
}
149+
129150
static p521_limb_t p521_felem_nz(const p521_limb_t in1[P521_NLIMBS]) {
130151
p521_limb_t is_not_zero = 0;
131152
for (int i = 0; i < P521_NLIMBS; i++) {
@@ -289,11 +310,11 @@ static void p521_point_add(p521_felem x3, p521_felem y3, p521_felem z3,
289310
DEFINE_METHOD_FUNCTION(ec_nistp_meth, p521_methods) {
290311
out->felem_num_limbs = P521_NLIMBS;
291312
out->felem_num_bits = 521;
292-
out->felem_add = bignum_add_p521;
293-
out->felem_sub = bignum_sub_p521;
313+
out->felem_add = p521_felem_add_wrapper;
314+
out->felem_sub = p521_felem_sub_wrapper;
294315
out->felem_mul = bignum_mul_p521_selector;
295316
out->felem_sqr = bignum_sqr_p521_selector;
296-
out->felem_neg = bignum_neg_p521;
317+
out->felem_neg = p521_felem_neg_wrapper;
297318
out->felem_nz = p521_felem_nz;
298319
out->felem_one = p521_felem_one;
299320
out->point_dbl = p521_point_double;

0 commit comments

Comments
 (0)