Exemple #1
0
static int ALL_RRI_GenerateBlock(byte *output, size_t size, unsigned int safety)
{
	CRYPTOPP_ASSERT((output && size) || !(output || size));
#if CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_X32
	word32 val;
#else
	word64 val;
#endif

	while (size >= sizeof(val))
	{
#if CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_X32
		if (_rdrand32_step((word32*)output))
#else
		// Cast due to GCC, http://github.com/weidai11/cryptopp/issues/236
		if (_rdrand64_step(reinterpret_cast<unsigned long long*>(output)))
#endif
		{
			output += sizeof(val);
			size -= sizeof(val);
		}
		else
		{
			if (!safety--)
			{
				CRYPTOPP_ASSERT(0);
				return 0;
			}
		}
	}

	if (size)
	{
#if CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_X32
		if (_rdrand32_step(&val))
#else
		// Cast due to GCC, http://github.com/weidai11/cryptopp/issues/236
		if (_rdrand64_step(reinterpret_cast<unsigned long long*>(&val)))
#endif
		{
			memcpy(output, &val, size);
			size = 0;
		}
		else
		{
			if (!safety--)
			{
				CRYPTOPP_ASSERT(0);
				return 0;
			}
		}
	}

	SecureWipeBuffer(&val, 1);

	return int(size == 0);
}
static int ALL_RRI_GenerateBlock(byte *output, size_t size, unsigned int safety)
{
	assert((output && size) || !(output || size));
#if CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_X32
	word32 val;
#else
	word64 val;
#endif

	while (size >= sizeof(val))
	{
#if CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_X32
		if (_rdrand32_step((word32*)output))
#else
		if (_rdrand64_step((word64*)output))
#endif
		{
			output += sizeof(val);
			size -= sizeof(val);
		}
		else
		{
			if (!safety--)
			{
				assert(0);
				return 0;
			}
		}
	}

	if (size)
	{
#if CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_X32
		if (_rdrand32_step(&val))
#else
		if (_rdrand64_step(&val))
#endif
		{
			memcpy(output, &val, size);
			size = 0;
		}
		else
		{
			if (!safety--)
			{
				assert(0);
				return 0;
			}
		}
	}

	SecureWipeBuffer(&val, 1);

	return int(size == 0);
}
Exemple #3
0
/* Return a random value, using hardware operations.  */
extern unsigned long long
hardware_rand64 (void)
{
    unsigned long long int x;
    while (! _rdrand64_step (&x))
        continue;
    return x;
}
Exemple #4
0
inline bool rdrand(
    UIntType *rand, std::integral_constant<std::size_t, sizeof(std::uint64_t)>)
{
#if defined(VSMC_MSVC) || (defined(VSMC_INTEL) && VSMC_INTEL_VERSION < 1600)
    unsigned __int64 r;
#else
    unsigned long long r;
#endif
    int cf = _rdrand64_step(&r);
    *rand = static_cast<UIntType>(r);

    return cf != 0;
}
void rand_bytes(uint8_t *buf, int size) {
	int i = 0, j;
	unsigned long long r;

	while (i < size) {
#ifdef __RDRND__
		while (_rdrand64_step(&r) == 0);
#else
#error "RdRand not available, check your compiler settings."
#endif
		for (j = 0; i < size && j < sizeof(ull_t); i++, j++) {
			buf[i] = r & 0xFF;
		}
	}
}
Exemple #6
0
void main(void)
{


#if 1
    /*
     *  1 Word,
     *  2 Byte,
     *  4 Kb
     *
     *  #define Bit (1)    Single Binary Digit (1 or 0)
     *  #define KB (1<<4)  Kilobyte
     *  #define MB (1<<8)  Megabyte (MB)   1,024 Kilobytes
     *  #define GB (1<<12) Gigabyte (GB)   1,024 Megabytes
     *  #define TB (1<<16) Terabyte (TB)   1,024 Gigabytes
     *  #define PB (1<<20) Petabyte (PB)   1,024 Terabytes
     *  #define EB (1<<24) Exabyte (EB)    1,024 Petabytes
     */
    #define BUFSIZE (1<<24)

    unsigned int ok, i;
    unsigned long long *rand = malloc(BUFSIZE*sizeof(unsigned long long)),
                       *seed = malloc(BUFSIZE*sizeof(unsigned long long));

    clock_t start, end, bm;
    // RDRAND (the benchmark)
    start = clock();
    for (i = 0; i < BUFSIZE; i++) {
      while (!_rdrand64_step(&rand[i]))
          ;
    }
    bm = clock() - start;
    printf("RDRAND: %li\n", bm);

    // RDSEED
    start = clock();
    for (i = 0; i < BUFSIZE; i++) {
      while (!_rdseed64_step(&seed[i]))
          ;
    }
    end = clock();
    exit(0);
#endif

    printf("Linked List Testing\n");
    // Master thread
    head = create_list(NULL,0,0);


// Choice 1: Create a server socket
    // Create a server socket.
    // Client socket will connect and update the linked list

// Choice 2:
    // Shared Memory buffer so that threads can read from the shared memory buffer.
    //

// Choice 3:
    // Message Queue Processing the linked list

}
Exemple #7
0
inline int rdrand64_step(uint64_t *x) { return _rdrand64_step ( (unsigned long long*) x ); }