Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [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 | |
| 15 | #include <openssl/crypto.h> |
| 16 | |
Adam Langley | 4139edb | 2016-01-13 15:00:54 -0800 | [diff] [blame] | 17 | #include <openssl/cpu.h> |
| 18 | |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 19 | #include "internal.h" |
| 20 | |
| 21 | |
Kenny Root | e99801b | 2015-11-06 15:31:15 -0800 | [diff] [blame] | 22 | #if !defined(OPENSSL_NO_ASM) && !defined(OPENSSL_STATIC_ARMCAP) && \ |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 23 | (defined(OPENSSL_X86) || defined(OPENSSL_X86_64) || \ |
| 24 | defined(OPENSSL_ARM) || defined(OPENSSL_AARCH64)) |
| 25 | /* x86, x86_64 and the ARMs need to record the result of a cpuid call for the |
| 26 | * asm to work correctly, unless compiled without asm code. */ |
| 27 | #define NEED_CPUID |
| 28 | |
| 29 | #else |
| 30 | |
| 31 | /* Otherwise, don't emit a static initialiser. */ |
| 32 | |
| 33 | #if !defined(BORINGSSL_NO_STATIC_INITIALIZER) |
| 34 | #define BORINGSSL_NO_STATIC_INITIALIZER |
| 35 | #endif |
| 36 | |
| 37 | #endif /* !OPENSSL_NO_ASM && (OPENSSL_X86 || OPENSSL_X86_64 || |
| 38 | OPENSSL_ARM || OPENSSL_AARCH64) */ |
| 39 | |
| 40 | |
| 41 | /* The capability variables are defined in this file in order to work around a |
| 42 | * linker bug. When linking with a .a, if no symbols in a .o are referenced |
| 43 | * then the .o is discarded, even if it has constructor functions. |
| 44 | * |
| 45 | * This still means that any binaries that don't include some functionality |
| 46 | * that tests the capability values will still skip the constructor but, so |
| 47 | * far, the init constructor function only sets the capability variables. */ |
| 48 | |
| 49 | #if defined(OPENSSL_X86) || defined(OPENSSL_X86_64) |
| 50 | /* This value must be explicitly initialised to zero in order to work around a |
| 51 | * bug in libtool or the linker on OS X. |
| 52 | * |
| 53 | * If not initialised then it becomes a "common symbol". When put into an |
| 54 | * archive, linking on OS X will fail to resolve common symbols. By |
| 55 | * initialising it to zero, it becomes a "data symbol", which isn't so |
| 56 | * affected. */ |
| 57 | uint32_t OPENSSL_ia32cap_P[4] = {0}; |
| 58 | #elif defined(OPENSSL_ARM) || defined(OPENSSL_AARCH64) |
| 59 | |
Kenny Root | b849459 | 2015-09-25 02:29:14 +0000 | [diff] [blame] | 60 | #include <openssl/arm_arch.h> |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 61 | |
Kenny Root | e99801b | 2015-11-06 15:31:15 -0800 | [diff] [blame] | 62 | #if defined(OPENSSL_STATIC_ARMCAP) |
| 63 | |
| 64 | uint32_t OPENSSL_armcap_P = |
| 65 | #if defined(OPENSSL_STATIC_ARMCAP_NEON) || defined(__ARM_NEON__) |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 66 | ARMV7_NEON | |
Kenny Root | e99801b | 2015-11-06 15:31:15 -0800 | [diff] [blame] | 67 | #endif |
| 68 | #if defined(OPENSSL_STATIC_ARMCAP_AES) |
| 69 | ARMV8_AES | |
| 70 | #endif |
| 71 | #if defined(OPENSSL_STATIC_ARMCAP_SHA1) |
| 72 | ARMV8_SHA1 | |
| 73 | #endif |
| 74 | #if defined(OPENSSL_STATIC_ARMCAP_SHA256) |
| 75 | ARMV8_SHA256 | |
| 76 | #endif |
| 77 | #if defined(OPENSSL_STATIC_ARMCAP_PMULL) |
| 78 | ARMV8_PMULL | |
| 79 | #endif |
| 80 | 0; |
| 81 | |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 82 | #else |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 83 | uint32_t OPENSSL_armcap_P = 0; |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 84 | #endif |
| 85 | |
| 86 | #endif |
| 87 | |
| 88 | |
Adam Langley | 4139edb | 2016-01-13 15:00:54 -0800 | [diff] [blame] | 89 | #if defined(OPENSSL_WINDOWS) && !defined(BORINGSSL_NO_STATIC_INITIALIZER) |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 90 | #define OPENSSL_CDECL __cdecl |
| 91 | #else |
| 92 | #define OPENSSL_CDECL |
| 93 | #endif |
| 94 | |
Adam Langley | 4139edb | 2016-01-13 15:00:54 -0800 | [diff] [blame] | 95 | #if defined(BORINGSSL_NO_STATIC_INITIALIZER) |
| 96 | static CRYPTO_once_t once = CRYPTO_ONCE_INIT; |
| 97 | #elif defined(OPENSSL_WINDOWS) |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 98 | #pragma section(".CRT$XCU", read) |
| 99 | static void __cdecl do_library_init(void); |
| 100 | __declspec(allocate(".CRT$XCU")) void(*library_init_constructor)(void) = |
| 101 | do_library_init; |
Adam Langley | 4139edb | 2016-01-13 15:00:54 -0800 | [diff] [blame] | 102 | #else |
| 103 | static void do_library_init(void) __attribute__ ((constructor)); |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 104 | #endif |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 105 | |
| 106 | /* do_library_init is the actual initialization function. If |
| 107 | * BORINGSSL_NO_STATIC_INITIALIZER isn't defined, this is set as a static |
| 108 | * initializer. Otherwise, it is called by CRYPTO_library_init. */ |
| 109 | static void OPENSSL_CDECL do_library_init(void) { |
| 110 | /* WARNING: this function may only configure the capability variables. See the |
| 111 | * note above about the linker bug. */ |
| 112 | #if defined(NEED_CPUID) |
| 113 | OPENSSL_cpuid_setup(); |
| 114 | #endif |
| 115 | } |
| 116 | |
| 117 | void CRYPTO_library_init(void) { |
| 118 | /* TODO(davidben): It would be tidier if this build knob could be replaced |
| 119 | * with an internal lazy-init mechanism that would handle things correctly |
Adam Langley | 4139edb | 2016-01-13 15:00:54 -0800 | [diff] [blame] | 120 | * in-library. https://crbug.com/542879 */ |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 121 | #if defined(BORINGSSL_NO_STATIC_INITIALIZER) |
Adam Langley | 4139edb | 2016-01-13 15:00:54 -0800 | [diff] [blame] | 122 | CRYPTO_once(&once, do_library_init); |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 123 | #endif |
| 124 | } |
Adam Langley | f40f42d | 2015-03-24 18:25:20 -0700 | [diff] [blame] | 125 | |
David Benjamin | 9aaebef | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 126 | int CRYPTO_is_confidential_build(void) { |
| 127 | #if defined(BORINGSSL_CONFIDENTIAL) |
| 128 | return 1; |
| 129 | #else |
| 130 | return 0; |
| 131 | #endif |
| 132 | } |
| 133 | |
David Benjamin | d316cba | 2016-06-02 16:17:39 -0400 | [diff] [blame] | 134 | int CRYPTO_has_asm(void) { |
| 135 | #if defined(OPENSSL_NO_ASM) |
| 136 | return 0; |
| 137 | #else |
| 138 | return 1; |
| 139 | #endif |
| 140 | } |
| 141 | |
Adam Langley | f40f42d | 2015-03-24 18:25:20 -0700 | [diff] [blame] | 142 | const char *SSLeay_version(int unused) { |
Adam Langley | 12addf8 | 2015-05-19 15:56:28 -0700 | [diff] [blame] | 143 | return "BoringSSL"; |
Adam Langley | f40f42d | 2015-03-24 18:25:20 -0700 | [diff] [blame] | 144 | } |
| 145 | |
Adam Langley | 12addf8 | 2015-05-19 15:56:28 -0700 | [diff] [blame] | 146 | unsigned long SSLeay(void) { |
| 147 | return OPENSSL_VERSION_NUMBER; |
Adam Langley | f40f42d | 2015-03-24 18:25:20 -0700 | [diff] [blame] | 148 | } |
Kenny Root | e99801b | 2015-11-06 15:31:15 -0800 | [diff] [blame] | 149 | |
| 150 | int CRYPTO_malloc_init(void) { |
| 151 | return 1; |
| 152 | } |
| 153 | |
| 154 | void ENGINE_load_builtin_engines(void) {} |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 155 | |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame^] | 156 | int ENGINE_register_all_complete(void) { |
| 157 | return 1; |
| 158 | } |
| 159 | |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 160 | void OPENSSL_load_builtin_modules(void) {} |
| 161 | |
| 162 | int FIPS_mode(void) { return 0; } |