浏览代码

package/python-hkdf: new package

HMAC-based Extract-and-Expand Key Derivation Function (HKDF).

https://github.com/casebeer/python-hkdf

Signed-off-by: Julien Olivain <ju.o@free.fr>
[Thomas: justify the license.]
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
Julien Olivain 2 年之前
父节点
当前提交
433ce2966f

+ 2 - 0
DEVELOPERS

@@ -1693,6 +1693,7 @@ F:	package/perftest/
 F:	package/ptm2human/
 F:	package/python-distro/
 F:	package/python-gnupg/
+F:	package/python-hkdf/
 F:	package/python-pyalsa/
 F:	package/rdma-core/
 F:	package/riscv-isa-sim/
@@ -1709,6 +1710,7 @@ F:	support/testing/tests/package/test_ola.py
 F:	support/testing/tests/package/test_ola/
 F:	support/testing/tests/package/test_perftest.py
 F:	support/testing/tests/package/test_python_distro.py
+F:	support/testing/tests/package/test_python_hkdf.py
 F:	support/testing/tests/package/test_python_gnupg.py
 F:	support/testing/tests/package/test_python_pyalsa.py
 F:	support/testing/tests/package/test_rdma_core.py

+ 1 - 0
package/Config.in

@@ -1073,6 +1073,7 @@ menu "External python modules"
 	source "package/python-h11/Config.in"
 	source "package/python-h2/Config.in"
 	source "package/python-hiredis/Config.in"
+	source "package/python-hkdf/Config.in"
 	source "package/python-hpack/Config.in"
 	source "package/python-html5lib/Config.in"
 	source "package/python-httplib2/Config.in"

+ 7 - 0
package/python-hkdf/Config.in

@@ -0,0 +1,7 @@
+config BR2_PACKAGE_PYTHON_HKDF
+	bool "python-hkdf"
+	help
+	  HMAC-based Extract-and-Expand Key Derivation Function
+	  (HKDF).
+
+	  https://github.com/casebeer/python-hkdf

+ 3 - 0
package/python-hkdf/python-hkdf.hash

@@ -0,0 +1,3 @@
+# md5, sha256 from https://pypi.org/pypi/hkdf/json
+md5  d10471ad0ec891cdbe165d78282c943e  hkdf-0.0.3.tar.gz
+sha256  622a31c634bc185581530a4b44ffb731ed208acf4614f9c795bdd70e77991dca  hkdf-0.0.3.tar.gz

+ 17 - 0
package/python-hkdf/python-hkdf.mk

@@ -0,0 +1,17 @@
+################################################################################
+#
+# python-hkdf
+#
+################################################################################
+
+PYTHON_HKDF_VERSION = 0.0.3
+PYTHON_HKDF_SOURCE = hkdf-$(PYTHON_HKDF_VERSION).tar.gz
+PYTHON_HKDF_SITE = https://files.pythonhosted.org/packages/c3/be/327e072850db181ce56afd51e26ec7aa5659b18466c709fa5ea2548c935f
+PYTHON_HKDF_SETUP_TYPE = setuptools
+# No license file in the tree, but
+# https://github.com/casebeer/python-hkdf/blob/master/LICENSE shows
+# it's BSD-2-Clause. Issue already reported upstream:
+# https://github.com/casebeer/python-hkdf/issues/6
+PYTHON_HKDF_LICENSE = BSD-2-Clause
+
+$(eval $(python-package))

+ 22 - 0
support/testing/tests/package/sample_python_hkdf.py

@@ -0,0 +1,22 @@
+import hashlib
+from binascii import hexlify, unhexlify
+
+from hkdf import Hkdf, hkdf_expand, hkdf_extract
+
+salt = b"ThisIsTheSalt."
+key_in = b"ThisIsTheSecretKey"
+key_info = b"KeyInfo1"
+key_len = 16
+expected_key = unhexlify(b"b49d6cc9065b72f3a0859377d8bb7299")
+
+prk = hkdf_extract(salt, input_key_material=key_in, hash=hashlib.sha512)
+key1 = hkdf_expand(prk, info=key_info, length=key_len)
+
+print("key1:", hexlify(key1))
+assert key1 == expected_key
+
+kdf = Hkdf(salt, input_key_material=key_in, hash=hashlib.sha512)
+key2 = kdf.expand(info=key_info, length=key_len)
+
+print("key2:", hexlify(key2))
+assert key2 == expected_key

+ 11 - 0
support/testing/tests/package/test_python_hkdf.py

@@ -0,0 +1,11 @@
+from tests.package.test_python import TestPythonPackageBase
+
+
+class TestPythonPy3Hkdf(TestPythonPackageBase):
+    __test__ = True
+    config = TestPythonPackageBase.config + \
+        """
+        BR2_PACKAGE_PYTHON3=y
+        BR2_PACKAGE_PYTHON_HKDF=y
+        """
+    sample_scripts = ["tests/package/sample_python_hkdf.py"]