/src/boringssl/crypto/crypto.cc
Line | Count | Source (jump to first uncovered line) |
1 | | // Copyright 2014 The BoringSSL Authors |
2 | | // |
3 | | // Licensed under the Apache License, Version 2.0 (the "License"); |
4 | | // you may not use this file except in compliance with the License. |
5 | | // You may obtain a copy of the License at |
6 | | // |
7 | | // https://www.apache.org/licenses/LICENSE-2.0 |
8 | | // |
9 | | // Unless required by applicable law or agreed to in writing, software |
10 | | // distributed under the License is distributed on an "AS IS" BASIS, |
11 | | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | | // See the License for the specific language governing permissions and |
13 | | // limitations under the License. |
14 | | |
15 | | #include <openssl/crypto.h> |
16 | | |
17 | | #include <assert.h> |
18 | | #include <stdio.h> |
19 | | |
20 | | #include "bcm_support.h" |
21 | | #include "fipsmodule/rand/internal.h" |
22 | | #include "internal.h" |
23 | | |
24 | | |
25 | | static_assert(sizeof(ossl_ssize_t) == sizeof(size_t), |
26 | | "ossl_ssize_t should be the same size as size_t"); |
27 | | |
28 | | |
29 | | // Our assembly does not use the GOT to reference symbols, which means |
30 | | // references to visible symbols will often require a TEXTREL. This is |
31 | | // undesirable, so all assembly-referenced symbols should be hidden. CPU |
32 | | // capabilities are the only such symbols defined in C. Explicitly hide them, |
33 | | // rather than rely on being built with -fvisibility=hidden. |
34 | | #if defined(OPENSSL_WINDOWS) |
35 | | #define HIDDEN |
36 | | #else |
37 | | #define HIDDEN __attribute__((visibility("hidden"))) |
38 | | #endif |
39 | | |
40 | | |
41 | | // The capability variables are defined in this file in order to work around a |
42 | | // linker bug. When linking with a .a, if no symbols in a .o are referenced |
43 | | // then the .o is discarded, even if it has constructor functions. |
44 | | // |
45 | | // This still means that any binaries that don't include some functionality |
46 | | // that tests the capability values will still skip the constructor but, so |
47 | | // far, the init constructor function only sets the capability variables. |
48 | | |
49 | | #if defined(BORINGSSL_DISPATCH_TEST) |
50 | | // This value must be explicitly initialised to zero in order to work around a |
51 | | // bug in libtool or the linker on OS X. |
52 | | // |
53 | | // If not initialised then it becomes a "common symbol". When put into an |
54 | | // archive, linking on OS X will fail to resolve common symbols. By |
55 | | // initialising it to zero, it becomes a "data symbol", which isn't so |
56 | | // affected. |
57 | | HIDDEN uint8_t BORINGSSL_function_hit[8] = {0}; |
58 | | #endif |
59 | | |
60 | | #if defined(OPENSSL_X86) || defined(OPENSSL_X86_64) |
61 | | |
62 | | // This value must be explicitly initialized to zero. See similar comment above. |
63 | | HIDDEN uint32_t OPENSSL_ia32cap_P[4] = {0}; |
64 | | |
65 | 35.8M | uint32_t OPENSSL_get_ia32cap(int idx) { |
66 | 35.8M | OPENSSL_init_cpuid(); |
67 | 35.8M | return OPENSSL_ia32cap_P[idx]; |
68 | 35.8M | } |
69 | | |
70 | | #elif (defined(OPENSSL_ARM) || defined(OPENSSL_AARCH64)) && \ |
71 | | !defined(OPENSSL_STATIC_ARMCAP) |
72 | | HIDDEN uint32_t OPENSSL_armcap_P = 0; |
73 | | |
74 | | uint32_t *OPENSSL_get_armcap_pointer_for_test(void) { |
75 | | OPENSSL_init_cpuid(); |
76 | | return &OPENSSL_armcap_P; |
77 | | } |
78 | | |
79 | | uint32_t OPENSSL_get_armcap(void) { |
80 | | OPENSSL_init_cpuid(); |
81 | | return OPENSSL_armcap_P; |
82 | | } |
83 | | #endif |
84 | | |
85 | | #if defined(NEED_CPUID) |
86 | | static CRYPTO_once_t once = CRYPTO_ONCE_INIT; |
87 | 35.8M | void OPENSSL_init_cpuid(void) { CRYPTO_once(&once, OPENSSL_cpuid_setup); } |
88 | | #endif |
89 | | |
90 | 0 | void CRYPTO_library_init(void) {} |
91 | | |
92 | 0 | int CRYPTO_is_confidential_build(void) { |
93 | | #if defined(BORINGSSL_CONFIDENTIAL) |
94 | | return 1; |
95 | | #else |
96 | 0 | return 0; |
97 | 0 | #endif |
98 | 0 | } |
99 | | |
100 | 0 | void CRYPTO_pre_sandbox_init(void) { |
101 | | // Read from /proc/cpuinfo if needed. |
102 | 0 | OPENSSL_init_cpuid(); |
103 | | // Open /dev/urandom if needed. |
104 | 0 | CRYPTO_init_sysrand(); |
105 | | // Set up MADV_WIPEONFORK state if needed. |
106 | 0 | CRYPTO_get_fork_generation(); |
107 | 0 | } |
108 | | |
109 | 0 | const char *SSLeay_version(int which) { return OpenSSL_version(which); } |
110 | | |
111 | 0 | const char *OpenSSL_version(int which) { |
112 | 0 | switch (which) { |
113 | 0 | case OPENSSL_VERSION: |
114 | 0 | return "BoringSSL"; |
115 | 0 | case OPENSSL_CFLAGS: |
116 | 0 | return "compiler: n/a"; |
117 | 0 | case OPENSSL_BUILT_ON: |
118 | 0 | return "built on: n/a"; |
119 | 0 | case OPENSSL_PLATFORM: |
120 | 0 | return "platform: n/a"; |
121 | 0 | case OPENSSL_DIR: |
122 | 0 | return "OPENSSLDIR: n/a"; |
123 | 0 | default: |
124 | 0 | return "not available"; |
125 | 0 | } |
126 | 0 | } |
127 | | |
128 | 0 | unsigned long SSLeay(void) { return OPENSSL_VERSION_NUMBER; } |
129 | | |
130 | 0 | unsigned long OpenSSL_version_num(void) { return OPENSSL_VERSION_NUMBER; } |
131 | | |
132 | 0 | int CRYPTO_malloc_init(void) { return 1; } |
133 | | |
134 | 0 | int OPENSSL_malloc_init(void) { return 1; } |
135 | | |
136 | 0 | void ENGINE_load_builtin_engines(void) {} |
137 | | |
138 | 0 | int ENGINE_register_all_complete(void) { return 1; } |
139 | | |
140 | 0 | void OPENSSL_load_builtin_modules(void) {} |
141 | | |
142 | 0 | int OPENSSL_init_crypto(uint64_t opts, const OPENSSL_INIT_SETTINGS *settings) { |
143 | 0 | return 1; |
144 | 0 | } |
145 | | |
146 | 0 | void OPENSSL_cleanup(void) {} |
147 | | |
148 | 0 | FILE *CRYPTO_get_stderr(void) { return stderr; } |