aboutsummaryrefslogtreecommitdiff
path: root/eim/sw/hash_eim.c
diff options
context:
space:
mode:
Diffstat (limited to 'eim/sw/hash_eim.c')
-rw-r--r--eim/sw/hash_eim.c55
1 files changed, 10 insertions, 45 deletions
diff --git a/eim/sw/hash_eim.c b/eim/sw/hash_eim.c
index 8ea761b..e698129 100644
--- a/eim/sw/hash_eim.c
+++ b/eim/sw/hash_eim.c
@@ -101,55 +101,25 @@ 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)
-{
- return tc_wait(offset, STATUS_READY_BIT, NULL);
-}
-
-int tc_wait_valid(off_t offset)
-{
- return tc_wait(offset, STATUS_VALID_BIT, NULL);
-}
-
/* ---------------- hash ---------------- */
-int transmit(off_t offset, uint8_t *block, int blen, int mode, int first)
+static 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,
- uint8_t mode, long long tlen, int first)
+static int pad_transmit(off_t offset, uint8_t *block, uint8_t flen, uint8_t blen,
+ uint8_t mode, long long tlen, int first)
{
assert(flen < blen);
@@ -173,7 +143,7 @@ int pad_transmit(off_t offset, uint8_t *block, uint8_t flen, uint8_t blen,
}
/* return number of digest bytes read */
-int hash(char *algo, char *file, uint8_t *digest)
+static int hash(char *algo, char *file, uint8_t *digest)
{
uint8_t block[SHA512_BLOCK_LEN];
struct ctrl *ctrl;
@@ -305,11 +275,6 @@ int main(int argc, char *argv[])
printf("reading from stdin\n");
}
- if (eim_setup() != 0) {
- fprintf(stderr, "EIM setup failed\n");
- return EXIT_FAILURE;
- }
-
dlen = hash(algo, file, digest);
if (dlen < 0)
return EXIT_FAILURE;