• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright 2023 The BoringSSL Authors
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 "../bcm_support.h"
18 #include "sysrand_internal.h"
19 
20 #if defined(OPENSSL_RAND_TRUSTY)
21 #include <stdint.h>
22 #include <stdlib.h>
23 
24 #include <sys/types.h>
25 #include <uapi/err.h>
26 
27 #include <lib/rng/trusty_rng.h>
28 
CRYPTO_init_sysrand(void)29 void CRYPTO_init_sysrand(void) {}
30 
CRYPTO_sysrand(uint8_t * out,size_t requested)31 void CRYPTO_sysrand(uint8_t *out, size_t requested) {
32   if (trusty_rng_hw_rand(out, requested) != NO_ERROR) {
33     abort();
34   }
35 }
36 
CRYPTO_sysrand_if_available(uint8_t * buf,size_t len)37 int CRYPTO_sysrand_if_available(uint8_t *buf, size_t len) {
38   CRYPTO_sysrand(buf, len);
39   return 1;
40 }
41 
CRYPTO_sysrand_for_seed(uint8_t * out,size_t requested)42 void CRYPTO_sysrand_for_seed(uint8_t *out, size_t requested) {
43   CRYPTO_sysrand(out, requested);
44 }
45 
46 #endif  // OPENSSL_RAND_TRUSTY
47