Reference implementations of PQC
Go to file
Thom Wiggers 133a38b890 Move test support files into tests directory (#200)
* Move test support files into tests directory

* Fix common tests dir in test

* Fix Windows Makefile for common tests

* notrandombytes.obj should be in TEST_COMMON_DIR
2019-07-26 10:26:14 +02:00
.circleci Skip AppVeyor and CircleCI tests for SPHINCS 2019-04-29 15:48:44 +02:00
.github Add small note to PR template 2019-04-16 13:39:26 +02:00
common Move test support files into tests directory (#200) 2019-07-26 10:26:14 +02:00
crypto_kem Make a static global explicitly const 2019-07-18 13:42:37 +02:00
crypto_sign Merge pull request #211 from PQClean/fix-205 2019-07-25 12:51:24 +02:00
test Move test support files into tests directory (#200) 2019-07-26 10:26:14 +02:00
.astylerc Disable AStyle line endings formatter 2019-03-06 17:15:24 +01:00
.clang-tidy Allow TODO without username / bug numbers 2019-04-05 17:53:30 +02:00
.gitattributes Fix tidy for signing 2019-01-16 13:02:35 +01:00
.gitignore Reimplement Python tests using nose framework 2019-02-13 22:25:34 -05:00
.gitmodules Prohibit using char without explicit sign modifier 2019-04-04 13:49:15 +02:00
.travis.yml try to more reliably run the Travis PR path 2019-07-08 13:33:52 +02:00
appveyor.yml Skip AppVeyor and CircleCI tests for SPHINCS 2019-04-29 15:48:44 +02:00
CONTRIBUTING.md Document AES key schedule release 2019-06-25 09:47:24 -04:00
README.md Trivial commit to trigger a rerun of all CI. 2019-06-26 09:58:05 -04:00
requirements.txt Prohibit using char without explicit sign modifier 2019-04-04 13:49:15 +02:00
SECURITY.md Create SECURITY.md 2019-07-22 14:30:09 +02:00

PQClean

Build Status on Travis CI Build Status on Appveyor Build Status on CircleCI

PQClean, in short, is an effort to collect clean implementations of the post-quantum schemes that are in the NIST post-quantum project. The goal of PQClean is to provide standalone implementations that

  • can easily be integrated into libraries such as liboqs or libpqcrypto;
  • can efficiently upstream into higher-level protocol integration efforts such as Open Quantum Safe;
  • can easily be integrated into benchmarking frameworks such as SUPERCOP;
  • can easily be integrated into frameworks targeting embedded platforms such as pqm4;
  • are suitable starting points for architecture-specific optimized implementations;
  • are suitable starting points for evaluation of implementation security; and
  • are suitable targets for formal verification.

What PQClean is not aiming for is

  • a build system producing an integrated library of all schemes;
  • including benchmarking of implementations; and
  • including integration into higher-level applications or protocols.

As a first main target, we are collecting C implementations that fulfill the requirements listed below. Please also review our guidelines for contributors if you are interested in adding a scheme to PQClean.

Requirements on C implementations that are automatically checked

The checking of items on this list is still being developed. Checked items should be working.

  • Code is valid C99
  • Passes functional tests
  • API functions do not write outside provided buffers
  • api.h cannot include external files
  • Compiles with -Wall -Wextra -Wpedantic -Werror -Wmissing-prototypes with gcc and clang
  • #if/#ifdefs only for header encapsulation
  • Consistent test vectors across runs
  • Consistent test vectors on big-endian and little-endian machines
  • Consistent test vectors on 32-bit and 64-bit machines
  • No errors/warnings reported by valgrind
  • No errors/warnings reported by address sanitizer
  • Only dependencies: fips202.c, sha2.c, aes.c, randombytes.c
  • API functions return 0 on success
  • No dynamic memory allocations (including variable-length arrays)
  • No branching on secret data (dynamically checked using valgrind)
  • No access to secret memory locations (dynamically checked using valgrind)
  • Separate subdirectories (without symlinks) for each parameter set of each scheme
  • Builds under Linux, MacOS, and Windows
    • Linux
    • MacOS
    • Windows
  • Makefile-based build for each separate scheme
  • Makefile-based build for Windows (nmake)
  • All exported symbols are namespaced with PQCLEAN_SCHEMENAME_
  • Each implementation comes with a LICENSE file (see below)
  • Each scheme comes with a META.yml file giving details about version of the algorithm, designers
    • Each individual implementation is specified in META.yml.

Requirements on C implementations that are manually checked

  • Minimalist Makefiles
  • No stringification macros
  • Output-parameter pointers in functions are on the left
  • const arguments are labeled as const
  • All exported symbols are namespaced in place
  • Integer types are of fixed size where relevant, using stdint.h types
  • Integers used for indexing memory are of size size_t
  • Variable declarations at the beginning (except in for (size_t i=...)

Clean C implementations currently in PQClean

Currently, the continuous-integration and testing environment of PQClean is still work in progress and as a consequence PQClean does not yet have many implementations.

API used by PQClean

PQClean is essentially using the same API as required for the NIST reference implementations, which is also used by SUPERCOP and by libpqcrypto. The only two differences to that API are the following:

  • All lengths are passed as type size_t instead of unsigned long long; and
  • Signatures offer two additional functions that follow the "traditional" approach used in most software stacks of computing and verifying signatures instead of producing and recovering signed messages. Specifically, those functions have the following name and signature:
int crypto_sign_signature(uint8_t *sig, size_t *siglen, const uint8_t *m, size_t mlen, const uint8_t *sk);
int crypto_sign_verify(const uint8_t *sig, size_t siglen, const uint8_t *m, size_t mlen, const uint8_t *pk);

Building PQClean

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.

List of required dependencies: gcc or clang, make, python3, python-yaml library, valgrind, astyle (>= 3.0).

Using source code from PQClean in your own project

Each implementation directory in PQClean (e.g., crypto_kem/kyber768\clean) can be extracted for use in your own project. You will need to:

  1. Copy the source code from the implementation's directory into your project.
  2. Add the files to your project's build system.
  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).

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:

  • The file Makefile which can be used with GNU Make, BSD Make, and possibly others.
  • The file Makefile.Microsoft_nmake which can be used with Visual Studio's nmake.

Projects integrating PQClean-distributed source code

The following projects consume implementations from PQClean and provide their own wrappers around the implementations. Their integration strategies may serve as examples for your own projects.

  • pqcrypto crate: Rust integration that automatically generates wrappers from PQClean source code.
  • mupq: Runs the implementations from PQClean as reference implementations to compare with microcontroller-optimized code.
  • Open Quantum Safe: The Open Quantum Safe project integrates implementations from PQClean into their liboqs C library, which then exposes them via C++, C# / .NET, and Python wrappers, as well as to forks of OpenSSL and OpenSSH.

License

Each subdirectory containing implementations contains a LICENSE file stating under what license that specific implementation is released. The files in common contain licensing information at the top of the file (and are currently either public domain or MIT). All other code in this repository is released under the conditions of CC0.

Running tests locally

See https://github.com/PQClean/PQClean/wiki/Test-framework for details about the PQClean test framework.

While we run extensive automatic testing on Circle CI (Linux builds), Travis CI (OS X builds) and Appveyor (Windows builds), most tests can also be run locally. To do this, make sure the following is installed:

  • Python 3.5+
  • nosetests or nose2 (either for Python 3)

You will also need to make sure the submodules are initialized by running:

git submodule update --init

Run the Python-based tests by going into the test directory and running nosetests -v or nose2 -B -v, depending on what you installed. If you have the rednose plugin for nosetests installed, run nosetests --rednose to get colored output.

You may also run python3 <testmodule> where <testmodule> is any of the files starting with test_ in the test/ folder.