Debian Codegraph @

Doc/src/hash/turboshake.rst

raw
1 TurboSHAKE128 and TurboSHAKE256
2 ===============================
3
4 TurboSHAKE is a family of *eXtendable-Output Functions* (XOFs) based on the Keccak permutation,
5 which is also the basis for SHA-3.
6
7 A XOF is a generalization of a cryptographic hash.
8 The output digest of a XOF can take any length, as required by the caller,
9 unlike SHA-256 (for instance) that always produces exactly 32 bytes.
10 The output bits of a XOF do **not** depend on the output length,
11 which means that the output length
12 does not even need to be known (or declared) when the XOF is created.
13
14 Therefore, a XOF object has a ``read(N: int)`` method (much like a file object)
15 instead of a ``digest()`` method. ``read()`` can be called any number of times,
16 and it will return different bytes each time.
17
18 .. figure:: xof.png
19 :align: center
20 :figwidth: 50%
21
22 Generic state diagram for a XOF object
23
24 The TurboSHAKE family is not standardized. However, an RFC_ is being written.
25 It comprises of two members:
26
27 .. csv-table::
28 :header: Name, (2nd) Pre-image strength, Collision strength
29
30 TurboSHAKE128, "128 bits (output >= 16 bytes)", "256 bits (output >= 32 bytes)"
31 TurboSHAKE256, "256 bits (output >= 32 bytes)", "512 bits (output >= 64 bytes)"
32
33 In addition to hashing, TurboSHAKE allows for domain separation
34 via a *domain separation byte* (that is, the ``domain`` parameter to :func:`Crypto.Hash.TurboSHAKE128.new`
35 and to :func:`Crypto.Hash.TurboSHAKE256.new`).
36
37 .. hint::
38
39 For instance, if you are using TurboSHAKE in two applications,
40 by picking different domain separation bytes you can ensure
41 that they will never end up using the same digest in practice.
42 The important factor is that the strings are different;
43 the actual value of the domain separation byte is irrelevant.
44
45 In the following example, we extract 26 bytes (208 bits) from the TurboSHAKE128 XOF::
46
47 >>> from Crypto.Hash import TurboSHAKE128
48 >>>
49 >>> xof = TurboSHAKE128.new()
50 >>> xof.update(b'Some data')
51 >>> print(xof.read(26).hex())
52 d9dfade4ff8be344749908073916d3abd185ef88f5401024f029
53
54 .. _RFC: https://datatracker.ietf.org/doc/draft-irtf-cfrg-kangarootwelve/
55
56 .. automodule:: Crypto.Hash.TurboSHAKE128
57 :members:
58
59 .. automodule:: Crypto.Hash.TurboSHAKE256
60 :members: