iPXE
Macros | Functions | Variables
entropy_sample.c File Reference

Entropy sampling. More...

#include <stdio.h>
#include <ipxe/entropy.h>
#include <ipxe/test.h>

Go to the source code of this file.

Macros

#define SAMPLE_COUNT   65536
 Total number of test samples. More...
 
#define SAMPLE_BLOCKSIZE   256
 Number of samples per block. More...
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
static void entropy_sample (struct entropy_source *source)
 Generate entropy samples for external testing. More...
 
static void entropy_sample_test_exec (void)
 Generate entropy samples for external testing. More...
 

Variables

struct self_test entropy_sample_test __self_test
 Entropy sampling self-test. More...
 

Detailed Description

Entropy sampling.

Definition in file entropy_sample.c.

Macro Definition Documentation

◆ SAMPLE_COUNT

#define SAMPLE_COUNT   65536

Total number of test samples.

Definition at line 37 of file entropy_sample.c.

◆ SAMPLE_BLOCKSIZE

#define SAMPLE_BLOCKSIZE   256

Number of samples per block.

Definition at line 40 of file entropy_sample.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ entropy_sample()

static void entropy_sample ( struct entropy_source source)
static

Generate entropy samples for external testing.

Parameters
sourceEntropy source

Definition at line 47 of file entropy_sample.c.

47  {
48  static noise_sample_t samples[SAMPLE_BLOCKSIZE];
49  unsigned int i;
50  unsigned int j;
51  int rc;
52 
53  /* Collect and print blocks of samples */
54  for ( i = 0 ; i < ( SAMPLE_COUNT / SAMPLE_BLOCKSIZE ) ; i++ ) {
55 
56  /* Collect one block of samples */
57  rc = entropy_enable ( source );
58  ok ( rc == 0 );
59  for ( j = 0 ; j < SAMPLE_BLOCKSIZE ; j++ ) {
60  rc = get_noise ( source, &samples[j] );
61  ok ( rc == 0 );
62  }
63  entropy_disable ( source );
64 
65  /* Print out sample values */
66  for ( j = 0 ; j < SAMPLE_BLOCKSIZE ; j++ ) {
67  printf ( "SAMPLE %s %d %d\n", source->name,
68  ( i * SAMPLE_BLOCKSIZE + j ), samples[j] );
69  }
70  }
71 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
int printf(const char *fmt,...)
Write a formatted string to the console.
Definition: vsprintf.c:464
const char * name
Name.
Definition: entropy.h:118
#define SAMPLE_COUNT
Total number of test samples.
static int get_noise(struct entropy_source *source, noise_sample_t *noise)
Get noise sample.
Definition: entropy.h:208
int entropy_enable(struct entropy_source *source)
Enable entropy gathering.
Definition: entropy.c:302
#define SAMPLE_BLOCKSIZE
Number of samples per block.
uint8_t noise_sample_t
A noise sample.
Definition: entropy.h:21
void entropy_disable(struct entropy_source *source)
Disable entropy gathering.
Definition: entropy.c:385
#define ok(success)
Definition: test.h:46

References entropy_disable(), entropy_enable(), get_noise(), entropy_source::name, ok, printf(), rc, SAMPLE_BLOCKSIZE, and SAMPLE_COUNT.

Referenced by entropy_sample_test_exec().

◆ entropy_sample_test_exec()

static void entropy_sample_test_exec ( void  )
static

Generate entropy samples for external testing.

Definition at line 77 of file entropy_sample.c.

77  {
78  struct entropy_source *source;
79 
80  /* Test each entropy source */
82  entropy_sample ( source );
83  }
84 }
static void entropy_sample(struct entropy_source *source)
Generate entropy samples for external testing.
#define ENTROPY_SOURCES
Entropy source table.
Definition: entropy.h:169
An entropy source.
Definition: entropy.h:116
#define for_each_table_entry(pointer, table)
Iterate through all entries within a linker table.
Definition: tables.h:385

References entropy_sample(), ENTROPY_SOURCES, and for_each_table_entry.

Variable Documentation

◆ __self_test

struct self_test entropy_sample_test __self_test
Initial value:
= {
.name = "entropy_sample",
}
static void entropy_sample_test_exec(void)
Generate entropy samples for external testing.

Entropy sampling self-test.

Definition at line 87 of file entropy_sample.c.