Coverage Report

Created: 2026-04-30 06:12

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/boringssl/crypto/crypto.cc
Line
Count
Source
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
using namespace bssl;
26
27
static_assert(sizeof(ossl_ssize_t) == sizeof(size_t),
28
              "ossl_ssize_t should be the same size as size_t");
29
30
31
// Our assembly does not use the GOT to reference symbols, which means
32
// references to visible symbols will often require a TEXTREL. This is
33
// undesirable, so all assembly-referenced symbols should be hidden. CPU
34
// capabilities are the only such symbols defined in C. Explicitly hide them,
35
// rather than rely on being built with -fvisibility=hidden.
36
#if defined(OPENSSL_WINDOWS)
37
#define HIDDEN
38
#else
39
#define HIDDEN __attribute__((visibility("hidden")))
40
#endif
41
42
43
// The capability variables are defined in this file in order to work around a
44
// linker bug. When linking with a .a, if no symbols in a .o are referenced
45
// then the .o is discarded, even if it has constructor functions.
46
//
47
// This still means that any binaries that don't include some functionality
48
// that tests the capability values will still skip the constructor but, so
49
// far, the init constructor function only sets the capability variables.
50
51
#if defined(BORINGSSL_DISPATCH_TEST)
52
// This value must be explicitly initialised to zero in order to work around a
53
// bug in libtool or the linker on OS X.
54
//
55
// If not initialised then it becomes a "common symbol". When put into an
56
// archive, linking on OS X will fail to resolve common symbols. By
57
// initialising it to zero, it becomes a "data symbol", which isn't so
58
// affected.
59
HIDDEN uint8_t bssl::BORINGSSL_function_hit[8] = {0};
60
#endif
61
62
#if defined(OPENSSL_X86) || defined(OPENSSL_X86_64)
63
64
// This value must be explicitly initialized to zero. See similar comment above.
65
HIDDEN uint32_t bssl::OPENSSL_ia32cap_P[4] = {0};
66
67
30.2M
uint32_t bssl::OPENSSL_get_ia32cap(int idx) {
68
30.2M
  OPENSSL_init_cpuid();
69
30.2M
  return OPENSSL_ia32cap_P[idx];
70
30.2M
}
71
72
#elif (defined(OPENSSL_ARM) || defined(OPENSSL_AARCH64)) && \
73
    !defined(OPENSSL_STATIC_ARMCAP)
74
HIDDEN uint32_t bssl::OPENSSL_armcap_P = 0;
75
76
uint32_t *bssl::OPENSSL_get_armcap_pointer_for_test() {
77
  OPENSSL_init_cpuid();
78
  return &OPENSSL_armcap_P;
79
}
80
81
uint32_t bssl::OPENSSL_get_armcap() {
82
  OPENSSL_init_cpuid();
83
  return OPENSSL_armcap_P;
84
}
85
#endif
86
87
#if defined(NEED_CPUID)
88
static bssl::CRYPTO_once_t once = CRYPTO_ONCE_INIT;
89
30.2M
void bssl::OPENSSL_init_cpuid() { CRYPTO_once(&once, OPENSSL_cpuid_setup); }
90
#endif
91
92
0
void CRYPTO_library_init() {}
93
94
0
int CRYPTO_is_confidential_build() {
95
#if defined(BORINGSSL_CONFIDENTIAL)
96
  return 1;
97
#else
98
0
  return 0;
99
0
#endif
100
0
}
101
102
0
void CRYPTO_pre_sandbox_init() {
103
  // Read from /proc/cpuinfo if needed.
104
0
  OPENSSL_init_cpuid();
105
  // Open /dev/urandom if needed.
106
0
  CRYPTO_init_sysrand();
107
  // Set up MADV_WIPEONFORK state if needed.
108
0
  CRYPTO_get_fork_generation();
109
0
}
110
111
0
const char *SSLeay_version(int which) { return OpenSSL_version(which); }
112
113
0
const char *OpenSSL_version(int which) {
114
0
  switch (which) {
115
0
    case OPENSSL_VERSION:
116
0
      return "BoringSSL";
117
0
    case OPENSSL_CFLAGS:
118
0
      return "compiler: n/a";
119
0
    case OPENSSL_BUILT_ON:
120
0
      return "built on: n/a";
121
0
    case OPENSSL_PLATFORM:
122
0
      return "platform: n/a";
123
0
    case OPENSSL_DIR:
124
0
      return "OPENSSLDIR: n/a";
125
0
    default:
126
0
      return "not available";
127
0
  }
128
0
}
129
130
0
unsigned long SSLeay() { return OPENSSL_VERSION_NUMBER; }
131
132
0
unsigned long OpenSSL_version_num() { return OPENSSL_VERSION_NUMBER; }
133
134
0
int CRYPTO_malloc_init() { return 1; }
135
136
0
int OPENSSL_malloc_init() { return 1; }
137
138
0
void ENGINE_load_builtin_engines() {}
139
140
0
int ENGINE_register_all_complete() { return 1; }
141
142
0
void ENGINE_cleanup() {}
143
144
0
void OPENSSL_load_builtin_modules() {}
145
146
0
int OPENSSL_init_crypto(uint64_t opts, const OPENSSL_INIT_SETTINGS *settings) {
147
0
  return 1;
148
0
}
149
150
0
void OPENSSL_cleanup() {}
151
152
0
FILE *bssl::CRYPTO_get_stderr() { return stderr; }