API参考
载入中...
搜索中...
未找到
xmss_params.h
1/*
2 * This file is part of the openHiTLS project.
3 *
4 * openHiTLS is licensed under the Mulan PSL v2.
5 * You can use this software according to the terms and conditions of the Mulan PSL v2.
6 * You may obtain a copy of Mulan PSL v2 at:
7 *
8 * http://license.coscl.org.cn/MulanPSL2
9 *
10 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
11 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
12 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
13 * See the Mulan PSL v2 for more details.
14 */
15
16#ifndef XMSS_PARAMS_H
17#define XMSS_PARAMS_H
18
19#include "hitls_build.h"
20#ifdef HITLS_CRYPTO_XMSS
21
22#include <stdint.h>
23#include <stddef.h>
24#include "crypt_algid.h"
25
26#ifdef __cplusplus
27extern "C" {
28#endif
29
30/* Maximum hash output length (for SHA512) */
31#define XMSS_MAX_N 64
32
33/* Maximum message digest size (same as max hash output) */
34#define XMSS_MAX_MDSIZE 64
35
36/* Maximum seed size */
37#define XMSS_MAX_SEED_SIZE 64
38
39/* Maximum tree height */
40#define XMSS_MAX_H 60
41
42/* Maximum WOTS+ parameter */
43#define XMSS_MAX_WOTS_W 16
44
45/* Maximum WOTS+ signature length (len * n) */
46#define XMSS_MAX_WOTS_LEN 67
47
48/* XDR algorithm type length (RFC 9802) */
49#define HASH_SIGN_XDR_ALG_TYPE_LEN 4
50
51/*
52 * XMSS Parameters Structure
53 *
54 * This structure contains all parameters needed for XMSS operations.
55 */
56typedef struct {
58
59 /* Security parameters */
60 uint32_t n; // Security parameter (hash output length in bytes)
61
62 /* Tree parameters */
63 uint32_t h; // Total tree height (number of layers in XMSSMT)
64 uint32_t d; // Number of layers (1 = XMSS, >1 = XMSSMT)
65 uint32_t hp; // Height of each layer = h / d
66
67 /* WOTS+ parameters */
68 uint32_t wotsW; // Winternitz parameter
69 /* the number of n-byte string elements in a WOTS+ private key,
70 public key, and signature. It is computed as len = len_1 + len_2,
71 with len_1 = ceil(8n / log_2(w)) and len_2 = floor(log_2(len_1 *
72 (w - 1)) / log_2(w)) + 1. */
73 uint32_t wotsLen;
74
75 /* Output sizes */
76 uint32_t pkBytes; // Public key size.
77 // Standard XMSS (RFC 8391): 4 (OID) + n (root) + n (SEED) = 4 + 2*n
78
79 uint32_t sigBytes; // Signature size.
80 // XMSS: 4 (idx) + n (r) + wotsLen*n + h*n
81 // XMSSMT: 4 (idx) + n (r) + d * (wotsLen*n + hp*n)
82
83 /* RFC 9802 X.509 support */
84 uint8_t xdrAlgId[HASH_SIGN_XDR_ALG_TYPE_LEN]; // 4-byte XDR OID (RFC 8391)
85
86 /* Hash algorithm parameters for generic hash function implementation */
87 CRYPT_MD_AlgId mdId; // Hash algorithm ID (e.g., CRYPT_MD_SHA256)
88 uint32_t paddingLen; // Padding length for domain separation
89} XmssParams;
90
91const XmssParams *FindXmssPara(CRYPT_PKEY_ParaId algId);
92
93/*
94 * Find XMSS parameters pointer by XDR algorithm ID (RFC 9802)
95 *
96 * Returns a pointer to the global parameter table entry.
97 * This is more memory efficient than copying the structure.
98 *
99 * @param xdrId XDR algorithm ID (32-bit value, big-endian)
100 *
101 * @return Pointer to XmssParams in global table, or NULL if not found
102 */
103const XmssParams *XmssParams_FindByXdrId(uint32_t xdrId);
104
105#ifdef __cplusplus
106}
107#endif
108
109#endif // HITLS_CRYPTO_XMSS
110#endif // XMSS_PARAMS_H
CRYPT_PKEY_ParaId
定义 crypt_algid.h:208
CRYPT_MD_AlgId
定义 crypt_algid.h:68