mirror of
https://github.com/polhenarejos/pico-hsm.git
synced 2024-09-20 03:10:09 +00:00
Adding routine for asymmetric decryption.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
This commit is contained in:
parent
2ce458dad5
commit
8bc4b133ca
@ -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()
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user