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