1 #if !defined(MBEDTLS_CONFIG_FILE) 2 #include "mbedtls/config.h" 3 #else 4 #include MBEDTLS_CONFIG_FILE 5 #endif 6 7 #if !defined(MBEDTLS_CTR_DRBG_C) 8 9 #include "mbedtls/ctr_drbg.h" 10 11 #include <string.h> 12 #if defined(CONFIG_TEE_CA) 13 #include <drv/tee.h> 14 #endif _tls_random(unsigned char * output,size_t output_len)15static void _tls_random(unsigned char *output, size_t output_len) 16 { 17 #if defined(CONFIG_TEE_CA) 18 csi_tee_rand_generate(output, output_len); 19 #else 20 int i; 21 uint32_t random; 22 int mod = output_len % 4; 23 int count = 0; 24 static uint32_t rnd = 0x12345; 25 for (i = 0; i < output_len / 4; i++) { 26 random = rnd * 0xFFFF777; 27 rnd = random; 28 output[count++] = (random >> 24) & 0xFF; 29 output[count++] = (random >> 16) & 0xFF; 30 output[count++] = (random >> 8) & 0xFF; 31 output[count++] = (random) & 0xFF; 32 } 33 random = rnd * 0xFFFF777; 34 rnd = random; 35 for (i = 0; i < mod; i++) { 36 output[i + count] = (random >> 8 * i) & 0xFF; 37 } 38 #endif 39 } 40 mbedtls_ctr_drbg_init(mbedtls_ctr_drbg_context * ctx)41void mbedtls_ctr_drbg_init( mbedtls_ctr_drbg_context *ctx ) 42 { 43 (void)ctx; 44 } 45 mbedtls_ctr_drbg_random(void * p_rng,unsigned char * output,size_t output_len)46int mbedtls_ctr_drbg_random(void *p_rng, unsigned char *output, size_t output_len) 47 { 48 (void)p_rng; 49 _tls_random(output, output_len); 50 return 0; 51 } 52 mbedtls_ctr_drbg_free(mbedtls_ctr_drbg_context * ctx)53void mbedtls_ctr_drbg_free( mbedtls_ctr_drbg_context *ctx ) 54 { 55 (void)ctx; 56 } 57 58 #endif /* MBEDTLS_CTR_DRBG_C */