Skip to content

Commit

Permalink
Refactor pqcrypto-templates build.rs.j2 and ffi.rs.j2
Browse files Browse the repository at this point in the history
  • Loading branch information
RW-sec committed Nov 24, 2021
1 parent 6369b8d commit 98371cb
Show file tree
Hide file tree
Showing 12 changed files with 515 additions and 636 deletions.
33 changes: 27 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# Changelog

## 2021-11-24

* Add a general implementation list for each scheme in implementations.yaml which is used by build.rs.j2
* Each scheme now has a list of supported implementation variants
* Refactor build.rs.js2 to use macro calls
* Update the other template files to adapt to this change
* Slight modifications to README.md

## 2021-10-26

* Make `pqcrypto-internals` cross-compilable

## 2021-10-18

* Fix small issue in randombytes implementation: should return 0
Expand All @@ -9,9 +21,9 @@
* `no_std` support thanks to @rozbb (PR#25)
* Extract randombytes from PQClean-provided APIs (avoids symbol conflict) (PR #24)
* Update PQClean:
* NTRUPrime new parametersets
* Small Falcon fixes
* Small NTRU fix
* NTRUPrime new parametersets
* Small Falcon fixes
* Small NTRU fix

## 2021-07-28

Expand All @@ -20,6 +32,10 @@
* NTRU Prime updates
* Move common files into `pqcrypto-internals` and out of individual libs

## 2021-06-28

* Refactor the wrapper methods in scheme.rs.js2 file to macro calls

## 2021-06-10

* Add optional `serde` support
Expand Down Expand Up @@ -120,10 +136,10 @@
* Update FALCON from PQClean
* Update SPHINCS+ from PQClean
* Package LEDAcryptKEM
* **Warning:** The LEDAcryptKEM implementations currently packaged are known to have timing side-channel vulnerabilities.
* **Warning:** The LEDAcryptKEM implementations currently packaged are known to have timing side-channel vulnerabilities.
* Package Rainbow
* The ``clean`` implementations are currently known to have undefined behaviour.
See https://github.com/PQClean/PQClean/issues/220
* The ``clean`` implementations are currently known to have undefined behaviour.
See [pqclean/issues/220](https://github.com/PQClean/PQClean/issues/220)
* Hide a internal enum variable from ``pqcrypto_traits::sign::VerificationError``

## 2019-07-24
Expand All @@ -138,23 +154,28 @@
* Update `rand` crate to `0.7.0`

## 2019-07-18

* Update PQClean implementations
* SPHINCS+ is now thread-safe.
* Frodo now uses ``opt`` implementation by default.
* Allow for multiple implementations in the ``ffi`` interface.

## 2019-07-09

* Make ``encapsulate`` and ``decapsulate`` take references.
* Add Dilithium
* Add SABER

## 2019-07-08

* Remove ``pqcrypto-internals``

## 2019-05-22

* Added ``pqcrypto_traits::{Error,Result}`` to ``from_bytes`` signature.
* Added ``pqcrypto::prelude`` to allow importing all traits in one easy go.
* Removed all uses of ``mem::uninitialized()``

## 2019-05-21

* Added MQDSS
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

[![dependency status](https://deps.rs/repo/github/rustpq/pqcrypto/status.svg)](https://deps.rs/repo/github/rustpq/pqcrypto)


This repository contains bindings to C implementations of cryptographic algorithms part of the [NIST competition][nist].
These bindings are generated based on the [PQClean][pqclean] project, which aims to collect 'clean' implementations of cryptographic algorithms.

## How this project works.
## How to generate the bindings

The `pqcrypto-templates` folder contains the master copies of the Rust files.
The binding libraries are generated from the PQClean meta files and PQClean specified API.
The file `implementations.yaml` controls the version numbers and included variants of each scheme.
The generation of the different pq-crates is done by the `generate-implementation.py` script.

## Documentation

Expand Down
16 changes: 6 additions & 10 deletions generate-implementations.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@


DEFAULT_AVX2_GUARD = 'avx2_enabled && target_arch == "x86_64"'
DEFAULT_AES_GUARD = 'aes_enabled && target_arch == "x86_64"'


def read_yaml():
Expand Down Expand Up @@ -64,13 +65,6 @@ def generate_scheme(name, type, properties):
except FileExistsError:
pass

has_avx2 = False
for scheme in properties['schemes']:
if 'avx2_implementation' in scheme:
has_avx2 = True
if 'avx2_feature' not in scheme:
scheme['avx2_feature'] = 'avx2'

render_template(
target_dir, 'Cargo.toml', 'scheme/Cargo.toml.j2',
traits_version=implementations['traits_version'],
Expand All @@ -79,15 +73,17 @@ def generate_scheme(name, type, properties):
type=type,
insecure=properties.get('insecure', False),
version=properties['version'],
has_avx2=has_avx2,
implementations=properties['implementations'],
)

render_template(
target_dir, 'build.rs', 'scheme/build.rs.j2',
name=name,
type=type,
implementations=properties['implementations'],
schemes=properties['schemes'],
avx2_guard=properties.get('avx2_guard', DEFAULT_AVX2_GUARD)
avx2_guard=properties.get('avx2_guard', DEFAULT_AVX2_GUARD),
aes_guard=properties.get('aes_guard', DEFAULT_AES_GUARD),
)

metadatas = dict()
Expand All @@ -100,7 +96,7 @@ def generate_scheme(name, type, properties):
type=type,
name=name,
metadatas=metadatas,
schemes=properties['schemes']
schemes=properties['schemes'],
)

for scheme in properties['schemes']:
Expand Down
Loading

0 comments on commit 98371cb

Please sign in to comment.