aboutsummaryrefslogtreecommitdiff
path: root/eim
diff options
context:
space:
mode:
authorPaul Selkirk <paul@psgd.org>2015-04-03 18:10:36 -0400
committerPaul Selkirk <paul@psgd.org>2015-04-03 18:10:36 -0400
commit891a24d969181f02762c031b9cfe0fd96c116634 (patch)
tree36e7cc19b8a53a4978042842b4f4205c469e5a14 /eim
parentb1ebb2a975de7f29e63c3a4046de15c26b44dceb (diff)
Add scaling factor to trng_extractor for easier bulk data extraction.
Diffstat (limited to 'eim')
-rw-r--r--eim/sw/trng_extractor_eim.c40
1 files changed, 26 insertions, 14 deletions
diff --git a/eim/sw/trng_extractor_eim.c b/eim/sw/trng_extractor_eim.c
index e023c79..18fc1d6 100644
--- a/eim/sw/trng_extractor_eim.c
+++ b/eim/sw/trng_extractor_eim.c
@@ -38,6 +38,7 @@
#include <stdlib.h>
#include <unistd.h>
#include <stdint.h>
+#include <ctype.h>
#include "tc_eim.h"
#include "cryptech_memory_map.h"
@@ -47,8 +48,8 @@ char *usage =
\n\
-a avalanche entropy\n\
-r rosc entropy\n\
--c csprng\n\
--n number of 4-byte samples (defaults to 10)\n\
+-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\
";
@@ -73,10 +74,13 @@ static int extract(off_t status_addr, off_t data_addr, uint32_t *data)
/* main */
int main(int argc, char *argv[])
{
- int i, opt, num_words = 10;
- uint32_t data;
- off_t status_addr = 0, data_addr = 0;
+ int i, opt;
+ unsigned long num_words = 1;
+ char *endptr;
+ off_t status_addr = CSPRNG_ADDR_STATUS;
+ off_t data_addr = CSPRNG_ADDR_RANDOM;
FILE *output = stdout;
+ uint32_t data;
/* parse command line */
while ((opt = getopt(argc, argv, "h?arcn:o:")) != -1) {
@@ -98,11 +102,23 @@ int main(int argc, char *argv[])
data_addr = CSPRNG_ADDR_RANDOM;
break;
case 'n':
- num_words = atoi(optarg);
- if (num_words <= 0) {
- fprintf(stderr, "-n requires a positive integer argument\n");
- return EXIT_FAILURE;
- }
+ num_words = strtoul(optarg, &endptr, 10);
+ switch (toupper(*endptr)) {
+ case '\0':
+ break;
+ case 'K':
+ num_words *= 1000;
+ break;
+ case 'M':
+ num_words *= 1000000;
+ break;
+ case 'G':
+ num_words *= 1000000000;
+ break;
+ default:
+ fprintf(stderr, "unsupported -n suffix %s\n", endptr);
+ return EXIT_FAILURE;
+ }
break;
case 'o':
output = fopen(optarg, "wb+");
@@ -128,10 +144,6 @@ int main(int argc, char *argv[])
fprintf(stderr, "\n");
goto errout;
}
- if (status_addr == 0) {
- fprintf(stderr, "%s: a data source must be specified\n", argv[0]);
- goto errout;
- }
/* set up EIM */
if (eim_setup() != 0) {