Skip to content

Commit 52c3efc

Browse files
committed
Added codec: snefru
1 parent a851a7d commit 52c3efc

5 files changed

Lines changed: 317 additions & 0 deletions

File tree

‎README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,7 @@ This category also contains `ascii85`, `adobe`, `[x]btoa`, `zeromq` with the `ba
417417
- [X] `ripemd160`: aka RIPEMD-160 (relies on `hashlib` when available, pure Python otherwise)
418418
- [X] `sha`: aka Secure Hash Algorithms ; includes SHA0, SHA1, 224, 256, 384, 512 (Python2/3) but also SHA3-224, -256, -384 and -512 (Python 3 only ; relies on `hashlib`)
419419
- [X] `shake`: aka SHAKE hashing (Python 3 only ; relies on `hashlib`)
420+
- [X] `snefru`: aka Snefru (Merkle's hash function) in 32 to 480 bits, with 2 to 8 passes
420421
- [X] `whirlpool`: aka Whirlpool (relies on `hashlib` when available, pure Python otherwise)
421422

422423
> :warning: Hash functions are of course definitely **NOT** encoding functions ; they are implemented for convenience with the `.encode(...)` API from `codecs` and useful for chaning codecs.

‎docs/pages/enc/hashing.md‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,25 @@ These one-way transformation functions rely on the native [`hashlib`](https://do
237237

238238
-----
239239

240+
### Snefru
241+
242+
This one-way transformation function, designed by Ralph Merkle in 1990, is implemented in pure Python. Its number of passes was raised from 2 to 8 after it was broken with differential cryptanalysis ; PHP's `snefru` is `snefru-256` (with 8 passes), while CyberChef defaults to `snefru` (128 bits).
243+
244+
**Codec** | **Conversions** | **Aliases** | **Comment**
245+
:---: | :---: | --- | ---
246+
`snefru` | data --> Snefru(data, size, passes) | `snefru128`, `snefru-256`, `snefru_256_4`, ... | parametrized ; *size* is a multiple of 32 from 32 to 480 (default: 128) and *passes* belongs to [2,8] (default: 8)
247+
248+
```python
249+
>>> codext.encode("This is a test string !", "snefru")
250+
'b4c5c863defc053ad15be9bc01609c57'
251+
>>> codext.encode("This is a test string !", "snefru-256")
252+
'ba1e1a138b432e94547c46aaf5fd4851651d1ab75da937cd4cf349a02961edf4'
253+
>>> codext.encode("This is a test string !", "snefru-256-4")
254+
'6c6e9478662fe169dfb487af98e1667644cac8f3c5eadba5fbd437bfdf5c1f1a'
255+
```
256+
257+
-----
258+
240259
### Whirlpool
241260

242261
This one-way transformation function, adopted in ISO/IEC 10118-3, relies on [`hashlib`](https://docs.python.org/3/library/hashlib.html) when it provides it, and on a pure Python implementation otherwise (OpenSSL 3 only provides it in its legacy provider).

‎src/codext/hashing/__init__.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from .ripemd import *
1111
from .sha import *
1212
from .shake import *
13+
from .snefru import *
1314
from .whirlpool import *
1415
from .windows import *
1516

0 commit comments

Comments
 (0)