Skip to content

Commit

Permalink
Remove 90s modes and AVX2 optimisations
Browse files Browse the repository at this point in the history
  • Loading branch information
bwesterb committed May 19, 2023
1 parent 9087213 commit a227159
Show file tree
Hide file tree
Showing 46 changed files with 13 additions and 6,108 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/cross.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,13 @@ jobs:
mips64-unknown-linux-gnuabi64,
]
feature: [kyber512, kyber768, kyber1024]
opt: ["", 90s, "90s-fixslice"]

steps:
- uses: actions/checkout@v3

- name: Cross Compile Tests ${{ matrix.target }} ${{ matrix.feature }} ${{ matrix.opt }}
- name: Cross Compile Tests ${{ matrix.target }} ${{ matrix.feature }}
uses: actions-rs/[email protected]
with:
use-cross: true
command: test
args: --target ${{ matrix.target }} --features "${{ matrix.feature }} ${{ matrix.opt }}"
args: --target ${{ matrix.target }} --features "${{ matrix.feature }}"
2 changes: 1 addition & 1 deletion .github/workflows/kat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ jobs:
working-directory: ./tests
run: |
chmod +x run_all_tests.sh
KAT=1 AVX2=1 NASM=1 ./run_all_tests.sh
KAT=1 ./run_all_tests.sh
27 changes: 0 additions & 27 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,8 @@ readme = "readme.md"
[dependencies]
rand_core = { version = "0.6.4", default-features = false }
wasm-bindgen = { version = "0.2.84", optional = true }
sha2 = { version = "0.10.6", optional = true , default-features = false }
getrandom = {version = "0.2.9", features = ["js"], optional = true }
zeroize = { version = "1.6.0", features = ["derive"], optional = true }
aes = { version = "0.8.2", optional = true }
ctr = { version = "0.9.2", optional = true }
# Optional dev-deps, see https://github.com/rust-lang/cargo/issues/1596
criterion = { version = "0.4.0", features = ["html_reports"], optional = true }

Expand All @@ -32,8 +29,6 @@ optional = true
rand = "0.8.5"

[build-dependencies]
cc = {version = "1.0.73", optional = true }
nasm-rs = {version = "0.2.4", optional = true }

[lib]
crate-type = ["cdylib", "rlib"]
Expand All @@ -50,31 +45,9 @@ kyber512 = []
kyber768 = []
kyber1024 = []

### Export IND-CPA primitives
# **WARNING** use with caution
hazmat = []

### Additional features ###
# 90s mode uses AES256-CTR and SHA2 as primitives instead
# Uses a bitslice implementation
90s = ["sha2"]

# Fixslice RustCrypto AES implementation offers some additional sidechannel
# attack resistance. Suggest benchmarking for comparison.
90s-fixslice = ["90s", "aes", "ctr"]

# Use avx2 intrinsics on x86 architectures
# Wont compile if the platform doesn't support it
avx2 = ["cc"]

# For compiling to wasm targets
wasm = ["wasm-bindgen", "getrandom", "rand"]

# Uses Netwide Assembler avx2 code instead of GAS, this offers increased
# portability, you will need a nasm compiler installed.
# Can be downloaded from https://www.nasm.us/
nasm = ["nasm-rs", "avx2"]

# Enable std library support
std = []

Expand Down
2 changes: 1 addition & 1 deletion benches/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Don't be surprised to significant speedups and regressions.
You will need to enable the benchmarking feature to run:

```bash
cargo bench --features "benchmarking kyber1024 avx2"
cargo bench --features "benchmarking kyber1024"
```
This is a workaround for issues with address sanitizer checks in the test suite.

Expand Down
41 changes: 0 additions & 41 deletions build.rs

This file was deleted.

4 changes: 2 additions & 2 deletions fuzz/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ cargo hfuzz run <TARGET>
Run different security levels and modes:

```bash
cargo hfuzz run <TARGET> --features "kyber512 90s"
cargo hfuzz run <TARGET> --features "kyber512"
```

Current targets are:

* keypair
* encap
* decap
* decap
16 changes: 1 addition & 15 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ A rust implementation of the Kyber algorithm, a KEM standardised by the NIST Pos
This library:
* Is no_std compatible and needs no allocator, suitable for embedded devices.
* Reference files contain no unsafe code and are written in pure rust.
* On x86_64 platforms offers an avx2 optimized version, which includes assembly from the C reference repo.
* Compiles to WASM using wasm-bindgen and has a ready-to-use binary published on NPM.


Expand All @@ -43,12 +42,6 @@ cargo add safe_pqc_kyber
use safe_pqc_kyber::*;
```

For optimisations on x86 platforms enable the `avx2` feature and the following RUSTFLAGS:

```shell
export RUSTFLAGS="-C target-feature=+aes,+avx2,+sse2,+sse4.1,+bmi2,+popcnt"
```

---

### Key Encapsulation
Expand Down Expand Up @@ -134,7 +127,7 @@ If no security level is specified then kyber768 is used by default as recommende

```toml
[dependencies]
safe_pqc_kyber = {version = "0.6.0", features = ["kyber512", "90s", "avx2"]}
safe_pqc_kyber = {version = "0.6.0", features = ["kyber512"]}
```


Expand All @@ -143,11 +136,7 @@ safe_pqc_kyber = {version = "0.6.0", features = ["kyber512", "90s", "avx2"]}
| std | Enable the standard library |
| kyber512 | Enables kyber512 mode, with a security level roughly equivalent to AES-128.|
| kyber1024 | Enables kyber1024 mode, with a security level roughly equivalent to AES-256. A compile-time error is raised if more than one security level is specified.|
| 90s | Uses AES256 in counter mode and SHA2 as a replacement for SHAKE. This can provide hardware speedups in some cases.|
| 90s-fixslice | Uses a fixslice implementation of AES256 by RustCrypto, this provides greater side-channel attack resistance, especially on embedded platforms |
| avx2 | On x86_64 platforms enable the optimized version. This flag is will cause a compile error on other architectures. |
| wasm | For compiling to WASM targets|
| nasm | Uses Netwide Assembler avx2 code instead of GAS for portability. Requires a nasm compiler: https://www.nasm.us/ |
| zeroize | This will zero out the key exchange structs on drop using the [zeroize](https://docs.rs/zeroize/latest/zeroize/) crate |
| benchmarking | Enables the criterion benchmarking suite |
---
Expand All @@ -164,9 +153,6 @@ There's a helper script to do this [here](./tests/KAT/build_kats.sh).
```bash
# This example runs the basic tests for kyber768
cargo test

# This runs the KATs for kyber512 in 90's mode
RUSTFLAGS='--cfg kyber_kat' cargo test --features "kyber512 90s"
```

See the [testing readme](./tests/readme.md) for more comprehensive info.
Expand Down
177 changes: 0 additions & 177 deletions src/avx2/aes256ctr.rs

This file was deleted.

Loading

0 comments on commit a227159

Please sign in to comment.