aboutsummaryrefslogtreecommitdiff
path: root/sw/trng_tester.c
diff options
context:
space:
mode:
Diffstat (limited to 'sw/trng_tester.c')
-rw-r--r--sw/trng_tester.c119
1 files changed, 96 insertions, 23 deletions
diff --git a/sw/trng_tester.c b/sw/trng_tester.c
index 715a20c..6243544 100644
--- a/sw/trng_tester.c
+++ b/sw/trng_tester.c
@@ -57,6 +57,27 @@ int repeat = 0;
int num_words = 10;
int wait_stats = 0;
+/* ---------------- startup code ---------------- */
+
+static off_t board_addr_base = 0;
+static off_t trng_addr_base, entropy1_addr_base, entropy2_addr_base, csprng_addr_base;
+
+static int init(void)
+{
+ static int inited = 0;
+
+ if (inited)
+ return 0;
+
+ trng_addr_base = tc_core_base("trng");
+ entropy1_addr_base = tc_core_base("extnoise");
+ entropy2_addr_base = tc_core_base("rosc ent");
+ csprng_addr_base = tc_core_base("csprng");
+
+ inited = 1;
+ return 0;
+}
+
/* ---------------- sanity test case ---------------- */
int TC0()
@@ -66,6 +87,9 @@ int TC0()
uint8_t version[4] = NOVENA_BOARD_VERSION;
uint8_t t[4];
+ if (init() != 0)
+ return -1;
+
if (!quiet)
printf("TC0: Reading board type, version, and dummy reg from global registers.\n");
@@ -73,14 +97,14 @@ int TC0()
* to make sure that we can actually write something into EIM
*/
(void)time((time_t *)t);
- if (tc_write(BOARD_ADDR_DUMMY, t, 4) != 0)
+ if (tc_write(board_addr_base + BOARD_ADDR_DUMMY, t, 4) != 0)
return 1;
return
- tc_expected(BOARD_ADDR_NAME0, name0, 4) ||
- tc_expected(BOARD_ADDR_NAME1, name1, 4) ||
- tc_expected(BOARD_ADDR_VERSION, version, 4) ||
- tc_expected(BOARD_ADDR_DUMMY, t, 4);
+ tc_expected(board_addr_base + BOARD_ADDR_NAME0, name0, 4) ||
+ tc_expected(board_addr_base + BOARD_ADDR_NAME1, name1, 4) ||
+ tc_expected(board_addr_base + BOARD_ADDR_VERSION, version, 4) ||
+ tc_expected(board_addr_base + BOARD_ADDR_DUMMY, t, 4);
}
/* ---------------- trng test cases ---------------- */
@@ -92,13 +116,20 @@ int TC1(void)
uint8_t name1[4] = TRNG_NAME1;
uint8_t version[4] = TRNG_VERSION;
+ if (init() != 0)
+ return -1;
+ if ((trng_addr_base == 0) && !quiet) {
+ printf("TC1: TRNG not present\n");
+ return 0;
+ }
+
if (!quiet)
printf("TC1: Reading name and version words from trng core.\n");
return
- tc_expected(TRNG_ADDR_NAME0, name0, 4) ||
- tc_expected(TRNG_ADDR_NAME1, name1, 4) ||
- tc_expected(TRNG_ADDR_VERSION, version, 4);
+ tc_expected(trng_addr_base + TRNG_ADDR_NAME0, name0, 4) ||
+ tc_expected(trng_addr_base + TRNG_ADDR_NAME1, name1, 4) ||
+ tc_expected(trng_addr_base + TRNG_ADDR_VERSION, version, 4);
}
/* XXX test cases for setting blinkenlights? */
@@ -113,13 +144,20 @@ int TC2(void)
uint8_t name1[4] = AVALANCHE_ENTROPY_NAME1;
uint8_t version[4] = AVALANCHE_ENTROPY_VERSION;
+ if (init() != 0)
+ return -1;
+ if ((entropy1_addr_base == 0) && !quiet) {
+ printf("TC2: AVALANCHE_ENTROPY not present\n");
+ return 0;
+ }
+
if (!quiet)
printf("TC2: Reading name and version words from avalanche_entropy core.\n");
return
- tc_expected(ENTROPY1_ADDR_NAME0, name0, 4) ||
- tc_expected(ENTROPY1_ADDR_NAME1, name1, 4) ||
- tc_expected(ENTROPY1_ADDR_VERSION, version, 4);
+ tc_expected(entropy1_addr_base + ENTROPY1_ADDR_NAME0, name0, 4) ||
+ tc_expected(entropy1_addr_base + ENTROPY1_ADDR_NAME1, name1, 4) ||
+ tc_expected(entropy1_addr_base + ENTROPY1_ADDR_VERSION, version, 4);
}
/* XXX clear 'enable' control bit, see if we read the same value */
@@ -130,16 +168,23 @@ int TC3(void)
int i, n;
uint32_t entropy;
+ if (init() != 0)
+ return -1;
+ if ((entropy1_addr_base == 0) && !quiet) {
+ printf("TC3: AVALANCHE_ENTROPY not present\n");
+ return 0;
+ }
+
if (!quiet)
printf("TC3: Read random data from avalanche_entropy.\n");
for (i = 0; i < num_words; ++i) {
/* check status */
n = 0;
- if (tc_wait(ENTROPY1_ADDR_STATUS, ENTROPY1_STATUS_VALID, &n) != 0)
+ if (tc_wait(entropy1_addr_base + ENTROPY1_ADDR_STATUS, ENTROPY1_STATUS_VALID, &n) != 0)
return 1;
/* read entropy data */
- if (tc_read(ENTROPY1_ADDR_ENTROPY, (uint8_t *)&entropy, 4) != 0)
+ if (tc_read(entropy1_addr_base + ENTROPY1_ADDR_ENTROPY, (uint8_t *)&entropy, 4) != 0)
return 1;
/* display entropy data */
if (!debug) {
@@ -162,13 +207,20 @@ int TC4(void)
uint8_t name1[4] = ROSC_ENTROPY_NAME1;
uint8_t version[4] = ROSC_ENTROPY_VERSION;
+ if (init() != 0)
+ return -1;
+ if ((entropy2_addr_base == 0) && !quiet) {
+ printf("TC4: ROSC_ENTROPY not present\n");
+ return 0;
+ }
+
if (!quiet)
printf("TC4: Reading name and version words from rosc_entropy core.\n");
return
- tc_expected(ENTROPY2_ADDR_NAME0, name0, 4) ||
- tc_expected(ENTROPY2_ADDR_NAME1, name1, 4) ||
- tc_expected(ENTROPY2_ADDR_VERSION, version, 4);
+ tc_expected(entropy2_addr_base + ENTROPY2_ADDR_NAME0, name0, 4) ||
+ tc_expected(entropy2_addr_base + ENTROPY2_ADDR_NAME1, name1, 4) ||
+ tc_expected(entropy2_addr_base + ENTROPY2_ADDR_VERSION, version, 4);
}
/* XXX clear 'enable' control bit, see if we read the same value */
@@ -179,16 +231,23 @@ int TC5(void)
int i, n;
uint32_t entropy;
+ if (init() != 0)
+ return -1;
+ if ((entropy2_addr_base == 0) && !quiet) {
+ printf("TC5: ROSC_ENTROPY not present\n");
+ return 0;
+ }
+
if (!quiet)
printf("TC5: Read random data from rosc_entropy.\n");
for (i = 0; i < num_words; ++i) {
/* check status */
n = 0;
- if (tc_wait(ENTROPY2_ADDR_STATUS, ENTROPY2_STATUS_VALID, &n) != 0)
+ if (tc_wait(entropy2_addr_base + ENTROPY2_ADDR_STATUS, ENTROPY2_STATUS_VALID, &n) != 0)
return 1;
/* read entropy data */
- if (tc_read(ENTROPY2_ADDR_ENTROPY, (uint8_t *)&entropy, 4) != 0)
+ if (tc_read(entropy2_addr_base + ENTROPY2_ADDR_ENTROPY, (uint8_t *)&entropy, 4) != 0)
return 1;
/* display entropy data */
if (!debug) {
@@ -211,13 +270,20 @@ int TC6(void)
uint8_t name1[4] = CSPRNG_NAME1;
uint8_t version[4] = CSPRNG_VERSION;
+ if (init() != 0)
+ return -1;
+ if ((csprng_addr_base == 0) && !quiet) {
+ printf("TC6: CSPRNG not present\n");
+ return 0;
+ }
+
if (!quiet)
printf("TC6: Reading name and version words from trng_csprng core.\n");
return
- tc_expected(CSPRNG_ADDR_NAME0, name0, 4) ||
- tc_expected(CSPRNG_ADDR_NAME1, name1, 4) ||
- tc_expected(CSPRNG_ADDR_VERSION, version, 4);
+ tc_expected(csprng_addr_base + CSPRNG_ADDR_NAME0, name0, 4) ||
+ tc_expected(csprng_addr_base + CSPRNG_ADDR_NAME1, name1, 4) ||
+ tc_expected(csprng_addr_base + CSPRNG_ADDR_VERSION, version, 4);
}
/* XXX clear 'enable' control bit, see if we read the same value */
@@ -229,16 +295,23 @@ int TC7(void)
int i, n;
uint32_t random;
+ if (init() != 0)
+ return -1;
+ if ((csprng_addr_base == 0) && !quiet) {
+ printf("TC7: CSPRNG not present\n");
+ return 0;
+ }
+
if (!quiet)
printf("TC7: Read random data from trng_csprng.\n");
for (i = 0; i < num_words; ++i) {
/* check status */
n = 0;
- if (tc_wait(CSPRNG_ADDR_STATUS, CSPRNG_STATUS_VALID, &n) != 0)
+ if (tc_wait(csprng_addr_base + CSPRNG_ADDR_STATUS, CSPRNG_STATUS_VALID, &n) != 0)
return 1;
/* read random data */
- if (tc_read(CSPRNG_ADDR_RANDOM, (uint8_t *)&random, 4) != 0)
+ if (tc_read(csprng_addr_base + CSPRNG_ADDR_RANDOM, (uint8_t *)&random, 4) != 0)
return 1;
/* display random data */
if (!debug) {