diff options
| author | jsing <> | 2021-12-15 18:00:32 +0000 |
|---|---|---|
| committer | jsing <> | 2021-12-15 18:00:32 +0000 |
| commit | 296d3ca5cd57dd602c85743229a5e6ef58976edc (patch) | |
| tree | 582bd7e91dc07b37e1a88c57120d362994f5a80b /src | |
| parent | e135a3ba22c8b5c9463cad3035704d99945030ac (diff) | |
| download | openbsd-296d3ca5cd57dd602c85743229a5e6ef58976edc.tar.gz openbsd-296d3ca5cd57dd602c85743229a5e6ef58976edc.tar.bz2 openbsd-296d3ca5cd57dd602c85743229a5e6ef58976edc.zip | |
Consolidate various ASN.1 code.
Rather than having multiple files per type (with minimal code per file),
use one file per type (a_<type>.c).
No functional change.
Discussed with tb@
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/libcrypto/Makefile | 10 | ||||
| -rw-r--r-- | src/lib/libcrypto/asn1/a_bitstr.c | 53 | ||||
| -rw-r--r-- | src/lib/libcrypto/asn1/a_enum.c | 130 | ||||
| -rw-r--r-- | src/lib/libcrypto/asn1/a_int.c | 131 | ||||
| -rw-r--r-- | src/lib/libcrypto/asn1/a_string.c (renamed from src/lib/libcrypto/asn1/f_string.c) | 149 | ||||
| -rw-r--r-- | src/lib/libcrypto/asn1/asn1_lib.c | 148 | ||||
| -rw-r--r-- | src/lib/libcrypto/asn1/f_enum.c | 190 | ||||
| -rw-r--r-- | src/lib/libcrypto/asn1/f_int.c | 192 | ||||
| -rw-r--r-- | src/lib/libcrypto/asn1/t_bitst.c | 112 |
9 files changed, 465 insertions, 650 deletions
diff --git a/src/lib/libcrypto/Makefile b/src/lib/libcrypto/Makefile index c7d84b437b..64b5cebd05 100644 --- a/src/lib/libcrypto/Makefile +++ b/src/lib/libcrypto/Makefile | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.56 2021/12/14 17:35:21 jsing Exp $ | 1 | # $OpenBSD: Makefile,v 1.57 2021/12/15 18:00:31 jsing Exp $ |
| 2 | 2 | ||
| 3 | LIB= crypto | 3 | LIB= crypto |
| 4 | LIBREBUILD=y | 4 | LIBREBUILD=y |
| @@ -53,16 +53,16 @@ SRCS+= aes_ctr.c aes_ige.c aes_wrap.c | |||
| 53 | 53 | ||
| 54 | # asn1/ | 54 | # asn1/ |
| 55 | SRCS+= a_object.c a_bitstr.c a_time.c a_int.c a_octet.c a_pkey.c a_pubkey.c | 55 | SRCS+= a_object.c a_bitstr.c a_time.c a_int.c a_octet.c a_pkey.c a_pubkey.c |
| 56 | SRCS+= a_print.c a_type.c a_dup.c a_d2i_fp.c a_i2d_fp.c | 56 | SRCS+= a_print.c a_type.c a_dup.c a_d2i_fp.c a_i2d_fp.c a_string.c |
| 57 | SRCS+= a_enum.c a_utf8.c a_sign.c a_digest.c a_verify.c a_mbstr.c a_strex.c | 57 | SRCS+= a_enum.c a_utf8.c a_sign.c a_digest.c a_verify.c a_mbstr.c a_strex.c |
| 58 | SRCS+= x_algor.c x_val.c x_pubkey.c x_sig.c x_req.c x_attrib.c x_bignum.c | 58 | SRCS+= x_algor.c x_val.c x_pubkey.c x_sig.c x_req.c x_attrib.c x_bignum.c |
| 59 | SRCS+= x_long.c x_name.c x_x509.c x_x509a.c x_crl.c x_info.c x_spki.c nsseq.c | 59 | SRCS+= x_long.c x_name.c x_x509.c x_x509a.c x_crl.c x_info.c x_spki.c nsseq.c |
| 60 | SRCS+= x_nx509.c | 60 | SRCS+= x_nx509.c |
| 61 | SRCS+= t_req.c t_x509.c t_x509a.c t_crl.c t_pkey.c t_spki.c t_bitst.c | 61 | SRCS+= t_req.c t_x509.c t_x509a.c t_crl.c t_pkey.c t_spki.c |
| 62 | SRCS+= tasn_new.c tasn_fre.c tasn_enc.c tasn_dec.c tasn_utl.c tasn_typ.c | 62 | SRCS+= tasn_new.c tasn_fre.c tasn_enc.c tasn_dec.c tasn_utl.c tasn_typ.c |
| 63 | SRCS+= tasn_prn.c ameth_lib.c | 63 | SRCS+= tasn_prn.c ameth_lib.c |
| 64 | SRCS+= f_int.c f_string.c n_pkey.c | 64 | SRCS+= n_pkey.c |
| 65 | SRCS+= f_enum.c x_pkey.c x_exten.c bio_asn1.c bio_ndef.c asn_mime.c | 65 | SRCS+= x_pkey.c x_exten.c bio_asn1.c bio_ndef.c asn_mime.c |
| 66 | SRCS+= asn1_gen.c asn1_par.c asn1_lib.c asn1_err.c a_strnid.c | 66 | SRCS+= asn1_gen.c asn1_par.c asn1_lib.c asn1_err.c a_strnid.c |
| 67 | SRCS+= evp_asn1.c asn_pack.c p5_pbe.c p5_pbev2.c p8_pkey.c asn_moid.c | 67 | SRCS+= evp_asn1.c asn_pack.c p5_pbe.c p5_pbev2.c p8_pkey.c asn_moid.c |
| 68 | SRCS+= a_time_tm.c asn1_types.c | 68 | SRCS+= a_time_tm.c asn1_types.c |
diff --git a/src/lib/libcrypto/asn1/a_bitstr.c b/src/lib/libcrypto/asn1/a_bitstr.c index f217f13d27..68cefee4a2 100644 --- a/src/lib/libcrypto/asn1/a_bitstr.c +++ b/src/lib/libcrypto/asn1/a_bitstr.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: a_bitstr.c,v 1.30 2020/09/03 17:19:27 tb Exp $ */ | 1 | /* $OpenBSD: a_bitstr.c,v 1.31 2021/12/15 18:00:31 jsing Exp $ */ |
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
| 3 | * All rights reserved. | 3 | * All rights reserved. |
| 4 | * | 4 | * |
| @@ -60,7 +60,9 @@ | |||
| 60 | #include <string.h> | 60 | #include <string.h> |
| 61 | 61 | ||
| 62 | #include <openssl/asn1.h> | 62 | #include <openssl/asn1.h> |
| 63 | #include <openssl/conf.h> | ||
| 63 | #include <openssl/err.h> | 64 | #include <openssl/err.h> |
| 65 | #include <openssl/x509v3.h> | ||
| 64 | 66 | ||
| 65 | int | 67 | int |
| 66 | ASN1_BIT_STRING_set(ASN1_BIT_STRING *x, unsigned char *d, int len) | 68 | 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, | |||
| 262 | } | 264 | } |
| 263 | return ok; | 265 | return ok; |
| 264 | } | 266 | } |
| 267 | |||
| 268 | int | ||
| 269 | ASN1_BIT_STRING_name_print(BIO *out, ASN1_BIT_STRING *bs, | ||
| 270 | BIT_STRING_BITNAME *tbl, int indent) | ||
| 271 | { | ||
| 272 | BIT_STRING_BITNAME *bnam; | ||
| 273 | char first = 1; | ||
| 274 | |||
| 275 | BIO_printf(out, "%*s", indent, ""); | ||
| 276 | for (bnam = tbl; bnam->lname; bnam++) { | ||
| 277 | if (ASN1_BIT_STRING_get_bit(bs, bnam->bitnum)) { | ||
| 278 | if (!first) | ||
| 279 | BIO_puts(out, ", "); | ||
| 280 | BIO_puts(out, bnam->lname); | ||
| 281 | first = 0; | ||
| 282 | } | ||
| 283 | } | ||
| 284 | BIO_puts(out, "\n"); | ||
| 285 | return 1; | ||
| 286 | } | ||
| 287 | |||
| 288 | int | ||
| 289 | ASN1_BIT_STRING_set_asc(ASN1_BIT_STRING *bs, const char *name, int value, | ||
| 290 | BIT_STRING_BITNAME *tbl) | ||
| 291 | { | ||
| 292 | int bitnum; | ||
| 293 | |||
| 294 | bitnum = ASN1_BIT_STRING_num_asc(name, tbl); | ||
| 295 | if (bitnum < 0) | ||
| 296 | return 0; | ||
| 297 | if (bs) { | ||
| 298 | if (!ASN1_BIT_STRING_set_bit(bs, bitnum, value)) | ||
| 299 | return 0; | ||
| 300 | } | ||
| 301 | return 1; | ||
| 302 | } | ||
| 303 | |||
| 304 | int | ||
| 305 | ASN1_BIT_STRING_num_asc(const char *name, BIT_STRING_BITNAME *tbl) | ||
| 306 | { | ||
| 307 | BIT_STRING_BITNAME *bnam; | ||
| 308 | |||
| 309 | for (bnam = tbl; bnam->lname; bnam++) { | ||
| 310 | if (!strcmp(bnam->sname, name) || | ||
| 311 | !strcmp(bnam->lname, name)) | ||
| 312 | return bnam->bitnum; | ||
| 313 | } | ||
| 314 | return -1; | ||
| 315 | } | ||
diff --git a/src/lib/libcrypto/asn1/a_enum.c b/src/lib/libcrypto/asn1/a_enum.c index 0952e049db..e0e64f0a81 100644 --- a/src/lib/libcrypto/asn1/a_enum.c +++ b/src/lib/libcrypto/asn1/a_enum.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: a_enum.c,v 1.20 2019/04/28 05:05:56 tb Exp $ */ | 1 | /* $OpenBSD: a_enum.c,v 1.21 2021/12/15 18:00:31 jsing Exp $ */ |
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
| 3 | * All rights reserved. | 3 | * All rights reserved. |
| 4 | * | 4 | * |
| @@ -61,6 +61,7 @@ | |||
| 61 | 61 | ||
| 62 | #include <openssl/asn1.h> | 62 | #include <openssl/asn1.h> |
| 63 | #include <openssl/bn.h> | 63 | #include <openssl/bn.h> |
| 64 | #include <openssl/buffer.h> | ||
| 64 | #include <openssl/err.h> | 65 | #include <openssl/err.h> |
| 65 | 66 | ||
| 66 | /* | 67 | /* |
| @@ -192,3 +193,130 @@ ASN1_ENUMERATED_to_BN(const ASN1_ENUMERATED *ai, BIGNUM *bn) | |||
| 192 | BN_set_negative(ret, 1); | 193 | BN_set_negative(ret, 1); |
| 193 | return (ret); | 194 | return (ret); |
| 194 | } | 195 | } |
| 196 | |||
| 197 | /* Based on a_int.c: equivalent ENUMERATED functions */ | ||
| 198 | |||
| 199 | int | ||
| 200 | i2a_ASN1_ENUMERATED(BIO *bp, const ASN1_ENUMERATED *a) | ||
| 201 | { | ||
| 202 | int i, n = 0; | ||
| 203 | static const char h[] = "0123456789ABCDEF"; | ||
| 204 | char buf[2]; | ||
| 205 | |||
| 206 | if (a == NULL) | ||
| 207 | return (0); | ||
| 208 | |||
| 209 | if (a->length == 0) { | ||
| 210 | if (BIO_write(bp, "00", 2) != 2) | ||
| 211 | goto err; | ||
| 212 | n = 2; | ||
| 213 | } else { | ||
| 214 | for (i = 0; i < a->length; i++) { | ||
| 215 | if ((i != 0) && (i % 35 == 0)) { | ||
| 216 | if (BIO_write(bp, "\\\n", 2) != 2) | ||
| 217 | goto err; | ||
| 218 | n += 2; | ||
| 219 | } | ||
| 220 | buf[0] = h[((unsigned char)a->data[i] >> 4) & 0x0f]; | ||
| 221 | buf[1] = h[((unsigned char)a->data[i]) & 0x0f]; | ||
| 222 | if (BIO_write(bp, buf, 2) != 2) | ||
| 223 | goto err; | ||
| 224 | n += 2; | ||
| 225 | } | ||
| 226 | } | ||
| 227 | return (n); | ||
| 228 | |||
| 229 | err: | ||
| 230 | return (-1); | ||
| 231 | } | ||
| 232 | |||
| 233 | int | ||
| 234 | a2i_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *bs, char *buf, int size) | ||
| 235 | { | ||
| 236 | int ret = 0; | ||
| 237 | int i, j,k, m,n, again, bufsize; | ||
| 238 | unsigned char *s = NULL, *sp; | ||
| 239 | unsigned char *bufp; | ||
| 240 | int first = 1; | ||
| 241 | size_t num = 0, slen = 0; | ||
| 242 | |||
| 243 | bs->type = V_ASN1_ENUMERATED; | ||
| 244 | |||
| 245 | bufsize = BIO_gets(bp, buf, size); | ||
| 246 | for (;;) { | ||
| 247 | if (bufsize < 1) | ||
| 248 | goto err_sl; | ||
| 249 | i = bufsize; | ||
| 250 | if (buf[i-1] == '\n') | ||
| 251 | buf[--i] = '\0'; | ||
| 252 | if (i == 0) | ||
| 253 | goto err_sl; | ||
| 254 | if (buf[i-1] == '\r') | ||
| 255 | buf[--i] = '\0'; | ||
| 256 | if (i == 0) | ||
| 257 | goto err_sl; | ||
| 258 | if (buf[i - 1] == '\\') { | ||
| 259 | i--; | ||
| 260 | again = 1; | ||
| 261 | } else | ||
| 262 | again = 0; | ||
| 263 | buf[i] = '\0'; | ||
| 264 | if (i < 2) | ||
| 265 | goto err_sl; | ||
| 266 | |||
| 267 | bufp = (unsigned char *)buf; | ||
| 268 | if (first) { | ||
| 269 | first = 0; | ||
| 270 | if ((bufp[0] == '0') && (buf[1] == '0')) { | ||
| 271 | bufp += 2; | ||
| 272 | i -= 2; | ||
| 273 | } | ||
| 274 | } | ||
| 275 | k = 0; | ||
| 276 | if (i % 2 != 0) { | ||
| 277 | ASN1error(ASN1_R_ODD_NUMBER_OF_CHARS); | ||
| 278 | goto err; | ||
| 279 | } | ||
| 280 | i /= 2; | ||
| 281 | if (num + i > slen) { | ||
| 282 | sp = realloc(s, num + i); | ||
| 283 | if (sp == NULL) { | ||
| 284 | ASN1error(ERR_R_MALLOC_FAILURE); | ||
| 285 | goto err; | ||
| 286 | } | ||
| 287 | s = sp; | ||
| 288 | slen = num + i; | ||
| 289 | } | ||
| 290 | for (j = 0; j < i; j++, k += 2) { | ||
| 291 | for (n = 0; n < 2; n++) { | ||
| 292 | m = bufp[k + n]; | ||
| 293 | if ((m >= '0') && (m <= '9')) | ||
| 294 | m -= '0'; | ||
| 295 | else if ((m >= 'a') && (m <= 'f')) | ||
| 296 | m = m - 'a' + 10; | ||
| 297 | else if ((m >= 'A') && (m <= 'F')) | ||
| 298 | m = m - 'A' + 10; | ||
| 299 | else { | ||
| 300 | ASN1error(ASN1_R_NON_HEX_CHARACTERS); | ||
| 301 | goto err; | ||
| 302 | } | ||
| 303 | s[num + j] <<= 4; | ||
| 304 | s[num + j] |= m; | ||
| 305 | } | ||
| 306 | } | ||
| 307 | num += i; | ||
| 308 | if (again) | ||
| 309 | bufsize = BIO_gets(bp, buf, size); | ||
| 310 | else | ||
| 311 | break; | ||
| 312 | } | ||
| 313 | bs->length = num; | ||
| 314 | bs->data = s; | ||
| 315 | return (1); | ||
| 316 | |||
| 317 | err_sl: | ||
| 318 | ASN1error(ASN1_R_SHORT_LINE); | ||
| 319 | err: | ||
| 320 | free(s); | ||
| 321 | return (ret); | ||
| 322 | } | ||
diff --git a/src/lib/libcrypto/asn1/a_int.c b/src/lib/libcrypto/asn1/a_int.c index d14bd7959b..314bd2b369 100644 --- a/src/lib/libcrypto/asn1/a_int.c +++ b/src/lib/libcrypto/asn1/a_int.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: a_int.c,v 1.34 2019/04/28 05:03:56 tb Exp $ */ | 1 | /* $OpenBSD: a_int.c,v 1.35 2021/12/15 18:00:31 jsing Exp $ */ |
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
| 3 | * All rights reserved. | 3 | * All rights reserved. |
| 4 | * | 4 | * |
| @@ -62,6 +62,7 @@ | |||
| 62 | 62 | ||
| 63 | #include <openssl/asn1.h> | 63 | #include <openssl/asn1.h> |
| 64 | #include <openssl/bn.h> | 64 | #include <openssl/bn.h> |
| 65 | #include <openssl/buffer.h> | ||
| 65 | #include <openssl/err.h> | 66 | #include <openssl/err.h> |
| 66 | 67 | ||
| 67 | static int | 68 | static int |
| @@ -101,6 +102,134 @@ ASN1_INTEGER_cmp(const ASN1_INTEGER *x, const ASN1_INTEGER *y) | |||
| 101 | return ret; | 102 | return ret; |
| 102 | } | 103 | } |
| 103 | 104 | ||
| 105 | int | ||
| 106 | i2a_ASN1_INTEGER(BIO *bp, const ASN1_INTEGER *a) | ||
| 107 | { | ||
| 108 | int i, n = 0; | ||
| 109 | static const char h[] = "0123456789ABCDEF"; | ||
| 110 | char buf[2]; | ||
| 111 | |||
| 112 | if (a == NULL) | ||
| 113 | return (0); | ||
| 114 | |||
| 115 | if (a->type & V_ASN1_NEG) { | ||
| 116 | if (BIO_write(bp, "-", 1) != 1) | ||
| 117 | goto err; | ||
| 118 | n = 1; | ||
| 119 | } | ||
| 120 | |||
| 121 | if (a->length == 0) { | ||
| 122 | if (BIO_write(bp, "00", 2) != 2) | ||
| 123 | goto err; | ||
| 124 | n += 2; | ||
| 125 | } else { | ||
| 126 | for (i = 0; i < a->length; i++) { | ||
| 127 | if ((i != 0) && (i % 35 == 0)) { | ||
| 128 | if (BIO_write(bp, "\\\n", 2) != 2) | ||
| 129 | goto err; | ||
| 130 | n += 2; | ||
| 131 | } | ||
| 132 | buf[0] = h[((unsigned char)a->data[i] >> 4) & 0x0f]; | ||
| 133 | buf[1] = h[((unsigned char)a->data[i]) & 0x0f]; | ||
| 134 | if (BIO_write(bp, buf, 2) != 2) | ||
| 135 | goto err; | ||
| 136 | n += 2; | ||
| 137 | } | ||
| 138 | } | ||
| 139 | return (n); | ||
| 140 | |||
| 141 | err: | ||
| 142 | return (-1); | ||
| 143 | } | ||
| 144 | |||
| 145 | int | ||
| 146 | a2i_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *bs, char *buf, int size) | ||
| 147 | { | ||
| 148 | int ret = 0; | ||
| 149 | int i, j,k, m,n, again, bufsize; | ||
| 150 | unsigned char *s = NULL, *sp; | ||
| 151 | unsigned char *bufp; | ||
| 152 | int num = 0, slen = 0, first = 1; | ||
| 153 | |||
| 154 | bs->type = V_ASN1_INTEGER; | ||
| 155 | |||
| 156 | bufsize = BIO_gets(bp, buf, size); | ||
| 157 | for (;;) { | ||
| 158 | if (bufsize < 1) | ||
| 159 | goto err_sl; | ||
| 160 | i = bufsize; | ||
| 161 | if (buf[i - 1] == '\n') | ||
| 162 | buf[--i] = '\0'; | ||
| 163 | if (i == 0) | ||
| 164 | goto err_sl; | ||
| 165 | if (buf[i - 1] == '\r') | ||
| 166 | buf[--i] = '\0'; | ||
| 167 | if (i == 0) | ||
| 168 | goto err_sl; | ||
| 169 | if (buf[i - 1] == '\\') { | ||
| 170 | i--; | ||
| 171 | again = 1; | ||
| 172 | } else | ||
| 173 | again = 0; | ||
| 174 | buf[i] = '\0'; | ||
| 175 | if (i < 2) | ||
| 176 | goto err_sl; | ||
| 177 | |||
| 178 | bufp = (unsigned char *)buf; | ||
| 179 | if (first) { | ||
| 180 | first = 0; | ||
| 181 | if ((bufp[0] == '0') && (buf[1] == '0')) { | ||
| 182 | bufp += 2; | ||
| 183 | i -= 2; | ||
| 184 | } | ||
| 185 | } | ||
| 186 | k = 0; | ||
| 187 | if (i % 2 != 0) { | ||
| 188 | ASN1error(ASN1_R_ODD_NUMBER_OF_CHARS); | ||
| 189 | goto err; | ||
| 190 | } | ||
| 191 | i /= 2; | ||
| 192 | if (num + i > slen) { | ||
| 193 | if ((sp = recallocarray(s, slen, num + i, 1)) == NULL) { | ||
| 194 | ASN1error(ERR_R_MALLOC_FAILURE); | ||
| 195 | goto err; | ||
| 196 | } | ||
| 197 | s = sp; | ||
| 198 | slen = num + i; | ||
| 199 | } | ||
| 200 | for (j = 0; j < i; j++, k += 2) { | ||
| 201 | for (n = 0; n < 2; n++) { | ||
| 202 | m = bufp[k + n]; | ||
| 203 | if ((m >= '0') && (m <= '9')) | ||
| 204 | m -= '0'; | ||
| 205 | else if ((m >= 'a') && (m <= 'f')) | ||
| 206 | m = m - 'a' + 10; | ||
| 207 | else if ((m >= 'A') && (m <= 'F')) | ||
| 208 | m = m - 'A' + 10; | ||
| 209 | else { | ||
| 210 | ASN1error(ASN1_R_NON_HEX_CHARACTERS); | ||
| 211 | goto err; | ||
| 212 | } | ||
| 213 | s[num + j] <<= 4; | ||
| 214 | s[num + j] |= m; | ||
| 215 | } | ||
| 216 | } | ||
| 217 | num += i; | ||
| 218 | if (again) | ||
| 219 | bufsize = BIO_gets(bp, buf, size); | ||
| 220 | else | ||
| 221 | break; | ||
| 222 | } | ||
| 223 | bs->length = num; | ||
| 224 | bs->data = s; | ||
| 225 | return (1); | ||
| 226 | |||
| 227 | err_sl: | ||
| 228 | ASN1error(ASN1_R_SHORT_LINE); | ||
| 229 | err: | ||
| 230 | free(s); | ||
| 231 | return (ret); | ||
| 232 | } | ||
| 104 | 233 | ||
| 105 | /* | 234 | /* |
| 106 | * This converts an ASN1 INTEGER into its content encoding. | 235 | * This converts an ASN1 INTEGER into its content encoding. |
diff --git a/src/lib/libcrypto/asn1/f_string.c b/src/lib/libcrypto/asn1/a_string.c index b34343db39..b3a1323a54 100644 --- a/src/lib/libcrypto/asn1/f_string.c +++ b/src/lib/libcrypto/asn1/a_string.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: f_string.c,v 1.19 2021/11/19 09:58:41 schwarze Exp $ */ | 1 | /* $OpenBSD: a_string.c,v 1.1 2021/12/15 18:00:31 jsing Exp $ */ |
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
| 3 | * All rights reserved. | 3 | * All rights reserved. |
| 4 | * | 4 | * |
| @@ -57,12 +57,159 @@ | |||
| 57 | */ | 57 | */ |
| 58 | 58 | ||
| 59 | #include <stdio.h> | 59 | #include <stdio.h> |
| 60 | #include <string.h> | ||
| 60 | 61 | ||
| 61 | #include <openssl/asn1.h> | 62 | #include <openssl/asn1.h> |
| 62 | #include <openssl/buffer.h> | 63 | #include <openssl/buffer.h> |
| 63 | #include <openssl/err.h> | 64 | #include <openssl/err.h> |
| 64 | 65 | ||
| 65 | int | 66 | int |
| 67 | ASN1_STRING_copy(ASN1_STRING *dst, const ASN1_STRING *str) | ||
| 68 | { | ||
| 69 | if (str == NULL) | ||
| 70 | return 0; | ||
| 71 | if (!ASN1_STRING_set(dst, str->data, str->length)) | ||
| 72 | return 0; | ||
| 73 | dst->type = str->type; | ||
| 74 | dst->flags = str->flags; | ||
| 75 | return 1; | ||
| 76 | } | ||
| 77 | |||
| 78 | ASN1_STRING * | ||
| 79 | ASN1_STRING_dup(const ASN1_STRING *str) | ||
| 80 | { | ||
| 81 | ASN1_STRING *ret; | ||
| 82 | |||
| 83 | if (!str) | ||
| 84 | return NULL; | ||
| 85 | ret = ASN1_STRING_new(); | ||
| 86 | if (!ret) | ||
| 87 | return NULL; | ||
| 88 | if (!ASN1_STRING_copy(ret, str)) { | ||
| 89 | ASN1_STRING_free(ret); | ||
| 90 | return NULL; | ||
| 91 | } | ||
| 92 | return ret; | ||
| 93 | } | ||
| 94 | |||
| 95 | int | ||
| 96 | ASN1_STRING_set(ASN1_STRING *str, const void *_data, int len) | ||
| 97 | { | ||
| 98 | const char *data = _data; | ||
| 99 | |||
| 100 | if (len < 0) { | ||
| 101 | if (data == NULL) | ||
| 102 | return (0); | ||
| 103 | else | ||
| 104 | len = strlen(data); | ||
| 105 | } | ||
| 106 | if ((str->length < len) || (str->data == NULL)) { | ||
| 107 | unsigned char *tmp; | ||
| 108 | tmp = realloc(str->data, len + 1); | ||
| 109 | if (tmp == NULL) { | ||
| 110 | ASN1error(ERR_R_MALLOC_FAILURE); | ||
| 111 | return (0); | ||
| 112 | } | ||
| 113 | str->data = tmp; | ||
| 114 | } | ||
| 115 | str->length = len; | ||
| 116 | if (data != NULL) { | ||
| 117 | memmove(str->data, data, len); | ||
| 118 | } | ||
| 119 | str->data[str->length] = '\0'; | ||
| 120 | return (1); | ||
| 121 | } | ||
| 122 | |||
| 123 | void | ||
| 124 | ASN1_STRING_set0(ASN1_STRING *str, void *data, int len) | ||
| 125 | { | ||
| 126 | freezero(str->data, str->length); | ||
| 127 | str->data = data; | ||
| 128 | str->length = len; | ||
| 129 | } | ||
| 130 | |||
| 131 | ASN1_STRING * | ||
| 132 | ASN1_STRING_new(void) | ||
| 133 | { | ||
| 134 | return (ASN1_STRING_type_new(V_ASN1_OCTET_STRING)); | ||
| 135 | } | ||
| 136 | |||
| 137 | ASN1_STRING * | ||
| 138 | ASN1_STRING_type_new(int type) | ||
| 139 | { | ||
| 140 | ASN1_STRING *a; | ||
| 141 | |||
| 142 | if ((a = calloc(1, sizeof(ASN1_STRING))) == NULL) { | ||
| 143 | ASN1error(ERR_R_MALLOC_FAILURE); | ||
| 144 | return NULL; | ||
| 145 | } | ||
| 146 | a->type = type; | ||
| 147 | |||
| 148 | return a; | ||
| 149 | } | ||
| 150 | |||
| 151 | void | ||
| 152 | ASN1_STRING_free(ASN1_STRING *a) | ||
| 153 | { | ||
| 154 | if (a == NULL) | ||
| 155 | return; | ||
| 156 | if (a->data != NULL && !(a->flags & ASN1_STRING_FLAG_NDEF)) | ||
| 157 | freezero(a->data, a->length); | ||
| 158 | free(a); | ||
| 159 | } | ||
| 160 | |||
| 161 | int | ||
| 162 | ASN1_STRING_cmp(const ASN1_STRING *a, const ASN1_STRING *b) | ||
| 163 | { | ||
| 164 | int cmp; | ||
| 165 | |||
| 166 | if (a == NULL || b == NULL) | ||
| 167 | return -1; | ||
| 168 | if ((cmp = (a->length - b->length)) != 0) | ||
| 169 | return cmp; | ||
| 170 | if ((cmp = memcmp(a->data, b->data, a->length)) != 0) | ||
| 171 | return cmp; | ||
| 172 | |||
| 173 | return (a->type - b->type); | ||
| 174 | } | ||
| 175 | |||
| 176 | void | ||
| 177 | asn1_add_error(const unsigned char *address, int offset) | ||
| 178 | { | ||
| 179 | ERR_asprintf_error_data("offset=%d", offset); | ||
| 180 | } | ||
| 181 | |||
| 182 | int | ||
| 183 | ASN1_STRING_length(const ASN1_STRING *x) | ||
| 184 | { | ||
| 185 | return (x->length); | ||
| 186 | } | ||
| 187 | |||
| 188 | void | ||
| 189 | ASN1_STRING_length_set(ASN1_STRING *x, int len) | ||
| 190 | { | ||
| 191 | x->length = len; | ||
| 192 | } | ||
| 193 | |||
| 194 | int | ||
| 195 | ASN1_STRING_type(const ASN1_STRING *x) | ||
| 196 | { | ||
| 197 | return (x->type); | ||
| 198 | } | ||
| 199 | |||
| 200 | unsigned char * | ||
| 201 | ASN1_STRING_data(ASN1_STRING *x) | ||
| 202 | { | ||
| 203 | return (x->data); | ||
| 204 | } | ||
| 205 | |||
| 206 | const unsigned char * | ||
| 207 | ASN1_STRING_get0_data(const ASN1_STRING *x) | ||
| 208 | { | ||
| 209 | return (x->data); | ||
| 210 | } | ||
| 211 | |||
| 212 | int | ||
| 66 | i2a_ASN1_STRING(BIO *bp, const ASN1_STRING *a, int type) | 213 | i2a_ASN1_STRING(BIO *bp, const ASN1_STRING *a, int type) |
| 67 | { | 214 | { |
| 68 | int i, n = 0; | 215 | int i, n = 0; |
diff --git a/src/lib/libcrypto/asn1/asn1_lib.c b/src/lib/libcrypto/asn1/asn1_lib.c index 3e2ba29495..fc0958fb45 100644 --- a/src/lib/libcrypto/asn1/asn1_lib.c +++ b/src/lib/libcrypto/asn1/asn1_lib.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: asn1_lib.c,v 1.48 2021/12/03 17:03:54 jsing Exp $ */ | 1 | /* $OpenBSD: asn1_lib.c,v 1.49 2021/12/15 18:00:31 jsing Exp $ */ |
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
| 3 | * All rights reserved. | 3 | * All rights reserved. |
| 4 | * | 4 | * |
| @@ -284,149 +284,3 @@ ASN1_object_size(int constructed, int length, int tag) | |||
| 284 | } | 284 | } |
| 285 | return (ret); | 285 | return (ret); |
| 286 | } | 286 | } |
| 287 | |||
| 288 | int | ||
| 289 | ASN1_STRING_copy(ASN1_STRING *dst, const ASN1_STRING *str) | ||
| 290 | { | ||
| 291 | if (str == NULL) | ||
| 292 | return 0; | ||
| 293 | if (!ASN1_STRING_set(dst, str->data, str->length)) | ||
| 294 | return 0; | ||
| 295 | dst->type = str->type; | ||
| 296 | dst->flags = str->flags; | ||
| 297 | return 1; | ||
| 298 | } | ||
| 299 | |||
| 300 | ASN1_STRING * | ||
| 301 | ASN1_STRING_dup(const ASN1_STRING *str) | ||
| 302 | { | ||
| 303 | ASN1_STRING *ret; | ||
| 304 | |||
| 305 | if (!str) | ||
| 306 | return NULL; | ||
| 307 | ret = ASN1_STRING_new(); | ||
| 308 | if (!ret) | ||
| 309 | return NULL; | ||
| 310 | if (!ASN1_STRING_copy(ret, str)) { | ||
| 311 | ASN1_STRING_free(ret); | ||
| 312 | return NULL; | ||
| 313 | } | ||
| 314 | return ret; | ||
| 315 | } | ||
| 316 | |||
| 317 | int | ||
| 318 | ASN1_STRING_set(ASN1_STRING *str, const void *_data, int len) | ||
| 319 | { | ||
| 320 | const char *data = _data; | ||
| 321 | |||
| 322 | if (len < 0) { | ||
| 323 | if (data == NULL) | ||
| 324 | return (0); | ||
| 325 | else | ||
| 326 | len = strlen(data); | ||
| 327 | } | ||
| 328 | if ((str->length < len) || (str->data == NULL)) { | ||
| 329 | unsigned char *tmp; | ||
| 330 | tmp = realloc(str->data, len + 1); | ||
| 331 | if (tmp == NULL) { | ||
| 332 | ASN1error(ERR_R_MALLOC_FAILURE); | ||
| 333 | return (0); | ||
| 334 | } | ||
| 335 | str->data = tmp; | ||
| 336 | } | ||
| 337 | str->length = len; | ||
| 338 | if (data != NULL) { | ||
| 339 | memmove(str->data, data, len); | ||
| 340 | } | ||
| 341 | str->data[str->length] = '\0'; | ||
| 342 | return (1); | ||
| 343 | } | ||
| 344 | |||
| 345 | void | ||
| 346 | ASN1_STRING_set0(ASN1_STRING *str, void *data, int len) | ||
| 347 | { | ||
| 348 | freezero(str->data, str->length); | ||
| 349 | str->data = data; | ||
| 350 | str->length = len; | ||
| 351 | } | ||
| 352 | |||
| 353 | ASN1_STRING * | ||
| 354 | ASN1_STRING_new(void) | ||
| 355 | { | ||
| 356 | return (ASN1_STRING_type_new(V_ASN1_OCTET_STRING)); | ||
| 357 | } | ||
| 358 | |||
| 359 | ASN1_STRING * | ||
| 360 | ASN1_STRING_type_new(int type) | ||
| 361 | { | ||
| 362 | ASN1_STRING *a; | ||
| 363 | |||
| 364 | if ((a = calloc(1, sizeof(ASN1_STRING))) == NULL) { | ||
| 365 | ASN1error(ERR_R_MALLOC_FAILURE); | ||
| 366 | return NULL; | ||
| 367 | } | ||
| 368 | a->type = type; | ||
| 369 | |||
| 370 | return a; | ||
| 371 | } | ||
| 372 | |||
| 373 | void | ||
| 374 | ASN1_STRING_free(ASN1_STRING *a) | ||
| 375 | { | ||
| 376 | if (a == NULL) | ||
| 377 | return; | ||
| 378 | if (a->data != NULL && !(a->flags & ASN1_STRING_FLAG_NDEF)) | ||
| 379 | freezero(a->data, a->length); | ||
| 380 | free(a); | ||
| 381 | } | ||
| 382 | |||
| 383 | int | ||
| 384 | ASN1_STRING_cmp(const ASN1_STRING *a, const ASN1_STRING *b) | ||
| 385 | { | ||
| 386 | int cmp; | ||
| 387 | |||
| 388 | if (a == NULL || b == NULL) | ||
| 389 | return -1; | ||
| 390 | if ((cmp = (a->length - b->length)) != 0) | ||
| 391 | return cmp; | ||
| 392 | if ((cmp = memcmp(a->data, b->data, a->length)) != 0) | ||
| 393 | return cmp; | ||
| 394 | |||
| 395 | return (a->type - b->type); | ||
| 396 | } | ||
| 397 | |||
| 398 | void | ||
| 399 | asn1_add_error(const unsigned char *address, int offset) | ||
| 400 | { | ||
| 401 | ERR_asprintf_error_data("offset=%d", offset); | ||
| 402 | } | ||
| 403 | |||
| 404 | int | ||
| 405 | ASN1_STRING_length(const ASN1_STRING *x) | ||
| 406 | { | ||
| 407 | return (x->length); | ||
| 408 | } | ||
| 409 | |||
| 410 | void | ||
| 411 | ASN1_STRING_length_set(ASN1_STRING *x, int len) | ||
| 412 | { | ||
| 413 | x->length = len; | ||
| 414 | } | ||
| 415 | |||
| 416 | int | ||
| 417 | ASN1_STRING_type(const ASN1_STRING *x) | ||
| 418 | { | ||
| 419 | return (x->type); | ||
| 420 | } | ||
| 421 | |||
| 422 | unsigned char * | ||
| 423 | ASN1_STRING_data(ASN1_STRING *x) | ||
| 424 | { | ||
| 425 | return (x->data); | ||
| 426 | } | ||
| 427 | |||
| 428 | const unsigned char * | ||
| 429 | ASN1_STRING_get0_data(const ASN1_STRING *x) | ||
| 430 | { | ||
| 431 | return (x->data); | ||
| 432 | } | ||
diff --git a/src/lib/libcrypto/asn1/f_enum.c b/src/lib/libcrypto/asn1/f_enum.c deleted file mode 100644 index e525670572..0000000000 --- a/src/lib/libcrypto/asn1/f_enum.c +++ /dev/null | |||
| @@ -1,190 +0,0 @@ | |||
| 1 | /* $OpenBSD: f_enum.c,v 1.17 2021/11/23 11:10:51 schwarze Exp $ */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | |||
| 61 | #include <openssl/asn1.h> | ||
| 62 | #include <openssl/buffer.h> | ||
| 63 | #include <openssl/err.h> | ||
| 64 | |||
| 65 | /* Based on a_int.c: equivalent ENUMERATED functions */ | ||
| 66 | |||
| 67 | int | ||
| 68 | i2a_ASN1_ENUMERATED(BIO *bp, const ASN1_ENUMERATED *a) | ||
| 69 | { | ||
| 70 | int i, n = 0; | ||
| 71 | static const char h[] = "0123456789ABCDEF"; | ||
| 72 | char buf[2]; | ||
| 73 | |||
| 74 | if (a == NULL) | ||
| 75 | return (0); | ||
| 76 | |||
| 77 | if (a->length == 0) { | ||
| 78 | if (BIO_write(bp, "00", 2) != 2) | ||
| 79 | goto err; | ||
| 80 | n = 2; | ||
| 81 | } else { | ||
| 82 | for (i = 0; i < a->length; i++) { | ||
| 83 | if ((i != 0) && (i % 35 == 0)) { | ||
| 84 | if (BIO_write(bp, "\\\n", 2) != 2) | ||
| 85 | goto err; | ||
| 86 | n += 2; | ||
| 87 | } | ||
| 88 | buf[0] = h[((unsigned char)a->data[i] >> 4) & 0x0f]; | ||
| 89 | buf[1] = h[((unsigned char)a->data[i]) & 0x0f]; | ||
| 90 | if (BIO_write(bp, buf, 2) != 2) | ||
| 91 | goto err; | ||
| 92 | n += 2; | ||
| 93 | } | ||
| 94 | } | ||
| 95 | return (n); | ||
| 96 | |||
| 97 | err: | ||
| 98 | return (-1); | ||
| 99 | } | ||
| 100 | |||
| 101 | int | ||
| 102 | a2i_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *bs, char *buf, int size) | ||
| 103 | { | ||
| 104 | int ret = 0; | ||
| 105 | int i, j,k, m,n, again, bufsize; | ||
| 106 | unsigned char *s = NULL, *sp; | ||
| 107 | unsigned char *bufp; | ||
| 108 | int first = 1; | ||
| 109 | size_t num = 0, slen = 0; | ||
| 110 | |||
| 111 | bs->type = V_ASN1_ENUMERATED; | ||
| 112 | |||
| 113 | bufsize = BIO_gets(bp, buf, size); | ||
| 114 | for (;;) { | ||
| 115 | if (bufsize < 1) | ||
| 116 | goto err_sl; | ||
| 117 | i = bufsize; | ||
| 118 | if (buf[i-1] == '\n') | ||
| 119 | buf[--i] = '\0'; | ||
| 120 | if (i == 0) | ||
| 121 | goto err_sl; | ||
| 122 | if (buf[i-1] == '\r') | ||
| 123 | buf[--i] = '\0'; | ||
| 124 | if (i == 0) | ||
| 125 | goto err_sl; | ||
| 126 | if (buf[i - 1] == '\\') { | ||
| 127 | i--; | ||
| 128 | again = 1; | ||
| 129 | } else | ||
| 130 | again = 0; | ||
| 131 | buf[i] = '\0'; | ||
| 132 | if (i < 2) | ||
| 133 | goto err_sl; | ||
| 134 | |||
| 135 | bufp = (unsigned char *)buf; | ||
| 136 | if (first) { | ||
| 137 | first = 0; | ||
| 138 | if ((bufp[0] == '0') && (buf[1] == '0')) { | ||
| 139 | bufp += 2; | ||
| 140 | i -= 2; | ||
| 141 | } | ||
| 142 | } | ||
| 143 | k = 0; | ||
| 144 | if (i % 2 != 0) { | ||
| 145 | ASN1error(ASN1_R_ODD_NUMBER_OF_CHARS); | ||
| 146 | goto err; | ||
| 147 | } | ||
| 148 | i /= 2; | ||
| 149 | if (num + i > slen) { | ||
| 150 | sp = realloc(s, num + i); | ||
| 151 | if (sp == NULL) { | ||
| 152 | ASN1error(ERR_R_MALLOC_FAILURE); | ||
| 153 | goto err; | ||
| 154 | } | ||
| 155 | s = sp; | ||
| 156 | slen = num + i; | ||
| 157 | } | ||
| 158 | for (j = 0; j < i; j++, k += 2) { | ||
| 159 | for (n = 0; n < 2; n++) { | ||
| 160 | m = bufp[k + n]; | ||
| 161 | if ((m >= '0') && (m <= '9')) | ||
| 162 | m -= '0'; | ||
| 163 | else if ((m >= 'a') && (m <= 'f')) | ||
| 164 | m = m - 'a' + 10; | ||
| 165 | else if ((m >= 'A') && (m <= 'F')) | ||
| 166 | m = m - 'A' + 10; | ||
| 167 | else { | ||
| 168 | ASN1error(ASN1_R_NON_HEX_CHARACTERS); | ||
| 169 | goto err; | ||
| 170 | } | ||
| 171 | s[num + j] <<= 4; | ||
| 172 | s[num + j] |= m; | ||
| 173 | } | ||
| 174 | } | ||
| 175 | num += i; | ||
| 176 | if (again) | ||
| 177 | bufsize = BIO_gets(bp, buf, size); | ||
| 178 | else | ||
| 179 | break; | ||
| 180 | } | ||
| 181 | bs->length = num; | ||
| 182 | bs->data = s; | ||
| 183 | return (1); | ||
| 184 | |||
| 185 | err_sl: | ||
| 186 | ASN1error(ASN1_R_SHORT_LINE); | ||
| 187 | err: | ||
| 188 | free(s); | ||
| 189 | return (ret); | ||
| 190 | } | ||
diff --git a/src/lib/libcrypto/asn1/f_int.c b/src/lib/libcrypto/asn1/f_int.c deleted file mode 100644 index 8ce9d20d5f..0000000000 --- a/src/lib/libcrypto/asn1/f_int.c +++ /dev/null | |||
| @@ -1,192 +0,0 @@ | |||
| 1 | /* $OpenBSD: f_int.c,v 1.21 2021/11/23 11:10:51 schwarze Exp $ */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | |||
| 61 | #include <openssl/asn1.h> | ||
| 62 | #include <openssl/buffer.h> | ||
| 63 | #include <openssl/err.h> | ||
| 64 | |||
| 65 | int | ||
| 66 | i2a_ASN1_INTEGER(BIO *bp, const ASN1_INTEGER *a) | ||
| 67 | { | ||
| 68 | int i, n = 0; | ||
| 69 | static const char h[] = "0123456789ABCDEF"; | ||
| 70 | char buf[2]; | ||
| 71 | |||
| 72 | if (a == NULL) | ||
| 73 | return (0); | ||
| 74 | |||
| 75 | if (a->type & V_ASN1_NEG) { | ||
| 76 | if (BIO_write(bp, "-", 1) != 1) | ||
| 77 | goto err; | ||
| 78 | n = 1; | ||
| 79 | } | ||
| 80 | |||
| 81 | if (a->length == 0) { | ||
| 82 | if (BIO_write(bp, "00", 2) != 2) | ||
| 83 | goto err; | ||
| 84 | n += 2; | ||
| 85 | } else { | ||
| 86 | for (i = 0; i < a->length; i++) { | ||
| 87 | if ((i != 0) && (i % 35 == 0)) { | ||
| 88 | if (BIO_write(bp, "\\\n", 2) != 2) | ||
| 89 | goto err; | ||
| 90 | n += 2; | ||
| 91 | } | ||
| 92 | buf[0] = h[((unsigned char)a->data[i] >> 4) & 0x0f]; | ||
| 93 | buf[1] = h[((unsigned char)a->data[i]) & 0x0f]; | ||
| 94 | if (BIO_write(bp, buf, 2) != 2) | ||
| 95 | goto err; | ||
| 96 | n += 2; | ||
| 97 | } | ||
| 98 | } | ||
| 99 | return (n); | ||
| 100 | |||
| 101 | err: | ||
| 102 | return (-1); | ||
| 103 | } | ||
| 104 | |||
| 105 | int | ||
| 106 | a2i_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *bs, char *buf, int size) | ||
| 107 | { | ||
| 108 | int ret = 0; | ||
| 109 | int i, j,k, m,n, again, bufsize; | ||
| 110 | unsigned char *s = NULL, *sp; | ||
| 111 | unsigned char *bufp; | ||
| 112 | int num = 0, slen = 0, first = 1; | ||
| 113 | |||
| 114 | bs->type = V_ASN1_INTEGER; | ||
| 115 | |||
| 116 | bufsize = BIO_gets(bp, buf, size); | ||
| 117 | for (;;) { | ||
| 118 | if (bufsize < 1) | ||
| 119 | goto err_sl; | ||
| 120 | i = bufsize; | ||
| 121 | if (buf[i - 1] == '\n') | ||
| 122 | buf[--i] = '\0'; | ||
| 123 | if (i == 0) | ||
| 124 | goto err_sl; | ||
| 125 | if (buf[i - 1] == '\r') | ||
| 126 | buf[--i] = '\0'; | ||
| 127 | if (i == 0) | ||
| 128 | goto err_sl; | ||
| 129 | if (buf[i - 1] == '\\') { | ||
| 130 | i--; | ||
| 131 | again = 1; | ||
| 132 | } else | ||
| 133 | again = 0; | ||
| 134 | buf[i] = '\0'; | ||
| 135 | if (i < 2) | ||
| 136 | goto err_sl; | ||
| 137 | |||
| 138 | bufp = (unsigned char *)buf; | ||
| 139 | if (first) { | ||
| 140 | first = 0; | ||
| 141 | if ((bufp[0] == '0') && (buf[1] == '0')) { | ||
| 142 | bufp += 2; | ||
| 143 | i -= 2; | ||
| 144 | } | ||
| 145 | } | ||
| 146 | k = 0; | ||
| 147 | if (i % 2 != 0) { | ||
| 148 | ASN1error(ASN1_R_ODD_NUMBER_OF_CHARS); | ||
| 149 | goto err; | ||
| 150 | } | ||
| 151 | i /= 2; | ||
| 152 | if (num + i > slen) { | ||
| 153 | if ((sp = recallocarray(s, slen, num + i, 1)) == NULL) { | ||
| 154 | ASN1error(ERR_R_MALLOC_FAILURE); | ||
| 155 | goto err; | ||
| 156 | } | ||
| 157 | s = sp; | ||
| 158 | slen = num + i; | ||
| 159 | } | ||
| 160 | for (j = 0; j < i; j++, k += 2) { | ||
| 161 | for (n = 0; n < 2; n++) { | ||
| 162 | m = bufp[k + n]; | ||
| 163 | if ((m >= '0') && (m <= '9')) | ||
| 164 | m -= '0'; | ||
| 165 | else if ((m >= 'a') && (m <= 'f')) | ||
| 166 | m = m - 'a' + 10; | ||
| 167 | else if ((m >= 'A') && (m <= 'F')) | ||
| 168 | m = m - 'A' + 10; | ||
| 169 | else { | ||
| 170 | ASN1error(ASN1_R_NON_HEX_CHARACTERS); | ||
| 171 | goto err; | ||
| 172 | } | ||
| 173 | s[num + j] <<= 4; | ||
| 174 | s[num + j] |= m; | ||
| 175 | } | ||
| 176 | } | ||
| 177 | num += i; | ||
| 178 | if (again) | ||
| 179 | bufsize = BIO_gets(bp, buf, size); | ||
| 180 | else | ||
| 181 | break; | ||
| 182 | } | ||
| 183 | bs->length = num; | ||
| 184 | bs->data = s; | ||
| 185 | return (1); | ||
| 186 | |||
| 187 | err_sl: | ||
| 188 | ASN1error(ASN1_R_SHORT_LINE); | ||
| 189 | err: | ||
| 190 | free(s); | ||
| 191 | return (ret); | ||
| 192 | } | ||
diff --git a/src/lib/libcrypto/asn1/t_bitst.c b/src/lib/libcrypto/asn1/t_bitst.c deleted file mode 100644 index 51515b88e2..0000000000 --- a/src/lib/libcrypto/asn1/t_bitst.c +++ /dev/null | |||
| @@ -1,112 +0,0 @@ | |||
| 1 | /* $OpenBSD: t_bitst.c,v 1.8 2018/04/25 11:48:21 tb Exp $ */ | ||
| 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | ||
| 3 | * project 1999. | ||
| 4 | */ | ||
| 5 | /* ==================================================================== | ||
| 6 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. | ||
| 7 | * | ||
| 8 | * Redistribution and use in source and binary forms, with or without | ||
| 9 | * modification, are permitted provided that the following conditions | ||
| 10 | * are met: | ||
| 11 | * | ||
| 12 | * 1. Redistributions of source code must retain the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer. | ||
| 14 | * | ||
| 15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 16 | * notice, this list of conditions and the following disclaimer in | ||
| 17 | * the documentation and/or other materials provided with the | ||
| 18 | * distribution. | ||
| 19 | * | ||
| 20 | * 3. All advertising materials mentioning features or use of this | ||
| 21 | * software must display the following acknowledgment: | ||
| 22 | * "This product includes software developed by the OpenSSL Project | ||
| 23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 24 | * | ||
| 25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 26 | * endorse or promote products derived from this software without | ||
| 27 | * prior written permission. For written permission, please contact | ||
| 28 | * licensing@OpenSSL.org. | ||
| 29 | * | ||
| 30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 31 | * nor may "OpenSSL" appear in their names without prior written | ||
| 32 | * permission of the OpenSSL Project. | ||
| 33 | * | ||
| 34 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 35 | * acknowledgment: | ||
| 36 | * "This product includes software developed by the OpenSSL Project | ||
| 37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 38 | * | ||
| 39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 51 | * ==================================================================== | ||
| 52 | * | ||
| 53 | * This product includes cryptographic software written by Eric Young | ||
| 54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 55 | * Hudson (tjh@cryptsoft.com). | ||
| 56 | * | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include <string.h> | ||
| 61 | |||
| 62 | #include <openssl/conf.h> | ||
| 63 | #include <openssl/x509v3.h> | ||
| 64 | |||
| 65 | int | ||
| 66 | ASN1_BIT_STRING_name_print(BIO *out, ASN1_BIT_STRING *bs, | ||
| 67 | BIT_STRING_BITNAME *tbl, int indent) | ||
| 68 | { | ||
| 69 | BIT_STRING_BITNAME *bnam; | ||
| 70 | char first = 1; | ||
| 71 | |||
| 72 | BIO_printf(out, "%*s", indent, ""); | ||
| 73 | for (bnam = tbl; bnam->lname; bnam++) { | ||
| 74 | if (ASN1_BIT_STRING_get_bit(bs, bnam->bitnum)) { | ||
| 75 | if (!first) | ||
| 76 | BIO_puts(out, ", "); | ||
| 77 | BIO_puts(out, bnam->lname); | ||
| 78 | first = 0; | ||
| 79 | } | ||
| 80 | } | ||
| 81 | BIO_puts(out, "\n"); | ||
| 82 | return 1; | ||
| 83 | } | ||
| 84 | |||
| 85 | int | ||
| 86 | ASN1_BIT_STRING_set_asc(ASN1_BIT_STRING *bs, const char *name, int value, | ||
| 87 | BIT_STRING_BITNAME *tbl) | ||
| 88 | { | ||
| 89 | int bitnum; | ||
| 90 | |||
| 91 | bitnum = ASN1_BIT_STRING_num_asc(name, tbl); | ||
| 92 | if (bitnum < 0) | ||
| 93 | return 0; | ||
| 94 | if (bs) { | ||
| 95 | if (!ASN1_BIT_STRING_set_bit(bs, bitnum, value)) | ||
| 96 | return 0; | ||
| 97 | } | ||
| 98 | return 1; | ||
| 99 | } | ||
| 100 | |||
| 101 | int | ||
| 102 | ASN1_BIT_STRING_num_asc(const char *name, BIT_STRING_BITNAME *tbl) | ||
| 103 | { | ||
| 104 | BIT_STRING_BITNAME *bnam; | ||
| 105 | |||
| 106 | for (bnam = tbl; bnam->lname; bnam++) { | ||
| 107 | if (!strcmp(bnam->sname, name) || | ||
| 108 | !strcmp(bnam->lname, name)) | ||
| 109 | return bnam->bitnum; | ||
| 110 | } | ||
| 111 | return -1; | ||
| 112 | } | ||
