Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
 
 
 
 
 
 

156 рядки
4.0 KiB

  1. /* Copyright (c) 2017, 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. #if !defined(_GNU_SOURCE)
  15. #define _GNU_SOURCE // needed for syscall() on Linux.
  16. #endif
  17. #include <openssl/crypto.h>
  18. #include <stdlib.h>
  19. #include <openssl/digest.h>
  20. #include <openssl/hmac.h>
  21. #include <openssl/sha.h>
  22. #include "../internal.h"
  23. #include "aes/aes.c"
  24. #include "aes/key_wrap.c"
  25. #include "aes/mode_wrappers.c"
  26. #include "bn/add.c"
  27. #include "bn/asm/x86_64-gcc.c"
  28. #include "bn/bn.c"
  29. #include "bn/bytes.c"
  30. #include "bn/cmp.c"
  31. #include "bn/ctx.c"
  32. #include "bn/div.c"
  33. #include "bn/div_extra.c"
  34. #include "bn/exponentiation.c"
  35. #include "bn/gcd.c"
  36. #include "bn/gcd_extra.c"
  37. #include "bn/generic.c"
  38. #include "bn/jacobi.c"
  39. #include "bn/montgomery.c"
  40. #include "bn/montgomery_inv.c"
  41. #include "bn/mul.c"
  42. #include "bn/prime.c"
  43. #include "bn/random.c"
  44. #include "bn/rsaz_exp.c"
  45. #include "bn/shift.c"
  46. #include "bn/sqrt.c"
  47. #include "cipher/aead.c"
  48. #include "cipher/cipher.c"
  49. #include "cipher/e_aes.c"
  50. #include "cipher/e_des.c"
  51. #include "des/des.c"
  52. #include "digest/digest.c"
  53. #include "digest/digests.c"
  54. #include "ecdh/ecdh.c"
  55. #include "ecdsa/ecdsa.c"
  56. #include "ec/ec.c"
  57. #include "ec/ec_key.c"
  58. #include "ec/ec_montgomery.c"
  59. #include "ec/felem.c"
  60. #include "ec/oct.c"
  61. #include "ec/p224-64.c"
  62. #include "../../third_party/fiat/p256.c"
  63. #include "ec/p256-x86_64.c"
  64. #include "ec/scalar.c"
  65. #include "ec/simple.c"
  66. #include "ec/simple_mul.c"
  67. #include "ec/util.c"
  68. #include "ec/wnaf.c"
  69. #include "hmac/hmac.c"
  70. #include "md4/md4.c"
  71. #include "md5/md5.c"
  72. #include "modes/cbc.c"
  73. #include "modes/ccm.c"
  74. #include "modes/cfb.c"
  75. #include "modes/ctr.c"
  76. #include "modes/gcm.c"
  77. #include "modes/ofb.c"
  78. #include "modes/polyval.c"
  79. #include "rand/ctrdrbg.c"
  80. #include "rand/rand.c"
  81. #include "rand/urandom.c"
  82. #include "rsa/blinding.c"
  83. #include "rsa/padding.c"
  84. #include "rsa/rsa.c"
  85. #include "rsa/rsa_impl.c"
  86. #include "self_check/self_check.c"
  87. #include "sha/sha1-altivec.c"
  88. #include "sha/sha1.c"
  89. #include "sha/sha256.c"
  90. #include "sha/sha512.c"
  91. #include "tls/kdf.c"
  92. #if defined(BORINGSSL_FIPS)
  93. #if !defined(OPENSSL_ASAN)
  94. // These symbols are filled in by delocate.go. They point to the start and end
  95. // of the module, and the location of the integrity hash, respectively.
  96. extern const uint8_t BORINGSSL_bcm_text_start[];
  97. extern const uint8_t BORINGSSL_bcm_text_end[];
  98. extern const uint8_t BORINGSSL_bcm_text_hash[];
  99. #endif
  100. static void __attribute__((constructor))
  101. BORINGSSL_bcm_power_on_self_test(void) {
  102. CRYPTO_library_init();
  103. #if !defined(OPENSSL_ASAN)
  104. // Integrity tests cannot run under ASAN because it involves reading the full
  105. // .text section, which triggers the global-buffer overflow detection.
  106. const uint8_t *const start = BORINGSSL_bcm_text_start;
  107. const uint8_t *const end = BORINGSSL_bcm_text_end;
  108. static const uint8_t kHMACKey[64] = {0};
  109. uint8_t result[SHA512_DIGEST_LENGTH];
  110. unsigned result_len;
  111. if (!HMAC(EVP_sha512(), kHMACKey, sizeof(kHMACKey), start, end - start,
  112. result, &result_len) ||
  113. result_len != sizeof(result)) {
  114. fprintf(stderr, "HMAC failed.\n");
  115. goto err;
  116. }
  117. const uint8_t *expected = BORINGSSL_bcm_text_hash;
  118. if (!check_test(expected, result, sizeof(result), "FIPS integrity test")) {
  119. goto err;
  120. }
  121. #endif
  122. if (!BORINGSSL_self_test()) {
  123. goto err;
  124. }
  125. return;
  126. err:
  127. BORINGSSL_FIPS_abort();
  128. }
  129. void BORINGSSL_FIPS_abort(void) {
  130. for (;;) {
  131. abort();
  132. exit(1);
  133. }
  134. }
  135. #endif // BORINGSSL_FIPS