API参考
载入中...
搜索中...
未找到
xmss_local.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_LOCAL_H
17#define XMSS_LOCAL_H
18
19#include "hitls_build.h"
20#ifdef HITLS_CRYPTO_XMSS
21
22#include <stdint.h>
23#include <stddef.h>
24#include "xmss_common.h"
25#include "xmss_params.h"
26#include "xmss_address.h"
27#include "xmss_tree.h"
28
29#ifdef __cplusplus
30extern "C" {
31#endif
32
33/* Maximum sizes for buffers */
34#define XMSS_MAX_SEED_SIZE 64
35
36/*
37 * XMSS Context
38 *
39 * This structure contains all state needed for XMSS operations.
40 * It is designed to be independent of SLH-DSA.
41 */
42typedef struct CryptXmssCtx {
43 const XmssParams *params; // XMSS parameters (pointer to global param table)
44
45 const CryptHashFuncs *hashFuncs; // Hash function table (pointer to static table)
46
47 CryptAdrsOps adrsOps; // Generic address operation function pointers
48
49 struct {
50 uint8_t seed[XMSS_MAX_SEED_SIZE]; // Private seed (SK.seed)
51 uint8_t prf[XMSS_MAX_SEED_SIZE]; // PRF key (SK.prf)
52 uint64_t idx; // Next unused leaf index
53 uint8_t root[XMSS_MAX_MDSIZE]; // Tree root (PK.root)
54 uint8_t pubSeed[XMSS_MAX_SEED_SIZE]; // Public seed (PK.seed)
55 } key;
56
57 /* Library context */
58 void *libCtx;
59} CryptXmssCtx;
60
61/*
62 * Initialize XMSS context
63 *
64 * @param ctx XMSS context to initialize
65 * @param params XMSS parameters
66 *
67 * @return CRYPT_SUCCESS on success
68 */
69int32_t CRYPT_XMSS_InitInternal(CryptXmssCtx *ctx, const XmssParams *params);
70
71/*
72 * Generate XMSS key pair
73 *
74 * @param ctx XMSS context (will be populated with generated keys)
75 *
76 * @return CRYPT_SUCCESS on success
77 */
78int32_t CRYPT_XMSS_KeyGenInternal(CryptXmssCtx *ctx);
79
80/*
81 * Sign a message using XMSS
82 *
83 * @param ctx XMSS context
84 * @param msg Message to sign (n bytes)
85 * @param msgLen Length of message (must be n)
86 * @param sig Output signature buffer
87 * @param sigLen Input: buffer size, Output: actual signature length
88 *
89 * @return CRYPT_SUCCESS on success
90 * CRYPT_XMSS_ERR_KEY_EXPIRED if all signatures used
91 */
92int32_t CRYPT_XMSS_SignInternal(CryptXmssCtx *ctx, const uint8_t *msg, uint32_t msgLen, uint8_t *sig, uint32_t *sigLen);
93
94/*
95 * Verify an XMSS signature (internal)
96 *
97 * @param ctx XMSS context
98 * @param msg Message to verify (n bytes)
99 * @param msgLen Length of message (must be n)
100 * @param sig Signature to verify
101 * @param sigLen Length of signature
102 *
103 * @return CRYPT_SUCCESS on success
104 * CRYPT_XMSS_ERR_VERIFY_FAIL on verification failure
105 */
106int32_t CRYPT_XMSS_VerifyInternal(const CryptXmssCtx *ctx, const uint8_t *msg, uint32_t msgLen, const uint8_t *sig,
107 uint32_t sigLen);
108
109/*
110 * Initialize TreeCtx from XMSS context
111 *
112 * @param treeCtx [out] Tree context to initialize
113 * @param ctx [in] XMSS context
114 */
115void InitTreeCtxFromXmssCtx(TreeCtx *treeCtx, const CryptXmssCtx *ctx);
116#ifdef __cplusplus
117}
118#endif
119
120#endif // HITLS_CRYPTO_XMSS
121#endif // XMSS_LOCAL_H