#ifndef SPX_API_H
#define SPX_API_H

#include <Library/UefiLib.h>
#include <Library/BaseLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/BaseMemoryLib.h>
#include <Uefi.h>

#include "params.h"

#define CRYPTO_ALGNAME "SPHINCS+"

#define CRYPTO_SECRETKEYBYTES SPX_SK_BYTES
#define CRYPTO_PUBLICKEYBYTES SPX_PK_BYTES
#define CRYPTO_BYTES SPX_BYTES
#define CRYPTO_SEEDBYTES 3*SPX_N

/*
 * Returns the length of a secret key, in bytes
 */
UINT64 crypto_sign_secretkeybytes(VOID);

/*
 * Returns the length of a public key, in bytes
 */
UINT64 crypto_sign_publickeybytes(VOID);

/*
 * Returns the length of a signature, in bytes
 */
UINT64 crypto_sign_bytes(VOID);

/*
 * Returns the length of the seed required to generate a key pair, in bytes
 */
UINT64 crypto_sign_seedbytes(VOID);

/*
 * Generates a SPHINCS+ key pair given a seed.
 * Format sk: [SK_SEED || SK_PRF || PUB_SEED || root]
 * Format pk: [root || PUB_SEED]
 */
INTN crypto_sign_seed_keypair(UINT8 *pk, UINT8 *sk,
                             const UINT8 *seed);

/*
 * Generates a SPHINCS+ key pair.
 * Format sk: [SK_SEED || SK_PRF || PUB_SEED || root]
 * Format pk: [root || PUB_SEED]
 */
INTN crypto_sign_keypair(UINT8 *pk, UINT8 *sk);

/**
 * Returns an array containing a detached signature.
 */
INTN crypto_sign_signature(UINT8 *sig, UINTN *siglen,
                          const UINT8 *m, UINTN mlen, const UINT8 *sk);

/**
 * Verifies a detached signature and message under a given public key.
 */
INTN crypto_sign_verify(const UINT8 *sig, UINTN siglen,
                       const UINT8 *m, UINTN mlen, const UINT8 *pk);

/**
 * Returns an array containing the signature followed by the message.
 */
INTN crypto_sign(UINT8 *sm, UINT64 *smlen,
                const UINT8 *m, UINT64 mlen,
                const UINT8 *sk);

/**
 * Verifies a given signature-message pair under a given public key.
 */
INTN crypto_sign_open(UINT8 *m, UINT64 *mlen,
                     const UINT8 *sm, UINT64 smlen,
                     const UINT8 *pk);

#endif
