Debian Codegraph @

src/nitrokey/trussed/_bootloader/lpc55_upload/crypto/hmac.py

raw
1 #!/usr/bin/env python
2 # -*- coding: UTF-8 -*-
3 #
4 # Copyright 2019-2023 NXP
5 #
6 # SPDX-License-Identifier: BSD-3-Clause
7
8 """OpenSSL implementation for HMAC packet authentication."""
9
10 # Used security modules
11 from cryptography.hazmat.primitives import hashes
12 from cryptography.hazmat.primitives import hmac as hmac_cls
13
14
15 def hmac_sha256(key: bytes, data: bytes) -> bytes:
16 """Return a HMAC from data with specified key and algorithm.
17
18 :param key: The key in bytes format
19 :param data: Input data in bytes format
20 :return: HMAC bytes
21 """
22 hmac_obj = hmac_cls.HMAC(key, hashes.SHA256())
23 hmac_obj.update(data)
24 return hmac_obj.finalize()