objects.h 6.5 KB

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