Преглед на файлове

[Minor] Another asan fix for rdrand

tags/2.0
Vsevolod Stakhov преди 4 години
родител
ревизия
d3a9edd737
променени са 1 файла, в които са добавени 3 реда и са изтрити 3 реда
  1. 3
    3
      contrib/libottery/ottery_entropy_rdrand.c

+ 3
- 3
contrib/libottery/ottery_entropy_rdrand.c Целия файл

extern int ottery_valgrind_; extern int ottery_valgrind_;
/** Helper: invoke the RDRAND instruction to get 4 random bytes in the output /** Helper: invoke the RDRAND instruction to get 4 random bytes in the output
* value. Return 1 on success, and 0 on failure. */ * value. Return 1 on success, and 0 on failure. */
#define rdrand32(x) ({ unsigned char err = 0; asm volatile(".byte 0x0f; .byte 0xc7; .byte 0xf0; setc %1":"=a"(*x), "=qm"(err)); err; })
#define rdrand32(x) ({ unsigned char err = 0; __asm volatile(".byte 0x0f; .byte 0xc7; .byte 0xf0; setc %1":"=a"(x), "=qm"(err) :"a"(0) :"cc"); err; })


/** Generate bytes using the Intel RDRAND instruction. */ /** Generate bytes using the Intel RDRAND instruction. */
static int static int
if (! (ottery_get_cpu_capabilities_() & OTTERY_CPUCAP_RAND) || ottery_valgrind_) if (! (ottery_get_cpu_capabilities_() & OTTERY_CPUCAP_RAND) || ottery_valgrind_)
return OTTERY_ERR_INIT_STRONG_RNG; return OTTERY_ERR_INIT_STRONG_RNG;
while (outlen >= 4) { while (outlen >= 4) {
if (rdrand32(&up) != 1)
if (rdrand32(up) != 1)
return OTTERY_ERR_INIT_STRONG_RNG; return OTTERY_ERR_INIT_STRONG_RNG;
memcpy (out, &up, sizeof (up)); memcpy (out, &up, sizeof (up));
out += sizeof (up); out += sizeof (up);
} }


if (outlen) { if (outlen) {
if (rdrand32(&up) != 1)
if (rdrand32(up) != 1)
return OTTERY_ERR_INIT_STRONG_RNG; return OTTERY_ERR_INIT_STRONG_RNG;
memcpy(out, &up, outlen); memcpy(out, &up, outlen);
} }

Loading…
Отказ
Запис