xref: /optee_os/core/crypto/rng_hw.c (revision 4a3e6b90d93a4fac9e5261a976b278c97fb3d6e3)
1 // SPDX-License-Identifier: BSD-2-Clause
2 /* Copyright (c) 2018, Linaro Limited */
3 
4 #include <compiler.h>
5 #include <crypto/crypto.h>
6 #include <kernel/panic.h>
7 #include <rng_support.h>
8 #include <tee/tee_cryp_utl.h>
9 #include <types_ext.h>
10 
11 /* This is a HW RNG, no need for seeding */
12 TEE_Result __weak crypto_rng_init(const void *data __unused,
13 				  size_t dlen __unused)
14 {
15 	return TEE_SUCCESS;
16 }
17 
18 /* This is a HW RNG, no need to add entropy */
19 void __weak crypto_rng_add_event(enum crypto_rng_src sid __unused,
20 				 unsigned int *pnum __unused,
21 				 const void *data __unused,
22 				 size_t dlen __unused)
23 {
24 }
25 
26 TEE_Result __weak crypto_rng_read(void *buf, size_t blen)
27 {
28 	if (!buf)
29 		return TEE_ERROR_BAD_PARAMETERS;
30 
31 	return hw_get_random_bytes(buf, blen);
32 }
33