early-access version 2698
This commit is contained in:
4
externals/libressl/crypto/bn/bn_exp2.c
vendored
4
externals/libressl/crypto/bn/bn_exp2.c
vendored
@@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: bn_exp2.c,v 1.12 2017/01/29 17:49:22 beck Exp $ */
|
||||
/* $OpenBSD: bn_exp2.c,v 1.13 2022/02/07 19:49:56 tb Exp $ */
|
||||
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
|
||||
* All rights reserved.
|
||||
*
|
||||
@@ -136,7 +136,7 @@ BN_mod_exp2_mont(BIGNUM *rr, const BIGNUM *a1, const BIGNUM *p1,
|
||||
bn_check_top(p2);
|
||||
bn_check_top(m);
|
||||
|
||||
if (!(m->d[0] & 1)) {
|
||||
if (!BN_is_odd(m)) {
|
||||
BNerror(BN_R_CALLED_WITH_EVEN_MODULUS);
|
||||
return (0);
|
||||
}
|
||||
|
40
externals/libressl/crypto/bn/bn_gcd.c
vendored
40
externals/libressl/crypto/bn/bn_gcd.c
vendored
@@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: bn_gcd.c,v 1.15 2017/01/29 17:49:22 beck Exp $ */
|
||||
/* $OpenBSD: bn_gcd.c,v 1.16 2021/12/26 15:16:50 tb Exp $ */
|
||||
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
|
||||
* All rights reserved.
|
||||
*
|
||||
@@ -576,6 +576,9 @@ BN_mod_inverse_no_branch(BIGNUM *in, const BIGNUM *a, const BIGNUM *n,
|
||||
bn_check_top(a);
|
||||
bn_check_top(n);
|
||||
|
||||
BN_init(&local_A);
|
||||
BN_init(&local_B);
|
||||
|
||||
BN_CTX_start(ctx);
|
||||
if ((A = BN_CTX_get(ctx)) == NULL)
|
||||
goto err;
|
||||
@@ -608,10 +611,12 @@ BN_mod_inverse_no_branch(BIGNUM *in, const BIGNUM *a, const BIGNUM *n,
|
||||
A->neg = 0;
|
||||
|
||||
if (B->neg || (BN_ucmp(B, A) >= 0)) {
|
||||
/* Turn BN_FLG_CONSTTIME flag on, so that when BN_div is invoked,
|
||||
* BN_div_no_branch will be called eventually.
|
||||
*/
|
||||
/*
|
||||
* Turn BN_FLG_CONSTTIME flag on, so that when BN_div is invoked,
|
||||
* BN_div_no_branch will be called eventually.
|
||||
*/
|
||||
pB = &local_B;
|
||||
/* BN_init() done at the top of the function. */
|
||||
BN_with_flags(pB, B, BN_FLG_CONSTTIME);
|
||||
if (!BN_nnmod(B, pB, A, ctx))
|
||||
goto err;
|
||||
@@ -633,10 +638,12 @@ BN_mod_inverse_no_branch(BIGNUM *in, const BIGNUM *a, const BIGNUM *n,
|
||||
* sign*Y*a == A (mod |n|)
|
||||
*/
|
||||
|
||||
/* Turn BN_FLG_CONSTTIME flag on, so that when BN_div is invoked,
|
||||
* BN_div_no_branch will be called eventually.
|
||||
*/
|
||||
/*
|
||||
* Turn BN_FLG_CONSTTIME flag on, so that when BN_div is invoked,
|
||||
* BN_div_no_branch will be called eventually.
|
||||
*/
|
||||
pA = &local_A;
|
||||
/* BN_init() done at the top of the function. */
|
||||
BN_with_flags(pA, A, BN_FLG_CONSTTIME);
|
||||
|
||||
/* (D, M) := (A/B, A%B) ... */
|
||||
@@ -740,6 +747,9 @@ BN_gcd_no_branch(BIGNUM *in, const BIGNUM *a, const BIGNUM *n,
|
||||
goto err;
|
||||
R = in;
|
||||
|
||||
BN_init(&local_A);
|
||||
BN_init(&local_B);
|
||||
|
||||
bn_check_top(a);
|
||||
bn_check_top(n);
|
||||
|
||||
@@ -768,10 +778,12 @@ BN_gcd_no_branch(BIGNUM *in, const BIGNUM *a, const BIGNUM *n,
|
||||
A->neg = 0;
|
||||
|
||||
if (B->neg || (BN_ucmp(B, A) >= 0)) {
|
||||
/* Turn BN_FLG_CONSTTIME flag on, so that when BN_div is invoked,
|
||||
* BN_div_no_branch will be called eventually.
|
||||
*/
|
||||
/*
|
||||
* Turn BN_FLG_CONSTTIME flag on, so that when BN_div is invoked,
|
||||
* BN_div_no_branch will be called eventually.
|
||||
*/
|
||||
pB = &local_B;
|
||||
/* BN_init() done at the top of the function. */
|
||||
BN_with_flags(pB, B, BN_FLG_CONSTTIME);
|
||||
if (!BN_nnmod(B, pB, A, ctx))
|
||||
goto err;
|
||||
@@ -793,10 +805,12 @@ BN_gcd_no_branch(BIGNUM *in, const BIGNUM *a, const BIGNUM *n,
|
||||
* sign*Y*a == A (mod |n|)
|
||||
*/
|
||||
|
||||
/* Turn BN_FLG_CONSTTIME flag on, so that when BN_div is invoked,
|
||||
* BN_div_no_branch will be called eventually.
|
||||
*/
|
||||
/*
|
||||
* Turn BN_FLG_CONSTTIME flag on, so that when BN_div is invoked,
|
||||
* BN_div_no_branch will be called eventually.
|
||||
*/
|
||||
pA = &local_A;
|
||||
/* BN_init() done at the top of the function. */
|
||||
BN_with_flags(pA, A, BN_FLG_CONSTTIME);
|
||||
|
||||
/* (D, M) := (A/B, A%B) ... */
|
||||
|
46
externals/libressl/crypto/bn/bn_lcl.h
vendored
46
externals/libressl/crypto/bn/bn_lcl.h
vendored
@@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: bn_lcl.h,v 1.30 2018/11/05 23:52:47 tb Exp $ */
|
||||
/* $OpenBSD: bn_lcl.h,v 1.31 2022/01/14 08:01:47 tb Exp $ */
|
||||
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
|
||||
* All rights reserved.
|
||||
*
|
||||
@@ -118,6 +118,50 @@
|
||||
|
||||
__BEGIN_HIDDEN_DECLS
|
||||
|
||||
struct bignum_st {
|
||||
BN_ULONG *d; /* Pointer to an array of 'BN_BITS2' bit chunks. */
|
||||
int top; /* Index of last used d +1. */
|
||||
/* The next are internal book keeping for bn_expand. */
|
||||
int dmax; /* Size of the d array. */
|
||||
int neg; /* one if the number is negative */
|
||||
int flags;
|
||||
};
|
||||
|
||||
/* Used for montgomery multiplication */
|
||||
struct bn_mont_ctx_st {
|
||||
int ri; /* number of bits in R */
|
||||
BIGNUM RR; /* used to convert to montgomery form */
|
||||
BIGNUM N; /* The modulus */
|
||||
BIGNUM Ni; /* R*(1/R mod N) - N*Ni = 1
|
||||
* (Ni is only stored for bignum algorithm) */
|
||||
BN_ULONG n0[2];/* least significant word(s) of Ni;
|
||||
(type changed with 0.9.9, was "BN_ULONG n0;" before) */
|
||||
int flags;
|
||||
};
|
||||
|
||||
/* Used for reciprocal division/mod functions
|
||||
* It cannot be shared between threads
|
||||
*/
|
||||
struct bn_recp_ctx_st {
|
||||
BIGNUM N; /* the divisor */
|
||||
BIGNUM Nr; /* the reciprocal */
|
||||
int num_bits;
|
||||
int shift;
|
||||
int flags;
|
||||
};
|
||||
|
||||
/* Used for slow "generation" functions. */
|
||||
struct bn_gencb_st {
|
||||
unsigned int ver; /* To handle binary (in)compatibility */
|
||||
void *arg; /* callback-specific data */
|
||||
union {
|
||||
/* if(ver==1) - handles old style callbacks */
|
||||
void (*cb_1)(int, int, void *);
|
||||
/* if(ver==2) - new callback style */
|
||||
int (*cb_2)(int, int, BN_GENCB *);
|
||||
} cb;
|
||||
};
|
||||
|
||||
/*
|
||||
* BN_window_bits_for_exponent_size -- macro for sliding window mod_exp functions
|
||||
*
|
||||
|
341
externals/libressl/crypto/bn/bn_lib.c
vendored
341
externals/libressl/crypto/bn/bn_lib.c
vendored
@@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: bn_lib.c,v 1.47 2019/06/17 17:11:48 tb Exp $ */
|
||||
/* $OpenBSD: bn_lib.c,v 1.53 2021/12/27 15:12:22 jsing Exp $ */
|
||||
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
|
||||
* All rights reserved.
|
||||
*
|
||||
@@ -92,6 +92,63 @@ static int bn_limit_num_high = 8; /* (1<<bn_limit_bits_high) */
|
||||
static int bn_limit_bits_mont = 0;
|
||||
static int bn_limit_num_mont = 8; /* (1<<bn_limit_bits_mont) */
|
||||
|
||||
BIGNUM *
|
||||
BN_new(void)
|
||||
{
|
||||
BIGNUM *ret;
|
||||
|
||||
if ((ret = malloc(sizeof(BIGNUM))) == NULL) {
|
||||
BNerror(ERR_R_MALLOC_FAILURE);
|
||||
return (NULL);
|
||||
}
|
||||
ret->flags = BN_FLG_MALLOCED;
|
||||
ret->top = 0;
|
||||
ret->neg = 0;
|
||||
ret->dmax = 0;
|
||||
ret->d = NULL;
|
||||
bn_check_top(ret);
|
||||
return (ret);
|
||||
}
|
||||
|
||||
void
|
||||
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;
|
||||
a->neg = 0;
|
||||
}
|
||||
|
||||
void
|
||||
BN_clear_free(BIGNUM *a)
|
||||
{
|
||||
int i;
|
||||
|
||||
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);
|
||||
explicit_bzero(a, sizeof(BIGNUM));
|
||||
if (i)
|
||||
free(a);
|
||||
}
|
||||
|
||||
void
|
||||
BN_free(BIGNUM *a)
|
||||
{
|
||||
BN_clear_free(a);
|
||||
}
|
||||
|
||||
void
|
||||
BN_set_params(int mult, int high, int low, int mont)
|
||||
{
|
||||
@@ -137,6 +194,30 @@ BN_get_params(int which)
|
||||
}
|
||||
#endif
|
||||
|
||||
void
|
||||
BN_set_flags(BIGNUM *b, int n)
|
||||
{
|
||||
b->flags |= n;
|
||||
}
|
||||
|
||||
int
|
||||
BN_get_flags(const BIGNUM *b, int n)
|
||||
{
|
||||
return b->flags & n;
|
||||
}
|
||||
|
||||
void
|
||||
BN_with_flags(BIGNUM *dest, const BIGNUM *b, int flags)
|
||||
{
|
||||
int dest_flags;
|
||||
|
||||
dest_flags = (dest->flags & BN_FLG_MALLOCED) |
|
||||
(b->flags & ~BN_FLG_MALLOCED) | BN_FLG_STATIC_DATA | flags;
|
||||
|
||||
*dest = *b;
|
||||
dest->flags = dest_flags;
|
||||
}
|
||||
|
||||
const BIGNUM *
|
||||
BN_value_one(void)
|
||||
{
|
||||
@@ -182,53 +263,6 @@ BN_num_bits(const BIGNUM *a)
|
||||
return ((i * BN_BITS2) + BN_num_bits_word(a->d[i]));
|
||||
}
|
||||
|
||||
void
|
||||
BN_clear_free(BIGNUM *a)
|
||||
{
|
||||
int i;
|
||||
|
||||
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);
|
||||
explicit_bzero(a, sizeof(BIGNUM));
|
||||
if (i)
|
||||
free(a);
|
||||
}
|
||||
|
||||
void
|
||||
BN_free(BIGNUM *a)
|
||||
{
|
||||
BN_clear_free(a);
|
||||
}
|
||||
|
||||
void
|
||||
BN_init(BIGNUM *a)
|
||||
{
|
||||
memset(a, 0, sizeof(BIGNUM));
|
||||
bn_check_top(a);
|
||||
}
|
||||
|
||||
BIGNUM *
|
||||
BN_new(void)
|
||||
{
|
||||
BIGNUM *ret;
|
||||
|
||||
if ((ret = malloc(sizeof(BIGNUM))) == NULL) {
|
||||
BNerror(ERR_R_MALLOC_FAILURE);
|
||||
return (NULL);
|
||||
}
|
||||
ret->flags = BN_FLG_MALLOCED;
|
||||
ret->top = 0;
|
||||
ret->neg = 0;
|
||||
ret->dmax = 0;
|
||||
ret->d = NULL;
|
||||
bn_check_top(ret);
|
||||
return (ret);
|
||||
}
|
||||
|
||||
/* This is used both by bn_expand2() and bn_dup_expand() */
|
||||
/* The caller MUST check that words > b->dmax before calling this */
|
||||
static BN_ULONG *
|
||||
@@ -494,16 +528,6 @@ BN_swap(BIGNUM *a, BIGNUM *b)
|
||||
bn_check_top(b);
|
||||
}
|
||||
|
||||
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;
|
||||
a->neg = 0;
|
||||
}
|
||||
|
||||
BN_ULONG
|
||||
BN_get_word(const BIGNUM *a)
|
||||
{
|
||||
@@ -583,20 +607,143 @@ BN_bin2bn(const unsigned char *s, int len, BIGNUM *ret)
|
||||
return (ret);
|
||||
}
|
||||
|
||||
typedef enum {
|
||||
big,
|
||||
little,
|
||||
} endianness_t;
|
||||
|
||||
/* ignore negative */
|
||||
static int
|
||||
bn2binpad(const BIGNUM *a, unsigned char *to, int tolen, endianness_t endianness)
|
||||
{
|
||||
int n;
|
||||
size_t i, lasti, j, atop, mask;
|
||||
BN_ULONG l;
|
||||
|
||||
/*
|
||||
* In case |a| is fixed-top, BN_num_bytes can return bogus length,
|
||||
* but it's assumed that fixed-top inputs ought to be "nominated"
|
||||
* even for padded output, so it works out...
|
||||
*/
|
||||
n = BN_num_bytes(a);
|
||||
if (tolen == -1)
|
||||
tolen = n;
|
||||
else if (tolen < n) { /* uncommon/unlike case */
|
||||
BIGNUM temp = *a;
|
||||
|
||||
bn_correct_top(&temp);
|
||||
|
||||
n = BN_num_bytes(&temp);
|
||||
if (tolen < n)
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Swipe through whole available data and don't give away padded zero. */
|
||||
atop = a->dmax * BN_BYTES;
|
||||
if (atop == 0) {
|
||||
explicit_bzero(to, tolen);
|
||||
return tolen;
|
||||
}
|
||||
|
||||
lasti = atop - 1;
|
||||
atop = a->top * BN_BYTES;
|
||||
|
||||
if (endianness == big)
|
||||
to += tolen; /* start from the end of the buffer */
|
||||
|
||||
for (i = 0, j = 0; j < (size_t)tolen; j++) {
|
||||
unsigned char val;
|
||||
|
||||
l = a->d[i / BN_BYTES];
|
||||
mask = 0 - ((j - atop) >> (8 * sizeof(i) - 1));
|
||||
val = (unsigned char)(l >> (8 * (i % BN_BYTES)) & mask);
|
||||
|
||||
if (endianness == big)
|
||||
*--to = val;
|
||||
else
|
||||
*to++ = val;
|
||||
|
||||
i += (i - lasti) >> (8 * sizeof(i) - 1); /* stay on last limb */
|
||||
}
|
||||
|
||||
return tolen;
|
||||
}
|
||||
|
||||
int
|
||||
BN_bn2binpad(const BIGNUM *a, unsigned char *to, int tolen)
|
||||
{
|
||||
if (tolen < 0)
|
||||
return -1;
|
||||
return bn2binpad(a, to, tolen, big);
|
||||
}
|
||||
|
||||
int
|
||||
BN_bn2bin(const BIGNUM *a, unsigned char *to)
|
||||
{
|
||||
int n, i;
|
||||
BN_ULONG l;
|
||||
return bn2binpad(a, to, -1, big);
|
||||
}
|
||||
|
||||
bn_check_top(a);
|
||||
n = i=BN_num_bytes(a);
|
||||
while (i--) {
|
||||
l = a->d[i / BN_BYTES];
|
||||
*(to++) = (unsigned char)(l >> (8 * (i % BN_BYTES))) & 0xff;
|
||||
BIGNUM *
|
||||
BN_lebin2bn(const unsigned char *s, int len, BIGNUM *ret)
|
||||
{
|
||||
unsigned int i, m, n;
|
||||
BN_ULONG l;
|
||||
BIGNUM *bn = NULL;
|
||||
|
||||
if (ret == NULL)
|
||||
ret = bn = BN_new();
|
||||
if (ret == NULL)
|
||||
return NULL;
|
||||
|
||||
bn_check_top(ret);
|
||||
|
||||
s += len;
|
||||
/* Skip trailing zeroes. */
|
||||
for (; len > 0 && s[-1] == 0; s--, len--)
|
||||
continue;
|
||||
|
||||
n = len;
|
||||
if (n == 0) {
|
||||
ret->top = 0;
|
||||
return ret;
|
||||
}
|
||||
return (n);
|
||||
|
||||
i = ((n - 1) / BN_BYTES) + 1;
|
||||
m = (n - 1) % BN_BYTES;
|
||||
if (bn_wexpand(ret, (int)i) == NULL) {
|
||||
BN_free(bn);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ret->top = i;
|
||||
ret->neg = 0;
|
||||
l = 0;
|
||||
while (n-- > 0) {
|
||||
s--;
|
||||
l = (l << 8L) | *s;
|
||||
if (m-- == 0) {
|
||||
ret->d[--i] = l;
|
||||
l = 0;
|
||||
m = BN_BYTES - 1;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* need to call this due to clear byte at top if avoiding having the
|
||||
* top bit set (-ve number)
|
||||
*/
|
||||
bn_correct_top(ret);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int
|
||||
BN_bn2lebinpad(const BIGNUM *a, unsigned char *to, int tolen)
|
||||
{
|
||||
if (tolen < 0)
|
||||
return -1;
|
||||
|
||||
return bn2binpad(a, to, tolen, little);
|
||||
}
|
||||
|
||||
int
|
||||
@@ -914,6 +1061,50 @@ BN_swap_ct(BN_ULONG condition, BIGNUM *a, BIGNUM *b, size_t nwords)
|
||||
return 1;
|
||||
}
|
||||
|
||||
void
|
||||
BN_zero_ex(BIGNUM *a)
|
||||
{
|
||||
a->neg = 0;
|
||||
a->top = 0;
|
||||
/* XXX: a->flags &= ~BN_FIXED_TOP */
|
||||
}
|
||||
|
||||
int
|
||||
BN_abs_is_word(const BIGNUM *a, const BN_ULONG w)
|
||||
{
|
||||
return (a->top == 1 && a->d[0] == w) || (w == 0 && a->top == 0);
|
||||
}
|
||||
|
||||
int
|
||||
BN_is_zero(const BIGNUM *a)
|
||||
{
|
||||
return a->top == 0;
|
||||
}
|
||||
|
||||
int
|
||||
BN_is_one(const BIGNUM *a)
|
||||
{
|
||||
return BN_abs_is_word(a, 1) && !a->neg;
|
||||
}
|
||||
|
||||
int
|
||||
BN_is_word(const BIGNUM *a, const BN_ULONG w)
|
||||
{
|
||||
return BN_abs_is_word(a, w) && (w == 0 || !a->neg);
|
||||
}
|
||||
|
||||
int
|
||||
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)
|
||||
{
|
||||
@@ -933,6 +1124,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)
|
||||
{
|
||||
|
11
externals/libressl/crypto/bn/bn_mont.c
vendored
11
externals/libressl/crypto/bn/bn_mont.c
vendored
@@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: bn_mont.c,v 1.26 2017/01/21 11:00:46 beck Exp $ */
|
||||
/* $OpenBSD: bn_mont.c,v 1.28 2022/02/07 19:44:23 tb Exp $ */
|
||||
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
|
||||
* All rights reserved.
|
||||
*
|
||||
@@ -175,6 +175,12 @@ err:
|
||||
return (ret);
|
||||
}
|
||||
|
||||
int
|
||||
BN_to_montgomery(BIGNUM *r, const BIGNUM *a, BN_MONT_CTX *mont, BN_CTX *ctx)
|
||||
{
|
||||
return BN_mod_mul_montgomery(r, a, &mont->RR, mont, ctx);
|
||||
}
|
||||
|
||||
#ifdef MONT_WORD
|
||||
static int
|
||||
BN_from_montgomery_word(BIGNUM *ret, BIGNUM *r, BN_MONT_CTX *mont)
|
||||
@@ -363,6 +369,9 @@ BN_MONT_CTX_set(BN_MONT_CTX *mont, const BIGNUM *mod, BN_CTX *ctx)
|
||||
int ret = 0;
|
||||
BIGNUM *Ri, *R;
|
||||
|
||||
if (BN_is_zero(mod))
|
||||
return 0;
|
||||
|
||||
BN_CTX_start(ctx);
|
||||
if ((Ri = BN_CTX_get(ctx)) == NULL)
|
||||
goto err;
|
||||
|
5
externals/libressl/crypto/bn/bn_nist.c
vendored
5
externals/libressl/crypto/bn/bn_nist.c
vendored
@@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: bn_nist.c,v 1.18 2016/07/18 01:04:52 bcook Exp $ */
|
||||
/* $OpenBSD: bn_nist.c,v 1.19 2021/11/09 18:40:20 bcook Exp $ */
|
||||
/*
|
||||
* Written by Nils Larsch for the OpenSSL project
|
||||
*/
|
||||
@@ -56,8 +56,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include <machine/endian.h>
|
||||
|
||||
#include <endian.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
|
12
externals/libressl/crypto/bn/bn_print.c
vendored
12
externals/libressl/crypto/bn/bn_print.c
vendored
@@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: bn_print.c,v 1.31 2017/01/29 17:49:22 beck Exp $ */
|
||||
/* $OpenBSD: bn_print.c,v 1.33 2022/01/20 10:53:33 inoguchi Exp $ */
|
||||
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
|
||||
* All rights reserved.
|
||||
*
|
||||
@@ -216,7 +216,7 @@ BN_hex2bn(BIGNUM **bn, const char *a)
|
||||
if ((ret = BN_new()) == NULL)
|
||||
return (0);
|
||||
} else {
|
||||
ret= *bn;
|
||||
ret = *bn;
|
||||
BN_zero(ret);
|
||||
}
|
||||
|
||||
@@ -228,7 +228,7 @@ BN_hex2bn(BIGNUM **bn, const char *a)
|
||||
m = 0;
|
||||
h = 0;
|
||||
while (j > 0) {
|
||||
m = ((BN_BYTES*2) <= j) ? (BN_BYTES * 2) : j;
|
||||
m = ((BN_BYTES * 2) <= j) ? (BN_BYTES * 2) : j;
|
||||
l = 0;
|
||||
for (;;) {
|
||||
c = a[j - m];
|
||||
@@ -310,8 +310,10 @@ BN_dec2bn(BIGNUM **bn, const char *a)
|
||||
l += *a - '0';
|
||||
a++;
|
||||
if (++j == BN_DEC_NUM) {
|
||||
BN_mul_word(ret, BN_DEC_CONV);
|
||||
BN_add_word(ret, l);
|
||||
if (!BN_mul_word(ret, BN_DEC_CONV))
|
||||
goto err;
|
||||
if (!BN_add_word(ret, l))
|
||||
goto err;
|
||||
l = 0;
|
||||
j = 0;
|
||||
}
|
||||
|
8
externals/libressl/crypto/bn/bn_rand.c
vendored
8
externals/libressl/crypto/bn/bn_rand.c
vendored
@@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: bn_rand.c,v 1.24 2020/09/12 17:16:36 tb Exp $ */
|
||||
/* $OpenBSD: bn_rand.c,v 1.25 2021/08/31 11:19:19 tb Exp $ */
|
||||
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
|
||||
* All rights reserved.
|
||||
*
|
||||
@@ -194,20 +194,20 @@ err:
|
||||
return (ret);
|
||||
}
|
||||
|
||||
int
|
||||
int
|
||||
BN_rand(BIGNUM *rnd, int bits, int top, int bottom)
|
||||
{
|
||||
return bnrand(0, rnd, bits, top, bottom);
|
||||
}
|
||||
|
||||
int
|
||||
int
|
||||
BN_pseudo_rand(BIGNUM *rnd, int bits, int top, int bottom)
|
||||
{
|
||||
return bnrand(1, rnd, bits, top, bottom);
|
||||
}
|
||||
|
||||
#if 1
|
||||
int
|
||||
int
|
||||
BN_bntest_rand(BIGNUM *rnd, int bits, int top, int bottom)
|
||||
{
|
||||
return bnrand(2, rnd, bits, top, bottom);
|
||||
|
29
externals/libressl/crypto/bn/bn_sqrt.c
vendored
29
externals/libressl/crypto/bn/bn_sqrt.c
vendored
@@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: bn_sqrt.c,v 1.9 2017/01/29 17:49:22 beck Exp $ */
|
||||
/* $OpenBSD: bn_sqrt.c,v 1.10 2022/03/15 15:52:39 tb Exp $ */
|
||||
/* Written by Lenka Fibikova <fibikova@exp-math.uni-essen.de>
|
||||
* and Bodo Moeller for the OpenSSL project. */
|
||||
/* ====================================================================
|
||||
@@ -351,21 +351,22 @@ BN_mod_sqrt(BIGNUM *in, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)
|
||||
goto vrfy;
|
||||
}
|
||||
|
||||
|
||||
/* find smallest i such that b^(2^i) = 1 */
|
||||
i = 1;
|
||||
if (!BN_mod_sqr(t, b, p, ctx))
|
||||
goto end;
|
||||
while (!BN_is_one(t)) {
|
||||
i++;
|
||||
if (i == e) {
|
||||
BNerror(BN_R_NOT_A_SQUARE);
|
||||
goto end;
|
||||
/* Find the smallest i with 0 < i < e such that b^(2^i) = 1. */
|
||||
for (i = 1; i < e; i++) {
|
||||
if (i == 1) {
|
||||
if (!BN_mod_sqr(t, b, p, ctx))
|
||||
goto end;
|
||||
} else {
|
||||
if (!BN_mod_sqr(t, t, p, ctx))
|
||||
goto end;
|
||||
}
|
||||
if (!BN_mod_mul(t, t, t, p, ctx))
|
||||
goto end;
|
||||
if (BN_is_one(t))
|
||||
break;
|
||||
}
|
||||
if (i >= e) {
|
||||
BNerror(BN_R_NOT_A_SQUARE);
|
||||
goto end;
|
||||
}
|
||||
|
||||
|
||||
/* t := y^2^(e - i - 1) */
|
||||
if (!BN_copy(t, y))
|
||||
|
11
externals/libressl/crypto/bn/bn_x931p.c
vendored
11
externals/libressl/crypto/bn/bn_x931p.c
vendored
@@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: bn_x931p.c,v 1.11 2019/01/20 01:56:59 tb Exp $ */
|
||||
/* $OpenBSD: bn_x931p.c,v 1.13 2022/01/20 10:56:22 inoguchi Exp $ */
|
||||
/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
|
||||
* project 2005.
|
||||
*/
|
||||
@@ -139,13 +139,13 @@ BN_X931_derive_prime_ex(BIGNUM *p, BIGNUM *p1, BIGNUM *p2, const BIGNUM *Xp,
|
||||
|
||||
/* First set p to value of Rp */
|
||||
|
||||
if (!BN_mod_inverse_ct(p, p2, p1, ctx))
|
||||
if (BN_mod_inverse_ct(p, p2, p1, ctx) == NULL)
|
||||
goto err;
|
||||
|
||||
if (!BN_mul(p, p, p2, ctx))
|
||||
goto err;
|
||||
|
||||
if (!BN_mod_inverse_ct(t, p1, p2, ctx))
|
||||
if (BN_mod_inverse_ct(t, p1, p2, ctx) == NULL)
|
||||
goto err;
|
||||
|
||||
if (!BN_mul(t, t, p1, ctx))
|
||||
@@ -154,7 +154,7 @@ BN_X931_derive_prime_ex(BIGNUM *p, BIGNUM *p1, BIGNUM *p2, const BIGNUM *Xp,
|
||||
if (!BN_sub(p, p, t))
|
||||
goto err;
|
||||
|
||||
if (p->neg && !BN_add(p, p, p1p2))
|
||||
if (BN_is_negative(p) && !BN_add(p, p, p1p2))
|
||||
goto err;
|
||||
|
||||
/* p now equals Rp */
|
||||
@@ -237,7 +237,8 @@ BN_X931_generate_Xpq(BIGNUM *Xp, BIGNUM *Xq, int nbits, BN_CTX *ctx)
|
||||
if (!BN_rand(Xq, nbits, 1, 0))
|
||||
goto err;
|
||||
/* Check that |Xp - Xq| > 2^(nbits - 100) */
|
||||
BN_sub(t, Xp, Xq);
|
||||
if (!BN_sub(t, Xp, Xq))
|
||||
goto err;
|
||||
if (BN_num_bits(t) > (nbits - 100))
|
||||
break;
|
||||
}
|
||||
|
@@ -1,7 +1,7 @@
|
||||
; 1 "crypto/bn/gf2m-masm-x86_64.S.tmp"
|
||||
; 1 "<built-in>" 1
|
||||
; 1 "<built-in>" 3
|
||||
; 340 "<built-in>" 3
|
||||
; 343 "<built-in>" 3
|
||||
; 1 "<command line>" 1
|
||||
; 1 "<built-in>" 2
|
||||
; 1 "crypto/bn/gf2m-masm-x86_64.S.tmp" 2
|
||||
|
@@ -1,7 +1,7 @@
|
||||
; 1 "crypto/bn/modexp512-masm-x86_64.S.tmp"
|
||||
; 1 "<built-in>" 1
|
||||
; 1 "<built-in>" 3
|
||||
; 340 "<built-in>" 3
|
||||
; 343 "<built-in>" 3
|
||||
; 1 "<command line>" 1
|
||||
; 1 "<built-in>" 2
|
||||
; 1 "crypto/bn/modexp512-masm-x86_64.S.tmp" 2
|
||||
|
@@ -1,7 +1,7 @@
|
||||
; 1 "crypto/bn/mont-masm-x86_64.S.tmp"
|
||||
; 1 "<built-in>" 1
|
||||
; 1 "<built-in>" 3
|
||||
; 340 "<built-in>" 3
|
||||
; 343 "<built-in>" 3
|
||||
; 1 "<command line>" 1
|
||||
; 1 "<built-in>" 2
|
||||
; 1 "crypto/bn/mont-masm-x86_64.S.tmp" 2
|
||||
|
@@ -1,7 +1,7 @@
|
||||
; 1 "crypto/bn/mont5-masm-x86_64.S.tmp"
|
||||
; 1 "<built-in>" 1
|
||||
; 1 "<built-in>" 3
|
||||
; 340 "<built-in>" 3
|
||||
; 343 "<built-in>" 3
|
||||
; 1 "<command line>" 1
|
||||
; 1 "<built-in>" 2
|
||||
; 1 "crypto/bn/mont5-masm-x86_64.S.tmp" 2
|
||||
|
Reference in New Issue
Block a user