From 8f35efbab122ffdcba209974cee7070747ccb68e Mon Sep 17 00:00:00 2001 From: tb Date: Wed, 9 Aug 2023 09:09:24 +0000 Subject: [PATCH] Merge BN_BLINDING_create_param() into BN_BLINDING_new() --- lib/libcrypto/bn/bn_blind.c | 36 ++++++++++-------------------------- lib/libcrypto/bn/bn_local.h | 9 ++++----- lib/libcrypto/rsa/rsa_crpt.c | 4 ++-- 3 files changed, 16 insertions(+), 33 deletions(-) diff --git a/lib/libcrypto/bn/bn_blind.c b/lib/libcrypto/bn/bn_blind.c index 996b1d69650..e126865754e 100644 --- a/lib/libcrypto/bn/bn_blind.c +++ b/lib/libcrypto/bn/bn_blind.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bn_blind.c,v 1.41 2023/08/09 08:39:46 tb Exp $ */ +/* $OpenBSD: bn_blind.c,v 1.42 2023/08/09 09:09:24 tb Exp $ */ /* ==================================================================== * Copyright (c) 1998-2006 The OpenSSL Project. All rights reserved. * @@ -131,8 +131,10 @@ struct bn_blinding_st { const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx); }; -static BN_BLINDING * -BN_BLINDING_new(const BIGNUM *e, const BIGNUM *mod) +BN_BLINDING * +BN_BLINDING_new(const BIGNUM *e, BIGNUM *mod, BN_CTX *ctx, + int (*bn_mod_exp)(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, + const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx), BN_MONT_CTX *m_ctx) { BN_BLINDING *ret = NULL; @@ -155,6 +157,11 @@ BN_BLINDING_new(const BIGNUM *e, const BIGNUM *mod) ret->counter = BN_BLINDING_COUNTER - 1; CRYPTO_THREADID_current(&ret->tid); + if (bn_mod_exp != NULL) + ret->bn_mod_exp = bn_mod_exp; + if (m_ctx != NULL) + ret->m_ctx = m_ctx; + return ret; err: @@ -250,26 +257,3 @@ BN_BLINDING_thread_id(BN_BLINDING *b) { return &b->tid; } - -BN_BLINDING * -BN_BLINDING_create_param(const BIGNUM *e, BIGNUM *m, BN_CTX *ctx, - int (*bn_mod_exp)(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, - const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx), BN_MONT_CTX *m_ctx) -{ - BN_BLINDING *ret = NULL; - - if ((ret = BN_BLINDING_new(e, m)) == NULL) - goto err; - - if (bn_mod_exp != NULL) - ret->bn_mod_exp = bn_mod_exp; - if (m_ctx != NULL) - ret->m_ctx = m_ctx; - - return ret; - - err: - BN_BLINDING_free(ret); - - return NULL; -} diff --git a/lib/libcrypto/bn/bn_local.h b/lib/libcrypto/bn/bn_local.h index be9f67adea5..66df40ada00 100644 --- a/lib/libcrypto/bn/bn_local.h +++ b/lib/libcrypto/bn/bn_local.h @@ -1,4 +1,4 @@ -/* $OpenBSD: bn_local.h,v 1.35 2023/08/09 08:27:02 tb Exp $ */ +/* $OpenBSD: bn_local.h,v 1.36 2023/08/09 09:09:24 tb Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -292,14 +292,13 @@ int BN_mod_exp_recp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, int BN_div_recp(BIGNUM *dv, BIGNUM *rem, const BIGNUM *m, BN_RECP_CTX *recp, BN_CTX *ctx); +BN_BLINDING *BN_BLINDING_new(const BIGNUM *e, BIGNUM *m, BN_CTX *ctx, + int (*bn_mod_exp)(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, + const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx), BN_MONT_CTX *m_ctx); void BN_BLINDING_free(BN_BLINDING *b); int BN_BLINDING_convert(BIGNUM *n, BIGNUM *r, BN_BLINDING *b, BN_CTX *); int BN_BLINDING_invert(BIGNUM *n, const BIGNUM *r, BN_BLINDING *b, BN_CTX *); - CRYPTO_THREADID *BN_BLINDING_thread_id(BN_BLINDING *); -BN_BLINDING *BN_BLINDING_create_param(const BIGNUM *e, BIGNUM *m, BN_CTX *ctx, - int (*bn_mod_exp)(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, - const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx), BN_MONT_CTX *m_ctx); /* Explicitly const time / non-const time versions for internal use */ int BN_mod_exp_ct(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, diff --git a/lib/libcrypto/rsa/rsa_crpt.c b/lib/libcrypto/rsa/rsa_crpt.c index 99086735ea9..4739b762405 100644 --- a/lib/libcrypto/rsa/rsa_crpt.c +++ b/lib/libcrypto/rsa/rsa_crpt.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rsa_crpt.c,v 1.25 2023/08/08 15:18:24 tb Exp $ */ +/* $OpenBSD: rsa_crpt.c,v 1.26 2023/08/09 09:09:24 tb Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -209,7 +209,7 @@ RSA_setup_blinding(RSA *rsa, BN_CTX *in_ctx) BN_init(&n); BN_with_flags(&n, rsa->n, BN_FLG_CONSTTIME); - if ((ret = BN_BLINDING_create_param(e, &n, ctx, rsa->meth->bn_mod_exp, + if ((ret = BN_BLINDING_new(e, &n, ctx, rsa->meth->bn_mod_exp, rsa->_method_mod_n)) == NULL) { RSAerror(ERR_R_BN_LIB); goto err; -- 2.20.1