xref: /aosp_15_r20/external/boringssl/src/crypto/spx/params.h (revision 8fb009dc861624b67b6cdb62ea21f0f22d0c584b)
1 /* Copyright (c) 2023, Google LLC
2  *
3  * Permission to use, copy, modify, and/or distribute this software for any
4  * purpose with or without fee is hereby granted, provided that the above
5  * copyright notice and this permission notice appear in all copies.
6  *
7  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
10  * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
12  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
13  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
14 
15 #ifndef OPENSSL_HEADER_CRYPTO_SPX_PARAMS_H
16 #define OPENSSL_HEADER_CRYPTO_SPX_PARAMS_H
17 
18 #if defined(__cplusplus)
19 extern "C" {
20 #endif
21 
22 
23 // Output length of the hash function.
24 #define SPX_N 16
25 // Total height of the tree structure.
26 #define SPX_FULL_HEIGHT 63
27 // Number of subtree layers.
28 #define SPX_D 7
29 // Height of the trees on each layer
30 #define SPX_TREE_HEIGHT 9
31 // Height of each individual FORS tree.
32 #define SPX_FORS_HEIGHT 12
33 // Total number of FORS tree used.
34 #define SPX_FORS_TREES 14
35 // Size of a FORS signature
36 #define SPX_FORS_BYTES ((SPX_FORS_HEIGHT + 1) * SPX_FORS_TREES * SPX_N)
37 
38 // Winternitz parameter and derived values
39 #define SPX_WOTS_W 16
40 #define SPX_WOTS_LOG_W 4
41 #define SPX_WOTS_LEN1 32
42 #define SPX_WOTS_LEN2 3
43 #define SPX_WOTS_LEN 35
44 #define SPX_WOTS_BYTES (SPX_N * SPX_WOTS_LEN)
45 
46 // XMSS sizes
47 #define SPX_XMSS_BYTES (SPX_WOTS_BYTES + (SPX_N * SPX_TREE_HEIGHT))
48 
49 // Size of the message digest (NOTE: This is only correct for the SHA256 params
50 // here)
51 #define SPX_DIGEST_SIZE                                                      \
52   (((SPX_FORS_TREES * SPX_FORS_HEIGHT) / 8) +                                \
53    (((SPX_FULL_HEIGHT - SPX_TREE_HEIGHT) / 8) + 1) + (SPX_TREE_HEIGHT / 8) + \
54    1)
55 
56 // Compressed address size when using SHA256
57 #define SPX_SHA256_ADDR_BYTES 22
58 
59 // Size of the FORS message hash
60 #define SPX_FORS_MSG_BYTES ((SPX_FORS_HEIGHT * SPX_FORS_TREES + 7) / 8)
61 #define SPX_TREE_BITS (SPX_TREE_HEIGHT * (SPX_D - 1))
62 #define SPX_TREE_BYTES ((SPX_TREE_BITS + 7) / 8)
63 #define SPX_LEAF_BITS SPX_TREE_HEIGHT
64 #define SPX_LEAF_BYTES ((SPX_LEAF_BITS + 7) / 8)
65 
66 
67 #if defined(__cplusplus)
68 }  // extern C
69 #endif
70 
71 #endif  // OPENSSL_HEADER_CRYPTO_SPX_PARAMS_H
72