-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fa45b38
commit af123cd
Showing
1 changed file
with
21 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,33 @@ | ||
# xof-py | ||
|
||
## Example | ||
|
||
## Documentation | ||
|
||
https://xof-py.readthedocs.io/en/latest/generated/xof.html | ||
|
||
|
||
## Building with Maturin | ||
|
||
- https://pyo3.rs/v0.22.2/ | ||
- https://github.com/PyO3/maturin | ||
|
||
First set up a virtual environment: | ||
|
||
``` | ||
python3 -m venv .env | ||
source .env/bin/activate | ||
``` | ||
|
||
Then install maturin | ||
|
||
``` | ||
pip install maturin | ||
```py | ||
>>> from xof import Shaker128 | ||
>>> Shake128 = Shaker128(b"a new XOF library").finalize() | ||
>>> Shake128.read(16).hex() | ||
'd071c7cdd2e2108ef8515922daf7e790913c1b75a9f8afd79b38f59d03ac52fe' | ||
>>> Shake128.read(16).hex() | ||
'15a8957dd9ea7d3beb8ddafbf085b9658c35fe353260dd05d9e9f1e7d0004f59' | ||
``` | ||
|
||
Then to build the package run | ||
## Tests | ||
|
||
``` | ||
maturin develop --release | ||
``` | ||
Could be expanded, currently just check random tests against hashlib | ||
|
||
You should now be able to use the package: | ||
## Documentation | ||
|
||
```py | ||
>>> from xof import pyo3_shake_128 | ||
>>> pyo3_shake_128(b"cryptohack", 100).hex() | ||
'8d043455562ebedd1b3fcf5b0e0a058091752d161e7eef40364a565aacb3b5d3bbefa804de6087e77c4c211ef57ab83869e3e18627f8421540ae9a8b61da847d0da513c56c5feba397ab2b4a1a2ef67c6f17162c8dfdb41901ad70bca8195fd35bcea259' | ||
``` | ||
https://xof-py.readthedocs.io/ | ||
|
||
### Speed Test | ||
## Benchmark | ||
|
||
``` | ||
(.env) Jack: xof-py % python3 speed_test.py | ||
10_000 calls with rust sha3: 0.08595705032348633 | ||
10_000 calls with hashlib: 0.06728601455688477 | ||
10_000 one block calls with rust sha3: 0.01061105728149414 | ||
10_000 one block calls with hashlib: 0.012787818908691406 | ||
10_000 2 block calls with rust sha3: 0.016810894012451172 | ||
10_000 2 block calls with hashlib: 0.01606297492980957 | ||
10_000 n block calls with rust sha3: 0.08771300315856934 | ||
10_000 n block calls with hashlib: 0.07766127586364746 | ||
10_000 calls with xof library: 0.014042854309082031 | ||
10_000 calls with hashlib: 0.022047996520996094 | ||
10_000 calls with pycryptodome: 0.029639005661010742 | ||
-------------------------------------------------------------------------------- | ||
1_000_000 single byte reads xof library: 0.18165993690490723 | ||
1_000_000 single byte reads pycryptodome: 1.1623139381408691 | ||
100_000 block reads xof library: 0.5895988941192627 | ||
100_000 block reads pycryptodome: 1.635364055633545 | ||
``` |