summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/libcrypto/Makefile10
-rw-r--r--lib/libcrypto/asn1/a_bitstr.c53
-rw-r--r--lib/libcrypto/asn1/a_enum.c130
-rw-r--r--lib/libcrypto/asn1/a_int.c131
-rw-r--r--lib/libcrypto/asn1/a_string.c (renamed from lib/libcrypto/asn1/f_string.c)149
-rw-r--r--lib/libcrypto/asn1/asn1_lib.c148
-rw-r--r--lib/libcrypto/asn1/f_enum.c190
-rw-r--r--lib/libcrypto/asn1/f_int.c192
-rw-r--r--lib/libcrypto/asn1/t_bitst.c112
9 files changed, 465 insertions, 650 deletions
diff --git a/lib/libcrypto/Makefile b/lib/libcrypto/Makefile
index c7d84b437ba..64b5cebd054 100644
--- a/lib/libcrypto/Makefile
+++ b/lib/libcrypto/Makefile
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile,v 1.56 2021/12/14 17:35:21 jsing Exp $
+# $OpenBSD: Makefile,v 1.57 2021/12/15 18:00:31 jsing Exp $
LIB= crypto
LIBREBUILD=y
@@ -53,16 +53,16 @@ SRCS+= aes_ctr.c aes_ige.c aes_wrap.c
# asn1/
SRCS+= a_object.c a_bitstr.c a_time.c a_int.c a_octet.c a_pkey.c a_pubkey.c
-SRCS+= a_print.c a_type.c a_dup.c a_d2i_fp.c a_i2d_fp.c
+SRCS+= a_print.c a_type.c a_dup.c a_d2i_fp.c a_i2d_fp.c a_string.c
SRCS+= a_enum.c a_utf8.c a_sign.c a_digest.c a_verify.c a_mbstr.c a_strex.c
SRCS+= x_algor.c x_val.c x_pubkey.c x_sig.c x_req.c x_attrib.c x_bignum.c
SRCS+= x_long.c x_name.c x_x509.c x_x509a.c x_crl.c x_info.c x_spki.c nsseq.c
SRCS+= x_nx509.c
-SRCS+= t_req.c t_x509.c t_x509a.c t_crl.c t_pkey.c t_spki.c t_bitst.c
+SRCS+= t_req.c t_x509.c t_x509a.c t_crl.c t_pkey.c t_spki.c
SRCS+= tasn_new.c tasn_fre.c tasn_enc.c tasn_dec.c tasn_utl.c tasn_typ.c
SRCS+= tasn_prn.c ameth_lib.c
-SRCS+= f_int.c f_string.c n_pkey.c
-SRCS+= f_enum.c x_pkey.c x_exten.c bio_asn1.c bio_ndef.c asn_mime.c
+SRCS+= n_pkey.c
+SRCS+= x_pkey.c x_exten.c bio_asn1.c bio_ndef.c asn_mime.c
SRCS+= asn1_gen.c asn1_par.c asn1_lib.c asn1_err.c a_strnid.c
SRCS+= evp_asn1.c asn_pack.c p5_pbe.c p5_pbev2.c p8_pkey.c asn_moid.c
SRCS+= a_time_tm.c asn1_types.c
diff --git a/lib/libcrypto/asn1/a_bitstr.c b/lib/libcrypto/asn1/a_bitstr.c
index f217f13d27a..68cefee4a2d 100644
--- a/lib/libcrypto/asn1/a_bitstr.c
+++ b/lib/libcrypto/asn1/a_bitstr.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: a_bitstr.c,v 1.30 2020/09/03 17:19:27 tb Exp $ */
+/* $OpenBSD: a_bitstr.c,v 1.31 2021/12/15 18:00:31 jsing Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@@ -60,7 +60,9 @@
#include <string.h>
#include <openssl/asn1.h>
+#include <openssl/conf.h>
#include <openssl/err.h>
+#include <openssl/x509v3.h>
int
ASN1_BIT_STRING_set(ASN1_BIT_STRING *x, unsigned char *d, int len)
@@ -262,3 +264,52 @@ ASN1_BIT_STRING_check(const ASN1_BIT_STRING *a, const unsigned char *flags,
}
return ok;
}
+
+int
+ASN1_BIT_STRING_name_print(BIO *out, ASN1_BIT_STRING *bs,
+ BIT_STRING_BITNAME *tbl, int indent)
+{
+ BIT_STRING_BITNAME *bnam;
+ char first = 1;
+
+ BIO_printf(out, "%*s", indent, "");
+ for (bnam = tbl; bnam->lname; bnam++) {
+ if (ASN1_BIT_STRING_get_bit(bs, bnam->bitnum)) {
+ if (!first)
+ BIO_puts(out, ", ");
+ BIO_puts(out, bnam->lname);
+ first = 0;
+ }
+ }
+ BIO_puts(out, "\n");
+ return 1;
+}
+
+int
+ASN1_BIT_STRING_set_asc(ASN1_BIT_STRING *bs, const char *name, int value,
+ BIT_STRING_BITNAME *tbl)
+{
+ int bitnum;
+
+ bitnum = ASN1_BIT_STRING_num_asc(name, tbl);
+ if (bitnum < 0)
+ return 0;
+ if (bs) {
+ if (!ASN1_BIT_STRING_set_bit(bs, bitnum, value))
+ return 0;
+ }
+ return 1;
+}
+
+int
+ASN1_BIT_STRING_num_asc(const char *name, BIT_STRING_BITNAME *tbl)
+{
+ BIT_STRING_BITNAME *bnam;
+
+ for (bnam = tbl; bnam->lname; bnam++) {
+ if (!strcmp(bnam->sname, name) ||
+ !strcmp(bnam->lname, name))
+ return bnam->bitnum;
+ }
+ return -1;
+}
diff --git a/lib/libcrypto/asn1/a_enum.c b/lib/libcrypto/asn1/a_enum.c
index 0952e049db8..e0e64f0a811 100644
--- a/lib/libcrypto/asn1/a_enum.c
+++ b/lib/libcrypto/asn1/a_enum.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: a_enum.c,v 1.20 2019/04/28 05:05:56 tb Exp $ */
+/* $OpenBSD: a_enum.c,v 1.21 2021/12/15 18:00:31 jsing Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@@ -61,6 +61,7 @@
#include <openssl/asn1.h>
#include <openssl/bn.h>
+#include <openssl/buffer.h>
#include <openssl/err.h>
/*
@@ -192,3 +193,130 @@ ASN1_ENUMERATED_to_BN(const ASN1_ENUMERATED *ai, BIGNUM *bn)
BN_set_negative(ret, 1);
return (ret);
}
+
+/* Based on a_int.c: equivalent ENUMERATED functions */
+
+int
+i2a_ASN1_ENUMERATED(BIO *bp, const ASN1_ENUMERATED *a)
+{
+ int i, n = 0;
+ static const char h[] = "0123456789ABCDEF";
+ char buf[2];
+
+ if (a == NULL)
+ return (0);
+
+ if (a->length == 0) {
+ if (BIO_write(bp, "00", 2) != 2)
+ goto err;
+ n = 2;
+ } else {
+ for (i = 0; i < a->length; i++) {
+ if ((i != 0) && (i % 35 == 0)) {
+ if (BIO_write(bp, "\\\n", 2) != 2)
+ goto err;
+ n += 2;
+ }
+ buf[0] = h[((unsigned char)a->data[i] >> 4) & 0x0f];
+ buf[1] = h[((unsigned char)a->data[i]) & 0x0f];
+ if (BIO_write(bp, buf, 2) != 2)
+ goto err;
+ n += 2;
+ }
+ }
+ return (n);
+
+err:
+ return (-1);
+}
+
+int
+a2i_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *bs, char *buf, int size)
+{
+ int ret = 0;
+ int i, j,k, m,n, again, bufsize;
+ unsigned char *s = NULL, *sp;
+ unsigned char *bufp;
+ int first = 1;
+ size_t num = 0, slen = 0;
+
+ bs->type = V_ASN1_ENUMERATED;
+
+ bufsize = BIO_gets(bp, buf, size);
+ for (;;) {
+ if (bufsize < 1)
+ goto err_sl;
+ i = bufsize;
+ if (buf[i-1] == '\n')
+ buf[--i] = '\0';
+ if (i == 0)
+ goto err_sl;
+ if (buf[i-1] == '\r')
+ buf[--i] = '\0';
+ if (i == 0)
+ goto err_sl;
+ if (buf[i - 1] == '\\') {
+ i--;
+ again = 1;
+ } else
+ again = 0;
+ buf[i] = '\0';
+ if (i < 2)
+ goto err_sl;
+
+ bufp = (unsigned char *)buf;
+ if (first) {
+ first = 0;
+ if ((bufp[0] == '0') && (buf[1] == '0')) {
+ bufp += 2;
+ i -= 2;
+ }
+ }
+ k = 0;
+ if (i % 2 != 0) {
+ ASN1error(ASN1_R_ODD_NUMBER_OF_CHARS);
+ goto err;
+ }
+ i /= 2;
+ if (num + i > slen) {
+ sp = realloc(s, num + i);
+ if (sp == NULL) {
+ ASN1error(ERR_R_MALLOC_FAILURE);
+ goto err;
+ }
+ s = sp;
+ slen = num + i;
+ }
+ for (j = 0; j < i; j++, k += 2) {
+ for (n = 0; n < 2; n++) {
+ m = bufp[k + n];
+ if ((m >= '0') && (m <= '9'))
+ m -= '0';
+ else if ((m >= 'a') && (m <= 'f'))
+ m = m - 'a' + 10;
+ else if ((m >= 'A') && (m <= 'F'))
+ m = m - 'A' + 10;
+ else {
+ ASN1error(ASN1_R_NON_HEX_CHARACTERS);
+ goto err;
+ }
+ s[num + j] <<= 4;
+ s[num + j] |= m;
+ }
+ }
+ num += i;
+ if (again)
+ bufsize = BIO_gets(bp, buf, size);
+ else
+ break;
+ }
+ bs->length = num;
+ bs->data = s;
+ return (1);
+
+err_sl:
+ ASN1error(ASN1_R_SHORT_LINE);
+err:
+ free(s);
+ return (ret);
+}
diff --git a/lib/libcrypto/asn1/a_int.c b/lib/libcrypto/asn1/a_int.c
index d14bd7959b5..314bd2b369e 100644
--- a/lib/libcrypto/asn1/a_int.c
+++ b/lib/libcrypto/asn1/a_int.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: a_int.c,v 1.34 2019/04/28 05:03:56 tb Exp $ */
+/* $OpenBSD: a_int.c,v 1.35 2021/12/15 18:00:31 jsing Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@@ -62,6 +62,7 @@
#include <openssl/asn1.h>
#include <openssl/bn.h>
+#include <openssl/buffer.h>
#include <openssl/err.h>
static int
@@ -101,6 +102,134 @@ ASN1_INTEGER_cmp(const ASN1_INTEGER *x, const ASN1_INTEGER *y)
return ret;
}
+int
+i2a_ASN1_INTEGER(BIO *bp, const ASN1_INTEGER *a)
+{
+ int i, n = 0;
+ static const char h[] = "0123456789ABCDEF";
+ char buf[2];
+
+ if (a == NULL)
+ return (0);
+
+ if (a->type & V_ASN1_NEG) {
+ if (BIO_write(bp, "-", 1) != 1)
+ goto err;
+ n = 1;
+ }
+
+ if (a->length == 0) {
+ if (BIO_write(bp, "00", 2) != 2)
+ goto err;
+ n += 2;
+ } else {
+ for (i = 0; i < a->length; i++) {
+ if ((i != 0) && (i % 35 == 0)) {
+ if (BIO_write(bp, "\\\n", 2) != 2)
+ goto err;
+ n += 2;
+ }
+ buf[0] = h[((unsigned char)a->data[i] >> 4) & 0x0f];
+ buf[1] = h[((unsigned char)a->data[i]) & 0x0f];
+ if (BIO_write(bp, buf, 2) != 2)
+ goto err;
+ n += 2;
+ }
+ }
+ return (n);
+
+err:
+ return (-1);
+}
+
+int
+a2i_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *bs, char *buf, int size)
+{
+ int ret = 0;
+ int i, j,k, m,n, again, bufsize;
+ unsigned char *s = NULL, *sp;
+ unsigned char *bufp;
+ int num = 0, slen = 0, first = 1;
+
+ bs->type = V_ASN1_INTEGER;
+
+ bufsize = BIO_gets(bp, buf, size);
+ for (;;) {
+ if (bufsize < 1)
+ goto err_sl;
+ i = bufsize;
+ if (buf[i - 1] == '\n')
+ buf[--i] = '\0';
+ if (i == 0)
+ goto err_sl;
+ if (buf[i - 1] == '\r')
+ buf[--i] = '\0';
+ if (i == 0)
+ goto err_sl;
+ if (buf[i - 1] == '\\') {
+ i--;
+ again = 1;
+ } else
+ again = 0;
+ buf[i] = '\0';
+ if (i < 2)
+ goto err_sl;
+
+ bufp = (unsigned char *)buf;
+ if (first) {
+ first = 0;
+ if ((bufp[0] == '0') && (buf[1] == '0')) {
+ bufp += 2;
+ i -= 2;
+ }
+ }
+ k = 0;
+ if (i % 2 != 0) {
+ ASN1error(ASN1_R_ODD_NUMBER_OF_CHARS);
+ goto err;
+ }
+ i /= 2;
+ if (num + i > slen) {
+ if ((sp = recallocarray(s, slen, num + i, 1)) == NULL) {
+ ASN1error(ERR_R_MALLOC_FAILURE);
+ goto err;
+ }
+ s = sp;
+ slen = num + i;
+ }
+ for (j = 0; j < i; j++, k += 2) {
+ for (n = 0; n < 2; n++) {
+ m = bufp[k + n];
+ if ((m >= '0') && (m <= '9'))
+ m -= '0';
+ else if ((m >= 'a') && (m <= 'f'))
+ m = m - 'a' + 10;
+ else if ((m >= 'A') && (m <= 'F'))
+ m = m - 'A' + 10;
+ else {
+ ASN1error(ASN1_R_NON_HEX_CHARACTERS);
+ goto err;
+ }
+ s[num + j] <<= 4;
+ s[num + j] |= m;
+ }
+ }
+ num += i;
+ if (again)
+ bufsize = BIO_gets(bp, buf, size);
+ else
+ break;
+ }
+ bs->length = num;
+ bs->data = s;
+ return (1);
+
+err_sl:
+ ASN1error(ASN1_R_SHORT_LINE);
+err:
+ free(s);
+ return (ret);
+}
/*
* This converts an ASN1 INTEGER into its content encoding.
diff --git a/lib/libcrypto/asn1/f_string.c b/lib/libcrypto/asn1/a_string.c
index b34343db390..b3a1323a54e 100644
--- a/lib/libcrypto/asn1/f_string.c
+++ b/lib/libcrypto/asn1/a_string.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: f_string.c,v 1.19 2021/11/19 09:58:41 schwarze Exp $ */
+/* $OpenBSD: a_string.c,v 1.1 2021/12/15 18:00:31 jsing Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@@ -57,12 +57,159 @@
*/
#include <stdio.h>
+#include <string.h>
#include <openssl/asn1.h>
#include <openssl/buffer.h>
#include <openssl/err.h>
int
+ASN1_STRING_copy(ASN1_STRING *dst, const ASN1_STRING *str)
+{
+ if (str == NULL)
+ return 0;
+ if (!ASN1_STRING_set(dst, str->data, str->length))
+ return 0;
+ dst->type = str->type;
+ dst->flags = str->flags;
+ return 1;
+}
+
+ASN1_STRING *
+ASN1_STRING_dup(const ASN1_STRING *str)
+{
+ ASN1_STRING *ret;
+
+ if (!str)
+ return NULL;
+ ret = ASN1_STRING_new();
+ if (!ret)
+ return NULL;
+ if (!ASN1_STRING_copy(ret, str)) {
+ ASN1_STRING_free(ret);
+ return NULL;
+ }
+ return ret;
+}
+
+int
+ASN1_STRING_set(ASN1_STRING *str, const void *_data, int len)
+{
+ const char *data = _data;
+
+ if (len < 0) {
+ if (data == NULL)
+ return (0);
+ else
+ len = strlen(data);
+ }
+ if ((str->length < len) || (str->data == NULL)) {
+ unsigned char *tmp;
+ tmp = realloc(str->data, len + 1);
+ if (tmp == NULL) {
+ ASN1error(ERR_R_MALLOC_FAILURE);
+ return (0);
+ }
+ str->data = tmp;
+ }
+ str->length = len;
+ if (data != NULL) {
+ memmove(str->data, data, len);
+ }
+ str->data[str->length] = '\0';
+ return (1);
+}
+
+void
+ASN1_STRING_set0(ASN1_STRING *str, void *data, int len)
+{
+ freezero(str->data, str->length);
+ str->data = data;
+ str->length = len;
+}
+
+ASN1_STRING *
+ASN1_STRING_new(void)
+{
+ return (ASN1_STRING_type_new(V_ASN1_OCTET_STRING));
+}
+
+ASN1_STRING *
+ASN1_STRING_type_new(int type)
+{
+ ASN1_STRING *a;
+
+ if ((a = calloc(1, sizeof(ASN1_STRING))) == NULL) {
+ ASN1error(ERR_R_MALLOC_FAILURE);
+ return NULL;
+ }
+ a->type = type;
+
+ return a;
+}
+
+void
+ASN1_STRING_free(ASN1_STRING *a)
+{
+ if (a == NULL)
+ return;
+ if (a->data != NULL && !(a->flags & ASN1_STRING_FLAG_NDEF))
+ freezero(a->data, a->length);
+ free(a);
+}
+
+int
+ASN1_STRING_cmp(const ASN1_STRING *a, const ASN1_STRING *b)
+{
+ int cmp;
+
+ if (a == NULL || b == NULL)
+ return -1;
+ if ((cmp = (a->length - b->length)) != 0)
+ return cmp;
+ if ((cmp = memcmp(a->data, b->data, a->length)) != 0)
+ return cmp;
+
+ return (a->type - b->type);
+}
+
+void
+asn1_add_error(const unsigned char *address, int offset)
+{
+ ERR_asprintf_error_data("offset=%d", offset);
+}
+
+int
+ASN1_STRING_length(const ASN1_STRING *x)
+{
+ return (x->length);
+}
+
+void
+ASN1_STRING_length_set(ASN1_STRING *x, int len)
+{
+ x->length = len;
+}
+
+int
+ASN1_STRING_type(const ASN1_STRING *x)
+{
+ return (x->type);
+}
+
+unsigned char *
+ASN1_STRING_data(ASN1_STRING *x)
+{
+ return (x->data);
+}
+
+const unsigned char *
+ASN1_STRING_get0_data(const ASN1_STRING *x)
+{
+ return (x->data);
+}
+
+int
i2a_ASN1_STRING(BIO *bp, const ASN1_STRING *a, int type)
{
int i, n = 0;
diff --git a/lib/libcrypto/asn1/asn1_lib.c b/lib/libcrypto/asn1/asn1_lib.c
index 3e2ba29495e..fc0958fb451 100644
--- a/lib/libcrypto/asn1/asn1_lib.c
+++ b/lib/libcrypto/asn1/asn1_lib.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: asn1_lib.c,v 1.48 2021/12/03 17:03:54 jsing Exp $ */
+/* $OpenBSD: asn1_lib.c,v 1.49 2021/12/15 18:00:31 jsing Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@@ -284,149 +284,3 @@ ASN1_object_size(int constructed, int length, int tag)
}
return (ret);
}
-
-int
-ASN1_STRING_copy(ASN1_STRING *dst, const ASN1_STRING *str)
-{
- if (str == NULL)
- return 0;
- if (!ASN1_STRING_set(dst, str->data, str->length))
- return 0;
- dst->type = str->type;
- dst->flags = str->flags;
- return 1;
-}
-
-ASN1_STRING *
-ASN1_STRING_dup(const ASN1_STRING *str)
-{
- ASN1_STRING *ret;
-
- if (!str)
- return NULL;
- ret = ASN1_STRING_new();
- if (!ret)
- return NULL;
- if (!ASN1_STRING_copy(ret, str)) {
- ASN1_STRING_free(ret);
- return NULL;
- }
- return ret;
-}
-
-int
-ASN1_STRING_set(ASN1_STRING *str, const void *_data, int len)
-{
- const char *data = _data;
-
- if (len < 0) {
- if (data == NULL)
- return (0);
- else
- len = strlen(data);
- }
- if ((str->length < len) || (str->data == NULL)) {
- unsigned char *tmp;
- tmp = realloc(str->data, len + 1);
- if (tmp == NULL) {
- ASN1error(ERR_R_MALLOC_FAILURE);
- return (0);
- }
- str->data = tmp;
- }
- str->length = len;
- if (data != NULL) {
- memmove(str->data, data, len);
- }
- str->data[str->length] = '\0';
- return (1);
-}
-
-void
-ASN1_STRING_set0(ASN1_STRING *str, void *data, int len)
-{
- freezero(str->data, str->length);
- str->data = data;
- str->length = len;
-}
-
-ASN1_STRING *
-ASN1_STRING_new(void)
-{
- return (ASN1_STRING_type_new(V_ASN1_OCTET_STRING));
-}
-
-ASN1_STRING *
-ASN1_STRING_type_new(int type)
-{
- ASN1_STRING *a;
-
- if ((a = calloc(1, sizeof(ASN1_STRING))) == NULL) {
- ASN1error(ERR_R_MALLOC_FAILURE);
- return NULL;
- }
- a->type = type;
-
- return a;
-}
-
-void
-ASN1_STRING_free(ASN1_STRING *a)
-{
- if (a == NULL)
- return;
- if (a->data != NULL && !(a->flags & ASN1_STRING_FLAG_NDEF))
- freezero(a->data, a->length);
- free(a);
-}
-
-int
-ASN1_STRING_cmp(const ASN1_STRING *a, const ASN1_STRING *b)
-{
- int cmp;
-
- if (a == NULL || b == NULL)
- return -1;
- if ((cmp = (a->length - b->length)) != 0)
- return cmp;
- if ((cmp = memcmp(a->data, b->data, a->length)) != 0)
- return cmp;
-
- return (a->type - b->type);
-}
-
-void
-asn1_add_error(const unsigned char *address, int offset)
-{
- ERR_asprintf_error_data("offset=%d", offset);
-}
-
-int
-ASN1_STRING_length(const ASN1_STRING *x)
-{
- return (x->length);
-}
-
-void
-ASN1_STRING_length_set(ASN1_STRING *x, int len)
-{
- x->length = len;
-}
-
-int
-ASN1_STRING_type(const ASN1_STRING *x)
-{
- return (x->type);
-}
-
-unsigned char *
-ASN1_STRING_data(ASN1_STRING *x)
-{
- return (x->data);
-}
-
-const unsigned char *
-ASN1_STRING_get0_data(const ASN1_STRING *x)
-{
- return (x->data);
-}
diff --git a/lib/libcrypto/asn1/f_enum.c b/lib/libcrypto/asn1/f_enum.c
deleted file mode 100644
index e5256705728..00000000000
--- a/lib/libcrypto/asn1/f_enum.c
+++ /dev/null
@@ -1,190 +0,0 @@
-/* $OpenBSD: f_enum.c,v 1.17 2021/11/23 11:10:51 schwarze Exp $ */
-/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
- * All rights reserved.
- *
- * This package is an SSL implementation written
- * by Eric Young (eay@cryptsoft.com).
- * The implementation was written so as to conform with Netscapes SSL.
- *
- * This library is free for commercial and non-commercial use as long as
- * the following conditions are aheared to. The following conditions
- * apply to all code found in this distribution, be it the RC4, RSA,
- * lhash, DES, etc., code; not just the SSL code. The SSL documentation
- * included with this distribution is covered by the same copyright terms
- * except that the holder is Tim Hudson (tjh@cryptsoft.com).
- *
- * Copyright remains Eric Young's, and as such any Copyright notices in
- * the code are not to be removed.
- * If this package is used in a product, Eric Young should be given attribution
- * as the author of the parts of the library used.
- * This can be in the form of a textual message at program startup or
- * in documentation (online or textual) provided with the package.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * "This product includes cryptographic software written by
- * Eric Young (eay@cryptsoft.com)"
- * The word 'cryptographic' can be left out if the rouines from the library
- * being used are not cryptographic related :-).
- * 4. If you include any Windows specific code (or a derivative thereof) from
- * the apps directory (application code) you must include an acknowledgement:
- * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
- *
- * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * The licence and distribution terms for any publically available version or
- * derivative of this code cannot be changed. i.e. this code cannot simply be
- * copied and put under another distribution licence
- * [including the GNU Public Licence.]
- */
-
-#include <stdio.h>
-
-#include <openssl/asn1.h>
-#include <openssl/buffer.h>
-#include <openssl/err.h>
-
-/* Based on a_int.c: equivalent ENUMERATED functions */
-
-int
-i2a_ASN1_ENUMERATED(BIO *bp, const ASN1_ENUMERATED *a)
-{
- int i, n = 0;
- static const char h[] = "0123456789ABCDEF";
- char buf[2];
-
- if (a == NULL)
- return (0);
-
- if (a->length == 0) {
- if (BIO_write(bp, "00", 2) != 2)
- goto err;
- n = 2;
- } else {
- for (i = 0; i < a->length; i++) {
- if ((i != 0) && (i % 35 == 0)) {
- if (BIO_write(bp, "\\\n", 2) != 2)
- goto err;
- n += 2;
- }
- buf[0] = h[((unsigned char)a->data[i] >> 4) & 0x0f];
- buf[1] = h[((unsigned char)a->data[i]) & 0x0f];
- if (BIO_write(bp, buf, 2) != 2)
- goto err;
- n += 2;
- }
- }
- return (n);
-
-err:
- return (-1);
-}
-
-int
-a2i_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *bs, char *buf, int size)
-{
- int ret = 0;
- int i, j,k, m,n, again, bufsize;
- unsigned char *s = NULL, *sp;
- unsigned char *bufp;
- int first = 1;
- size_t num = 0, slen = 0;
-
- bs->type = V_ASN1_ENUMERATED;
-
- bufsize = BIO_gets(bp, buf, size);
- for (;;) {
- if (bufsize < 1)
- goto err_sl;
- i = bufsize;
- if (buf[i-1] == '\n')
- buf[--i] = '\0';
- if (i == 0)
- goto err_sl;
- if (buf[i-1] == '\r')
- buf[--i] = '\0';
- if (i == 0)
- goto err_sl;
- if (buf[i - 1] == '\\') {
- i--;
- again = 1;
- } else
- again = 0;
- buf[i] = '\0';
- if (i < 2)
- goto err_sl;
-
- bufp = (unsigned char *)buf;
- if (first) {
- first = 0;
- if ((bufp[0] == '0') && (buf[1] == '0')) {
- bufp += 2;
- i -= 2;
- }
- }
- k = 0;
- if (i % 2 != 0) {
- ASN1error(ASN1_R_ODD_NUMBER_OF_CHARS);
- goto err;
- }
- i /= 2;
- if (num + i > slen) {
- sp = realloc(s, num + i);
- if (sp == NULL) {
- ASN1error(ERR_R_MALLOC_FAILURE);
- goto err;
- }
- s = sp;
- slen = num + i;
- }
- for (j = 0; j < i; j++, k += 2) {
- for (n = 0; n < 2; n++) {
- m = bufp[k + n];
- if ((m >= '0') && (m <= '9'))
- m -= '0';
- else if ((m >= 'a') && (m <= 'f'))
- m = m - 'a' + 10;
- else if ((m >= 'A') && (m <= 'F'))
- m = m - 'A' + 10;
- else {
- ASN1error(ASN1_R_NON_HEX_CHARACTERS);
- goto err;
- }
- s[num + j] <<= 4;
- s[num + j] |= m;
- }
- }
- num += i;
- if (again)
- bufsize = BIO_gets(bp, buf, size);
- else
- break;
- }
- bs->length = num;
- bs->data = s;
- return (1);
-
-err_sl:
- ASN1error(ASN1_R_SHORT_LINE);
-err:
- free(s);
- return (ret);
-}
diff --git a/lib/libcrypto/asn1/f_int.c b/lib/libcrypto/asn1/f_int.c
deleted file mode 100644
index 8ce9d20d5f4..00000000000
--- a/lib/libcrypto/asn1/f_int.c
+++ /dev/null
@@ -1,192 +0,0 @@
-/* $OpenBSD: f_int.c,v 1.21 2021/11/23 11:10:51 schwarze Exp $ */
-/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
- * All rights reserved.
- *
- * This package is an SSL implementation written
- * by Eric Young (eay@cryptsoft.com).
- * The implementation was written so as to conform with Netscapes SSL.
- *
- * This library is free for commercial and non-commercial use as long as
- * the following conditions are aheared to. The following conditions
- * apply to all code found in this distribution, be it the RC4, RSA,
- * lhash, DES, etc., code; not just the SSL code. The SSL documentation
- * included with this distribution is covered by the same copyright terms
- * except that the holder is Tim Hudson (tjh@cryptsoft.com).
- *
- * Copyright remains Eric Young's, and as such any Copyright notices in
- * the code are not to be removed.
- * If this package is used in a product, Eric Young should be given attribution
- * as the author of the parts of the library used.
- * This can be in the form of a textual message at program startup or
- * in documentation (online or textual) provided with the package.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * "This product includes cryptographic software written by
- * Eric Young (eay@cryptsoft.com)"
- * The word 'cryptographic' can be left out if the rouines from the library
- * being used are not cryptographic related :-).
- * 4. If you include any Windows specific code (or a derivative thereof) from
- * the apps directory (application code) you must include an acknowledgement:
- * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
- *
- * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * The licence and distribution terms for any publically available version or
- * derivative of this code cannot be changed. i.e. this code cannot simply be
- * copied and put under another distribution licence
- * [including the GNU Public Licence.]
- */
-
-#include <stdio.h>
-
-#include <openssl/asn1.h>
-#include <openssl/buffer.h>
-#include <openssl/err.h>
-
-int
-i2a_ASN1_INTEGER(BIO *bp, const ASN1_INTEGER *a)
-{
- int i, n = 0;
- static const char h[] = "0123456789ABCDEF";
- char buf[2];
-
- if (a == NULL)
- return (0);
-
- if (a->type & V_ASN1_NEG) {
- if (BIO_write(bp, "-", 1) != 1)
- goto err;
- n = 1;
- }
-
- if (a->length == 0) {
- if (BIO_write(bp, "00", 2) != 2)
- goto err;
- n += 2;
- } else {
- for (i = 0; i < a->length; i++) {
- if ((i != 0) && (i % 35 == 0)) {
- if (BIO_write(bp, "\\\n", 2) != 2)
- goto err;
- n += 2;
- }
- buf[0] = h[((unsigned char)a->data[i] >> 4) & 0x0f];
- buf[1] = h[((unsigned char)a->data[i]) & 0x0f];
- if (BIO_write(bp, buf, 2) != 2)
- goto err;
- n += 2;
- }
- }
- return (n);
-
-err:
- return (-1);
-}
-
-int
-a2i_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *bs, char *buf, int size)
-{
- int ret = 0;
- int i, j,k, m,n, again, bufsize;
- unsigned char *s = NULL, *sp;
- unsigned char *bufp;
- int num = 0, slen = 0, first = 1;
-
- bs->type = V_ASN1_INTEGER;
-
- bufsize = BIO_gets(bp, buf, size);
- for (;;) {
- if (bufsize < 1)
- goto err_sl;
- i = bufsize;
- if (buf[i - 1] == '\n')
- buf[--i] = '\0';
- if (i == 0)
- goto err_sl;
- if (buf[i - 1] == '\r')
- buf[--i] = '\0';
- if (i == 0)
- goto err_sl;
- if (buf[i - 1] == '\\') {
- i--;
- again = 1;
- } else
- again = 0;
- buf[i] = '\0';
- if (i < 2)
- goto err_sl;
-
- bufp = (unsigned char *)buf;
- if (first) {
- first = 0;
- if ((bufp[0] == '0') && (buf[1] == '0')) {
- bufp += 2;
- i -= 2;
- }
- }
- k = 0;
- if (i % 2 != 0) {
- ASN1error(ASN1_R_ODD_NUMBER_OF_CHARS);
- goto err;
- }
- i /= 2;
- if (num + i > slen) {
- if ((sp = recallocarray(s, slen, num + i, 1)) == NULL) {
- ASN1error(ERR_R_MALLOC_FAILURE);
- goto err;
- }
- s = sp;
- slen = num + i;
- }
- for (j = 0; j < i; j++, k += 2) {
- for (n = 0; n < 2; n++) {
- m = bufp[k + n];
- if ((m >= '0') && (m <= '9'))
- m -= '0';
- else if ((m >= 'a') && (m <= 'f'))
- m = m - 'a' + 10;
- else if ((m >= 'A') && (m <= 'F'))
- m = m - 'A' + 10;
- else {
- ASN1error(ASN1_R_NON_HEX_CHARACTERS);
- goto err;
- }
- s[num + j] <<= 4;
- s[num + j] |= m;
- }
- }
- num += i;
- if (again)
- bufsize = BIO_gets(bp, buf, size);
- else
- break;
- }
- bs->length = num;
- bs->data = s;
- return (1);
-
-err_sl:
- ASN1error(ASN1_R_SHORT_LINE);
-err:
- free(s);
- return (ret);
-}
diff --git a/lib/libcrypto/asn1/t_bitst.c b/lib/libcrypto/asn1/t_bitst.c
deleted file mode 100644
index 51515b88e25..00000000000
--- a/lib/libcrypto/asn1/t_bitst.c
+++ /dev/null
@@ -1,112 +0,0 @@
-/* $OpenBSD: t_bitst.c,v 1.8 2018/04/25 11:48:21 tb Exp $ */
-/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
- * project 1999.
- */
-/* ====================================================================
- * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * 3. All advertising materials mentioning features or use of this
- * software must display the following acknowledgment:
- * "This product includes software developed by the OpenSSL Project
- * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
- *
- * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
- * endorse or promote products derived from this software without
- * prior written permission. For written permission, please contact
- * licensing@OpenSSL.org.
- *
- * 5. Products derived from this software may not be called "OpenSSL"
- * nor may "OpenSSL" appear in their names without prior written
- * permission of the OpenSSL Project.
- *
- * 6. Redistributions of any form whatsoever must retain the following
- * acknowledgment:
- * "This product includes software developed by the OpenSSL Project
- * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
- *
- * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
- * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
- * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
- * OF THE POSSIBILITY OF SUCH DAMAGE.
- * ====================================================================
- *
- * This product includes cryptographic software written by Eric Young
- * (eay@cryptsoft.com). This product includes software written by Tim
- * Hudson (tjh@cryptsoft.com).
- *
- */
-
-#include <stdio.h>
-#include <string.h>
-
-#include <openssl/conf.h>
-#include <openssl/x509v3.h>
-
-int
-ASN1_BIT_STRING_name_print(BIO *out, ASN1_BIT_STRING *bs,
- BIT_STRING_BITNAME *tbl, int indent)
-{
- BIT_STRING_BITNAME *bnam;
- char first = 1;
-
- BIO_printf(out, "%*s", indent, "");
- for (bnam = tbl; bnam->lname; bnam++) {
- if (ASN1_BIT_STRING_get_bit(bs, bnam->bitnum)) {
- if (!first)
- BIO_puts(out, ", ");
- BIO_puts(out, bnam->lname);
- first = 0;
- }
- }
- BIO_puts(out, "\n");
- return 1;
-}
-
-int
-ASN1_BIT_STRING_set_asc(ASN1_BIT_STRING *bs, const char *name, int value,
- BIT_STRING_BITNAME *tbl)
-{
- int bitnum;
-
- bitnum = ASN1_BIT_STRING_num_asc(name, tbl);
- if (bitnum < 0)
- return 0;
- if (bs) {
- if (!ASN1_BIT_STRING_set_bit(bs, bitnum, value))
- return 0;
- }
- return 1;
-}
-
-int
-ASN1_BIT_STRING_num_asc(const char *name, BIT_STRING_BITNAME *tbl)
-{
- BIT_STRING_BITNAME *bnam;
-
- for (bnam = tbl; bnam->lname; bnam++) {
- if (!strcmp(bnam->sname, name) ||
- !strcmp(bnam->lname, name))
- return bnam->bitnum;
- }
- return -1;
-}