Coverage Report

Created: 2024-11-21 07:03

/src/boringssl/crypto/fipsmodule/rand/internal.h
Line
Count
Source (jump to first uncovered line)
1
/* Copyright (c) 2015, 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
15
#ifndef OPENSSL_HEADER_CRYPTO_RAND_INTERNAL_H
16
#define OPENSSL_HEADER_CRYPTO_RAND_INTERNAL_H
17
18
#include <openssl/aes.h>
19
#include <openssl/ctrdrbg.h>
20
21
#include "../../bcm_support.h"
22
#include "../modes/internal.h"
23
24
#if defined(__cplusplus)
25
extern "C" {
26
#endif
27
28
// rand_fork_unsafe_buffering_enabled returns whether fork-unsafe buffering has
29
// been enabled via |RAND_enable_fork_unsafe_buffering|.
30
int rand_fork_unsafe_buffering_enabled(void);
31
32
// CTR_DRBG_STATE contains the state of a CTR_DRBG based on AES-256. See SP
33
// 800-90Ar1.
34
struct ctr_drbg_state_st {
35
  AES_KEY ks;
36
  block128_f block;
37
  ctr128_f ctr;
38
  uint8_t counter[16];
39
  uint64_t reseed_counter;
40
};
41
42
// CTR_DRBG_init initialises |*drbg| given |CTR_DRBG_ENTROPY_LEN| bytes of
43
// entropy in |entropy| and, optionally, a personalization string up to
44
// |CTR_DRBG_ENTROPY_LEN| bytes in length. It returns one on success and zero
45
// on error.
46
OPENSSL_EXPORT int CTR_DRBG_init(CTR_DRBG_STATE *drbg,
47
                                 const uint8_t entropy[CTR_DRBG_ENTROPY_LEN],
48
                                 const uint8_t *personalization,
49
                                 size_t personalization_len);
50
51
#if defined(OPENSSL_X86_64) && !defined(OPENSSL_NO_ASM)
52
53
OPENSSL_INLINE int have_rdrand(void) {
54
  return CRYPTO_is_RDRAND_capable();
55
}
56
57
// have_fast_rdrand returns true if RDRAND is supported and it's reasonably
58
// fast. Concretely the latter is defined by whether the chip is Intel (fast) or
59
// not (assumed slow).
60
OPENSSL_INLINE int have_fast_rdrand(void) {
61
  return CRYPTO_is_RDRAND_capable() && CRYPTO_is_intel_cpu();
62
}
63
64
// CRYPTO_rdrand writes eight bytes of random data from the hardware RNG to
65
// |out|. It returns one on success or zero on hardware failure.
66
int CRYPTO_rdrand(uint8_t out[8]);
67
68
// CRYPTO_rdrand_multiple8_buf fills |len| bytes at |buf| with random data from
69
// the hardware RNG. The |len| argument must be a multiple of eight. It returns
70
// one on success and zero on hardware failure.
71
int CRYPTO_rdrand_multiple8_buf(uint8_t *buf, size_t len);
72
73
#else  // OPENSSL_X86_64 && !OPENSSL_NO_ASM
74
75
0
OPENSSL_INLINE int have_rdrand(void) {
76
0
  return 0;
77
0
}
Unexecuted instantiation: bcm.c:have_rdrand
Unexecuted instantiation: crypto.c:have_rdrand
Unexecuted instantiation: forkunsafe.c:have_rdrand
78
79
3.32k
OPENSSL_INLINE int have_fast_rdrand(void) {
80
3.32k
  return 0;
81
3.32k
}
bcm.c:have_fast_rdrand
Line
Count
Source
79
3.32k
OPENSSL_INLINE int have_fast_rdrand(void) {
80
3.32k
  return 0;
81
3.32k
}
Unexecuted instantiation: crypto.c:have_fast_rdrand
Unexecuted instantiation: forkunsafe.c:have_fast_rdrand
82
83
#endif  // OPENSSL_X86_64 && !OPENSSL_NO_ASM
84
85
86
#if defined(__cplusplus)
87
}  // extern C
88
#endif
89
90
#endif  // OPENSSL_HEADER_CRYPTO_RAND_INTERNAL_H