File: hash.rst

package info (click to toggle)
python-nacl 1.3.0-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 14,408 kB
  • sloc: ansic: 41,345; sh: 16,028; python: 5,152; asm: 4,264; makefile: 1,136; xml: 30; pascal: 10
file content (81 lines) | stat: -rw-r--r-- 2,913 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
nacl.hash
=========

.. currentmodule:: nacl.hash

.. function:: sha256(message, encoder)

    Hashes ``message`` with SHA256.

    :param bytes message: The message to hash.
    :param encoder: A class that is able to encode the hashed message.
    :return bytes: The hashed message.

.. function:: sha512(message, encoder)

    Hashes ``message`` with SHA512.

    :param bytes message: The message to hash.
    :param encoder: A class that is able to encode the hashed message.
    :return bytes: The hashed message.

.. function:: blake2b(data, digest_size=BLAKE2B_BYTES, key=b'', \
                      salt=b'', person=b'', encoder=nacl.encoding.HexEncoder)

    One-shot blake2b digest

    :param data: the digest input byte sequence
    :type data: bytes
    :param digest_size: the requested digest size; must be at most
                        :py:data:`.BLAKE2B_BYTES_MAX`;
                        the default digest size is :py:data:`.BLAKE2B_BYTES`
    :type digest_size: int
    :param key: the key to be set for keyed MAC/PRF usage; if set, the key
                must be at most :py:data:`.BLAKE2B_KEYBYTES_MAX` long
    :type key: bytes
    :param salt: an initialization salt at most
                 :py:data:`.BLAKE2B_SALTBYTES` long; it will be zero-padded
                 if needed
    :type salt: bytes
    :param person: a personalization string at most
                     :py:data:`.BLAKE2B_PERSONALBYTES` long; it will be
                     zero-padded if needed
    :type person: bytes
    :param encoder: the encoder to use on returned digest
    :type encoder: class
    :return: encoded bytes data
    :rtype: the return type of the choosen encoder


.. function:: siphash24(message, key=b'', encoder=nacl.encoding.HexEncoder)

    Computes a keyed MAC of ``message`` using siphash-2-4

    :param message: The message to hash.
    :type message: bytes
    :param key: the message authentication key to be used
                It must be a :py:data:`.SIPHASH_KEYBYTES` long
                bytes sequence
    :type key: bytes(:py:data:`.SIPHASH_KEYBYTES`)
    :param encoder: A class that is able to encode the hashed message.
    :return: The hashed message.
    :rtype: bytes(:py:data:`.SIPHASH_BYTES`) long bytes sequence


.. function:: siphashx24(message, key=b'', encoder=nacl.encoding.HexEncoder)

    .. versionadded:: 1.2

    Computes a keyed MAC of ``message`` using the extended output length
    variant of siphash-2-4

    :param message: The message to hash.
    :type message: bytes
    :param key: the message authentication key to be used
                It must be a :py:data:`.SIPHASHX_KEYBYTES` long
                bytes sequence
    :type key: bytes(:py:data:`.SIPHASHX_KEYBYTES`)
    :param encoder: A class that is able to encode the hashed message.
    :return: The hashed message.
    :rtype: bytes(:py:data:`.SIPHASHX_BYTES`) long bytes sequence