Intel third-generation CPU core processor built-in hardware random number Acquisition Method

Source: Internet
Author: User

Intel's third-generation CPU core processor in the IVB architecture (which began to be produced in 2012) has a built-in feature that uses resistance thermal noise to obtain real hardware random numbers.

Philosophical arguments about the differences between real and pseudo-random numbers and whether real random numbers exist in the world are not covered in this article.

The following shows the Delphi Code. There are four functions in total. Two functions are used:

Rdrand_issupported checks whether the current CPU supports this function,

Rdrand_16 gets a 16-bit random number to the Aex register. To obtain a 32-bit or 64-bit random number, please refer to the intel development manual to modify the corresponding instructions. In addition, this function does not determine whether the CPU supports this command. Therefore, call rdrand_issupported at the beginning of the program or elsewhere to determine whether the CPU supports this function.

Function getcpuid (): uint;
VaR
Bexception: bool;
// Szcpu: array [0 .. 15] of byte;
Ucpuid: uint;
Begin
Result: = 0;
// Zeromemory (@ szcpu, sizeof (szcpu ));
Ucpuid: = 0;
Bexception: = true;

Try
ASM
MoV eax, 1
Cpuid
{Mov dword ptr szcpu [0], EBX
MoV dword ptr szcpu [4], EDX
MoV dword ptr szcpu [8], ECx
MoV eax, 1
Cpuid}
MoV ucpuid, ECx
End;
Except
Bexception: = false;
End;

If bexception then
Result: = ucpuid;
End;

Function getcpuname (): string;
VaR
Bexception: bool;
Szcpu: array [0 .. 15] of byte;
// Ucpuid: uint;
Begin
Result: = '';
Zeromemory (@ szcpu, sizeof (szcpu ));
// Ucpuid: = 0;
Bexception: = true;

Try
ASM
MoV eax, 0
// Cpuid
DB 0fh, 0a2h
MoV dword ptr szcpu [0], EBX
MoV dword ptr szcpu [4], EDX
MoV dword ptr szcpu [8], ECx
// Mov eax, 1
// Cpuid
// Mov ucpuid, EDX
End;
Except
Bexception: = false;
End;

If bexception then
Begin
Result: = strpas (pansichar (@ szcpu ));

End;
End;

Function rdrand_issupported: Boolean;
VaR info: DWORD;
SS: string;
Begin
SS: = getcpuname;
If pos ('intel ', SS) = 0 then
Begin
Result: = false;
Exit;
End;

Info: = getcpuid;

// Showmessage (inttostr (Info ));

If Info and $40000000 = $40000000 then
Result: = true
Else
Result: = false;

End;

Function rdrand_16: DWORD; // gets a 16-bit random number.
ASM
DB $ 0f, $ C7, $ F0
End;

Intel third-generation CPU core processor built-in hardware random number Acquisition Method

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.