#ifndef WOLF_CRYPT_ECCSI_H
#define WOLF_CRYPT_ECCSI_H
#include <wolfssl/wolfcrypt/types.h>
#ifdef WOLFCRYPT_HAVE_ECCSI
#include <wolfssl/wolfcrypt/wolfmath.h>
#include <wolfssl/wolfcrypt/ecc.h>
#include <wolfssl/wolfcrypt/hash.h>
#include <wolfssl/wolfcrypt/hmac.h>
#define WOLFCRYPT_ECCSI_KMS
#define WOLFCRYPT_ECCSI_CLIENT
#define MAX_ECCSI_BYTES (256 / 8)
#ifndef ECCSI_MAX_GEN_COUNT
#define ECCSI_MAX_GEN_COUNT 10
#endif
typedef struct EccsiKeyParams {
mp_int order;
#ifdef WOLFCRYPT_ECCSI_CLIENT
mp_int a;
mp_int b;
mp_int prime;
#endif
ecc_point* base;
WC_BITFIELD haveOrder:1;
WC_BITFIELD haveA:1;
WC_BITFIELD haveB:1;
WC_BITFIELD havePrime:1;
WC_BITFIELD haveBase:1;
} EccsiKeyParams;
typedef struct EccsiKey {
ecc_key ecc;
ecc_key pubkey;
EccsiKeyParams params;
#ifdef WOLFCRYPT_ECCSI_CLIENT
mp_int tmp;
mp_int ssk;
ecc_point* pvt;
#endif
wc_HashAlg hash;
byte data[(MAX_ECCSI_BYTES * 2) + 1];
#ifdef WOLFCRYPT_ECCSI_CLIENT
byte idHash[WC_MAX_DIGEST_SIZE];
byte idHashSz;
#endif
void* heap;
WC_BITFIELD kpakMont:1;
} EccsiKey;
#ifdef __cplusplus
extern "C" {
#endif
WOLFSSL_API int wc_InitEccsiKey(EccsiKey* key, void* heap, int devId);
WOLFSSL_API int wc_InitEccsiKey_ex(EccsiKey* key, int keySz, int curveId,
void* heap, int devId);
WOLFSSL_API void wc_FreeEccsiKey(EccsiKey* key);
WOLFSSL_API int wc_MakeEccsiKey(EccsiKey* key, WC_RNG* rng);
WOLFSSL_API int wc_MakeEccsiPair(EccsiKey* key, WC_RNG* rng,
enum wc_HashType hashType, const byte* id, word32 idSz, mp_int* ssk,
ecc_point* pvt);
WOLFSSL_API int wc_ValidateEccsiPair(EccsiKey* key, enum wc_HashType hashType,
const byte* id, word32 idSz, const mp_int* ssk, ecc_point* pvt,
int* valid);
WOLFSSL_API int wc_ValidateEccsiPvt(EccsiKey* key, const ecc_point* pvt,
int* valid);
WOLFSSL_API int wc_EncodeEccsiPair(const EccsiKey* key, mp_int* ssk,
ecc_point* pvt, byte* data, word32* sz);
WOLFSSL_API int wc_EncodeEccsiSsk(const EccsiKey* key, mp_int* ssk, byte* data,
word32* sz);
WOLFSSL_API int wc_EncodeEccsiPvt(const EccsiKey* key, ecc_point* pvt,
byte* data, word32* sz, int raw);
WOLFSSL_API int wc_DecodeEccsiPair(const EccsiKey* key, const byte* data,
word32 sz, mp_int* ssk, ecc_point* pvt);
WOLFSSL_API int wc_DecodeEccsiSsk(const EccsiKey* key, const byte* data,
word32 sz, mp_int* ssk);
WOLFSSL_API int wc_DecodeEccsiPvt(const EccsiKey* key, const byte* data,
word32 sz, ecc_point* pvt);
WOLFSSL_API int wc_DecodeEccsiPvtFromSig(const EccsiKey* key, const byte* sig,
word32 sz, ecc_point* pvt);
WOLFSSL_API int wc_ExportEccsiKey(EccsiKey* key, byte* data, word32* sz);
WOLFSSL_API int wc_ImportEccsiKey(EccsiKey* key, const byte* data, word32 sz);
WOLFSSL_API int wc_ExportEccsiPrivateKey(EccsiKey* key, byte* data, word32* sz);
WOLFSSL_API int wc_ImportEccsiPrivateKey(EccsiKey* key, const byte* data,
word32 sz);
WOLFSSL_API int wc_ExportEccsiPublicKey(EccsiKey* key, byte* data, word32* sz,
int raw);
WOLFSSL_API int wc_ImportEccsiPublicKey(EccsiKey* key, const byte* data,
word32 sz, int trusted);
WOLFSSL_API int wc_HashEccsiId(EccsiKey* key, enum wc_HashType hashType,
const byte* id, word32 idSz, ecc_point* pvt, byte* hash, byte* hashSz);
WOLFSSL_API int wc_SetEccsiHash(EccsiKey* key, const byte* hash, byte hashSz);
WOLFSSL_API int wc_SetEccsiPair(EccsiKey* key, const mp_int* ssk,
const ecc_point* pvt);
WOLFSSL_API int wc_SignEccsiHash(EccsiKey* key, WC_RNG* rng,
enum wc_HashType hashType, const byte* msg, word32 msgSz, byte* sig,
word32* sigSz);
WOLFSSL_API int wc_VerifyEccsiHash(EccsiKey* key, enum wc_HashType hashType,
const byte* msg, word32 msgSz, const byte* sig, word32 sigSz,
int* verified);
#ifdef __cplusplus
}
#endif
#endif
#endif