summaryrefslogtreecommitdiffstats
path: root/src/interface
diff options
context:
space:
mode:
authorSimon Rettberg2019-04-12 11:35:24 +0200
committerSimon Rettberg2019-04-12 11:35:24 +0200
commit11826ca46ce135473d84e2abeff83916526301e2 (patch)
tree3a88dd37afca7d8f4a1a8b599545900790075230 /src/interface
parent[login] Add "--nouser" option to just ask for password (diff)
downloadipxe-11826ca46ce135473d84e2abeff83916526301e2.tar.gz
ipxe-11826ca46ce135473d84e2abeff83916526301e2.tar.xz
ipxe-11826ca46ce135473d84e2abeff83916526301e2.zip
[efi] Put rdrand workaround in sep. function
Diffstat (limited to 'src/interface')
-rw-r--r--src/interface/efi/efi_entropy.c57
1 files changed, 35 insertions, 22 deletions
diff --git a/src/interface/efi/efi_entropy.c b/src/interface/efi/efi_entropy.c
index 2dd231b22..a1dfaaa79 100644
--- a/src/interface/efi/efi_entropy.c
+++ b/src/interface/efi/efi_entropy.c
@@ -125,28 +125,6 @@ static int efi_entropy_tick ( void ) {
EFI_STATUS efirc;
int rc;
-#if defined(__i386) || defined(__x86_64)
- if ( have_hwrnd == 0 ) {
- struct x86_features features;
- x86_features( &features );
- if ( features.intel.ecx & ( 1 << 30 ) ) {
- have_hwrnd = 1;
- } else {
- have_hwrnd = 2;
- }
- DBGC( &tick, "Have RDRAND: %s\n", ( have_hwrnd == 1 ? "YES!" : "NO :-(" ) );
- }
- if ( have_hwrnd == 1 ) {
- int ret, retries = 10;
- char ok;
- while ( --retries > 0 ) {
- __asm__ volatile ( "rdrand %0; setc %1" : "=r" ( ret ), "=qm" ( ok ) );
- if ( ok )
- return ret & 0x7fffffff;
- }
- }
-#endif
-
/* Wait for next timer tick */
if ( ( efirc = bs->SetTimer ( tick, TimerRelative,
EFI_ENTROPY_TRIGGER_TIME ) ) != 0 ) {
@@ -169,6 +147,40 @@ static int efi_entropy_tick ( void ) {
}
/**
+ * Get noise sample from rdrand
+ *
+ * @ret noise Noise sample
+ * @ret rc Return status code
+ */
+static int efi_get_noise_rdrand ( noise_sample_t *noise ) {
+#if defined(__i386) || defined(__x86_64)
+ if ( have_hwrnd == 0 ) {
+ struct x86_features features;
+ x86_features( &features );
+ if ( features.intel.ecx & ( 1 << 30 ) ) {
+ have_hwrnd = 1;
+ } else {
+ have_hwrnd = 2;
+ }
+ DBGC( &tick, "Have RDRAND: %s\n", ( have_hwrnd == 1 ? "YES!" : "NO :-(" ) );
+ }
+ if ( have_hwrnd == 1 ) {
+ int ret, retries = 10;
+ char ok;
+ while ( --retries > 0 ) {
+ __asm__ volatile ( "rdrand %0; setc %1" : "=r" ( ret ), "=qm" ( ok ) );
+ if ( ok ) {
+ *noise = ret;
+ return 0;
+ }
+ }
+ return -EBUSY;
+ }
+#endif
+ return -ENOTSUP;
+}
+
+/**
* Get noise sample from timer ticks
*
* @ret noise Noise sample
@@ -244,6 +256,7 @@ static int efi_get_noise ( noise_sample_t *noise ) {
/* Try RNG first, falling back to timer ticks */
if ( ( ( rc = efi_get_noise_rng ( noise ) ) != 0 ) &&
+ ( ( rc = efi_get_noise_rdrand ( noise ) ) != 0 ) &&
( ( rc = efi_get_noise_ticks ( noise ) ) != 0 ) )
return rc;