• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved.
3  *
4  * Licensed under the OpenSSL license (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 HEADER_OBJECTS_H
11 # define HEADER_OBJECTS_H
12 
13 # include <openssl/obj_mac.h>
14 # include <openssl/bio.h>
15 # include <openssl/asn1.h>
16 # include <openssl/objectserr.h>
17 
18 # define OBJ_NAME_TYPE_UNDEF             0x00
19 # define OBJ_NAME_TYPE_MD_METH           0x01
20 # define OBJ_NAME_TYPE_CIPHER_METH       0x02
21 # define OBJ_NAME_TYPE_PKEY_METH         0x03
22 # define OBJ_NAME_TYPE_COMP_METH         0x04
23 # define OBJ_NAME_TYPE_NUM               0x05
24 
25 # define OBJ_NAME_ALIAS                  0x8000
26 
27 # define OBJ_BSEARCH_VALUE_ON_NOMATCH            0x01
28 # define OBJ_BSEARCH_FIRST_VALUE_ON_MATCH        0x02
29 
30 
31 #ifdef  __cplusplus
32 extern "C" {
33 #endif
34 
35 typedef struct obj_name_st {
36     int type;
37     int alias;
38     const char *name;
39     const char *data;
40 } OBJ_NAME;
41 
42 # define         OBJ_create_and_add_object(a,b,c) OBJ_create(a,b,c)
43 
44 int OBJ_NAME_init(void);
45 int OBJ_NAME_new_index(unsigned long (*hash_func) (const char *),
46                        int (*cmp_func) (const char *, const char *),
47                        void (*free_func) (const char *, int, const char *));
48 const char *OBJ_NAME_get(const char *name, int type);
49 int OBJ_NAME_add(const char *name, int type, const char *data);
50 int OBJ_NAME_remove(const char *name, int type);
51 void OBJ_NAME_cleanup(int type); /* -1 for everything */
52 void OBJ_NAME_do_all(int type, void (*fn) (const OBJ_NAME *, void *arg),
53                      void *arg);
54 void OBJ_NAME_do_all_sorted(int type,
55                             void (*fn) (const OBJ_NAME *, void *arg),
56                             void *arg);
57 
58 ASN1_OBJECT *OBJ_dup(const ASN1_OBJECT *o);
59 ASN1_OBJECT *OBJ_nid2obj(int n);
60 const char *OBJ_nid2ln(int n);
61 const char *OBJ_nid2sn(int n);
62 int OBJ_obj2nid(const ASN1_OBJECT *o);
63 ASN1_OBJECT *OBJ_txt2obj(const char *s, int no_name);
64 int OBJ_obj2txt(char *buf, int buf_len, const ASN1_OBJECT *a, int no_name);
65 int OBJ_txt2nid(const char *s);
66 int OBJ_ln2nid(const char *s);
67 int OBJ_sn2nid(const char *s);
68 int OBJ_cmp(const ASN1_OBJECT *a, const ASN1_OBJECT *b);
69 const void *OBJ_bsearch_(const void *key, const void *base, int num, int size,
70                          int (*cmp) (const void *, const void *));
71 const void *OBJ_bsearch_ex_(const void *key, const void *base, int num,
72                             int size,
73                             int (*cmp) (const void *, const void *),
74                             int flags);
75 
76 # define _DECLARE_OBJ_BSEARCH_CMP_FN(scope, type1, type2, nm)    \
77   static int nm##_cmp_BSEARCH_CMP_FN(const void *, const void *); \
78   static int nm##_cmp(type1 const *, type2 const *); \
79   scope type2 * OBJ_bsearch_##nm(type1 *key, type2 const *base, int num)
80 
81 # define DECLARE_OBJ_BSEARCH_CMP_FN(type1, type2, cmp)   \
82   _DECLARE_OBJ_BSEARCH_CMP_FN(static, type1, type2, cmp)
83 # define DECLARE_OBJ_BSEARCH_GLOBAL_CMP_FN(type1, type2, nm)     \
84   type2 * OBJ_bsearch_##nm(type1 *key, type2 const *base, int num)
85 
86 /*-
87  * Unsolved problem: if a type is actually a pointer type, like
88  * nid_triple is, then its impossible to get a const where you need
89  * it. Consider:
90  *
91  * typedef int nid_triple[3];
92  * const void *a_;
93  * const nid_triple const *a = a_;
94  *
95  * The assignment discards a const because what you really want is:
96  *
97  * const int const * const *a = a_;
98  *
99  * But if you do that, you lose the fact that a is an array of 3 ints,
100  * which breaks comparison functions.
101  *
102  * Thus we end up having to cast, sadly, or unpack the
103  * declarations. Or, as I finally did in this case, declare nid_triple
104  * to be a struct, which it should have been in the first place.
105  *
106  * Ben, August 2008.
107  *
108  * Also, strictly speaking not all types need be const, but handling
109  * the non-constness means a lot of complication, and in practice
110  * comparison routines do always not touch their arguments.
111  */
112 
113 # define IMPLEMENT_OBJ_BSEARCH_CMP_FN(type1, type2, nm)  \
114   static int nm##_cmp_BSEARCH_CMP_FN(const void *a_, const void *b_)    \
115       { \
116       type1 const *a = a_; \
117       type2 const *b = b_; \
118       return nm##_cmp(a,b); \
119       } \
120   static type2 *OBJ_bsearch_##nm(type1 *key, type2 const *base, int num) \
121       { \
122       return (type2 *)OBJ_bsearch_(key, base, num, sizeof(type2), \
123                                         nm##_cmp_BSEARCH_CMP_FN); \
124       } \
125       extern void dummy_prototype(void)
126 
127 # define IMPLEMENT_OBJ_BSEARCH_GLOBAL_CMP_FN(type1, type2, nm)   \
128   static int nm##_cmp_BSEARCH_CMP_FN(const void *a_, const void *b_)    \
129       { \
130       type1 const *a = a_; \
131       type2 const *b = b_; \
132       return nm##_cmp(a,b); \
133       } \
134   type2 *OBJ_bsearch_##nm(type1 *key, type2 const *base, int num) \
135       { \
136       return (type2 *)OBJ_bsearch_(key, base, num, sizeof(type2), \
137                                         nm##_cmp_BSEARCH_CMP_FN); \
138       } \
139       extern void dummy_prototype(void)
140 
141 # define OBJ_bsearch(type1,key,type2,base,num,cmp)                              \
142   ((type2 *)OBJ_bsearch_(CHECKED_PTR_OF(type1,key),CHECKED_PTR_OF(type2,base), \
143                          num,sizeof(type2),                             \
144                          ((void)CHECKED_PTR_OF(type1,cmp##_type_1),     \
145                           (void)CHECKED_PTR_OF(type2,cmp##_type_2),     \
146                           cmp##_BSEARCH_CMP_FN)))
147 
148 # define OBJ_bsearch_ex(type1,key,type2,base,num,cmp,flags)                      \
149   ((type2 *)OBJ_bsearch_ex_(CHECKED_PTR_OF(type1,key),CHECKED_PTR_OF(type2,base), \
150                          num,sizeof(type2),                             \
151                          ((void)CHECKED_PTR_OF(type1,cmp##_type_1),     \
152                           (void)type_2=CHECKED_PTR_OF(type2,cmp##_type_2), \
153                           cmp##_BSEARCH_CMP_FN)),flags)
154 
155 int OBJ_new_nid(int num);
156 int OBJ_add_object(const ASN1_OBJECT *obj);
157 int OBJ_create(const char *oid, const char *sn, const char *ln);
158 #if OPENSSL_API_COMPAT < 0x10100000L
159 # define OBJ_cleanup() while(0) continue
160 #endif
161 int OBJ_create_objects(BIO *in);
162 
163 size_t OBJ_length(const ASN1_OBJECT *obj);
164 const unsigned char *OBJ_get0_data(const ASN1_OBJECT *obj);
165 
166 int OBJ_find_sigid_algs(int signid, int *pdig_nid, int *ppkey_nid);
167 int OBJ_find_sigid_by_algs(int *psignid, int dig_nid, int pkey_nid);
168 int OBJ_add_sigid(int signid, int dig_id, int pkey_id);
169 void OBJ_sigid_free(void);
170 
171 
172 # ifdef  __cplusplus
173 }
174 # endif
175 #endif
176