From 86701154b036ff0d3ab2e7733d3dfaecd1f7b87a Mon Sep 17 00:00:00 2001 From: Rob Austein Date: Sat, 5 Nov 2016 14:54:20 -0400 Subject: Add attribute read timing tests. Result of running all these timing tests is about what theory would have predicted: read time does not vary significantly between RAM and flash, but write time sure does. --- unit-tests.py | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 60 insertions(+), 4 deletions(-) diff --git a/unit-tests.py b/unit-tests.py index 3f74b36..ca18e3a 100644 --- a/unit-tests.py +++ b/unit-tests.py @@ -614,7 +614,7 @@ class TestPKeyAttribute(TestCaseLoggedIn): self.load_and_fill(HAL_KEY_FLAG_TOKEN, n_attrs = 16, n_fill = 1024) -class TestPKeyAttributeSpeedToken(TestCaseLoggedIn): +class TestPKeyAttributeWriteSpeedToken(TestCaseLoggedIn): """ Attribute speed tests. """ @@ -623,7 +623,7 @@ class TestPKeyAttributeSpeedToken(TestCaseLoggedIn): der = PreloadedKey.db[HAL_KEY_TYPE_EC_PRIVATE, HAL_CURVE_P256].der self.k = hsm.pkey_load(HAL_KEY_TYPE_EC_PRIVATE, HAL_CURVE_P256, der, HAL_KEY_FLAG_TOKEN) self.addCleanup(self.k.delete) - super(TestPKeyAttributeSpeedToken, self).setUp() + super(TestPKeyAttributeWriteSpeedToken, self).setUp() def set_attributes(self, n_attrs): pinwheel = Pinwheel() @@ -640,7 +640,7 @@ class TestPKeyAttributeSpeedToken(TestCaseLoggedIn): def test_set_12_attributes(self): self.set_attributes(12) -class TestPKeyAttributeSpeedVolatile(TestCaseLoggedIn): +class TestPKeyAttributeWriteSpeedVolatile(TestCaseLoggedIn): """ Attribute speed tests. """ @@ -649,7 +649,7 @@ class TestPKeyAttributeSpeedVolatile(TestCaseLoggedIn): der = PreloadedKey.db[HAL_KEY_TYPE_EC_PRIVATE, HAL_CURVE_P256].der self.k = hsm.pkey_load(HAL_KEY_TYPE_EC_PRIVATE, HAL_CURVE_P256, der, 0) self.addCleanup(self.k.delete) - super(TestPKeyAttributeSpeedVolatile, self).setUp() + super(TestPKeyAttributeWriteSpeedVolatile, self).setUp() def set_attributes(self, n_attrs): for i in xrange(n_attrs): @@ -665,6 +665,62 @@ class TestPKeyAttributeSpeedVolatile(TestCaseLoggedIn): self.set_attributes(12) +class TestPKeyAttributeReadSpeedToken(TestCaseLoggedIn): + """ + Attribute speed tests. + """ + + def setUp(self): + der = PreloadedKey.db[HAL_KEY_TYPE_EC_PRIVATE, HAL_CURVE_P256].der + self.k = hsm.pkey_load(HAL_KEY_TYPE_EC_PRIVATE, HAL_CURVE_P256, der, HAL_KEY_FLAG_TOKEN) + self.addCleanup(self.k.delete) + self.k.set_attribute(0, "Attribute 0") + super(TestPKeyAttributeReadSpeedToken, self).setUp() + + def get_attributes(self, n_attrs): + pinwheel = Pinwheel() + for i in xrange(n_attrs): + pinwheel() + self.k.get_attribute(0) + + def test_get_1_attribute(self): + self.get_attributes(1) + + def test_get_6_attributes(self): + self.get_attributes(6) + + def test_get_12_attributes(self): + self.get_attributes(12) + +class TestPKeyAttributeReadSpeedVolatile(TestCaseLoggedIn): + """ + Attribute speed tests. + """ + + def setUp(self): + der = PreloadedKey.db[HAL_KEY_TYPE_EC_PRIVATE, HAL_CURVE_P256].der + self.k = hsm.pkey_load(HAL_KEY_TYPE_EC_PRIVATE, HAL_CURVE_P256, der, 0) + self.addCleanup(self.k.delete) + self.k.set_attribute(0, "Attribute 0") + super(TestPKeyAttributeReadSpeedVolatile, self).setUp() + + def get_attributes(self, n_attrs): + pinwheel = Pinwheel() + for i in xrange(n_attrs): + pinwheel() + self.k.get_attribute(0) + + def test_get_1_attribute(self): + self.get_attributes(1) + + def test_get_6_attributes(self): + self.get_attributes(6) + + def test_get_12_attributes(self): + self.get_attributes(12) + + + @unittest.skipUnless(ecdsa_loaded, "Requires Python ECDSA package") class TestPkeyECDSAVerificationNIST(TestCaseLoggedIn): """ -- cgit v1.2.3