Software APIs
spx_key.h
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#ifndef OPENTITAN_SW_DEVICE_SILICON_CREATOR_LIB_SIGVERIFY_SPX_KEY_H_
6#define OPENTITAN_SW_DEVICE_SILICON_CREATOR_LIB_SIGVERIFY_SPX_KEY_H_
7
8#include <stdint.h>
9
11#include "sw/device/silicon_creator/lib/sigverify/sphincsplus/params.h"
12
13#ifdef __cplusplus
14extern "C" {
15#endif // __cplusplus
16
17enum {
18 /**
19 * Size of an SPX public key in bits.
20 */
21 kSigverifySpxKeyNumBits = kSpxPkBytes * 8,
22 /**
23 * Size of an SPX public key in bytes.
24 */
25 kSigverifySpxKeyNumBytes = kSigverifySpxKeyNumBits / 8,
26 /**
27 * Size of an SPX public key in words.
28 */
29 kSigverifySpxKeyNumWords = kSigverifySpxKeyNumBytes / sizeof(uint32_t),
30 /**
31 * Size of an SPX root node in bits.
32 */
33 kSigverifySpxRootNumBits = kSpxN * 8,
34 /**
35 * Size of an SPX root node in bytes.
36 */
37 kSigverifySpxRootNumBytes = kSigverifySpxRootNumBits / 8,
38 /**
39 * Size of an SPX root node in words.
40 */
41 kSigverifySpxRootNumWords = kSigverifySpxRootNumBytes / sizeof(uint32_t),
42 /**
43 * Size of an SPX signature in bits.
44 */
45 kSigverifySpxSigNumBits = kSpxBytes * 8,
46 /**
47 * Size of an SPX signature in bytes.
48 */
49 kSigverifySpxSigNumBytes = kSigverifySpxSigNumBits / 8,
50 /**
51 * Size of an SPX signature in words.
52 */
53 kSigverifySpxSigNumWords = kSigverifySpxSigNumBytes / sizeof(uint32_t),
54};
55
56/**
57 * SPX configuration ID.
58 *
59 * Used to identify the SPX parameter confuration used to sign/verify a message.
60 *
61 * Encoding generated with:
62 * ./util/design/sparse-fsm-encode.py -d 6 -m 2 -n 32 -s 359186736 --language=c
63 */
64typedef enum sigverify_spx_config_id {
65 /** SPHINCS+-SHA2-128s without pre-hashing. */
66 kSigverifySpxConfigIdSha2128s = 0x0142410e,
67 /**
68 * SPHINCS+-SHA2-128s-q20 without pre-hashing.
69 *
70 * As specified in https://eprint.iacr.org/2022/1725.pdf.
71 *
72 * n | h | d | b | k | w | bitsec | sigsize
73 * 16 | 18 | 1 | 24 | 6 | 16 | 128 | 3264
74 */
75 kSigverifySpxConfigIdSha2128sQ20 = 0x9b28d8da,
76 /** SPHINCS+-SHA2-128s with SHA256 pre-hashing. */
77 kSigverifySpxConfigIdSha2128sPrehash = 0x4694e9cb,
78 /** SPHINCS+-SHA2-128s-q20 with SHA256 pre-hashing. */
79 kSigverifySpxConfigIdSha2128sQ20Prehash = 0xa3ed7f9a,
80} sigverify_spx_config_id_t;
81
82/**
83 * An SPX signature.
84 */
86 /**
87 * A `kSigverifySpxSigNumWords` base 2^32 digit integer, little-endian.
88 */
89 uint32_t data[kSigverifySpxSigNumWords];
90} sigverify_spx_signature_t;
91
92/**
93 * An SPX public key.
94 */
95typedef struct sigverify_spx_key {
96 /**
97 * A `kSigverifySpxKeyNumWords` base 2^32 digit integer, little-endian.
98 */
99 uint32_t data[kSigverifySpxKeyNumWords];
100} sigverify_spx_key_t;
101
102/**
103 * An SPX root node.
104 */
105typedef struct sigverify_spx_root {
106 /**
107 * A `kSigverifySpxRootNumWords` base 2^32 digit integer, little-endian.
108 */
109 uint32_t data[kSigverifySpxRootNumWords];
110} sigverify_spx_root_t;
111
112/**
113 * Gets the ID of an SPX public key.
114 *
115 * ID of a key is its least significant word.
116 * Callers must make sure that `key` is valid before calling this function.
117 *
118 * @param key An SPX public key.
119 * @return ID of the key.
120 */
122inline uint32_t sigverify_spx_key_id_get(const sigverify_spx_key_t *key) {
123 return key->data[0];
124}
125
126#ifdef __cplusplus
127} // extern "C"
128#endif // __cplusplus
129
130#endif // OPENTITAN_SW_DEVICE_SILICON_CREATOR_LIB_SIGVERIFY_SPX_KEY_H_