Coverage Report

Created: 2026-02-14 06:34

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/boringssl/crypto/rand/rand.cc
Line
Count
Source
1
// Copyright 2017 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 <limits.h>
16
17
#include <openssl/rand.h>
18
19
#include "../bcm_support.h"
20
#include "../fipsmodule/bcm_interface.h"
21
22
23
using namespace bssl;
24
25
358k
int RAND_bytes(uint8_t *buf, size_t len) {
26
358k
  BCM_rand_bytes(buf, len);
27
358k
  return 1;
28
358k
}
29
30
0
int RAND_pseudo_bytes(uint8_t *buf, size_t len) { return RAND_bytes(buf, len); }
31
32
0
void RAND_seed(const void *buf, int num) {
33
  // OpenSSH calls |RAND_seed| before jailing on the assumption that any needed
34
  // file descriptors etc will be opened.
35
0
  uint8_t unused;
36
0
  RAND_bytes(&unused, sizeof(unused));
37
0
}
38
39
0
int RAND_load_file(const char *path, long num) {
40
0
  if (num < 0) {  // read the "whole file"
41
0
    return 1;
42
0
  } else if (num <= INT_MAX) {
43
0
    return (int)num;
44
0
  } else {
45
0
    return INT_MAX;
46
0
  }
47
0
}
48
49
0
const char *RAND_file_name(char *buf, size_t num) { return nullptr; }
50
51
0
void RAND_add(const void *buf, int num, double entropy) {}
52
53
0
int RAND_egd(const char *path) { return 255; }
54
55
0
int RAND_poll() { return 1; }
56
57
0
int RAND_status() { return 1; }
58
59
static const struct rand_meth_st kSSLeayMethod = {
60
    RAND_seed, RAND_bytes,        RAND_cleanup,
61
    RAND_add,  RAND_pseudo_bytes, RAND_status,
62
};
63
64
0
RAND_METHOD *RAND_SSLeay() { return (RAND_METHOD *)&kSSLeayMethod; }
65
66
0
RAND_METHOD *RAND_OpenSSL() { return RAND_SSLeay(); }
67
68
0
const RAND_METHOD *RAND_get_rand_method() { return RAND_SSLeay(); }
69
70
0
int RAND_set_rand_method(const RAND_METHOD *method) { return 1; }
71
72
0
void RAND_cleanup() {}
73
74
0
void RAND_get_system_entropy_for_custom_prng(uint8_t *buf, size_t len) {
75
0
  if (len > 256) {
76
0
    abort();
77
0
  }
78
0
  CRYPTO_sysrand(buf, len);
79
0
}