From d21248b995ec2ae02e41315536a6a02bb826a023 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 21 Jun 2016 21:22:50 -0400 Subject: [PATCH] Use _rdrand32_step for X32. Whitespace --- rdrand.S | 52 ++++++++++++++-------------- rdrand.cpp | 100 ++++++++++++++++++++++++++--------------------------- 2 files changed, 76 insertions(+), 76 deletions(-) diff --git a/rdrand.S b/rdrand.S index 74da74cb..4a8f387a 100644 --- a/rdrand.S +++ b/rdrand.S @@ -120,19 +120,19 @@ NASM_RRA_GenerateBlock: cmp bsize, MWSIZE jb .Partial_Machine_Word - + .Full_Machine_Word: %ifdef X32 mov [buffer+4], eax ;; We can only move 4 at a time - DB 048h ;; Combined, these result in + DB 048h ;; Combined, these result in shr eax, 32 ;; `shr rax, 32` %endif mov [buffer], eax add buffer, MWSIZE ;; No need for Intel Core 2 slow word workarounds, sub bsize, MWSIZE ;; like `lea buffer,[buffer+MWSIZE]` for faster adds - + ;; Continue jmp .GenerateBlock_Top @@ -148,7 +148,7 @@ NASM_RRA_GenerateBlock: mov [buffer], eax add buffer, 4 - DB 048h ;; Combined, these result in + DB 048h ;; Combined, these result in shr eax, 32 ;; `shr rax, 32` .Bit_2_Not_Set: @@ -161,9 +161,9 @@ NASM_RRA_GenerateBlock: mov [buffer], ax shr eax, 16 add buffer, 2 - + .Bit_1_Not_Set: - + ;; Test bit 0 to see if size is at least 1 test bsize, 1 jz .GenerateBlock_Success @@ -179,14 +179,14 @@ NASM_RRA_GenerateBlock: ;; Test for success (was the request completely fulfilled?) cmp bsize, 0 - je .GenerateBlock_Success - + je .GenerateBlock_Success + .GenerateBlock_Failure: xor eax, eax mov al, RDRAND_FAILURE ret - + .GenerateBlock_Success: xor eax, eax @@ -253,7 +253,7 @@ NASM_RRA_GenerateBlock: cmp bsize, MWSIZE jb .Partial_Machine_Word - + .Full_Machine_Word: mov [buffer], rax @@ -296,19 +296,19 @@ NASM_RRA_GenerateBlock: ;; We've hit all the bits jmp .GenerateBlock_Success - + .GenerateBlock_PreRet: ;; Test for success (was the request completely fulfilled?) cmp bsize, 0 je .GenerateBlock_Success - + .GenerateBlock_Failure: xor rax, rax mov al, RDRAND_FAILURE ret - + .GenerateBlock_Success: xor rax, rax @@ -382,7 +382,7 @@ NASM_RSA_GenerateBlock: ;; RDSEED is not available prior to VS2012. Just emit ;; the byte codes using DB. This is `rdseed eax`. DB 0Fh, 0C7h, 0F8h - + ;; If CF=1, the number returned by RDSEED is valid. ;; If CF=0, a random number was not available. jc .RDSEED_succeeded @@ -400,13 +400,13 @@ NASM_RSA_GenerateBlock: cmp bsize, MWSIZE jb .Partial_Machine_Word - + .Full_Machine_Word: mov [buffer], eax add buffer, MWSIZE ;; No need for Intel Core 2 slow word workarounds, sub bsize, MWSIZE ;; like `lea buffer,[buffer+MWSIZE]` for faster adds - + ;; Continue jmp .GenerateBlock_Top @@ -422,7 +422,7 @@ NASM_RSA_GenerateBlock: mov [buffer], eax add buffer, 4 - DB 048h ;; Combined, these result in + DB 048h ;; Combined, these result in shr eax, 32 ;; `shr rax, 32` .Bit_2_Not_Set: @@ -435,9 +435,9 @@ NASM_RSA_GenerateBlock: mov [buffer], ax shr eax, 16 add buffer, 2 - + .Bit_1_Not_Set: - + ;; Test bit 0 to see if size is at least 1 test bsize, 1 jz .GenerateBlock_Success @@ -453,14 +453,14 @@ NASM_RSA_GenerateBlock: ;; Test for success (was the request completely fulfilled?) cmp bsize, 0 - je .GenerateBlock_Success - + je .GenerateBlock_Success + .GenerateBlock_Failure: xor eax, eax mov al, RDSEED_FAILURE ret - + .GenerateBlock_Success: xor eax, eax @@ -527,7 +527,7 @@ NASM_RSA_GenerateBlock: cmp bsize, MWSIZE jb .Partial_Machine_Word - + .Full_Machine_Word: mov [buffer], rax @@ -570,19 +570,19 @@ NASM_RSA_GenerateBlock: ;; We've hit all the bits jmp .GenerateBlock_Success - + .GenerateBlock_PreRet: ;; Test for success (was the request completely fulfilled?) cmp bsize, 0 je .GenerateBlock_Success - + .GenerateBlock_Failure: xor rax, rax mov al, RDSEED_FAILURE ret - + .GenerateBlock_Success: xor rax, rax diff --git a/rdrand.cpp b/rdrand.cpp index 351d583e..6149315e 100644 --- a/rdrand.cpp +++ b/rdrand.cpp @@ -179,39 +179,39 @@ NAMESPACE_BEGIN(CryptoPP) static int ALL_RRI_GenerateBlock(byte *output, size_t size, unsigned int safety) { assert((output && size) || !(output || size)); -#if CRYPTOPP_BOOL_X64 || CRYTPOPP_BOOL_X32 - word64 val; -#else +#if CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_X32 word32 val; +#else + word64 val; #endif while (size >= sizeof(val)) { -#if CRYPTOPP_BOOL_X64 || CRYTPOPP_BOOL_X32 - if (_rdrand64_step((word64*)output)) -#else +#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 - { + } + else + { if (!safety--) { assert(0); return 0; } - } + } } if (size) { -#if CRYPTOPP_BOOL_X64 || CRYTPOPP_BOOL_X32 - if (_rdrand64_step(&val)) -#else +#if CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_X32 if (_rdrand32_step(&val)) +#else + if (_rdrand64_step(&val)) #endif { memcpy(output, &val, size); @@ -225,12 +225,12 @@ static int ALL_RRI_GenerateBlock(byte *output, size_t size, unsigned int safety) return 0; } } - } + } -#if CRYPTOPP_BOOL_X64 || CRYTPOPP_BOOL_X32 - *((volatile word64*)&val) = 0; -#else +#if CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_X32 *((volatile word32*)&val) = 0; +#else + *((volatile word64*)&val) = 0; #endif return int(size == 0); @@ -249,7 +249,7 @@ static int GCC_RRA_GenerateBlock(byte *output, size_t size, unsigned int safety) char rc; while (size) { - __asm__ volatile( + __asm__ volatile( #if CRYPTOPP_BOOL_X64 || CRYPTOPP_BOOL_X32 ".byte 0x48, 0x0f, 0xc7, 0xf0;\n" // rdrand rax #else @@ -259,10 +259,10 @@ static int GCC_RRA_GenerateBlock(byte *output, size_t size, unsigned int safety) : "=a" (val), "=qm" (rc) : : "cc" - ); + ); if (rc) - { + { if (size >= sizeof(val)) { #if defined(CRYPTOPP_ALLOW_UNALIGNED_DATA_ACCESS) && (CRYPTOPP_BOOL_X64 || CRYPTOPP_BOOL_X32) @@ -280,15 +280,15 @@ static int GCC_RRA_GenerateBlock(byte *output, size_t size, unsigned int safety) memcpy(output, &val, size); size = 0; } - } - else - { + } + else + { if (!safety--) { assert(0); return 0; } - } + } } #if CRYPTOPP_BOOL_X64 || CRYPTOPP_BOOL_X32 @@ -360,39 +360,39 @@ void RDRAND::DiscardBytes(size_t n) static int ALL_RSI_GenerateBlock(byte *output, size_t size, unsigned int safety) { assert((output && size) || !(output || size)); -#if CRYPTOPP_BOOL_X64 || CRYPTOPP_BOOL_X32 - word64 val; -#else +#if CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_X32 word32 val; +#else + word64 val; #endif while (size >= sizeof(val)) { -#if CRYPTOPP_BOOL_X64 || CRYPTOPP_BOOL_X32 - if (_rdseed64_step((word64*)output)) -#else +#if CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_X32 if (_rdseed32_step((word32*)output)) +#else + if (_rdseed64_step((word64*)output)) #endif - { + { output += sizeof(val); size -= sizeof(val); - } - else - { + } + else + { if (!safety--) { assert(0); return 0; } - } + } } if (size) { -#if CRYPTOPP_BOOL_X64 || CRYPTOPP_BOOL_X32 - if (_rdseed64_step(&val)) -#else +#if CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_X32 if (_rdseed32_step(&val)) +#else + if (_rdseed64_step(&val)) #endif { memcpy(output, &val, size); @@ -406,12 +406,12 @@ static int ALL_RSI_GenerateBlock(byte *output, size_t size, unsigned int safety) return 0; } } - } + } -#if CRYPTOPP_BOOL_X64 || CRYPTOPP_BOOL_X32 - *((volatile word64*)&val) = 0; -#else +#if CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_X32 *((volatile word32*)&val) = 0; +#else + *((volatile word64*)&val) = 0; #endif return int(size == 0); @@ -430,7 +430,7 @@ static int GCC_RSA_GenerateBlock(byte *output, size_t size, unsigned int safety) char rc; while (size) { - __asm__ volatile( + __asm__ volatile( #if CRYPTOPP_BOOL_X64 || CRYPTOPP_BOOL_X32 ".byte 0x48, 0x0f, 0xc7, 0xf8;\n" // rdseed rax #else @@ -440,10 +440,10 @@ static int GCC_RSA_GenerateBlock(byte *output, size_t size, unsigned int safety) : "=a" (val), "=qm" (rc) : : "cc" - ); + ); if (rc) - { + { if (size >= sizeof(val)) { #if defined(CRYPTOPP_ALLOW_UNALIGNED_DATA_ACCESS) && (CRYPTOPP_BOOL_X64 || CRYPTOPP_BOOL_X32) @@ -461,15 +461,15 @@ static int GCC_RSA_GenerateBlock(byte *output, size_t size, unsigned int safety) memcpy(output, &val, size); size = 0; } - } - else - { + } + else + { if (!safety--) { assert(0); return 0; } - } + } } #if CRYPTOPP_BOOL_X64 || CRYPTOPP_BOOL_X32