Coverage Report

Created: 2026-08-08 07:14

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/boringssl/crypto/fipsmodule/slhdsa/params.h
Line
Count
Source
1
// Copyright 2024 The BoringSSL Authors
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
//     https://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
15
#ifndef OPENSSL_HEADER_CRYPTO_FIPSMODULE_SLHDSA_PARAMS_H
16
#define OPENSSL_HEADER_CRYPTO_FIPSMODULE_SLHDSA_PARAMS_H
17
18
#include <openssl/base.h>
19
20
#include <stdbool.h>
21
22
#include "../bcm_interface.h"
23
24
25
BSSL_NAMESPACE_BEGIN
26
27
enum slh_dsa_hash_type {
28
  SLH_DSA_HASH_SHA2_256,
29
  SLH_DSA_HASH_SHAKE_256,
30
};
31
32
// Upper bounds for stack allocations across all SLH-DSA parameter sets in
33
// FIPS 205. These keep the code simple and avoid dynamic allocation while
34
// still covering larger future parameter sets such as SLH-DSA-SHAKE-256f.
35
#define SLHDSA_MAX_N 32
36
#define SLHDSA_MAX_WOTS_LEN 67
37
#define SLHDSA_MAX_WOTS_BYTES (SLHDSA_MAX_N * SLHDSA_MAX_WOTS_LEN)
38
#define SLHDSA_MAX_FORS_HEIGHT 17
39
#define SLHDSA_MAX_FORS_TREES 35
40
#define SLHDSA_MAX_FORS_BYTES \
41
  ((SLHDSA_MAX_FORS_HEIGHT + 1) * SLHDSA_MAX_FORS_TREES * SLHDSA_MAX_N)
42
#define SLHDSA_MAX_FORS_MSG_BYTES \
43
  ((SLHDSA_MAX_FORS_HEIGHT * SLHDSA_MAX_FORS_TREES + 7) / 8)
44
#define SLHDSA_MAX_TREE_HEIGHT 18
45
#define SLHDSA_MAX_D 18
46
#define SLHDSA_MAX_DIGEST_SIZE 64
47
#define SLHDSA_MAX_HASH_BLOCK_BYTES 168
48
49
// Values bound by these limits are assumed to be valid shifts within a
50
// uint32_t.
51
static_assert(SLHDSA_MAX_TREE_HEIGHT < 32);
52
static_assert(SLHDSA_MAX_FORS_HEIGHT < 32);
53
54
0
#define SLHDSA_ADDR_BYTES 32
55
0
#define SLHDSA_ADDR_COMPRESSED_BYTES 22
56
0
#define SLHDSA_ADDR_COMP_OFFSET_LAYER 0
57
0
#define SLHDSA_ADDR_COMP_OFFSET_TREE 1
58
0
#define SLHDSA_ADDR_COMP_OFFSET_TYPE 9
59
0
#define SLHDSA_ADDR_COMP_OFFSET_KEYPAIR 10
60
0
#define SLHDSA_ADDR_COMP_OFFSET_CHAIN 14
61
0
#define SLHDSA_ADDR_COMP_OFFSET_TREE_HEIGHT 14
62
0
#define SLHDSA_ADDR_COMP_OFFSET_HASH 18
63
0
#define SLHDSA_ADDR_COMP_OFFSET_TREE_INDEX 18
64
0
#define SLHDSA_ADDR_COMP_ZERO_START 10
65
0
#define SLHDSA_ADDR_COMP_ZERO_LEN 12
66
0
#define SLHDSA_ADDR_FULL_OFFSET_LAYER 0
67
0
#define SLHDSA_ADDR_FULL_OFFSET_TREE 4
68
0
#define SLHDSA_ADDR_FULL_OFFSET_TYPE 16
69
0
#define SLHDSA_ADDR_FULL_OFFSET_KEYPAIR 20
70
0
#define SLHDSA_ADDR_FULL_OFFSET_CHAIN 24
71
0
#define SLHDSA_ADDR_FULL_OFFSET_TREE_HEIGHT 24
72
0
#define SLHDSA_ADDR_FULL_OFFSET_HASH 28
73
0
#define SLHDSA_ADDR_FULL_OFFSET_TREE_INDEX 28
74
0
#define SLHDSA_ADDR_FULL_ZERO_START 20
75
0
#define SLHDSA_ADDR_FULL_ZERO_LEN 12
76
77
typedef struct slh_dsa_config {
78
  uint32_t n;
79
  uint32_t full_height;
80
  uint32_t d;
81
  uint32_t tree_height;
82
  uint32_t fors_height;
83
  uint32_t fors_trees;
84
  uint32_t wots_w;
85
  uint32_t wots_log_w;
86
  uint32_t wots_len1;
87
  uint32_t wots_len2;
88
  uint32_t digest_size;
89
  uint32_t hash_block_bytes;
90
  uint32_t hash_output_bytes;
91
  uint32_t public_key_bytes;
92
  uint32_t private_key_bytes;
93
  uint32_t signature_bytes;
94
  enum slh_dsa_hash_type hash_type;
95
  bool compressed_addresses;
96
} slh_dsa_config;
97
98
0
inline uint32_t slhdsa_wots_len(const slh_dsa_config *config) {
99
0
  return config->wots_len1 + config->wots_len2;
100
0
}
101
102
0
inline uint32_t slhdsa_wots_bytes(const slh_dsa_config *config) {
103
0
  return config->n * slhdsa_wots_len(config);
104
0
}
105
106
0
inline uint32_t slhdsa_xmss_bytes(const slh_dsa_config *config) {
107
0
  return slhdsa_wots_bytes(config) + config->n * config->tree_height;
108
0
}
109
110
0
inline uint32_t slhdsa_fors_msg_bytes(const slh_dsa_config *config) {
111
0
  return (config->fors_height * config->fors_trees + 7) / 8;
112
0
}
113
114
0
inline uint32_t slhdsa_fors_bytes(const slh_dsa_config *config) {
115
0
  return (config->fors_height + 1) * config->fors_trees * config->n;
116
0
}
117
118
0
inline uint32_t slhdsa_tree_bits(const slh_dsa_config *config) {
119
0
  return config->tree_height * (config->d - 1);
120
0
}
121
122
0
inline uint32_t slhdsa_tree_bytes(const slh_dsa_config *config) {
123
0
  return (slhdsa_tree_bits(config) + 7) / 8;
124
0
}
125
126
0
inline uint32_t slhdsa_leaf_bits(const slh_dsa_config *config) {
127
0
  return config->tree_height;
128
0
}
129
130
0
inline uint32_t slhdsa_leaf_bytes(const slh_dsa_config *config) {
131
0
  return (slhdsa_leaf_bits(config) + 7) / 8;
132
0
}
133
134
static const slh_dsa_config kSLHDSAConfigSHA2_128s = {
135
    /*n=*/BCM_SLHDSA_SHA2_128S_N,
136
    /*full_height=*/63,
137
    /*d=*/7,
138
    /*tree_height=*/9,
139
    /*fors_height=*/12,
140
    /*fors_trees=*/14,
141
    /*wots_w=*/16,
142
    /*wots_log_w=*/4,
143
    /*wots_len1=*/32,
144
    /*wots_len2=*/3,
145
    /*digest_size=*/30,
146
    /*hash_block_bytes=*/64,
147
    /*hash_output_bytes=*/32,
148
    /*public_key_bytes=*/BCM_SLHDSA_SHA2_128S_PUBLIC_KEY_BYTES,
149
    /*private_key_bytes=*/BCM_SLHDSA_SHA2_128S_PRIVATE_KEY_BYTES,
150
    /*signature_bytes=*/BCM_SLHDSA_SHA2_128S_SIGNATURE_BYTES,
151
    /*hash_type=*/SLH_DSA_HASH_SHA2_256,
152
    /*compressed_addresses=*/true,
153
};
154
155
static const slh_dsa_config kSLHDSAConfigSHAKE_256f = {
156
    /*n=*/BCM_SLHDSA_SHAKE_256F_N,
157
    /*full_height=*/68,
158
    /*d=*/17,
159
    /*tree_height=*/4,
160
    /*fors_height=*/9,
161
    /*fors_trees=*/35,
162
    /*wots_w=*/16,
163
    /*wots_log_w=*/4,
164
    /*wots_len1=*/64,
165
    /*wots_len2=*/3,
166
    /*digest_size=*/49,
167
    /*hash_block_bytes=*/136,
168
    /*hash_output_bytes=*/32,
169
    /*public_key_bytes=*/BCM_SLHDSA_SHAKE_256F_PUBLIC_KEY_BYTES,
170
    /*private_key_bytes=*/BCM_SLHDSA_SHAKE_256F_PRIVATE_KEY_BYTES,
171
    /*signature_bytes=*/BCM_SLHDSA_SHAKE_256F_SIGNATURE_BYTES,
172
    /*hash_type=*/SLH_DSA_HASH_SHAKE_256,
173
    /*compressed_addresses=*/false,
174
};
175
176
BSSL_NAMESPACE_END
177
178
#endif  // OPENSSL_HEADER_CRYPTO_FIPSMODULE_SLHDSA_PARAMS_H