codekingpro/portable-devtools
114k
1# This file is dual licensed under the terms of the Apache License, Version2# 2.0, and the BSD License. See the LICENSE file in the root of this repository3# for complete details.4 5from __future__ import annotations6 7import abc8 9from cryptography.utils import Buffer10 11 12class KeyDerivationFunction(metaclass=abc.ABCMeta):13 @abc.abstractmethod14 def derive(self, key_material: bytes) -> bytes:15 """16 Deterministically generates and returns a new key based on the existing17 key material.18 """19 20 @abc.abstractmethod21 def derive_into(self, key_material: bytes, buffer: Buffer) -> None:22 """23 Deterministically generates a new key based on the existing key24 material and stores it in the provided buffer.25 """26 27 @abc.abstractmethod28 def verify(self, key_material: bytes, expected_key: bytes) -> None:29 """30 Checks whether the key generated by the key material matches the31 expected derived key. Raises an exception if they do not match.32 """33 