Skip to content

Commit a53f845

Browse files
author
Akshitij Malik
committed
Add AES Key Derivation Support (ECB,CBC Encrypt)
Additional Information: 1. Added AES Key Derivation mechanisms described in PKCS11 v2.4.0 Section 2.15: - CKM_AES_ECB_ENCRYPT_DATA - CKM_AES_CBC_ENCRYPT_DATA 2. Incorporated code-review comments: - directly sliced the IV data to extract mechanism_params for CBC_ENCRYPT, - added Unit Tests for ECB_ENCRYPT - test_derive_ecb_encrypt - added Unit Tests for CBC_ENCRYPT - test_derive_cbc_encrypt - updated dev-requirements - split the Unit Tests into 2 phases: - key-derivation tests - data encrypyion/decryption tests - replaced f-strings with python3.5 compatible format strings Sanity Testing: 1. Build Validation: python setup.py build_ext --inplace 2. AES Testing: export PKCS11_MODULE=XXX export PKCS11_TOKEN_LABEL=XXX export PKCS11_TOKEN_PIN=XXX export PKCS11_TOKEN_SO_PIN=XXX pytest ./tests/test_aes.py Signed-off-by: Akshitij Malik
1 parent 84d28f2 commit a53f845

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

tests/test_aes.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ def test_derive_using_ecb_encrypt(self, test_type, test_key_length, iv_length):
152152
pkcs11.Attribute.SENSITIVE: False,
153153
})
154154

155-
self.assertTrue(key is not None, f"Failed to create {test_key_length}-bit Master Key")
155+
self.assertTrue(key is not None, "Failed to create {}-bit Master Key".format(test_key_length))
156156

157157
# Derive a Key from the Master Key
158158
iv = b'0' * iv_length
@@ -170,9 +170,9 @@ def test_derive_using_ecb_encrypt(self, test_type, test_key_length, iv_length):
170170
derived_key = None
171171

172172
if test_type.startswith("NEGATIVE"):
173-
self.assertTrue(derived_key is None, f"Unexpected {test_key_length}-bit Derived Key")
173+
self.assertTrue(derived_key is None, "Unexpected {}-bit Derived Key".format(test_key_length))
174174
else:
175-
self.assertTrue(derived_key is not None, f"Failed to derive {test_key_length}-bit Derived Key")
175+
self.assertTrue(derived_key is not None, "Failed to derive {}-bit Derived Key".format(test_key_length))
176176

177177
@parameterized.expand([
178178
("POSITIVE_128_BIT", 128, 16),
@@ -200,7 +200,7 @@ def test_encrypt_with_key_derived_using_ecb_encrypt(self, test_type, test_key_le
200200
pkcs11.Attribute.SENSITIVE: False,
201201
})
202202

203-
self.assertTrue(key is not None, f"Failed to create {test_key_length}-bit Master Key")
203+
self.assertTrue(key is not None, "Failed to create {}-bit Master Key".format(test_key_length))
204204

205205
# Derive a Key from the Master Key
206206
iv = b'0' * iv_length
@@ -217,7 +217,7 @@ def test_encrypt_with_key_derived_using_ecb_encrypt(self, test_type, test_key_le
217217
pkcs11.exceptions.FunctionFailed) as e:
218218
derived_key = None
219219

220-
self.assertTrue(derived_key is not None, f"Failed to derive {test_key_length}-bit Derived Key")
220+
self.assertTrue(derived_key is not None, "Failed to derive {}-bit Derived Key".format(test_key_length))
221221

222222
# Test capability of Key to Encrypt/Decrypt data
223223
data = b'HELLO WORLD' * 1024
@@ -258,7 +258,7 @@ def test_derive_using_cbc_encrypt(self, test_type, test_key_length, iv_length, d
258258
pkcs11.Attribute.SENSITIVE: False,
259259
})
260260

261-
self.assertTrue(key is not None, f"Failed to create {test_key_length}-bit Master Key")
261+
self.assertTrue(key is not None, "Failed to create {}-bit Master Key".format(test_key_length))
262262

263263
# Derive a Key from the Master Key
264264
iv = b'0' * iv_length
@@ -278,9 +278,9 @@ def test_derive_using_cbc_encrypt(self, test_type, test_key_length, iv_length, d
278278
derived_key = None
279279

280280
if test_type.startswith("NEGATIVE"):
281-
self.assertTrue(derived_key is None, f"Unexpected {test_key_length}-bit Derived Key")
281+
self.assertTrue(derived_key is None, "Unexpected {}-bit Derived Key".format(test_key_length))
282282
else:
283-
self.assertTrue(derived_key is not None, f"Failed to derive {test_key_length}-bit Derived Key")
283+
self.assertTrue(derived_key is not None, "Failed to derive {}-bit Derived Key".format(test_key_length))
284284

285285
@parameterized.expand([
286286
("POSITIVE_128_BIT", 128, 16, 16),
@@ -309,7 +309,7 @@ def test_encrypt_with_key_derived_using_cbc_encrypt(self, test_type, test_key_le
309309
pkcs11.Attribute.SENSITIVE: False,
310310
})
311311

312-
self.assertTrue(key is not None, f"Failed to create {test_key_length}-bit Master Key")
312+
self.assertTrue(key is not None, "Failed to create {}-bit Master Key".format(test_key_length))
313313

314314
# Derive a Key from the Master Key
315315
iv = b'0' * iv_length
@@ -328,7 +328,7 @@ def test_encrypt_with_key_derived_using_cbc_encrypt(self, test_type, test_key_le
328328
IndexError) as e:
329329
derived_key = None
330330

331-
self.assertTrue(derived_key is not None, f"Failed to derive {test_key_length}-bit Derived Key")
331+
self.assertTrue(derived_key is not None, "Failed to derive {}-bit Derived Key".format(test_key_length))
332332

333333
# Test capability of Key to Encrypt/Decrypt data
334334
data = b'HELLO WORLD' * 1024

0 commit comments

Comments
 (0)