int rdrand16_retry (unsigned int retries, uint16_t *rand) { unsigned int count= 0; while ( count <= retries ) { if ( rdrand16_step(rand) ) { return 1; } ++count; } return 0; }
/** *************************************************************** * fill with _step functions */ int fill_uint16_step(uint16_t* buf, int size, int retry_limit) { int j,k; int rc; for (j=0; j<size; ++j) { k = 0; do { rc = rdrand16_step ( &buf[j] ); ++k; } while ( rc == RDRAND_FAILURE && k < retry_limit); } return size; }
int rdrand_get_uint16_retry(uint16_t *dest, int retry_limit) { int rc; int count; uint16_t x; if ( retry_limit < 0 ) retry_limit = RETRY_LIMIT; count = 0; do { rc=rdrand16_step( &x ); ++count; } while((rc == 0) || (count < retry_limit)); if (rc == 1) { *dest = x; return 1; } else { return 0; } }