Skip to content

Commit 95e0708

Browse files
author
tb
committed
Merge BN_BLINDING_create_param() into BN_BLINDING_new()
1 parent b747bfb commit 95e0708

File tree

3 files changed

+16
-33
lines changed

3 files changed

+16
-33
lines changed

src/lib/libcrypto/bn/bn_blind.c

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $OpenBSD: bn_blind.c,v 1.41 2023/08/09 08:39:46 tb Exp $ */
1+
/* $OpenBSD: bn_blind.c,v 1.42 2023/08/09 09:09:24 tb Exp $ */
22
/* ====================================================================
33
* Copyright (c) 1998-2006 The OpenSSL Project. All rights reserved.
44
*
@@ -131,8 +131,10 @@ struct bn_blinding_st {
131131
const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx);
132132
};
133133

134-
static BN_BLINDING *
135-
BN_BLINDING_new(const BIGNUM *e, const BIGNUM *mod)
134+
BN_BLINDING *
135+
BN_BLINDING_new(const BIGNUM *e, BIGNUM *mod, BN_CTX *ctx,
136+
int (*bn_mod_exp)(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
137+
const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx), BN_MONT_CTX *m_ctx)
136138
{
137139
BN_BLINDING *ret = NULL;
138140

@@ -155,6 +157,11 @@ BN_BLINDING_new(const BIGNUM *e, const BIGNUM *mod)
155157
ret->counter = BN_BLINDING_COUNTER - 1;
156158
CRYPTO_THREADID_current(&ret->tid);
157159

160+
if (bn_mod_exp != NULL)
161+
ret->bn_mod_exp = bn_mod_exp;
162+
if (m_ctx != NULL)
163+
ret->m_ctx = m_ctx;
164+
158165
return ret;
159166

160167
err:
@@ -250,26 +257,3 @@ BN_BLINDING_thread_id(BN_BLINDING *b)
250257
{
251258
return &b->tid;
252259
}
253-
254-
BN_BLINDING *
255-
BN_BLINDING_create_param(const BIGNUM *e, BIGNUM *m, BN_CTX *ctx,
256-
int (*bn_mod_exp)(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
257-
const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx), BN_MONT_CTX *m_ctx)
258-
{
259-
BN_BLINDING *ret = NULL;
260-
261-
if ((ret = BN_BLINDING_new(e, m)) == NULL)
262-
goto err;
263-
264-
if (bn_mod_exp != NULL)
265-
ret->bn_mod_exp = bn_mod_exp;
266-
if (m_ctx != NULL)
267-
ret->m_ctx = m_ctx;
268-
269-
return ret;
270-
271-
err:
272-
BN_BLINDING_free(ret);
273-
274-
return NULL;
275-
}

src/lib/libcrypto/bn/bn_local.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $OpenBSD: bn_local.h,v 1.35 2023/08/09 08:27:02 tb Exp $ */
1+
/* $OpenBSD: bn_local.h,v 1.36 2023/08/09 09:09:24 tb Exp $ */
22
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
33
* All rights reserved.
44
*
@@ -292,14 +292,13 @@ int BN_mod_exp_recp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
292292
int BN_div_recp(BIGNUM *dv, BIGNUM *rem, const BIGNUM *m,
293293
BN_RECP_CTX *recp, BN_CTX *ctx);
294294

295+
BN_BLINDING *BN_BLINDING_new(const BIGNUM *e, BIGNUM *m, BN_CTX *ctx,
296+
int (*bn_mod_exp)(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
297+
const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx), BN_MONT_CTX *m_ctx);
295298
void BN_BLINDING_free(BN_BLINDING *b);
296299
int BN_BLINDING_convert(BIGNUM *n, BIGNUM *r, BN_BLINDING *b, BN_CTX *);
297300
int BN_BLINDING_invert(BIGNUM *n, const BIGNUM *r, BN_BLINDING *b, BN_CTX *);
298-
299301
CRYPTO_THREADID *BN_BLINDING_thread_id(BN_BLINDING *);
300-
BN_BLINDING *BN_BLINDING_create_param(const BIGNUM *e, BIGNUM *m, BN_CTX *ctx,
301-
int (*bn_mod_exp)(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
302-
const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx), BN_MONT_CTX *m_ctx);
303302

304303
/* Explicitly const time / non-const time versions for internal use */
305304
int BN_mod_exp_ct(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,

src/lib/libcrypto/rsa/rsa_crpt.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $OpenBSD: rsa_crpt.c,v 1.25 2023/08/08 15:18:24 tb Exp $ */
1+
/* $OpenBSD: rsa_crpt.c,v 1.26 2023/08/09 09:09:24 tb Exp $ */
22
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
33
* All rights reserved.
44
*
@@ -209,7 +209,7 @@ RSA_setup_blinding(RSA *rsa, BN_CTX *in_ctx)
209209
BN_init(&n);
210210
BN_with_flags(&n, rsa->n, BN_FLG_CONSTTIME);
211211

212-
if ((ret = BN_BLINDING_create_param(e, &n, ctx, rsa->meth->bn_mod_exp,
212+
if ((ret = BN_BLINDING_new(e, &n, ctx, rsa->meth->bn_mod_exp,
213213
rsa->_method_mod_n)) == NULL) {
214214
RSAerror(ERR_R_BN_LIB);
215215
goto err;

0 commit comments

Comments
 (0)