| 1 |
KangarooTwelve |
| 2 |
============== |
| 3 |
|
| 4 |
KangarooTwelve is an *extendable-output function* (XOF) based on the Keccak permutation, |
| 5 |
which is also the basis for SHA-3. |
| 6 |
|
| 7 |
As a XOF, KangarooTwelve is a generalization of a cryptographic hash function. |
| 8 |
It is not limited to creating fixed-length digests (e.g., SHA-256 will always output exactly 32 bytes): |
| 9 |
it produces digests of any length, and it can be used as a Pseudo Random Generator (PRG). |
| 10 |
|
| 11 |
Output bits do **not** depend on the output length. |
| 12 |
|
| 13 |
KangarooTwelve is not standardized. However, an RFC_ is being written. |
| 14 |
It provides 128 bit of security against (second) pre-image attacks when the output is at least 128 bits long. |
| 15 |
It provides the same security level against collision attacks when the output is at least 256 bits long. |
| 16 |
|
| 17 |
In addition to hashing, KangarooTwelve allows for domain separation |
| 18 |
via a customization string (``custom`` parameter to :func:`Crypto.Hash.KangarooTwelve.new`). |
| 19 |
|
| 20 |
.. hint:: |
| 21 |
|
| 22 |
For instance, if you are using KangarooTwelve in two applications, |
| 23 |
by picking different customization strings you can ensure |
| 24 |
that they will never end up using the same digest in practice. |
| 25 |
The important factor is that the strings are different; |
| 26 |
what the strings say does not matter. |
| 27 |
|
| 28 |
In the following example, we extract 26 bytes (208 bits) from the XOF:: |
| 29 |
|
| 30 |
>>> from Crypto.Hash import KangarooTwelve as K12 |
| 31 |
>>> |
| 32 |
>>> kangaroo = K12.new(custom=b'Email Signature') |
| 33 |
>>> kangaroo.update(b'Some data') |
| 34 |
>>> print(kangaroo.read(26).hex()) |
| 35 |
61e571c51da64228a85d495f3546c43a4dd2c1fd5de87e45dc58 |
| 36 |
|
| 37 |
.. _RFC: https://datatracker.ietf.org/doc/draft-irtf-cfrg-kangarootwelve/ |
| 38 |
|
| 39 |
.. automodule:: Crypto.Hash.KangarooTwelve |
| 40 |
:members: |