Esempio n. 1
0
size_t rdrand_get_uint64_array_retry(uint64_t *dest, size_t size, int retry_limit) {
  int rc;
  int retry_count;
  size_t generated_64 = 0;
  size_t i;
  uint64_t x_64;

  if ( retry_limit < 0 ) retry_limit = RETRY_LIMIT;

  for ( i=0; i<size; ++i) {
    retry_count = 0;
    do {
      rc=rdrand64_step( &x_64 );
      ++retry_count;
    } while((rc == 0) && (retry_count < retry_limit));

    if (rc == 1) {
      *dest = x_64;
      ++dest;
      ++generated_64;
    } else {
      return generated_64;
    }
  }
  return generated_64;
}
Esempio n. 2
0
size_t rdrand_get_uint32_array_retry(uint32_t *dest, size_t size, int retry_limit) {
  int rc;
  int retry_count;
  size_t generated_32 = 0;
  size_t generated_64 = 0;

  size_t count_64 = size / 2;;
  size_t count_32 = size - 2 * count_64;
  size_t i;

  uint32_t x_32;
  uint64_t x_64;
  uint64_t* dest_64;

  if ( retry_limit < 0 ) retry_limit = RETRY_LIMIT;

  if ( count_32 > 0 ) {
    retry_count = 0;
    do {
      rc=rdrand32_step( &x_32 );
      ++retry_count;
    } while((rc == 0) || (retry_count < retry_limit));

    if (rc == 1) {
      *dest = x_32;
      ++dest;
      ++generated_32;
    } else {
      return generated_32;
    }
  }

  dest_64 = (uint64_t* ) dest;

  for ( i=0; i<count_64; ++i) {
    retry_count = 0;
    do {
      rc=rdrand64_step( &x_64 );
      ++retry_count;
    } while((rc == 0) || (retry_count < retry_limit));

    if (rc == 1) {
      *dest_64 = x_64;
      ++dest_64;
      ++generated_64;
    } else {
      generated_32 += 2 * generated_64;
      return generated_32;
    }
  }
  generated_32 += 2 * generated_64;
  return generated_32;
}
Esempio n. 3
0
END_TEST


START_TEST (rdrand_step_64_stub)
{
  unsigned char dst[DEST_SIZE] = {0};
  ck_assert_int_eq (rdrand64_step((uint64_t *)&dst),RDRAND_SUCCESS);
  
  // test if it wrote just into the place it should
  ck_assert(test_zeros(dst, DEST_SIZE, 8, DEST_SIZE));
  
  // test if it set all to 1
  ck_assert(test_ones(dst, DEST_SIZE, 0, 8));
}
Esempio n. 4
0
int rdrand64_retry (unsigned int retries, uint64_t *rand)
{
	unsigned int count= 0;

	while ( count <= retries ) {
		if ( rdrand64_step(rand) ) {
			return 1;
		}

		++count;
	}

	return 0;
}
Esempio n. 5
0
int fill_uint64_step(uint64_t* buf, int size, int retry_limit)
{
	int j,k;
	int rc;

	for (j=0; j<size; ++j)
	{
		k = 0;
		do
		{
			rc = rdrand64_step (&buf[j] );
			++k;
		}
		while ( rc == RDRAND_FAILURE && k < retry_limit);
	}
	return size;
}
Esempio n. 6
0
int rdrand_get_uint64_retry(uint64_t *dest, int retry_limit) {
  int rc;
  int count;
  uint64_t x;

  if ( retry_limit < 0 ) retry_limit = RETRY_LIMIT;
  count = 0;
  do {
    rc=rdrand64_step( &x );
    ++count;
  } while((rc == 0) || (count < retry_limit));

  if (rc == 1) {
    *dest = x;
    return 1;
  } else {
    return 0;
  }
}
Esempio n. 7
0
size_t rdrand_get_uint8_array_retry(uint8_t *dest, size_t size, int retry_limit) {
  int rc;
  int retry_count;
  size_t generated_8 = 0;
  size_t generated_64 = 0;

  size_t count_64 = size / 8;
  size_t count_8 = size % 8;
  size_t i;

  uint64_t x_64;
  uint64_t* dest_64;

  if ( retry_limit < 0 ) retry_limit = RETRY_LIMIT;

  if ( count_8 > 0 ) {
    retry_count = 0;
    do {
      rc=rdrand64_step( &x_64 );
      ++retry_count;
    } while((rc == 0) || (retry_count < retry_limit));

    if (rc == 1) {
#if 0
      for (i=0; i<count_8;++i) {
        *dest = (uint8_t)(x_64 & 0xff);
        x_64 = x_64 >> 8;
        ++dest;
        ++generated_8;
      }
#else
      memcpy((void*) dest, (void*) &x_64, count_8);
      dest += count_8;
      generated_8 = count_8;
#endif
    } else {
      return generated_8;