From: tb Date: Sat, 4 Dec 2021 15:48:23 +0000 (+0000) Subject: Provide replacement functions for the BN_GENCB_set{,_old}() macros X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=6bbb73995c8e71f4ccedb27558b1e4887fc58c34;p=openbsd Provide replacement functions for the BN_GENCB_set{,_old}() macros The function implementations are necessary to make BIGNUM opaque. They will be used in libcrypto internally until they will replace the macro implementations with the next bump. ok inoguchi jsing --- diff --git a/lib/libcrypto/bn/bn.h b/lib/libcrypto/bn/bn.h index 319cfd67caf..cfdf46906bc 100644 --- a/lib/libcrypto/bn/bn.h +++ b/lib/libcrypto/bn/bn.h @@ -1,4 +1,4 @@ -/* $OpenBSD: bn.h,v 1.44 2021/11/18 18:01:08 tb Exp $ */ +/* $OpenBSD: bn.h,v 1.45 2021/12/04 15:48:23 tb Exp $ */ /* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -297,10 +297,19 @@ struct bn_gencb_st { BN_GENCB *BN_GENCB_new(void); void BN_GENCB_free(BN_GENCB *cb); -void *BN_GENCB_get_arg(BN_GENCB *cb); /* Wrapper function to make using BN_GENCB easier, */ int BN_GENCB_call(BN_GENCB *cb, int a, int b); + +#if defined(LIBRESSL_OPAQUE_BN) || defined(LIBRESSL_CRYPTO_INTERNAL) +/* Populate a BN_GENCB structure with an "old"-style callback */ +void BN_GENCB_set_old(BN_GENCB *gencb, void (*callback)(int, int, void *), + void *cb_arg); + +/* Populate a BN_GENCB structure with a "new"-style callback */ +void BN_GENCB_set(BN_GENCB *gencb, int (*callback)(int, int, BN_GENCB *), + void *cb_arg); +#else /* Macro to populate a BN_GENCB structure with an "old"-style callback */ #define BN_GENCB_set_old(gencb, callback, cb_arg) { \ BN_GENCB *tmp_gencb = (gencb); \ @@ -313,6 +322,9 @@ int BN_GENCB_call(BN_GENCB *cb, int a, int b); tmp_gencb->ver = 2; \ tmp_gencb->arg = (cb_arg); \ tmp_gencb->cb.cb_2 = (callback); } +#endif /* !LIBRESSL_CRYPTO_INTERNAL */ + +void *BN_GENCB_get_arg(BN_GENCB *cb); #define BN_prime_checks 0 /* default: select number of iterations based on the size of the number */ diff --git a/lib/libcrypto/bn/bn_lib.c b/lib/libcrypto/bn/bn_lib.c index af837eed01c..14817629aa1 100644 --- a/lib/libcrypto/bn/bn_lib.c +++ b/lib/libcrypto/bn/bn_lib.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bn_lib.c,v 1.48 2021/09/08 12:19:17 tb Exp $ */ +/* $OpenBSD: bn_lib.c,v 1.49 2021/12/04 15:48:23 tb Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -1056,6 +1056,24 @@ BN_GENCB_free(BN_GENCB *cb) free(cb); } +/* Populate a BN_GENCB structure with an "old"-style callback */ +void +BN_GENCB_set_old(BN_GENCB *gencb, void (*cb)(int, int, void *), void *cb_arg) +{ + gencb->ver = 1; + gencb->cb.cb_1 = cb; + gencb->arg = cb_arg; +} + +/* Populate a BN_GENCB structure with a "new"-style callback */ +void +BN_GENCB_set(BN_GENCB *gencb, int (*cb)(int, int, BN_GENCB *), void *cb_arg) +{ + gencb->ver = 2; + gencb->cb.cb_2 = cb; + gencb->arg = cb_arg; +} + void * BN_GENCB_get_arg(BN_GENCB *cb) {