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 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# define OBJ_NAME_TYPE_MD_METH 0x01 26# 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# define OBJ_NAME_TYPE_KDF_METH 0x06 31# define OBJ_NAME_TYPE_NUM 0x07 32 33# 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 40extern "C" { 41#endif 42 43typedef 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 52int OBJ_NAME_init(void); 53int 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 *)); 56const char *OBJ_NAME_get(const char *name, int type); 57int OBJ_NAME_add(const char *name, int type, const char *data); 58int OBJ_NAME_remove(const char *name, int type); 59void OBJ_NAME_cleanup(int type); /* -1 for everything */ 60void OBJ_NAME_do_all(int type, void (*fn) (const OBJ_NAME *, void *arg), 61 void *arg); 62void OBJ_NAME_do_all_sorted(int type, 63 void (*fn) (const OBJ_NAME *, void *arg), 64 void *arg); 65 66DECLARE_ASN1_DUP_FUNCTION_name(ASN1_OBJECT, OBJ) 67ASN1_OBJECT *OBJ_nid2obj(int n); 68const char *OBJ_nid2ln(int n); 69const char *OBJ_nid2sn(int n); 70int OBJ_obj2nid(const ASN1_OBJECT *o); 71ASN1_OBJECT *OBJ_txt2obj(const char *s, int no_name); 72int OBJ_obj2txt(char *buf, int buf_len, const ASN1_OBJECT *a, int no_name); 73int OBJ_txt2nid(const char *s); 74int OBJ_ln2nid(const char *s); 75int OBJ_sn2nid(const char *s); 76int OBJ_cmp(const ASN1_OBJECT *a, const ASN1_OBJECT *b); 77const void *OBJ_bsearch_(const void *key, const void *base, int num, int size, 78 int (*cmp) (const void *, const void *)); 79const 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 { \ 124 type1 const *a = a_; \ 125 type2 const *b = b_; \ 126 return nm##_cmp(a,b); \ 127 } \ 128 static type2 *OBJ_bsearch_##nm(type1 *key, type2 const *base, int num) \ 129 { \ 130 return (type2 *)OBJ_bsearch_(key, base, num, sizeof(type2), \ 131 nm##_cmp_BSEARCH_CMP_FN); \ 132 } \ 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 163int OBJ_new_nid(int num); 164int OBJ_add_object(const ASN1_OBJECT *obj); 165int 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 169int OBJ_create_objects(BIO *in); 170 171size_t OBJ_length(const ASN1_OBJECT *obj); 172const unsigned char *OBJ_get0_data(const ASN1_OBJECT *obj); 173 174int OBJ_find_sigid_algs(int signid, int *pdig_nid, int *ppkey_nid); 175int OBJ_find_sigid_by_algs(int *psignid, int dig_nid, int pkey_nid); 176int OBJ_add_sigid(int signid, int dig_id, int pkey_id); 177void OBJ_sigid_free(void); 178 179 180# ifdef __cplusplus 181} 182# endif 183#endif 184