您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 
 

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