/src/boringssl/crypto/rand_extra/rand_extra.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* Copyright (c) 2017, 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 | | #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 | 72.9k | RAND_METHOD *RAND_OpenSSL(void) { return RAND_SSLeay(); } |
65 | | |
66 | 0 | const RAND_METHOD *RAND_get_rand_method(void) { return RAND_SSLeay(); } |
67 | | |
68 | 3 | 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 | } |