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 CRYPT_SLH_DSA_H 17 #define CRYPT_SLH_DSA_H 18 19 #include "hitls_build.h" 20 #ifdef HITLS_CRYPTO_SLH_DSA 21 22 #include <stdint.h> 23 #include "bsl_params.h" 24 25 typedef struct SlhDsaCtx CryptSlhDsaCtx; 26 typedef struct HashFuncs SlhDsaHashFuncs; 27 typedef union Adrs SlhDsaAdrs; 28 29 /** 30 * @brief Create a new SLH-DSA context 31 * 32 * @return CryptSlhDsaCtx* Pointer to the new SLH-DSA context 33 */ 34 CryptSlhDsaCtx *CRYPT_SLH_DSA_NewCtx(void); 35 36 /** 37 * @brief Create a new SLH-DSA context 38 * 39 * @param libCtx Pointer to the library context 40 * 41 * @return CryptSlhDsaCtx* Pointer to the new SLH-DSA context 42 */ 43 CryptSlhDsaCtx *CRYPT_SLH_DSA_NewCtxEx(void *libCtx); 44 45 /** 46 * @brief Free a SLH-DSA context 47 * 48 * @param ctx Pointer to the SLH-DSA context 49 */ 50 void CRYPT_SLH_DSA_FreeCtx(CryptSlhDsaCtx *ctx); 51 52 /** 53 * @brief Generate a SLH-DSA key pair 54 * 55 * @param ctx Pointer to the SLH-DSA context 56 */ 57 int32_t CRYPT_SLH_DSA_Gen(CryptSlhDsaCtx *ctx); 58 59 /** 60 * @brief Sign data using SLH-DSA 61 * 62 * @param ctx Pointer to the SLH-DSA context 63 * @param algId Algorithm ID 64 * @param data Pointer to the data to sign 65 * @param dataLen Length of the data 66 * @param sign Pointer to the signature 67 * @param signLen Length of the signature 68 */ 69 int32_t CRYPT_SLH_DSA_Sign(CryptSlhDsaCtx *ctx, int32_t algId, const uint8_t *data, uint32_t dataLen, uint8_t *sign, 70 uint32_t *signLen); 71 72 /** 73 * @brief Verify data using SLH-DSA 74 * 75 * @param ctx Pointer to the SLH-DSA context 76 * @param algId Algorithm ID 77 * @param data Pointer to the data to verify 78 * @param dataLen Length of the data 79 * @param sign Pointer to the signature 80 * @param signLen Length of the signature 81 */ 82 83 int32_t CRYPT_SLH_DSA_Verify(const CryptSlhDsaCtx *ctx, int32_t algId, const uint8_t *data, uint32_t dataLen, 84 const uint8_t *sign, uint32_t signLen); 85 86 /** 87 * @brief Control function for SLH-DSA 88 * 89 * @param ctx Pointer to the SLH-DSA context 90 * @param opt Option 91 * @param val Value 92 * @param len Length of the value 93 */ 94 int32_t CRYPT_SLH_DSA_Ctrl(CryptSlhDsaCtx *ctx, int32_t opt, void *val, uint32_t len); 95 96 /** 97 * @brief Get the public key of SLH-DSA 98 * 99 * @param ctx Pointer to the SLH-DSA context 100 * @param para Pointer to the public key 101 */ 102 int32_t CRYPT_SLH_DSA_GetPubKey(const CryptSlhDsaCtx *ctx, BSL_Param *para); 103 104 /** 105 * @brief Get the private key of SLH-DSA 106 * 107 * @param ctx Pointer to the SLH-DSA context 108 * @param para Pointer to the private key 109 */ 110 int32_t CRYPT_SLH_DSA_GetPrvKey(const CryptSlhDsaCtx *ctx, BSL_Param *para); 111 112 /** 113 * @brief Set the public key of SLH-DSA 114 * 115 * @param ctx Pointer to the SLH-DSA context 116 * @param para Pointer to the public key 117 */ 118 int32_t CRYPT_SLH_DSA_SetPubKey(CryptSlhDsaCtx *ctx, const BSL_Param *para); 119 120 /** 121 * @brief Set the private key of SLH-DSA 122 * 123 * @param ctx Pointer to the SLH-DSA context 124 * @param para Pointer to the private key 125 */ 126 int32_t CRYPT_SLH_DSA_SetPrvKey(CryptSlhDsaCtx *ctx, const BSL_Param *para); 127 128 #endif // HITLS_CRYPTO_SLH_DSA 129 #endif // CRYPT_SLH_DSA_H