| 1 |
cSHAKE128 |
| 2 |
========= |
| 3 |
|
| 4 |
cSHAKE128 is an *extendable-output function* (XOF) in the SHA-3 family, as specified in `SP 800-185`_. |
| 5 |
|
| 6 |
As a XOF, cSHAKE128 is a generalization of a cryptographic hash function. |
| 7 |
It is not limited to creating fixed-length digests (e.g., SHA-256 will always output exactly 32 bytes): |
| 8 |
it produces digests of any length, and it can be used as a Pseudo Random Generator (PRG). |
| 9 |
|
| 10 |
Output bits do **not** depend on the output length. |
| 11 |
|
| 12 |
The *128* in its name indicates its maximum security level (in bits), |
| 13 |
as described in Section 3.1 of `SP 800-185`_. |
| 14 |
|
| 15 |
cSHAKE128 is a customizable version of SHAKE128 and allows for additional domain separation |
| 16 |
via a customization string (``custom`` parameter to :func:`Crypto.Hash.cSHAKE128.new`). |
| 17 |
|
| 18 |
.. hint:: |
| 19 |
|
| 20 |
For instance, if you are using cSHAKE128 in two applications, |
| 21 |
by picking different customization strings you can ensure |
| 22 |
that they will never end up using the same digest in practice. |
| 23 |
The important factor is that the strings are different; |
| 24 |
what the strings say does not matter. |
| 25 |
|
| 26 |
If the customization string is empty, cSHAKE128 defaults back to :doc:`shake128`. |
| 27 |
See also Section 3.3 of `SP 800-185`_. |
| 28 |
|
| 29 |
In the following example, we extract 26 bytes (208 bits) from the XOF:: |
| 30 |
|
| 31 |
>>> from Crypto.Hash import cSHAKE128 |
| 32 |
>>> |
| 33 |
>>> shake = cSHAKE128.new(custom=b'Email Signature') |
| 34 |
>>> shake.update(b'Some data') |
| 35 |
>>> print(shake.read(26).hex()) |
| 36 |
|
| 37 |
.. _SP 800-185: https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-185.pdf |
| 38 |
|
| 39 |
.. _SHA-2: http://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.180-4.pdf |
| 40 |
|
| 41 |
.. automodule:: Crypto.Hash.cSHAKE128 |
| 42 |
:members: |