x86 asm: move rdrand from x86-assembly-cheat

This commit is contained in:
Ciro Santilli 六四事件 法轮功
2019-06-16 00:00:00 +00:00
parent 4ee1e06299
commit 4d4b82f248
3 changed files with 35 additions and 0 deletions

View File

@@ -12416,6 +12416,22 @@ link:userland/arch/x86_64/loop.S[LOOP]
Vs <<x86-jcc-instructions,Jcc>>: https://stackoverflow.com/questions/6805692/x86-assembly-programming-loops-with-ecx-and-loop-instruction-versus-jmp-jcond Holy CISC! Vs <<x86-jcc-instructions,Jcc>>: https://stackoverflow.com/questions/6805692/x86-assembly-programming-loops-with-ecx-and-loop-instruction-versus-jmp-jcond Holy CISC!
=== x86 random number generator instructions
<<intel-manual-1>> 5.1.15 Random Number Generator Instructions
Example: link:userland/arch/x86_64/rdrand.S[RDRAND]
If you run that executable multiple times, it prints a random number every time to stdout.
RDRAND is a true random number generator!
This Intel engineer says its based on quantum effects: https://stackoverflow.com/questions/17616960/true-random-numbers-with-c11-and-rdrand/18004959#18004959
Generated some polemic when kernel devs wanted to use it as part of `/dev/random`, because it could be used as a cryptographic backdoor by Intel since it is a black box.
RDRAND sets the carry flag when data is ready so we must loop if the carry flag isn't set.
=== x86 SIMD === x86 SIMD
History: History:

8
lkmc.c
View File

@@ -56,6 +56,14 @@ void lkmc_assert_memcmp(
} }
} }
void lkmc_print_hex_64(uint64_t x) {
printf("0x%016" PRIx64, x);
}
void lkmc_print_newline() {
printf("\n");
}
#if defined(__aarch64__) #if defined(__aarch64__)
#define LKMC_SYSREG_READ_WRITE(type, name) \ #define LKMC_SYSREG_READ_WRITE(type, name) \
type LKMC_CONCAT(LKMC_CONCAT(LKMC_SYSREG_SYMBOL_PREFIX, name), _read(void)) { \ type LKMC_CONCAT(LKMC_CONCAT(LKMC_SYSREG_SYMBOL_PREFIX, name), _read(void)) { \

View File

@@ -0,0 +1,11 @@
/* https://github.com/cirosantilli/linux-kernel-module-cheat#x86-random-number-generator-instructions */
#include <lkmc.h>
LKMC_PROLOGUE
1:
rdrand %rdi
jnc 1b
call lkmc_print_hex_64
call lkmc_print_newline
LKMC_EPILOGUE