#ifndef WOLF_CRYPT_XMSS_H
#define WOLF_CRYPT_XMSS_H
#include <wolfssl/wolfcrypt/types.h>
#include <wolfssl/wolfcrypt/random.h>
#ifdef WOLFSSL_HAVE_XMSS
#define XMSS_SHA256_PUBLEN (68)
#define XMSS_NAME_LEN (16)
#define XMSSMT_NAME_MIN_LEN (20)
#define XMSSMT_NAME_MAX_LEN (21)
#if defined(HAVE_FIPS) || defined(HAVE_LIBXMSS)
#undef WOLFSSL_WC_XMSS_NO_SHA512
#define WOLFSSL_WC_XMSS_NO_SHA512
#undef WOLFSSL_WC_XMSS_NO_SHAKE128
#define WOLFSSL_WC_XMSS_NO_SHAKE128
#undef WOLFSSL_WC_XMSS_MAX_HASH_SIZE
#ifdef HAVE_LIBXMSS
#define WOLFSSL_WC_XMSS_MIN_HASH_SIZE 256
#else
#define WOLFSSL_WC_XMSS_MIN_HASH_SIZE 192
#endif
#define WOLFSSL_WC_XMSS_MAX_HASH_SIZE 256
#endif
#if !defined(NO_SHA256) && !defined(WOLFSSL_WC_XMSS_NO_SHA256)
#define WC_XMSS_SHA256
#endif
#if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_WC_XMSS_NO_SHA512)
#define WC_XMSS_SHA512
#endif
#if defined(WOLFSSL_SHAKE128) && !defined(WOLFSSL_WC_XMSS_NO_SHAKE128)
#define WC_XMSS_SHAKE128
#endif
#if defined(WOLFSSL_SHAKE256) && !defined(WOLFSSL_WC_XMSS_NO_SHAKE256)
#define WC_XMSS_SHAKE256
#endif
#ifndef WOLFSSL_WC_XMSS_MIN_HASH_SIZE
#define WOLFSSL_WC_XMSS_MIN_HASH_SIZE 192
#endif
#ifndef WOLFSSL_WC_XMSS_MAX_HASH_SIZE
#define WOLFSSL_WC_XMSS_MAX_HASH_SIZE 512
#endif
#if WOLFSSL_WC_XMSS_MIN_HASH_SIZE > WOLFSSL_WC_XMSS_MAX_HASH_SIZE
#error "XMSS minimum hash size is greater than maximum hash size"
#endif
#ifndef WOLFSSL_XMSS_MIN_HEIGHT
#define WOLFSSL_XMSS_MIN_HEIGHT 10
#endif
#ifndef WOLFSSL_XMSS_MAX_HEIGHT
#define WOLFSSL_XMSS_MAX_HEIGHT 60
#endif
#if WOLFSSL_XMSS_MIN_HEIGHT > WOLFSSL_XMSS_MAX_HEIGHT
#error "XMSS minimum height is greater than maximum height"
#endif
typedef struct XmssKey XmssKey;
enum wc_XmssRc {
WC_XMSS_RC_NONE,
WC_XMSS_RC_BAD_ARG,
WC_XMSS_RC_WRITE_FAIL,
WC_XMSS_RC_READ_FAIL,
WC_XMSS_RC_SAVED_TO_NV_MEMORY,
WC_XMSS_RC_READ_TO_MEMORY
};
enum wc_XmssState {
WC_XMSS_STATE_FREED,
WC_XMSS_STATE_INITED,
WC_XMSS_STATE_PARMSET,
WC_XMSS_STATE_OK,
WC_XMSS_STATE_VERIFYONLY,
WC_XMSS_STATE_BAD,
WC_XMSS_STATE_NOSIGS
};
typedef enum wc_XmssRc (*wc_xmss_write_private_key_cb)(const byte* priv, word32 privSz,
void* context);
typedef enum wc_XmssRc (*wc_xmss_read_private_key_cb)(byte* priv, word32 privSz,
void* context);
#ifdef __cplusplus
extern "C" {
#endif
WOLFSSL_API int wc_XmssKey_Init(XmssKey* key, void* heap, int devId);
WOLFSSL_API int wc_XmssKey_SetParamStr(XmssKey* key, const char* str);
#ifndef WOLFSSL_XMSS_VERIFY_ONLY
WOLFSSL_API int wc_XmssKey_SetWriteCb(XmssKey* key,
wc_xmss_write_private_key_cb write_cb);
WOLFSSL_API int wc_XmssKey_SetReadCb(XmssKey* key,
wc_xmss_read_private_key_cb read_cb);
WOLFSSL_API int wc_XmssKey_SetContext(XmssKey* key, void* context);
WOLFSSL_API int wc_XmssKey_MakeKey(XmssKey* key, WC_RNG* rng);
WOLFSSL_API int wc_XmssKey_Reload(XmssKey* key);
WOLFSSL_API int wc_XmssKey_GetPrivLen(const XmssKey* key, word32* len);
WOLFSSL_API int wc_XmssKey_Sign(XmssKey* key, byte* sig, word32* sigSz,
const byte* msg, int msgSz);
WOLFSSL_API int wc_XmssKey_SigsLeft(XmssKey* key);
#endif
WOLFSSL_API void wc_XmssKey_Free(XmssKey* key);
WOLFSSL_API int wc_XmssKey_GetSigLen(const XmssKey* key, word32* len);
WOLFSSL_API int wc_XmssKey_GetPubLen(const XmssKey* key, word32* len);
WOLFSSL_API int wc_XmssKey_ExportPub(XmssKey* keyDst, const XmssKey* keySrc);
WOLFSSL_API int wc_XmssKey_ExportPubRaw(const XmssKey* key, byte* out,
word32* outLen);
WOLFSSL_API int wc_XmssKey_ImportPubRaw(XmssKey* key, const byte* in,
word32 inLen);
WOLFSSL_API int wc_XmssKey_Verify(XmssKey* key, const byte* sig, word32 sigSz,
const byte* msg, int msgSz);
#ifdef __cplusplus
}
#endif
#endif
#endif