aboutsummaryrefslogtreecommitdiff
path: root/i2c/sw/hash_i2c.c
diff options
context:
space:
mode:
Diffstat (limited to 'i2c/sw/hash_i2c.c')
-rw-r--r--i2c/sw/hash_i2c.c63
1 files changed, 8 insertions, 55 deletions
diff --git a/i2c/sw/hash_i2c.c b/i2c/sw/hash_i2c.c
index 04006d3..3a9f0cf 100644
--- a/i2c/sw/hash_i2c.c
+++ b/i2c/sw/hash_i2c.c
@@ -49,7 +49,7 @@
#include "cryptech_memory_map.h"
char *usage =
-"Usage: %s [-d] [-v] [-q] [-i I2C_device] [-a I2C_addr] [algorithm [file]]\n"
+"Usage: %s [-d] [-v] [-q] [algorithm [file]]\n"
"algorithms: sha-1, sha-256, sha-512/224, sha-512/256, sha-384, sha-512\n";
int debug = 0;
@@ -96,53 +96,21 @@ struct ctrl *find_algo(char *algo)
return NULL;
}
-/* ---------------- test-case low-level code ---------------- */
-
-int tc_init(off_t offset, int mode)
-{
- uint8_t buf[4] = { 0, 0, 0, CTRL_INIT_CMD + mode };
-
- return tc_write(offset, buf, 4);
-}
-
-int tc_next(off_t offset, int mode)
-{
- uint8_t buf[4] = { 0, 0, 0, CTRL_NEXT_CMD + mode };
-
- return tc_write(offset, buf, 4);
-}
-
-int tc_wait_ready(off_t offset)
-{
- int limit = 10;
- return tc_wait(offset, STATUS_READY_BIT, &limit);
-}
-
-int tc_wait_valid(off_t offset)
-{
- int limit = 10;
- return tc_wait(offset, STATUS_VALID_BIT, &limit);
-}
-
/* ---------------- hash ---------------- */
int transmit(off_t offset, uint8_t *block, int blen, int mode, int first)
{
- off_t base = offset & ~(0xff);
+ off_t base = offset & ~(0x1ff);
+ uint8_t ctrl_cmd[4] = { 0 };
if (tc_write(offset, block, blen) != 0)
return 1;
- if (first) {
- if (tc_init(base + ADDR_CTRL, mode) != 0)
- return 1;
- }
- else {
- if (tc_next(base + ADDR_CTRL, mode) != 0)
- return 1;
- }
+ ctrl_cmd[3] = (first ? CTRL_INIT_CMD : CTRL_NEXT_CMD) | mode;
- return tc_wait_ready(base + ADDR_STATUS);
+ return
+ tc_write(base + ADDR_CTRL, ctrl_cmd, 4) ||
+ tc_wait_ready(base + ADDR_STATUS);
}
int pad_transmit(off_t offset, uint8_t *block, uint8_t flen, uint8_t blen,
@@ -257,15 +225,13 @@ out:
int main(int argc, char *argv[])
{
- char *dev = I2C_dev;
- int addr = I2C_addr;
int i, opt;
char *algo = "sha-1";
char *file = "-";
uint8_t digest[512/8];
int dlen;
- while ((opt = getopt(argc, argv, "h?dvqi:a:")) != -1) {
+ while ((opt = getopt(argc, argv, "h?dvq")) != -1) {
switch (opt) {
case 'h':
case '?':
@@ -280,16 +246,6 @@ int main(int argc, char *argv[])
case 'q':
quiet = 1;
break;
- case 'i':
- dev = optarg;
- break;
- case 'a':
- addr = (int)strtol(optarg, NULL, 0);
- if ((addr < 0x03) || (addr > 0x77)) {
- fprintf(stderr, "addr must be between 0x03 and 0x77\n");
- return EXIT_FAILURE;
- }
- break;
default:
fprintf(stderr, usage, argv[0]);
return EXIT_FAILURE;
@@ -314,9 +270,6 @@ int main(int argc, char *argv[])
printf("reading from stdin\n");
}
- if (i2c_open(dev, addr) != 0)
- return EXIT_FAILURE;
-
dlen = hash(algo, file, digest);
if (dlen < 0)
return EXIT_FAILURE;