blob: e15ecb85d1be308125b0e335f05a5135c6ba45ad [file] [log] [blame]
Robert Sloan572a4e22017-04-17 10:52:19 -07001/* 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
Robert Sloan9254e682017-04-24 09:42:06 -070015#if !defined(_GNU_SOURCE)
Robert Sloan8f860b12017-08-28 07:37:06 -070016#define _GNU_SOURCE // needed for syscall() on Linux.
Robert Sloan9254e682017-04-24 09:42:06 -070017#endif
18
Robert Sloan572a4e22017-04-17 10:52:19 -070019#include <openssl/crypto.h>
Robert Sloan309a31e2018-01-29 10:22:47 -080020
21#include <stdlib.h>
22
23#include <openssl/digest.h>
Robert Sloan572a4e22017-04-17 10:52:19 -070024#include <openssl/hmac.h>
Robert Sloan8ff03552017-06-14 12:40:58 -070025#include <openssl/sha.h>
Robert Sloan572a4e22017-04-17 10:52:19 -070026
27#include "../internal.h"
28
29#include "aes/aes.c"
30#include "aes/key_wrap.c"
31#include "aes/mode_wrappers.c"
Robert Sloan8ff03552017-06-14 12:40:58 -070032#include "bn/add.c"
33#include "bn/asm/x86_64-gcc.c"
34#include "bn/bn.c"
35#include "bn/bytes.c"
36#include "bn/cmp.c"
37#include "bn/ctx.c"
38#include "bn/div.c"
Adam Vartanianbfcf3a72018-08-10 14:55:24 +010039#include "bn/div_extra.c"
Robert Sloan8ff03552017-06-14 12:40:58 -070040#include "bn/exponentiation.c"
41#include "bn/gcd.c"
Adam Vartanianbfcf3a72018-08-10 14:55:24 +010042#include "bn/gcd_extra.c"
Robert Sloan8ff03552017-06-14 12:40:58 -070043#include "bn/generic.c"
44#include "bn/jacobi.c"
45#include "bn/montgomery.c"
46#include "bn/montgomery_inv.c"
47#include "bn/mul.c"
48#include "bn/prime.c"
49#include "bn/random.c"
50#include "bn/rsaz_exp.c"
51#include "bn/shift.c"
52#include "bn/sqrt.c"
53#include "cipher/aead.c"
54#include "cipher/cipher.c"
55#include "cipher/e_aes.c"
56#include "cipher/e_des.c"
57#include "des/des.c"
Robert Sloan572a4e22017-04-17 10:52:19 -070058#include "digest/digest.c"
59#include "digest/digests.c"
Adam Vartanianbfcf3a72018-08-10 14:55:24 +010060#include "ecdh/ecdh.c"
Robert Sloan8ff03552017-06-14 12:40:58 -070061#include "ecdsa/ecdsa.c"
62#include "ec/ec.c"
63#include "ec/ec_key.c"
64#include "ec/ec_montgomery.c"
Robert Sloanc6ebb282018-04-30 10:10:26 -070065#include "ec/felem.c"
Robert Sloan8ff03552017-06-14 12:40:58 -070066#include "ec/oct.c"
67#include "ec/p224-64.c"
Robert Sloan55818102017-12-18 11:26:17 -080068#include "../../third_party/fiat/p256.c"
Robert Sloan8ff03552017-06-14 12:40:58 -070069#include "ec/p256-x86_64.c"
Robert Sloan5cbb5c82018-04-24 11:35:46 -070070#include "ec/scalar.c"
Robert Sloan8ff03552017-06-14 12:40:58 -070071#include "ec/simple.c"
Robert Sloanc6ebb282018-04-30 10:10:26 -070072#include "ec/simple_mul.c"
Robert Sloan55818102017-12-18 11:26:17 -080073#include "ec/util.c"
Robert Sloan8ff03552017-06-14 12:40:58 -070074#include "ec/wnaf.c"
Robert Sloan572a4e22017-04-17 10:52:19 -070075#include "hmac/hmac.c"
76#include "md4/md4.c"
77#include "md5/md5.c"
Robert Sloan9254e682017-04-24 09:42:06 -070078#include "modes/cbc.c"
Srinivas Paladugudd42a612019-08-09 19:30:39 +000079#include "modes/ccm.c"
Robert Sloan9254e682017-04-24 09:42:06 -070080#include "modes/cfb.c"
81#include "modes/ctr.c"
82#include "modes/gcm.c"
83#include "modes/ofb.c"
84#include "modes/polyval.c"
85#include "rand/ctrdrbg.c"
86#include "rand/rand.c"
87#include "rand/urandom.c"
Robert Sloan8ff03552017-06-14 12:40:58 -070088#include "rsa/blinding.c"
89#include "rsa/padding.c"
90#include "rsa/rsa.c"
91#include "rsa/rsa_impl.c"
Robert Sloan309a31e2018-01-29 10:22:47 -080092#include "self_check/self_check.c"
Robert Sloan572a4e22017-04-17 10:52:19 -070093#include "sha/sha1-altivec.c"
94#include "sha/sha1.c"
95#include "sha/sha256.c"
96#include "sha/sha512.c"
Robert Sloan978112c2018-01-22 12:53:01 -080097#include "tls/kdf.c"
Robert Sloan572a4e22017-04-17 10:52:19 -070098
99
Robert Sloan978112c2018-01-22 12:53:01 -0800100#if defined(BORINGSSL_FIPS)
101
102#if !defined(OPENSSL_ASAN)
Srinivas Paladugudd42a612019-08-09 19:30:39 +0000103// These symbols are filled in by delocate.go. They point to the start and end
104// of the module, and the location of the integrity hash, respectively.
Robert Sloan978112c2018-01-22 12:53:01 -0800105extern const uint8_t BORINGSSL_bcm_text_start[];
106extern const uint8_t BORINGSSL_bcm_text_end[];
107extern const uint8_t BORINGSSL_bcm_text_hash[];
108#endif
109
110static void __attribute__((constructor))
111BORINGSSL_bcm_power_on_self_test(void) {
112 CRYPTO_library_init();
113
114#if !defined(OPENSSL_ASAN)
115 // Integrity tests cannot run under ASAN because it involves reading the full
116 // .text section, which triggers the global-buffer overflow detection.
117 const uint8_t *const start = BORINGSSL_bcm_text_start;
118 const uint8_t *const end = BORINGSSL_bcm_text_end;
119
120 static const uint8_t kHMACKey[64] = {0};
121 uint8_t result[SHA512_DIGEST_LENGTH];
122
123 unsigned result_len;
Srinivas Paladugudd42a612019-08-09 19:30:39 +0000124 if (!HMAC(EVP_sha512(), kHMACKey, sizeof(kHMACKey), start, end - start,
125 result, &result_len) ||
Robert Sloan978112c2018-01-22 12:53:01 -0800126 result_len != sizeof(result)) {
Robert Sloanf068def2018-10-10 18:45:40 -0700127 fprintf(stderr, "HMAC failed.\n");
Robert Sloan978112c2018-01-22 12:53:01 -0800128 goto err;
129 }
130
131 const uint8_t *expected = BORINGSSL_bcm_text_hash;
132
133 if (!check_test(expected, result, sizeof(result), "FIPS integrity test")) {
134 goto err;
135 }
136#endif
137
138 if (!BORINGSSL_self_test()) {
139 goto err;
140 }
141
Robert Sloan572a4e22017-04-17 10:52:19 -0700142 return;
143
144err:
Robert Sloan8ff03552017-06-14 12:40:58 -0700145 BORINGSSL_FIPS_abort();
146}
147
148void BORINGSSL_FIPS_abort(void) {
Robert Sloan572a4e22017-04-17 10:52:19 -0700149 for (;;) {
Robert Sloan572a4e22017-04-17 10:52:19 -0700150 abort();
Robert Sloan8ff03552017-06-14 12:40:58 -0700151 exit(1);
Robert Sloan572a4e22017-04-17 10:52:19 -0700152 }
153}
Robert Sloan978112c2018-01-22 12:53:01 -0800154
Robert Sloan8f860b12017-08-28 07:37:06 -0700155#endif // BORINGSSL_FIPS