BN_zero() is currently implemented using BN_set_word(), which means it can
fail, however almost nothing ever checks the return value. A long time
ago OpenSSL changed BN_zero() to always succeed and return void, however
kept BN_zero as a macro that calls a new BN_zero_ex() function, so that
it can be switched back to the "can fail" version.
Take a simpler approach - change BN_zero()/BN_one() to functions and make
BN_zero() always succeed. This will be exposed in the next bump, at which
point we can hopefully also remove the BN_zero_ex() function.
ok tb@
-/* $OpenBSD: bn.h,v 1.56 2022/11/30 01:47:19 jsing Exp $ */
+/* $OpenBSD: bn.h,v 1.57 2022/12/17 15:56:25 jsing Exp $ */
/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
int BN_is_word(const BIGNUM *a, const BN_ULONG w);
int BN_is_odd(const BIGNUM *a);
+#if defined(LIBRESSL_INTERNAL) || defined(LIBRESSL_NEXT_API)
+void BN_zero(BIGNUM *a);
+int BN_one(BIGNUM *a);
+#else
#define BN_one(a) BN_set_word((a), 1)
void BN_zero_ex(BIGNUM *a);
#else
#define BN_zero(a) (BN_set_word((a),0))
#endif
+#endif
const BIGNUM *BN_value_one(void);
char * BN_options(void);
-/* $OpenBSD: bn_isqrt.c,v 1.5 2022/12/01 21:59:54 tb Exp $ */
+/* $OpenBSD: bn_isqrt.c,v 1.6 2022/12/17 15:56:25 jsing Exp $ */
/*
* Copyright (c) 2022 Theo Buehler <tb@openbsd.org>
*
if (BN_is_zero(n)) {
perfect = 1;
- if (!BN_zero(a))
- goto err;
+ BN_zero(a);
goto done;
}
-/* $OpenBSD: bn_lib.c,v 1.66 2022/11/30 03:08:39 jsing Exp $ */
+/* $OpenBSD: bn_lib.c,v 1.67 2022/12/17 15:56:25 jsing Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
}
void
-BN_zero_ex(BIGNUM *a)
+BN_zero(BIGNUM *a)
{
a->neg = 0;
a->top = 0;
- /* XXX: a->flags &= ~BN_FIXED_TOP */
+}
+
+void
+BN_zero_ex(BIGNUM *a)
+{
+ BN_zero(a);
+}
+
+int
+BN_one(BIGNUM *a)
+{
+ return BN_set_word(a, 1);
}
int