bool test_randLIB_get_8bit() { randLIB_seed_random(); uint8_t test = randLIB_get_8bit(); if( test == 0 ) { test = randLIB_get_8bit(); if( test == 0 ) { return false; } } return true; }
void pana_session_base_init(pana_session_t *p_session) { memset(p_session, 0, sizeof(pana_session_t)); p_session->session_ready = false; p_session->key_warp = false; p_session->user_server = false; p_session->eap_id_seq = randLIB_get_8bit(); //Take Random EAP ID }
pana_session_t *pana_session_allocate(void) { pana_session_t *p_session = ns_dyn_mem_alloc(sizeof(pana_session_t)); if (p_session) { memset(p_session, 0, sizeof(pana_session_t)); p_session->session_ready = false; p_session->key_warp = false; p_session->user_server = false; p_session->eap_id_seq = randLIB_get_8bit(); //Take Random EAP ID } return p_session; }
/** * Get a random array of bytes. * Called back by mbedtls when it wants to fill a buffer with random data * Must return 0 on success. */ static int get_random(void *ctx, unsigned char *buf, size_t len) { static int initialised = 0; uint32_t i; (void)ctx; /* No context */ if (!initialised) { randLIB_seed_random(); initialised = 1; } for (i = 0; i < len; i++) { buf[i] = (uint8_t)randLIB_get_8bit(); } return 0; /* Success */ }
int entropy_poll( void *ctx, unsigned char *output, size_t len, size_t *olen ) { (void)ctx; //TODO: change to more secure random randLIB_seed_random(); char *c = (char*)ns_dyn_mem_temporary_alloc(len); if( !c ){ return MBEDTLS_ERR_ENTROPY_SOURCE_FAILED; } memset(c, 0, len); for(uint16_t i=0; i < len; i++){ *(c + i) = (char)randLIB_get_8bit(); } memmove(output, c, len); *olen = len; ns_dyn_mem_free(c); return( 0 ); }