Coverage Report

Created: 2025-06-11 06:40

/src/boringssl/crypto/rand/rand.cc
Line
Count
Source (jump to first uncovered line)
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
0
int RAND_bytes(uint8_t *buf, size_t len) {
24
0
  BCM_rand_bytes(buf, len);
25
0
  return 1;
26
0
}
27
28
0
int RAND_pseudo_bytes(uint8_t *buf, size_t len) { return RAND_bytes(buf, len); }
29
30
0
void RAND_seed(const void *buf, int num) {
31
  // OpenSSH calls |RAND_seed| before jailing on the assumption that any needed
32
  // file descriptors etc will be opened.
33
0
  uint8_t unused;
34
0
  RAND_bytes(&unused, sizeof(unused));
35
0
}
36
37
0
int RAND_load_file(const char *path, long num) {
38
0
  if (num < 0) {  // read the "whole file"
39
0
    return 1;
40
0
  } else if (num <= INT_MAX) {
41
0
    return (int)num;
42
0
  } else {
43
0
    return INT_MAX;
44
0
  }
45
0
}
46
47
0
const char *RAND_file_name(char *buf, size_t num) { return NULL; }
48
49
0
void RAND_add(const void *buf, int num, double entropy) {}
50
51
0
int RAND_egd(const char *path) { return 255; }
52
53
0
int RAND_poll(void) { return 1; }
54
55
0
int RAND_status(void) { return 1; }
56
57
static const struct rand_meth_st kSSLeayMethod = {
58
    RAND_seed, RAND_bytes,        RAND_cleanup,
59
    RAND_add,  RAND_pseudo_bytes, RAND_status,
60
};
61
62
0
RAND_METHOD *RAND_SSLeay(void) { return (RAND_METHOD *)&kSSLeayMethod; }
63
64
0
RAND_METHOD *RAND_OpenSSL(void) { return RAND_SSLeay(); }
65
66
0
const RAND_METHOD *RAND_get_rand_method(void) { return RAND_SSLeay(); }
67
68
0
int RAND_set_rand_method(const RAND_METHOD *method) { return 1; }
69
70
0
void RAND_cleanup(void) {}
71
72
0
void RAND_get_system_entropy_for_custom_prng(uint8_t *buf, size_t len) {
73
0
  if (len > 256) {
74
0
    abort();
75
0
  }
76
0
  CRYPTO_sysrand_for_seed(buf, len);
77
0
}