summaryrefslogtreecommitdiff
path: root/dev-python/spake2
diff options
context:
space:
mode:
Diffstat (limited to 'dev-python/spake2')
-rw-r--r--dev-python/spake2/Manifest2
-rw-r--r--dev-python/spake2/files/spake2-0.8-do_not_use_hkdf_package.patch113
-rw-r--r--dev-python/spake2/metadata.xml10
-rw-r--r--dev-python/spake2/spake2-0.8-r1.ebuild45
-rw-r--r--dev-python/spake2/spake2-0.9.ebuild41
5 files changed, 211 insertions, 0 deletions
diff --git a/dev-python/spake2/Manifest b/dev-python/spake2/Manifest
new file mode 100644
index 000000000000..a0dbf66952ae
--- /dev/null
+++ b/dev-python/spake2/Manifest
@@ -0,0 +1,2 @@
+DIST python-spake2-0.8.gh.tar.gz 62425 BLAKE2B 64215362af26fff0785fdabf4282f7111a4cc917750827075b616f009cb1fa6373fc2325382c26b43c051aa5b94e414ca2a5223d9ab666289eb2d04723b15cb5 SHA512 908c377c831f4a11551973ca917b113d51a66c533d35fd19b2692fdb7e575ed2a5045d9b632bc55c37b68ad092f01dff5da191e9dfbfb5599b72844788438d68
+DIST python-spake2-0.9.gh.tar.gz 61563 BLAKE2B e8179a90bf71d72f19ae4bdeda2092147f409c8b5bf3b8eb98bb624e413bcbd73306de20ffa0d36fca010a00dea0f16aafa660f08ae5e15425c2756fafeaf24d SHA512 557b17b8e28214b9c2cd0362c991ac0f61996812fd747e66397c48fdbbb314eb4e9acba9670ca41d0924f4b688931f2b32a7e9ba947ee1db3df00e9e9670d497
diff --git a/dev-python/spake2/files/spake2-0.8-do_not_use_hkdf_package.patch b/dev-python/spake2/files/spake2-0.8-do_not_use_hkdf_package.patch
new file mode 100644
index 000000000000..40e9e17a6843
--- /dev/null
+++ b/dev-python/spake2/files/spake2-0.8-do_not_use_hkdf_package.patch
@@ -0,0 +1,113 @@
+From 930bfabc17748ea3772e6a40b04e84fc4aafcf04 Mon Sep 17 00:00:00 2001
+From: meejah <meejah@meejah.ca>
+Date: Wed, 9 Nov 2022 23:42:33 -0700
+Subject: [PATCH 1/2] use cryptography's HKDF implementation
+
+---
+ setup.py | 2 +-
+ src/spake2/ed25519_basic.py | 2 +-
+ src/spake2/groups.py | 21 ++++++++++++++-------
+ src/spake2/test/test_compat.py | 9 +++++----
+ 4 files changed, 21 insertions(+), 13 deletions(-)
+
+diff --git a/setup.py b/setup.py
+index 660f055..ba3cc28 100755
+--- a/setup.py
++++ b/setup.py
+@@ -79,5 +79,5 @@ def abbrev(t):
+ "Programming Language :: Python :: 3.6",
+ "Topic :: Security :: Cryptography",
+ ],
+- install_requires=["hkdf"],
++ install_requires=["cryptography"],
+ )
+diff --git a/src/spake2/ed25519_basic.py b/src/spake2/ed25519_basic.py
+index 1890be7..dbab56d 100644
+--- a/src/spake2/ed25519_basic.py
++++ b/src/spake2/ed25519_basic.py
+@@ -273,7 +273,7 @@ def arbitrary_element(seed): # unknown DL
+ # oversized string (128 bits more than the field size), then reducing
+ # down to Q. But it's comforting, and it's the same technique we use for
+ # converting passwords/seeds to scalars (which *does* need uniformity).
+- hseed = expand_arbitrary_element_seed(seed, (256/8)+16)
++ hseed = expand_arbitrary_element_seed(seed, int((256/8)+16))
+ y = int(binascii.hexlify(hseed), 16) % Q
+
+ # we try successive Y values until we find a valid point
+diff --git a/src/spake2/groups.py b/src/spake2/groups.py
+index de4f75d..66b08e7 100644
+--- a/src/spake2/groups.py
++++ b/src/spake2/groups.py
+@@ -1,6 +1,7 @@
+ from __future__ import division
+ import hashlib
+-from hkdf import Hkdf
++from cryptography.hazmat.primitives.kdf import hkdf
++from cryptography.hazmat.primitives import hashes
+ from .six import integer_types
+ from .util import (size_bits, size_bytes, unbiased_randrange,
+ bytes_to_number, number_to_bytes)
+@@ -63,9 +64,12 @@
+
+
+ def expand_password(data, num_bytes):
+- h = Hkdf(salt=b"", input_key_material=data, hash=hashlib.sha256)
+- info = b"SPAKE2 pw"
+- return h.expand(info, num_bytes)
++ return hkdf.HKDF(
++ algorithm=hashes.SHA256(),
++ length=num_bytes,
++ salt=b"",
++ info=b"SPAKE2 pw"
++ ).derive(data)
+
+ def password_to_scalar(pw, scalar_size_bytes, q):
+ assert isinstance(pw, bytes)
+@@ -77,9 +81,12 @@ def password_to_scalar(pw, scalar_size_bytes, q):
+ return i % q
+
+ def expand_arbitrary_element_seed(data, num_bytes):
+- h = Hkdf(salt=b"", input_key_material=data, hash=hashlib.sha256)
+- info = b"SPAKE2 arbitrary element"
+- return h.expand(info, num_bytes)
++ return hkdf.HKDF(
++ algorithm=hashes.SHA256(),
++ length=num_bytes,
++ salt=b"",
++ info=b"SPAKE2 arbitrary element"
++ ).derive(data)
+
+ class _Element:
+ def __init__(self, group, e):
+diff --git a/src/spake2/test/test_compat.py b/src/spake2/test/test_compat.py
+index 3c636be..1c1340c 100644
+--- a/src/spake2/test/test_compat.py
++++ b/src/spake2/test/test_compat.py
+@@ -1,7 +1,8 @@
+ import unittest
+ from binascii import hexlify, unhexlify
+ from hashlib import sha256
+-from hkdf import Hkdf
++from cryptography.hazmat.primitives.kdf import hkdf
++from cryptography.hazmat.primitives import hashes
+ from .myhkdf import HKDF as myHKDF
+ from spake2 import groups, ed25519_group
+ from spake2.spake2 import (SPAKE2_A, SPAKE2_B, SPAKE2_Symmetric,
+@@ -213,14 +214,14 @@ def test_vectors(self):
+ {"salt": "00", "IKM": "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", "info": "", "L": 4, "OKM": "37ad2910"},
+ ]
+
+-class HKDF(unittest.TestCase):
++class TestHKDF(unittest.TestCase):
+ def test_vectors(self):
+ for vector in HKDF_TEST_VECTORS:
+ salt = unhexlify(vector["salt"].encode("ascii"))
+ IKM = unhexlify(vector["IKM"].encode("ascii"))
+ info = unhexlify(vector["info"].encode("ascii"))
+- h = Hkdf(salt=salt, input_key_material=IKM, hash=sha256)
+- digest = h.expand(info, vector["L"])
++ h = hkdf.HKDF(algorithm=hashes.SHA256(), length=vector["L"], salt=salt, info=info)
++ digest = h.derive(IKM)
+ self.assertEqual(digest, myHKDF(IKM, vector["L"], salt, info))
+ #print(hexlify(digest))
+ expected = vector["OKM"].encode("ascii")
diff --git a/dev-python/spake2/metadata.xml b/dev-python/spake2/metadata.xml
new file mode 100644
index 000000000000..5e95859f915a
--- /dev/null
+++ b/dev-python/spake2/metadata.xml
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE pkgmetadata SYSTEM "https://docs.baldeagleos.com/dtd/metadata.dtd">
+<pkgmetadata>
+ <maintainer type="project">
+ <email>python@gentoo.org</email>
+ <name>Python</name>
+ </maintainer>
+ <stabilize-allarches />
+ <origin>baldeagleos-repo</origin>
+</pkgmetadata>
diff --git a/dev-python/spake2/spake2-0.8-r1.ebuild b/dev-python/spake2/spake2-0.8-r1.ebuild
new file mode 100644
index 000000000000..2ceadf9562df
--- /dev/null
+++ b/dev-python/spake2/spake2-0.8-r1.ebuild
@@ -0,0 +1,45 @@
+# Copyright 1999-2024 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=8
+
+DISTUTILS_USE_PEP517=setuptools
+PYTHON_COMPAT=( python3_{13..14} )
+
+inherit distutils-r1
+
+MY_P=python-spake2-${PV}
+DESCRIPTION="python implementation of SPAKE2 password-authenticated key exchange algorithm"
+HOMEPAGE="
+ https://github.com/warner/python-spake2/
+ https://pypi.org/project/spake2/
+"
+SRC_URI="
+ https://github.com/warner/python-spake2/archive/v${PV}.tar.gz
+ -> ${MY_P}.gh.tar.gz
+"
+S=${WORKDIR}/${MY_P}
+
+LICENSE="MIT"
+SLOT="0"
+KEYWORDS="~amd64 ~arm64 ~x86"
+
+RDEPEND="
+ dev-python/cryptography[${PYTHON_USEDEP}]
+ dev-python/more-itertools[${PYTHON_USEDEP}]
+"
+BDEPEND="
+ dev-python/versioneer[${PYTHON_USEDEP}]
+"
+
+PATCHES=(
+ "${FILESDIR}"/${P}-do_not_use_hkdf_package.patch
+)
+
+distutils_enable_tests pytest
+
+src_prepare() {
+ # remove outdated bundled versioneer
+ rm versioneer.py || die
+ distutils-r1_src_prepare
+}
diff --git a/dev-python/spake2/spake2-0.9.ebuild b/dev-python/spake2/spake2-0.9.ebuild
new file mode 100644
index 000000000000..6a424a6a7bba
--- /dev/null
+++ b/dev-python/spake2/spake2-0.9.ebuild
@@ -0,0 +1,41 @@
+# Copyright 1999-2025 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=8
+
+DISTUTILS_USE_PEP517=setuptools
+PYTHON_COMPAT=( python3_{13..14} )
+
+inherit distutils-r1
+
+MY_P=python-spake2-${PV}
+DESCRIPTION="python implementation of SPAKE2 password-authenticated key exchange algorithm"
+HOMEPAGE="
+ https://github.com/warner/python-spake2/
+ https://pypi.org/project/spake2/
+"
+SRC_URI="
+ https://github.com/warner/python-spake2/archive/v${PV}.tar.gz
+ -> ${MY_P}.gh.tar.gz
+"
+S=${WORKDIR}/${MY_P}
+
+LICENSE="MIT"
+SLOT="0"
+KEYWORDS="amd64 ~arm64 ~x86"
+
+RDEPEND="
+ dev-python/cryptography[${PYTHON_USEDEP}]
+ dev-python/more-itertools[${PYTHON_USEDEP}]
+"
+BDEPEND="
+ dev-python/versioneer[${PYTHON_USEDEP}]
+"
+
+distutils_enable_tests pytest
+
+src_prepare() {
+ # remove outdated bundled versioneer
+ rm versioneer.py || die
+ distutils-r1_src_prepare
+}