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.
 
 
 

159 line
4.4 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. _(RAINBOWICLASSIC) \
  17. _(RAINBOWIIICLASSIC) \
  18. _(RAINBOWVCLASSIC) \
  19. _(SPHINCSSHAKE256128FSIMPLE) \
  20. _(SPHINCSSHAKE256128SSIMPLE) \
  21. _(SPHINCSSHAKE256128FROBUST) \
  22. _(SPHINCSSHAKE256128SROBUST) \
  23. _(SPHINCSSHAKE256192FSIMPLE) \
  24. _(SPHINCSSHAKE256192SSIMPLE) \
  25. _(SPHINCSSHAKE256192FROBUST) \
  26. _(SPHINCSSHAKE256192SROBUST) \
  27. _(SPHINCSSHAKE256256FSIMPLE) \
  28. _(SPHINCSSHAKE256256SSIMPLE) \
  29. _(SPHINCSSHAKE256256FROBUST) \
  30. _(SPHINCSSHAKE256256SROBUST) \
  31. _(SPHINCSSHA256128FSIMPLE) \
  32. _(SPHINCSSHA256128SSIMPLE) \
  33. _(SPHINCSSHA256128FROBUST) \
  34. _(SPHINCSSHA256128SROBUST) \
  35. _(SPHINCSSHA256192FSIMPLE) \
  36. _(SPHINCSSHA256192SSIMPLE) \
  37. _(SPHINCSSHA256192FROBUST) \
  38. _(SPHINCSSHA256192SROBUST) \
  39. _(SPHINCSSHA256256FSIMPLE) \
  40. _(SPHINCSSHA256256SSIMPLE) \
  41. _(SPHINCSSHA256256FROBUST) \
  42. _(SPHINCSSHA256256SROBUST)
  43. // Defines supported kem algorithm list. The resulting
  44. // ID of an algorithm is PQC_ALG_KEM_(NAME_AS_BELOW)
  45. #define PQC_SUPPORTED_KEMS(_)\
  46. _(FRODOKEM640SHAKE) \
  47. _(FRODOKEM976SHAKE) \
  48. _(FRODOKEM1344SHAKE) \
  49. _(KYBER512) \
  50. _(KYBER768) \
  51. _(KYBER1024) \
  52. _(NTRUHPS2048509) \
  53. _(NTRUHPS4096821) \
  54. _(NTRUHRSS701) \
  55. _(NTRUHPS2048677) \
  56. _(NTRULPR761) \
  57. _(NTRULPR653) \
  58. _(NTRULPR857) \
  59. _(LIGHTSABER) \
  60. _(SABER) \
  61. _(FIRESABER) \
  62. _(HQCRMRS128) \
  63. _(HQCRMRS192) \
  64. _(HQCRMRS256) \
  65. _(SIKE434) \
  66. _(MCELIECE348864) \
  67. _(MCELIECE460896) \
  68. _(MCELIECE6688128) \
  69. _(MCELIECE6960119) \
  70. _(MCELIECE8192128) \
  71. _(MCELIECE348864F) \
  72. _(MCELIECE460896F) \
  73. _(MCELIECE6688128F) \
  74. _(MCELIECE6960119F) \
  75. _(MCELIECE8192128F)
  76. // Defines IDs for each algorithm. The
  77. // PQC_ALG_SIG/KEM_MAX indicates number
  78. // of KEM and signature schemes supported.
  79. #define DEFNUM_SIG(N) PQC_ALG_SIG_##N,
  80. #define DEFNUM_KEM(N) PQC_ALG_KEM_##N,
  81. enum { PQC_SUPPORTED_SIGS(DEFNUM_SIG) PQC_ALG_SIG_MAX };
  82. enum { PQC_SUPPORTED_KEMS(DEFNUM_KEM) PQC_ALG_KEM_MAX };
  83. #undef DEFNUM_SIG
  84. #undef DEFNUM_KEM
  85. // Parameters of the scheme
  86. typedef struct pqc_ctx_t {
  87. const uint8_t alg_id;
  88. const char* alg_name;
  89. const uint32_t prv_key_bsz;
  90. const uint32_t pub_key_bsz;
  91. const bool is_kem;
  92. int (*keygen)(uint8_t *sk, uint8_t *pk);
  93. } pqc_ctx_t;
  94. typedef struct pqc_kem_ctx_t {
  95. pqc_ctx_t p;
  96. const uint32_t ciphertext_bsz;
  97. const uint32_t secret_bsz;
  98. int (*encapsulate)(uint8_t *ct, uint8_t *ss, const uint8_t *pk);
  99. int (*decapsulate)(uint8_t *ss, const uint8_t *ct, const uint8_t *sk);
  100. } pqc_kem_ctx_t;
  101. typedef struct pqc_sig_ctx_t {
  102. pqc_ctx_t p;
  103. const uint32_t sign_bsz;
  104. int (*sign)(uint8_t *sig, uint64_t *siglen, const uint8_t *m, uint64_t mlen, const uint8_t *sk);
  105. int (*verify)(const uint8_t *sig, uint64_t siglen, const uint8_t *m, uint64_t mlen, const uint8_t *pk);
  106. } pqc_sig_ctx_t;
  107. bool pqc_keygen(
  108. const pqc_ctx_t *p,
  109. uint8_t *pk, uint8_t *sk);
  110. bool pqc_kem_encapsulate(
  111. const pqc_ctx_t *p,
  112. uint8_t *ct, uint8_t *ss,
  113. const uint8_t *pk);
  114. bool pqc_kem_decapsulate(
  115. const pqc_ctx_t *p,
  116. uint8_t *ss, const uint8_t *ct,
  117. const uint8_t *sk);
  118. bool pqc_sig_create(
  119. const pqc_ctx_t *p,
  120. uint8_t *sig, uint64_t *siglen,
  121. const uint8_t *m, uint64_t mlen,
  122. const uint8_t *sk);
  123. bool pqc_sig_verify(
  124. const pqc_ctx_t *p,
  125. const uint8_t *sig, uint64_t siglen,
  126. const uint8_t *m, uint64_t mlen,
  127. const uint8_t *pk);
  128. const pqc_ctx_t *pqc_kem_alg_by_id(uint8_t id);
  129. const pqc_ctx_t *pqc_sig_alg_by_id(uint8_t id);
  130. uint32_t pqc_ciphertext_bsz(const pqc_ctx_t *p);
  131. uint32_t pqc_shared_secret_bsz(const pqc_ctx_t *p);
  132. uint32_t pqc_signature_bsz(const pqc_ctx_t *p);
  133. uint32_t pqc_public_key_bsz(const pqc_ctx_t *p);
  134. uint32_t pqc_private_key_bsz(const pqc_ctx_t *p);
  135. #ifdef __cplusplus
  136. }
  137. #endif
  138. #endif