File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11""" This module contains benchmark tests intended to guide development of a performant codebase. """
2+
3+ import hashlib
4+
25import nacl .bindings
36import pysodium
47import pytest
@@ -77,3 +80,31 @@ def encrypt_and_decrypt():
7780
7881 plain_text = benchmark (encrypt_and_decrypt )
7982 assert plain_text == MESSAGE
83+
84+
85+ def test_hash_functions ():
86+ """Test that hash functions produce the same digest."""
87+ assert (
88+ pysodium .crypto_generichash (MESSAGE , KEY )
89+ == hashlib .blake2b (MESSAGE , key = KEY , digest_size = 32 ).digest ()
90+ )
91+
92+
93+ @pytest .mark .benchmark (group = "hash" )
94+ def test_hash_one (benchmark ):
95+ """Benchmark hash function."""
96+
97+ def hash_one ():
98+ return pysodium .crypto_generichash (MESSAGE , KEY )
99+
100+ benchmark (hash_one )
101+
102+
103+ @pytest .mark .benchmark (group = "hash" )
104+ def test_hash_two (benchmark ):
105+ """Benchmark hash function."""
106+
107+ def hash_two ():
108+ return hashlib .blake2b (MESSAGE , key = KEY , digest_size = 32 ).digest ()
109+
110+ benchmark (hash_two )
You can’t perform that action at this time.
0 commit comments