sync with OpenBSD -current
This commit is contained in:
parent
382ecd9441
commit
1b576c8ddf
25 changed files with 517 additions and 395 deletions
|
@ -2693,8 +2693,8 @@ X509_STORE_add_crl
|
|||
X509_STORE_add_lookup
|
||||
X509_STORE_free
|
||||
X509_STORE_get0_objects
|
||||
X509_STORE_get1_objects
|
||||
X509_STORE_get0_param
|
||||
X509_STORE_get1_objects
|
||||
X509_STORE_get_check_issued
|
||||
X509_STORE_get_ex_data
|
||||
X509_STORE_get_verify
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $OpenBSD: bn_convert.c,v 1.15 2023/07/09 18:37:58 tb Exp $ */
|
||||
/* $OpenBSD: bn_convert.c,v 1.18 2024/04/16 13:14:46 jsing Exp $ */
|
||||
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
|
||||
* All rights reserved.
|
||||
*
|
||||
|
@ -153,46 +153,69 @@ BN_bn2binpad(const BIGNUM *a, unsigned char *to, int tolen)
|
|||
}
|
||||
LCRYPTO_ALIAS(BN_bn2binpad);
|
||||
|
||||
BIGNUM *
|
||||
BN_bin2bn(const unsigned char *s, int len, BIGNUM *ret)
|
||||
static int
|
||||
bn_bin2bn_cbs(BIGNUM **bnp, CBS *cbs)
|
||||
{
|
||||
unsigned int i, m;
|
||||
unsigned int n;
|
||||
BN_ULONG l;
|
||||
BIGNUM *bn = NULL;
|
||||
BN_ULONG w;
|
||||
uint8_t v;
|
||||
int b, i;
|
||||
|
||||
if (len < 0)
|
||||
return (NULL);
|
||||
if (ret == NULL)
|
||||
ret = bn = BN_new();
|
||||
if (ret == NULL)
|
||||
return (NULL);
|
||||
l = 0;
|
||||
n = len;
|
||||
if (n == 0) {
|
||||
ret->top = 0;
|
||||
return (ret);
|
||||
}
|
||||
i = ((n - 1) / BN_BYTES) + 1;
|
||||
m = ((n - 1) % (BN_BYTES));
|
||||
if (!bn_wexpand(ret, (int)i)) {
|
||||
BN_free(bn);
|
||||
return NULL;
|
||||
}
|
||||
ret->top = i;
|
||||
ret->neg = 0;
|
||||
while (n--) {
|
||||
l = (l << 8L) | *(s++);
|
||||
if (m-- == 0) {
|
||||
ret->d[--i] = l;
|
||||
l = 0;
|
||||
m = BN_BYTES - 1;
|
||||
if ((bn = *bnp) == NULL)
|
||||
bn = BN_new();
|
||||
if (bn == NULL)
|
||||
goto err;
|
||||
if (!bn_expand_bytes(bn, CBS_len(cbs)))
|
||||
goto err;
|
||||
|
||||
b = 0;
|
||||
i = 0;
|
||||
w = 0;
|
||||
|
||||
while (CBS_len(cbs) > 0) {
|
||||
if (!CBS_get_last_u8(cbs, &v))
|
||||
goto err;
|
||||
|
||||
w |= (BN_ULONG)v << b;
|
||||
b += 8;
|
||||
|
||||
if (b == BN_BITS2 || CBS_len(cbs) == 0) {
|
||||
b = 0;
|
||||
bn->d[i++] = w;
|
||||
w = 0;
|
||||
}
|
||||
}
|
||||
/* 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);
|
||||
|
||||
bn->neg = 0;
|
||||
bn->top = i;
|
||||
|
||||
bn_correct_top(bn);
|
||||
|
||||
*bnp = bn;
|
||||
|
||||
return 1;
|
||||
|
||||
err:
|
||||
if (*bnp == NULL)
|
||||
BN_free(bn);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
BIGNUM *
|
||||
BN_bin2bn(const unsigned char *d, int len, BIGNUM *bn)
|
||||
{
|
||||
CBS cbs;
|
||||
|
||||
if (len < 0)
|
||||
return NULL;
|
||||
|
||||
CBS_init(&cbs, d, len);
|
||||
|
||||
if (!bn_bin2bn_cbs(&bn, &cbs))
|
||||
return NULL;
|
||||
|
||||
return bn;
|
||||
}
|
||||
LCRYPTO_ALIAS(BN_bin2bn);
|
||||
|
||||
|
@ -431,7 +454,7 @@ bn_dec2bn_cbs(BIGNUM **bnp, CBS *cbs)
|
|||
bn = BN_new();
|
||||
if (bn == NULL)
|
||||
goto err;
|
||||
if (!bn_expand(bn, digits * 4))
|
||||
if (!bn_expand_bits(bn, digits * 4))
|
||||
goto err;
|
||||
|
||||
if ((d = digits % BN_DEC_NUM) == 0)
|
||||
|
@ -628,13 +651,13 @@ bn_hex2bn_cbs(BIGNUM **bnp, CBS *cbs)
|
|||
bn = BN_new();
|
||||
if (bn == NULL)
|
||||
goto err;
|
||||
if (!bn_expand(bn, digits * 4))
|
||||
if (!bn_expand_bits(bn, digits * 4))
|
||||
goto err;
|
||||
|
||||
if (!CBS_get_bytes(cbs, cbs, digits))
|
||||
goto err;
|
||||
|
||||
b = BN_BITS2;
|
||||
b = 0;
|
||||
i = 0;
|
||||
w = 0;
|
||||
|
||||
|
@ -652,11 +675,11 @@ bn_hex2bn_cbs(BIGNUM **bnp, CBS *cbs)
|
|||
else
|
||||
goto err;
|
||||
|
||||
w |= (BN_ULONG)v << (BN_BITS2 - b);
|
||||
b -= 4;
|
||||
w |= (BN_ULONG)v << b;
|
||||
b += 4;
|
||||
|
||||
if (b == 0 || digits == 0) {
|
||||
b = BN_BITS2;
|
||||
if (b == BN_BITS2 || digits == 0) {
|
||||
b = 0;
|
||||
bn->d[i++] = w;
|
||||
w = 0;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $OpenBSD: bn_lib.c,v 1.91 2024/04/15 14:35:25 jsing Exp $ */
|
||||
/* $OpenBSD: bn_lib.c,v 1.93 2024/04/16 13:07:14 jsing Exp $ */
|
||||
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
|
||||
* All rights reserved.
|
||||
*
|
||||
|
@ -219,13 +219,10 @@ bn_expand_internal(BIGNUM *bn, int words)
|
|||
}
|
||||
|
||||
int
|
||||
bn_expand(BIGNUM *bn, int bits)
|
||||
bn_expand_bits(BIGNUM *bn, size_t bits)
|
||||
{
|
||||
int words;
|
||||
|
||||
if (bits < 0)
|
||||
return 0;
|
||||
|
||||
if (bits > (INT_MAX - BN_BITS2 + 1))
|
||||
return 0;
|
||||
|
||||
|
@ -234,6 +231,19 @@ bn_expand(BIGNUM *bn, int bits)
|
|||
return bn_wexpand(bn, words);
|
||||
}
|
||||
|
||||
int
|
||||
bn_expand_bytes(BIGNUM *bn, size_t bytes)
|
||||
{
|
||||
int words;
|
||||
|
||||
if (bytes > (INT_MAX - BN_BYTES + 1))
|
||||
return 0;
|
||||
|
||||
words = (bytes + BN_BYTES - 1) / BN_BYTES;
|
||||
|
||||
return bn_wexpand(bn, words);
|
||||
}
|
||||
|
||||
int
|
||||
bn_wexpand(BIGNUM *bn, int words)
|
||||
{
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $OpenBSD: bn_local.h,v 1.41 2024/04/10 15:09:03 tb Exp $ */
|
||||
/* $OpenBSD: bn_local.h,v 1.43 2024/04/16 13:07:14 jsing Exp $ */
|
||||
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
|
||||
* All rights reserved.
|
||||
*
|
||||
|
@ -259,7 +259,8 @@ int bn_mul_mont(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp,
|
|||
const BN_ULONG *np, const BN_ULONG *n0, int num);
|
||||
|
||||
void bn_correct_top(BIGNUM *a);
|
||||
int bn_expand(BIGNUM *a, int bits);
|
||||
int bn_expand_bits(BIGNUM *a, size_t bits);
|
||||
int bn_expand_bytes(BIGNUM *a, size_t bytes);
|
||||
int bn_wexpand(BIGNUM *a, int words);
|
||||
|
||||
BN_ULONG bn_add_words(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue