summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/asn1
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/asn1')
-rw-r--r--src/lib/libcrypto/asn1/a_bitstr.c29
-rw-r--r--src/lib/libcrypto/asn1/a_enum.c4
-rw-r--r--src/lib/libcrypto/asn1/a_int.c4
-rw-r--r--src/lib/libcrypto/asn1/a_mbstr.c4
-rw-r--r--src/lib/libcrypto/asn1/a_object.c4
-rw-r--r--src/lib/libcrypto/asn1/a_pkey.c4
-rw-r--r--src/lib/libcrypto/asn1/a_pubkey.c4
-rw-r--r--src/lib/libcrypto/asn1/a_string.c4
-rw-r--r--src/lib/libcrypto/asn1/a_strnid.c3
-rw-r--r--src/lib/libcrypto/asn1/a_time.c3
-rw-r--r--src/lib/libcrypto/asn1/a_time_tm.c6
-rw-r--r--src/lib/libcrypto/asn1/a_type.c10
-rw-r--r--src/lib/libcrypto/asn1/asn1.h9
-rw-r--r--src/lib/libcrypto/asn1/asn1_gen.c4
-rw-r--r--src/lib/libcrypto/asn1/asn1_item.c4
-rw-r--r--src/lib/libcrypto/asn1/asn1_local.h7
-rw-r--r--src/lib/libcrypto/asn1/asn1_old.c4
-rw-r--r--src/lib/libcrypto/asn1/asn1_old_lib.c4
-rw-r--r--src/lib/libcrypto/asn1/asn1t.h824
-rw-r--r--src/lib/libcrypto/asn1/asn_mime.c9
-rw-r--r--src/lib/libcrypto/asn1/asn_moid.c4
-rw-r--r--src/lib/libcrypto/asn1/bio_ndef.c4
-rw-r--r--src/lib/libcrypto/asn1/p5_pbe.c37
-rw-r--r--src/lib/libcrypto/asn1/p5_pbev2.c14
-rw-r--r--src/lib/libcrypto/asn1/p8_pkey.c4
-rw-r--r--src/lib/libcrypto/asn1/t_crl.c4
-rw-r--r--src/lib/libcrypto/asn1/t_req.c4
-rw-r--r--src/lib/libcrypto/asn1/t_x509.c62
-rw-r--r--src/lib/libcrypto/asn1/tasn_dec.c4
-rw-r--r--src/lib/libcrypto/asn1/tasn_enc.c4
-rw-r--r--src/lib/libcrypto/asn1/tasn_fre.c7
-rw-r--r--src/lib/libcrypto/asn1/tasn_new.c4
-rw-r--r--src/lib/libcrypto/asn1/tasn_prn.c5
-rw-r--r--src/lib/libcrypto/asn1/tasn_typ.c5
-rw-r--r--src/lib/libcrypto/asn1/tasn_utl.c4
-rw-r--r--src/lib/libcrypto/asn1/x_crl.c15
-rw-r--r--src/lib/libcrypto/asn1/x_info.c96
-rw-r--r--src/lib/libcrypto/asn1/x_long.c12
-rw-r--r--src/lib/libcrypto/asn1/x_name.c6
-rw-r--r--src/lib/libcrypto/asn1/x_pkey.c123
-rw-r--r--src/lib/libcrypto/asn1/x_pubkey.c20
41 files changed, 655 insertions, 727 deletions
diff --git a/src/lib/libcrypto/asn1/a_bitstr.c b/src/lib/libcrypto/asn1/a_bitstr.c
index d5d00c4d44..e656c43f0c 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.43 2024/07/08 14:52:31 beck Exp $ */ 1/* $OpenBSD: a_bitstr.c,v 1.48 2026/01/04 09:54:23 tb 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 *
@@ -63,10 +63,10 @@
63#include <openssl/asn1.h> 63#include <openssl/asn1.h>
64#include <openssl/asn1t.h> 64#include <openssl/asn1t.h>
65#include <openssl/conf.h> 65#include <openssl/conf.h>
66#include <openssl/err.h>
67#include <openssl/x509v3.h> 66#include <openssl/x509v3.h>
68 67
69#include "bytestring.h" 68#include "bytestring.h"
69#include "err_local.h"
70 70
71const ASN1_ITEM ASN1_BIT_STRING_it = { 71const ASN1_ITEM ASN1_BIT_STRING_it = {
72 .itype = ASN1_ITYPE_PRIMITIVE, 72 .itype = ASN1_ITYPE_PRIMITIVE,
@@ -182,18 +182,9 @@ i2c_ASN1_BIT_STRING(ASN1_BIT_STRING *a, unsigned char **pp)
182 unsigned char *p, *d; 182 unsigned char *p, *d;
183 183
184 if (a == NULL) 184 if (a == NULL)
185 return (0); 185 return 0;
186
187 if (a->length == INT_MAX)
188 return (0);
189
190 ret = a->length + 1;
191
192 if (pp == NULL)
193 return (ret);
194 186
195 len = a->length; 187 len = a->length;
196
197 if (len > 0) { 188 if (len > 0) {
198 if (a->flags & ASN1_STRING_FLAG_BITS_LEFT) { 189 if (a->flags & ASN1_STRING_FLAG_BITS_LEFT) {
199 bits = (int)a->flags & 0x07; 190 bits = (int)a->flags & 0x07;
@@ -222,12 +213,20 @@ i2c_ASN1_BIT_STRING(ASN1_BIT_STRING *a, unsigned char **pp)
222 else if (j & 0x80) 213 else if (j & 0x80)
223 bits = 7; 214 bits = 7;
224 else 215 else
225 bits = 0; /* should not happen */ 216 bits = 0;
226 } 217 }
227 } else 218 } else
228 bits = 0; 219 bits = 0;
229 220
230 p= *pp; 221 if (len > INT_MAX - 1)
222 return 0;
223
224 ret = len + 1;
225
226 if (pp == NULL)
227 return ret;
228
229 p = *pp;
231 230
232 *(p++) = (unsigned char)bits; 231 *(p++) = (unsigned char)bits;
233 d = a->data; 232 d = a->data;
@@ -237,7 +236,7 @@ i2c_ASN1_BIT_STRING(ASN1_BIT_STRING *a, unsigned char **pp)
237 p[-1] &= 0xff << bits; 236 p[-1] &= 0xff << bits;
238 } 237 }
239 *pp = p; 238 *pp = p;
240 return (ret); 239 return ret;
241} 240}
242 241
243int 242int
diff --git a/src/lib/libcrypto/asn1/a_enum.c b/src/lib/libcrypto/asn1/a_enum.c
index 5d3a3dd0c7..ac5033ea8a 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.30 2024/07/08 14:52:31 beck Exp $ */ 1/* $OpenBSD: a_enum.c,v 1.31 2025/05/10 05:54:38 tb 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 *
@@ -63,10 +63,10 @@
63#include <openssl/asn1t.h> 63#include <openssl/asn1t.h>
64#include <openssl/bn.h> 64#include <openssl/bn.h>
65#include <openssl/buffer.h> 65#include <openssl/buffer.h>
66#include <openssl/err.h>
67 66
68#include "asn1_local.h" 67#include "asn1_local.h"
69#include "bytestring.h" 68#include "bytestring.h"
69#include "err_local.h"
70 70
71/* 71/*
72 * Code for ENUMERATED type: identical to INTEGER apart from a different tag. 72 * Code for ENUMERATED type: identical to INTEGER apart from a different tag.
diff --git a/src/lib/libcrypto/asn1/a_int.c b/src/lib/libcrypto/asn1/a_int.c
index 0d9b6577d7..f171e330f6 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.48 2024/07/08 14:52:31 beck Exp $ */ 1/* $OpenBSD: a_int.c,v 1.49 2025/05/10 05:54:38 tb 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 *
@@ -64,9 +64,9 @@
64#include <openssl/asn1t.h> 64#include <openssl/asn1t.h>
65#include <openssl/bn.h> 65#include <openssl/bn.h>
66#include <openssl/buffer.h> 66#include <openssl/buffer.h>
67#include <openssl/err.h>
68 67
69#include "bytestring.h" 68#include "bytestring.h"
69#include "err_local.h"
70 70
71const ASN1_ITEM ASN1_INTEGER_it = { 71const ASN1_ITEM ASN1_INTEGER_it = {
72 .itype = ASN1_ITYPE_PRIMITIVE, 72 .itype = ASN1_ITYPE_PRIMITIVE,
diff --git a/src/lib/libcrypto/asn1/a_mbstr.c b/src/lib/libcrypto/asn1/a_mbstr.c
index f050f97539..38398ad1d1 100644
--- a/src/lib/libcrypto/asn1/a_mbstr.c
+++ b/src/lib/libcrypto/asn1/a_mbstr.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: a_mbstr.c,v 1.27 2023/07/05 21:23:36 beck Exp $ */ 1/* $OpenBSD: a_mbstr.c,v 1.28 2025/05/10 05:54:38 tb Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 1999. 3 * project 1999.
4 */ 4 */
@@ -61,9 +61,9 @@
61#include <string.h> 61#include <string.h>
62 62
63#include <openssl/asn1.h> 63#include <openssl/asn1.h>
64#include <openssl/err.h>
65 64
66#include "asn1_local.h" 65#include "asn1_local.h"
66#include "err_local.h"
67 67
68static int traverse_string(const unsigned char *p, int len, int inform, 68static int traverse_string(const unsigned char *p, int len, int inform,
69 int (*rfunc)(unsigned long value, void *in), void *arg); 69 int (*rfunc)(unsigned long value, void *in), void *arg);
diff --git a/src/lib/libcrypto/asn1/a_object.c b/src/lib/libcrypto/asn1/a_object.c
index 2f3ca1398f..333ac60348 100644
--- a/src/lib/libcrypto/asn1/a_object.c
+++ b/src/lib/libcrypto/asn1/a_object.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: a_object.c,v 1.55 2024/07/08 14:52:31 beck Exp $ */ 1/* $OpenBSD: a_object.c,v 1.56 2025/05/10 05:54:38 tb 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,11 +62,11 @@
62 62
63#include <openssl/asn1.h> 63#include <openssl/asn1.h>
64#include <openssl/asn1t.h> 64#include <openssl/asn1t.h>
65#include <openssl/err.h>
66#include <openssl/buffer.h> 65#include <openssl/buffer.h>
67#include <openssl/objects.h> 66#include <openssl/objects.h>
68 67
69#include "asn1_local.h" 68#include "asn1_local.h"
69#include "err_local.h"
70 70
71const ASN1_ITEM ASN1_OBJECT_it = { 71const ASN1_ITEM ASN1_OBJECT_it = {
72 .itype = ASN1_ITYPE_PRIMITIVE, 72 .itype = ASN1_ITYPE_PRIMITIVE,
diff --git a/src/lib/libcrypto/asn1/a_pkey.c b/src/lib/libcrypto/asn1/a_pkey.c
index a730728076..636b602377 100644
--- a/src/lib/libcrypto/asn1/a_pkey.c
+++ b/src/lib/libcrypto/asn1/a_pkey.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: a_pkey.c,v 1.8 2024/04/09 13:52:41 beck Exp $ */ 1/* $OpenBSD: a_pkey.c,v 1.9 2025/05/10 05:54:38 tb 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,12 +62,12 @@
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/err.h>
66#include <openssl/evp.h> 65#include <openssl/evp.h>
67#include <openssl/objects.h> 66#include <openssl/objects.h>
68#include <openssl/x509.h> 67#include <openssl/x509.h>
69 68
70#include "asn1_local.h" 69#include "asn1_local.h"
70#include "err_local.h"
71#include "evp_local.h" 71#include "evp_local.h"
72 72
73EVP_PKEY * 73EVP_PKEY *
diff --git a/src/lib/libcrypto/asn1/a_pubkey.c b/src/lib/libcrypto/asn1/a_pubkey.c
index 544f3d2cf0..f846b6cda5 100644
--- a/src/lib/libcrypto/asn1/a_pubkey.c
+++ b/src/lib/libcrypto/asn1/a_pubkey.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: a_pubkey.c,v 1.7 2024/04/09 13:52:41 beck Exp $ */ 1/* $OpenBSD: a_pubkey.c,v 1.8 2025/05/10 05:54:38 tb 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,7 +62,6 @@
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/err.h>
66#include <openssl/evp.h> 65#include <openssl/evp.h>
67#include <openssl/objects.h> 66#include <openssl/objects.h>
68 67
@@ -76,6 +75,7 @@
76#include <openssl/rsa.h> 75#include <openssl/rsa.h>
77#endif 76#endif
78 77
78#include "err_local.h"
79#include "evp_local.h" 79#include "evp_local.h"
80 80
81EVP_PKEY * 81EVP_PKEY *
diff --git a/src/lib/libcrypto/asn1/a_string.c b/src/lib/libcrypto/asn1/a_string.c
index ec492e71f0..70e9c95f22 100644
--- a/src/lib/libcrypto/asn1/a_string.c
+++ b/src/lib/libcrypto/asn1/a_string.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: a_string.c,v 1.17 2023/08/15 18:05:15 tb Exp $ */ 1/* $OpenBSD: a_string.c,v 1.18 2025/05/10 05:54:38 tb 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,9 +61,9 @@
61#include <string.h> 61#include <string.h>
62 62
63#include <openssl/asn1.h> 63#include <openssl/asn1.h>
64#include <openssl/err.h>
65 64
66#include "asn1_local.h" 65#include "asn1_local.h"
66#include "err_local.h"
67 67
68ASN1_STRING * 68ASN1_STRING *
69ASN1_STRING_new(void) 69ASN1_STRING_new(void)
diff --git a/src/lib/libcrypto/asn1/a_strnid.c b/src/lib/libcrypto/asn1/a_strnid.c
index 5fa60b9ce7..3519d6725d 100644
--- a/src/lib/libcrypto/asn1/a_strnid.c
+++ b/src/lib/libcrypto/asn1/a_strnid.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: a_strnid.c,v 1.31 2024/03/02 08:54:02 tb Exp $ */ 1/* $OpenBSD: a_strnid.c,v 1.32 2025/05/10 05:54:38 tb Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 1999. 3 * project 1999.
4 */ 4 */
@@ -62,7 +62,6 @@
62#include <string.h> 62#include <string.h>
63 63
64#include <openssl/asn1.h> 64#include <openssl/asn1.h>
65#include <openssl/err.h>
66#include <openssl/objects.h> 65#include <openssl/objects.h>
67 66
68/* 67/*
diff --git a/src/lib/libcrypto/asn1/a_time.c b/src/lib/libcrypto/asn1/a_time.c
index 15ac1af5c4..3deff56eda 100644
--- a/src/lib/libcrypto/asn1/a_time.c
+++ b/src/lib/libcrypto/asn1/a_time.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: a_time.c,v 1.38 2024/07/08 14:52:31 beck Exp $ */ 1/* $OpenBSD: a_time.c,v 1.39 2025/05/10 05:54:38 tb Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved. 3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 * 4 *
@@ -65,7 +65,6 @@
65#include <time.h> 65#include <time.h>
66 66
67#include <openssl/asn1t.h> 67#include <openssl/asn1t.h>
68#include <openssl/err.h>
69 68
70#include "asn1_local.h" 69#include "asn1_local.h"
71 70
diff --git a/src/lib/libcrypto/asn1/a_time_tm.c b/src/lib/libcrypto/asn1/a_time_tm.c
index a1f329be96..dd2893167f 100644
--- a/src/lib/libcrypto/asn1/a_time_tm.c
+++ b/src/lib/libcrypto/asn1/a_time_tm.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: a_time_tm.c,v 1.42 2024/05/03 18:33:27 tb Exp $ */ 1/* $OpenBSD: a_time_tm.c,v 1.43 2025/05/10 05:54:38 tb Exp $ */
2/* 2/*
3 * Copyright (c) 2015 Bob Beck <beck@openbsd.org> 3 * Copyright (c) 2015 Bob Beck <beck@openbsd.org>
4 * 4 *
@@ -22,10 +22,10 @@
22#include <time.h> 22#include <time.h>
23 23
24#include <openssl/asn1t.h> 24#include <openssl/asn1t.h>
25#include <openssl/err.h>
26 25
27#include "bytestring.h"
28#include "asn1_local.h" 26#include "asn1_local.h"
27#include "bytestring.h"
28#include "err_local.h"
29 29
30#define RFC5280 0 30#define RFC5280 0
31#define GENTIME_LENGTH 15 31#define GENTIME_LENGTH 15
diff --git a/src/lib/libcrypto/asn1/a_type.c b/src/lib/libcrypto/asn1/a_type.c
index ef0a76e810..0615de1ccb 100644
--- a/src/lib/libcrypto/asn1/a_type.c
+++ b/src/lib/libcrypto/asn1/a_type.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: a_type.c,v 1.27 2023/07/28 10:00:10 tb Exp $ */ 1/* $OpenBSD: a_type.c,v 1.29 2025/12/05 14:19:27 tb 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 *
@@ -59,10 +59,10 @@
59#include <string.h> 59#include <string.h>
60 60
61#include <openssl/asn1t.h> 61#include <openssl/asn1t.h>
62#include <openssl/err.h>
63#include <openssl/objects.h> 62#include <openssl/objects.h>
64 63
65#include "asn1_local.h" 64#include "asn1_local.h"
65#include "err_local.h"
66 66
67typedef struct { 67typedef struct {
68 ASN1_INTEGER *num; 68 ASN1_INTEGER *num;
@@ -227,14 +227,14 @@ int
227ASN1_TYPE_get_octetstring(const ASN1_TYPE *a, unsigned char *data, int max_len) 227ASN1_TYPE_get_octetstring(const ASN1_TYPE *a, unsigned char *data, int max_len)
228{ 228{
229 int ret, num; 229 int ret, num;
230 unsigned char *p; 230 const unsigned char *p;
231 231
232 if ((a->type != V_ASN1_OCTET_STRING) || 232 if ((a->type != V_ASN1_OCTET_STRING) ||
233 (a->value.octet_string == NULL)) { 233 (a->value.octet_string == NULL)) {
234 ASN1error(ASN1_R_DATA_IS_WRONG); 234 ASN1error(ASN1_R_DATA_IS_WRONG);
235 return (-1); 235 return (-1);
236 } 236 }
237 p = ASN1_STRING_data(a->value.octet_string); 237 p = ASN1_STRING_get0_data(a->value.octet_string);
238 ret = ASN1_STRING_length(a->value.octet_string); 238 ret = ASN1_STRING_length(a->value.octet_string);
239 if (ret < max_len) 239 if (ret < max_len)
240 num = ret; 240 num = ret;
@@ -298,7 +298,7 @@ ASN1_TYPE_get_int_octetstring(const ASN1_TYPE *at, long *num, unsigned char *dat
298 len = ASN1_STRING_length(ios->value); 298 len = ASN1_STRING_length(ios->value);
299 if (len > max_len) 299 if (len > max_len)
300 len = max_len; 300 len = max_len;
301 memcpy(data, ASN1_STRING_data(ios->value), len); 301 memcpy(data, ASN1_STRING_get0_data(ios->value), len);
302 } 302 }
303 303
304 ret = ASN1_STRING_length(ios->value); 304 ret = ASN1_STRING_length(ios->value);
diff --git a/src/lib/libcrypto/asn1/asn1.h b/src/lib/libcrypto/asn1/asn1.h
index aeabbc0a28..2b19f58717 100644
--- a/src/lib/libcrypto/asn1/asn1.h
+++ b/src/lib/libcrypto/asn1/asn1.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: asn1.h,v 1.92 2024/04/10 14:55:12 beck Exp $ */ 1/* $OpenBSD: asn1.h,v 1.95 2026/01/02 08:03:02 tb 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 *
@@ -85,7 +85,6 @@ extern "C" {
85#define V_ASN1_PRIMITIVE_TAG 0x1f 85#define V_ASN1_PRIMITIVE_TAG 0x1f
86#define V_ASN1_PRIMATIVE_TAG 0x1f 86#define V_ASN1_PRIMATIVE_TAG 0x1f
87 87
88#define V_ASN1_APP_CHOOSE -2 /* let the recipient choose */
89#define V_ASN1_OTHER -3 /* used in ASN1_TYPE */ 88#define V_ASN1_OTHER -3 /* used in ASN1_TYPE */
90#define V_ASN1_ANY -4 /* used in ASN1 template code */ 89#define V_ASN1_ANY -4 /* used in ASN1 template code */
91 90
@@ -200,11 +199,9 @@ typedef struct ASN1_ENCODING_st {
200 int modified; /* set to 1 if 'enc' is invalid */ 199 int modified; /* set to 1 if 'enc' is invalid */
201} ASN1_ENCODING; 200} ASN1_ENCODING;
202 201
203/* Used with ASN1 LONG type: if a long is set to this it is omitted */ 202/* Used by security/xca */
204#define ASN1_LONG_UNDEF 0x7fffffffL
205
206#define STABLE_FLAGS_MALLOC 0x01
207#define STABLE_NO_MASK 0x02 203#define STABLE_NO_MASK 0x02
204
208#define DIRSTRING_TYPE \ 205#define DIRSTRING_TYPE \
209 (B_ASN1_PRINTABLESTRING|B_ASN1_T61STRING|B_ASN1_BMPSTRING|B_ASN1_UTF8STRING) 206 (B_ASN1_PRINTABLESTRING|B_ASN1_T61STRING|B_ASN1_BMPSTRING|B_ASN1_UTF8STRING)
210#define PKCS9STRING_TYPE (DIRSTRING_TYPE|B_ASN1_IA5STRING) 207#define PKCS9STRING_TYPE (DIRSTRING_TYPE|B_ASN1_IA5STRING)
diff --git a/src/lib/libcrypto/asn1/asn1_gen.c b/src/lib/libcrypto/asn1/asn1_gen.c
index edd6743993..b409e83c7d 100644
--- a/src/lib/libcrypto/asn1/asn1_gen.c
+++ b/src/lib/libcrypto/asn1/asn1_gen.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: asn1_gen.c,v 1.27 2025/03/06 07:25:01 tb Exp $ */ 1/* $OpenBSD: asn1_gen.c,v 1.28 2025/05/10 05:54:38 tb Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 2002. 3 * project 2002.
4 */ 4 */
@@ -59,11 +59,11 @@
59#include <string.h> 59#include <string.h>
60 60
61#include <openssl/asn1.h> 61#include <openssl/asn1.h>
62#include <openssl/err.h>
63#include <openssl/x509v3.h> 62#include <openssl/x509v3.h>
64 63
65#include "asn1_local.h" 64#include "asn1_local.h"
66#include "conf_local.h" 65#include "conf_local.h"
66#include "err_local.h"
67#include "x509_local.h" 67#include "x509_local.h"
68 68
69#define ASN1_GEN_FLAG 0x10000 69#define ASN1_GEN_FLAG 0x10000
diff --git a/src/lib/libcrypto/asn1/asn1_item.c b/src/lib/libcrypto/asn1/asn1_item.c
index 86c800e3ad..621d65711b 100644
--- a/src/lib/libcrypto/asn1/asn1_item.c
+++ b/src/lib/libcrypto/asn1/asn1_item.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: asn1_item.c,v 1.21 2024/04/09 13:55:02 beck Exp $ */ 1/* $OpenBSD: asn1_item.c,v 1.22 2025/05/10 05:54:38 tb 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 *
@@ -112,11 +112,11 @@
112#include <limits.h> 112#include <limits.h>
113 113
114#include <openssl/buffer.h> 114#include <openssl/buffer.h>
115#include <openssl/err.h>
116#include <openssl/evp.h> 115#include <openssl/evp.h>
117#include <openssl/x509.h> 116#include <openssl/x509.h>
118 117
119#include "asn1_local.h" 118#include "asn1_local.h"
119#include "err_local.h"
120#include "evp_local.h" 120#include "evp_local.h"
121#include "x509_local.h" 121#include "x509_local.h"
122 122
diff --git a/src/lib/libcrypto/asn1/asn1_local.h b/src/lib/libcrypto/asn1/asn1_local.h
index 19de978772..d61cfaa7b9 100644
--- a/src/lib/libcrypto/asn1/asn1_local.h
+++ b/src/lib/libcrypto/asn1/asn1_local.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: asn1_local.h,v 1.10 2024/03/02 09:10:42 tb Exp $ */ 1/* $OpenBSD: asn1_local.h,v 1.11 2025/11/26 10:19:57 tb Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 2006. 3 * project 2006.
4 */ 4 */
@@ -56,6 +56,9 @@
56 * 56 *
57 */ 57 */
58 58
59#ifndef HEADER_ASN1_LOCAL_H
60#define HEADER_ASN1_LOCAL_H
61
59#include "bytestring.h" 62#include "bytestring.h"
60 63
61__BEGIN_HIDDEN_DECLS 64__BEGIN_HIDDEN_DECLS
@@ -191,3 +194,5 @@ int ASN1_time_parse(const char *_bytes, size_t _len, struct tm *_tm, int _mode);
191int ASN1_time_tm_cmp(struct tm *_tm1, struct tm *_tm2); 194int ASN1_time_tm_cmp(struct tm *_tm1, struct tm *_tm2);
192 195
193__END_HIDDEN_DECLS 196__END_HIDDEN_DECLS
197
198#endif /* HEADER_ASN1_LOCAL_H */
diff --git a/src/lib/libcrypto/asn1/asn1_old.c b/src/lib/libcrypto/asn1/asn1_old.c
index 7992fccdef..c47ea8e74a 100644
--- a/src/lib/libcrypto/asn1/asn1_old.c
+++ b/src/lib/libcrypto/asn1/asn1_old.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: asn1_old.c,v 1.6 2024/04/10 14:55:12 beck Exp $ */ 1/* $OpenBSD: asn1_old.c,v 1.7 2025/05/10 05:54:38 tb 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,9 +61,9 @@
61 61
62#include <openssl/asn1.h> 62#include <openssl/asn1.h>
63#include <openssl/buffer.h> 63#include <openssl/buffer.h>
64#include <openssl/err.h>
65 64
66#include "asn1_local.h" 65#include "asn1_local.h"
66#include "err_local.h"
67 67
68#ifndef NO_OLD_ASN1 68#ifndef NO_OLD_ASN1
69 69
diff --git a/src/lib/libcrypto/asn1/asn1_old_lib.c b/src/lib/libcrypto/asn1/asn1_old_lib.c
index 80362ae689..541ac7b615 100644
--- a/src/lib/libcrypto/asn1/asn1_old_lib.c
+++ b/src/lib/libcrypto/asn1/asn1_old_lib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: asn1_old_lib.c,v 1.6 2023/07/05 21:23:36 beck Exp $ */ 1/* $OpenBSD: asn1_old_lib.c,v 1.7 2025/05/10 05:54:38 tb 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,9 +61,9 @@
61#include <string.h> 61#include <string.h>
62 62
63#include <openssl/asn1.h> 63#include <openssl/asn1.h>
64#include <openssl/err.h>
65 64
66#include "asn1_local.h" 65#include "asn1_local.h"
66#include "err_local.h"
67 67
68static void asn1_put_length(unsigned char **pp, int length); 68static void asn1_put_length(unsigned char **pp, int length);
69 69
diff --git a/src/lib/libcrypto/asn1/asn1t.h b/src/lib/libcrypto/asn1/asn1t.h
index 22cde48669..b3fb1cf838 100644
--- a/src/lib/libcrypto/asn1/asn1t.h
+++ b/src/lib/libcrypto/asn1/asn1t.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: asn1t.h,v 1.24 2024/07/08 16:24:22 beck Exp $ */ 1/* $OpenBSD: asn1t.h,v 1.31 2026/01/16 09:25:15 tb Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 2000. 3 * project 2000.
4 */ 4 */
@@ -78,44 +78,43 @@ extern "C" {
78 78
79/* Macros for start and end of ASN1_ITEM definition */ 79/* Macros for start and end of ASN1_ITEM definition */
80 80
81#define ASN1_ITEM_start(itname) \ 81#define ASN1_ITEM_start(itname) \
82 const ASN1_ITEM itname##_it = { 82 const ASN1_ITEM itname##_it = {
83 83
84#define static_ASN1_ITEM_start(itname) \ 84#define static_ASN1_ITEM_start(itname) \
85 static const ASN1_ITEM itname##_it = { 85 static const ASN1_ITEM itname##_it = {
86 86
87#define ASN1_ITEM_end(itname) \ 87#define ASN1_ITEM_end(itname) \
88 }; 88 };
89
90 89
91 90
92/* Macros to aid ASN1 template writing */ 91/* Macros to aid ASN1 template writing */
93 92
94#define ASN1_ITEM_TEMPLATE(tname) \ 93#define ASN1_ITEM_TEMPLATE(tname) \
95 static const ASN1_TEMPLATE tname##_item_tt 94 static const ASN1_TEMPLATE tname##_item_tt
96 95
97#define ASN1_ITEM_TEMPLATE_END(tname) \ 96#define ASN1_ITEM_TEMPLATE_END(tname) \
98 ;\ 97 ; \
99 ASN1_ITEM_start(tname) \ 98 ASN1_ITEM_start(tname) \
100 ASN1_ITYPE_PRIMITIVE,\ 99 .itype = ASN1_ITYPE_PRIMITIVE, \
101 -1,\ 100 .utype = -1, \
102 &tname##_item_tt,\ 101 .templates = &tname##_item_tt, \
103 0,\ 102 .tcount = 0, \
104 NULL,\ 103 .funcs = NULL, \
105 0,\ 104 .size = 0, \
106 #tname \ 105 .sname = #tname, \
107 ASN1_ITEM_end(tname) 106 ASN1_ITEM_end(tname)
108 107
109#define static_ASN1_ITEM_TEMPLATE_END(tname) \ 108#define static_ASN1_ITEM_TEMPLATE_END(tname) \
110 ;\ 109 ; \
111 static_ASN1_ITEM_start(tname) \ 110 static_ASN1_ITEM_start(tname) \
112 ASN1_ITYPE_PRIMITIVE,\ 111 .itype = ASN1_ITYPE_PRIMITIVE, \
113 -1,\ 112 .utype = -1, \
114 &tname##_item_tt,\ 113 .templates = &tname##_item_tt, \
115 0,\ 114 .tcount = 0, \
116 NULL,\ 115 .funcs = NULL, \
117 0,\ 116 .size = 0, \
118 #tname \ 117 .sname = #tname, \
119 ASN1_ITEM_end(tname) 118 ASN1_ITEM_end(tname)
120 119
121 120
@@ -142,119 +141,145 @@ extern "C" {
142 * a structure called stname. 141 * a structure called stname.
143 */ 142 */
144 143
145#define ASN1_SEQUENCE(tname) \ 144#define ASN1_SEQUENCE(tname) \
146 static const ASN1_TEMPLATE tname##_seq_tt[] 145 static const ASN1_TEMPLATE tname##_seq_tt[]
147 146
148#define ASN1_SEQUENCE_END(stname) ASN1_SEQUENCE_END_name(stname, stname) 147#define ASN1_SEQUENCE_END(stname) \
149 148 ASN1_SEQUENCE_END_name(stname, stname)
150#define static_ASN1_SEQUENCE_END(stname) static_ASN1_SEQUENCE_END_name(stname, stname) 149
151 150#define static_ASN1_SEQUENCE_END(stname) \
152#define ASN1_SEQUENCE_END_name(stname, tname) \ 151 static_ASN1_SEQUENCE_END_name(stname, stname)
153 ;\ 152
154 ASN1_ITEM_start(tname) \ 153#define ASN1_SEQUENCE_END_name(stname, tname) \
155 ASN1_ITYPE_SEQUENCE,\ 154 ; \
156 V_ASN1_SEQUENCE,\ 155 ASN1_ITEM_start(tname) \
157 tname##_seq_tt,\ 156 .itype = ASN1_ITYPE_SEQUENCE, \
158 sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE),\ 157 .utype = V_ASN1_SEQUENCE, \
159 NULL,\ 158 .templates = tname##_seq_tt, \
160 sizeof(stname),\ 159 .tcount = sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE),\
161 #stname \ 160 .funcs = NULL, \
161 .size = sizeof(stname), \
162 .sname = #stname, \
162 ASN1_ITEM_end(tname) 163 ASN1_ITEM_end(tname)
163 164
164#define static_ASN1_SEQUENCE_END_name(stname, tname) \ 165#define static_ASN1_SEQUENCE_END_name(stname, tname) \
165 ;\ 166 ; \
166 static_ASN1_ITEM_start(tname) \ 167 static_ASN1_ITEM_start(tname) \
167 ASN1_ITYPE_SEQUENCE,\ 168 .itype = ASN1_ITYPE_SEQUENCE, \
168 V_ASN1_SEQUENCE,\ 169 .utype = V_ASN1_SEQUENCE, \
169 tname##_seq_tt,\ 170 .templates = tname##_seq_tt, \
170 sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE),\ 171 .tcount = sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE),\
171 NULL,\ 172 .funcs = NULL, \
172 sizeof(stname),\ 173 .size = sizeof(stname), \
173 #stname \ 174 .sname = #stname, \
174 ASN1_ITEM_end(tname) 175 ASN1_ITEM_end(tname)
175 176
176#define ASN1_NDEF_SEQUENCE(tname) \ 177#define ASN1_NDEF_SEQUENCE(tname) \
177 ASN1_SEQUENCE(tname) 178 ASN1_SEQUENCE(tname)
178 179
179#define ASN1_NDEF_SEQUENCE_cb(tname, cb) \ 180#define ASN1_NDEF_SEQUENCE_cb(tname, cb) \
180 ASN1_SEQUENCE_cb(tname, cb) 181 ASN1_SEQUENCE_cb(tname, cb)
181 182
182#define ASN1_SEQUENCE_cb(tname, cb) \ 183#define ASN1_SEQUENCE_cb(tname, cb) \
183 static const ASN1_AUX tname##_aux = {NULL, 0, 0, 0, cb, 0}; \ 184 static const ASN1_AUX tname##_aux = { \
185 .app_data = NULL, \
186 .flags = 0, \
187 .ref_offset = 0, \
188 .ref_lock = 0, \
189 .asn1_cb = cb, \
190 .enc_offset = 0, \
191 }; \
184 ASN1_SEQUENCE(tname) 192 ASN1_SEQUENCE(tname)
185 193
186#define ASN1_SEQUENCE_ref(tname, cb, lck) \ 194#define ASN1_SEQUENCE_ref(tname, cb, lck) \
187 static const ASN1_AUX tname##_aux = {NULL, ASN1_AFLG_REFCOUNT, offsetof(tname, references), lck, cb, 0}; \ 195 static const ASN1_AUX tname##_aux = { \
196 .app_data = NULL, \
197 .flags = ASN1_AFLG_REFCOUNT, \
198 .ref_offset = offsetof(tname, references), \
199 .ref_lock = lck, \
200 .asn1_cb = cb, \
201 .enc_offset = 0, \
202 }; \
188 ASN1_SEQUENCE(tname) 203 ASN1_SEQUENCE(tname)
189 204
190#define ASN1_SEQUENCE_enc(tname, enc, cb) \ 205#define ASN1_SEQUENCE_enc(tname, enc, cb) \
191 static const ASN1_AUX tname##_aux = {NULL, ASN1_AFLG_ENCODING, 0, 0, cb, offsetof(tname, enc)}; \ 206 static const ASN1_AUX tname##_aux = { \
207 .app_data = NULL, \
208 .flags = ASN1_AFLG_ENCODING, \
209 .ref_offset = 0, \
210 .ref_lock = 0, \
211 .asn1_cb = cb, \
212 .enc_offset = offsetof(tname, enc), \
213 }; \
192 ASN1_SEQUENCE(tname) 214 ASN1_SEQUENCE(tname)
193 215
194#define ASN1_NDEF_SEQUENCE_END(tname) \ 216#define ASN1_NDEF_SEQUENCE_END(tname) \
195 ;\ 217 ; \
196 ASN1_ITEM_start(tname) \ 218 ASN1_ITEM_start(tname) \
197 ASN1_ITYPE_NDEF_SEQUENCE,\ 219 .itype = ASN1_ITYPE_NDEF_SEQUENCE, \
198 V_ASN1_SEQUENCE,\ 220 .utype = V_ASN1_SEQUENCE, \
199 tname##_seq_tt,\ 221 .templates = tname##_seq_tt, \
200 sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE),\ 222 .tcount = sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE),\
201 NULL,\ 223 .funcs = NULL, \
202 sizeof(tname),\ 224 .size = sizeof(tname), \
203 #tname \ 225 .sname = #tname, \
204 ASN1_ITEM_end(tname) 226 ASN1_ITEM_end(tname)
205 227
206#define static_ASN1_NDEF_SEQUENCE_END(tname) \ 228#define static_ASN1_NDEF_SEQUENCE_END(tname) \
207 ;\ 229 ; \
208 static_ASN1_ITEM_start(tname) \ 230 static_ASN1_ITEM_start(tname) \
209 ASN1_ITYPE_NDEF_SEQUENCE,\ 231 .itype = ASN1_ITYPE_NDEF_SEQUENCE, \
210 V_ASN1_SEQUENCE,\ 232 .utype = V_ASN1_SEQUENCE, \
211 tname##_seq_tt,\ 233 .templates = tname##_seq_tt, \
212 sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE),\ 234 .tcount = sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE),\
213 NULL,\ 235 .funcs = NULL, \
214 sizeof(tname),\ 236 .size = sizeof(tname), \
215 #tname \ 237 .sname = #tname, \
216 ASN1_ITEM_end(tname) 238 ASN1_ITEM_end(tname)
217 239
218#define ASN1_SEQUENCE_END_enc(stname, tname) ASN1_SEQUENCE_END_ref(stname, tname) 240#define ASN1_SEQUENCE_END_enc(stname, tname) \
219 241 ASN1_SEQUENCE_END_ref(stname, tname)
220#define ASN1_SEQUENCE_END_cb(stname, tname) ASN1_SEQUENCE_END_ref(stname, tname) 242
221 243#define ASN1_SEQUENCE_END_cb(stname, tname) \
222#define static_ASN1_SEQUENCE_END_cb(stname, tname) static_ASN1_SEQUENCE_END_ref(stname, tname) 244 ASN1_SEQUENCE_END_ref(stname, tname)
223 245
224#define ASN1_SEQUENCE_END_ref(stname, tname) \ 246#define static_ASN1_SEQUENCE_END_cb(stname, tname) \
225 ;\ 247 static_ASN1_SEQUENCE_END_ref(stname, tname)
226 ASN1_ITEM_start(tname) \ 248
227 ASN1_ITYPE_SEQUENCE,\ 249#define ASN1_SEQUENCE_END_ref(stname, tname) \
228 V_ASN1_SEQUENCE,\ 250 ; \
229 tname##_seq_tt,\ 251 ASN1_ITEM_start(tname) \
230 sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE),\ 252 .itype = ASN1_ITYPE_SEQUENCE, \
231 &tname##_aux,\ 253 .utype = V_ASN1_SEQUENCE, \
232 sizeof(stname),\ 254 .templates = tname##_seq_tt, \
233 #stname \ 255 .tcount = sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE),\
256 .funcs = &tname##_aux, \
257 .size = sizeof(stname), \
258 .sname = #stname, \
234 ASN1_ITEM_end(tname) 259 ASN1_ITEM_end(tname)
235 260
236#define static_ASN1_SEQUENCE_END_ref(stname, tname) \ 261#define static_ASN1_SEQUENCE_END_ref(stname, tname) \
237 ;\ 262 ; \
238 static_ASN1_ITEM_start(tname) \ 263 static_ASN1_ITEM_start(tname) \
239 ASN1_ITYPE_SEQUENCE,\ 264 .itype = ASN1_ITYPE_SEQUENCE, \
240 V_ASN1_SEQUENCE,\ 265 .utype = V_ASN1_SEQUENCE, \
241 tname##_seq_tt,\ 266 .templates = tname##_seq_tt, \
242 sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE),\ 267 .tcount = sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE),\
243 &tname##_aux,\ 268 .funcs = &tname##_aux, \
244 sizeof(stname),\ 269 .size = sizeof(stname), \
245 #stname \ 270 .sname = #stname, \
246 ASN1_ITEM_end(tname) 271 ASN1_ITEM_end(tname)
247 272
248#define ASN1_NDEF_SEQUENCE_END_cb(stname, tname) \ 273#define ASN1_NDEF_SEQUENCE_END_cb(stname, tname) \
249 ;\ 274 ; \
250 ASN1_ITEM_start(tname) \ 275 ASN1_ITEM_start(tname) \
251 ASN1_ITYPE_NDEF_SEQUENCE,\ 276 .itype = ASN1_ITYPE_NDEF_SEQUENCE, \
252 V_ASN1_SEQUENCE,\ 277 .utype = V_ASN1_SEQUENCE, \
253 tname##_seq_tt,\ 278 .templates = tname##_seq_tt, \
254 sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE),\ 279 .tcount = sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE),\
255 &tname##_aux,\ 280 .funcs = &tname##_aux, \
256 sizeof(stname),\ 281 .size = sizeof(stname), \
257 #stname \ 282 .sname = #stname, \
258 ASN1_ITEM_end(tname) 283 ASN1_ITEM_end(tname)
259 284
260 285
@@ -281,170 +306,214 @@ extern "C" {
281 * ASN1_CHOICE_END_selector() version. 306 * ASN1_CHOICE_END_selector() version.
282 */ 307 */
283 308
284#define ASN1_CHOICE(tname) \ 309#define ASN1_CHOICE(tname) \
285 static const ASN1_TEMPLATE tname##_ch_tt[] 310 static const ASN1_TEMPLATE tname##_ch_tt[]
286 311
287#define ASN1_CHOICE_cb(tname, cb) \ 312#define ASN1_CHOICE_cb(tname, cb) \
288 static const ASN1_AUX tname##_aux = {NULL, 0, 0, 0, cb, 0}; \ 313 static const ASN1_AUX tname##_aux = { \
314 .app_data = NULL, \
315 .flags = 0, \
316 .ref_offset = 0, \
317 .ref_lock = 0, \
318 .asn1_cb = cb, \
319 .enc_offset = 0, \
320 }; \
289 ASN1_CHOICE(tname) 321 ASN1_CHOICE(tname)
290 322
291#define ASN1_CHOICE_END(stname) ASN1_CHOICE_END_name(stname, stname) 323#define ASN1_CHOICE_END(stname) \
324 ASN1_CHOICE_END_name(stname, stname)
292 325
293#define static_ASN1_CHOICE_END(stname) static_ASN1_CHOICE_END_name(stname, stname) 326#define static_ASN1_CHOICE_END(stname) \
327 static_ASN1_CHOICE_END_name(stname, stname)
294 328
295#define ASN1_CHOICE_END_name(stname, tname) ASN1_CHOICE_END_selector(stname, tname, type) 329#define ASN1_CHOICE_END_name(stname, tname) \
330 ASN1_CHOICE_END_selector(stname, tname, type)
296 331
297#define static_ASN1_CHOICE_END_name(stname, tname) static_ASN1_CHOICE_END_selector(stname, tname, type) 332#define static_ASN1_CHOICE_END_name(stname, tname) \
333 static_ASN1_CHOICE_END_selector(stname, tname, type)
298 334
299#define ASN1_CHOICE_END_selector(stname, tname, selname) \ 335#define ASN1_CHOICE_END_selector(stname, tname, selname) \
300 ;\ 336 ; \
301 ASN1_ITEM_start(tname) \ 337 ASN1_ITEM_start(tname) \
302 ASN1_ITYPE_CHOICE,\ 338 .itype = ASN1_ITYPE_CHOICE, \
303 offsetof(stname,selname) ,\ 339 .utype = offsetof(stname, selname), \
304 tname##_ch_tt,\ 340 .templates = tname##_ch_tt, \
305 sizeof(tname##_ch_tt) / sizeof(ASN1_TEMPLATE),\ 341 .tcount = sizeof(tname##_ch_tt) / sizeof(ASN1_TEMPLATE),\
306 NULL,\ 342 .funcs = NULL, \
307 sizeof(stname),\ 343 .size = sizeof(stname), \
308 #stname \ 344 .sname = #stname, \
309 ASN1_ITEM_end(tname) 345 ASN1_ITEM_end(tname)
310 346
311#define static_ASN1_CHOICE_END_selector(stname, tname, selname) \ 347#define static_ASN1_CHOICE_END_selector(stname, tname, selname) \
312 ;\ 348 ; \
313 static_ASN1_ITEM_start(tname) \ 349 static_ASN1_ITEM_start(tname) \
314 ASN1_ITYPE_CHOICE,\ 350 .itype = ASN1_ITYPE_CHOICE, \
315 offsetof(stname,selname) ,\ 351 .utype = offsetof(stname, selname), \
316 tname##_ch_tt,\ 352 .templates = tname##_ch_tt, \
317 sizeof(tname##_ch_tt) / sizeof(ASN1_TEMPLATE),\ 353 .tcount = sizeof(tname##_ch_tt) / sizeof(ASN1_TEMPLATE),\
318 NULL,\ 354 .funcs = NULL, \
319 sizeof(stname),\ 355 .size = sizeof(stname), \
320 #stname \ 356 .sname = #stname, \
321 ASN1_ITEM_end(tname) 357 ASN1_ITEM_end(tname)
322 358
323#define ASN1_CHOICE_END_cb(stname, tname, selname) \ 359#define ASN1_CHOICE_END_cb(stname, tname, selname) \
324 ;\ 360 ; \
325 ASN1_ITEM_start(tname) \ 361 ASN1_ITEM_start(tname) \
326 ASN1_ITYPE_CHOICE,\ 362 .itype = ASN1_ITYPE_CHOICE, \
327 offsetof(stname,selname) ,\ 363 .utype = offsetof(stname, selname), \
328 tname##_ch_tt,\ 364 .templates = tname##_ch_tt, \
329 sizeof(tname##_ch_tt) / sizeof(ASN1_TEMPLATE),\ 365 .tcount = sizeof(tname##_ch_tt) / sizeof(ASN1_TEMPLATE),\
330 &tname##_aux,\ 366 .funcs = &tname##_aux, \
331 sizeof(stname),\ 367 .size = sizeof(stname), \
332 #stname \ 368 .sname = #stname, \
333 ASN1_ITEM_end(tname) 369 ASN1_ITEM_end(tname)
334 370
335/* This helps with the template wrapper form of ASN1_ITEM */ 371/* This helps with the template wrapper form of ASN1_ITEM */
336 372
337#define ASN1_EX_TEMPLATE_TYPE(flags, tag, name, type) { \ 373#define ASN1_EX_TEMPLATE_TYPE(flagsval, tagval, name, type) \
338 (flags), (tag), 0,\ 374 { \
339 #name, ASN1_ITEM_ref(type) } 375 .flags = (flagsval), \
376 .tag = (tagval), \
377 .offset = 0, \
378 .field_name = #name, \
379 .item = ASN1_ITEM_ref(type), \
380 }
340 381
341/* These help with SEQUENCE or CHOICE components */ 382/* These help with SEQUENCE or CHOICE components */
342 383
343/* used to declare other types */ 384/* used to declare other types */
344 385
345#define ASN1_EX_TYPE(flags, tag, stname, field, type) { \ 386#define ASN1_EX_TYPE(flagsval, tagval, stname, field, type) \
346 (flags), (tag), offsetof(stname, field),\ 387 { \
347 #field, ASN1_ITEM_ref(type) } 388 .flags = (flagsval), \
389 .tag = (tagval), \
390 .offset = offsetof(stname, field), \
391 .field_name = #field, \
392 .item = ASN1_ITEM_ref(type), \
393 }
348 394
349/* implicit and explicit helper macros */ 395/* implicit and explicit helper macros */
350 396
351#define ASN1_IMP_EX(stname, field, type, tag, ex) \ 397#define ASN1_IMP_EX(stname, field, type, tag, ex) \
352 ASN1_EX_TYPE(ASN1_TFLG_IMPLICIT | ex, tag, stname, field, type) 398 ASN1_EX_TYPE(ASN1_TFLG_IMPLICIT | ex, tag, stname, field, type)
353 399
354#define ASN1_EXP_EX(stname, field, type, tag, ex) \ 400#define ASN1_EXP_EX(stname, field, type, tag, ex) \
355 ASN1_EX_TYPE(ASN1_TFLG_EXPLICIT | ex, tag, stname, field, type) 401 ASN1_EX_TYPE(ASN1_TFLG_EXPLICIT | ex, tag, stname, field, type)
356 402
357/* Any defined by macros: the field used is in the table itself */ 403/* Any defined by macros: the field used is in the table itself */
358 404
359#define ASN1_ADB_OBJECT(tblname) { ASN1_TFLG_ADB_OID, -1, 0, #tblname, (const ASN1_ITEM *)&(tblname##_adb) } 405#define ASN1_ADB_OBJECT(tblname) \
360#define ASN1_ADB_INTEGER(tblname) { ASN1_TFLG_ADB_INT, -1, 0, #tblname, (const ASN1_ITEM *)&(tblname##_adb) } 406 { \
407 .flags = ASN1_TFLG_ADB_OID, \
408 .tag = -1, \
409 .offset = 0, \
410 .field_name = #tblname, \
411 .item = (const ASN1_ITEM *)&(tblname##_adb), \
412 }
413#define ASN1_ADB_INTEGER(tblname) \
414 { \
415 .flags = ASN1_TFLG_ADB_INT, \
416 .tag = -1, \
417 .offset = 0, \
418 .field_name = #tblname, \
419 .item = (const ASN1_ITEM *)&(tblname##_adb), \
420 }
421
361/* Plain simple type */ 422/* Plain simple type */
362#define ASN1_SIMPLE(stname, field, type) ASN1_EX_TYPE(0,0, stname, field, type) 423#define ASN1_SIMPLE(stname, field, type) \
424 ASN1_EX_TYPE(0, 0, stname, field, type)
363 425
364/* OPTIONAL simple type */ 426/* OPTIONAL simple type */
365#define ASN1_OPT(stname, field, type) ASN1_EX_TYPE(ASN1_TFLG_OPTIONAL, 0, stname, field, type) 427#define ASN1_OPT(stname, field, type) \
428 ASN1_EX_TYPE(ASN1_TFLG_OPTIONAL, 0, stname, field, type)
366 429
367/* IMPLICIT tagged simple type */ 430/* IMPLICIT tagged simple type */
368#define ASN1_IMP(stname, field, type, tag) ASN1_IMP_EX(stname, field, type, tag, 0) 431#define ASN1_IMP(stname, field, type, tag) \
432 ASN1_IMP_EX(stname, field, type, tag, 0)
369 433
370/* IMPLICIT tagged OPTIONAL simple type */ 434/* IMPLICIT tagged OPTIONAL simple type */
371#define ASN1_IMP_OPT(stname, field, type, tag) ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_OPTIONAL) 435#define ASN1_IMP_OPT(stname, field, type, tag) \
436 ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_OPTIONAL)
372 437
373/* Same as above but EXPLICIT */ 438/* Same as above but EXPLICIT */
374 439
375#define ASN1_EXP(stname, field, type, tag) ASN1_EXP_EX(stname, field, type, tag, 0) 440#define ASN1_EXP(stname, field, type, tag) \
376#define ASN1_EXP_OPT(stname, field, type, tag) ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_OPTIONAL) 441 ASN1_EXP_EX(stname, field, type, tag, 0)
442#define ASN1_EXP_OPT(stname, field, type, tag) \
443 ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_OPTIONAL)
377 444
378/* SEQUENCE OF type */ 445/* SEQUENCE OF type */
379#define ASN1_SEQUENCE_OF(stname, field, type) \ 446#define ASN1_SEQUENCE_OF(stname, field, type) \
380 ASN1_EX_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, stname, field, type) 447 ASN1_EX_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, stname, field, type)
381 448
382/* OPTIONAL SEQUENCE OF */ 449/* OPTIONAL SEQUENCE OF */
383#define ASN1_SEQUENCE_OF_OPT(stname, field, type) \ 450#define ASN1_SEQUENCE_OF_OPT(stname, field, type) \
384 ASN1_EX_TYPE(ASN1_TFLG_SEQUENCE_OF|ASN1_TFLG_OPTIONAL, 0, stname, field, type) 451 ASN1_EX_TYPE(ASN1_TFLG_SEQUENCE_OF|ASN1_TFLG_OPTIONAL, 0, stname, field, type)
385 452
386/* Same as above but for SET OF */ 453/* Same as above but for SET OF */
387 454
388#define ASN1_SET_OF(stname, field, type) \ 455#define ASN1_SET_OF(stname, field, type) \
389 ASN1_EX_TYPE(ASN1_TFLG_SET_OF, 0, stname, field, type) 456 ASN1_EX_TYPE(ASN1_TFLG_SET_OF, 0, stname, field, type)
390 457
391#define ASN1_SET_OF_OPT(stname, field, type) \ 458#define ASN1_SET_OF_OPT(stname, field, type) \
392 ASN1_EX_TYPE(ASN1_TFLG_SET_OF|ASN1_TFLG_OPTIONAL, 0, stname, field, type) 459 ASN1_EX_TYPE(ASN1_TFLG_SET_OF|ASN1_TFLG_OPTIONAL, 0, stname, field, type)
393 460
394/* Finally compound types of SEQUENCE, SET, IMPLICIT, EXPLICIT and OPTIONAL */ 461/* Finally compound types of SEQUENCE, SET, IMPLICIT, EXPLICIT and OPTIONAL */
395 462
396#define ASN1_IMP_SET_OF(stname, field, type, tag) \ 463#define ASN1_IMP_SET_OF(stname, field, type, tag) \
397 ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_SET_OF) 464 ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_SET_OF)
398 465
399#define ASN1_EXP_SET_OF(stname, field, type, tag) \ 466#define ASN1_EXP_SET_OF(stname, field, type, tag) \
400 ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_SET_OF) 467 ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_SET_OF)
401 468
402#define ASN1_IMP_SET_OF_OPT(stname, field, type, tag) \ 469#define ASN1_IMP_SET_OF_OPT(stname, field, type, tag) \
403 ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_SET_OF|ASN1_TFLG_OPTIONAL) 470 ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_SET_OF|ASN1_TFLG_OPTIONAL)
404 471
405#define ASN1_EXP_SET_OF_OPT(stname, field, type, tag) \ 472#define ASN1_EXP_SET_OF_OPT(stname, field, type, tag) \
406 ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_SET_OF|ASN1_TFLG_OPTIONAL) 473 ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_SET_OF|ASN1_TFLG_OPTIONAL)
407 474
408#define ASN1_IMP_SEQUENCE_OF(stname, field, type, tag) \ 475#define ASN1_IMP_SEQUENCE_OF(stname, field, type, tag) \
409 ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_SEQUENCE_OF) 476 ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_SEQUENCE_OF)
410 477
411#define ASN1_IMP_SEQUENCE_OF_OPT(stname, field, type, tag) \ 478#define ASN1_IMP_SEQUENCE_OF_OPT(stname, field, type, tag) \
412 ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_SEQUENCE_OF|ASN1_TFLG_OPTIONAL) 479 ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_SEQUENCE_OF|ASN1_TFLG_OPTIONAL)
413 480
414#define ASN1_EXP_SEQUENCE_OF(stname, field, type, tag) \ 481#define ASN1_EXP_SEQUENCE_OF(stname, field, type, tag) \
415 ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_SEQUENCE_OF) 482 ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_SEQUENCE_OF)
416 483
417#define ASN1_EXP_SEQUENCE_OF_OPT(stname, field, type, tag) \ 484#define ASN1_EXP_SEQUENCE_OF_OPT(stname, field, type, tag) \
418 ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_SEQUENCE_OF|ASN1_TFLG_OPTIONAL) 485 ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_SEQUENCE_OF|ASN1_TFLG_OPTIONAL)
419 486
420/* EXPLICIT using indefinite length constructed form */ 487/* EXPLICIT using indefinite length constructed form */
421#define ASN1_NDEF_EXP(stname, field, type, tag) \ 488#define ASN1_NDEF_EXP(stname, field, type, tag) \
422 ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_NDEF) 489 ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_NDEF)
423 490
424/* EXPLICIT OPTIONAL using indefinite length constructed form */ 491/* EXPLICIT OPTIONAL using indefinite length constructed form */
425#define ASN1_NDEF_EXP_OPT(stname, field, type, tag) \ 492#define ASN1_NDEF_EXP_OPT(stname, field, type, tag) \
426 ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_OPTIONAL|ASN1_TFLG_NDEF) 493 ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_OPTIONAL|ASN1_TFLG_NDEF)
427 494
428/* Macros for the ASN1_ADB structure */ 495/* Macros for the ASN1_ADB structure */
429 496
430#define ASN1_ADB(name) \ 497#define ASN1_ADB(name) \
431 static const ASN1_ADB_TABLE name##_adbtbl[] 498 static const ASN1_ADB_TABLE name##_adbtbl[]
432 499
433 500/* In 5b70372d OpenSSL added adb_cb. Ignore this until someone complains. */
434#define ASN1_ADB_END(name, flags, field, app_table, def, none) \ 501#define ASN1_ADB_END(name, flagsval, field, adb_cb, def, none) \
435 ;\ 502 ; \
436 static const ASN1_ADB name##_adb = {\ 503 static const ASN1_ADB name##_adb = { \
437 flags,\ 504 .flags = flagsval, \
438 offsetof(name, field),\ 505 .offset = offsetof(name, field), \
439 app_table,\ 506 .tbl = name##_adbtbl, \
440 name##_adbtbl,\ 507 .tblcount = sizeof(name##_adbtbl) / sizeof(ASN1_ADB_TABLE),\
441 sizeof(name##_adbtbl) / sizeof(ASN1_ADB_TABLE),\ 508 .default_tt = def, \
442 def,\ 509 .null_tt = none, \
443 none\
444 } 510 }
445 511
446 512#define ADB_ENTRY(val, template) \
447#define ADB_ENTRY(val, template) {val, template} 513 { \
514 .value = val, \
515 .tt = template, \
516 }
448 517
449#define ASN1_ADB_TEMPLATE(name) \ 518#define ASN1_ADB_TEMPLATE(name) \
450 static const ASN1_TEMPLATE name##_tt 519 static const ASN1_TEMPLATE name##_tt
@@ -474,16 +543,16 @@ typedef struct ASN1_ADB_TABLE_st ASN1_ADB_TABLE;
474typedef struct ASN1_ADB_st ASN1_ADB; 543typedef struct ASN1_ADB_st ASN1_ADB;
475 544
476struct ASN1_ADB_st { 545struct ASN1_ADB_st {
477 unsigned long flags; /* Various flags */ 546 unsigned long flags; /* Various flags */
478 unsigned long offset; /* Offset of selector field */ 547 unsigned long offset; /* Offset of selector field */
479 const ASN1_ADB_TABLE *tbl; /* Table of possible types */ 548 const ASN1_ADB_TABLE *tbl; /* Table of possible types */
480 long tblcount; /* Number of entries in tbl */ 549 long tblcount; /* Number of entries in tbl */
481 const ASN1_TEMPLATE *default_tt; /* Type to use if no match */ 550 const ASN1_TEMPLATE *default_tt; /* Type to use if no match */
482 const ASN1_TEMPLATE *null_tt; /* Type to use if selector is NULL */ 551 const ASN1_TEMPLATE *null_tt; /* Type to use if selector is NULL */
483}; 552};
484 553
485struct ASN1_ADB_TABLE_st { 554struct ASN1_ADB_TABLE_st {
486 long value; /* NID for an object or value for an int */ 555 long value; /* NID for an object or value for an int */
487 const ASN1_TEMPLATE tt; /* item for this value */ 556 const ASN1_TEMPLATE tt; /* item for this value */
488}; 557};
489 558
@@ -498,9 +567,9 @@ struct ASN1_ADB_TABLE_st {
498/* Field is a SEQUENCE OF */ 567/* Field is a SEQUENCE OF */
499#define ASN1_TFLG_SEQUENCE_OF (0x2 << 1) 568#define ASN1_TFLG_SEQUENCE_OF (0x2 << 1)
500 569
501/* Special case: this refers to a SET OF that 570/*
502 * will be sorted into DER order when encoded *and* 571 * Special case: this refers to a SET OF that will be sorted into DER order
503 * the corresponding STACK will be modified to match 572 * when encoded *and* the corresponding STACK will be modified to match
504 * the new order. 573 * the new order.
505 */ 574 */
506#define ASN1_TFLG_SET_ORDER (0x3 << 1) 575#define ASN1_TFLG_SET_ORDER (0x3 << 1)
@@ -508,9 +577,9 @@ struct ASN1_ADB_TABLE_st {
508/* Mask for SET OF or SEQUENCE OF */ 577/* Mask for SET OF or SEQUENCE OF */
509#define ASN1_TFLG_SK_MASK (0x3 << 1) 578#define ASN1_TFLG_SK_MASK (0x3 << 1)
510 579
511/* These flags mean the tag should be taken from the 580/*
512 * tag field. If EXPLICIT then the underlying type 581 * These flags mean the tag should be taken from the tag field. If EXPLICIT
513 * is used for the inner tag. 582 * then the underlying type is used for the inner tag.
514 */ 583 */
515 584
516/* IMPLICIT tagging */ 585/* IMPLICIT tagging */
@@ -529,7 +598,7 @@ struct ASN1_ADB_TABLE_st {
529#define ASN1_TFLG_EXPLICIT ASN1_TFLG_EXPTAG|ASN1_TFLG_CONTEXT 598#define ASN1_TFLG_EXPLICIT ASN1_TFLG_EXPTAG|ASN1_TFLG_CONTEXT
530 599
531/* 600/*
532 * If tagging is in force these determine the type of tag to use. Otherwiser 601 * If tagging is in force these determine the type of tag to use. Otherwise
533 * the tag is determined by the underlying type. These values reflect the 602 * the tag is determined by the underlying type. These values reflect the
534 * actual octet format. 603 * actual octet format.
535 */ 604 */
@@ -546,10 +615,9 @@ struct ASN1_ADB_TABLE_st {
546#define ASN1_TFLG_TAG_CLASS (0x3<<6) 615#define ASN1_TFLG_TAG_CLASS (0x3<<6)
547 616
548/* 617/*
549 * These are for ANY DEFINED BY type. In this case 618 * These are for ANY DEFINED BY type. In this case the 'item' field points
550 * the 'item' field points to an ASN1_ADB structure 619 * to an ASN1_ADB structure which contains a table of values to decode the
551 * which contains a table of values to decode the 620 * relevant type.
552 * relevant type
553 */ 621 */
554 622
555#define ASN1_TFLG_ADB_MASK (0x3<<8) 623#define ASN1_TFLG_ADB_MASK (0x3<<8)
@@ -559,9 +627,8 @@ struct ASN1_ADB_TABLE_st {
559#define ASN1_TFLG_ADB_INT (0x1<<9) 627#define ASN1_TFLG_ADB_INT (0x1<<9)
560 628
561/* 629/*
562 * This flag when present in a SEQUENCE OF, SET OF 630 * This flag when present in a SEQUENCE OF, SET OF or EXPLICIT causes
563 * or EXPLICIT causes indefinite length constructed 631 * indefinite length constructed encoding to be used if required.
564 * encoding to be used if required.
565 */ 632 */
566 633
567#define ASN1_TFLG_NDEF (0x1<<11) 634#define ASN1_TFLG_NDEF (0x1<<11)
@@ -569,52 +636,43 @@ struct ASN1_ADB_TABLE_st {
569/* This is the actual ASN1 item itself */ 636/* This is the actual ASN1 item itself */
570 637
571struct ASN1_ITEM_st { 638struct ASN1_ITEM_st {
572 char itype; /* The item type, primitive, SEQUENCE, CHOICE or extern */ 639 char itype; /* The item type, primitive, SEQUENCE, CHOICE or extern */
573 long utype; /* underlying type */ 640 long utype; /* underlying type */
574 const ASN1_TEMPLATE *templates; /* If SEQUENCE or CHOICE this contains the contents */ 641 const ASN1_TEMPLATE *templates; /* contents for SEQUENCE or CHOICE */
575 long tcount; /* Number of templates if SEQUENCE or CHOICE */ 642 long tcount; /* Number of templates if SEQUENCE or CHOICE */
576 const void *funcs; /* functions that handle this type */ 643 const void *funcs; /* functions that handle this type */
577 long size; /* Structure size (usually)*/ 644 long size; /* Structure size (usually) */
578 const char *sname; /* Structure name */ 645 const char *sname; /* Structure name */
579}; 646};
580 647
581/* These are values for the itype field and 648/*
582 * determine how the type is interpreted. 649 * These are values for the itype field and determine how the type is
650 * interpreted.
583 * 651 *
584 * For PRIMITIVE types the underlying type 652 * For PRIMITIVE types the underlying type determines the behaviour if
585 * determines the behaviour if items is NULL. 653 * items is NULL.
586 * 654 *
587 * Otherwise templates must contain a single 655 * Otherwise templates must contain a single template and the type is
588 * template and the type is treated in the 656 * treated in the same way as the type specified in the template.
589 * same way as the type specified in the template.
590 * 657 *
591 * For SEQUENCE types the templates field points 658 * For SEQUENCE types the templates field points to the members, the
592 * to the members, the size field is the 659 * size field is the structure size.
593 * structure size.
594 * 660 *
595 * For CHOICE types the templates field points 661 * For CHOICE types the templates field points to each possible member
596 * to each possible member (typically a union) 662 * (typically a union) and the 'size' field is the offset of the selector.
597 * and the 'size' field is the offset of the
598 * selector.
599 * 663 *
600 * The 'funcs' field is used for application 664 * The 'funcs' field is used for application specific functions.
601 * specific functions.
602 * 665 *
603 * The EXTERN type uses a new style d2i/i2d. 666 * The EXTERN type uses a new style d2i/i2d. The new style should be used
604 * The new style should be used where possible 667 * where possible because it avoids things like the d2i IMPLICIT hack.
605 * because it avoids things like the d2i IMPLICIT
606 * hack.
607 * 668 *
608 * MSTRING is a multiple string type, it is used 669 * MSTRING is a multiple string type, it is used for a CHOICE of character
609 * for a CHOICE of character strings where the 670 * strings where the actual strings all occupy an ASN1_STRING structure.
610 * actual strings all occupy an ASN1_STRING 671 * In this case the 'utype' field has a special meaning, it is used as a
611 * structure. In this case the 'utype' field 672 * mask of acceptable types using the B_ASN1 constants.
612 * has a special meaning, it is used as a mask
613 * of acceptable types using the B_ASN1 constants.
614 * 673 *
615 * NDEF_SEQUENCE is the same as SEQUENCE except 674 * NDEF_SEQUENCE is the same as SEQUENCE except that it will use
616 * that it will use indefinite length constructed 675 * indefinite length constructed encoding if requested.
617 * encoding if requested.
618 * 676 *
619 */ 677 */
620 678
@@ -648,23 +706,27 @@ struct ASN1_TLC_st {
648 706
649typedef ASN1_VALUE * ASN1_new_func(void); 707typedef ASN1_VALUE * ASN1_new_func(void);
650typedef void ASN1_free_func(ASN1_VALUE *a); 708typedef void ASN1_free_func(ASN1_VALUE *a);
651typedef ASN1_VALUE * ASN1_d2i_func(ASN1_VALUE **a, const unsigned char ** in, long length); 709typedef ASN1_VALUE * ASN1_d2i_func(ASN1_VALUE **a, const unsigned char ** in,
710 long length);
652typedef int ASN1_i2d_func(ASN1_VALUE * a, unsigned char **in); 711typedef int ASN1_i2d_func(ASN1_VALUE * a, unsigned char **in);
653 712
654typedef int ASN1_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, const ASN1_ITEM *it, 713typedef int ASN1_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
655 int tag, int aclass, char opt, ASN1_TLC *ctx); 714 const ASN1_ITEM *it, int tag, int aclass, char opt, ASN1_TLC *ctx);
656 715
657typedef int ASN1_ex_i2d(ASN1_VALUE **pval, unsigned char **out, const ASN1_ITEM *it, int tag, int aclass); 716typedef int ASN1_ex_i2d(ASN1_VALUE **pval, unsigned char **out,
717 const ASN1_ITEM *it, int tag, int aclass);
658typedef int ASN1_ex_new_func(ASN1_VALUE **pval, const ASN1_ITEM *it); 718typedef int ASN1_ex_new_func(ASN1_VALUE **pval, const ASN1_ITEM *it);
659typedef void ASN1_ex_free_func(ASN1_VALUE **pval, const ASN1_ITEM *it); 719typedef void ASN1_ex_free_func(ASN1_VALUE **pval, const ASN1_ITEM *it);
660 720
661typedef int ASN1_ex_print_func(BIO *out, ASN1_VALUE **pval, 721typedef int ASN1_ex_print_func(BIO *out, ASN1_VALUE **pval, int indent,
662 int indent, const char *fname, 722 const char *fname, const ASN1_PCTX *pctx);
663 const ASN1_PCTX *pctx);
664 723
665typedef int ASN1_primitive_i2c(ASN1_VALUE **pval, unsigned char *cont, int *putype, const ASN1_ITEM *it); 724typedef int ASN1_primitive_i2c(ASN1_VALUE **pval, unsigned char *cont,
666typedef int ASN1_primitive_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len, int utype, char *free_cont, const ASN1_ITEM *it); 725 int *putype, const ASN1_ITEM *it);
667typedef int ASN1_primitive_print(BIO *out, ASN1_VALUE **pval, const ASN1_ITEM *it, int indent, const ASN1_PCTX *pctx); 726typedef int ASN1_primitive_c2i(ASN1_VALUE **pval, const unsigned char *cont,
727 int len, int utype, char *free_cont, const ASN1_ITEM *it);
728typedef int ASN1_primitive_print(BIO *out, ASN1_VALUE **pval,
729 const ASN1_ITEM *it, int indent, const ASN1_PCTX *pctx);
668 730
669typedef struct ASN1_EXTERN_FUNCS_st { 731typedef struct ASN1_EXTERN_FUNCS_st {
670 void *app_data; 732 void *app_data;
@@ -687,25 +749,25 @@ typedef struct ASN1_PRIMITIVE_FUNCS_st {
687 ASN1_primitive_print *prim_print; 749 ASN1_primitive_print *prim_print;
688} ASN1_PRIMITIVE_FUNCS; 750} ASN1_PRIMITIVE_FUNCS;
689 751
690/* This is the ASN1_AUX structure: it handles various 752/*
691 * miscellaneous requirements. For example the use of 753 * This is the ASN1_AUX structure: it handles various miscellaneous
692 * reference counts and an informational callback. 754 * requirements. For example the use of reference counts and an
755 * informational callback.
693 * 756 *
694 * The "informational callback" is called at various 757 * The "informational callback" is called at various points during
695 * points during the ASN1 encoding and decoding. It can 758 * the ASN1 encoding and decoding. It can be used to provide minor
696 * be used to provide minor customisation of the structures 759 * customisation of the structures used. This is most useful where
697 * used. This is most useful where the supplied routines 760 * the supplied routines *almost* do the right thing but need some
698 * *almost* do the right thing but need some extra help 761 * extra help at a few points. If the callback returns zero then it
699 * at a few points. If the callback returns zero then 762 * is assumed a fatal error has occurred and the main operation
700 * it is assumed a fatal error has occurred and the 763 * should be abandoned.
701 * main operation should be abandoned.
702 * 764 *
703 * If major changes in the default behaviour are required 765 * If major changes in the default behaviour are required then an
704 * then an external type is more appropriate. 766 * external type is more appropriate.
705 */ 767 */
706 768
707typedef int ASN1_aux_cb(int operation, ASN1_VALUE **in, const ASN1_ITEM *it, 769typedef int ASN1_aux_cb(int operation, ASN1_VALUE **in, const ASN1_ITEM *it,
708 void *exarg); 770 void *exarg);
709 771
710typedef struct ASN1_AUX_st { 772typedef struct ASN1_AUX_st {
711 void *app_data; 773 void *app_data;
@@ -761,116 +823,146 @@ typedef struct ASN1_STREAM_ARG_st {
761 823
762/* Macro to implement a primitive type */ 824/* Macro to implement a primitive type */
763#define IMPLEMENT_ASN1_TYPE(stname) IMPLEMENT_ASN1_TYPE_ex(stname, stname, 0) 825#define IMPLEMENT_ASN1_TYPE(stname) IMPLEMENT_ASN1_TYPE_ex(stname, stname, 0)
764#define IMPLEMENT_ASN1_TYPE_ex(itname, vname, ex) \ 826#define IMPLEMENT_ASN1_TYPE_ex(itname, vname, ex) \
765 ASN1_ITEM_start(itname) \ 827 ASN1_ITEM_start(itname) \
766 ASN1_ITYPE_PRIMITIVE, V_##vname, NULL, 0, NULL, ex, #itname \ 828 .itype = ASN1_ITYPE_PRIMITIVE, \
767 ASN1_ITEM_end(itname) 829 .utype = V_##vname, \
830 .templates = NULL, \
831 .tcount = 0, \
832 .funcs = NULL, \
833 .size = ex, \
834 .sname = #itname, \
835 ASN1_ITEM_end(itname)
768 836
769/* Macro to implement a multi string type */ 837/* Macro to implement a multi string type */
770#define IMPLEMENT_ASN1_MSTRING(itname, mask) \ 838#define IMPLEMENT_ASN1_MSTRING(itname, mask) \
771 ASN1_ITEM_start(itname) \ 839 ASN1_ITEM_start(itname) \
772 ASN1_ITYPE_MSTRING, mask, NULL, 0, NULL, sizeof(ASN1_STRING), #itname \ 840 .itype = ASN1_ITYPE_MSTRING, \
773 ASN1_ITEM_end(itname) 841 .utype = mask, \
774#define IMPLEMENT_EXTERN_ASN1(sname, tag, fptrs) \ 842 .templates = NULL, \
775 ASN1_ITEM_start(sname) \ 843 .tcount = 0, \
776 ASN1_ITYPE_EXTERN, \ 844 .funcs = NULL, \
777 tag, \ 845 .size = sizeof(ASN1_STRING), \
778 NULL, \ 846 .sname = #itname, \
779 0, \ 847 ASN1_ITEM_end(itname)
780 &fptrs, \ 848#define IMPLEMENT_EXTERN_ASN1(sname, tag, fptrs) \
781 0, \ 849 ASN1_ITEM_start(sname) \
782 #sname \ 850 .itype = ASN1_ITYPE_EXTERN, \
851 .utype = tag, \
852 .templates = NULL, \
853 .tcount = 0, \
854 .funcs = &fptrs, \
855 .size = 0, \
856 .sname = #sname, \
783 ASN1_ITEM_end(sname) 857 ASN1_ITEM_end(sname)
784 858
785/* Macro to implement standard functions in terms of ASN1_ITEM structures */ 859/* Macro to implement standard functions in terms of ASN1_ITEM structures */
786 860
787#define IMPLEMENT_ASN1_FUNCTIONS(stname) IMPLEMENT_ASN1_FUNCTIONS_fname(stname, stname, stname) 861#define IMPLEMENT_ASN1_FUNCTIONS(stname) \
862 IMPLEMENT_ASN1_FUNCTIONS_fname(stname, stname, stname)
788 863
789#define IMPLEMENT_ASN1_FUNCTIONS_name(stname, itname) IMPLEMENT_ASN1_FUNCTIONS_fname(stname, itname, itname) 864#define IMPLEMENT_ASN1_FUNCTIONS_name(stname, itname) \
865 IMPLEMENT_ASN1_FUNCTIONS_fname(stname, itname, itname)
790 866
791#define IMPLEMENT_ASN1_FUNCTIONS_ENCODE_name(stname, itname) \ 867#define IMPLEMENT_ASN1_FUNCTIONS_ENCODE_name(stname, itname) \
792 IMPLEMENT_ASN1_FUNCTIONS_ENCODE_fname(stname, itname, itname) 868 IMPLEMENT_ASN1_FUNCTIONS_ENCODE_fname(stname, itname, itname)
793 869
794#define IMPLEMENT_STATIC_ASN1_ALLOC_FUNCTIONS(stname) \ 870#define IMPLEMENT_STATIC_ASN1_ALLOC_FUNCTIONS(stname) \
795 IMPLEMENT_ASN1_ALLOC_FUNCTIONS_pfname(static, stname, stname, stname) 871 IMPLEMENT_ASN1_ALLOC_FUNCTIONS_pfname(static, stname, stname, stname)
796 872
797#define IMPLEMENT_ASN1_ALLOC_FUNCTIONS(stname) \ 873#define IMPLEMENT_ASN1_ALLOC_FUNCTIONS(stname) \
798 IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(stname, stname, stname) 874 IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(stname, stname, stname)
799 875
800#define IMPLEMENT_ASN1_ALLOC_FUNCTIONS_pfname(pre, stname, itname, fname) \ 876#define IMPLEMENT_ASN1_ALLOC_FUNCTIONS_pfname(pre, stname, itname, fname) \
801 pre stname *fname##_new(void) \ 877 pre stname * \
802 { \ 878 fname##_new(void) \
803 return (stname *)ASN1_item_new(ASN1_ITEM_rptr(itname)); \ 879 { \
804 } \ 880 return (stname *)ASN1_item_new(ASN1_ITEM_rptr(itname)); \
805 pre void fname##_free(stname *a) \ 881 } \
806 { \ 882 pre void \
883 fname##_free(stname *a) \
884 { \
807 ASN1_item_free((ASN1_VALUE *)a, ASN1_ITEM_rptr(itname)); \ 885 ASN1_item_free((ASN1_VALUE *)a, ASN1_ITEM_rptr(itname)); \
808 } 886 }
809 887
810#define IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(stname, itname, fname) \ 888#define IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(stname, itname, fname) \
811 stname *fname##_new(void) \ 889 stname * \
812 { \ 890 fname##_new(void) \
813 return (stname *)ASN1_item_new(ASN1_ITEM_rptr(itname)); \ 891 { \
814 } \ 892 return (stname *)ASN1_item_new(ASN1_ITEM_rptr(itname)); \
815 void fname##_free(stname *a) \ 893 } \
816 { \ 894 void \
895 fname##_free(stname *a) \
896 { \
817 ASN1_item_free((ASN1_VALUE *)a, ASN1_ITEM_rptr(itname)); \ 897 ASN1_item_free((ASN1_VALUE *)a, ASN1_ITEM_rptr(itname)); \
818 } 898 }
819 899
820#define IMPLEMENT_ASN1_FUNCTIONS_fname(stname, itname, fname) \ 900#define IMPLEMENT_ASN1_FUNCTIONS_fname(stname, itname, fname) \
821 IMPLEMENT_ASN1_ENCODE_FUNCTIONS_fname(stname, itname, fname) \ 901 IMPLEMENT_ASN1_ENCODE_FUNCTIONS_fname(stname, itname, fname) \
822 IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(stname, itname, fname) 902 IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(stname, itname, fname)
823 903
824#define IMPLEMENT_ASN1_ENCODE_FUNCTIONS_fname(stname, itname, fname) \ 904#define IMPLEMENT_ASN1_ENCODE_FUNCTIONS_fname(stname, itname, fname) \
825 stname *d2i_##fname(stname **a, const unsigned char **in, long len) \ 905 stname * \
826 { \ 906 d2i_##fname(stname **a, const unsigned char **in, long len) \
827 return (stname *)ASN1_item_d2i((ASN1_VALUE **)a, in, len, ASN1_ITEM_rptr(itname));\ 907 { \
828 } \ 908 return (stname *)ASN1_item_d2i((ASN1_VALUE **)a, in, \
829 int i2d_##fname(stname *a, unsigned char **out) \ 909 len, ASN1_ITEM_rptr(itname)); \
830 { \ 910 } \
831 return ASN1_item_i2d((ASN1_VALUE *)a, out, ASN1_ITEM_rptr(itname));\ 911 int \
912 i2d_##fname(stname *a, unsigned char **out) \
913 { \
914 return ASN1_item_i2d((ASN1_VALUE *)a, out, \
915 ASN1_ITEM_rptr(itname)); \
832 } 916 }
833 917
834#define IMPLEMENT_ASN1_NDEF_FUNCTION(stname) \ 918#define IMPLEMENT_ASN1_NDEF_FUNCTION(stname) \
835 int i2d_##stname##_NDEF(stname *a, unsigned char **out) \ 919 int \
836 { \ 920 i2d_##stname##_NDEF(stname *a, unsigned char **out) \
837 return ASN1_item_ndef_i2d((ASN1_VALUE *)a, out, ASN1_ITEM_rptr(stname));\ 921 { \
922 return ASN1_item_ndef_i2d((ASN1_VALUE *)a, out, \
923 ASN1_ITEM_rptr(stname)); \
838 } 924 }
839 925
840/* This includes evil casts to remove const: they will go away when full 926/* This includes evil casts to remove const: they will go away when full
841 * ASN1 constification is done. 927 * ASN1 constification is done.
842 */ 928 */
843#define IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(stname, itname, fname) \ 929#define IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(stname, itname, fname) \
844 stname *d2i_##fname(stname **a, const unsigned char **in, long len) \ 930 stname * \
845 { \ 931 d2i_##fname(stname **a, const unsigned char **in, long len) \
846 return (stname *)ASN1_item_d2i((ASN1_VALUE **)a, in, len, ASN1_ITEM_rptr(itname));\ 932 { \
847 } \ 933 return (stname *)ASN1_item_d2i((ASN1_VALUE **)a, in, \
848 int i2d_##fname(const stname *a, unsigned char **out) \ 934 len, ASN1_ITEM_rptr(itname)); \
849 { \ 935 } \
850 return ASN1_item_i2d((ASN1_VALUE *)a, out, ASN1_ITEM_rptr(itname));\ 936 int \
937 i2d_##fname(const stname *a, unsigned char **out) \
938 { \
939 return ASN1_item_i2d((ASN1_VALUE *)a, out, \
940 ASN1_ITEM_rptr(itname)); \
851 } 941 }
852 942
853#define IMPLEMENT_ASN1_DUP_FUNCTION(stname) \ 943#define IMPLEMENT_ASN1_DUP_FUNCTION(stname) \
854 stname * stname##_dup(stname *x) \ 944 stname * \
855 { \ 945 stname##_dup(stname *x) \
856 return ASN1_item_dup(ASN1_ITEM_rptr(stname), x); \ 946 { \
857 } 947 return ASN1_item_dup(ASN1_ITEM_rptr(stname), x); \
948 }
858 949
859#define IMPLEMENT_ASN1_PRINT_FUNCTION(stname) \ 950#define IMPLEMENT_ASN1_PRINT_FUNCTION(stname) \
860 IMPLEMENT_ASN1_PRINT_FUNCTION_fname(stname, stname, stname) 951 IMPLEMENT_ASN1_PRINT_FUNCTION_fname(stname, stname, stname)
861 952
862#define IMPLEMENT_ASN1_PRINT_FUNCTION_fname(stname, itname, fname) \ 953#define IMPLEMENT_ASN1_PRINT_FUNCTION_fname(stname, itname, fname) \
863 int fname##_print_ctx(BIO *out, stname *x, int indent, \ 954 int \
864 const ASN1_PCTX *pctx) \ 955 fname##_print_ctx(BIO *out, stname *x, int indent, \
865 { \ 956 const ASN1_PCTX *pctx) \
866 return ASN1_item_print(out, (ASN1_VALUE *)x, indent, \ 957 { \
867 ASN1_ITEM_rptr(itname), pctx); \ 958 return ASN1_item_print(out, (ASN1_VALUE *)x, indent, \
959 ASN1_ITEM_rptr(itname), pctx); \
868 } 960 }
869 961
870#define IMPLEMENT_ASN1_FUNCTIONS_const(name) \ 962#define IMPLEMENT_ASN1_FUNCTIONS_const(name) \
871 IMPLEMENT_ASN1_FUNCTIONS_const_fname(name, name, name) 963 IMPLEMENT_ASN1_FUNCTIONS_const_fname(name, name, name)
872 964
873#define IMPLEMENT_ASN1_FUNCTIONS_const_fname(stname, itname, fname) \ 965#define IMPLEMENT_ASN1_FUNCTIONS_const_fname(stname, itname, fname) \
874 IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(stname, itname, fname) \ 966 IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(stname, itname, fname) \
875 IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(stname, itname, fname) 967 IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(stname, itname, fname)
876 968
@@ -893,10 +985,10 @@ DECLARE_STACK_OF(ASN1_VALUE)
893 985
894int ASN1_item_ex_new(ASN1_VALUE **pval, const ASN1_ITEM *it); 986int ASN1_item_ex_new(ASN1_VALUE **pval, const ASN1_ITEM *it);
895void ASN1_item_ex_free(ASN1_VALUE **pval, const ASN1_ITEM *it); 987void ASN1_item_ex_free(ASN1_VALUE **pval, const ASN1_ITEM *it);
896int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, const ASN1_ITEM *it, 988int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
897 int tag, int aclass, char opt, ASN1_TLC *ctx); 989 const ASN1_ITEM *it, int tag, int aclass, char opt, ASN1_TLC *ctx);
898 990int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out,
899int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out, const ASN1_ITEM *it, int tag, int aclass); 991 const ASN1_ITEM *it, int tag, int aclass);
900 992
901#ifdef __cplusplus 993#ifdef __cplusplus
902} 994}
diff --git a/src/lib/libcrypto/asn1/asn_mime.c b/src/lib/libcrypto/asn1/asn_mime.c
index 3995fc547c..d42dd8663e 100644
--- a/src/lib/libcrypto/asn1/asn_mime.c
+++ b/src/lib/libcrypto/asn1/asn_mime.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: asn_mime.c,v 1.35 2025/01/17 05:02:18 tb Exp $ */ 1/* $OpenBSD: asn_mime.c,v 1.37 2025/06/02 12:18:21 jsg Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project. 3 * project.
4 */ 4 */
@@ -59,10 +59,10 @@
59 59
60#include <openssl/asn1.h> 60#include <openssl/asn1.h>
61#include <openssl/asn1t.h> 61#include <openssl/asn1t.h>
62#include <openssl/err.h>
63#include <openssl/x509.h> 62#include <openssl/x509.h>
64 63
65#include "asn1_local.h" 64#include "asn1_local.h"
65#include "err_local.h"
66#include "evp_local.h" 66#include "evp_local.h"
67 67
68/* Generalised MIME like utilities for streaming ASN1. Although many 68/* Generalised MIME like utilities for streaming ASN1. Although many
@@ -507,8 +507,9 @@ SMIME_read_ASN1(BIO *bio, BIO **bcont, const ASN1_ITEM *it)
507 *bcont = sk_BIO_value(parts, 0); 507 *bcont = sk_BIO_value(parts, 0);
508 BIO_free(asnin); 508 BIO_free(asnin);
509 sk_BIO_free(parts); 509 sk_BIO_free(parts);
510 } else sk_BIO_pop_free(parts, BIO_vfree); 510 } else
511 return val; 511 sk_BIO_pop_free(parts, BIO_vfree);
512 return val;
512 } 513 }
513 514
514 /* OK, if not multipart/signed try opaque signature */ 515 /* OK, if not multipart/signed try opaque signature */
diff --git a/src/lib/libcrypto/asn1/asn_moid.c b/src/lib/libcrypto/asn1/asn_moid.c
index e3c7d09446..a9a752cc38 100644
--- a/src/lib/libcrypto/asn1/asn_moid.c
+++ b/src/lib/libcrypto/asn1/asn_moid.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: asn_moid.c,v 1.18 2024/08/31 09:26:18 tb Exp $ */ 1/* $OpenBSD: asn_moid.c,v 1.20 2025/05/10 11:51:01 tb Exp $ */
2/* Written by Stephen Henson (steve@openssl.org) for the OpenSSL 2/* Written by Stephen Henson (steve@openssl.org) for the OpenSSL
3 * project 2001. 3 * project 2001.
4 */ 4 */
@@ -60,13 +60,13 @@
60#include <stdio.h> 60#include <stdio.h>
61#include <string.h> 61#include <string.h>
62 62
63#include <openssl/err.h>
64#include <openssl/conf.h> 63#include <openssl/conf.h>
65#include <openssl/crypto.h> 64#include <openssl/crypto.h>
66#include <openssl/x509.h> 65#include <openssl/x509.h>
67 66
68#include "asn1_local.h" 67#include "asn1_local.h"
69#include "conf_local.h" 68#include "conf_local.h"
69#include "err_local.h"
70 70
71/* Simple ASN1 OID module: add all objects in a given section */ 71/* Simple ASN1 OID module: add all objects in a given section */
72 72
diff --git a/src/lib/libcrypto/asn1/bio_ndef.c b/src/lib/libcrypto/asn1/bio_ndef.c
index 98bb1cd197..d001ffb0ae 100644
--- a/src/lib/libcrypto/asn1/bio_ndef.c
+++ b/src/lib/libcrypto/asn1/bio_ndef.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: bio_ndef.c,v 1.24 2023/07/28 09:58:30 tb Exp $ */ 1/* $OpenBSD: bio_ndef.c,v 1.25 2025/05/10 05:54:38 tb Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project. 3 * project.
4 */ 4 */
@@ -57,9 +57,9 @@
57#include <openssl/asn1.h> 57#include <openssl/asn1.h>
58#include <openssl/asn1t.h> 58#include <openssl/asn1t.h>
59#include <openssl/bio.h> 59#include <openssl/bio.h>
60#include <openssl/err.h>
61 60
62#include "asn1_local.h" 61#include "asn1_local.h"
62#include "err_local.h"
63 63
64int BIO_asn1_set_prefix(BIO *b, asn1_ps_func *prefix, asn1_ps_func *prefix_free); 64int BIO_asn1_set_prefix(BIO *b, asn1_ps_func *prefix, asn1_ps_func *prefix_free);
65int BIO_asn1_set_suffix(BIO *b, asn1_ps_func *suffix, asn1_ps_func *suffix_free); 65int BIO_asn1_set_suffix(BIO *b, asn1_ps_func *suffix, asn1_ps_func *suffix_free);
diff --git a/src/lib/libcrypto/asn1/p5_pbe.c b/src/lib/libcrypto/asn1/p5_pbe.c
index 582d2d9a9b..feccf8af58 100644
--- a/src/lib/libcrypto/asn1/p5_pbe.c
+++ b/src/lib/libcrypto/asn1/p5_pbe.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: p5_pbe.c,v 1.28 2024/07/08 14:48:49 beck Exp $ */ 1/* $OpenBSD: p5_pbe.c,v 1.31 2025/12/07 09:27:02 tb Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 1999. 3 * project 1999.
4 */ 4 */
@@ -61,11 +61,14 @@
61#include <string.h> 61#include <string.h>
62 62
63#include <openssl/asn1t.h> 63#include <openssl/asn1t.h>
64#include <openssl/err.h>
65#include <openssl/x509.h> 64#include <openssl/x509.h>
66 65
66#include "err_local.h"
67#include "x509_local.h" 67#include "x509_local.h"
68 68
69/* RFC 8018, section 6.1 specifies an eight-octet salt for PBES1. */
70#define PKCS5_PBE1_SALT_LEN 8
71
69/* PKCS#5 password based encryption structure */ 72/* PKCS#5 password based encryption structure */
70 73
71static const ASN1_TEMPLATE PBEPARAM_seq_tt[] = { 74static const ASN1_TEMPLATE PBEPARAM_seq_tt[] = {
@@ -126,7 +129,6 @@ PKCS5_pbe_set0_algor(X509_ALGOR *algor, int alg, int iter,
126{ 129{
127 PBEPARAM *pbe = NULL; 130 PBEPARAM *pbe = NULL;
128 ASN1_STRING *pbe_str = NULL; 131 ASN1_STRING *pbe_str = NULL;
129 unsigned char *sstr;
130 132
131 if ((pbe = PBEPARAM_new()) == NULL) { 133 if ((pbe = PBEPARAM_new()) == NULL) {
132 ASN1error(ERR_R_MALLOC_FAILURE); 134 ASN1error(ERR_R_MALLOC_FAILURE);
@@ -138,17 +140,24 @@ PKCS5_pbe_set0_algor(X509_ALGOR *algor, int alg, int iter,
138 ASN1error(ERR_R_MALLOC_FAILURE); 140 ASN1error(ERR_R_MALLOC_FAILURE);
139 goto err; 141 goto err;
140 } 142 }
141 if (!saltlen) 143 if (saltlen < 0)
142 saltlen = PKCS5_SALT_LEN;
143 if (!ASN1_STRING_set(pbe->salt, NULL, saltlen)) {
144 ASN1error(ERR_R_MALLOC_FAILURE);
145 goto err; 144 goto err;
146 } 145 if (saltlen == 0)
147 sstr = ASN1_STRING_data(pbe->salt); 146 saltlen = PKCS5_PBE1_SALT_LEN;
148 if (salt) 147 if (salt != NULL) {
149 memcpy(sstr, salt, saltlen); 148 if (!ASN1_STRING_set(pbe->salt, salt, saltlen))
150 else 149 goto err;
150 } else {
151 unsigned char *sstr = NULL;
152
153 if ((sstr = malloc(saltlen)) == NULL) {
154 ASN1error(ERR_R_MALLOC_FAILURE);
155 goto err;
156 }
151 arc4random_buf(sstr, saltlen); 157 arc4random_buf(sstr, saltlen);
158 ASN1_STRING_set0(pbe->salt, sstr, saltlen);
159 sstr = NULL;
160 }
152 161
153 if (!ASN1_item_pack(pbe, &PBEPARAM_it, &pbe_str)) { 162 if (!ASN1_item_pack(pbe, &PBEPARAM_it, &pbe_str)) {
154 ASN1error(ERR_R_MALLOC_FAILURE); 163 ASN1error(ERR_R_MALLOC_FAILURE);
@@ -162,9 +171,9 @@ PKCS5_pbe_set0_algor(X509_ALGOR *algor, int alg, int iter,
162 return 1; 171 return 1;
163 172
164 err: 173 err:
165 if (pbe != NULL) 174 PBEPARAM_free(pbe);
166 PBEPARAM_free(pbe);
167 ASN1_STRING_free(pbe_str); 175 ASN1_STRING_free(pbe_str);
176
168 return 0; 177 return 0;
169} 178}
170 179
diff --git a/src/lib/libcrypto/asn1/p5_pbev2.c b/src/lib/libcrypto/asn1/p5_pbev2.c
index 76872a8dec..64924d9b38 100644
--- a/src/lib/libcrypto/asn1/p5_pbev2.c
+++ b/src/lib/libcrypto/asn1/p5_pbev2.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: p5_pbev2.c,v 1.35 2024/03/26 07:03:10 tb Exp $ */ 1/* $OpenBSD: p5_pbev2.c,v 1.38 2025/05/24 02:57:14 tb Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 1999-2004. 3 * project 1999-2004.
4 */ 4 */
@@ -61,12 +61,18 @@
61#include <string.h> 61#include <string.h>
62 62
63#include <openssl/asn1t.h> 63#include <openssl/asn1t.h>
64#include <openssl/err.h>
65#include <openssl/x509.h> 64#include <openssl/x509.h>
66 65
66#include "err_local.h"
67#include "evp_local.h" 67#include "evp_local.h"
68#include "x509_local.h" 68#include "x509_local.h"
69 69
70/*
71 * RFC 8018, sections 6.2 and 4 specify at least 64 bits for PBES2, apparently
72 * FIPS will require at least 128 bits in the future, OpenSSL does that.
73 */
74#define PKCS5_PBE2_SALT_LEN 16
75
70/* PKCS#5 v2.0 password based encryption structures */ 76/* PKCS#5 v2.0 password based encryption structures */
71 77
72static const ASN1_TEMPLATE PBE2PARAM_seq_tt[] = { 78static const ASN1_TEMPLATE PBE2PARAM_seq_tt[] = {
@@ -187,7 +193,7 @@ PKCS5_pbe2_set(const EVP_CIPHER *cipher, int iter, unsigned char *salt,
187 int saltlen) 193 int saltlen)
188{ 194{
189 X509_ALGOR *scheme = NULL, *kalg = NULL, *ret = NULL; 195 X509_ALGOR *scheme = NULL, *kalg = NULL, *ret = NULL;
190 int prf_nid = NID_hmacWithSHA1; 196 int prf_nid = NID_hmacWithSHA256;
191 int alg_nid, keylen; 197 int alg_nid, keylen;
192 EVP_CIPHER_CTX ctx; 198 EVP_CIPHER_CTX ctx;
193 unsigned char iv[EVP_MAX_IV_LENGTH]; 199 unsigned char iv[EVP_MAX_IV_LENGTH];
@@ -292,7 +298,7 @@ PKCS5_pbkdf2_set(int iter, unsigned char *salt, int saltlen, int prf_nid,
292 kdf->salt->type = V_ASN1_OCTET_STRING; 298 kdf->salt->type = V_ASN1_OCTET_STRING;
293 299
294 if (!saltlen) 300 if (!saltlen)
295 saltlen = PKCS5_SALT_LEN; 301 saltlen = PKCS5_PBE2_SALT_LEN;
296 if (!(osalt->data = malloc (saltlen))) 302 if (!(osalt->data = malloc (saltlen)))
297 goto merr; 303 goto merr;
298 304
diff --git a/src/lib/libcrypto/asn1/p8_pkey.c b/src/lib/libcrypto/asn1/p8_pkey.c
index bdb0c39ad5..a5e82ef7ff 100644
--- a/src/lib/libcrypto/asn1/p8_pkey.c
+++ b/src/lib/libcrypto/asn1/p8_pkey.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: p8_pkey.c,v 1.25 2024/07/08 14:48:49 beck Exp $ */ 1/* $OpenBSD: p8_pkey.c,v 1.26 2025/12/05 14:19:27 tb Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 1999. 3 * project 1999.
4 */ 4 */
@@ -168,7 +168,7 @@ PKCS8_pkey_get0(const ASN1_OBJECT **ppkalg, const unsigned char **pk,
168 if (ppkalg != NULL) 168 if (ppkalg != NULL)
169 *ppkalg = p8->pkeyalg->algorithm; 169 *ppkalg = p8->pkeyalg->algorithm;
170 if (pk != NULL) { 170 if (pk != NULL) {
171 *pk = ASN1_STRING_data(p8->pkey); 171 *pk = ASN1_STRING_get0_data(p8->pkey);
172 *ppklen = ASN1_STRING_length(p8->pkey); 172 *ppklen = ASN1_STRING_length(p8->pkey);
173 } 173 }
174 if (pa != NULL) 174 if (pa != NULL)
diff --git a/src/lib/libcrypto/asn1/t_crl.c b/src/lib/libcrypto/asn1/t_crl.c
index 6449e7f199..295ab6c050 100644
--- a/src/lib/libcrypto/asn1/t_crl.c
+++ b/src/lib/libcrypto/asn1/t_crl.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: t_crl.c,v 1.26 2024/05/03 02:52:00 tb Exp $ */ 1/* $OpenBSD: t_crl.c,v 1.27 2025/05/10 05:54:38 tb Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 1999. 3 * project 1999.
4 */ 4 */
@@ -61,11 +61,11 @@
61 61
62#include <openssl/bn.h> 62#include <openssl/bn.h>
63#include <openssl/buffer.h> 63#include <openssl/buffer.h>
64#include <openssl/err.h>
65#include <openssl/objects.h> 64#include <openssl/objects.h>
66#include <openssl/x509.h> 65#include <openssl/x509.h>
67#include <openssl/x509v3.h> 66#include <openssl/x509v3.h>
68 67
68#include "err_local.h"
69#include "x509_local.h" 69#include "x509_local.h"
70 70
71int 71int
diff --git a/src/lib/libcrypto/asn1/t_req.c b/src/lib/libcrypto/asn1/t_req.c
index 1d4be9865d..51e4b4f651 100644
--- a/src/lib/libcrypto/asn1/t_req.c
+++ b/src/lib/libcrypto/asn1/t_req.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: t_req.c,v 1.28 2024/05/03 02:52:00 tb Exp $ */ 1/* $OpenBSD: t_req.c,v 1.29 2025/05/10 05:54:38 tb 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,7 +62,6 @@
62 62
63#include <openssl/bn.h> 63#include <openssl/bn.h>
64#include <openssl/buffer.h> 64#include <openssl/buffer.h>
65#include <openssl/err.h>
66#include <openssl/objects.h> 65#include <openssl/objects.h>
67#include <openssl/x509.h> 66#include <openssl/x509.h>
68#include <openssl/x509v3.h> 67#include <openssl/x509v3.h>
@@ -74,6 +73,7 @@
74#include <openssl/rsa.h> 73#include <openssl/rsa.h>
75#endif 74#endif
76 75
76#include "err_local.h"
77#include "x509_local.h" 77#include "x509_local.h"
78 78
79int 79int
diff --git a/src/lib/libcrypto/asn1/t_x509.c b/src/lib/libcrypto/asn1/t_x509.c
index 7cf4557314..71f97a8214 100644
--- a/src/lib/libcrypto/asn1/t_x509.c
+++ b/src/lib/libcrypto/asn1/t_x509.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: t_x509.c,v 1.51 2025/02/08 03:41:36 tb Exp $ */ 1/* $OpenBSD: t_x509.c,v 1.54 2025/07/01 06:46:39 tb 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 *
@@ -65,13 +65,13 @@
65 65
66#include <openssl/asn1.h> 66#include <openssl/asn1.h>
67#include <openssl/bio.h> 67#include <openssl/bio.h>
68#include <openssl/err.h>
69#include <openssl/evp.h> 68#include <openssl/evp.h>
70#include <openssl/objects.h> 69#include <openssl/objects.h>
71#include <openssl/sha.h> 70#include <openssl/sha.h>
72#include <openssl/x509.h> 71#include <openssl/x509.h>
73#include <openssl/x509v3.h> 72#include <openssl/x509v3.h>
74 73
74#include "err_local.h"
75#include "evp_local.h" 75#include "evp_local.h"
76#include "x509_local.h" 76#include "x509_local.h"
77 77
@@ -106,6 +106,28 @@ X509_print(BIO *bp, X509 *x)
106} 106}
107LCRYPTO_ALIAS(X509_print); 107LCRYPTO_ALIAS(X509_print);
108 108
109static int
110x509_print_uids(BIO *bp, const X509 *x, int indent)
111{
112 const ASN1_BIT_STRING *issuerUID = NULL, *subjectUID = NULL;
113
114 X509_get0_uids(x, &issuerUID, &subjectUID);
115 if (issuerUID != NULL) {
116 if (BIO_printf(bp, "%*sIssuer Unique ID: ", indent, "") <= 0)
117 return 0;
118 if (!X509_signature_dump(bp, issuerUID, indent + 4))
119 return 0;
120 }
121 if (subjectUID != NULL) {
122 if (BIO_printf(bp, "%*sSubject Unique ID: ", indent, "") <= 0)
123 return 0;
124 if (!X509_signature_dump(bp, subjectUID, indent + 4))
125 return 0;
126 }
127
128 return 1;
129}
130
109int 131int
110X509_print_ex(BIO *bp, X509 *x, unsigned long nmflags, unsigned long cflag) 132X509_print_ex(BIO *bp, X509 *x, unsigned long nmflags, unsigned long cflag)
111{ 133{
@@ -127,9 +149,9 @@ X509_print_ex(BIO *bp, X509 *x, unsigned long nmflags, unsigned long cflag)
127 149
128 ci = x->cert_info; 150 ci = x->cert_info;
129 if (!(cflag & X509_FLAG_NO_HEADER)) { 151 if (!(cflag & X509_FLAG_NO_HEADER)) {
130 if (BIO_write(bp, "Certificate:\n", 13) <= 0) 152 if (BIO_printf(bp, "Certificate:\n") <= 0)
131 goto err; 153 goto err;
132 if (BIO_write(bp, " Data:\n", 10) <= 0) 154 if (BIO_printf(bp, " Data:\n") <= 0)
133 goto err; 155 goto err;
134 } 156 }
135 if (!(cflag & X509_FLAG_NO_VERSION)) { 157 if (!(cflag & X509_FLAG_NO_VERSION)) {
@@ -145,7 +167,7 @@ X509_print_ex(BIO *bp, X509 *x, unsigned long nmflags, unsigned long cflag)
145 } 167 }
146 } 168 }
147 if (!(cflag & X509_FLAG_NO_SERIAL)) { 169 if (!(cflag & X509_FLAG_NO_SERIAL)) {
148 if (BIO_write(bp, " Serial Number:", 22) <= 0) 170 if (BIO_printf(bp, " Serial Number:") <= 0)
149 goto err; 171 goto err;
150 172
151 bs = X509_get_serialNumber(x); 173 bs = X509_get_serialNumber(x);
@@ -196,21 +218,21 @@ X509_print_ex(BIO *bp, X509 *x, unsigned long nmflags, unsigned long cflag)
196 if (X509_NAME_print_ex(bp, X509_get_issuer_name(x), 218 if (X509_NAME_print_ex(bp, X509_get_issuer_name(x),
197 nmindent, nmflags) < (nmflags == X509_FLAG_COMPAT ? 1 : 0)) 219 nmindent, nmflags) < (nmflags == X509_FLAG_COMPAT ? 1 : 0))
198 goto err; 220 goto err;
199 if (BIO_write(bp, "\n", 1) <= 0) 221 if (BIO_printf(bp, "\n") <= 0)
200 goto err; 222 goto err;
201 } 223 }
202 if (!(cflag & X509_FLAG_NO_VALIDITY)) { 224 if (!(cflag & X509_FLAG_NO_VALIDITY)) {
203 if (BIO_write(bp, " Validity\n", 17) <= 0) 225 if (BIO_printf(bp, " Validity\n") <= 0)
204 goto err; 226 goto err;
205 if (BIO_write(bp, " Not Before: ", 24) <= 0) 227 if (BIO_printf(bp, " Not Before: ") <= 0)
206 goto err; 228 goto err;
207 if (!ASN1_TIME_print(bp, X509_get_notBefore(x))) 229 if (!ASN1_TIME_print(bp, X509_get_notBefore(x)))
208 goto err; 230 goto err;
209 if (BIO_write(bp, "\n Not After : ", 25) <= 0) 231 if (BIO_printf(bp, "\n Not After : ") <= 0)
210 goto err; 232 goto err;
211 if (!ASN1_TIME_print(bp, X509_get_notAfter(x))) 233 if (!ASN1_TIME_print(bp, X509_get_notAfter(x)))
212 goto err; 234 goto err;
213 if (BIO_write(bp, "\n", 1) <= 0) 235 if (BIO_printf(bp, "\n") <= 0)
214 goto err; 236 goto err;
215 } 237 }
216 if (!(cflag & X509_FLAG_NO_SUBJECT)) { 238 if (!(cflag & X509_FLAG_NO_SUBJECT)) {
@@ -219,12 +241,11 @@ X509_print_ex(BIO *bp, X509 *x, unsigned long nmflags, unsigned long cflag)
219 if (X509_NAME_print_ex(bp, X509_get_subject_name(x), 241 if (X509_NAME_print_ex(bp, X509_get_subject_name(x),
220 nmindent, nmflags) < (nmflags == X509_FLAG_COMPAT ? 1 : 0)) 242 nmindent, nmflags) < (nmflags == X509_FLAG_COMPAT ? 1 : 0))
221 goto err; 243 goto err;
222 if (BIO_write(bp, "\n", 1) <= 0) 244 if (BIO_printf(bp, "\n") <= 0)
223 goto err; 245 goto err;
224 } 246 }
225 if (!(cflag & X509_FLAG_NO_PUBKEY)) { 247 if (!(cflag & X509_FLAG_NO_PUBKEY)) {
226 if (BIO_write(bp, " Subject Public Key Info:\n", 248 if (BIO_printf(bp, " Subject Public Key Info:\n") <= 0)
227 33) <= 0)
228 goto err; 249 goto err;
229 if (BIO_printf(bp, "%12sPublic Key Algorithm: ", "") <= 0) 250 if (BIO_printf(bp, "%12sPublic Key Algorithm: ", "") <= 0)
230 goto err; 251 goto err;
@@ -243,6 +264,11 @@ X509_print_ex(BIO *bp, X509 *x, unsigned long nmflags, unsigned long cflag)
243 } 264 }
244 } 265 }
245 266
267 if (!(cflag & X509_FLAG_NO_IDS)) {
268 if (!x509_print_uids(bp, x, 8))
269 goto err;
270 }
271
246 if (!(cflag & X509_FLAG_NO_EXTENSIONS)) 272 if (!(cflag & X509_FLAG_NO_EXTENSIONS))
247 X509V3_extensions_print(bp, "X509v3 extensions", 273 X509V3_extensions_print(bp, "X509v3 extensions",
248 ci->extensions, cflag, 8); 274 ci->extensions, cflag, 8);
@@ -325,7 +351,7 @@ X509_signature_dump(BIO *bp, const ASN1_STRING *sig, int indent)
325 s = sig->data; 351 s = sig->data;
326 for (i = 0; i < n; i++) { 352 for (i = 0; i < n; i++) {
327 if ((i % 18) == 0) { 353 if ((i % 18) == 0) {
328 if (BIO_write(bp, "\n", 1) <= 0) 354 if (BIO_printf(bp, "\n") <= 0)
329 return 0; 355 return 0;
330 if (BIO_indent(bp, indent, indent) <= 0) 356 if (BIO_indent(bp, indent, indent) <= 0)
331 return 0; 357 return 0;
@@ -334,7 +360,7 @@ X509_signature_dump(BIO *bp, const ASN1_STRING *sig, int indent)
334 ((i + 1) == n) ? "" : ":") <= 0) 360 ((i + 1) == n) ? "" : ":") <= 0)
335 return 0; 361 return 0;
336 } 362 }
337 if (BIO_write(bp, "\n", 1) != 1) 363 if (BIO_printf(bp, "\n") != 1)
338 return 0; 364 return 0;
339 365
340 return 1; 366 return 1;
@@ -375,7 +401,7 @@ ASN1_TIME_print(BIO *bp, const ASN1_TIME *tm)
375 return ASN1_UTCTIME_print(bp, tm); 401 return ASN1_UTCTIME_print(bp, tm);
376 if (tm->type == V_ASN1_GENERALIZEDTIME) 402 if (tm->type == V_ASN1_GENERALIZEDTIME)
377 return ASN1_GENERALIZEDTIME_print(bp, tm); 403 return ASN1_GENERALIZEDTIME_print(bp, tm);
378 BIO_write(bp, "Bad time value", 14); 404 BIO_printf(bp, "Bad time value");
379 return (0); 405 return (0);
380} 406}
381LCRYPTO_ALIAS(ASN1_TIME_print); 407LCRYPTO_ALIAS(ASN1_TIME_print);
@@ -435,7 +461,7 @@ ASN1_GENERALIZEDTIME_print(BIO *bp, const ASN1_GENERALIZEDTIME *tm)
435 return (1); 461 return (1);
436 462
437 err: 463 err:
438 BIO_write(bp, "Bad time value", 14); 464 BIO_printf(bp, "Bad time value");
439 return (0); 465 return (0);
440} 466}
441LCRYPTO_ALIAS(ASN1_GENERALIZEDTIME_print); 467LCRYPTO_ALIAS(ASN1_GENERALIZEDTIME_print);
@@ -479,7 +505,7 @@ ASN1_UTCTIME_print(BIO *bp, const ASN1_UTCTIME *tm)
479 return (1); 505 return (1);
480 506
481 err: 507 err:
482 BIO_write(bp, "Bad time value", 14); 508 BIO_printf(bp, "Bad time value");
483 return (0); 509 return (0);
484} 510}
485LCRYPTO_ALIAS(ASN1_UTCTIME_print); 511LCRYPTO_ALIAS(ASN1_UTCTIME_print);
diff --git a/src/lib/libcrypto/asn1/tasn_dec.c b/src/lib/libcrypto/asn1/tasn_dec.c
index 31b9efee54..1bffae8a94 100644
--- a/src/lib/libcrypto/asn1/tasn_dec.c
+++ b/src/lib/libcrypto/asn1/tasn_dec.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: tasn_dec.c,v 1.88 2023/07/28 10:00:10 tb Exp $ */ 1/* $OpenBSD: tasn_dec.c,v 1.89 2025/05/10 05:54:38 tb Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 2000. 3 * project 2000.
4 */ 4 */
@@ -63,11 +63,11 @@
63#include <openssl/asn1.h> 63#include <openssl/asn1.h>
64#include <openssl/asn1t.h> 64#include <openssl/asn1t.h>
65#include <openssl/buffer.h> 65#include <openssl/buffer.h>
66#include <openssl/err.h>
67#include <openssl/objects.h> 66#include <openssl/objects.h>
68 67
69#include "asn1_local.h" 68#include "asn1_local.h"
70#include "bytestring.h" 69#include "bytestring.h"
70#include "err_local.h"
71 71
72/* 72/*
73 * Constructed types with a recursive definition (such as can be found in PKCS7) 73 * Constructed types with a recursive definition (such as can be found in PKCS7)
diff --git a/src/lib/libcrypto/asn1/tasn_enc.c b/src/lib/libcrypto/asn1/tasn_enc.c
index b71993a139..a65fb5b7e7 100644
--- a/src/lib/libcrypto/asn1/tasn_enc.c
+++ b/src/lib/libcrypto/asn1/tasn_enc.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: tasn_enc.c,v 1.33 2023/07/28 10:00:10 tb Exp $ */ 1/* $OpenBSD: tasn_enc.c,v 1.34 2025/05/10 05:54:38 tb Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 2000. 3 * project 2000.
4 */ 4 */
@@ -61,10 +61,10 @@
61 61
62#include <openssl/asn1.h> 62#include <openssl/asn1.h>
63#include <openssl/asn1t.h> 63#include <openssl/asn1t.h>
64#include <openssl/err.h>
65#include <openssl/objects.h> 64#include <openssl/objects.h>
66 65
67#include "asn1_local.h" 66#include "asn1_local.h"
67#include "err_local.h"
68 68
69static int asn1_i2d_ex_primitive(ASN1_VALUE **pval, unsigned char **out, 69static int asn1_i2d_ex_primitive(ASN1_VALUE **pval, unsigned char **out,
70 const ASN1_ITEM *it, int tag, int aclass); 70 const ASN1_ITEM *it, int tag, int aclass);
diff --git a/src/lib/libcrypto/asn1/tasn_fre.c b/src/lib/libcrypto/asn1/tasn_fre.c
index 0e259a13ab..c3de668483 100644
--- a/src/lib/libcrypto/asn1/tasn_fre.c
+++ b/src/lib/libcrypto/asn1/tasn_fre.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: tasn_fre.c,v 1.24 2024/12/11 11:22:06 tb Exp $ */ 1/* $OpenBSD: tasn_fre.c,v 1.25 2025/08/14 19:02:17 tb Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 2000. 3 * project 2000.
4 */ 4 */
@@ -147,8 +147,9 @@ asn1_item_free(ASN1_VALUE **pval, const ASN1_ITEM *it)
147 return; 147 return;
148 } 148 }
149 asn1_enc_cleanup(pval, it); 149 asn1_enc_cleanup(pval, it);
150 /* If we free up as normal we will invalidate any 150 /*
151 * ANY DEFINED BY field and we wont be able to 151 * If we free up as normal, we will invalidate any
152 * ANY DEFINED BY field and we won't be able to
152 * determine the type of the field it defines. So 153 * determine the type of the field it defines. So
153 * free up in reverse order. 154 * free up in reverse order.
154 */ 155 */
diff --git a/src/lib/libcrypto/asn1/tasn_new.c b/src/lib/libcrypto/asn1/tasn_new.c
index 10c1137dbf..e17810b832 100644
--- a/src/lib/libcrypto/asn1/tasn_new.c
+++ b/src/lib/libcrypto/asn1/tasn_new.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: tasn_new.c,v 1.25 2023/07/28 10:00:10 tb Exp $ */ 1/* $OpenBSD: tasn_new.c,v 1.26 2025/05/10 05:54:38 tb Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 2000. 3 * project 2000.
4 */ 4 */
@@ -60,11 +60,11 @@
60#include <stddef.h> 60#include <stddef.h>
61#include <openssl/asn1.h> 61#include <openssl/asn1.h>
62#include <openssl/objects.h> 62#include <openssl/objects.h>
63#include <openssl/err.h>
64#include <openssl/asn1t.h> 63#include <openssl/asn1t.h>
65#include <string.h> 64#include <string.h>
66 65
67#include "asn1_local.h" 66#include "asn1_local.h"
67#include "err_local.h"
68 68
69static int asn1_item_ex_new(ASN1_VALUE **pval, const ASN1_ITEM *it); 69static int asn1_item_ex_new(ASN1_VALUE **pval, const ASN1_ITEM *it);
70static void asn1_item_clear(ASN1_VALUE **pval, const ASN1_ITEM *it); 70static void asn1_item_clear(ASN1_VALUE **pval, const ASN1_ITEM *it);
diff --git a/src/lib/libcrypto/asn1/tasn_prn.c b/src/lib/libcrypto/asn1/tasn_prn.c
index 07764fc091..4db6d61111 100644
--- a/src/lib/libcrypto/asn1/tasn_prn.c
+++ b/src/lib/libcrypto/asn1/tasn_prn.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: tasn_prn.c,v 1.27 2024/03/02 09:04:07 tb Exp $ */ 1/* $OpenBSD: tasn_prn.c,v 1.29 2025/06/07 09:28:00 tb Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 2000. 3 * project 2000.
4 */ 4 */
@@ -61,7 +61,6 @@
61#include <openssl/asn1.h> 61#include <openssl/asn1.h>
62#include <openssl/asn1t.h> 62#include <openssl/asn1t.h>
63#include <openssl/buffer.h> 63#include <openssl/buffer.h>
64#include <openssl/err.h>
65#include <openssl/objects.h> 64#include <openssl/objects.h>
66#include <openssl/x509v3.h> 65#include <openssl/x509v3.h>
67 66
@@ -411,7 +410,7 @@ asn1_primitive_print(BIO *out, ASN1_VALUE **fld, const ASN1_ITEM *it,
411 if (!asn1_print_fsname(out, indent, fname, sname, pctx)) 410 if (!asn1_print_fsname(out, indent, fname, sname, pctx))
412 return 0; 411 return 0;
413 412
414 if (it != NULL && it->funcs != NULL) { 413 if (it->funcs != NULL) {
415 const ASN1_PRIMITIVE_FUNCS *pf = it->funcs; 414 const ASN1_PRIMITIVE_FUNCS *pf = it->funcs;
416 415
417 if (pf->prim_print == NULL) 416 if (pf->prim_print == NULL)
diff --git a/src/lib/libcrypto/asn1/tasn_typ.c b/src/lib/libcrypto/asn1/tasn_typ.c
index 0f7fcb0e03..64faad7240 100644
--- a/src/lib/libcrypto/asn1/tasn_typ.c
+++ b/src/lib/libcrypto/asn1/tasn_typ.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: tasn_typ.c,v 1.20 2024/07/08 16:24:22 beck Exp $ */ 1/* $OpenBSD: tasn_typ.c,v 1.21 2025/08/22 14:07:34 tb Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 2000. 3 * project 2000.
4 */ 4 */
@@ -623,6 +623,7 @@ const ASN1_ITEM ASN1_BOOLEAN_it = {
623 .size = -1, 623 .size = -1,
624 .sname = "ASN1_BOOLEAN", 624 .sname = "ASN1_BOOLEAN",
625}; 625};
626LCRYPTO_ALIAS(ASN1_BOOLEAN_it);
626 627
627int 628int
628i2d_ASN1_BOOLEAN(int a, unsigned char **out) 629i2d_ASN1_BOOLEAN(int a, unsigned char **out)
@@ -652,6 +653,7 @@ const ASN1_ITEM ASN1_TBOOLEAN_it = {
652 .size = 1, 653 .size = 1,
653 .sname = "ASN1_TBOOLEAN", 654 .sname = "ASN1_TBOOLEAN",
654}; 655};
656LCRYPTO_ALIAS(ASN1_TBOOLEAN_it);
655 657
656const ASN1_ITEM ASN1_FBOOLEAN_it = { 658const ASN1_ITEM ASN1_FBOOLEAN_it = {
657 .itype = ASN1_ITYPE_PRIMITIVE, 659 .itype = ASN1_ITYPE_PRIMITIVE,
@@ -659,6 +661,7 @@ const ASN1_ITEM ASN1_FBOOLEAN_it = {
659 .size = 0, 661 .size = 0,
660 .sname = "ASN1_FBOOLEAN", 662 .sname = "ASN1_FBOOLEAN",
661}; 663};
664LCRYPTO_ALIAS(ASN1_FBOOLEAN_it);
662 665
663/* Special, OCTET STRING with indefinite length constructed support */ 666/* Special, OCTET STRING with indefinite length constructed support */
664 667
diff --git a/src/lib/libcrypto/asn1/tasn_utl.c b/src/lib/libcrypto/asn1/tasn_utl.c
index ae546edd4b..178a364c89 100644
--- a/src/lib/libcrypto/asn1/tasn_utl.c
+++ b/src/lib/libcrypto/asn1/tasn_utl.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: tasn_utl.c,v 1.18 2022/12/26 07:18:51 jmc Exp $ */ 1/* $OpenBSD: tasn_utl.c,v 1.19 2025/05/10 05:54:38 tb Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 2000. 3 * project 2000.
4 */ 4 */
@@ -63,9 +63,9 @@
63#include <openssl/asn1.h> 63#include <openssl/asn1.h>
64#include <openssl/asn1t.h> 64#include <openssl/asn1t.h>
65#include <openssl/objects.h> 65#include <openssl/objects.h>
66#include <openssl/err.h>
67 66
68#include "bytestring.h" 67#include "bytestring.h"
68#include "err_local.h"
69 69
70/* Utility functions for manipulating fields and offsets */ 70/* Utility functions for manipulating fields and offsets */
71 71
diff --git a/src/lib/libcrypto/asn1/x_crl.c b/src/lib/libcrypto/asn1/x_crl.c
index 7ad8350f3d..59f867bc12 100644
--- a/src/lib/libcrypto/asn1/x_crl.c
+++ b/src/lib/libcrypto/asn1/x_crl.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: x_crl.c,v 1.48 2025/02/27 20:13:41 tb Exp $ */ 1/* $OpenBSD: x_crl.c,v 1.51 2025/08/19 21:54:11 tb 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,11 +61,11 @@
61#include <openssl/opensslconf.h> 61#include <openssl/opensslconf.h>
62 62
63#include <openssl/asn1t.h> 63#include <openssl/asn1t.h>
64#include <openssl/err.h>
65#include <openssl/x509.h> 64#include <openssl/x509.h>
66#include <openssl/x509v3.h> 65#include <openssl/x509v3.h>
67 66
68#include "asn1_local.h" 67#include "asn1_local.h"
68#include "err_local.h"
69#include "x509_local.h" 69#include "x509_local.h"
70 70
71static void setup_idp(X509_CRL *crl, ISSUING_DIST_POINT *idp); 71static void setup_idp(X509_CRL *crl, ISSUING_DIST_POINT *idp);
@@ -105,8 +105,9 @@ X509_REVOKED_cmp(const X509_REVOKED * const *a, const X509_REVOKED * const *b)
105 return ASN1_INTEGER_cmp((*a)->serialNumber, (*b)->serialNumber); 105 return ASN1_INTEGER_cmp((*a)->serialNumber, (*b)->serialNumber);
106} 106}
107 107
108/* The X509_CRL_INFO structure needs a bit of customisation. 108/*
109 * Since we cache the original encoding the signature wont be affected by 109 * The X509_CRL_INFO structure needs a bit of customisation.
110 * Since we cache the original encoding, the signature won't be affected by
110 * reordering of the revoked field. 111 * reordering of the revoked field.
111 */ 112 */
112static int 113static int
@@ -540,6 +541,12 @@ LCRYPTO_ALIAS(X509_CRL_add0_revoked);
540int 541int
541X509_CRL_verify(X509_CRL *crl, EVP_PKEY *pkey) 542X509_CRL_verify(X509_CRL *crl, EVP_PKEY *pkey)
542{ 543{
544 /*
545 * The CertificateList's signature AlgorithmIdentifier must match
546 * the one inside the TBSCertList, see RFC 5280, 5.1.1.2, 5.1.2.2.
547 */
548 if (X509_ALGOR_cmp(crl->sig_alg, crl->crl->sig_alg) != 0)
549 return 0;
543 return ASN1_item_verify(&X509_CRL_INFO_it, crl->sig_alg, crl->signature, 550 return ASN1_item_verify(&X509_CRL_INFO_it, crl->sig_alg, crl->signature,
544 crl->crl, pkey); 551 crl->crl, pkey);
545} 552}
diff --git a/src/lib/libcrypto/asn1/x_info.c b/src/lib/libcrypto/asn1/x_info.c
deleted file mode 100644
index d2c4bcfe7a..0000000000
--- a/src/lib/libcrypto/asn1/x_info.c
+++ /dev/null
@@ -1,96 +0,0 @@
1/* $OpenBSD: x_info.c,v 1.22 2024/12/11 10:28:03 tb 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/err.h>
63#include <openssl/x509.h>
64
65X509_INFO *
66X509_INFO_new(void)
67{
68 X509_INFO *ret;
69
70 if ((ret = calloc(1, sizeof(X509_INFO))) == NULL) {
71 ASN1error(ERR_R_MALLOC_FAILURE);
72 return NULL;
73 }
74 ret->references = 1;
75
76 return ret;
77}
78LCRYPTO_ALIAS(X509_INFO_new);
79
80void
81X509_INFO_free(X509_INFO *x)
82{
83 if (x == NULL)
84 return;
85
86 if (CRYPTO_add(&x->references, -1, CRYPTO_LOCK_X509_INFO) > 0)
87 return;
88
89 X509_free(x->x509);
90 X509_CRL_free(x->crl);
91 X509_PKEY_free(x->x_pkey);
92 free(x->enc_data);
93
94 free(x);
95}
96LCRYPTO_ALIAS(X509_INFO_free);
diff --git a/src/lib/libcrypto/asn1/x_long.c b/src/lib/libcrypto/asn1/x_long.c
index 5e673f4521..ed463bf7c5 100644
--- a/src/lib/libcrypto/asn1/x_long.c
+++ b/src/lib/libcrypto/asn1/x_long.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: x_long.c,v 1.21 2024/07/08 16:24:22 beck Exp $ */ 1/* $OpenBSD: x_long.c,v 1.23 2026/01/02 08:03:02 tb Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 2000. 3 * project 2000.
4 */ 4 */
@@ -61,15 +61,18 @@
61 61
62#include <openssl/asn1t.h> 62#include <openssl/asn1t.h>
63#include <openssl/bn.h> 63#include <openssl/bn.h>
64#include <openssl/err.h>
65 64
66#include "asn1_local.h" 65#include "asn1_local.h"
66#include "err_local.h"
67 67
68/* 68/*
69 * Custom primitive type for long handling. This converts between an 69 * Custom primitive type for long handling. This converts between an
70 * ASN1_INTEGER and a long directly. 70 * ASN1_INTEGER and a long directly.
71 */ 71 */
72 72
73/* Used with ASN1 LONG type: if a long is set to this it is omitted */
74#define ASN1_LONG_UNDEF 0x7fffffffL
75
73static int long_new(ASN1_VALUE **pval, const ASN1_ITEM *it); 76static int long_new(ASN1_VALUE **pval, const ASN1_ITEM *it);
74static void long_free(ASN1_VALUE **pval, const ASN1_ITEM *it); 77static void long_free(ASN1_VALUE **pval, const ASN1_ITEM *it);
75static void long_clear(ASN1_VALUE **pval, const ASN1_ITEM *it); 78static void long_clear(ASN1_VALUE **pval, const ASN1_ITEM *it);
@@ -159,8 +162,9 @@ long_i2c(ASN1_VALUE **pval, unsigned char *content, int *putype,
159 long_get(pval, &val); 162 long_get(pval, &val);
160 163
161 /* 164 /*
162 * The zero value for this type (stored in the overloaded it->size 165 * Omit this field if it has the zero value for this type (stored
163 * field) is considered to be invalid. 166 * in the overloaded it->size field) - asn1_i2d_ex_primitive()
167 * specifically checks for a -1 return value.
164 */ 168 */
165 if (val == it->size) 169 if (val == it->size)
166 return -1; 170 return -1;
diff --git a/src/lib/libcrypto/asn1/x_name.c b/src/lib/libcrypto/asn1/x_name.c
index c60714b74f..eab14ad503 100644
--- a/src/lib/libcrypto/asn1/x_name.c
+++ b/src/lib/libcrypto/asn1/x_name.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: x_name.c,v 1.45 2025/03/20 09:41:47 tb Exp $ */ 1/* $OpenBSD: x_name.c,v 1.47 2026/01/05 05:22:09 tb 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,10 +61,10 @@
61#include <string.h> 61#include <string.h>
62 62
63#include <openssl/asn1t.h> 63#include <openssl/asn1t.h>
64#include <openssl/err.h>
65#include <openssl/x509.h> 64#include <openssl/x509.h>
66 65
67#include "asn1_local.h" 66#include "asn1_local.h"
67#include "err_local.h"
68#include "x509_local.h" 68#include "x509_local.h"
69 69
70typedef STACK_OF(X509_NAME_ENTRY) STACK_OF_X509_NAME_ENTRY; 70typedef STACK_OF(X509_NAME_ENTRY) STACK_OF_X509_NAME_ENTRY;
@@ -194,7 +194,7 @@ static const ASN1_ITEM X509_NAME_INTERNAL_it = {
194 * to the external form. 194 * to the external form.
195 */ 195 */
196 196
197const ASN1_EXTERN_FUNCS x509_name_ff = { 197static const ASN1_EXTERN_FUNCS x509_name_ff = {
198 .app_data = NULL, 198 .app_data = NULL,
199 .asn1_ex_new = x509_name_ex_new, 199 .asn1_ex_new = x509_name_ex_new,
200 .asn1_ex_free = x509_name_ex_free, 200 .asn1_ex_free = x509_name_ex_free,
diff --git a/src/lib/libcrypto/asn1/x_pkey.c b/src/lib/libcrypto/asn1/x_pkey.c
deleted file mode 100644
index 5c96c13ab9..0000000000
--- a/src/lib/libcrypto/asn1/x_pkey.c
+++ /dev/null
@@ -1,123 +0,0 @@
1/* $OpenBSD: x_pkey.c,v 1.24 2024/04/09 13:55:02 beck 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#include <string.h>
61
62#include <openssl/err.h>
63#include <openssl/evp.h>
64#include <openssl/objects.h>
65#include <openssl/x509.h>
66
67X509_PKEY *
68X509_PKEY_new(void)
69{
70 X509_PKEY *ret = NULL;
71
72 if ((ret = malloc(sizeof(X509_PKEY))) == NULL) {
73 ASN1error(ERR_R_MALLOC_FAILURE);
74 goto err;
75 }
76 ret->version = 0;
77 if ((ret->enc_algor = X509_ALGOR_new()) == NULL) {
78 ASN1error(ERR_R_MALLOC_FAILURE);
79 goto err;
80 }
81 if ((ret->enc_pkey = ASN1_OCTET_STRING_new()) == NULL) {
82 ASN1error(ERR_R_MALLOC_FAILURE);
83 goto err;
84 }
85 ret->dec_pkey = NULL;
86 ret->key_length = 0;
87 ret->key_data = NULL;
88 ret->key_free = 0;
89 ret->cipher.cipher = NULL;
90 memset(ret->cipher.iv, 0, EVP_MAX_IV_LENGTH);
91 ret->references = 1;
92 return (ret);
93
94 err:
95 if (ret) {
96 X509_ALGOR_free(ret->enc_algor);
97 free(ret);
98 }
99 return NULL;
100}
101LCRYPTO_ALIAS(X509_PKEY_new);
102
103void
104X509_PKEY_free(X509_PKEY *x)
105{
106 int i;
107
108 if (x == NULL)
109 return;
110
111 i = CRYPTO_add(&x->references, -1, CRYPTO_LOCK_X509_PKEY);
112 if (i > 0)
113 return;
114
115 if (x->enc_algor != NULL)
116 X509_ALGOR_free(x->enc_algor);
117 ASN1_OCTET_STRING_free(x->enc_pkey);
118 EVP_PKEY_free(x->dec_pkey);
119 if ((x->key_data != NULL) && (x->key_free))
120 free(x->key_data);
121 free(x);
122}
123LCRYPTO_ALIAS(X509_PKEY_free);
diff --git a/src/lib/libcrypto/asn1/x_pubkey.c b/src/lib/libcrypto/asn1/x_pubkey.c
index 1e772a3458..895b4da4d0 100644
--- a/src/lib/libcrypto/asn1/x_pubkey.c
+++ b/src/lib/libcrypto/asn1/x_pubkey.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: x_pubkey.c,v 1.37 2024/07/08 14:48:49 beck Exp $ */ 1/* $OpenBSD: x_pubkey.c,v 1.40 2026/01/05 05:23:56 tb 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,7 +61,6 @@
61#include <openssl/opensslconf.h> 61#include <openssl/opensslconf.h>
62 62
63#include <openssl/asn1t.h> 63#include <openssl/asn1t.h>
64#include <openssl/err.h>
65#include <openssl/x509.h> 64#include <openssl/x509.h>
66 65
67#ifndef OPENSSL_NO_DSA 66#ifndef OPENSSL_NO_DSA
@@ -72,6 +71,7 @@
72#endif 71#endif
73 72
74#include "asn1_local.h" 73#include "asn1_local.h"
74#include "err_local.h"
75#include "evp_local.h" 75#include "evp_local.h"
76#include "x509_local.h" 76#include "x509_local.h"
77 77
@@ -385,7 +385,7 @@ pkey_pubkey_ex_i2d(ASN1_VALUE **pval, unsigned char **out, const ASN1_ITEM *it,
385 return pubkey_ex_i2d(EVP_PKEY_NONE, pval, out, it); 385 return pubkey_ex_i2d(EVP_PKEY_NONE, pval, out, it);
386} 386}
387 387
388const ASN1_EXTERN_FUNCS pkey_pubkey_asn1_ff = { 388static const ASN1_EXTERN_FUNCS pkey_pubkey_asn1_ff = {
389 .app_data = NULL, 389 .app_data = NULL,
390 .asn1_ex_new = pkey_pubkey_ex_new, 390 .asn1_ex_new = pkey_pubkey_ex_new,
391 .asn1_ex_free = pkey_pubkey_ex_free, 391 .asn1_ex_free = pkey_pubkey_ex_free,
@@ -395,7 +395,7 @@ const ASN1_EXTERN_FUNCS pkey_pubkey_asn1_ff = {
395 .asn1_ex_print = NULL, 395 .asn1_ex_print = NULL,
396}; 396};
397 397
398const ASN1_ITEM EVP_PKEY_PUBKEY_it = { 398static const ASN1_ITEM EVP_PKEY_PUBKEY_it = {
399 .itype = ASN1_ITYPE_EXTERN, 399 .itype = ASN1_ITYPE_EXTERN,
400 .utype = 0, 400 .utype = 0,
401 .templates = NULL, 401 .templates = NULL,
@@ -485,7 +485,7 @@ rsa_pubkey_ex_i2d(ASN1_VALUE **pval, unsigned char **out, const ASN1_ITEM *it,
485 return pubkey_ex_i2d(EVP_PKEY_RSA, pval, out, it); 485 return pubkey_ex_i2d(EVP_PKEY_RSA, pval, out, it);
486} 486}
487 487
488const ASN1_EXTERN_FUNCS rsa_pubkey_asn1_ff = { 488static const ASN1_EXTERN_FUNCS rsa_pubkey_asn1_ff = {
489 .app_data = NULL, 489 .app_data = NULL,
490 .asn1_ex_new = rsa_pubkey_ex_new, 490 .asn1_ex_new = rsa_pubkey_ex_new,
491 .asn1_ex_free = rsa_pubkey_ex_free, 491 .asn1_ex_free = rsa_pubkey_ex_free,
@@ -495,7 +495,7 @@ const ASN1_EXTERN_FUNCS rsa_pubkey_asn1_ff = {
495 .asn1_ex_print = NULL, 495 .asn1_ex_print = NULL,
496}; 496};
497 497
498const ASN1_ITEM RSA_PUBKEY_it = { 498static const ASN1_ITEM RSA_PUBKEY_it = {
499 .itype = ASN1_ITYPE_EXTERN, 499 .itype = ASN1_ITYPE_EXTERN,
500 .utype = 0, 500 .utype = 0,
501 .templates = NULL, 501 .templates = NULL,
@@ -581,7 +581,7 @@ dsa_pubkey_ex_i2d(ASN1_VALUE **pval, unsigned char **out, const ASN1_ITEM *it,
581 return pubkey_ex_i2d(EVP_PKEY_DSA, pval, out, it); 581 return pubkey_ex_i2d(EVP_PKEY_DSA, pval, out, it);
582} 582}
583 583
584const ASN1_EXTERN_FUNCS dsa_pubkey_asn1_ff = { 584static const ASN1_EXTERN_FUNCS dsa_pubkey_asn1_ff = {
585 .app_data = NULL, 585 .app_data = NULL,
586 .asn1_ex_new = dsa_pubkey_ex_new, 586 .asn1_ex_new = dsa_pubkey_ex_new,
587 .asn1_ex_free = dsa_pubkey_ex_free, 587 .asn1_ex_free = dsa_pubkey_ex_free,
@@ -591,7 +591,7 @@ const ASN1_EXTERN_FUNCS dsa_pubkey_asn1_ff = {
591 .asn1_ex_print = NULL, 591 .asn1_ex_print = NULL,
592}; 592};
593 593
594const ASN1_ITEM DSA_PUBKEY_it = { 594static const ASN1_ITEM DSA_PUBKEY_it = {
595 .itype = ASN1_ITYPE_EXTERN, 595 .itype = ASN1_ITYPE_EXTERN,
596 .utype = 0, 596 .utype = 0,
597 .templates = NULL, 597 .templates = NULL,
@@ -678,7 +678,7 @@ ec_pubkey_ex_i2d(ASN1_VALUE **pval, unsigned char **out, const ASN1_ITEM *it,
678 return pubkey_ex_i2d(EVP_PKEY_EC, pval, out, it); 678 return pubkey_ex_i2d(EVP_PKEY_EC, pval, out, it);
679} 679}
680 680
681const ASN1_EXTERN_FUNCS ec_pubkey_asn1_ff = { 681static const ASN1_EXTERN_FUNCS ec_pubkey_asn1_ff = {
682 .app_data = NULL, 682 .app_data = NULL,
683 .asn1_ex_new = ec_pubkey_ex_new, 683 .asn1_ex_new = ec_pubkey_ex_new,
684 .asn1_ex_free = ec_pubkey_ex_free, 684 .asn1_ex_free = ec_pubkey_ex_free,
@@ -688,7 +688,7 @@ const ASN1_EXTERN_FUNCS ec_pubkey_asn1_ff = {
688 .asn1_ex_print = NULL, 688 .asn1_ex_print = NULL,
689}; 689};
690 690
691const ASN1_ITEM EC_PUBKEY_it = { 691static const ASN1_ITEM EC_PUBKEY_it = {
692 .itype = ASN1_ITYPE_EXTERN, 692 .itype = ASN1_ITYPE_EXTERN,
693 .utype = 0, 693 .utype = 0,
694 .templates = NULL, 694 .templates = NULL,