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