mirror of
https://github.com/polhenarejos/pico-hsm.git
synced 2026-01-17 01:18:06 +00:00
Added CMAC tests.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
This commit is contained in:
parent
a1f478239d
commit
0b71bf693d
2 changed files with 19 additions and 1 deletions
|
|
@ -447,6 +447,10 @@ class Device:
|
|||
resp = self.send(cla=0x80, command=0x78, p1=keyid, p2=0x51, data=data)
|
||||
return resp
|
||||
|
||||
def cmac(self, keyid, data):
|
||||
resp = self.send(cla=0x80, command=0x78, p1=keyid, p2=Algorithm.ALGO_AES_CMAC.value, data=data)
|
||||
return resp
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def device():
|
||||
|
|
|
|||
|
|
@ -19,7 +19,8 @@
|
|||
|
||||
import pytest
|
||||
import os
|
||||
from cryptography.hazmat.primitives import hashes, hmac
|
||||
from cryptography.hazmat.primitives import hashes, hmac, cmac
|
||||
from cryptography.hazmat.primitives.ciphers import algorithms
|
||||
from utils import Algorithm, DOPrefixes
|
||||
from const import DEFAULT_DKEK_SHARES, DEFAULT_DKEK
|
||||
|
||||
|
|
@ -44,3 +45,16 @@ def test_mac_hmac(device, size, algo):
|
|||
h.update(MESSAGE)
|
||||
resB = h.finalize()
|
||||
assert(bytes(resA) == resB)
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"size", [128, 192, 256]
|
||||
)
|
||||
def test_mac_cmac(device, size):
|
||||
pkey = os.urandom(size // 8)
|
||||
keyid = device.import_key(pkey)
|
||||
resA = device.cmac(keyid, MESSAGE)
|
||||
c = cmac.CMAC(algorithms.AES(pkey))
|
||||
c.update(MESSAGE)
|
||||
resB = c.finalize()
|
||||
assert(bytes(resA) == resB)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue