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

177 lines
5.1 KiB

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