1
1
mirror of https://github.com/henrydcase/pqc.git synced 2024-11-25 17:01:22 +00:00
pqcrypto/public/pqc/pqc.h

142 lines
3.9 KiB
C
Raw Normal View History

2021-03-24 10:25:45 +00:00
#ifndef PQAPI_H_
#define PQAPI_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
#include <stdbool.h>
// Defines supported signature algorithm list. The resulting
// ID of an algorithm is PQC_ALG_SIG_(NAME_AS_BELOW)
#define PQC_SUPPORTED_SIGS(_) \
2021-03-24 23:22:44 +00:00
_(DILITHIUM2) \
_(DILITHIUM3) \
_(DILITHIUM5) \
_(FALCON512) \
2021-05-17 11:24:34 +01:00
_(FALCON1024) \
2021-03-24 23:22:44 +00:00
_(SPHINCSSHAKE256128FSIMPLE) \
_(SPHINCSSHAKE256128SSIMPLE) \
_(SPHINCSSHAKE256128FROBUST) \
_(SPHINCSSHAKE256128SROBUST) \
2021-05-17 11:24:34 +01:00
_(SPHINCSSHAKE256192FSIMPLE) \
2021-03-24 23:22:44 +00:00
_(SPHINCSSHAKE256192SSIMPLE) \
2021-05-17 11:24:34 +01:00
_(SPHINCSSHAKE256192FROBUST) \
2021-03-24 23:22:44 +00:00
_(SPHINCSSHAKE256192SROBUST) \
2021-05-17 11:24:34 +01:00
_(SPHINCSSHAKE256256FSIMPLE) \
_(SPHINCSSHAKE256256SSIMPLE) \
2021-03-24 23:22:44 +00:00
_(SPHINCSSHAKE256256FROBUST) \
2021-05-17 11:24:34 +01:00
_(SPHINCSSHAKE256256SROBUST) \
2021-03-24 23:22:44 +00:00
_(SPHINCSSHA256128FSIMPLE) \
2021-05-17 11:24:34 +01:00
_(SPHINCSSHA256128SSIMPLE) \
_(SPHINCSSHA256128FROBUST) \
_(SPHINCSSHA256128SROBUST) \
_(SPHINCSSHA256192FSIMPLE) \
_(SPHINCSSHA256192SSIMPLE) \
_(SPHINCSSHA256192FROBUST) \
_(SPHINCSSHA256192SROBUST) \
_(SPHINCSSHA256256FSIMPLE) \
_(SPHINCSSHA256256SSIMPLE) \
_(SPHINCSSHA256256FROBUST) \
_(SPHINCSSHA256256SROBUST)
2021-03-24 23:22:44 +00:00
// Defines supported kem algorithm list. The resulting
// ID of an algorithm is PQC_ALG_KEM_(NAME_AS_BELOW)
2021-03-24 23:22:44 +00:00
#define PQC_SUPPORTED_KEMS(_)\
2021-05-17 11:24:34 +01:00
_(KYBER512) \
2021-03-24 23:22:44 +00:00
_(KYBER768) \
_(KYBER1024) \
2021-03-27 00:34:03 +00:00
_(HQCRMRS128) \
_(HQCRMRS192) \
_(HQCRMRS256) \
2021-05-26 13:09:25 +01:00
_(MCELIECE348864) \
_(MCELIECE460896) \
_(MCELIECE6688128) \
_(MCELIECE6960119) \
_(MCELIECE8192128) \
_(MCELIECE348864F) \
_(MCELIECE460896F) \
_(MCELIECE6688128F) \
_(MCELIECE6960119F) \
_(MCELIECE8192128F)
2021-03-24 23:22:44 +00:00
// Defines IDs for each algorithm. The
// PQC_ALG_SIG/KEM_MAX indicates number
// of KEM and signature schemes supported.
#define DEFNUM_SIG(N) PQC_ALG_SIG_##N,
#define DEFNUM_KEM(N) PQC_ALG_KEM_##N,
enum { PQC_SUPPORTED_SIGS(DEFNUM_SIG) PQC_ALG_SIG_MAX };
enum { PQC_SUPPORTED_KEMS(DEFNUM_KEM) PQC_ALG_KEM_MAX };
#undef DEFNUM_SIG
#undef DEFNUM_KEM
2021-03-24 23:22:44 +00:00
2021-03-24 10:25:45 +00:00
// Parameters of the scheme
2021-05-10 16:01:48 +01:00
typedef struct pqc_ctx_t {
2021-03-24 10:25:45 +00:00
const uint8_t alg_id;
const char* alg_name;
const uint32_t prv_key_bsz;
const uint32_t pub_key_bsz;
const bool is_kem;
int (*keygen)(uint8_t *sk, uint8_t *pk);
2021-05-10 16:01:48 +01:00
} pqc_ctx_t;
2021-03-24 10:25:45 +00:00
2021-05-10 16:01:48 +01:00
typedef struct pqc_kem_ctx_t {
pqc_ctx_t p;
2021-03-24 10:25:45 +00:00
const uint32_t ciphertext_bsz;
const uint32_t secret_bsz;
int (*encapsulate)(uint8_t *ct, uint8_t *ss, const uint8_t *pk);
int (*decapsulate)(uint8_t *ss, const uint8_t *ct, const uint8_t *sk);
2021-05-10 16:01:48 +01:00
} pqc_kem_ctx_t;
2021-03-24 10:25:45 +00:00
2021-05-10 16:01:48 +01:00
typedef struct pqc_sig_ctx_t {
pqc_ctx_t p;
2021-03-24 10:25:45 +00:00
const uint32_t sign_bsz;
int (*sign)(uint8_t *sig, uint64_t *siglen, const uint8_t *m, uint64_t mlen, const uint8_t *sk);
int (*verify)(const uint8_t *sig, uint64_t siglen, const uint8_t *m, uint64_t mlen, const uint8_t *pk);
2021-05-10 16:01:48 +01:00
} pqc_sig_ctx_t;
2021-03-24 10:25:45 +00:00
bool pqc_keygen(
2021-05-10 16:01:48 +01:00
const pqc_ctx_t *p,
uint8_t *pk, uint8_t *sk);
2021-03-24 10:25:45 +00:00
bool pqc_kem_encapsulate(
2021-05-10 16:01:48 +01:00
const pqc_ctx_t *p,
2021-03-24 10:25:45 +00:00
uint8_t *ct, uint8_t *ss,
const uint8_t *pk);
bool pqc_kem_decapsulate(
2021-05-10 16:01:48 +01:00
const pqc_ctx_t *p,
2021-03-24 10:25:45 +00:00
uint8_t *ss, const uint8_t *ct,
const uint8_t *sk);
bool pqc_sig_create(
2021-05-10 16:01:48 +01:00
const pqc_ctx_t *p,
2021-03-24 10:25:45 +00:00
uint8_t *sig, uint64_t *siglen,
const uint8_t *m, uint64_t mlen,
const uint8_t *sk);
bool pqc_sig_verify(
2021-05-10 16:01:48 +01:00
const pqc_ctx_t *p,
2021-03-24 10:25:45 +00:00
const uint8_t *sig, uint64_t siglen,
const uint8_t *m, uint64_t mlen,
const uint8_t *pk);
2021-03-24 23:22:44 +00:00
2021-05-10 16:01:48 +01:00
const pqc_ctx_t *pqc_kem_alg_by_id(uint8_t id);
const pqc_ctx_t *pqc_sig_alg_by_id(uint8_t id);
uint32_t pqc_ciphertext_bsz(const pqc_ctx_t *p);
uint32_t pqc_shared_secret_bsz(const pqc_ctx_t *p);
uint32_t pqc_signature_bsz(const pqc_ctx_t *p);
uint32_t pqc_public_key_bsz(const pqc_ctx_t *p);
uint32_t pqc_private_key_bsz(const pqc_ctx_t *p);
2021-03-24 23:22:44 +00:00
2021-03-24 10:25:45 +00:00
#ifdef __cplusplus
}
#endif
#endif