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 17 #include "internal.h" 18 19 20 #if !defined(OPENSSL_NO_ASM) && \ 21 (defined(OPENSSL_X86) || defined(OPENSSL_X86_64) || \ 22 defined(OPENSSL_ARM) || defined(OPENSSL_AARCH64)) 23 /* x86, x86_64 and the ARMs need to record the result of a cpuid call for the 24 * asm to work correctly, unless compiled without asm code. */ 25 #define NEED_CPUID 26 27 #else 28 29 /* Otherwise, don't emit a static initialiser. */ 30 31 #if !defined(BORINGSSL_NO_STATIC_INITIALIZER) 32 #define BORINGSSL_NO_STATIC_INITIALIZER 33 #endif 34 35 #endif /* !OPENSSL_NO_ASM && (OPENSSL_X86 || OPENSSL_X86_64 || 36 OPENSSL_ARM || OPENSSL_AARCH64) */ 37 38 39 /* The capability variables are defined in this file in order to work around a 40 * linker bug. When linking with a .a, if no symbols in a .o are referenced 41 * then the .o is discarded, even if it has constructor functions. 42 * 43 * This still means that any binaries that don't include some functionality 44 * that tests the capability values will still skip the constructor but, so 45 * far, the init constructor function only sets the capability variables. */ 46 47 #if defined(OPENSSL_X86) || defined(OPENSSL_X86_64) 48 /* This value must be explicitly initialised to zero in order to work around a 49 * bug in libtool or the linker on OS X. 50 * 51 * If not initialised then it becomes a "common symbol". When put into an 52 * archive, linking on OS X will fail to resolve common symbols. By 53 * initialising it to zero, it becomes a "data symbol", which isn't so 54 * affected. */ 55 uint32_t OPENSSL_ia32cap_P[4] = {0}; 56 #elif defined(OPENSSL_ARM) || defined(OPENSSL_AARCH64) 57 58 #include "arm_arch.h" 59 60 #if defined(__ARM_NEON__) 61 uint32_t OPENSSL_armcap_P = ARMV7_NEON | ARMV7_NEON_FUNCTIONAL; 62 #else 63 uint32_t OPENSSL_armcap_P = ARMV7_NEON_FUNCTIONAL; 64 #endif 65 66 #endif 67 68 69 #if defined(OPENSSL_WINDOWS) 70 #define OPENSSL_CDECL __cdecl 71 #else 72 #define OPENSSL_CDECL 73 #endif 74 75 #if !defined(BORINGSSL_NO_STATIC_INITIALIZER) 76 #if !defined(OPENSSL_WINDOWS) 77 static void do_library_init(void) __attribute__ ((constructor)); 78 #else 79 #pragma section(".CRT$XCU", read) 80 static void __cdecl do_library_init(void); 81 __declspec(allocate(".CRT$XCU")) void(*library_init_constructor)(void) = 82 do_library_init; 83 #endif 84 #endif /* !BORINGSSL_NO_STATIC_INITIALIZER */ 85 86 /* do_library_init is the actual initialization function. If 87 * BORINGSSL_NO_STATIC_INITIALIZER isn't defined, this is set as a static 88 * initializer. Otherwise, it is called by CRYPTO_library_init. */ 89 static void OPENSSL_CDECL do_library_init(void) { 90 /* WARNING: this function may only configure the capability variables. See the 91 * note above about the linker bug. */ 92 #if defined(NEED_CPUID) 93 OPENSSL_cpuid_setup(); 94 #endif 95 } 96 97 void CRYPTO_library_init(void) { 98 /* TODO(davidben): It would be tidier if this build knob could be replaced 99 * with an internal lazy-init mechanism that would handle things correctly 100 * in-library. */ 101 #if defined(BORINGSSL_NO_STATIC_INITIALIZER) 102 do_library_init(); 103 #endif 104 } 105 106 const char *SSLeay_version(int unused) { 107 return "BoringSSL"; 108 } 109 110 unsigned long SSLeay(void) { 111 return OPENSSL_VERSION_NUMBER; 112 } 113