summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortb <>2021-12-04 15:53:01 +0000
committertb <>2021-12-04 15:53:01 +0000
commite37ca09a6c0f7eb15f33d536aa0fdbb4241c633f (patch)
treed6e778b0f86a5a6d60eef0b24c751d23a791739e
parent9e67971b75131ba30d80f574f8a566cc6baec963 (diff)
downloadopenbsd-e37ca09a6c0f7eb15f33d536aa0fdbb4241c633f.tar.gz
openbsd-e37ca09a6c0f7eb15f33d536aa0fdbb4241c633f.tar.bz2
openbsd-e37ca09a6c0f7eb15f33d536aa0fdbb4241c633f.zip
Provide replacement functions for the BN_{get,set,with}_flags() macros.
ok inoguchi jsing
-rw-r--r--src/lib/libcrypto/bn/bn.h10
-rw-r--r--src/lib/libcrypto/bn/bn_lib.c26
2 files changed, 34 insertions, 2 deletions
diff --git a/src/lib/libcrypto/bn/bn.h b/src/lib/libcrypto/bn/bn.h
index cfdf46906b..20212bf171 100644
--- a/src/lib/libcrypto/bn/bn.h
+++ b/src/lib/libcrypto/bn/bn.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: bn.h,v 1.45 2021/12/04 15:48:23 tb Exp $ */ 1/* $OpenBSD: bn.h,v 1.46 2021/12/04 15:53:01 tb Exp $ */
2/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -228,8 +228,14 @@ extern "C" {
228#ifndef OPENSSL_NO_DEPRECATED 228#ifndef OPENSSL_NO_DEPRECATED
229#define BN_FLG_FREE 0x8000 /* used for debugging */ 229#define BN_FLG_FREE 0x8000 /* used for debugging */
230#endif 230#endif
231#if defined(LIBRESSL_OPAQUE_BN) || defined(LIBRESSL_CRYPTO_INTERNAL)
232void BN_set_flags(BIGNUM *b, int n);
233int BN_get_flags(const BIGNUM *b, int n);
234void BN_with_flags(BIGNUM *dest, const BIGNUM *src, int flags);
235#else
231#define BN_set_flags(b,n) ((b)->flags|=(n)) 236#define BN_set_flags(b,n) ((b)->flags|=(n))
232#define BN_get_flags(b,n) ((b)->flags&(n)) 237#define BN_get_flags(b,n) ((b)->flags&(n))
238#endif
233 239
234/* Values for |top| in BN_rand() */ 240/* Values for |top| in BN_rand() */
235#define BN_RAND_TOP_ANY -1 241#define BN_RAND_TOP_ANY -1
@@ -240,6 +246,7 @@ extern "C" {
240#define BN_RAND_BOTTOM_ANY 0 246#define BN_RAND_BOTTOM_ANY 0
241#define BN_RAND_BOTTOM_ODD 1 247#define BN_RAND_BOTTOM_ODD 1
242 248
249#if !defined(LIBRESSL_OPAQUE_BN) && !defined(LIBRESSL_CRYPTO_INTERNAL)
243/* get a clone of a BIGNUM with changed flags, for *temporary* use only 250/* get a clone of a BIGNUM with changed flags, for *temporary* use only
244 * (the two BIGNUMs cannot not be used in parallel!) */ 251 * (the two BIGNUMs cannot not be used in parallel!) */
245#define BN_with_flags(dest,b,n) ((dest)->d=(b)->d, \ 252#define BN_with_flags(dest,b,n) ((dest)->d=(b)->d, \
@@ -250,6 +257,7 @@ extern "C" {
250 | ((b)->flags & ~BN_FLG_MALLOCED) \ 257 | ((b)->flags & ~BN_FLG_MALLOCED) \
251 | BN_FLG_STATIC_DATA \ 258 | BN_FLG_STATIC_DATA \
252 | (n))) 259 | (n)))
260#endif
253 261
254struct bignum_st { 262struct bignum_st {
255 BN_ULONG *d; /* Pointer to an array of 'BN_BITS2' bit chunks. */ 263 BN_ULONG *d; /* Pointer to an array of 'BN_BITS2' bit chunks. */
diff --git a/src/lib/libcrypto/bn/bn_lib.c b/src/lib/libcrypto/bn/bn_lib.c
index 14817629aa..e4085c9d67 100644
--- a/src/lib/libcrypto/bn/bn_lib.c
+++ b/src/lib/libcrypto/bn/bn_lib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: bn_lib.c,v 1.49 2021/12/04 15:48:23 tb Exp $ */ 1/* $OpenBSD: bn_lib.c,v 1.50 2021/12/04 15:53:01 tb Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -137,6 +137,30 @@ BN_get_params(int which)
137} 137}
138#endif 138#endif
139 139
140void
141BN_set_flags(BIGNUM *b, int n)
142{
143 b->flags |= n;
144}
145
146int
147BN_get_flags(const BIGNUM *b, int n)
148{
149 return b->flags & n;
150}
151
152void
153BN_with_flags(BIGNUM *dest, const BIGNUM *b, int flags)
154{
155 int dest_flags;
156
157 dest_flags = (dest->flags & BN_FLG_MALLOCED) |
158 (b->flags & ~BN_FLG_MALLOCED) | BN_FLG_STATIC_DATA | flags;
159
160 *dest = *b;
161 dest->flags = dest_flags;
162}
163
140const BIGNUM * 164const BIGNUM *
141BN_value_one(void) 165BN_value_one(void)
142{ 166{