aboutsummaryrefslogtreecommitdiffstats
path: root/SoftHSMv2/src/lib/crypto/test
diff options
context:
space:
mode:
Diffstat (limited to 'SoftHSMv2/src/lib/crypto/test')
-rw-r--r--SoftHSMv2/src/lib/crypto/test/GOSTTests.cpp34
-rw-r--r--SoftHSMv2/src/lib/crypto/test/GOSTTests.h2
2 files changed, 36 insertions, 0 deletions
diff --git a/SoftHSMv2/src/lib/crypto/test/GOSTTests.cpp b/SoftHSMv2/src/lib/crypto/test/GOSTTests.cpp
index 91f6876..50d42e0 100644
--- a/SoftHSMv2/src/lib/crypto/test/GOSTTests.cpp
+++ b/SoftHSMv2/src/lib/crypto/test/GOSTTests.cpp
@@ -264,6 +264,40 @@ void GOSTTests::testSerialisation()
gost->recycleKeyPair(dKP);
}
+void GOSTTests::testPKCS8()
+{
+ AsymmetricKeyPair* kp;
+ ECParameters *p;
+ ByteString curve = "06072a850302022301";
+
+ // Get parameters
+ p = new ECParameters;
+ CPPUNIT_ASSERT(p != NULL);
+ p->setEC(curve);
+
+ // Generate key-pair
+ CPPUNIT_ASSERT(gost->generateKeyPair(&kp, p));
+ CPPUNIT_ASSERT(kp != NULL);
+
+ GOSTPrivateKey* priv = (GOSTPrivateKey*) kp->getPrivateKey();
+ CPPUNIT_ASSERT(priv != NULL);
+
+ // Encode and decode the private key
+ ByteString pkcs8 = priv->PKCS8Encode();
+ CPPUNIT_ASSERT(pkcs8.size() != 0);
+
+ GOSTPrivateKey* dPriv = (GOSTPrivateKey*) gost->newPrivateKey();
+ CPPUNIT_ASSERT(dPriv != NULL);
+
+ CPPUNIT_ASSERT(dPriv->PKCS8Decode(pkcs8));
+
+ CPPUNIT_ASSERT(priv->getD() == dPriv->getD());
+ CPPUNIT_ASSERT(priv->getEC() == dPriv->getEC());
+
+ gost->recycleKeyPair(kp);
+ gost->recyclePrivateKey(dPriv);
+}
+
void GOSTTests::testSigningVerifying()
{
AsymmetricKeyPair* kp;
diff --git a/SoftHSMv2/src/lib/crypto/test/GOSTTests.h b/SoftHSMv2/src/lib/crypto/test/GOSTTests.h
index f243392..ac6bf01 100644
--- a/SoftHSMv2/src/lib/crypto/test/GOSTTests.h
+++ b/SoftHSMv2/src/lib/crypto/test/GOSTTests.h
@@ -47,6 +47,7 @@ class GOSTTests : public CppUnit::TestFixture
CPPUNIT_TEST(testHashKnownVector);
CPPUNIT_TEST(testKeyGeneration);
CPPUNIT_TEST(testSerialisation);
+ CPPUNIT_TEST(testPKCS8);
CPPUNIT_TEST(testSigningVerifying);
CPPUNIT_TEST(testSignVerifyKnownVector);
CPPUNIT_TEST_SUITE_END();
@@ -57,6 +58,7 @@ public:
void testHashKnownVector();
void testKeyGeneration();
void testSerialisation();
+ void testPKCS8();
void testSigningVerifying();
void testSignVerifyKnownVector();