API参考
载入中...
搜索中...
未找到
xmss_common.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_COMMON_H
17#define XMSS_COMMON_H
18
19#include "hitls_build.h"
20#if defined(HITLS_CRYPTO_XMSS) || defined(HITLS_CRYPTO_SLH_DSA)
21
22#include <stdint.h>
23#include <stddef.h>
24
25#ifdef __cplusplus
26extern "C" {
27#endif
28
29/* Maximum digest size for hash operations (shared between XMSS and SLH-DSA) */
30#define MAX_MDSIZE 64
31#define MAX_ADRS_SIZE 32
32
33/*
34 * Multi-message hash calculation utility
35 *
36 * This function is used by both XMSS and SLH-DSA for computing
37 * hash of multiple message segments.
38 *
39 * @param mdId Hash algorithm ID
40 * @param hashData Array of message segments
41 * @param hashDataLen Number of segments
42 * @param out Output buffer
43 * @param outLen Output length (will be truncated if needed)
44 *
45 * @return CRYPT_SUCCESS on success
46 */
47int32_t CalcMultiMsgHash(CRYPT_MD_AlgId mdId, const CRYPT_ConstData *hashData, uint32_t hashDataLen, uint8_t *out,
48 uint32_t outLen);
49
50
51
52/*
53 * Generic Hash Functions Interface
54 *
55 * This structure defines a set of generic hash function pointers that can be
56 * implemented by different cryptographic algorithms (XMSS, SLH-DSA, etc.).
57 */
58typedef struct CryptHashFuncs {
63 int32_t (*prf)(const void *ctx, const void *adrs, uint8_t *out);
64
69 int32_t (*f)(const void *ctx, const void *adrs, const uint8_t *msg, uint32_t msgLen, uint8_t *out);
70
75 int32_t (*h)(const void *ctx, const void *adrs, const uint8_t *in, uint32_t inLen, uint8_t *out);
76
81 int32_t (*hmsg)(const void *ctx, const uint8_t *r, const uint8_t *msg, uint32_t msgLen, const uint8_t *idx,
82 uint8_t *out);
83
88 int32_t (*tl)(const void *ctx, const void *adrs, const uint8_t *msg, uint32_t msgLen, uint8_t *out);
89
94 int32_t (*prfmsg)(const void *ctx, const uint8_t *key, const uint8_t *msg, uint32_t msgLen, uint8_t *out);
95
100 int32_t (*chain)(const uint8_t *x, uint32_t xLen, uint32_t start, uint32_t steps, const uint8_t *pubSeed,
101 void *adrs, const void *ctx, uint8_t *output);
102} CryptHashFuncs;
103
104/*
105 * Generic Address Operations Interface
106 *
107 * This structure provides a standard interface for manipulating addresses
108 * used by both XMSS and SLH-DSA.
109 */
110typedef struct CryptAdrsOps {
111 /* Set functions - modify address fields */
112 void (*setLayerAddr)(void *adrs, uint32_t layer);
113 void (*setTreeAddr)(void *adrs, uint64_t tree);
114 void (*setType)(void *adrs, uint32_t type);
115 void (*setKeyPairAddr)(void *adrs, uint32_t keyPair);
116 void (*setChainAddr)(void *adrs, uint32_t chain);
117 void (*setTreeHeight)(void *adrs, uint32_t height);
118 void (*setHashAddr)(void *adrs, uint32_t hash);
119 void (*setTreeIndex)(void *adrs, uint32_t index);
120
121 /* Get functions - retrieve address fields */
122 uint32_t (*getTreeHeight)(const void *adrs);
123 uint32_t (*getTreeIndex)(const void *adrs);
124
125 /* Copy function */
126 void (*copyKeyPairAddr)(void *dest, const void *src);
127
128 /* Utility */
129 uint32_t (*getAdrsLen)(void);
130} CryptAdrsOps;
131
132#ifdef __cplusplus
133}
134#endif
135
136#endif // HITLS_CRYPTO_XMSS || HITLS_CRYPTO_SLH_DSA
137#endif // XMSS_COMMON_H
CRYPT_MD_AlgId
定义 crypt_algid.h:68
定义 crypt_types.h:48