xref: /openbsd-src/lib/libcrypto/objects/objects.h (revision 521ba2f2ab0e0e89d1776559874b3ecc227442fc)
1 /* $OpenBSD: objects.h,v 1.22 2023/06/29 06:11:33 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 #ifndef HEADER_OBJECTS_H
60 #define HEADER_OBJECTS_H
61 
62 #include <openssl/obj_mac.h>
63 
64 #define SN_ED25519			SN_Ed25519
65 #define NID_ED25519			NID_Ed25519
66 #define OBJ_ED25519			OBJ_Ed25519
67 
68 #include <openssl/bio.h>
69 #include <openssl/asn1.h>
70 
71 #define	OBJ_NAME_TYPE_UNDEF		0x00
72 #define	OBJ_NAME_TYPE_MD_METH		0x01
73 #define	OBJ_NAME_TYPE_CIPHER_METH	0x02
74 #define	OBJ_NAME_TYPE_PKEY_METH		0x03
75 #define	OBJ_NAME_TYPE_COMP_METH		0x04
76 #define	OBJ_NAME_TYPE_NUM		0x05
77 
78 #define	OBJ_NAME_ALIAS			0x8000
79 
80 #define OBJ_BSEARCH_VALUE_ON_NOMATCH		0x01
81 #define OBJ_BSEARCH_FIRST_VALUE_ON_MATCH	0x02
82 
83 
84 #ifdef  __cplusplus
85 extern "C" {
86 #endif
87 
88 typedef struct obj_name_st {
89 	int type;
90 	int alias;
91 	const char *name;
92 	const char *data;
93 } OBJ_NAME;
94 
95 #define		OBJ_create_and_add_object(a,b,c) OBJ_create(a,b,c)
96 
97 
98 int OBJ_NAME_init(void);
99 int OBJ_NAME_new_index(unsigned long (*hash_func)(const char *),
100     int (*cmp_func)(const char *, const char *),
101     void (*free_func)(const char *, int, const char *));
102 const char *OBJ_NAME_get(const char *name, int type);
103 int OBJ_NAME_add(const char *name, int type, const char *data);
104 int OBJ_NAME_remove(const char *name, int type);
105 void OBJ_NAME_cleanup(int type); /* -1 for everything */
106 void OBJ_NAME_do_all(int type, void (*fn)(const OBJ_NAME *, void *arg),
107     void *arg);
108 void OBJ_NAME_do_all_sorted(int type, void (*fn)(const OBJ_NAME *, void *arg),
109     void *arg);
110 
111 ASN1_OBJECT *	OBJ_dup(const ASN1_OBJECT *o);
112 ASN1_OBJECT *	OBJ_nid2obj(int n);
113 const char *	OBJ_nid2ln(int n);
114 const char *	OBJ_nid2sn(int n);
115 int		OBJ_obj2nid(const ASN1_OBJECT *o);
116 ASN1_OBJECT *	OBJ_txt2obj(const char *s, int no_name);
117 int	OBJ_obj2txt(char *buf, int buf_len, const ASN1_OBJECT *a, int no_name);
118 int		OBJ_txt2nid(const char *s);
119 int		OBJ_ln2nid(const char *s);
120 int		OBJ_sn2nid(const char *s);
121 int		OBJ_cmp(const ASN1_OBJECT *a, const ASN1_OBJECT *b);
122 
123 #if defined(LIBRESSL_INTERNAL)
124 const void *	OBJ_bsearch_(const void *key, const void *base, int num,
125 		    int size, int (*cmp)(const void *, const void *));
126 const void *	OBJ_bsearch_ex_(const void *key, const void *base, int num,
127 		    int size, int (*cmp)(const void *, const void *),
128 		    int flags);
129 #endif
130 
131 int		OBJ_new_nid(int num);
132 int		OBJ_add_object(const ASN1_OBJECT *obj);
133 int		OBJ_create(const char *oid, const char *sn, const char *ln);
134 void		OBJ_cleanup(void);
135 int		OBJ_create_objects(BIO *in);
136 
137 size_t OBJ_length(const ASN1_OBJECT *obj);
138 const unsigned char *OBJ_get0_data(const ASN1_OBJECT *obj);
139 
140 int OBJ_find_sigid_algs(int signid, int *pdig_nid, int *ppkey_nid);
141 int OBJ_find_sigid_by_algs(int *psignid, int dig_nid, int pkey_nid);
142 int OBJ_add_sigid(int signid, int dig_id, int pkey_id);
143 void OBJ_sigid_free(void);
144 
145 void ERR_load_OBJ_strings(void);
146 
147 /* Error codes for the OBJ functions. */
148 
149 /* Function codes. */
150 #define OBJ_F_OBJ_ADD_OBJECT				 105
151 #define OBJ_F_OBJ_CREATE				 100
152 #define OBJ_F_OBJ_DUP					 101
153 #define OBJ_F_OBJ_NAME_NEW_INDEX			 106
154 #define OBJ_F_OBJ_NID2LN				 102
155 #define OBJ_F_OBJ_NID2OBJ				 103
156 #define OBJ_F_OBJ_NID2SN				 104
157 
158 /* Reason codes. */
159 #define OBJ_R_MALLOC_FAILURE				 100
160 #define OBJ_R_UNKNOWN_NID				 101
161 
162 #ifdef  __cplusplus
163 }
164 #endif
165 #endif
166