Browse Source

[rng] Add entropy sample generator

Allow a list of raw noise samples to be generated for offline
analysis.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 12 years ago
parent
commit
5d2e65c60f
1 changed files with 70 additions and 0 deletions
  1. 70
    0
      src/tests/entropy_sample.c

+ 70
- 0
src/tests/entropy_sample.c View File

@@ -0,0 +1,70 @@
1
+/*
2
+ * Copyright (C) 2012 Michael Brown <mbrown@fensystems.co.uk>.
3
+ *
4
+ * This program is free software; you can redistribute it and/or
5
+ * modify it under the terms of the GNU General Public License as
6
+ * published by the Free Software Foundation; either version 2 of the
7
+ * License, or any later version.
8
+ *
9
+ * This program is distributed in the hope that it will be useful, but
10
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
+ * General Public License for more details.
13
+ *
14
+ * You should have received a copy of the GNU General Public License
15
+ * along with this program; if not, write to the Free Software
16
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
+ */
18
+
19
+FILE_LICENCE ( GPL2_OR_LATER );
20
+
21
+/** @file
22
+ *
23
+ * Entropy sampling
24
+ *
25
+ */
26
+
27
+#include <stdio.h>
28
+#include <ipxe/entropy.h>
29
+#include <ipxe/test.h>
30
+
31
+/** Total number of test samples */
32
+#define SAMPLE_COUNT 65536
33
+
34
+/** Number of samples per block */
35
+#define SAMPLE_BLOCKSIZE 256
36
+
37
+/**
38
+ * Generate entropy samples for external testing
39
+ *
40
+ */
41
+static void entropy_sample_test_exec ( void ) {
42
+	static noise_sample_t samples[SAMPLE_BLOCKSIZE];
43
+	unsigned int i;
44
+	unsigned int j;
45
+	int rc;
46
+
47
+	/* Collect and print blocks of samples */
48
+	for ( i = 0 ; i < ( SAMPLE_COUNT / SAMPLE_BLOCKSIZE ) ; i++ ) {
49
+
50
+		/* Collect one block of samples */
51
+		entropy_enable();
52
+		for ( j = 0 ; j < SAMPLE_BLOCKSIZE ; j++ ) {
53
+			rc = get_noise ( &samples[j] );
54
+			ok ( rc == 0 );
55
+		}
56
+		entropy_disable();
57
+
58
+		/* Print out sample values */
59
+		for ( j = 0 ; j < SAMPLE_BLOCKSIZE ; j++ ) {
60
+			printf ( "SAMPLE %d %d\n", ( i * SAMPLE_BLOCKSIZE + j ),
61
+				 samples[j] );
62
+		}
63
+	}
64
+}
65
+
66
+/** Entropy sampling self-test */
67
+struct self_test entropy_sample_test __self_test = {
68
+	.name = "entropy_sample",
69
+	.exec = entropy_sample_test_exec,
70
+};

Loading…
Cancel
Save