Adam Langley | 4c921e1 | 2014-07-14 15:28:14 -0700 | [diff] [blame] | 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 | |
David Benjamin | a70c75c | 2014-09-11 19:11:15 -0400 | [diff] [blame] | 15 | #ifndef OPENSSL_HEADER_CRYPTO_H |
| 16 | #define OPENSSL_HEADER_CRYPTO_H |
| 17 | |
| 18 | #include <openssl/base.h> |
Adam Langley | a8ffaf1 | 2019-08-21 14:27:23 -0700 | [diff] [blame] | 19 | #include <openssl/sha.h> |
David Benjamin | a70c75c | 2014-09-11 19:11:15 -0400 | [diff] [blame] | 20 | |
David Benjamin | 4512b79 | 2017-08-18 19:21:50 -0400 | [diff] [blame] | 21 | // Upstream OpenSSL defines |OPENSSL_malloc|, etc., in crypto.h rather than |
| 22 | // mem.h. |
David Benjamin | 2c6080f | 2015-04-24 10:15:31 -0400 | [diff] [blame] | 23 | #include <openssl/mem.h> |
| 24 | |
David Benjamin | 4512b79 | 2017-08-18 19:21:50 -0400 | [diff] [blame] | 25 | // Upstream OpenSSL defines |CRYPTO_LOCK|, etc., in crypto.h rather than |
| 26 | // thread.h. |
Matt Braithwaite | d0e1f1c | 2015-08-05 11:40:35 -0700 | [diff] [blame] | 27 | #include <openssl/thread.h> |
| 28 | |
David Benjamin | a70c75c | 2014-09-11 19:11:15 -0400 | [diff] [blame] | 29 | |
| 30 | #if defined(__cplusplus) |
| 31 | extern "C" { |
| 32 | #endif |
| 33 | |
| 34 | |
David Benjamin | 4512b79 | 2017-08-18 19:21:50 -0400 | [diff] [blame] | 35 | // crypto.h contains functions for initializing the crypto library. |
David Benjamin | a70c75c | 2014-09-11 19:11:15 -0400 | [diff] [blame] | 36 | |
| 37 | |
David Benjamin | 4512b79 | 2017-08-18 19:21:50 -0400 | [diff] [blame] | 38 | // CRYPTO_library_init initializes the crypto library. It must be called if the |
| 39 | // library is built with BORINGSSL_NO_STATIC_INITIALIZER. Otherwise, it does |
| 40 | // nothing and a static initializer is used instead. It is safe to call this |
| 41 | // function multiple times and concurrently from multiple threads. |
| 42 | // |
| 43 | // On some ARM configurations, this function may require filesystem access and |
| 44 | // should be called before entering a sandbox. |
David Benjamin | a70c75c | 2014-09-11 19:11:15 -0400 | [diff] [blame] | 45 | OPENSSL_EXPORT void CRYPTO_library_init(void); |
| 46 | |
David Benjamin | 4512b79 | 2017-08-18 19:21:50 -0400 | [diff] [blame] | 47 | // CRYPTO_is_confidential_build returns one if the linked version of BoringSSL |
| 48 | // has been built with the BORINGSSL_CONFIDENTIAL define and zero otherwise. |
| 49 | // |
| 50 | // This is used by some consumers to identify whether they are using an |
| 51 | // internal version of BoringSSL. |
Adam Langley | b83c680 | 2016-05-03 09:16:21 -0700 | [diff] [blame] | 52 | OPENSSL_EXPORT int CRYPTO_is_confidential_build(void); |
| 53 | |
David Benjamin | 4512b79 | 2017-08-18 19:21:50 -0400 | [diff] [blame] | 54 | // CRYPTO_has_asm returns one unless BoringSSL was built with OPENSSL_NO_ASM, |
| 55 | // in which case it returns zero. |
Adam Langley | 4fac8d0 | 2016-05-16 13:44:40 -0700 | [diff] [blame] | 56 | OPENSSL_EXPORT int CRYPTO_has_asm(void); |
| 57 | |
Adam Langley | a8ffaf1 | 2019-08-21 14:27:23 -0700 | [diff] [blame] | 58 | // BORINGSSL_self_test triggers the FIPS KAT-based self tests. It returns one on |
Adam Langley | 959c76d | 2020-03-11 10:51:35 -0700 | [diff] [blame] | 59 | // success and zero on error. |
Adam Langley | 9638f8f | 2019-10-01 10:01:25 -0700 | [diff] [blame] | 60 | OPENSSL_EXPORT int BORINGSSL_self_test(void); |
Adam Langley | f2e7b22 | 2018-01-22 11:07:42 -0800 | [diff] [blame] | 61 | |
Adam Langley | 972ab52 | 2022-03-18 11:38:22 -0700 | [diff] [blame] | 62 | // BORINGSSL_integrity_test triggers the module's integrity test where the code |
| 63 | // and data of the module is matched against a hash injected at build time. It |
| 64 | // returns one on success or zero if there's a mismatch. This function only |
| 65 | // exists if the module was built in FIPS mode without ASAN. |
| 66 | OPENSSL_EXPORT int BORINGSSL_integrity_test(void); |
| 67 | |
David Benjamin | 3e4dfbb | 2020-04-21 17:29:50 -0400 | [diff] [blame] | 68 | // CRYPTO_pre_sandbox_init initializes the crypto library, pre-acquiring some |
| 69 | // unusual resources to aid running in sandboxed environments. It is safe to |
| 70 | // call this function multiple times and concurrently from multiple threads. |
| 71 | // |
| 72 | // For more details on using BoringSSL in a sandboxed environment, see |
| 73 | // SANDBOXING.md in the source tree. |
| 74 | OPENSSL_EXPORT void CRYPTO_pre_sandbox_init(void); |
| 75 | |
David Benjamin | 37faa93 | 2021-12-21 18:43:32 -0500 | [diff] [blame] | 76 | #if defined(OPENSSL_ARM) && defined(OPENSSL_LINUX) && \ |
| 77 | !defined(OPENSSL_STATIC_ARMCAP) |
David Benjamin | 37faa93 | 2021-12-21 18:43:32 -0500 | [diff] [blame] | 78 | // CRYPTO_needs_hwcap2_workaround returns one if the ARMv8 AArch32 AT_HWCAP2 |
| 79 | // workaround was needed. See https://crbug.com/boringssl/46. |
| 80 | OPENSSL_EXPORT int CRYPTO_needs_hwcap2_workaround(void); |
| 81 | #endif // OPENSSL_ARM && OPENSSL_LINUX && !OPENSSL_STATIC_ARMCAP |
| 82 | |
David Benjamin | a70c75c | 2014-09-11 19:11:15 -0400 | [diff] [blame] | 83 | |
Adam Langley | f7b87c8 | 2021-03-09 13:17:06 -0800 | [diff] [blame] | 84 | // FIPS monitoring |
| 85 | |
| 86 | // FIPS_mode returns zero unless BoringSSL is built with BORINGSSL_FIPS, in |
| 87 | // which case it returns one. |
| 88 | OPENSSL_EXPORT int FIPS_mode(void); |
| 89 | |
| 90 | // fips_counter_t denotes specific APIs/algorithms. A counter is maintained for |
| 91 | // each in FIPS mode so that tests can be written to assert that the expected, |
| 92 | // FIPS functions are being called by a certain peice of code. |
| 93 | enum fips_counter_t { |
| 94 | fips_counter_evp_aes_128_gcm = 0, |
| 95 | fips_counter_evp_aes_256_gcm = 1, |
Adam Langley | 0da75f3 | 2021-03-30 16:28:49 -0700 | [diff] [blame] | 96 | fips_counter_evp_aes_128_ctr = 2, |
| 97 | fips_counter_evp_aes_256_ctr = 3, |
Adam Langley | f7b87c8 | 2021-03-09 13:17:06 -0800 | [diff] [blame] | 98 | |
Adam Langley | 0da75f3 | 2021-03-30 16:28:49 -0700 | [diff] [blame] | 99 | fips_counter_max = 3, |
Adam Langley | f7b87c8 | 2021-03-09 13:17:06 -0800 | [diff] [blame] | 100 | }; |
| 101 | |
| 102 | // FIPS_read_counter returns a counter of the number of times the specific |
| 103 | // function denoted by |counter| has been used. This always returns zero unless |
| 104 | // BoringSSL was built with BORINGSSL_FIPS_COUNTERS defined. |
| 105 | OPENSSL_EXPORT size_t FIPS_read_counter(enum fips_counter_t counter); |
| 106 | |
| 107 | |
David Benjamin | 4512b79 | 2017-08-18 19:21:50 -0400 | [diff] [blame] | 108 | // Deprecated functions. |
Adam Langley | c3ef76f | 2015-04-13 14:34:17 -0700 | [diff] [blame] | 109 | |
David Benjamin | 4512b79 | 2017-08-18 19:21:50 -0400 | [diff] [blame] | 110 | // OPENSSL_VERSION_TEXT contains a string the identifies the version of |
| 111 | // “OpenSSL”. node.js requires a version number in this text. |
David Benjamin | 49e9f67 | 2020-09-16 12:29:13 -0400 | [diff] [blame] | 112 | #define OPENSSL_VERSION_TEXT "OpenSSL 1.1.1 (compatible; BoringSSL)" |
Adam Langley | c3ef76f | 2015-04-13 14:34:17 -0700 | [diff] [blame] | 113 | |
David Benjamin | 81f030b | 2016-08-12 14:48:19 -0400 | [diff] [blame] | 114 | #define OPENSSL_VERSION 0 |
David Benjamin | 5d626b2 | 2018-05-08 16:07:00 -0400 | [diff] [blame] | 115 | #define OPENSSL_CFLAGS 1 |
| 116 | #define OPENSSL_BUILT_ON 2 |
| 117 | #define OPENSSL_PLATFORM 3 |
| 118 | #define OPENSSL_DIR 4 |
David Benjamin | 81f030b | 2016-08-12 14:48:19 -0400 | [diff] [blame] | 119 | |
| 120 | // OpenSSL_version is a compatibility function that returns the string |
David Benjamin | d6e31f6 | 2018-05-15 13:37:53 -0400 | [diff] [blame] | 121 | // "BoringSSL" if |which| is |OPENSSL_VERSION| and placeholder strings |
| 122 | // otherwise. |
David Benjamin | 5d626b2 | 2018-05-08 16:07:00 -0400 | [diff] [blame] | 123 | OPENSSL_EXPORT const char *OpenSSL_version(int which); |
| 124 | |
| 125 | #define SSLEAY_VERSION OPENSSL_VERSION |
| 126 | #define SSLEAY_CFLAGS OPENSSL_CFLAGS |
| 127 | #define SSLEAY_BUILT_ON OPENSSL_BUILT_ON |
| 128 | #define SSLEAY_PLATFORM OPENSSL_PLATFORM |
| 129 | #define SSLEAY_DIR OPENSSL_DIR |
| 130 | |
| 131 | // SSLeay_version calls |OpenSSL_version|. |
| 132 | OPENSSL_EXPORT const char *SSLeay_version(int which); |
David Benjamin | 81f030b | 2016-08-12 14:48:19 -0400 | [diff] [blame] | 133 | |
David Benjamin | 4512b79 | 2017-08-18 19:21:50 -0400 | [diff] [blame] | 134 | // SSLeay is a compatibility function that returns OPENSSL_VERSION_NUMBER from |
| 135 | // base.h. |
Adam Langley | b3a262c | 2015-05-19 16:30:20 -0700 | [diff] [blame] | 136 | OPENSSL_EXPORT unsigned long SSLeay(void); |
Adam Langley | c3ef76f | 2015-04-13 14:34:17 -0700 | [diff] [blame] | 137 | |
David Benjamin | 81f030b | 2016-08-12 14:48:19 -0400 | [diff] [blame] | 138 | // OpenSSL_version_num is a compatibility function that returns |
| 139 | // OPENSSL_VERSION_NUMBER from base.h. |
| 140 | OPENSSL_EXPORT unsigned long OpenSSL_version_num(void); |
| 141 | |
David Benjamin | 4512b79 | 2017-08-18 19:21:50 -0400 | [diff] [blame] | 142 | // CRYPTO_malloc_init returns one. |
Adam Langley | 05ee4fd | 2015-08-02 09:35:44 -0700 | [diff] [blame] | 143 | OPENSSL_EXPORT int CRYPTO_malloc_init(void); |
| 144 | |
David Benjamin | 27e4c3b | 2018-04-12 18:31:36 -0400 | [diff] [blame] | 145 | // OPENSSL_malloc_init returns one. |
| 146 | OPENSSL_EXPORT int OPENSSL_malloc_init(void); |
| 147 | |
David Benjamin | 4512b79 | 2017-08-18 19:21:50 -0400 | [diff] [blame] | 148 | // ENGINE_load_builtin_engines does nothing. |
Adam Langley | 05ee4fd | 2015-08-02 09:35:44 -0700 | [diff] [blame] | 149 | OPENSSL_EXPORT void ENGINE_load_builtin_engines(void); |
| 150 | |
David Benjamin | 4512b79 | 2017-08-18 19:21:50 -0400 | [diff] [blame] | 151 | // ENGINE_register_all_complete returns one. |
Adam Langley | 27516f7 | 2016-07-12 10:26:56 -0700 | [diff] [blame] | 152 | OPENSSL_EXPORT int ENGINE_register_all_complete(void); |
| 153 | |
David Benjamin | 4512b79 | 2017-08-18 19:21:50 -0400 | [diff] [blame] | 154 | // OPENSSL_load_builtin_modules does nothing. |
David Benjamin | e5aa791 | 2016-01-26 01:09:19 -0500 | [diff] [blame] | 155 | OPENSSL_EXPORT void OPENSSL_load_builtin_modules(void); |
| 156 | |
David Benjamin | 81f030b | 2016-08-12 14:48:19 -0400 | [diff] [blame] | 157 | #define OPENSSL_INIT_NO_LOAD_CRYPTO_STRINGS 0 |
| 158 | #define OPENSSL_INIT_LOAD_CRYPTO_STRINGS 0 |
| 159 | #define OPENSSL_INIT_ADD_ALL_CIPHERS 0 |
| 160 | #define OPENSSL_INIT_ADD_ALL_DIGESTS 0 |
| 161 | #define OPENSSL_INIT_NO_ADD_ALL_CIPHERS 0 |
| 162 | #define OPENSSL_INIT_NO_ADD_ALL_DIGESTS 0 |
| 163 | #define OPENSSL_INIT_LOAD_CONFIG 0 |
| 164 | #define OPENSSL_INIT_NO_LOAD_CONFIG 0 |
| 165 | |
| 166 | // OPENSSL_init_crypto calls |CRYPTO_library_init| and returns one. |
| 167 | OPENSSL_EXPORT int OPENSSL_init_crypto(uint64_t opts, |
| 168 | const OPENSSL_INIT_SETTINGS *settings); |
| 169 | |
David Benjamin | bc3286b | 2018-08-13 17:52:48 -0500 | [diff] [blame] | 170 | // OPENSSL_cleanup does nothing. |
| 171 | OPENSSL_EXPORT void OPENSSL_cleanup(void); |
| 172 | |
David Benjamin | 5d626b2 | 2018-05-08 16:07:00 -0400 | [diff] [blame] | 173 | // FIPS_mode_set returns one if |on| matches whether BoringSSL was built with |
| 174 | // |BORINGSSL_FIPS| and zero otherwise. |
| 175 | OPENSSL_EXPORT int FIPS_mode_set(int on); |
| 176 | |
Adam Langley | a56d941 | 2022-05-04 12:06:05 -0700 | [diff] [blame] | 177 | // FIPS_module_name returns the name of the FIPS module. |
| 178 | OPENSSL_EXPORT const char *FIPS_module_name(void); |
| 179 | |
Adam Langley | c6e8f3e | 2022-03-18 11:13:24 -0700 | [diff] [blame] | 180 | // FIPS_version returns the version of the FIPS module, or zero if the build |
| 181 | // isn't exactly at a verified version. The version, expressed in base 10, will |
| 182 | // be a date in the form yyyymmddXX where XX is often "00", but can be |
| 183 | // incremented if multiple versions are defined on a single day. |
| 184 | // |
| 185 | // (This format exceeds a |uint32_t| in the year 4294.) |
| 186 | OPENSSL_EXPORT uint32_t FIPS_version(void); |
| 187 | |
Adam Langley | 7f4057e | 2022-03-18 10:57:09 -0700 | [diff] [blame] | 188 | // FIPS_query_algorithm_status returns one if |algorithm| is FIPS validated in |
| 189 | // the current BoringSSL and zero otherwise. |
| 190 | OPENSSL_EXPORT int FIPS_query_algorithm_status(const char *algorithm); |
| 191 | |
David Benjamin | 2c12ebd | 2023-02-01 10:39:50 -0500 | [diff] [blame] | 192 | #if defined(OPENSSL_ARM) && defined(OPENSSL_LINUX) && \ |
| 193 | !defined(OPENSSL_STATIC_ARMCAP) |
| 194 | // CRYPTO_has_broken_NEON returns zero. |
| 195 | OPENSSL_EXPORT int CRYPTO_has_broken_NEON(void); |
| 196 | #endif |
| 197 | |
Adam Langley | c3ef76f | 2015-04-13 14:34:17 -0700 | [diff] [blame] | 198 | |
David Benjamin | a70c75c | 2014-09-11 19:11:15 -0400 | [diff] [blame] | 199 | #if defined(__cplusplus) |
David Benjamin | 4512b79 | 2017-08-18 19:21:50 -0400 | [diff] [blame] | 200 | } // extern C |
David Benjamin | a70c75c | 2014-09-11 19:11:15 -0400 | [diff] [blame] | 201 | #endif |
Adam Langley | 4c921e1 | 2014-07-14 15:28:14 -0700 | [diff] [blame] | 202 | |
David Benjamin | 4512b79 | 2017-08-18 19:21:50 -0400 | [diff] [blame] | 203 | #endif // OPENSSL_HEADER_CRYPTO_H |