objects.h 6.6 KB

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