-/* $OpenBSD: bn_add.c,v 1.14 2022/11/24 01:30:01 jsing Exp $ */
+/* $OpenBSD: bn_add.c,v 1.15 2022/11/26 13:56:33 jsing Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
{
int ret, r_neg;
- bn_check_top(a);
- bn_check_top(b);
if (a->neg == b->neg) {
r_neg = a->neg;
}
r->neg = r_neg;
- bn_check_top(r);
return ret;
}
const BN_ULONG *ap, *bp;
BN_ULONG *rp, carry, t1, t2;
- bn_check_top(a);
- bn_check_top(b);
if (a->top < b->top) {
const BIGNUM *tmp;
r->top += carry;
r->neg = 0;
- bn_check_top(r);
return 1;
}
const BN_ULONG *ap, *bp;
BN_ULONG t1, t2, borrow, *rp;
- bn_check_top(a);
- bn_check_top(b);
max = a->top;
min = b->top;
{
int ret, r_neg;
- bn_check_top(a);
- bn_check_top(b);
if (a->neg != b->neg) {
r_neg = a->neg;
}
r->neg = r_neg;
- bn_check_top(r);
return ret;
}
-/* $OpenBSD: bn_blind.c,v 1.17 2017/01/29 17:49:22 beck Exp $ */
+/* $OpenBSD: bn_blind.c,v 1.18 2022/11/26 13:56:33 jsing Exp $ */
/* ====================================================================
* Copyright (c) 1998-2006 The OpenSSL Project. All rights reserved.
*
{
BN_BLINDING *ret = NULL;
- bn_check_top(mod);
if ((ret = calloc(1, sizeof(BN_BLINDING))) == NULL) {
BNerror(ERR_R_MALLOC_FAILURE);
{
int ret = 1;
- bn_check_top(n);
if ((b->A == NULL) || (b->Ai == NULL)) {
BNerror(BN_R_NOT_INITIALIZED);
{
int ret;
- bn_check_top(n);
if (r != NULL)
ret = BN_mod_mul(n, n, r, b->mod, ctx);
ret = BN_mod_mul(n, n, b->Ai, b->mod, ctx);
}
- bn_check_top(n);
return (ret);
}
-/* $OpenBSD: bn_ctx.c,v 1.16 2019/08/20 10:59:09 schwarze Exp $ */
+/* $OpenBSD: bn_ctx.c,v 1.17 2022/11/26 13:56:33 jsing Exp $ */
/* Written by Ulf Moeller for the OpenSSL project. */
/* ====================================================================
* Copyright (c) 1998-2004 The OpenSSL Project. All rights reserved.
p->used -= num;
while (num--) {
- bn_check_top(p->current->vals + offset);
if (!offset) {
offset = BN_CTX_POOL_SIZE - 1;
p->current = p->current->prev;
-/* $OpenBSD: bn_div.c,v 1.26 2022/11/24 01:30:01 jsing Exp $ */
+/* $OpenBSD: bn_div.c,v 1.27 2022/11/26 13:56:33 jsing Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
int num_n, div_n;
int no_branch = 0;
- /* Invalid zero-padding would have particularly bad consequences
- * in the case of 'num', so don't just rely on bn_check_top() for this one
- * (bn_check_top() works only for BN_DEBUG builds) */
+ /* Invalid zero-padding would have particularly bad consequences. */
if (num->top > 0 && num->d[num->top - 1] == 0) {
BNerror(BN_R_NOT_INITIALIZED);
return 0;
}
- bn_check_top(num);
if (ct)
no_branch = 1;
- bn_check_top(dv);
- bn_check_top(rm);
- /* bn_check_top(num); */ /* 'num' has been checked already */
- bn_check_top(divisor);
if (BN_is_zero(divisor)) {
BNerror(BN_R_DIV_BY_ZERO);
if (!no_branch) {
if (BN_ucmp(&wnum, sdiv) >= 0) {
- /* If BN_DEBUG_RAND is defined BN_ucmp changes (via
- * bn_pollute) the const bignum arguments =>
- * clean the values between top and max again */
- bn_clear_top2max(&wnum);
bn_sub_words(wnum.d, wnum.d, sdiv->d, div_n);
*resp = 1;
} else
BN_rshift(rm, snum, norm_shift);
if (!BN_is_zero(rm))
rm->neg = neg;
- bn_check_top(rm);
}
if (no_branch)
bn_correct_top(res);
return (1);
err:
- bn_check_top(rm);
BN_CTX_end(ctx);
return (0);
}
-/* $OpenBSD: bn_exp.c,v 1.33 2022/11/24 01:30:01 jsing Exp $ */
+/* $OpenBSD: bn_exp.c,v 1.34 2022/11/26 13:56:33 jsing Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
if (r != rr && rr != NULL)
BN_copy(r, rr);
BN_CTX_end(ctx);
- bn_check_top(r);
return (ret);
}
{
int ret;
- bn_check_top(a);
- bn_check_top(p);
- bn_check_top(m);
/* For even modulus m = 2^k*m_odd, it might make sense to compute
* a^p mod m_odd and a^p mod 2^k separately (with Montgomery
ret = BN_mod_exp_recp(r, a,p, m, ctx);
}
- bn_check_top(r);
return (ret);
}
err:
BN_CTX_end(ctx);
BN_RECP_CTX_free(&recp);
- bn_check_top(r);
return (ret);
}
return BN_mod_exp_mont_consttime(rr, a, p, m, ctx, in_mont);
}
- bn_check_top(a);
- bn_check_top(p);
- bn_check_top(m);
if (!BN_is_odd(m)) {
BNerror(BN_R_CALLED_WITH_EVEN_MODULUS);
if ((in_mont == NULL) && (mont != NULL))
BN_MONT_CTX_free(mont);
BN_CTX_end(ctx);
- bn_check_top(rr);
return (ret);
}
unsigned char *powerbuf = NULL;
BIGNUM tmp, am;
- bn_check_top(a);
- bn_check_top(p);
- bn_check_top(m);
if (!BN_is_odd(m)) {
BNerror(BN_R_CALLED_WITH_EVEN_MODULUS);
return -1;
}
- bn_check_top(p);
- bn_check_top(m);
if (!BN_is_odd(m)) {
BNerror(BN_R_CALLED_WITH_EVEN_MODULUS);
if ((in_mont == NULL) && (mont != NULL))
BN_MONT_CTX_free(mont);
BN_CTX_end(ctx);
- bn_check_top(rr);
return (ret);
}
err:
BN_CTX_end(ctx);
- bn_check_top(r);
return (ret);
}
-/* $OpenBSD: bn_exp2.c,v 1.13 2022/02/07 19:49:56 tb Exp $ */
+/* $OpenBSD: bn_exp2.c,v 1.14 2022/11/26 13:56:33 jsing Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
BIGNUM *val1[TABLE_SIZE], *val2[TABLE_SIZE];
BN_MONT_CTX *mont = NULL;
- bn_check_top(a1);
- bn_check_top(p1);
- bn_check_top(a2);
- bn_check_top(p2);
- bn_check_top(m);
if (!BN_is_odd(m)) {
BNerror(BN_R_CALLED_WITH_EVEN_MODULUS);
if ((in_mont == NULL) && (mont != NULL))
BN_MONT_CTX_free(mont);
BN_CTX_end(ctx);
- bn_check_top(rr);
return (ret);
}
-/* $OpenBSD: bn_gcd.c,v 1.16 2021/12/26 15:16:50 tb Exp $ */
+/* $OpenBSD: bn_gcd.c,v 1.17 2022/11/26 13:56:33 jsing Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
BIGNUM *a, *b, *t;
int ret = 0;
- bn_check_top(in_a);
- bn_check_top(in_b);
BN_CTX_start(ctx);
if ((a = BN_CTX_get(ctx)) == NULL)
err:
BN_CTX_end(ctx);
- bn_check_top(r);
return (ret);
}
BIGNUM *t;
int shifts = 0;
- bn_check_top(a);
- bn_check_top(b);
/* 0 <= b <= a */
while (!BN_is_zero(b)) {
if (!BN_lshift(a, a, shifts))
goto err;
}
- bn_check_top(a);
return (a);
err:
if (ct)
return BN_mod_inverse_no_branch(in, a, n, ctx);
- bn_check_top(a);
- bn_check_top(n);
BN_CTX_start(ctx);
if ((A = BN_CTX_get(ctx)) == NULL)
if ((ret == NULL) && (in == NULL))
BN_free(R);
BN_CTX_end(ctx);
- bn_check_top(ret);
return (ret);
}
BIGNUM *ret = NULL;
int sign;
- bn_check_top(a);
- bn_check_top(n);
BN_init(&local_A);
BN_init(&local_B);
if ((ret == NULL) && (in == NULL))
BN_free(R);
BN_CTX_end(ctx);
- bn_check_top(ret);
return (ret);
}
BN_init(&local_A);
BN_init(&local_B);
- bn_check_top(a);
- bn_check_top(n);
BN_CTX_start(ctx);
if ((A = BN_CTX_get(ctx)) == NULL)
if ((ret == NULL) && (in == NULL))
BN_free(R);
BN_CTX_end(ctx);
- bn_check_top(ret);
return (ret);
}
-/* $OpenBSD: bn_gf2m.c,v 1.26 2022/11/24 01:30:01 jsing Exp $ */
+/* $OpenBSD: bn_gf2m.c,v 1.27 2022/11/26 13:56:33 jsing Exp $ */
/* ====================================================================
* Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
*
int i;
const BIGNUM *at, *bt;
- bn_check_top(a);
- bn_check_top(b);
if (a->top < b->top) {
at = b;
int n, dN, d0, d1;
BN_ULONG zz, *z;
- bn_check_top(a);
if (!p[0]) {
/* reduction mod 1 => return 0 */
const int max = BN_num_bits(p) + 1;
int *arr = NULL;
- bn_check_top(a);
- bn_check_top(p);
if ((arr = reallocarray(NULL, max, sizeof(int))) == NULL)
goto err;
ret = BN_GF2m_poly2arr(p, arr, max);
goto err;
}
ret = BN_GF2m_mod_arr(r, a, arr);
- bn_check_top(r);
err:
free(arr);
BIGNUM *s;
BN_ULONG x1, x0, y1, y0, zz[4];
- bn_check_top(a);
- bn_check_top(b);
if (a == b) {
return BN_GF2m_mod_sqr_arr(r, a, p, ctx);
bn_correct_top(s);
if (BN_GF2m_mod_arr(r, s, p))
ret = 1;
- bn_check_top(r);
err:
BN_CTX_end(ctx);
const int max = BN_num_bits(p) + 1;
int *arr = NULL;
- bn_check_top(a);
- bn_check_top(b);
- bn_check_top(p);
if ((arr = reallocarray(NULL, max, sizeof(int))) == NULL)
goto err;
ret = BN_GF2m_poly2arr(p, arr, max);
goto err;
}
ret = BN_GF2m_mod_mul_arr(r, a, b, arr, ctx);
- bn_check_top(r);
err:
free(arr);
int i, ret = 0;
BIGNUM *s;
- bn_check_top(a);
BN_CTX_start(ctx);
if ((s = BN_CTX_get(ctx)) == NULL)
goto err;
bn_correct_top(s);
if (!BN_GF2m_mod_arr(r, s, p))
goto err;
- bn_check_top(r);
ret = 1;
err:
const int max = BN_num_bits(p) + 1;
int *arr = NULL;
- bn_check_top(a);
- bn_check_top(p);
if ((arr = reallocarray(NULL, max, sizeof(int))) == NULL)
goto err;
ret = BN_GF2m_poly2arr(p, arr, max);
goto err;
}
ret = BN_GF2m_mod_sqr_arr(r, a, arr, ctx);
- bn_check_top(r);
err:
free(arr);
BIGNUM *b, *c = NULL, *u = NULL, *v = NULL, *tmp;
int ret = 0;
- bn_check_top(a);
- bn_check_top(p);
BN_CTX_start(ctx);
if (!BN_copy(r, b))
goto err;
- bn_check_top(r);
ret = 1;
err:
BIGNUM *field;
int ret = 0;
- bn_check_top(xx);
BN_CTX_start(ctx);
if ((field = BN_CTX_get(ctx)) == NULL)
goto err;
goto err;
ret = BN_GF2m_mod_inv(r, xx, field, ctx);
- bn_check_top(r);
err:
BN_CTX_end(ctx);
BIGNUM *xinv = NULL;
int ret = 0;
- bn_check_top(y);
- bn_check_top(x);
- bn_check_top(p);
BN_CTX_start(ctx);
if ((xinv = BN_CTX_get(ctx)) == NULL)
goto err;
if (!BN_GF2m_mod_mul(r, y, xinv, p, ctx))
goto err;
- bn_check_top(r);
ret = 1;
err:
BIGNUM *a, *b, *u, *v;
int ret = 0;
- bn_check_top(y);
- bn_check_top(x);
- bn_check_top(p);
BN_CTX_start(ctx);
if (!BN_copy(r, u))
goto err;
- bn_check_top(r);
ret = 1;
err:
BIGNUM *field;
int ret = 0;
- bn_check_top(yy);
- bn_check_top(xx);
BN_CTX_start(ctx);
if ((field = BN_CTX_get(ctx)) == NULL)
goto err;
ret = BN_GF2m_mod_div(r, yy, xx, field, ctx);
- bn_check_top(r);
err:
BN_CTX_end(ctx);
int ret = 0, i, n;
BIGNUM *u;
- bn_check_top(a);
- bn_check_top(b);
if (BN_is_zero(b))
return (BN_one(r));
}
if (!BN_copy(r, u))
goto err;
- bn_check_top(r);
ret = 1;
err:
const int max = BN_num_bits(p) + 1;
int *arr = NULL;
- bn_check_top(a);
- bn_check_top(b);
- bn_check_top(p);
if ((arr = reallocarray(NULL, max, sizeof(int))) == NULL)
goto err;
ret = BN_GF2m_poly2arr(p, arr, max);
goto err;
}
ret = BN_GF2m_mod_exp_arr(r, a, b, arr, ctx);
- bn_check_top(r);
err:
free(arr);
int ret = 0;
BIGNUM *u;
- bn_check_top(a);
if (!p[0]) {
/* reduction mod 1 => return 0 */
if (!BN_set_bit(u, p[0] - 1))
goto err;
ret = BN_GF2m_mod_exp_arr(r, a, u, p, ctx);
- bn_check_top(r);
err:
BN_CTX_end(ctx);
int ret = 0;
const int max = BN_num_bits(p) + 1;
int *arr = NULL;
- bn_check_top(a);
- bn_check_top(p);
if ((arr = reallocarray(NULL, max, sizeof(int))) == NULL)
goto err;
ret = BN_GF2m_poly2arr(p, arr, max);
goto err;
}
ret = BN_GF2m_mod_sqrt_arr(r, a, arr, ctx);
- bn_check_top(r);
err:
free(arr);
int ret = 0, count = 0, j;
BIGNUM *a, *z, *rho, *w, *w2, *tmp;
- bn_check_top(a_);
if (!p[0]) {
/* reduction mod 1 => return 0 */
if (!BN_copy(r, z))
goto err;
- bn_check_top(r);
ret = 1;
const int max = BN_num_bits(p) + 1;
int *arr = NULL;
- bn_check_top(a);
- bn_check_top(p);
if ((arr = reallocarray(NULL, max, sizeof(int))) == NULL)
goto err;
ret = BN_GF2m_poly2arr(p, arr, max);
goto err;
}
ret = BN_GF2m_mod_solve_quad_arr(r, a, arr, ctx);
- bn_check_top(r);
err:
free(arr);
{
int i;
- bn_check_top(a);
BN_zero(a);
for (i = 0; p[i] != -1; i++) {
if (BN_set_bit(a, p[i]) == 0)
return 0;
}
- bn_check_top(a);
return 1;
}
-/* $OpenBSD: bn_kron.c,v 1.10 2022/07/12 16:08:19 tb Exp $ */
+/* $OpenBSD: bn_kron.c,v 1.11 2022/11/26 13:56:33 jsing Exp $ */
/* ====================================================================
* Copyright (c) 1998-2000 The OpenSSL Project. All rights reserved.
*
int k, v;
int ret = -2;
- bn_check_top(A);
- bn_check_top(B);
BN_CTX_start(ctx);
-/* $OpenBSD: bn_lcl.h,v 1.38 2022/11/24 01:30:01 jsing Exp $ */
+/* $OpenBSD: bn_lcl.h,v 1.39 2022/11/26 13:56:33 jsing Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
#define Lw(t) (((BN_ULONG)(t))&BN_MASK2)
#define Hw(t) (((BN_ULONG)((t)>>BN_BITS2))&BN_MASK2)
-#ifdef BN_DEBUG_RAND
-#define bn_clear_top2max(a) \
- { \
- int ind = (a)->dmax - (a)->top; \
- BN_ULONG *ftl = &(a)->d[(a)->top-1]; \
- for (; ind != 0; ind--) \
- *(++ftl) = 0x0; \
- }
-#else
-#define bn_clear_top2max(a)
-#endif
-
#ifdef BN_LLONG
#define mul_add(r,a,w,c) { \
BN_ULLONG t; \
int bn_expand(BIGNUM *a, int bits);
int bn_wexpand(BIGNUM *a, int words);
-/* Bignum consistency macros
- * There is one "API" macro, bn_fix_top(), for stripping leading zeroes from
- * bignum data after direct manipulations on the data. There is also an
- * "internal" macro, bn_check_top(), for verifying that there are no leading
- * zeroes. Unfortunately, some auditing is required due to the fact that
- * bn_fix_top() has become an overabused duct-tape because bignum data is
- * occasionally passed around in an inconsistent state. So the following
- * changes have been made to sort this out;
- * - bn_fix_top()s implementation has been moved to bn_correct_top()
- * - if BN_DEBUG isn't defined, bn_fix_top() maps to bn_correct_top(), and
- * bn_check_top() is as before.
- * - if BN_DEBUG *is* defined;
- * - bn_check_top() tries to pollute unused words even if the bignum 'top' is
- * consistent. (ed: only if BN_DEBUG_RAND is defined)
- * - bn_fix_top() maps to bn_check_top() rather than "fixing" anything.
- * The idea is to have debug builds flag up inconsistent bignums when they
- * occur. If that occurs in a bn_fix_top(), we examine the code in question; if
- * the use of bn_fix_top() was appropriate (ie. it follows directly after code
- * that manipulates the bignum) it is converted to bn_correct_top(), and if it
- * was not appropriate, we convert it permanently to bn_check_top() and track
- * down the cause of the bug. Eventually, no internal code should be using the
- * bn_fix_top() macro. External applications and libraries should try this with
- * their own code too, both in terms of building against the openssl headers
- * with BN_DEBUG defined *and* linking with a version of OpenSSL built with it
- * defined. This not only improves external code, it provides more test
- * coverage for openssl's own code.
- */
-
-#ifdef BN_DEBUG
-
-/* We only need assert() when debugging */
-#include <assert.h>
-
-#ifdef BN_DEBUG_RAND
-#define bn_pollute(a) \
- do { \
- const BIGNUM *_bnum1 = (a); \
- if(_bnum1->top < _bnum1->dmax) { \
- unsigned char _tmp_char; \
- /* We cast away const without the compiler knowing, any \
- * *genuinely* constant variables that aren't mutable \
- * wouldn't be constructed with top!=dmax. */ \
- BN_ULONG *_not_const; \
- memcpy(&_not_const, &_bnum1->d, sizeof(BN_ULONG*)); \
- arc4random_buf(&_tmp_char, 1); \
- memset((unsigned char *)(_not_const + _bnum1->top), _tmp_char, \
- (_bnum1->dmax - _bnum1->top) * sizeof(BN_ULONG)); \
- } \
- } while(0)
-#else
-#define bn_pollute(a)
-#endif
-
-#define bn_check_top(a) \
- do { \
- const BIGNUM *_bnum2 = (a); \
- if (_bnum2 != NULL) { \
- assert((_bnum2->top == 0) || \
- (_bnum2->d[_bnum2->top - 1] != 0)); \
- bn_pollute(_bnum2); \
- } \
- } while(0)
-
-#define bn_fix_top(a) bn_check_top(a)
-
-#define bn_check_size(bn, bits) bn_wcheck_size(bn, ((bits+BN_BITS2-1))/BN_BITS2)
-#define bn_wcheck_size(bn, words) \
- do { \
- const BIGNUM *_bnum2 = (bn); \
- assert(words <= (_bnum2)->dmax && words >= (_bnum2)->top); \
- } while(0)
-
-#else /* !BN_DEBUG */
-
-#define bn_pollute(a)
-#define bn_check_top(a)
-#define bn_fix_top(a) bn_correct_top(a)
-#define bn_check_size(bn, bits)
-#define bn_wcheck_size(bn, words)
-
-#endif
-
#define bn_correct_top(a) \
{ \
BN_ULONG *ftl; \
if (*(ftl--)) break; \
(a)->top = tmp_top; \
} \
- bn_pollute(a); \
}
BN_ULONG bn_mul_add_words(BN_ULONG *rp, const BN_ULONG *ap, int num, BN_ULONG w);
-/* $OpenBSD: bn_lib.c,v 1.61 2022/11/24 01:30:01 jsing Exp $ */
+/* $OpenBSD: bn_lib.c,v 1.62 2022/11/26 13:56:33 jsing Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
ret->neg = 0;
ret->dmax = 0;
ret->d = NULL;
- bn_check_top(ret);
return (ret);
}
BN_init(BIGNUM *a)
{
memset(a, 0, sizeof(BIGNUM));
- bn_check_top(a);
}
void
BN_clear(BIGNUM *a)
{
- bn_check_top(a);
if (a->d != NULL)
explicit_bzero(a->d, a->dmax * sizeof(a->d[0]));
a->top = 0;
if (a == NULL)
return;
- bn_check_top(a);
if (a->d != NULL && !(BN_get_flags(a, BN_FLG_STATIC_DATA)))
freezero(a->d, a->dmax * sizeof(a->d[0]));
i = BN_get_flags(a, BN_FLG_MALLOCED);
{
int i = a->top - 1;
- bn_check_top(a);
if (BN_is_zero(a))
return 0;
const BN_ULONG *B;
int i;
- bn_check_top(b);
if (words > (INT_MAX/(4*BN_BITS2))) {
BNerror(BN_R_BIGNUM_TOO_LONG);
static int
bn_expand2(BIGNUM *b, int words)
{
- bn_check_top(b);
if (words > b->dmax) {
BN_ULONG *a = bn_expand_internal(b, words);
assert(A == &(b->d[b->dmax]));
}
#endif
- bn_check_top(b);
return 1;
}
if (a == NULL)
return NULL;
- bn_check_top(a);
t = BN_new();
if (t == NULL)
BN_free(t);
return NULL;
}
- bn_check_top(t);
return t;
}
BN_ULONG *A;
const BN_ULONG *B;
- bn_check_top(b);
if (a == b)
return (a);
a->top = b->top;
a->neg = b->neg;
- bn_check_top(a);
return (a);
}
BN_ULONG *tmp_d;
int tmp_top, tmp_dmax, tmp_neg;
- bn_check_top(a);
- bn_check_top(b);
flags_old_a = a->flags;
flags_old_b = b->flags;
(flags_old_b & BN_FLG_STATIC_DATA);
b->flags = (flags_old_b & BN_FLG_MALLOCED) |
(flags_old_a & BN_FLG_STATIC_DATA);
- bn_check_top(a);
- bn_check_top(b);
}
BN_ULONG
int
BN_set_word(BIGNUM *a, BN_ULONG w)
{
- bn_check_top(a);
if (!bn_wexpand(a, 1))
return (0);
a->neg = 0;
a->d[0] = w;
a->top = (w ? 1 : 0);
- bn_check_top(a);
return (1);
}
ret = bn = BN_new();
if (ret == NULL)
return (NULL);
- bn_check_top(ret);
l = 0;
n = len;
if (n == 0) {
if (ret == NULL)
return NULL;
- bn_check_top(ret);
s += len;
/* Skip trailing zeroes. */
int i;
BN_ULONG t1, t2, *ap, *bp;
- bn_check_top(a);
- bn_check_top(b);
i = a->top - b->top;
if (i != 0)
return (0);
}
- bn_check_top(a);
- bn_check_top(b);
if (a->neg != b->neg) {
if (a->neg)
}
a->d[i] |= (((BN_ULONG)1) << j);
- bn_check_top(a);
return (1);
}
{
int i, j;
- bn_check_top(a);
if (n < 0)
return 0;
{
int i, j;
- bn_check_top(a);
if (n < 0)
return 0;
i = n / BN_BITS2;
{
int b, w;
- bn_check_top(a);
if (n < 0)
return 0;
BN_ULONG t;
int i;
- bn_wcheck_size(a, nwords);
- bn_wcheck_size(b, nwords);
-
assert(a != b);
assert((condition & (condition - 1)) == 0);
assert(sizeof(BN_ULONG) >= sizeof(int));
-/* $OpenBSD: bn_mod.c,v 1.12 2017/01/29 17:49:22 beck Exp $ */
+/* $OpenBSD: bn_mod.c,v 1.13 2022/11/26 13:56:33 jsing Exp $ */
/* Includes code written by Lenka Fibikova <fibikova@exp-math.uni-essen.de>
* for the OpenSSL project. */
/* ====================================================================
BIGNUM *t;
int ret = 0;
- bn_check_top(a);
- bn_check_top(b);
- bn_check_top(m);
BN_CTX_start(ctx);
if ((t = BN_CTX_get(ctx)) == NULL)
}
if (!BN_nnmod(r, t,m, ctx))
goto err;
- bn_check_top(r);
ret = 1;
err:
{
if (!BN_lshift1(r, a))
return 0;
- bn_check_top(r);
return BN_nnmod(r, r, m, ctx);
}
{
if (!BN_lshift1(r, a))
return 0;
- bn_check_top(r);
if (BN_cmp(r, m) >= 0)
return BN_sub(r, r, m);
return 1;
}
ret = BN_mod_lshift_quick(r, r, n, (abs_m ? abs_m : m));
- bn_check_top(r);
BN_free(abs_m);
return ret;
return 0;
}
}
- bn_check_top(r);
return 1;
}
-/* $OpenBSD: bn_mont.c,v 1.30 2022/11/24 01:30:01 jsing Exp $ */
+/* $OpenBSD: bn_mont.c,v 1.31 2022/11/26 13:56:33 jsing Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
if ((tmp = BN_CTX_get(ctx)) == NULL)
goto err;
- bn_check_top(tmp);
if (a == b) {
if (!BN_sqr(tmp, a, ctx))
goto err;
if (!BN_from_montgomery(r, tmp, mont, ctx))
goto err;
#endif
- bn_check_top(r);
ret = 1;
err:
BN_CTX_end(ctx);
#endif
bn_correct_top(r);
bn_correct_top(ret);
- bn_check_top(ret);
return (1);
}
goto err;
}
retn = 1;
- bn_check_top(ret);
err:
BN_CTX_end(ctx);
-/* $OpenBSD: bn_mpi.c,v 1.9 2022/11/09 01:05:45 tobhe Exp $ */
+/* $OpenBSD: bn_mpi.c,v 1.10 2022/11/26 13:56:33 jsing Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
if (neg) {
BN_clear_bit(a, BN_num_bits(a) - 1);
}
- bn_check_top(a);
return (a);
}
-/* $OpenBSD: bn_mul.c,v 1.21 2022/11/24 01:30:01 jsing Exp $ */
+/* $OpenBSD: bn_mul.c,v 1.22 2022/11/26 13:56:33 jsing Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
fprintf(stderr, "BN_mul %d * %d\n",a->top,b->top);
#endif
- bn_check_top(a);
- bn_check_top(b);
- bn_check_top(r);
al = a->top;
bl = b->top;
BN_copy(r, rr);
ret = 1;
err:
- bn_check_top(r);
BN_CTX_end(ctx);
return (ret);
}
-/* $OpenBSD: bn_prime.c,v 1.26 2022/11/09 22:52:51 tb Exp $ */
+/* $OpenBSD: bn_prime.c,v 1.27 2022/11/26 13:56:33 jsing Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
err:
BN_CTX_end(ctx);
BN_CTX_free(ctx);
- bn_check_top(ret);
return found;
}
}
if (!BN_add_word(rnd, delta))
return (0);
- bn_check_top(rnd);
return (1);
}
err:
BN_CTX_end(ctx);
- bn_check_top(rnd);
return (ret);
}
err:
BN_CTX_end(ctx);
- bn_check_top(p);
return (ret);
}
-/* $OpenBSD: bn_print.c,v 1.35 2022/11/24 01:30:01 jsing Exp $ */
+/* $OpenBSD: bn_print.c,v 1.36 2022/11/26 13:56:33 jsing Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
ret->neg = neg;
*bn = ret;
- bn_check_top(ret);
return (num);
err:
bn_correct_top(ret);
*bn = ret;
- bn_check_top(ret);
return (num);
err:
-/* $OpenBSD: bn_rand.c,v 1.25 2021/08/31 11:19:19 tb Exp $ */
+/* $OpenBSD: bn_rand.c,v 1.26 2022/11/26 13:56:33 jsing Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
err:
freezero(buf, bytes);
- bn_check_top(rnd);
return (ret);
}
} while (BN_cmp(r, range) >= 0);
}
- bn_check_top(r);
return 1;
}
-/* $OpenBSD: bn_recp.c,v 1.15 2017/01/29 17:49:22 beck Exp $ */
+/* $OpenBSD: bn_recp.c,v 1.16 2022/11/26 13:56:33 jsing Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
err:
BN_CTX_end(ctx);
- bn_check_top(r);
return (ret);
}
err:
BN_CTX_end(ctx);
- bn_check_top(dv);
- bn_check_top(rem);
return (ret);
}
ret = len;
err:
- bn_check_top(r);
BN_CTX_end(ctx);
return (ret);
}
-/* $OpenBSD: bn_shift.c,v 1.15 2022/11/24 01:30:01 jsing Exp $ */
+/* $OpenBSD: bn_shift.c,v 1.16 2022/11/26 13:56:33 jsing Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
BN_ULONG *ap, *rp, t, c;
int i;
- bn_check_top(r);
- bn_check_top(a);
if (r != a) {
r->neg = a->neg;
*rp = 1;
r->top++;
}
- bn_check_top(r);
return (1);
}
BN_ULONG *ap, *rp, t, c;
int i, j;
- bn_check_top(r);
- bn_check_top(a);
if (BN_is_zero(a)) {
BN_zero(r);
c = (t & 1) ? BN_TBIT : 0;
}
r->top = j;
- bn_check_top(r);
return (1);
}
return 0;
}
- bn_check_top(r);
- bn_check_top(a);
r->neg = a->neg;
nw = n / BN_BITS2;
t[i]=0;*/
r->top = a->top + nw + 1;
bn_correct_top(r);
- bn_check_top(r);
return (1);
}
return 0;
}
- bn_check_top(r);
- bn_check_top(a);
nw = n / BN_BITS2;
rb = n % BN_BITS2;
if ((l = (l >> rb) & BN_MASK2))
*(t) = l;
}
- bn_check_top(r);
return (1);
}
-/* $OpenBSD: bn_sqr.c,v 1.14 2022/11/24 01:30:01 jsing Exp $ */
+/* $OpenBSD: bn_sqr.c,v 1.15 2022/11/26 13:56:33 jsing Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
#ifdef BN_COUNT
fprintf(stderr, "BN_sqr %d * %d\n", a->top, a->top);
#endif
- bn_check_top(a);
al = a->top;
if (al <= 0) {
ret = 1;
err:
- bn_check_top(rr);
- bn_check_top(tmp);
BN_CTX_end(ctx);
return (ret);
}
-/* $OpenBSD: bn_sqrt.c,v 1.12 2022/11/19 12:25:23 tb Exp $ */
+/* $OpenBSD: bn_sqrt.c,v 1.13 2022/11/26 13:56:33 jsing Exp $ */
/* Written by Lenka Fibikova <fibikova@exp-math.uni-essen.de>
* and Bodo Moeller for the OpenSSL project. */
/* ====================================================================
BN_free(ret);
return NULL;
}
- bn_check_top(ret);
return ret;
}
BN_free(ret);
return NULL;
}
- bn_check_top(ret);
return ret;
}
ret = NULL;
}
BN_CTX_end(ctx);
- bn_check_top(ret);
return ret;
}
-/* $OpenBSD: bn_word.c,v 1.14 2022/11/24 01:30:01 jsing Exp $ */
+/* $OpenBSD: bn_word.c,v 1.15 2022/11/26 13:56:33 jsing Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
}
#endif
- bn_check_top(a);
w &= BN_MASK2;
for (i = a->top - 1; i >= 0; i--) {
#ifndef BN_LLONG
BN_ULONG ret = 0;
int i, j;
- bn_check_top(a);
w &= BN_MASK2;
if (!w)
if ((a->top > 0) && (a->d[a->top - 1] == 0))
a->top--;
ret >>= j;
- bn_check_top(a);
return (ret);
}
BN_ULONG l;
int i;
- bn_check_top(a);
w &= BN_MASK2;
/* degenerate case: w is zero */
a->top++;
a->d[i] = w;
}
- bn_check_top(a);
return (1);
}
{
int i;
- bn_check_top(a);
w &= BN_MASK2;
/* degenerate case: w is zero */
}
if ((a->d[i] == 0) && (i == (a->top - 1)))
a->top--;
- bn_check_top(a);
return (1);
}
{
BN_ULONG ll;
- bn_check_top(a);
w &= BN_MASK2;
if (a->top) {
if (w == 0)
}
}
}
- bn_check_top(a);
return (1);
}