Software APIs
thash_sha2_simple.c
1 // Copyright lowRISC contributors (OpenTitan project).
2 // Licensed under the Apache License, Version 2.0, see LICENSE for details.
3 // SPDX-License-Identifier: Apache-2.0
4 //
5 // Derived from code in the SPHINCS+ reference implementation (CC0 license):
6 // https://github.com/sphincs/sphincsplus/blob/7ec789ace6874d875f4bb84cb61b81155398167e/ref/thash_sha2_simple.h
7 
9 #include "sw/device/silicon_creator/lib/drivers/hmac.h"
10 #include "sw/device/silicon_creator/lib/sigverify/sphincsplus/params.h"
11 #include "sw/device/silicon_creator/lib/sigverify/sphincsplus/sha2.h"
12 #include "sw/device/silicon_creator/lib/sigverify/sphincsplus/thash.h"
13 
14 void thash(const uint32_t *in, size_t inblocks, const spx_ctx_t *ctx,
15  const spx_addr_t *addr, uint32_t *out) {
16  hmac_sha256_restore(&ctx->state_seeded);
17  hmac_sha256_update((unsigned char *)addr->addr, kSpxSha256AddrBytes);
18  hmac_sha256_update_words(in, inblocks * kSpxNWords);
19  hmac_sha256_process();
20  hmac_sha256_final_truncated(out, kSpxNWords);
21 }