Adding routine for asymmetric decryption.

Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
This commit is contained in:
Pol Henarejos 2023-02-12 21:53:19 +01:00
parent 2ce458dad5
commit 8bc4b133ca
No known key found for this signature in database
GPG Key ID: C0095B7870A4CCD3
2 changed files with 16 additions and 1 deletions

View File

@ -2,7 +2,7 @@
import sys
import pytest
from binascii import hexlify
from utils import APDUResponse, DOPrefixes, KeyType, Algorithm
from utils import APDUResponse, DOPrefixes, KeyType, Algorithm, Padding
import hashlib
try:
@ -240,6 +240,16 @@ class Device:
)
return pubkey.verify(signature, data, padd, hsh)
def decrypt(self, keyid, data, pad):
if (isinstance(pad, padding.OAEP)):
p2 = Padding.OAEP.value
elif (isinstance(pad, padding.PKCS1v15)):
p2 = Padding.PKCS.value
else:
p2 = Padding.RAW.value
resp = self.send(command=0x62, p1=keyid, p2=p2, data=list(data))
return bytes(resp)
@pytest.fixture(scope="session")
def device():
dev = Device()

View File

@ -118,3 +118,8 @@ class Algorithm(Enum):
ALGO_RSA_PSS_SHA256 = 0x43
ALGO_RSA_PSS_SHA384 = 0x44
ALGO_RSA_PSS_SHA512 = 0x45
class Padding(Enum):
RAW = 0x21
PKCS = 0x22
OAEP = 0x23