Add UEFI RNG Protocol support. The driver will leverage Intel Secure Key technology to produce the Random Number Generator protocol, which is used to provide high-quality random numbers for use in applications, or entropy for seeding other random number generators. Refer to http://software.intel.com/en-us/articles/intel-digital-random-number-generator-drng-software-implementation-guide/ for more information about Intel Secure Key technology.

Signed-off-by: Long, Qin <qin.long@intel.com>
Reviewed-by: Fu, Siyuan <siyuan.fu@intel.com>
Reviewed-by: Rosenbaum, Lee G <lee.g.rosenbaum@intel.com>


git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@14858 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
Long, Qin
2013-11-19 01:49:49 +00:00
committed by sfu5
parent 419db80bef
commit 3aa8dc6cd3
17 changed files with 2247 additions and 0 deletions

View File

@@ -0,0 +1,95 @@
/** @file
RDRAND Support Routines for GCC environment.
Copyright (c) 2013, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
/**
Generates a 16-bit random number through RDRAND instruction.
@param[out] Rand Buffer pointer to store the random result.
@retval TRUE RDRAND call was successful.
@retval FALSE Failed attempts to call RDRAND.
**/
BOOLEAN
EFIAPI
RdRand16Step (
OUT UINT16 *Rand
)
{
UINT8 Carry;
//
// Uses byte code for RDRAND instruction,
// in case that GCC version has no direct support on RDRAND assembly.
//
__asm__ __volatile__ (
".byte 0x66; .byte 0x0f; .byte 0xc7; .byte 0xf0; setc %1"
:"=a" (*Rand),
"=qm" (Carry)
);
return (BOOLEAN) Carry;
}
/**
Generates a 32-bit random number through RDRAND instruction.
@param[out] Rand Buffer pointer to store the random result.
@retval TRUE RDRAND call was successful.
@retval FALSE Failed attempts to call RDRAND.
**/
BOOLEAN
EFIAPI
RdRand32Step (
OUT UINT32 *Rand
)
{
UINT8 Carry;
__asm__ __volatile__ (
".byte 0x0f; .byte 0xc7; .byte 0xf0; setc %1"
:"=a" (*Rand),
"=qm" (Carry)
);
return (BOOLEAN) Carry;
}
/**
Generates a 64-bit random number through RDRAND instruction.
@param[out] Rand Buffer pointer to store the random result.
@retval TRUE RDRAND call was successful.
@retval FALSE Failed attempts to call RDRAND.
**/
BOOLEAN
EFIAPI
RdRand64Step (
OUT UINT64 *Rand
)
{
UINT8 Carry;
__asm__ __volatile__ (
".byte 0x48; .byte 0x0f; .byte 0xc7; .byte 0xf0; setc %1"
:"=a" (*Rand),
"=qm" (Carry)
);
return (BOOLEAN) Carry;
}