aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Selkirk <paul@psgd.org>2015-05-05 16:15:10 -0400
committerPaul Selkirk <paul@psgd.org>2015-05-05 16:15:10 -0400
commit05b139f4407890a8671bc3f40c48e4d54e3a83c5 (patch)
tree1d1e9ab6ed090baaf0b8bd71c33fd0b67aff0f23
parent5311cc678dc82222146a384080d5f2bc95cb1eb6 (diff)
Rename bitmask symbols.
-rw-r--r--sw/cryptech.h14
-rw-r--r--sw/hash.c2
-rw-r--r--sw/hash_tester.c6
-rw-r--r--sw/tc_eim.c8
-rw-r--r--sw/tc_i2c.c8
-rw-r--r--sw/trng_extractor.c25
6 files changed, 32 insertions, 31 deletions
diff --git a/sw/cryptech.h b/sw/cryptech.h
index 186f804..05862bb 100644
--- a/sw/cryptech.h
+++ b/sw/cryptech.h
@@ -90,11 +90,11 @@ in order to map it into a 16-bit address space.
#define ADDR_NAME1 0x01
#define ADDR_VERSION 0x02
#define ADDR_CTRL 0x08
-#define CTRL_INIT_BIT 1
-#define CTRL_NEXT_BIT 2
+#define CTRL_INIT 1
+#define CTRL_NEXT 2
#define ADDR_STATUS 0x09
-#define STATUS_READY_BIT 1
-#define STATUS_VALID_BIT 2
+#define STATUS_READY 1
+#define STATUS_VALID 2
// a handy macro from cryptlib
@@ -136,8 +136,6 @@ in order to map it into a 16-bit address space.
// Hashes segment.
//------------------------------------------------------------------
// addresses common to all hash cores
-#define CTRL_INIT_CMD 1
-#define CTRL_NEXT_CMD 2
#define ADDR_BLOCK 0x10
#define ADDR_DIGEST 0x20 // except SHA512
@@ -294,8 +292,8 @@ in order to map it into a 16-bit address space.
#define AES_ADDR_STATUS AES_ADDR_BASE + ADDR_STATUS
#define AES_ADDR_CONFIG AES_ADDR_BASE + 0x0a
-#define AES_CONFIG_ENCDEC_BIT 1
-#define AES_CONFIG_KEYLEN_BIT 2
+#define AES_CONFIG_ENCDEC 1
+#define AES_CONFIG_KEYLEN 2
#define AES_ADDR_KEY0 0x10
#define AES_ADDR_KEY1 0x11
diff --git a/sw/hash.c b/sw/hash.c
index ae34ded..8b3bac2 100644
--- a/sw/hash.c
+++ b/sw/hash.c
@@ -109,7 +109,7 @@ static int transmit(off_t offset, uint8_t *block, int blen, int mode, int first)
if (tc_write(offset, block, blen) != 0)
return 1;
- ctrl_cmd[3] = (first ? CTRL_INIT_CMD : CTRL_NEXT_CMD) | mode;
+ ctrl_cmd[3] = (first ? CTRL_INIT : CTRL_NEXT) | mode;
return
tc_write(base + ADDR_CTRL, ctrl_cmd, 4) ||
diff --git a/sw/hash_tester.c b/sw/hash_tester.c
index 3df62d3..7e4f2c8 100644
--- a/sw/hash_tester.c
+++ b/sw/hash_tester.c
@@ -460,7 +460,7 @@ int TC8()
int tc9(int mode, const uint8_t *expected, int digest_len)
{
const uint8_t *block = NIST_1024_SINGLE;
- uint8_t init[4] = { 0, 0, 0, CTRL_INIT_CMD + mode };
+ uint8_t init[4] = { 0, 0, 0, CTRL_INIT + mode };
return
/* Write block to SHA-512. */
@@ -502,8 +502,8 @@ int TC9()
int tc10(int mode, const uint8_t *expected, int digest_len)
{
const uint8_t *block[2] = { NIST_1024_DOUBLE0, NIST_1024_DOUBLE1 };
- uint8_t init[4] = { 0, 0, 0, CTRL_INIT_CMD + mode };
- uint8_t next[4] = { 0, 0, 0, CTRL_NEXT_CMD + mode };
+ uint8_t init[4] = { 0, 0, 0, CTRL_INIT + mode };
+ uint8_t next[4] = { 0, 0, 0, CTRL_NEXT + mode };
return
/* Write first block to SHA-512. */
diff --git a/sw/tc_eim.c b/sw/tc_eim.c
index 0461f15..c812478 100644
--- a/sw/tc_eim.c
+++ b/sw/tc_eim.c
@@ -163,14 +163,14 @@ errout:
int tc_init(off_t offset)
{
- uint8_t buf[4] = { 0, 0, 0, CTRL_INIT_CMD };
+ uint8_t buf[4] = { 0, 0, 0, CTRL_INIT };
return tc_write(offset, buf, 4);
}
int tc_next(off_t offset)
{
- uint8_t buf[4] = { 0, 0, 0, CTRL_NEXT_CMD };
+ uint8_t buf[4] = { 0, 0, 0, CTRL_NEXT };
return tc_write(offset, buf, 4);
}
@@ -198,11 +198,11 @@ int tc_wait(off_t offset, uint8_t status, int *count)
int tc_wait_ready(off_t offset)
{
int limit = 256;
- return tc_wait(offset, STATUS_READY_BIT, &limit);
+ return tc_wait(offset, STATUS_READY, &limit);
}
int tc_wait_valid(off_t offset)
{
int limit = 256;
- return tc_wait(offset, STATUS_VALID_BIT, &limit);
+ return tc_wait(offset, STATUS_VALID, &limit);
}
diff --git a/sw/tc_i2c.c b/sw/tc_i2c.c
index 333a531..bcc6be9 100644
--- a/sw/tc_i2c.c
+++ b/sw/tc_i2c.c
@@ -290,14 +290,14 @@ int tc_expected(off_t offset, const uint8_t *buf, size_t len)
int tc_init(off_t offset)
{
- uint8_t buf[4] = { 0, 0, 0, CTRL_INIT_CMD };
+ uint8_t buf[4] = { 0, 0, 0, CTRL_INIT };
return tc_write(offset, buf, 4);
}
int tc_next(off_t offset)
{
- uint8_t buf[4] = { 0, 0, 0, CTRL_NEXT_CMD };
+ uint8_t buf[4] = { 0, 0, 0, CTRL_NEXT };
return tc_write(offset, buf, 4);
}
@@ -325,11 +325,11 @@ int tc_wait(off_t offset, uint8_t status, int *count)
int tc_wait_ready(off_t offset)
{
int limit = 10;
- return tc_wait(offset, STATUS_READY_BIT, &limit);
+ return tc_wait(offset, STATUS_READY, &limit);
}
int tc_wait_valid(off_t offset)
{
int limit = 10;
- return tc_wait(offset, STATUS_VALID_BIT, &limit);
+ return tc_wait(offset, STATUS_VALID, &limit);
}
diff --git a/sw/trng_extractor.c b/sw/trng_extractor.c
index fe37044..e25ebf0 100644
--- a/sw/trng_extractor.c
+++ b/sw/trng_extractor.c
@@ -42,8 +42,6 @@
#include "cryptech.h"
-int verbose;
-
char *usage =
"%s [-a|r|c] [-n #] [-o file]\n\
\n\
@@ -52,7 +50,7 @@ char *usage =
-c csprng (default data source)\n\
-n number of 4-byte samples (scale with K, M, or G suffix)\n\
-o output file (defaults to stdout)\n\
--v verbose operation
+-v verbose operation\n\
";
/* check availability of avalanche entropy core by reading core name and version */
@@ -98,13 +96,14 @@ static int extract(off_t status_addr, off_t data_addr, uint32_t *data)
/* main */
int main(int argc, char *argv[])
{
- int i, opt;
- unsigned long num_words = 1;
+ int opt;
+ unsigned long num_words = 1, i;
char *endptr;
off_t status_addr = CSPRNG_ADDR_STATUS;
off_t data_addr = CSPRNG_ADDR_RANDOM;
FILE *output = stdout;
uint32_t data;
+ int verbose = 0;
/* parse command line */
while ((opt = getopt(argc, argv, "h?varcn:o:")) != -1) {
@@ -125,9 +124,9 @@ int main(int argc, char *argv[])
status_addr = CSPRNG_ADDR_STATUS;
data_addr = CSPRNG_ADDR_RANDOM;
break;
- case 'v':
- verbose = 1;
- break;
+ case 'v':
+ verbose = 1;
+ break;
case 'n':
num_words = strtoul(optarg, &endptr, 10);
switch (toupper(*endptr)) {
@@ -172,15 +171,15 @@ int main(int argc, char *argv[])
goto errout;
}
- // Check that we have can talk to the trng.
+ // Check that we can talk to the trng.
if (verbose)
- printf("Checking that we can access the TRNG...\n");
+ printf("Checking that we can access the TRNG...\n");
if (avalanche_check() || rosc_check() || csprng_check()) {
fprintf(stderr, "Can't properly access the trng.\n");
return EXIT_FAILURE;
}
if (verbose)
- printf("TRNG access ok..\n");
+ printf("TRNG access ok..\n");
/* get the data */
for (i = 0; i < num_words; ++i) {
@@ -191,6 +190,10 @@ int main(int argc, char *argv[])
fclose(output);
return EXIT_FAILURE;
}
+ if (verbose && ((i & 0xffff) == 0)) {
+ fprintf(stderr, ".");
+ fflush(stderr);
+ }
}
fclose(output);