Skip to content

Commit

Permalink
test and document blake3
Browse files Browse the repository at this point in the history
  • Loading branch information
GiacomoPope committed Jul 31, 2024
1 parent 1acca15 commit e26070c
Show file tree
Hide file tree
Showing 6 changed files with 315 additions and 45 deletions.
26 changes: 18 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ We currently have pyO3 bindings for the four Shake XOF available in the [`sha3`]
- [AsconXof()](https://xoflib.readthedocs.io/en/stable/xoflib.html#xoflib.AsconXof)
- [AsconAXof()](https://xoflib.readthedocs.io/en/stable/xoflib.html#xoflib.AsconAXof)

### BLAKE3

- [Blake3()](https://xoflib.readthedocs.io/en/stable/xoflib.html#xoflib.Blake3)

### Sha3

- [Shake128()](https://xoflib.readthedocs.io/en/stable/xoflib.html#xoflib.Shake128)
Expand Down Expand Up @@ -100,6 +104,11 @@ The purpose of this package is to implement XOF for their intended use case, wit

`AsconXOF` and `AsconAXof` are tested by comparing the output with the KAT vectors generated from [`pyascon`](https://github.com/meichlseder/pyascon). For more information, see the test file: [tests/test_ascon.py](https://github.com/GiacomoPope/xoflib/blob/main/tests/test_ascon.py)

### BLAKE3

`Blake3` is tested by comparing the output with the KAT vectors downloaded from
the [BLAKE3 team implementation](https://github.com/BLAKE3-team) [`test_vectors.json`](https://github.com/BLAKE3-team/BLAKE3/blob/master/test_vectors/test_vectors.json). For more information, see the test file: [tests/test_blake3.py](https://github.com/GiacomoPope/xoflib/blob/main/tests/test_blake3.py).

### Sha3

`Shake128` and `Shake256` are tested by comparing the output with the KAT vectors downloaded from the "SHA-3 XOF Test Vectors for Byte-Oriented Output" section from [Cryptographic Algorithm Validation Program (CAVP)](https://csrc.nist.gov/projects/cryptographic-algorithm-validation-program/secure-hashing). For more information, see the test file: [tests/test_shake.py](https://github.com/GiacomoPope/xoflib/blob/main/tests/test_shake.py).
Expand All @@ -120,14 +129,15 @@ We include rough benchmarks of the time it takes to read and absorb 100MB of
data into each XOF in chunk sizes of 32B, 1KB and 1MB. Results are displayed in
MB/s and are computed as the average throughput for running the test 100 times.

| Algorithm | Absorb (32B) | Read (32B) | Absorb (1KB) | Read (1KB) | Absorb (1MB) | Read (1MB) |
|---------------|----------------|--------------|----------------|--------------|----------------|--------------|
| Ascon | 82 MB/s | 102 MB/s | 147 MB/s | 145 MB/s | 145 MB/s | 152 MB/s |
| AsconA | 96 MB/s | 129 MB/s | 209 MB/s | 160 MB/s | 164 MB/s | 153 MB/s |
| Shake128 | 89 MB/s | 102 MB/s | 271 MB/s | 193 MB/s | 348 MB/s | 316 MB/s |
| Shake256 | 79 MB/s | 103 MB/s | 222 MB/s | 216 MB/s | 234 MB/s | 222 MB/s |
| TurboShake128 | 104 MB/s | 144 MB/s | 425 MB/s | 477 MB/s | 414 MB/s | 505 MB/s |
| TurboShake256 | 126 MB/s | 183 MB/s | 477 MB/s | 513 MB/s | 534 MB/s | 581 MB/s |
| Algorithm | Absorb (32B) | Read (32B) | Absorb (1KB) | Read (1KB) | Absorb (1MB) | Read (1MB) |
|----------------|----------------|--------------|----------------|--------------|----------------|--------------|
| AsconXof | 84 MB/s | 104 MB/s | 147 MB/s | 154 MB/s | 160 MB/s | 157 MB/s |
| AsconAXof | 100 MB/s | 130 MB/s | 210 MB/s | 221 MB/s | 222 MB/s | 223 MB/s |
| Blake3 | 141 MB/s | 195 MB/s | 793 MB/s | 900 MB/s | 2935 MB/s | 1022 MB/s |
| Shake128 | 116 MB/s | 158 MB/s | 320 MB/s | 341 MB/s | 368 MB/s | 358 MB/s |
| Shake256 | 106 MB/s | 144 MB/s | 268 MB/s | 281 MB/s | 287 MB/s | 297 MB/s |
| TurboShaker128 | 138 MB/s | 197 MB/s | 564 MB/s | 615 MB/s | 689 MB/s | 709 MB/s |
| TurboShaker256 | 130 MB/s | 185 MB/s | 470 MB/s | 513 MB/s | 556 MB/s | 572 MB/s |

### Benchmarking against `hashlib`

Expand Down
3 changes: 2 additions & 1 deletion benchmarks/benchmark_xof.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
from timeit import timeit
from xoflib import Shake128, Shake256, AsconXof, AsconAXof, TurboShake128, TurboShake256
from xoflib import Blake3, Shake128, Shake256, AsconXof, AsconAXof, TurboShake128, TurboShake256
from tabulate import tabulate

REPEAT = 1
Expand Down Expand Up @@ -35,6 +35,7 @@ def read_chunks(xof_sponge, read_amount, read_count):
for xof_shaker in [
AsconXof(),
AsconAXof(),
Blake3(),
Shake128(),
Shake256(),
TurboShake128(1),
Expand Down
Loading

0 comments on commit e26070c

Please sign in to comment.