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_WOTS_H 17 #define CRYPT_SLH_DSA_WOTS_H 18 19 #include "hitls_build.h" 20 #ifdef HITLS_CRYPTO_SLH_DSA 21 22 #include <stdint.h> 23 #include "crypt_slh_dsa.h" 24 25 /** 26 * @brief Compute a WOTS+ public key from a private key 27 * 28 * @param pub Output WOTS+ public key 29 * @param seed Public seed for chain computation 30 * @param adrs Address structure for domain separation 31 * @return int 0 on success, error code otherwise 32 */ 33 int WotsGeneratePublicKey(uint8_t *pub, SlhDsaAdrs *adrs, const CryptSlhDsaCtx *ctx); 34 35 /** 36 * @brief Sign a message using WOTS+ 37 * 38 * @param sig Output WOTS+ signature 39 * @param sigLen Length of the signature 40 * @param msg Input message to sign 41 * @param msgLen Length of the message 42 * @param adrs Address structure for domain separation 43 * @param ctx SLH-DSA context 44 * @return int 0 on success, error code otherwise 45 */ 46 int32_t WotsSign(uint8_t *sig, uint32_t *sigLen, const uint8_t *msg, uint32_t msgLen, SlhDsaAdrs *adrs, 47 const CryptSlhDsaCtx *ctx); 48 49 /** 50 * @brief Compute a WOTS+ public key from a signature and message 51 * 52 * @param msg Input message that was signed 53 * @param msgLen Length of the message 54 * @param sig WOTS+ signature 55 * @param sigLen Length of the signature 56 * @param adrs Address structure for domain separation 57 * @param ctx SLH-DSA context 58 * @param pub Output reconstructed WOTS+ public key, the length is n 59 * @return int 0 on success, error code otherwise 60 */ 61 int32_t WotsPubKeyFromSig(const uint8_t *msg, uint32_t msgLen, const uint8_t *sig, uint32_t sigLen, SlhDsaAdrs *adrs, 62 const CryptSlhDsaCtx *ctx, uint8_t *pub); 63 64 /** 65 * @brief Compute a WOTS+ chain 66 * 67 * @param x Input private key value to chain 68 * @param xLen Length of the input private key value 69 * @param start Starting position in the chain 70 * @param end Ending position in the chain 71 * @param seed Public seed for chain computation 72 * @param adrs Address structure for domain separation 73 * @param ctx SLH-DSA context 74 * @param output Output chain result, the length is n 75 * @return int 0 on success, error code otherwise 76 */ 77 int32_t WotsChain(const uint8_t *x, uint32_t xLen, uint32_t start, uint32_t end, const uint8_t *seed, SlhDsaAdrs *adrs, 78 const CryptSlhDsaCtx *ctx, uint8_t *output); 79 80 #endif // HITLS_CRYPTO_SLH_DSA 81 #endif // CRYPT_SLH_DSA_WOTS_H