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