xref: /optee_os/core/crypto/rng_hw.c (revision 391a38544bcf9f4989b96cc5cfd47e557893394f)
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 <rng_support.h>
7 #include <tee/tee_cryp_utl.h>
8 #include <types_ext.h>
9 
10 TEE_Result __weak hw_get_random_bytes(void *buf, size_t blen)
11 {
12 	uint8_t *b = buf;
13 	size_t n = 0;
14 
15 	for (n = 0; n < blen; n++)
16 		b[n] = hw_get_random_byte();
17 
18 	return TEE_SUCCESS;
19 }
20 
21 /* This is a HW RNG, no need for seeding */
22 TEE_Result __weak crypto_rng_init(const void *data __unused,
23 				  size_t dlen __unused)
24 {
25 	return TEE_SUCCESS;
26 }
27 
28 /* This is a HW RNG, no need to add entropy */
29 void __weak crypto_rng_add_event(enum crypto_rng_src sid __unused,
30 				 unsigned int *pnum __unused,
31 				 const void *data __unused,
32 				 size_t dlen __unused)
33 {
34 }
35 
36 TEE_Result __weak crypto_rng_read(void *buf, size_t blen)
37 {
38 	if (!buf)
39 		return TEE_ERROR_BAD_PARAMETERS;
40 
41 	return hw_get_random_bytes(buf, blen);
42 }
43