Debian Codegraph @

docs/api/hash.rst

raw
1 nacl.hash
2 =========
3
4 .. currentmodule:: nacl.hash
5
6 .. function:: sha256(message, encoder)
7
8 Hashes ``message`` with SHA256.
9
10 :param bytes message: The message to hash.
11 :param encoder: A class that is able to encode the hashed message.
12 :return bytes: The hashed message.
13
14 .. function:: sha512(message, encoder)
15
16 Hashes ``message`` with SHA512.
17
18 :param bytes message: The message to hash.
19 :param encoder: A class that is able to encode the hashed message.
20 :return bytes: The hashed message.
21
22 .. function:: blake2b(data, digest_size=BLAKE2B_BYTES, key=b'', \
23 salt=b'', person=b'', encoder=nacl.encoding.HexEncoder)
24
25 One-shot blake2b digest
26
27 :param data: the digest input byte sequence
28 :type data: bytes
29 :param digest_size: the requested digest size; must be at most
30 :py:data:`.BLAKE2B_BYTES_MAX`;
31 the default digest size is :py:data:`.BLAKE2B_BYTES`
32 :type digest_size: int
33 :param key: the key to be set for keyed MAC/PRF usage; if set, the key
34 must be at most :py:data:`.BLAKE2B_KEYBYTES_MAX` long
35 :type key: bytes
36 :param salt: an initialization salt at most
37 :py:data:`.BLAKE2B_SALTBYTES` long; it will be zero-padded
38 if needed
39 :type salt: bytes
40 :param person: a personalization string at most
41 :py:data:`.BLAKE2B_PERSONALBYTES` long; it will be
42 zero-padded if needed
43 :type person: bytes
44 :param encoder: the encoder to use on returned digest
45 :type encoder: class
46 :return: encoded bytes data
47 :rtype: the return type of the chosen encoder
48
49
50 .. function:: siphash24(message, key=b'', encoder=nacl.encoding.HexEncoder)
51
52 Computes a keyed MAC of ``message`` using siphash-2-4
53
54 :param message: The message to hash.
55 :type message: bytes
56 :param key: the message authentication key to be used
57 It must be a :py:data:`.SIPHASH_KEYBYTES` long
58 bytes sequence
59 :type key: bytes(:py:data:`.SIPHASH_KEYBYTES`)
60 :param encoder: A class that is able to encode the hashed message.
61 :return: The hashed message.
62 :rtype: bytes(:py:data:`.SIPHASH_BYTES`) long bytes sequence
63
64
65 .. function:: siphashx24(message, key=b'', encoder=nacl.encoding.HexEncoder)
66
67 .. versionadded:: 1.2
68
69 Computes a keyed MAC of ``message`` using the extended output length
70 variant of siphash-2-4
71
72 :param message: The message to hash.
73 :type message: bytes
74 :param key: the message authentication key to be used
75 It must be a :py:data:`.SIPHASHX_KEYBYTES` long
76 bytes sequence
77 :type key: bytes(:py:data:`.SIPHASHX_KEYBYTES`)
78 :param encoder: A class that is able to encode the hashed message.
79 :return: The hashed message.
80 :rtype: bytes(:py:data:`.SIPHASHX_BYTES`) long bytes sequence
81 :raises nacl.exceptions.UnavailableError: If called when using a
82 minimal build of libsodium.