aboutsummaryrefslogtreecommitdiff
path: root/eim/sw/trng_tester_eim.c
diff options
context:
space:
mode:
authorPaul Selkirk <paul@psgd.org>2015-04-02 15:07:22 -0400
committerPaul Selkirk <paul@psgd.org>2015-04-02 15:07:22 -0400
commitb1ebb2a975de7f29e63c3a4046de15c26b44dceb (patch)
tree20c6e29fa7f51953a83629146bcf61ad556092ab /eim/sw/trng_tester_eim.c
parentaea9e93e560b1468bf0ff2cf5b61e5409ce60dc5 (diff)
Add trng_extractor app to eim and i2c, refactor i2c apps to use common memory map.
Diffstat (limited to 'eim/sw/trng_tester_eim.c')
-rw-r--r--eim/sw/trng_tester_eim.c78
1 files changed, 31 insertions, 47 deletions
diff --git a/eim/sw/trng_tester_eim.c b/eim/sw/trng_tester_eim.c
index 0cb9312..d25b784 100644
--- a/eim/sw/trng_tester_eim.c
+++ b/eim/sw/trng_tester_eim.c
@@ -50,13 +50,13 @@
#include "tc_eim.h"
#include "cryptech_memory_map.h"
-#define WAIT_STATS /* report number of status reads before core says "ready" */
+char *usage = "Usage: %s [-h] [-d] [-q] [-r] [-w] [-n #] tc...\n";
int debug = 0;
int quiet = 0;
int repeat = 0;
-int dump_data = 1;
int num_words = 10;
+int wait_stats = 0;
/* ---------------- sanity test case ---------------- */
@@ -80,7 +80,7 @@ int TC0()
*/
(void)time((time_t *)t);
if (tc_write(BOARD_ADDR_DUMMY, (void *)&t, 4) != 0)
- return 1;
+ return 1;
if (tc_expected(BOARD_ADDR_NAME0, board_name0, 4) ||
tc_expected(BOARD_ADDR_NAME1, board_name1, 4) ||
@@ -142,26 +142,26 @@ int TC2(void)
int TC3(void)
{
int i, n;
- unsigned long entropy;
+ uint32_t entropy;
if (!quiet)
printf("TC3: Read random data from avalanche_entropy.\n");
for (i = 0; i < num_words; ++i) {
/* check status */
- n = 0;
+ n = 0;
if (tc_wait(ENTROPY1_ADDR_STATUS, ENTROPY1_STATUS_VALID, &n) != 0)
return 1;
/* read entropy data */
if (tc_read(ENTROPY1_ADDR_ENTROPY, (uint8_t *)&entropy, 4) != 0)
return 1;
/* display entropy data */
- if (!debug)
-#ifdef WAIT_STATS
- printf("%08lx %d\n", entropy, n);
-#else
- printf("%08lx\n", entropy);
-#endif
+ if (!debug) {
+ if (wait_stats)
+ printf("%08x %d\n", entropy, n);
+ else
+ printf("%08x\n", entropy);
+ }
}
return 0;
@@ -191,26 +191,26 @@ int TC4(void)
int TC5(void)
{
int i, n;
- unsigned long entropy;
+ uint32_t entropy;
if (!quiet)
printf("TC5: Read random data from rosc_entropy.\n");
for (i = 0; i < num_words; ++i) {
/* check status */
- n = 0;
+ n = 0;
if (tc_wait(ENTROPY2_ADDR_STATUS, ENTROPY2_STATUS_VALID, &n) != 0)
return 1;
/* read entropy data */
if (tc_read(ENTROPY2_ADDR_ENTROPY, (uint8_t *)&entropy, 4) != 0)
return 1;
/* display entropy data */
- if (!debug)
-#ifdef WAIT_STATS
- printf("%08lx %d\n", entropy, n);
-#else
- printf("%08lx\n", entropy);
-#endif
+ if (!debug) {
+ if (wait_stats)
+ printf("%08x %d\n", entropy, n);
+ else
+ printf("%08x\n", entropy);
+ }
}
return 0;
@@ -231,10 +231,7 @@ int TC6(void)
/* TC7: Read random data from trng_csprng. */
int TC7(void)
{
- int i;
-#ifdef WAIT_STATS
- int n;
-#endif
+ int i, n;
uint32_t random;
if (!quiet)
@@ -242,33 +239,19 @@ int TC7(void)
for (i = 0; i < num_words; ++i) {
/* check status */
-#ifdef WAIT_STATS
- if ((n = tc_wait(CSPRNG_ADDR_STATUS, CSPRNG_STATUS_VALID)) < 0)
-#else
- if (tc_wait(CSPRNG_ADDR_STATUS, CSPRNG_STATUS_VALID) != 0)
-#endif
+ n = 0;
+ if (tc_wait(CSPRNG_ADDR_STATUS, CSPRNG_STATUS_VALID, &n) != 0)
return 1;
/* read random data */
if (tc_read(CSPRNG_ADDR_RANDOM, (uint8_t *)&random, 4) != 0)
return 1;
/* display random data */
if (!debug) {
- if (dump_data) {
- // Raw data output to std out.
- printf("%c%c%c%c", (int8_t)(random >> 24 & 0xff),
- (int8_t)(random >> 16 & 0xff),
- (int8_t)(random >> 8 & 0xff),
- (int8_t)(random & 0xff));
- }
- else
- {
-#ifdef WAIT_STATS
- printf("0x%08x %d\n", random, n);
-#else
- printf("0x%08x\n", random);
-#endif
- }
- }
+ if (wait_stats)
+ printf("%08x %d\n", random, n);
+ else
+ printf("%08x\n", random);
+ }
}
return 0;
@@ -296,11 +279,9 @@ int main(int argc, char *argv[])
{
typedef int (*tcfp)(void);
tcfp all_tests[] = { TC0, TC1, TC2, TC3, TC4, TC5, TC6, TC7 };
-
- char *usage = "Usage: %s [-h] [-d] [-q] [-r] [-n #] tc...\n";
int i, j, opt;
- while ((opt = getopt(argc, argv, "h?dqrn:")) != -1) {
+ while ((opt = getopt(argc, argv, "h?dqrn:w")) != -1) {
switch (opt) {
case 'h':
case '?':
@@ -322,6 +303,9 @@ int main(int argc, char *argv[])
return EXIT_FAILURE;
}
break;
+ case 'w':
+ wait_stats = 1;
+ break;
default:
fprintf(stderr, usage, argv[0]);
return EXIT_FAILURE;