25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

crypto.c 4.7 KiB

Add PPC64LE assembly for AES-GCM. This change adds AES and GHASH assembly from upstream, with the aim of speeding up AES-GCM. The PPC64LE assembly matches the interface of the ARMv8 assembly so I've changed the prefix of both sets of asm functions to be the same ("aes_hw_"). Otherwise, the new assmebly files and Perlasm match exactly those from upstream's c536b6be1a (from their master branch). Before: Did 1879000 AES-128-GCM (16 bytes) seal operations in 1000428us (1878196.1 ops/sec): 30.1 MB/s Did 61000 AES-128-GCM (1350 bytes) seal operations in 1006660us (60596.4 ops/sec): 81.8 MB/s Did 11000 AES-128-GCM (8192 bytes) seal operations in 1072649us (10255.0 ops/sec): 84.0 MB/s Did 1665000 AES-256-GCM (16 bytes) seal operations in 1000591us (1664016.6 ops/sec): 26.6 MB/s Did 52000 AES-256-GCM (1350 bytes) seal operations in 1006971us (51640.0 ops/sec): 69.7 MB/s Did 8840 AES-256-GCM (8192 bytes) seal operations in 1013294us (8724.0 ops/sec): 71.5 MB/s After: Did 4994000 AES-128-GCM (16 bytes) seal operations in 1000017us (4993915.1 ops/sec): 79.9 MB/s Did 1389000 AES-128-GCM (1350 bytes) seal operations in 1000073us (1388898.6 ops/sec): 1875.0 MB/s Did 319000 AES-128-GCM (8192 bytes) seal operations in 1000101us (318967.8 ops/sec): 2613.0 MB/s Did 4668000 AES-256-GCM (16 bytes) seal operations in 1000149us (4667304.6 ops/sec): 74.7 MB/s Did 1202000 AES-256-GCM (1350 bytes) seal operations in 1000646us (1201224.0 ops/sec): 1621.7 MB/s Did 269000 AES-256-GCM (8192 bytes) seal operations in 1002804us (268247.8 ops/sec): 2197.5 MB/s Change-Id: Id848562bd4e1aa79a4683012501dfa5e6c08cfcc Reviewed-on: https://boringssl-review.googlesource.com/11262 Reviewed-by: Adam Langley <agl@google.com> Commit-Queue: Adam Langley <agl@google.com> CQ-Verified: CQ bot account: commit-bot@chromium.org <commit-bot@chromium.org>
8 yıl önce
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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. #elif defined(OPENSSL_ARM) || defined(OPENSSL_AARCH64)
  49. #include <openssl/arm_arch.h>
  50. #if defined(OPENSSL_STATIC_ARMCAP)
  51. uint32_t OPENSSL_armcap_P =
  52. #if defined(OPENSSL_STATIC_ARMCAP_NEON) || defined(__ARM_NEON__)
  53. ARMV7_NEON |
  54. #endif
  55. #if defined(OPENSSL_STATIC_ARMCAP_AES)
  56. ARMV8_AES |
  57. #endif
  58. #if defined(OPENSSL_STATIC_ARMCAP_SHA1)
  59. ARMV8_SHA1 |
  60. #endif
  61. #if defined(OPENSSL_STATIC_ARMCAP_SHA256)
  62. ARMV8_SHA256 |
  63. #endif
  64. #if defined(OPENSSL_STATIC_ARMCAP_PMULL)
  65. ARMV8_PMULL |
  66. #endif
  67. 0;
  68. #else
  69. uint32_t OPENSSL_armcap_P = 0;
  70. #endif
  71. #endif
  72. #if defined(OPENSSL_WINDOWS) && !defined(BORINGSSL_NO_STATIC_INITIALIZER)
  73. #define OPENSSL_CDECL __cdecl
  74. #else
  75. #define OPENSSL_CDECL
  76. #endif
  77. #if defined(BORINGSSL_NO_STATIC_INITIALIZER)
  78. static CRYPTO_once_t once = CRYPTO_ONCE_INIT;
  79. #elif defined(OPENSSL_WINDOWS)
  80. #pragma section(".CRT$XCU", read)
  81. static void __cdecl do_library_init(void);
  82. __declspec(allocate(".CRT$XCU")) void(*library_init_constructor)(void) =
  83. do_library_init;
  84. #else
  85. static void do_library_init(void) __attribute__ ((constructor));
  86. #endif
  87. /* do_library_init is the actual initialization function. If
  88. * BORINGSSL_NO_STATIC_INITIALIZER isn't defined, this is set as a static
  89. * initializer. Otherwise, it is called by CRYPTO_library_init. */
  90. static void OPENSSL_CDECL do_library_init(void) {
  91. /* WARNING: this function may only configure the capability variables. See the
  92. * note above about the linker bug. */
  93. #if defined(NEED_CPUID)
  94. OPENSSL_cpuid_setup();
  95. #endif
  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. https://crbug.com/542879 */
  101. #if defined(BORINGSSL_NO_STATIC_INITIALIZER)
  102. CRYPTO_once(&once, do_library_init);
  103. #endif
  104. }
  105. int CRYPTO_is_confidential_build(void) {
  106. #if defined(BORINGSSL_CONFIDENTIAL)
  107. return 1;
  108. #else
  109. return 0;
  110. #endif
  111. }
  112. int CRYPTO_has_asm(void) {
  113. #if defined(OPENSSL_NO_ASM)
  114. return 0;
  115. #else
  116. return 1;
  117. #endif
  118. }
  119. const char *SSLeay_version(int unused) {
  120. return "BoringSSL";
  121. }
  122. unsigned long SSLeay(void) {
  123. return OPENSSL_VERSION_NUMBER;
  124. }
  125. int CRYPTO_malloc_init(void) {
  126. return 1;
  127. }
  128. void ENGINE_load_builtin_engines(void) {}
  129. int ENGINE_register_all_complete(void) {
  130. return 1;
  131. }
  132. void OPENSSL_load_builtin_modules(void) {}
  133. int FIPS_mode(void) { return 0; }