You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

142 lines
3.9 KiB

  1. #ifndef PQAPI_H_
  2. #define PQAPI_H_
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. #include <stdint.h>
  7. #include <stdbool.h>
  8. // Defines supported signature algorithm list. The resulting
  9. // ID of an algorithm is PQC_ALG_SIG_(NAME_AS_BELOW)
  10. #define PQC_SUPPORTED_SIGS(_) \
  11. _(DILITHIUM2) \
  12. _(DILITHIUM3) \
  13. _(DILITHIUM5) \
  14. _(FALCON512) \
  15. _(FALCON1024) \
  16. _(SPHINCSSHAKE256128FSIMPLE) \
  17. _(SPHINCSSHAKE256128SSIMPLE) \
  18. _(SPHINCSSHAKE256128FROBUST) \
  19. _(SPHINCSSHAKE256128SROBUST) \
  20. _(SPHINCSSHAKE256192FSIMPLE) \
  21. _(SPHINCSSHAKE256192SSIMPLE) \
  22. _(SPHINCSSHAKE256192FROBUST) \
  23. _(SPHINCSSHAKE256192SROBUST) \
  24. _(SPHINCSSHAKE256256FSIMPLE) \
  25. _(SPHINCSSHAKE256256SSIMPLE) \
  26. _(SPHINCSSHAKE256256FROBUST) \
  27. _(SPHINCSSHAKE256256SROBUST) \
  28. _(SPHINCSSHA256128FSIMPLE) \
  29. _(SPHINCSSHA256128SSIMPLE) \
  30. _(SPHINCSSHA256128FROBUST) \
  31. _(SPHINCSSHA256128SROBUST) \
  32. _(SPHINCSSHA256192FSIMPLE) \
  33. _(SPHINCSSHA256192SSIMPLE) \
  34. _(SPHINCSSHA256192FROBUST) \
  35. _(SPHINCSSHA256192SROBUST) \
  36. _(SPHINCSSHA256256FSIMPLE) \
  37. _(SPHINCSSHA256256SSIMPLE) \
  38. _(SPHINCSSHA256256FROBUST) \
  39. _(SPHINCSSHA256256SROBUST)
  40. // Defines supported kem algorithm list. The resulting
  41. // ID of an algorithm is PQC_ALG_KEM_(NAME_AS_BELOW)
  42. #define PQC_SUPPORTED_KEMS(_)\
  43. _(KYBER512) \
  44. _(KYBER768) \
  45. _(KYBER1024) \
  46. _(HQCRMRS128) \
  47. _(HQCRMRS192) \
  48. _(HQCRMRS256) \
  49. _(MCELIECE348864) \
  50. _(MCELIECE460896) \
  51. _(MCELIECE6688128) \
  52. _(MCELIECE6960119) \
  53. _(MCELIECE8192128) \
  54. _(MCELIECE348864F) \
  55. _(MCELIECE460896F) \
  56. _(MCELIECE6688128F) \
  57. _(MCELIECE6960119F) \
  58. _(MCELIECE8192128F)
  59. // Defines IDs for each algorithm. The
  60. // PQC_ALG_SIG/KEM_MAX indicates number
  61. // of KEM and signature schemes supported.
  62. #define DEFNUM_SIG(N) PQC_ALG_SIG_##N,
  63. #define DEFNUM_KEM(N) PQC_ALG_KEM_##N,
  64. enum { PQC_SUPPORTED_SIGS(DEFNUM_SIG) PQC_ALG_SIG_MAX };
  65. enum { PQC_SUPPORTED_KEMS(DEFNUM_KEM) PQC_ALG_KEM_MAX };
  66. #undef DEFNUM_SIG
  67. #undef DEFNUM_KEM
  68. // Parameters of the scheme
  69. typedef struct pqc_ctx_t {
  70. const uint8_t alg_id;
  71. const char* alg_name;
  72. const uint32_t prv_key_bsz;
  73. const uint32_t pub_key_bsz;
  74. const bool is_kem;
  75. int (*keygen)(uint8_t *sk, uint8_t *pk);
  76. } pqc_ctx_t;
  77. typedef struct pqc_kem_ctx_t {
  78. pqc_ctx_t p;
  79. const uint32_t ciphertext_bsz;
  80. const uint32_t secret_bsz;
  81. int (*encapsulate)(uint8_t *ct, uint8_t *ss, const uint8_t *pk);
  82. int (*decapsulate)(uint8_t *ss, const uint8_t *ct, const uint8_t *sk);
  83. } pqc_kem_ctx_t;
  84. typedef struct pqc_sig_ctx_t {
  85. pqc_ctx_t p;
  86. const uint32_t sign_bsz;
  87. int (*sign)(uint8_t *sig, uint64_t *siglen, const uint8_t *m, uint64_t mlen, const uint8_t *sk);
  88. int (*verify)(const uint8_t *sig, uint64_t siglen, const uint8_t *m, uint64_t mlen, const uint8_t *pk);
  89. } pqc_sig_ctx_t;
  90. bool pqc_keygen(
  91. const pqc_ctx_t *p,
  92. uint8_t *pk, uint8_t *sk);
  93. bool pqc_kem_encapsulate(
  94. const pqc_ctx_t *p,
  95. uint8_t *ct, uint8_t *ss,
  96. const uint8_t *pk);
  97. bool pqc_kem_decapsulate(
  98. const pqc_ctx_t *p,
  99. uint8_t *ss, const uint8_t *ct,
  100. const uint8_t *sk);
  101. bool pqc_sig_create(
  102. const pqc_ctx_t *p,
  103. uint8_t *sig, uint64_t *siglen,
  104. const uint8_t *m, uint64_t mlen,
  105. const uint8_t *sk);
  106. bool pqc_sig_verify(
  107. const pqc_ctx_t *p,
  108. const uint8_t *sig, uint64_t siglen,
  109. const uint8_t *m, uint64_t mlen,
  110. const uint8_t *pk);
  111. const pqc_ctx_t *pqc_kem_alg_by_id(uint8_t id);
  112. const pqc_ctx_t *pqc_sig_alg_by_id(uint8_t id);
  113. uint32_t pqc_ciphertext_bsz(const pqc_ctx_t *p);
  114. uint32_t pqc_shared_secret_bsz(const pqc_ctx_t *p);
  115. uint32_t pqc_signature_bsz(const pqc_ctx_t *p);
  116. uint32_t pqc_public_key_bsz(const pqc_ctx_t *p);
  117. uint32_t pqc_private_key_bsz(const pqc_ctx_t *p);
  118. #ifdef __cplusplus
  119. }
  120. #endif
  121. #endif