crypto.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. /* Copyright (c) 2014, Google Inc.
  2. *
  3. * Permission to use, copy, modify, and/or distribute this software for any
  4. * purpose with or without fee is hereby granted, provided that the above
  5. * copyright notice and this permission notice appear in all copies.
  6. *
  7. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  8. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  9. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
  10. * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  11. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  12. * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  13. * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
  14. #ifndef OPENSSL_HEADER_CRYPTO_H
  15. #define OPENSSL_HEADER_CRYPTO_H
  16. #include <openssl/base.h>
  17. #include <openssl/sha.h>
  18. // Upstream OpenSSL defines |OPENSSL_malloc|, etc., in crypto.h rather than
  19. // mem.h.
  20. #include <openssl/mem.h>
  21. // Upstream OpenSSL defines |CRYPTO_LOCK|, etc., in crypto.h rather than
  22. // thread.h.
  23. //#include <openssl/thread.h>
  24. #if defined(__cplusplus)
  25. extern "C" {
  26. #endif
  27. // crypto.h contains functions for initializing the crypto library.
  28. // CRYPTO_library_init initializes the crypto library. It must be called if the
  29. // library is built with BORINGSSL_NO_STATIC_INITIALIZER. Otherwise, it does
  30. // nothing and a static initializer is used instead. It is safe to call this
  31. // function multiple times and concurrently from multiple threads.
  32. //
  33. // On some ARM configurations, this function may require filesystem access and
  34. // should be called before entering a sandbox.
  35. OPENSSL_EXPORT void CRYPTO_library_init(void);
  36. // CRYPTO_is_confidential_build returns one if the linked version of BoringSSL
  37. // has been built with the BORINGSSL_CONFIDENTIAL define and zero otherwise.
  38. //
  39. // This is used by some consumers to identify whether they are using an
  40. // internal version of BoringSSL.
  41. OPENSSL_EXPORT int CRYPTO_is_confidential_build(void);
  42. // CRYPTO_has_asm returns one unless BoringSSL was built with OPENSSL_NO_ASM,
  43. // in which case it returns zero.
  44. OPENSSL_EXPORT int CRYPTO_has_asm(void);
  45. // BORINGSSL_self_test triggers the FIPS KAT-based self tests. It returns one on
  46. // success and zero on error.
  47. OPENSSL_EXPORT int BORINGSSL_self_test(void);
  48. // BORINGSSL_integrity_test triggers the module's integrity test where the code
  49. // and data of the module is matched against a hash injected at build time. It
  50. // returns one on success or zero if there's a mismatch. This function only
  51. // exists if the module was built in FIPS mode without ASAN.
  52. OPENSSL_EXPORT int BORINGSSL_integrity_test(void);
  53. // CRYPTO_pre_sandbox_init initializes the crypto library, pre-acquiring some
  54. // unusual resources to aid running in sandboxed environments. It is safe to
  55. // call this function multiple times and concurrently from multiple threads.
  56. //
  57. // For more details on using BoringSSL in a sandboxed environment, see
  58. // SANDBOXING.md in the source tree.
  59. OPENSSL_EXPORT void CRYPTO_pre_sandbox_init(void);
  60. #if defined(OPENSSL_ARM) && defined(OPENSSL_LINUX) && \
  61. !defined(OPENSSL_STATIC_ARMCAP)
  62. // CRYPTO_has_broken_NEON returns one if the current CPU is known to have a
  63. // broken NEON unit. See https://crbug.com/341598.
  64. OPENSSL_EXPORT int CRYPTO_has_broken_NEON(void);
  65. // CRYPTO_needs_hwcap2_workaround returns one if the ARMv8 AArch32 AT_HWCAP2
  66. // workaround was needed. See https://crbug.com/boringssl/46.
  67. OPENSSL_EXPORT int CRYPTO_needs_hwcap2_workaround(void);
  68. #endif // OPENSSL_ARM && OPENSSL_LINUX && !OPENSSL_STATIC_ARMCAP
  69. // FIPS monitoring
  70. // FIPS_mode returns zero unless BoringSSL is built with BORINGSSL_FIPS, in
  71. // which case it returns one.
  72. OPENSSL_EXPORT int FIPS_mode(void);
  73. // fips_counter_t denotes specific APIs/algorithms. A counter is maintained for
  74. // each in FIPS mode so that tests can be written to assert that the expected,
  75. // FIPS functions are being called by a certain peice of code.
  76. enum fips_counter_t {
  77. fips_counter_evp_aes_128_gcm = 0,
  78. fips_counter_evp_aes_256_gcm = 1,
  79. fips_counter_evp_aes_128_ctr = 2,
  80. fips_counter_evp_aes_256_ctr = 3,
  81. fips_counter_max = 3,
  82. };
  83. // FIPS_read_counter returns a counter of the number of times the specific
  84. // function denoted by |counter| has been used. This always returns zero unless
  85. // BoringSSL was built with BORINGSSL_FIPS_COUNTERS defined.
  86. OPENSSL_EXPORT size_t FIPS_read_counter(enum fips_counter_t counter);
  87. // Deprecated functions.
  88. // OPENSSL_VERSION_TEXT contains a string the identifies the version of
  89. // “OpenSSL”. node.js requires a version number in this text.
  90. #define OPENSSL_VERSION_TEXT "OpenSSL 1.1.1 (compatible; BoringSSL)"
  91. #define OPENSSL_VERSION 0
  92. #define OPENSSL_CFLAGS 1
  93. #define OPENSSL_BUILT_ON 2
  94. #define OPENSSL_PLATFORM 3
  95. #define OPENSSL_DIR 4
  96. // OpenSSL_version is a compatibility function that returns the string
  97. // "BoringSSL" if |which| is |OPENSSL_VERSION| and placeholder strings
  98. // otherwise.
  99. OPENSSL_EXPORT const char *OpenSSL_version(int which);
  100. #define SSLEAY_VERSION OPENSSL_VERSION
  101. #define SSLEAY_CFLAGS OPENSSL_CFLAGS
  102. #define SSLEAY_BUILT_ON OPENSSL_BUILT_ON
  103. #define SSLEAY_PLATFORM OPENSSL_PLATFORM
  104. #define SSLEAY_DIR OPENSSL_DIR
  105. // SSLeay_version calls |OpenSSL_version|.
  106. OPENSSL_EXPORT const char *SSLeay_version(int which);
  107. // SSLeay is a compatibility function that returns OPENSSL_VERSION_NUMBER from
  108. // base.h.
  109. OPENSSL_EXPORT unsigned long SSLeay(void);
  110. // OpenSSL_version_num is a compatibility function that returns
  111. // OPENSSL_VERSION_NUMBER from base.h.
  112. OPENSSL_EXPORT unsigned long OpenSSL_version_num(void);
  113. // CRYPTO_malloc_init returns one.
  114. OPENSSL_EXPORT int CRYPTO_malloc_init(void);
  115. // OPENSSL_malloc_init returns one.
  116. OPENSSL_EXPORT int OPENSSL_malloc_init(void);
  117. // ENGINE_load_builtin_engines does nothing.
  118. OPENSSL_EXPORT void ENGINE_load_builtin_engines(void);
  119. // ENGINE_register_all_complete returns one.
  120. OPENSSL_EXPORT int ENGINE_register_all_complete(void);
  121. // OPENSSL_load_builtin_modules does nothing.
  122. OPENSSL_EXPORT void OPENSSL_load_builtin_modules(void);
  123. #define OPENSSL_INIT_NO_LOAD_CRYPTO_STRINGS 0
  124. #define OPENSSL_INIT_LOAD_CRYPTO_STRINGS 0
  125. #define OPENSSL_INIT_ADD_ALL_CIPHERS 0
  126. #define OPENSSL_INIT_ADD_ALL_DIGESTS 0
  127. #define OPENSSL_INIT_NO_ADD_ALL_CIPHERS 0
  128. #define OPENSSL_INIT_NO_ADD_ALL_DIGESTS 0
  129. #define OPENSSL_INIT_LOAD_CONFIG 0
  130. #define OPENSSL_INIT_NO_LOAD_CONFIG 0
  131. // OPENSSL_init_crypto calls |CRYPTO_library_init| and returns one.
  132. OPENSSL_EXPORT int OPENSSL_init_crypto(uint64_t opts,
  133. const OPENSSL_INIT_SETTINGS *settings);
  134. // OPENSSL_cleanup does nothing.
  135. OPENSSL_EXPORT void OPENSSL_cleanup(void);
  136. // FIPS_mode_set returns one if |on| matches whether BoringSSL was built with
  137. // |BORINGSSL_FIPS| and zero otherwise.
  138. OPENSSL_EXPORT int FIPS_mode_set(int on);
  139. // FIPS_module_name returns the name of the FIPS module.
  140. OPENSSL_EXPORT const char *FIPS_module_name(void);
  141. // FIPS_version returns the version of the FIPS module, or zero if the build
  142. // isn't exactly at a verified version. The version, expressed in base 10, will
  143. // be a date in the form yyyymmddXX where XX is often "00", but can be
  144. // incremented if multiple versions are defined on a single day.
  145. //
  146. // (This format exceeds a |uint32_t| in the year 4294.)
  147. OPENSSL_EXPORT uint32_t FIPS_version(void);
  148. // FIPS_query_algorithm_status returns one if |algorithm| is FIPS validated in
  149. // the current BoringSSL and zero otherwise.
  150. OPENSSL_EXPORT int FIPS_query_algorithm_status(const char *algorithm);
  151. #if defined(__cplusplus)
  152. } // extern C
  153. #endif
  154. #endif // OPENSSL_HEADER_CRYPTO_H