Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

CONTRIBUTING.md 7.7 KiB

5 år sedan
5 år sedan
5 år sedan
5 år sedan
5 år sedan
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. Contributing new schemes to PQClean
  2. ===================================
  3. Why contribute to PQClean
  4. -------------------------
  5. PQClean hopes to provide your scheme to people who want to integrate post-quantum cryptography into their own libraries and applications. But our extensive testing framework might also help you catch bugs in your implementation, that might have otherwise gone unnoticed. We run our builds on (emulated) ARMv7, ARMv8, 32-bit PowerPC, x86 and amd64. Also, we apply static and dynamic analysis tools.
  6. Adding your scheme
  7. ------------------
  8. For this text, we will assume that you want to contribute a **key encapsulation mechanism (KEM)** to PQClean. For a signature scheme, these steps are equivalent, but the API is slightly different.
  9. See the section [API](#API) below.
  10. 1. Fork our repository. You will be creating a pull request soon.
  11. * **Tip:** Do not wait until you think you have gotten everything perfect, before you open the pull request. We set up things so Github and the CI environment will give you feedback and guidance on the steps to follow.
  12. 2. Create the following folder structure: `crypto_kem/yourschemename/clean`. We follow the SUPERCOP layout, so please create a separate folder under `crypto_kem` for each parameter set.
  13. For now, we only accept **pure, portable C code**. Our coding conventions impose certain constraints on the C code -- C99 code, fixed sized integer types (e.g., `uint64_t` rather than `unsigned long long`), and more. See README.md for more information.
  14. 3. Create a `META.yml` file in `crypto_(kem|sign)/yourschemename` following this template:
  15. ```yaml
  16. name: Name
  17. type: <kem|signature>
  18. claimed-nist-level: <N>
  19. claimed-security: IND-CPA/IND-CCA2 # KEM only
  20. length-public-key: <N> # KEM and signature
  21. length-secret-key: <N> # KEM and signature
  22. length-ciphertext: <N> # KEM only
  23. length-shared-secret: <N> # KEM only
  24. length-signature: <N> # Signature only
  25. nistkat-sha256: sha256sum of 1st NIST KAT test case # KEM and signature
  26. testvectors-sha256: sha256sum of output of testvectors # Signature only
  27. principal-submitters:
  28. - Alice
  29. - Bob
  30. - ...
  31. auxiliary-submitters: # optional
  32. - Alice
  33. - Bob
  34. - ...
  35. implementations:
  36. - name: clean
  37. version: <some version indicator>
  38. ```
  39. This file needs to be valid [YAML](https://yaml.org/).
  40. 4. Put your scheme's C source code into `crypto_kem/yourschemename/clean`.
  41. 1. Make sure all symbols are prefixed with `PQCLEAN_YOURSCHEME_CLEAN_`.
  42. 2. Include `api.h` into your scheme with the symbols specified in the section [API](#API). Make sure it does not include other files.
  43. 3. We use `astyle` to format code. You may consider running the following command on your submission:
  44. ```
  45. astyle --project crypto_kem/yourschemename/clean/*.[ch]
  46. ```
  47. 4. You may run the tests in the `tests/` folder. See the `README` for how to run the test suite.
  48. 5. Migrate your use of AES, SHA-2, and SHA-3 to the API in the `common` directory.
  49. Note that if you use the AES API, you must use the `aes128_ecb_keyexp` or aes128_ctr_keyexp` routines (or 192 or 256) to expand the key into a key schedule object,
  50. then use `aes128_ctx_release` to release the key schedule object once you're finished with it.
  51. For the SHAKE API, use the appropriate `_ctx_release` functions.
  52. For fixed-output functions SHA-2 and SHA-3, the `_finalize` function will free the state.
  53. If you need to make copies of any of the states of these primitives, use the appropriate functions.
  54. 5. Create `Makefile` and `Makefile.Microsoft_nmake` files to compile your scheme as static library.
  55. * We suggest you copy these from `crypto_kem/kyber768/clean` and modify them to suit your scheme.
  56. 6. Add a `LICENSE` file to your implementation folder.
  57. 7. Commit everything and push it to your fork.
  58. 8. Open a pull request on our Github repository and process the feedback given to you by the CI environment. The pull request will also set up a checklist for you and us to follow. Feel free to ask us questions via the pull request.
  59. ### Generating implementations
  60. It may sometimes be helpful to generate the implementations from a shared code base.
  61. You can find an example of how this can be done for [SPHINCS+][sphincsclean], [Dilithium][Dilithiumclean] or [Kyber][kyberclean]
  62. [sphincsclean]: https://github.com/thomwiggers/sphincsplus/tree/pqcleanup
  63. [dilithiumclean]: https://github.com/thomwiggers/dilithium/tree/pqclean
  64. [kyberclean]: https://github.com/thomwiggers/kyber-clean/
  65. ### Testing your implementations locally using the PQClean test environment
  66. It can be helpful to debug issues if you run the testing environment locally.
  67. This allows you to solve, for example, endianness problems or 32-bit problems much quicker, without waiting for the full CI runs to complete.
  68. You will need Docker on your computer.
  69. To run the ARM and powerpc containers you will need to run the following from a Linux computer:
  70. ```sh
  71. docker pull multiarch/qemu-user-static:register
  72. docker run --rm --privileged multiarch/qemu-user-static:register --reset
  73. ```
  74. Then, to launch a specific testing environment, we suggest the following command:
  75. ```sh
  76. docker run \
  77. --rm --tty --interactive \
  78. --volume $PWD:/pqclean \
  79. --user $(id -u):$(id -g) \
  80. --workdir /pqclean \
  81. pqclean/ci-container:ARCHITECTURE \
  82. /bin/bash
  83. ```
  84. Replace `ARCHITECTURE` by one of the following:
  85. * armhf\*
  86. * arm64\*
  87. * i386
  88. * amd64
  89. * unstable-ppc\*
  90. Items marked with \* require the `multiarch/qemu-user-static` registation step.
  91. API
  92. ---
  93. These items should be available in your `api.h` file.
  94. ### KEMs
  95. Functions:
  96. ```c
  97. int PQCLEAN_YOURSCHEME_IMPLEMENTATION_crypto_kem_keypair(
  98. uint8_t *pk, uint8_t *sk);
  99. int PQCLEAN_YOURSCHEME_IMPLEMENTATION_crypto_kem_enc(
  100. uint8_t *ct, uint8_t *ss, const uint8_t *pk);
  101. int PQCLEAN_YOURSCHEME_IMPLEMENTATION_crypto_kem_dec(
  102. uint8_t *ss, const uint8_t *ct, const uint8_t *sk);
  103. ```
  104. `#define` macros:
  105. * `CRYPTO_SECRETKEYBYTES`
  106. * `CRYPTO_PUBLICKEYBYTES`
  107. * `CRYPTO_CIPHERTEXTBYTES`
  108. * `CRYPTO_BYTES`
  109. * `CRYPTO_ALGNAME`
  110. ### Signature schemes
  111. Functions:
  112. ```c
  113. int PQCLEAN_YOURSCHEME_IMPLEMENTATION_crypto_sign_keypair(
  114. uint8_t *pk, uint8_t *sk);
  115. int PQCLEAN_YOURSCHEME_IMPLEMENTATION_crypto_sign(
  116. uint8_t *sm, size_t *smlen,
  117. const uint8_t *msg, size_t len,
  118. const uint8_t *sk);
  119. int PQCLEAN_YOURSCHEME_IMPLEMENTATION_crypto_sign_open(
  120. uint8_t *m, size_t *mlen,
  121. const uint8_t *sm, size_t smlen,
  122. const uint8_t *pk);
  123. int PQCLEAN_YOURSCHEME_IMPLEMENTATION_crypto_sign_signature(
  124. uint8_t *sig, size_t *siglen,
  125. const uint8_t *m, size_t mlen,
  126. const uint8_t *sk);
  127. int PQCLEAN_YOURSCHEME_IMPLEMENTATION_crypto_sign_verify(
  128. const uint8_t *sig, size_t siglen,
  129. const uint8_t *m, size_t mlen,
  130. const uint8_t *pk);
  131. ```
  132. `#define` macros:
  133. * `PQCLEAN_YOURSCHEME_IMPLEMENTATION_CRYPTO_SECRETKEYBYTES`
  134. * `PQCLEAN_YOURSCHEME_IMPLEMENTATION_CRYPTO_PUBLICKEYBYTES`
  135. * `PQCLEAN_YOURSCHEME_IMPLEMENTATION_CRYPTO_ALGNAME`
  136. * `PQCLEAN_YOURSCHEME_IMPLEMENTATION_CRYPTO_BYTES`
  137. for KEMs, additionally define:
  138. * `PQCLEAN_YOURSCHEME_IMPLEMENTATION_CRYPTO_CIPHERTEXTBYTES`
  139. Please make sure your `api.h` file does not include any other files.
  140. ### Return codes
  141. Your schemes should return 0 on success, or a negative value on failure.
  142. Notably, `crypto_sign_open` should return `-1` if signature verification failed.
  143. Contributing to the framework of PQClean
  144. ========================================
  145. We also welcome contributions to the testing framework. Open an issue or pull request on Github and we will review your suggestion. In general, we are always looking to improve the experience of submitters of schemes and of people consuming the implementations collected by this project.