Reference implementations of PQC
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.

5 年之前
5 年之前
5 年之前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. # PQClean
  2. [![Build Status on Travis CI](https://travis-ci.com/PQClean/PQClean.svg?branch=master)](https://travis-ci.com/PQClean/PQClean)
  3. [![Build Status on Appveyor](https://ci.appveyor.com/api/projects/status/186ky7yb9mlqj3io/branch/master?svg=true)](https://ci.appveyor.com/project/PQClean/pqclean/branch/master)
  4. [![Build Status on CircleCI](https://circleci.com/gh/PQClean/PQClean/tree/master.svg?style=svg)](https://circleci.com/gh/PQClean/PQClean/tree/master)
  5. **PQClean**, in short, is an effort to collect **clean** implementations of the post-quantum
  6. schemes that are in the
  7. [NIST post-quantum project](https://csrc.nist.gov/projects/post-quantum-cryptography).
  8. The goal of PQClean is to provide *standalone implementations* that
  9. * can easily be integrated into libraries such as [liboqs](https://openquantumsafe.org/#liboqs) or [libpqcrypto](https://libpqcrypto.org/);
  10. * can efficiently upstream into higher-level protocol integration efforts such as [Open Quantum Safe](https://openquantumsafe.org/#integrations);
  11. * can easily be integrated into benchmarking frameworks such as [SUPERCOP](https://bench.cr.yp.to/supercop.html);
  12. * can easily be integrated into frameworks targeting embedded platforms such as [pqm4](https://github.com/mupq/pqm4);
  13. * are suitable starting points for architecture-specific optimized implementations;
  14. * are suitable starting points for evaluation of implementation security; and
  15. * are suitable targets for formal verification.
  16. What PQClean is **not** aiming for is
  17. * a build system producing an integrated library of all schemes;
  18. * including benchmarking of implementations; and
  19. * including integration into higher-level applications or protocols.
  20. As a first main target, we are collecting C implementations that fulfill the requirements
  21. listed below.
  22. Please also review our [guidelines for contributors](CONTRIBUTING.md) if you are interested in adding a scheme to PQClean.
  23. ## Requirements on C implementations that are automatically checked
  24. _The checking of items on this list is still being developed. Checked items should be working._
  25. * [x] Code is valid C99
  26. * [x] Passes functional tests
  27. * [x] API functions do not write outside provided buffers
  28. * [x] `api.h` cannot include external files
  29. * [x] Compiles with `-Wall -Wextra -Wpedantic -Werror -Wmissing-prototypes` with `gcc` and `clang`
  30. * [x] `#if`/`#ifdef`s only for header encapsulation
  31. * [x] Consistent test vectors across runs
  32. * [x] Consistent test vectors on big-endian and little-endian machines
  33. * [x] Consistent test vectors on 32-bit and 64-bit machines
  34. * [x] No errors/warnings reported by valgrind
  35. * [x] No errors/warnings reported by address sanitizer
  36. * [x] Only dependencies: `fips202.c`, `sha2.c`, `aes.c`, `randombytes.c`
  37. * [x] API functions return `0` on success
  38. * [x] No dynamic memory allocations (including variable-length arrays)
  39. * [ ] No branching on secret data (dynamically checked using valgrind)
  40. * [ ] No access to secret memory locations (dynamically checked using valgrind)
  41. * [x] Separate subdirectories (without symlinks) for each parameter set of each scheme
  42. * [x] Builds under Linux, MacOS, and Windows
  43. * [x] Linux
  44. * [x] MacOS
  45. * [x] Windows
  46. * [x] Makefile-based build for each separate scheme
  47. * [x] Makefile-based build for Windows (`nmake`)
  48. * [x] All exported symbols are namespaced with `PQCLEAN_SCHEMENAME_`
  49. * [x] Each implementation comes with a `LICENSE` file (see below)
  50. * [x] Each scheme comes with a `META.yml` file giving details about version of the algorithm, designers
  51. * [x] Each individual implementation is specified in `META.yml`.
  52. ## Requirements on C implementations that are manually checked
  53. * Minimalist Makefiles
  54. * No stringification macros
  55. * Output-parameter pointers in functions are on the left
  56. * `const` arguments are labeled as `const`
  57. * All exported symbols are namespaced in place
  58. * Integer types are of fixed size where relevant, using `stdint.h` types
  59. * Integers used for indexing memory are of size `size_t`
  60. * Variable declarations at the beginning (except in `for (size_t i=...`)
  61. ## Clean C implementations currently in PQClean
  62. Currently, the continuous-integration and testing environment of PQClean is still work in progress
  63. and as a consequence PQClean does not yet have many implementations.
  64. <!--
  65. Currently, PQClean includes clean C implementations of the following KEMs:
  66. * [Kyber-512](https://pq-crystals.org/kyber/)
  67. * [Kyber-768](https://pq-crystals.org/kyber/)
  68. * [Kyber-1024](https://pq-crystals.org/kyber/)
  69. Currently, PQClean includes clean C implementations of the following signature schemes:
  70. * [Dilithium-III](https://pq-crystals.org/dilithium/)
  71. -->
  72. ## API used by PQClean
  73. PQClean is essentially using the same API as required for the NIST reference implementations,
  74. which is also used by SUPERCOP and by libpqcrypto. The only two differences to that API are
  75. the following:
  76. * All lengths are passed as type `size_t` instead of `unsigned long long`; and
  77. * Signatures offer two additional functions that follow the "traditional" approach used
  78. in most software stacks of computing and verifying signatures instead of producing and
  79. recovering signed messages. Specifically, those functions have the following name and signature:
  80. ```
  81. int crypto_sign_signature(uint8_t *sig, size_t *siglen, const uint8_t *m, size_t mlen, const uint8_t *sk);
  82. int crypto_sign_verify(const uint8_t *sig, size_t siglen, const uint8_t *m, size_t mlen, const uint8_t *pk);
  83. ```
  84. ## Building PQClean
  85. As noted above, PQClean is **not** meant to be built as a single library: it is a collection of source code that can be easily integrated into other libraries. The PQClean repository includes various test programs which do build various files, but you should not use the resulting binaries for any purpose.
  86. List of required dependencies: ``gcc or clang, make, python3, python-yaml library, valgrind, astyle (>= 3.0)``.
  87. ## Using source code from PQClean in your own project
  88. Each implementation directory in PQClean (e.g., crypto\_kem/kyber768\clean) can be extracted for use in your own project. You will need to:
  89. 1. Copy the source code from the implementation's directory into your project.
  90. 2. Add the files to your project's build system.
  91. 3. Provide instantiations of any of the common cryptographic algorithms used by the implementation. This likely includes `common/randombytes.h` (a cryptographic random number generator), and possibly `common/sha2.h` (the SHA-2 hash function family) and `common/fips202.h` (the SHA-3 hash function family).
  92. Regarding #2, adding the files to your project's build system, each implementation in PQClean is accompanied by example two makefiles that show how one could build the files for that implementation:
  93. - The file `Makefile` which can be used with GNU Make, BSD Make, and possibly others.
  94. - The file `Makefile.Microsoft_nmake` which can be used with Visual Studio's nmake.
  95. ## Projects integrating PQClean-distributed source code
  96. The following projects consume implementations from PQClean and provide their own wrappers around the implementations.
  97. Their integration strategies may serve as examples for your own projects.
  98. - **[pqcrypto crate](https://github.com/rustpq/pqcrypto)**: Rust integration that automatically generates wrappers from PQClean source code.
  99. - **[mupq](https://github.com/mupq/)**: Runs the implementations from PQClean as reference implementations to compare with microcontroller-optimized code.
  100. - **[Open Quantum Safe](https://github.com/open-quantum-safe/)**: The Open Quantum Safe project integrates implementations from PQClean into their [liboqs](https://github.com/open-quantum-safe/liboqs/) C library, which then exposes them via [C++](https://github.com/open-quantum-safe/liboqs-cpp), [C# / .NET](https://github.com/open-quantum-safe/liboqs-dotnet), and [Python](https://github.com/open-quantum-safe/liboqs-python) wrappers, as well as to forks of [OpenSSL](https://github.com/open-quantum-safe/openssl) and [OpenSSH](https://github.com/open-quantum-safe/openssh-portable).
  101. ## License
  102. Each subdirectory containing implementations contains a `LICENSE` file stating under what license that specific implementation is released.
  103. The files in `common` contain licensing information at the top of the file (and are currently either public domain or MIT).
  104. All other code in this repository is released under the conditions of [CC0](http://creativecommons.org/publicdomain/zero/1.0/).
  105. ## Running tests locally
  106. See https://github.com/PQClean/PQClean/wiki/Test-framework for details about the PQClean test framework.
  107. While we run extensive automatic testing on [Circle CI][circleci-pqc] (Linux builds), [Travis CI][travis-pqc] (OS X builds) and [Appveyor][appveyor-pqc] (Windows builds), most tests can also be run locally.
  108. To do this, make sure the following is installed:
  109. * Python 3.5+
  110. * `pytest` for python 3.
  111. We also recommend installing ``pytest-xdist`` to allow running tests in parallel.
  112. You will also need to make sure the submodules are initialized by running:
  113. ```
  114. git submodule update --init
  115. ```
  116. Run the Python-based tests by going into the `test` directory and running `pytest -v` or (recommended) `pytest -n=auto` for parallel testing.
  117. You may also run `python3 <testmodule>` where `<testmodule>` is any of the files starting with `test_` in the `test/` folder.
  118. [circleci-pqc]: https://circleci.com/gh/PQClean/PQClean/
  119. [travis-pqc]: https://travis-ci.com/PQClean/PQClean/
  120. [appveyor-pqc]: https://ci.appveyor.com/project/PQClean/pqclean