|
31 | 31 | /** |
32 | 32 | * Takes an array of inblocks concatenated arrays of LC_SPX_N bytes. |
33 | 33 | */ |
34 | | -void thash(uint8_t out[LC_SPX_N], const uint8_t *in, unsigned int inblocks, |
| 34 | +void thash(struct lc_hash_ctx *hash_ctx, uint8_t out[LC_SPX_N], |
| 35 | + const uint8_t *in, unsigned int inblocks, |
35 | 36 | const uint8_t pub_seed[LC_SPX_N], uint32_t addr[8]) |
36 | 37 | { |
37 | | - LC_HASH_CTX_ON_STACK(buf_ctx, LC_SPHINCS_HASH_TYPE); |
| 38 | +// LC_HASH_CTX_ON_STACK(hash_ctx, LC_SPHINCS_HASH_TYPE); |
38 | 39 |
|
39 | | - lc_hash_init(buf_ctx); |
40 | | - lc_hash_update(buf_ctx, pub_seed, LC_SPX_N); |
41 | | - lc_hash_update(buf_ctx, (uint8_t *)addr, LC_SPX_ADDR_BYTES); |
42 | | - lc_hash_update(buf_ctx, in, LC_SPX_N * inblocks); |
| 40 | + lc_hash_init(hash_ctx); |
| 41 | + lc_hash_update(hash_ctx, pub_seed, LC_SPX_N); |
| 42 | + lc_hash_update(hash_ctx, (uint8_t *)addr, LC_SPX_ADDR_BYTES); |
| 43 | + lc_hash_update(hash_ctx, in, LC_SPX_N * inblocks); |
43 | 44 |
|
44 | 45 | /* Squeeze out the final data point */ |
45 | | - lc_hash_set_digestsize(buf_ctx, LC_SPX_N); |
46 | | - lc_hash_final(buf_ctx, out); |
| 46 | + lc_hash_set_digestsize(hash_ctx, LC_SPX_N); |
| 47 | + lc_hash_final(hash_ctx, out); |
47 | 48 |
|
48 | | - lc_hash_zero(buf_ctx); |
| 49 | +// lc_hash_zero(hash_ctx); |
49 | 50 | } |
50 | 51 |
|
51 | 52 | /* |
52 | 53 | * Identical operation to thash, but with a shortcut for Ascon: since Ascon's |
53 | 54 | * rate is only 8 bytes, cache the Ascon state for the static part of the |
54 | 55 | * operation to avoid reruning Ascon permutations on already known data. |
55 | 56 | */ |
56 | | -void thash_ascon(uint8_t out[LC_SPX_N], const uint8_t *in, |
57 | | - unsigned int inblocks, const uint8_t pub_seed[LC_SPX_N], |
58 | | - uint32_t addr[8], unsigned int addr_static, |
59 | | - uint8_t *ascon_state, int first) |
| 57 | +void thash_ascon(struct lc_hash_ctx *hash_ctx, uint8_t out[LC_SPX_N], |
| 58 | + const uint8_t *in, unsigned int inblocks, |
| 59 | + const uint8_t pub_seed[LC_SPX_N], uint32_t addr[8], |
| 60 | + unsigned int addr_static, uint8_t *ascon_state, int first) |
60 | 61 | { |
61 | | - LC_HASH_CTX_ON_STACK(buf_ctx, LC_SPHINCS_HASH_TYPE); |
| 62 | +// LC_HASH_CTX_ON_STACK(hash_ctx, LC_SPHINCS_HASH_TYPE); |
62 | 63 |
|
63 | | - lc_hash_init(buf_ctx); |
| 64 | + lc_hash_init(hash_ctx); |
64 | 65 | if (first) { |
65 | | - lc_hash_update(buf_ctx, pub_seed, LC_SPX_N); |
66 | | - lc_hash_update(buf_ctx, (uint8_t *)addr, addr_static); |
67 | | - memcpy(ascon_state, buf_ctx->hash_state, |
| 66 | + lc_hash_update(hash_ctx, pub_seed, LC_SPX_N); |
| 67 | + lc_hash_update(hash_ctx, (uint8_t *)addr, addr_static); |
| 68 | + memcpy(ascon_state, hash_ctx->hash_state, |
68 | 69 | LC_ASCON_HASH_STATE_SIZE); |
69 | 70 | } else { |
70 | | - memcpy(buf_ctx->hash_state, ascon_state, |
| 71 | + memcpy(hash_ctx->hash_state, ascon_state, |
71 | 72 | LC_ASCON_HASH_STATE_SIZE); |
72 | 73 | } |
73 | | - lc_hash_update(buf_ctx, (uint8_t *)addr + addr_static, |
| 74 | + lc_hash_update(hash_ctx, (uint8_t *)addr + addr_static, |
74 | 75 | LC_SPX_ADDR_BYTES - addr_static); |
75 | | - lc_hash_update(buf_ctx, in, LC_SPX_N * inblocks); |
| 76 | + lc_hash_update(hash_ctx, in, LC_SPX_N * inblocks); |
76 | 77 |
|
77 | 78 | /* Squeeze out the final data point */ |
78 | | - lc_hash_set_digestsize(buf_ctx, LC_SPX_N); |
79 | | - lc_hash_final(buf_ctx, out); |
| 79 | + lc_hash_set_digestsize(hash_ctx, LC_SPX_N); |
| 80 | + lc_hash_final(hash_ctx, out); |
80 | 81 |
|
81 | | - lc_hash_zero(buf_ctx); |
| 82 | +// lc_hash_zero(hash_ctx); |
82 | 83 | } |
0 commit comments