API参考
载入中...
搜索中...
未找到
xmss_wots.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_WOTS_H
17#define XMSS_WOTS_H
18
19#include "hitls_build.h"
20#ifdef HITLS_CRYPTO_XMSS
21
22#include <stdint.h>
23#include <stddef.h>
24#include "xmss_address.h"
25#include "xmss_local.h"
26
27#ifdef __cplusplus
28extern "C" {
29#endif
30
31/*
32 * XMSS WOTS+ Context
33 * This structure encapsulates the parameters needed for WOTS+ operations
34 * Uses generic interfaces for hash functions and address operations
35 */
36typedef struct {
37 void *coreCtx; // Pointer to original context (CryptXmssCtx or CryptSlhDsaCtx)
38 uint32_t n; // Hash output length
39 uint32_t wotsLen; // WOTS+ chain length
40 const CryptHashFuncs *hashFuncs; // Generic hash function table (pointer)
41 const CryptAdrsOps *adrsOps; // Generic address operation function pointers
42 const uint8_t *pubSeed; // Public seed (for key derivation)
43 const uint8_t *skSeed; // Private seed (for WOTS+ key generation)
44 bool isXmss;
45} XmssWotsCtx;
46
47/*
48 * Generate a WOTS+ public key from a private key
49 *
50 * Computes the WOTS+ public key by chaining each private key element.
51 *
52 * @param pub Output WOTS+ public key (n bytes)
53 * @param adrs Address for domain separation
54 * @param ctx WOTS+ context
55 *
56 * @return CRYPT_SUCCESS on success
57 */
58int32_t XmssWots_GeneratePublicKey(uint8_t *pub, void *adrs, const XmssWotsCtx *ctx);
59
60/*
61 * Sign a message using WOTS+
62 *
63 * @param sig Output WOTS+ signature (len * n bytes)
64 * @param sigLen Input: buffer size, Output: actual signature length
65 * @param msg Message to sign (n bytes - already hashed)
66 * @param msgLen Length of message (must be n)
67 * @param adrs Address for domain separation
68 * @param ctx WOTS+ context
69 *
70 * @return CRYPT_SUCCESS on success
71 */
72int32_t XmssWots_Sign(uint8_t *sig, uint32_t *sigLen, const uint8_t *msg, uint32_t msgLen, void *adrs,
73 const XmssWotsCtx *ctx);
74
75/*
76 * Compute a WOTS+ public key from a signature and message
77 *
78 * Reconstructs the WOTS+ public key from the signature by completing
79 * the chains from the signature values.
80 *
81 * @param msg Message that was signed (n bytes)
82 * @param msgLen Length of message (must be n)
83 * @param sig WOTS+ signature (len * n bytes)
84 * @param sigLen Length of signature
85 * @param adrs Address for domain separation
86 * @param ctx WOTS+ context
87 * @param pub Output reconstructed WOTS+ public key (n bytes)
88 *
89 * @return CRYPT_SUCCESS on success
90 */
91int32_t XmssWots_PkFromSig(const uint8_t *msg, uint32_t msgLen, const uint8_t *sig, uint32_t sigLen, void *adrs,
92 const XmssWotsCtx *ctx, uint8_t *pub);
93
94#ifdef __cplusplus
95}
96#endif
97
98#endif // HITLS_CRYPTO_XMSS
99#endif // XMSS_WOTS_H