1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
From 0fbb9d099370c0a7031dd13990986538f586836a Mon Sep 17 00:00:00 2001
From: Erik Larsson <who+github@cnackers.org>
Date: Fri, 26 Jan 2024 12:01:41 +0100
Subject: [PATCH 3/3] internal/crypto: fix _MyRSAPrivateNumbers with
cryptograpy >= 42.0.1
RSAPrivateNumbers was moved to a rust implementation in 42.0.1.
So inheritance is no longer possible, so turn the class into a
wrapper instead of a subclass.
Fixes #561
Signed-off-by: Erik Larsson <who+github@cnackers.org>
---
src/tpm2_pytss/internal/crypto.py | 21 +++++++++------------
1 file changed, 9 insertions(+), 12 deletions(-)
diff --git a/src/tpm2_pytss/internal/crypto.py b/src/tpm2_pytss/internal/crypto.py
index 93e5181..42030c5 100644
--- a/src/tpm2_pytss/internal/crypto.py
+++ b/src/tpm2_pytss/internal/crypto.py
@@ -23,7 +23,7 @@ from cryptography.hazmat.primitives.ciphers.algorithms import AES, Camellia
from cryptography.hazmat.primitives.ciphers import modes, Cipher, CipherAlgorithm
from cryptography.hazmat.backends import default_backend
from cryptography.exceptions import UnsupportedAlgorithm, InvalidSignature
-from typing import Tuple, Type
+from typing import Tuple, Type, Any
import secrets
import sys
@@ -220,7 +220,7 @@ def public_to_key(obj):
return key
-class _MyRSAPrivateNumbers(rsa.RSAPrivateNumbers):
+class _MyRSAPrivateNumbers:
def __init__(self, p: int, n: int, e: int, pubnums: rsa.RSAPublicNumbers):
q = n // p
@@ -231,7 +231,12 @@ class _MyRSAPrivateNumbers(rsa.RSAPrivateNumbers):
dmq1 = rsa.rsa_crt_dmq1(d, q)
iqmp = rsa.rsa_crt_iqmp(p, q)
- super().__init__(p, q, d, dmp1, dmq1, iqmp, pubnums)
+ self._private_numbers = rsa.RSAPrivateNumbers(
+ p, q, d, dmp1, dmq1, iqmp, pubnums
+ )
+
+ def private_key(self, *args: Any, **kwargs: Any) -> rsa.RSAPrivateKey:
+ return self._private_numbers.private_key(*args, **kwargs)
@staticmethod
def _xgcd(a: int, b: int) -> Tuple[int, int, int]:
@@ -251,15 +256,7 @@ class _MyRSAPrivateNumbers(rsa.RSAPrivateNumbers):
#
@staticmethod
def _modinv(a, m):
-
- if sys.version_info < (3, 8):
- g, x, y = _MyRSAPrivateNumbers._xgcd(a, m)
- if g != 1:
- raise Exception("modular inverse does not exist")
- else:
- return x % m
- else:
- return pow(a, -1, m)
+ return pow(a, -1, m)
@staticmethod
def _generate_d(p, q, e, n):
--
2.43.0
|