• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 // Copyright (C) 2022 Beken Corporation
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://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 #if !defined(MBEDTLS_CONFIG_FILE)
16 #include "mbedtls/config.h"
17 #else
18 #include MBEDTLS_CONFIG_FILE
19 #endif
20 
21 #include <sys/types.h>
22 #include <stdlib.h>
23 #include <stdio.h>
24 
25 #if defined(MBEDTLS_ENTROPY_HARDWARE_ALT)
26 
os_get_random(unsigned char * buf,size_t len)27 static int os_get_random(unsigned char *buf, size_t len)
28 {
29 	    int i, j;
30 	        unsigned long tmp;
31 
32 		    for (i = 0; i < (((int)len + 3) & ~3) / 4; i++) {
33 			            tmp = rand();
34 
35 				            for (j = 0; j < 4; j++) {
36 						                if ((i * 4 + j) < (int)len) {
37 									                buf[i * 4 + j] = (unsigned char)(tmp >> (j * 8));
38 											            } else {
39 													                    break;
40 															                }
41 								        }
42 					        }
43 
44 		        return 0;
45 }
46 
mbedtls_hardware_poll(void * data,unsigned char * output,size_t len,size_t * olen)47 int mbedtls_hardware_poll( void *data,
48 		                           unsigned char *output, size_t len, size_t *olen )
49 {
50 	    (void)data;
51 	    os_get_random(output, len);
52 	    *olen = len;
53 
54 	    return 0;
55 }
56 #endif
57 
58 
59