iPXE
Macros | Functions
rtc_entropy.h File Reference

RTC-based entropy source. More...

#include <stdint.h>

Go to the source code of this file.

Macros

#define ENTROPY_PREFIX_rtc   __rtc_
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
static __always_inline min_entropy_t ENTROPY_INLINE (rtc, min_entropy_per_sample)(void)
 min-entropy per sample More...
 
uint8_t rtc_sample (void)
 Measure a single RTC tick. More...
 
static __always_inline int ENTROPY_INLINE (rtc, get_noise)(noise_sample_t *noise)
 Get noise sample. More...
 

Detailed Description

RTC-based entropy source.

Definition in file rtc_entropy.h.

Macro Definition Documentation

◆ ENTROPY_PREFIX_rtc

#define ENTROPY_PREFIX_rtc   __rtc_

Definition at line 17 of file rtc_entropy.h.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ ENTROPY_INLINE() [1/2]

static __always_inline min_entropy_t ENTROPY_INLINE ( rtc  ,
min_entropy_per_sample   
)
inlinestatic

min-entropy per sample

Return values
min_entropymin-entropy of each sample

Definition at line 26 of file rtc_entropy.h.

26  {
27 
28  /* The min-entropy has been measured on several platforms
29  * using the entropy_sample test code. Modelling the samples
30  * as independent, and using a confidence level of 99.99%, the
31  * measurements were as follows:
32  *
33  * qemu-kvm : 7.38 bits
34  * VMware : 7.46 bits
35  * Physical hardware : 2.67 bits
36  *
37  * We choose the lowest of these (2.67 bits) and apply a 50%
38  * safety margin to allow for some potential non-independence
39  * of samples.
40  */
41  return MIN_ENTROPY ( 1.3 );
42 }
#define MIN_ENTROPY(bits)
Construct a min-entropy fixed-point value.
Definition: entropy.h:71

References MIN_ENTROPY.

◆ rtc_sample()

uint8_t rtc_sample ( void  )

Measure a single RTC tick.

Return values
deltaLength of RTC tick (in TSC units)

Definition at line 214 of file rtc_entropy.c.

214  {
215  uint32_t before;
216  uint32_t after;
217  uint32_t temp;
218 
220  REAL_CODE ( /* Enable interrupts */
221  "sti\n\t"
222  /* Wait for RTC interrupt */
223  "movb %b2, %%cs:rtc_flag\n\t"
224  "\n1:\n\t"
225  "xchgb %b2, %%cs:rtc_flag\n\t" /* Serialize */
226  "testb %b2, %b2\n\t"
227  "jz 1b\n\t"
228  /* Read "before" TSC */
229  "rdtsc\n\t"
230  /* Store "before" TSC on stack */
231  "pushl %0\n\t"
232  /* Wait for another RTC interrupt */
233  "xorb %b2, %b2\n\t"
234  "movb %b2, %%cs:rtc_flag\n\t"
235  "\n1:\n\t"
236  "xchgb %b2, %%cs:rtc_flag\n\t" /* Serialize */
237  "testb %b2, %b2\n\t"
238  "jz 1b\n\t"
239  /* Read "after" TSC */
240  "rdtsc\n\t"
241  /* Retrieve "before" TSC on stack */
242  "popl %1\n\t"
243  /* Disable interrupts */
244  "cli\n\t"
245  )
246  : "=a" ( after ), "=d" ( before ), "=Q" ( temp )
247  : "2" ( 0 ) );
248 
249  return ( after - before );
250 }
unsigned int uint32_t
Definition: stdint.h:12
__asm__ __volatile__("\n1:\n\t" "movb -1(%2,%1), %%al\n\t" "stosb\n\t" "loop 1b\n\t" "xorl %%eax, %%eax\n\t" "mov %3, %1\n\t" "rep stosb\n\t" :"=&D"(discard_D), "=&c"(discard_c) :"r"(data), "g"(pad_len), "0"(value0), "1"(len) :"eax")
__asm__(".section \".rodata\", \"a\", " PROGBITS "\n\t" "\nprivate_key_data:\n\t" ".size private_key_data, ( . - private_key_data )\n\t" ".equ private_key_len, ( . - private_key_data )\n\t" ".previous\n\t")
#define REAL_CODE(asm_code_str)
Definition: libkir.h:226

References __asm__(), __volatile__(), and REAL_CODE.

Referenced by ENTROPY_INLINE().

◆ ENTROPY_INLINE() [2/2]

static __always_inline int ENTROPY_INLINE ( rtc  ,
get_noise   
)
inlinestatic

Get noise sample.

Return values
noiseNoise sample
rcReturn status code

Definition at line 53 of file rtc_entropy.h.

53  {
54 
55  /* Get sample */
56  *noise = rtc_sample();
57 
58  /* Always successful */
59  return 0;
60 }
uint8_t rtc_sample(void)
Measure a single RTC tick.
Definition: rtc_entropy.c:214

References rtc_sample().