1 /*
2 * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved.
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
16 #if !defined(MBEDTLS_CONFIG_FILE)
17 #include "mbedtls/config.h"
18 #else
19 #include MBEDTLS_CONFIG_FILE
20 #endif
21
22 #include <string.h>
23
24 #if defined(MBEDTLS_ENTROPY_C)
25
26 #include "mbedtls/entropy.h"
27 #include "entropy_poll.h"
28
29 #if defined(MBEDTLS_TEST_NULL_ENTROPY)
30 #include "stdlib.h"
31 #include "hal_trng.h"
mbedtls_null_entropy_poll(void * data,unsigned char * output,size_t len,size_t * olen)32 int mbedtls_null_entropy_poll( void *data,
33 unsigned char *output, size_t len, size_t *olen )
34 {
35 ((void) data);
36 ((void) output);
37 int ret;
38 uint32_t i;
39
40 len = len > HAL_TRNG_DATA_LEN ? HAL_TRNG_DATA_LEN : len;
41 ret = hal_get_trngdata(output, len);
42 if (ret) {
43 for (i = 0; i < len; i++) {
44 output[i] = rand() & 0xFF;
45 }
46 }
47
48 *olen = len;
49 return( 0 );
50 }
51 #endif
52 #endif /* MBEDTLS_ENTROPY_C */