You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

objects.h 7.6 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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. {
  34. #endif
  35. typedef struct obj_name_st
  36. {
  37. int type;
  38. int alias;
  39. const char* name;
  40. const char* data;
  41. } OBJ_NAME;
  42. #define OBJ_create_and_add_object(a, b, c) OBJ_create(a, b, c)
  43. int OBJ_NAME_init(void);
  44. int OBJ_NAME_new_index(unsigned long (*hash_func)(const char*), int (*cmp_func)(const char*, const char*), 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), void* arg);
  50. void OBJ_NAME_do_all_sorted(int type, void (*fn)(const OBJ_NAME*, void* arg), void* arg);
  51. DECLARE_ASN1_DUP_FUNCTION_name(ASN1_OBJECT, OBJ)
  52. ASN1_OBJECT* OBJ_nid2obj(int n);
  53. const char* OBJ_nid2ln(int n);
  54. const char* OBJ_nid2sn(int n);
  55. int OBJ_obj2nid(const ASN1_OBJECT* o);
  56. ASN1_OBJECT* OBJ_txt2obj(const char* s, int no_name);
  57. int OBJ_obj2txt(char* buf, int buf_len, const ASN1_OBJECT* a, int no_name);
  58. int OBJ_txt2nid(const char* s);
  59. int OBJ_ln2nid(const char* s);
  60. int OBJ_sn2nid(const char* s);
  61. int OBJ_cmp(const ASN1_OBJECT* a, const ASN1_OBJECT* b);
  62. const void* OBJ_bsearch_(const void* key, const void* base, int num, int size, int (*cmp)(const void*, const void*));
  63. const void* OBJ_bsearch_ex_(const void* key, const void* base, int num, int size, int (*cmp)(const void*, const void*), 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), nm##_cmp_BSEARCH_CMP_FN); \
  108. } \
  109. extern void dummy_prototype(void)
  110. #define IMPLEMENT_OBJ_BSEARCH_GLOBAL_CMP_FN(type1, type2, nm) \
  111. static int nm##_cmp_BSEARCH_CMP_FN(const void* a_, const void* b_) \
  112. { \
  113. type1 const* a = a_; \
  114. type2 const* b = b_; \
  115. return nm##_cmp(a, b); \
  116. } \
  117. type2* OBJ_bsearch_##nm(type1* key, type2 const* base, int num) \
  118. { \
  119. return (type2*)OBJ_bsearch_(key, base, num, sizeof(type2), nm##_cmp_BSEARCH_CMP_FN); \
  120. } \
  121. extern void dummy_prototype(void)
  122. #define OBJ_bsearch(type1, key, type2, base, num, cmp) \
  123. ((type2*)OBJ_bsearch_(CHECKED_PTR_OF(type1, key), CHECKED_PTR_OF(type2, base), num, sizeof(type2), ((void)CHECKED_PTR_OF(type1, cmp##_type_1), (void)CHECKED_PTR_OF(type2, cmp##_type_2), cmp##_BSEARCH_CMP_FN)))
  124. #define OBJ_bsearch_ex(type1, key, type2, base, num, cmp, flags) \
  125. ((type2*)OBJ_bsearch_ex_(CHECKED_PTR_OF(type1, key), CHECKED_PTR_OF(type2, base), num, sizeof(type2), ((void)CHECKED_PTR_OF(type1, cmp##_type_1), (void)type_2 = CHECKED_PTR_OF(type2, cmp##_type_2), cmp##_BSEARCH_CMP_FN)), flags)
  126. int OBJ_new_nid(int num);
  127. int OBJ_add_object(const ASN1_OBJECT* obj);
  128. int OBJ_create(const char* oid, const char* sn, const char* ln);
  129. #ifndef OPENSSL_NO_DEPRECATED_1_1_0
  130. #define OBJ_cleanup() \
  131. while (0) \
  132. continue
  133. #endif
  134. int OBJ_create_objects(BIO* in);
  135. size_t OBJ_length(const ASN1_OBJECT* obj);
  136. const unsigned char* OBJ_get0_data(const ASN1_OBJECT* obj);
  137. int OBJ_find_sigid_algs(int signid, int* pdig_nid, int* ppkey_nid);
  138. int OBJ_find_sigid_by_algs(int* psignid, int dig_nid, int pkey_nid);
  139. int OBJ_add_sigid(int signid, int dig_id, int pkey_id);
  140. void OBJ_sigid_free(void);
  141. #ifdef __cplusplus
  142. }
  143. #endif
  144. #endif