sync with OpenBSD -current

This commit is contained in:
purplerain 2024-06-23 03:24:22 +00:00
parent 747d3a4033
commit 7bc640af07
Signed by: purplerain
GPG key ID: F42C07F07E2E35B7
19 changed files with 98 additions and 146 deletions

View file

@ -1,4 +1,4 @@
/* $OpenBSD: bn_convert.c,v 1.21 2024/04/17 21:55:43 tb Exp $ */
/* $OpenBSD: bn_convert.c,v 1.22 2024/06/22 16:33:00 jsing Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@ -690,32 +690,43 @@ BN_hex2bn(BIGNUM **bnp, const char *s)
LCRYPTO_ALIAS(BN_hex2bn);
int
BN_bn2mpi(const BIGNUM *a, unsigned char *d)
BN_bn2mpi(const BIGNUM *bn, unsigned char *d)
{
int bits;
int num = 0;
int ext = 0;
long l;
uint8_t *out_bin;
size_t out_len, out_bin_len;
int bits, bytes;
int extend;
CBB cbb, cbb_bin;
bits = BN_num_bits(bn);
bytes = (bits + 7) / 8;
extend = (bits != 0) && (bits % 8 == 0);
out_bin_len = extend + bytes;
out_len = 4 + out_bin_len;
bits = BN_num_bits(a);
num = (bits + 7) / 8;
if (bits > 0) {
ext = ((bits & 0x07) == 0);
}
if (d == NULL)
return (num + 4 + ext);
return out_len;
l = num + ext;
d[0] = (unsigned char)(l >> 24) & 0xff;
d[1] = (unsigned char)(l >> 16) & 0xff;
d[2] = (unsigned char)(l >> 8) & 0xff;
d[3] = (unsigned char)(l) & 0xff;
if (ext)
d[4] = 0;
num = BN_bn2bin(a, &(d[4 + ext]));
if (a->neg)
if (!CBB_init_fixed(&cbb, d, out_len))
goto err;
if (!CBB_add_u32_length_prefixed(&cbb, &cbb_bin))
goto err;
if (!CBB_add_space(&cbb_bin, &out_bin, out_bin_len))
goto err;
if (BN_bn2binpad(bn, out_bin, out_bin_len) != out_bin_len)
goto err;
if (!CBB_finish(&cbb, NULL, NULL))
goto err;
if (bn->neg)
d[4] |= 0x80;
return (num + 4 + ext);
return out_len;
err:
CBB_cleanup(&cbb);
return -1;
}
LCRYPTO_ALIAS(BN_bn2mpi);

View file

@ -1,4 +1,4 @@
/* $OpenBSD: bs_cbb.c,v 1.5 2024/05/25 15:12:47 tb Exp $ */
/* $OpenBSD: bs_cbb.c,v 1.6 2024/06/22 15:32:51 jsing Exp $ */
/*
* Copyright (c) 2014, Google Inc.
*
@ -328,6 +328,12 @@ CBB_add_u24_length_prefixed(CBB *cbb, CBB *out_contents)
return cbb_add_length_prefixed(cbb, out_contents, 3);
}
int
CBB_add_u32_length_prefixed(CBB *cbb, CBB *out_contents)
{
return cbb_add_length_prefixed(cbb, out_contents, 4);
}
int
CBB_add_asn1(CBB *cbb, CBB *out_contents, unsigned int tag)
{

View file

@ -1,4 +1,4 @@
/* $OpenBSD: bytestring.h,v 1.4 2022/11/09 19:05:42 jsing Exp $ */
/* $OpenBSD: bytestring.h,v 1.5 2024/06/22 15:32:51 jsing Exp $ */
/*
* Copyright (c) 2014, Google Inc.
*
@ -459,6 +459,13 @@ int CBB_add_u16_length_prefixed(CBB *cbb, CBB *out_contents);
*/
int CBB_add_u24_length_prefixed(CBB *cbb, CBB *out_contents);
/*
* CBB_add_u32_length_prefixed sets |*out_contents| to a new child of |cbb|.
* The data written to |*out_contents| will be prefixed in |cbb| with a 32-bit,
* big-endian length. It returns one on success or zero on error.
*/
int CBB_add_u32_length_prefixed(CBB *cbb, CBB *out_contents);
/*
* CBB_add_asn sets |*out_contents| to a |CBB| into which the contents of an
* ASN.1 object can be written. The |tag| argument will be used as the tag for

View file

@ -1,4 +1,4 @@
/* $OpenBSD: lhash.c,v 1.25 2024/05/07 13:40:42 jsing Exp $ */
/* $OpenBSD: lhash.c,v 1.26 2024/06/22 16:38:31 jsing Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@ -56,44 +56,6 @@
* [including the GNU Public Licence.]
*/
/* Code for dynamic hash table routines
* Author - Eric Young v 2.0
*
* 2.2 eay - added #include "crypto.h" so the memory leak checking code is
* present. eay 18-Jun-98
*
* 2.1 eay - Added an 'error in last operation' flag. eay 6-May-98
*
* 2.0 eay - Fixed a bug that occurred when using lh_delete
* from inside lh_doall(). As entries were deleted,
* the 'table' was 'contract()ed', making some entries
* jump from the end of the table to the start, there by
* skipping the lh_doall() processing. eay - 4/12/95
*
* 1.9 eay - Fixed a memory leak in lh_free, the LHASH_NODEs
* were not being free()ed. 21/11/95
*
* 1.8 eay - Put the stats routines into a separate file, lh_stats.c
* 19/09/95
*
* 1.7 eay - Removed the fputs() for realloc failures - the code
* should silently tolerate them. I have also fixed things
* lint complained about 04/05/95
*
* 1.6 eay - Fixed an invalid pointers in contract/expand 27/07/92
*
* 1.5 eay - Fixed a misuse of realloc in expand 02/03/1992
*
* 1.4 eay - Fixed lh_doall so the function can call lh_delete 28/05/91
*
* 1.3 eay - Fixed a few lint problems 19/3/1991
*
* 1.2 eay - Fixed lh_doall problem 13/3/1991
*
* 1.1 eay - Added lh_doall
*
* 1.0 eay - First version
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>