How to use the libnacl.crypto_generichash function in libnacl

To help you get started, we’ve selected a few libnacl examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github saltstack / libnacl / tests / unit / test_blake.py View on Github external
def test_keyless_blake(self):
        msg1 = b'Are you suggesting coconuts migrate?'
        msg2 = b'Not at all, they could be carried.'
        chash1 = libnacl.crypto_generichash(msg1)
        chash2 = libnacl.crypto_generichash(msg2)
        self.assertNotEqual(msg1, chash1)
        self.assertNotEqual(msg2, chash2)
        self.assertNotEqual(chash2, chash1)
github saltstack / libnacl / tests / unit / test_raw_generichash.py View on Github external
def test_key_generichash(self):
        msg1 = b'Are you suggesting coconuts migrate?'
        msg2 = b'Not at all, they could be carried.'
        key1 = libnacl.utils.rand_nonce()
        key2 = libnacl.utils.rand_nonce()
        khash1_1 = libnacl.crypto_generichash(msg1, key1)
        khash1_1_2 = libnacl.crypto_generichash(msg1, key1)
        khash1_2 = libnacl.crypto_generichash(msg1, key2)
        khash2_1 = libnacl.crypto_generichash(msg2, key1)
        khash2_2 = libnacl.crypto_generichash(msg2, key2)
        self.assertNotEqual(msg1, khash1_1)
        self.assertNotEqual(msg1, khash1_2)
        self.assertNotEqual(msg2, khash2_1)
        self.assertNotEqual(msg2, khash2_2)
        self.assertNotEqual(khash1_1, khash1_2)
        self.assertNotEqual(khash2_1, khash2_2)
        self.assertNotEqual(khash1_1, khash2_1)
        self.assertNotEqual(khash1_2, khash2_2)
        self.assertEqual(khash1_1, khash1_1_2)
github saltstack / libnacl / tests / unit / test_raw_generichash.py View on Github external
def test_key_generichash(self):
        msg1 = b'Are you suggesting coconuts migrate?'
        msg2 = b'Not at all, they could be carried.'
        key1 = libnacl.utils.rand_nonce()
        key2 = libnacl.utils.rand_nonce()
        khash1_1 = libnacl.crypto_generichash(msg1, key1)
        khash1_1_2 = libnacl.crypto_generichash(msg1, key1)
        khash1_2 = libnacl.crypto_generichash(msg1, key2)
        khash2_1 = libnacl.crypto_generichash(msg2, key1)
        khash2_2 = libnacl.crypto_generichash(msg2, key2)
        self.assertNotEqual(msg1, khash1_1)
        self.assertNotEqual(msg1, khash1_2)
        self.assertNotEqual(msg2, khash2_1)
        self.assertNotEqual(msg2, khash2_2)
        self.assertNotEqual(khash1_1, khash1_2)
        self.assertNotEqual(khash2_1, khash2_2)
        self.assertNotEqual(khash1_1, khash2_1)
        self.assertNotEqual(khash1_2, khash2_2)
        self.assertEqual(khash1_1, khash1_1_2)
github saltstack / libnacl / tests / unit / test_raw_generichash.py View on Github external
def test_keyless_generichash(self):
        msg1 = b'Are you suggesting coconuts migrate?'
        msg2 = b'Not at all, they could be carried.'
        chash1 = libnacl.crypto_generichash(msg1)
        chash2 = libnacl.crypto_generichash(msg2)
        self.assertNotEqual(msg1, chash1)
        self.assertNotEqual(msg2, chash2)
        self.assertNotEqual(chash2, chash1)
github JoinMarket-Org / joinmarket / lib / libnacl / blake.py View on Github external
def __init__(self, msg, key=None):
        self.msg = msg
        self.key = key
        self.raw_digest = libnacl.crypto_generichash(msg, key)
        self.digest_size = len(self.raw_digest)
github EternityForest / drayer / drayer / drayer.py View on Github external
def drayer_hash(d):
    if not isinstance(d, bytes):
        raise TypeError
    return libnacl.crypto_generichash(d)
github saltstack / libnacl / libnacl / blake.py View on Github external
def __init__(self, msg, key=None):
        self.msg = msg
        self.key = key
        self.raw_digest = libnacl.crypto_generichash(msg, key)
        self.digest_size = len(self.raw_digest)
github jheling / freeathome / freeathome / fah / crypto.py View on Github external
def makeAuthenticator(self, message, key):

        generic_hash = libnacl.crypto_generichash(message, key)

        if generic_hash is None:
            raise Error('generic hash undefined')

        token = libnacl.crypto_onetimeauth(self.publicKey, generic_hash)

        if len(self.publicKey) + len(key) + len(token) != 64:
            raise Error('Unexpected token size')

        authenticator = bytearray(self.publicKey)
        authenticator.extend(key)
        authenticator.extend(token)

        return authenticator