objects.h 6.5 KB

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