| 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 | int RAND_bytes(uint8_t *buf, size_t len) { |
| 24 | BCM_rand_bytes(buf, len); |
| 25 | return 1; |
| 26 | } |
| 27 |
| 28 | int RAND_pseudo_bytes(uint8_t *buf, size_t len) { return RAND_bytes(buf, len); } |
| 29 |
| 30 | 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 | uint8_t unused; |
| 34 | RAND_bytes(&unused, sizeof(unused)); |
| 35 | } |
| 36 |
| 37 | int RAND_load_file(const char *path, long num) { |
| 38 | if (num < 0) { // read the "whole file" |
| 39 | return 1; |
| 40 | } else if (num <= INT_MAX) { |
| 41 | return (int)num; |
| 42 | } else { |
| 43 | return INT_MAX; |
| 44 | } |
| 45 | } |
| 46 |
| 47 | const char *RAND_file_name(char *buf, size_t num) { return NULL; } |
| 48 |
| 49 | void RAND_add(const void *buf, int num, double entropy) {} |
| 50 |
| 51 | int RAND_egd(const char *path) { return 255; } |
| 52 |
| 53 | int RAND_poll(void) { return 1; } |
| 54 |
| 55 | 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 | RAND_METHOD *RAND_SSLeay(void) { return (RAND_METHOD *)&kSSLeayMethod; } |
| 63 |
| 64 | RAND_METHOD *RAND_OpenSSL(void) { return RAND_SSLeay(); } |
| 65 |
| 66 | const RAND_METHOD *RAND_get_rand_method(void) { return RAND_SSLeay(); } |
| 67 |
| 68 | int RAND_set_rand_method(const RAND_METHOD *method) { return 1; } |
| 69 |
| 70 | void RAND_cleanup(void) {} |
| 71 |
| 72 | void RAND_get_system_entropy_for_custom_prng(uint8_t *buf, size_t len) { |
| 73 | if (len > 256) { |
| 74 | abort(); |
| 75 | } |
| 76 | CRYPTO_sysrand_for_seed(buf, len); |
| 77 | } |
| 78 |