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 <openssl/rand.h>
16
17#include <limits.h>
18
19
20void RAND_seed(const void *buf, int num) {
21 // OpenSSH calls |RAND_seed| before jailing on the assumption that any needed
22 // file descriptors etc will be opened.
23 uint8_t unused;
24 RAND_bytes(&unused, sizeof(unused));
25}
26
27int RAND_load_file(const char *path, long num) {
28 if (num < 0) { // read the "whole file"
29 return 1;
30 } else if (num <= INT_MAX) {
31 return (int) num;
32 } else {
33 return INT_MAX;
34 }
35}
36
37const char *RAND_file_name(char *buf, size_t num) { return NULL; }
38
39void RAND_add(const void *buf, int num, double entropy) {}
40
41int RAND_egd(const char *path) {
42 return 255;
43}
44
45int RAND_poll(void) {
46 return 1;
47}
48
49int RAND_status(void) {
50 return 1;
51}
52
53static const struct rand_meth_st kSSLeayMethod = {
54 RAND_seed,
55 RAND_bytes,
56 RAND_cleanup,
57 RAND_add,
58 RAND_pseudo_bytes,
59 RAND_status,
60};
61
62RAND_METHOD *RAND_SSLeay(void) {
63 return (RAND_METHOD*) &kSSLeayMethod;
64}
65
66const RAND_METHOD *RAND_get_rand_method(void) { return RAND_SSLeay(); }
67
68void RAND_set_rand_method(const RAND_METHOD *method) {}
69
70void RAND_cleanup(void) {}
71