/src/openssl/include/openssl/objects.h
Line  | Count  | Source  | 
1  |  | /*  | 
2  |  |  * Copyright 1995-2024 The OpenSSL Project Authors. All Rights Reserved.  | 
3  |  |  *  | 
4  |  |  * Licensed under the Apache License 2.0 (the "License").  You may not use  | 
5  |  |  * this file except in compliance with the License.  You can obtain a copy  | 
6  |  |  * in the file LICENSE in the source distribution or at  | 
7  |  |  * https://www.openssl.org/source/license.html  | 
8  |  |  */  | 
9  |  |  | 
10  |  | #ifndef OPENSSL_OBJECTS_H  | 
11  |  | # define OPENSSL_OBJECTS_H  | 
12  |  | # pragma once  | 
13  |  |  | 
14  |  | # include <openssl/macros.h>  | 
15  |  | # ifndef OPENSSL_NO_DEPRECATED_3_0  | 
16  |  | #  define HEADER_OBJECTS_H  | 
17  |  | # endif  | 
18  |  |  | 
19  |  | # include <openssl/obj_mac.h>  | 
20  |  | # include <openssl/bio.h>  | 
21  |  | # include <openssl/asn1.h>  | 
22  |  | # include <openssl/objectserr.h>  | 
23  |  |  | 
24  |  | # define OBJ_NAME_TYPE_UNDEF             0x00  | 
25  | 1.21k  | # define OBJ_NAME_TYPE_MD_METH           0x01  | 
26  | 689  | # define OBJ_NAME_TYPE_CIPHER_METH       0x02  | 
27  |  | # define OBJ_NAME_TYPE_PKEY_METH         0x03  | 
28  |  | # define OBJ_NAME_TYPE_COMP_METH         0x04  | 
29  |  | # define OBJ_NAME_TYPE_MAC_METH          0x05  | 
30  | 2  | # define OBJ_NAME_TYPE_KDF_METH          0x06  | 
31  |  | # define OBJ_NAME_TYPE_NUM               0x07  | 
32  |  |  | 
33  | 4.94k  | # define OBJ_NAME_ALIAS                  0x8000  | 
34  |  |  | 
35  |  | # define OBJ_BSEARCH_VALUE_ON_NOMATCH            0x01  | 
36  |  | # define OBJ_BSEARCH_FIRST_VALUE_ON_MATCH        0x02  | 
37  |  |  | 
38  |  |  | 
39  |  | #ifdef  __cplusplus  | 
40  |  | extern "C" { | 
41  |  | #endif  | 
42  |  |  | 
43  |  | typedef struct obj_name_st { | 
44  |  |     int type;  | 
45  |  |     int alias;  | 
46  |  |     const char *name;  | 
47  |  |     const char *data;  | 
48  |  | } OBJ_NAME;  | 
49  |  |  | 
50  |  | # define         OBJ_create_and_add_object(a,b,c) OBJ_create(a,b,c)  | 
51  |  |  | 
52  |  | int OBJ_NAME_init(void);  | 
53  |  | int OBJ_NAME_new_index(unsigned long (*hash_func) (const char *),  | 
54  |  |                        int (*cmp_func) (const char *, const char *),  | 
55  |  |                        void (*free_func) (const char *, int, const char *));  | 
56  |  | const char *OBJ_NAME_get(const char *name, int type);  | 
57  |  | int OBJ_NAME_add(const char *name, int type, const char *data);  | 
58  |  | int OBJ_NAME_remove(const char *name, int type);  | 
59  |  | void OBJ_NAME_cleanup(int type); /* -1 for everything */  | 
60  |  | void OBJ_NAME_do_all(int type, void (*fn) (const OBJ_NAME *, void *arg),  | 
61  |  |                      void *arg);  | 
62  |  | void OBJ_NAME_do_all_sorted(int type,  | 
63  |  |                             void (*fn) (const OBJ_NAME *, void *arg),  | 
64  |  |                             void *arg);  | 
65  |  |  | 
66  |  | DECLARE_ASN1_DUP_FUNCTION_name(ASN1_OBJECT, OBJ)  | 
67  |  | ASN1_OBJECT *OBJ_nid2obj(int n);  | 
68  |  | const char *OBJ_nid2ln(int n);  | 
69  |  | const char *OBJ_nid2sn(int n);  | 
70  |  | int OBJ_obj2nid(const ASN1_OBJECT *o);  | 
71  |  | ASN1_OBJECT *OBJ_txt2obj(const char *s, int no_name);  | 
72  |  | int OBJ_obj2txt(char *buf, int buf_len, const ASN1_OBJECT *a, int no_name);  | 
73  |  | int OBJ_txt2nid(const char *s);  | 
74  |  | int OBJ_ln2nid(const char *s);  | 
75  |  | int OBJ_sn2nid(const char *s);  | 
76  |  | int OBJ_cmp(const ASN1_OBJECT *a, const ASN1_OBJECT *b);  | 
77  |  | const void *OBJ_bsearch_(const void *key, const void *base, int num, int size,  | 
78  |  |                          int (*cmp) (const void *, const void *));  | 
79  |  | const void *OBJ_bsearch_ex_(const void *key, const void *base, int num,  | 
80  |  |                             int size,  | 
81  |  |                             int (*cmp) (const void *, const void *),  | 
82  |  |                             int flags);  | 
83  |  |  | 
84  |  | # define _DECLARE_OBJ_BSEARCH_CMP_FN(scope, type1, type2, nm)    \  | 
85  |  |   static int nm##_cmp_BSEARCH_CMP_FN(const void *, const void *); \  | 
86  |  |   static int nm##_cmp(type1 const *, type2 const *); \  | 
87  |  |   scope type2 * OBJ_bsearch_##nm(type1 *key, type2 const *base, int num)  | 
88  |  |  | 
89  |  | # define DECLARE_OBJ_BSEARCH_CMP_FN(type1, type2, cmp)   \  | 
90  |  |   _DECLARE_OBJ_BSEARCH_CMP_FN(static, type1, type2, cmp)  | 
91  |  | # define DECLARE_OBJ_BSEARCH_GLOBAL_CMP_FN(type1, type2, nm)     \  | 
92  |  |   type2 * OBJ_bsearch_##nm(type1 *key, type2 const *base, int num)  | 
93  |  |  | 
94  |  | /*-  | 
95  |  |  * Unsolved problem: if a type is actually a pointer type, like  | 
96  |  |  * nid_triple is, then its impossible to get a const where you need  | 
97  |  |  * it. Consider:  | 
98  |  |  *  | 
99  |  |  * typedef int nid_triple[3];  | 
100  |  |  * const void *a_;  | 
101  |  |  * const nid_triple const *a = a_;  | 
102  |  |  *  | 
103  |  |  * The assignment discards a const because what you really want is:  | 
104  |  |  *  | 
105  |  |  * const int const * const *a = a_;  | 
106  |  |  *  | 
107  |  |  * But if you do that, you lose the fact that a is an array of 3 ints,  | 
108  |  |  * which breaks comparison functions.  | 
109  |  |  *  | 
110  |  |  * Thus we end up having to cast, sadly, or unpack the  | 
111  |  |  * declarations. Or, as I finally did in this case, declare nid_triple  | 
112  |  |  * to be a struct, which it should have been in the first place.  | 
113  |  |  *  | 
114  |  |  * Ben, August 2008.  | 
115  |  |  *  | 
116  |  |  * Also, strictly speaking not all types need be const, but handling  | 
117  |  |  * the non-constness means a lot of complication, and in practice  | 
118  |  |  * comparison routines do always not touch their arguments.  | 
119  |  |  */  | 
120  |  |  | 
121  |  | # define IMPLEMENT_OBJ_BSEARCH_CMP_FN(type1, type2, nm)  \  | 
122  |  |   static int nm##_cmp_BSEARCH_CMP_FN(const void *a_, const void *b_)    \  | 
123  | 26.9M  |       { \ | 
124  | 26.9M  |       type1 const *a = a_; \  | 
125  | 26.9M  |       type2 const *b = b_; \  | 
126  | 26.9M  |       return nm##_cmp(a,b); \  | 
127  | 26.9M  |       } \ obj_dat.c:ln_cmp_BSEARCH_CMP_FN Line  | Count  | Source  |  123  | 781  |       { \ |  124  | 781  |       type1 const *a = a_; \  |  125  | 781  |       type2 const *b = b_; \  |  126  | 781  |       return nm##_cmp(a,b); \  |  127  | 781  |       } \  |  
 obj_dat.c:sn_cmp_BSEARCH_CMP_FN Line  | Count  | Source  |  123  | 824  |       { \ |  124  | 824  |       type1 const *a = a_; \  |  125  | 824  |       type2 const *b = b_; \  |  126  | 824  |       return nm##_cmp(a,b); \  |  127  | 824  |       } \  |  
 obj_dat.c:obj_cmp_BSEARCH_CMP_FN Line  | Count  | Source  |  123  | 25.8M  |       { \ |  124  | 25.8M  |       type1 const *a = a_; \  |  125  | 25.8M  |       type2 const *b = b_; \  |  126  | 25.8M  |       return nm##_cmp(a,b); \  |  127  | 25.8M  |       } \  |  
 obj_xref.c:sig_cmp_BSEARCH_CMP_FN Line  | Count  | Source  |  123  | 41.0k  |       { \ |  124  | 41.0k  |       type1 const *a = a_; \  |  125  | 41.0k  |       type2 const *b = b_; \  |  126  | 41.0k  |       return nm##_cmp(a,b); \  |  127  | 41.0k  |       } \  |  
 Unexecuted instantiation: obj_xref.c:sigx_cmp_BSEARCH_CMP_FN v3_purp.c:nid_cmp_BSEARCH_CMP_FN Line  | Count  | Source  |  123  | 1.06k  |       { \ |  124  | 1.06k  |       type1 const *a = a_; \  |  125  | 1.06k  |       type2 const *b = b_; \  |  126  | 1.06k  |       return nm##_cmp(a,b); \  |  127  | 1.06k  |       } \  |  
 x509_vpm.c:table_cmp_BSEARCH_CMP_FN Line  | Count  | Source  |  123  | 2.87k  |       { \ |  124  | 2.87k  |       type1 const *a = a_; \  |  125  | 2.87k  |       type2 const *b = b_; \  |  126  | 2.87k  |       return nm##_cmp(a,b); \  |  127  | 2.87k  |       } \  |  
 Unexecuted instantiation: a_strnid.c:table_cmp_BSEARCH_CMP_FN ameth_lib.c:ameth_cmp_BSEARCH_CMP_FN Line  | Count  | Source  |  123  | 36.5k  |       { \ |  124  | 36.5k  |       type1 const *a = a_; \  |  125  | 36.5k  |       type2 const *b = b_; \  |  126  | 36.5k  |       return nm##_cmp(a,b); \  |  127  | 36.5k  |       } \  |  
 Unexecuted instantiation: pmeth_lib.c:pmeth_func_cmp_BSEARCH_CMP_FN v3_lib.c:ext_cmp_BSEARCH_CMP_FN Line  | Count  | Source  |  123  | 1.03M  |       { \ |  124  | 1.03M  |       type1 const *a = a_; \  |  125  | 1.03M  |       type2 const *b = b_; \  |  126  | 1.03M  |       return nm##_cmp(a,b); \  |  127  | 1.03M  |       } \  |  
 Unexecuted instantiation: evp_pbe.c:pbe2_cmp_BSEARCH_CMP_FN  | 
128  |  |   static type2 *OBJ_bsearch_##nm(type1 *key, type2 const *base, int num) \  | 
129  | 2.63M  |       { \ | 
130  | 2.63M  |       return (type2 *)OBJ_bsearch_(key, base, num, sizeof(type2), \  | 
131  | 2.63M  |                                         nm##_cmp_BSEARCH_CMP_FN); \  | 
132  | 2.63M  |       } \ Line  | Count  | Source  |  129  | 74  |       { \ |  130  | 74  |       return (type2 *)OBJ_bsearch_(key, base, num, sizeof(type2), \  |  131  | 74  |                                         nm##_cmp_BSEARCH_CMP_FN); \  |  132  | 74  |       } \  |  
 Line  | Count  | Source  |  129  | 79  |       { \ |  130  | 79  |       return (type2 *)OBJ_bsearch_(key, base, num, sizeof(type2), \  |  131  | 79  |                                         nm##_cmp_BSEARCH_CMP_FN); \  |  132  | 79  |       } \  |  
 obj_dat.c:OBJ_bsearch_obj Line  | Count  | Source  |  129  | 2.42M  |       { \ |  130  | 2.42M  |       return (type2 *)OBJ_bsearch_(key, base, num, sizeof(type2), \  |  131  | 2.42M  |                                         nm##_cmp_BSEARCH_CMP_FN); \  |  132  | 2.42M  |       } \  |  
 obj_xref.c:OBJ_bsearch_sig Line  | Count  | Source  |  129  | 7.47k  |       { \ |  130  | 7.47k  |       return (type2 *)OBJ_bsearch_(key, base, num, sizeof(type2), \  |  131  | 7.47k  |                                         nm##_cmp_BSEARCH_CMP_FN); \  |  132  | 7.47k  |       } \  |  
 Unexecuted instantiation: obj_xref.c:OBJ_bsearch_sigx v3_purp.c:OBJ_bsearch_nid Line  | Count  | Source  |  129  | 356  |       { \ |  130  | 356  |       return (type2 *)OBJ_bsearch_(key, base, num, sizeof(type2), \  |  131  | 356  |                                         nm##_cmp_BSEARCH_CMP_FN); \  |  132  | 356  |       } \  |  
 x509_vpm.c:OBJ_bsearch_table Line  | Count  | Source  |  129  | 1.43k  |       { \ |  130  | 1.43k  |       return (type2 *)OBJ_bsearch_(key, base, num, sizeof(type2), \  |  131  | 1.43k  |                                         nm##_cmp_BSEARCH_CMP_FN); \  |  132  | 1.43k  |       } \  |  
 Unexecuted instantiation: a_strnid.c:OBJ_bsearch_table ameth_lib.c:OBJ_bsearch_ameth Line  | Count  | Source  |  129  | 13.3k  |       { \ |  130  | 13.3k  |       return (type2 *)OBJ_bsearch_(key, base, num, sizeof(type2), \  |  131  | 13.3k  |                                         nm##_cmp_BSEARCH_CMP_FN); \  |  132  | 13.3k  |       } \  |  
 Unexecuted instantiation: pmeth_lib.c:OBJ_bsearch_pmeth_func Line  | Count  | Source  |  129  | 184k  |       { \ |  130  | 184k  |       return (type2 *)OBJ_bsearch_(key, base, num, sizeof(type2), \  |  131  | 184k  |                                         nm##_cmp_BSEARCH_CMP_FN); \  |  132  | 184k  |       } \  |  
 Unexecuted instantiation: evp_pbe.c:OBJ_bsearch_pbe2  | 
133  |  |       extern void dummy_prototype(void)  | 
134  |  |  | 
135  |  | # define IMPLEMENT_OBJ_BSEARCH_GLOBAL_CMP_FN(type1, type2, nm)   \  | 
136  |  |   static int nm##_cmp_BSEARCH_CMP_FN(const void *a_, const void *b_)    \  | 
137  |  |       { \ | 
138  |  |       type1 const *a = a_; \  | 
139  |  |       type2 const *b = b_; \  | 
140  |  |       return nm##_cmp(a,b); \  | 
141  |  |       } \  | 
142  |  |   type2 *OBJ_bsearch_##nm(type1 *key, type2 const *base, int num) \  | 
143  |  |       { \ | 
144  |  |       return (type2 *)OBJ_bsearch_(key, base, num, sizeof(type2), \  | 
145  |  |                                         nm##_cmp_BSEARCH_CMP_FN); \  | 
146  |  |       } \  | 
147  |  |       extern void dummy_prototype(void)  | 
148  |  |  | 
149  |  | # define OBJ_bsearch(type1,key,type2,base,num,cmp)                              \  | 
150  |  |   ((type2 *)OBJ_bsearch_(CHECKED_PTR_OF(type1,key),CHECKED_PTR_OF(type2,base), \  | 
151  |  |                          num,sizeof(type2),                             \  | 
152  |  |                          ((void)CHECKED_PTR_OF(type1,cmp##_type_1),     \  | 
153  |  |                           (void)CHECKED_PTR_OF(type2,cmp##_type_2),     \  | 
154  |  |                           cmp##_BSEARCH_CMP_FN)))  | 
155  |  |  | 
156  |  | # define OBJ_bsearch_ex(type1,key,type2,base,num,cmp,flags)                      \  | 
157  |  |   ((type2 *)OBJ_bsearch_ex_(CHECKED_PTR_OF(type1,key),CHECKED_PTR_OF(type2,base), \  | 
158  |  |                          num,sizeof(type2),                             \  | 
159  |  |                          ((void)CHECKED_PTR_OF(type1,cmp##_type_1),     \  | 
160  |  |                           (void)type_2=CHECKED_PTR_OF(type2,cmp##_type_2), \  | 
161  |  |                           cmp##_BSEARCH_CMP_FN)),flags)  | 
162  |  |  | 
163  |  | int OBJ_new_nid(int num);  | 
164  |  | int OBJ_add_object(const ASN1_OBJECT *obj);  | 
165  |  | int OBJ_create(const char *oid, const char *sn, const char *ln);  | 
166  |  | #ifndef OPENSSL_NO_DEPRECATED_1_1_0  | 
167  |  | # define OBJ_cleanup() while(0) continue  | 
168  |  | #endif  | 
169  |  | int OBJ_create_objects(BIO *in);  | 
170  |  |  | 
171  |  | size_t OBJ_length(const ASN1_OBJECT *obj);  | 
172  |  | const unsigned char *OBJ_get0_data(const ASN1_OBJECT *obj);  | 
173  |  |  | 
174  |  | int OBJ_find_sigid_algs(int signid, int *pdig_nid, int *ppkey_nid);  | 
175  |  | int OBJ_find_sigid_by_algs(int *psignid, int dig_nid, int pkey_nid);  | 
176  |  | int OBJ_add_sigid(int signid, int dig_id, int pkey_id);  | 
177  |  | void OBJ_sigid_free(void);  | 
178  |  |  | 
179  |  | #define SN_ac_auditEntity SN_ac_auditIdentity  | 
180  |  |  | 
181  |  | # ifdef  __cplusplus  | 
182  |  | }  | 
183  |  | # endif  | 
184  |  | #endif  |