iPXE
Defines | Functions
rtc_entropy.h File Reference

RTC-based entropy source. More...

#include <stdint.h>

Go to the source code of this file.

Defines

#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
uint8_t rtc_sample (void)
 Measure a single RTC tick.
static __always_inline int ENTROPY_INLINE (rtc, get_noise)(noise_sample_t *noise)
 Get noise sample.

Detailed Description

RTC-based entropy source.

Definition in file rtc_entropy.h.


Define Documentation

#define ENTROPY_PREFIX_rtc   __rtc_

Definition at line 17 of file rtc_entropy.h.


Function Documentation

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )
static __always_inline min_entropy_t ENTROPY_INLINE ( rtc  ,
min_entropy_per_sample   
) [inline, static]

min-entropy per sample

Return values:
min_entropymin-entropy of each sample

Definition at line 26 of file rtc_entropy.h.

References MIN_ENTROPY.

                                                        {

        /* The min-entropy has been measured on several platforms
         * using the entropy_sample test code.  Modelling the samples
         * as independent, and using a confidence level of 99.99%, the
         * measurements were as follows:
         *
         *    qemu-kvm          : 7.38 bits
         *    VMware            : 7.46 bits
         *    Physical hardware : 2.67 bits
         *
         * We choose the lowest of these (2.67 bits) and apply a 50%
         * safety margin to allow for some potential non-independence
         * of samples.
         */
        return MIN_ENTROPY ( 1.3 );
}
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.

References __asm__(), and REAL_CODE.

Referenced by ENTROPY_INLINE().

                            {
        uint32_t before;
        uint32_t after;
        uint32_t temp;

        __asm__ __volatile__ (
                REAL_CODE ( /* Enable interrupts */
                            "sti\n\t"
                            /* Wait for RTC interrupt */
                            "movb %b2, %%cs:rtc_flag\n\t"
                            "\n1:\n\t"
                            "xchgb %b2, %%cs:rtc_flag\n\t" /* Serialize */
                            "testb %b2, %b2\n\t"
                            "jz 1b\n\t"
                            /* Read "before" TSC */
                            "rdtsc\n\t"
                            /* Store "before" TSC on stack */
                            "pushl %0\n\t"
                            /* Wait for another RTC interrupt */
                            "xorb %b2, %b2\n\t"
                            "movb %b2, %%cs:rtc_flag\n\t"
                            "\n1:\n\t"
                            "xchgb %b2, %%cs:rtc_flag\n\t" /* Serialize */
                            "testb %b2, %b2\n\t"
                            "jz 1b\n\t"
                            /* Read "after" TSC */
                            "rdtsc\n\t"
                            /* Retrieve "before" TSC on stack */
                            "popl %1\n\t"
                            /* Disable interrupts */
                            "cli\n\t"
                            )
                : "=a" ( after ), "=d" ( before ), "=Q" ( temp )
                : "2" ( 0 ) );

        return ( after - before );
}
static __always_inline int ENTROPY_INLINE ( rtc  ,
get_noise   
) [inline, static]

Get noise sample.

Return values:
noiseNoise sample
rcReturn status code

Definition at line 53 of file rtc_entropy.h.

References rtc_sample().

                                                            {

        /* Get sample */
        *noise = rtc_sample();

        /* Always successful */
        return 0;
}