objects.h 6.7 KB

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