Exemplo n.º 1
0
void rand_hw_xor(unsigned char *buf, size_t num)
{
    size_t rnd;
    if (!(OPENSSL_ia32cap_P[1] & (1 << (62 - 32))))
        return;
    while (num >= sizeof(size_t)) {
        rnd = OPENSSL_ia32_rdrand();
        if (rnd == 0)
            return;
        *((size_t *)buf) ^= rnd;
        buf += sizeof(size_t);
        num -= sizeof(size_t);
    }
    if (num) {
        rnd = OPENSSL_ia32_rdrand();
        if (rnd == 0)
            return;
        while (num) {
            *buf ^= rnd & 0xff;
            rnd >>= 8;
            buf++;
            num--;
        }
    }
}
Exemplo n.º 2
0
static int get_random_bytes (unsigned char *buf, int num)
	{
	size_t rnd;

	while (num>=(int)sizeof(size_t)) {
		if ((rnd = OPENSSL_ia32_rdrand()) == 0) return 0;

		*((size_t *)buf) = rnd;
		buf += sizeof(size_t);
		num -= sizeof(size_t);
	}
	if (num) {
		if ((rnd = OPENSSL_ia32_rdrand()) == 0) return 0;

		memcpy (buf,&rnd,num);
	}

	return 1;
	}
Exemplo n.º 3
0
static void rand_hw_seed(EVP_MD_CTX *ctx)
	{
	int i;
	if (!(OPENSSL_ia32cap_P[1] & (1<<(62-32))))
		return;
	for (i = 0; i < RDRAND_CALLS; i++)
		{
		size_t rnd;
		rnd = OPENSSL_ia32_rdrand();
		if (rnd == 0)
			return;
		MD_Update(ctx, (unsigned char *)&rnd, sizeof(size_t));
		}
	}