From 7eab76581522a8858953ba6e999298d4b672ef8e Mon Sep 17 00:00:00 2001 From: tb Date: Sat, 4 Dec 2021 16:02:44 +0000 Subject: [PATCH] Implement the BN_is_negative macro as a function ok inoguchi jsing --- lib/libcrypto/bn/bn.h | 7 ++++++- lib/libcrypto/bn/bn_lib.c | 8 +++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/libcrypto/bn/bn.h b/lib/libcrypto/bn/bn.h index e9837cbbd61..4bfb81d32e0 100644 --- a/lib/libcrypto/bn/bn.h +++ b/lib/libcrypto/bn/bn.h @@ -1,4 +1,4 @@ -/* $OpenBSD: bn.h,v 1.47 2021/12/04 15:59:52 tb Exp $ */ +/* $OpenBSD: bn.h,v 1.48 2021/12/04 16:02:44 tb Exp $ */ /* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -485,11 +485,16 @@ int BN_sqr(BIGNUM *r, const BIGNUM *a, BN_CTX *ctx); * \param n 0 if the BIGNUM b should be positive and a value != 0 otherwise */ void BN_set_negative(BIGNUM *b, int n); + +#if defined(LIBRESSL_OPAQUE_BN) || defined(LIBRESSL_CRYPTO_INTERNAL) +int BN_is_negative(const BIGNUM *b); +#else /** BN_is_negative returns 1 if the BIGNUM is negative * \param a pointer to the BIGNUM object * \return 1 if a < 0 and 0 otherwise */ #define BN_is_negative(a) ((a)->neg != 0) +#endif #ifndef LIBRESSL_INTERNAL int BN_div(BIGNUM *dv, BIGNUM *rem, const BIGNUM *m, const BIGNUM *d, diff --git a/lib/libcrypto/bn/bn_lib.c b/lib/libcrypto/bn/bn_lib.c index 77ee3b1fdcd..2544722ea9a 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.51 2021/12/04 15:59:52 tb Exp $ */ +/* $OpenBSD: bn_lib.c,v 1.52 2021/12/04 16:02:44 tb Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -1099,6 +1099,12 @@ BN_is_odd(const BIGNUM *a) return a->top > 0 && (a->d[0] & 1); } +int +BN_is_negative(const BIGNUM *a) +{ + return a->neg != 0; +} + BN_GENCB * BN_GENCB_new(void) { -- 2.20.1