YACA: yaca sign vector tests 90/76090/2
authorLukasz Pawelczyk <l.pawelczyk@samsung.com>
Wed, 22 Jun 2016 14:25:26 +0000 (16:25 +0200)
committerLukasz Pawelczyk <l.pawelczyk@samsung.com>
Thu, 23 Jun 2016 12:33:37 +0000 (14:33 +0200)
Change-Id: Ib4485dc497108a0f00c6c8dcf91fcbb09b843af0

src/yaca/test-vectors/sign_ascii.txt [new file with mode: 0644]
src/yaca/yaca-test-sign.cpp

diff --git a/src/yaca/test-vectors/sign_ascii.txt b/src/yaca/test-vectors/sign_ascii.txt
new file mode 100644 (file)
index 0000000..f88da4b
--- /dev/null
@@ -0,0 +1,49 @@
+##################### RSA #####################
+algo=SHA256
+key_type=RSA_PRIV
+key=3082025d02010002818100b8e7b2cfb6263ab59563b2468d7a912695585fb91e61ed72e65167821572d36fc8c213339660e205b5a02f1f1c9f5adb0a5f0ba11f6b4f1ac6e6a7e3a0b0f322345811d062edfac670413cdf84541086d135d67442c0f8007d021f501fdd7b58f672f43a607e1aa2e4dbdec1b85924c075465fd48975ff1cb3c70a62eb21d859020301000102818023325f94304d08a1e604eb3b88d4caea7845313b70b01d5de0bfa01f5febd29995b273ab3f35c3f068494c8ef488d4e79b0aca90ea052832a5a7e44f6d1821bf8f3786fc31fa62c4b94bf459c1d2cf9959950a9a62cf84f175ebc38f5744ba7abd63b74c1f3a2b336b9a6aac44f140a4224b8bd92f85c1bd15aadb609fc6f3cd024100dc0030b906977e4fe63c5cea11bfaf3c6c674b8fb97b6d6221b6abfc37dec2c93bb011cd5d59943f8b351f052f75dfbef695ca25ee1e7ee50c8984af91467b2b024100d7295a9a1f1c94bcb84271f8cf386fe5f5c7aa08ee9b434ef166cb90eb3723722951bce56b42ae9e25a2450c2f4d7eb93dd98ff1111cfd70a7040aba87bae88b02400a44cc0166e85d51f76a2be015120068ee9a67b17eb3df282c70ad586977315a5939dfaad9479c1ed72d94941662071e8fbdf020931bc34a87aa47923652b6df02410096041155b0277f54edabf64722441950dec2edbcf8906ca7980cb21642c9d8fef9ec31a64bd8dc630b9e4e4226a103a0288d8e9ce7efac8d65059e6d5bc167ed024100da8ca5833e81132808890eb9cd6bbc6cd9b35f25cdc78dbe9e42ee463f8d115a0d6c086bb4fe489a343e7bc72ceb56532667a734477794913437b2d002f7e128
+repeats=1
+input=
+output=ae9ad1b6bf1beb19bff66a97e14573f392820d56dc6bd7ecfc9f95c296c556d1250f5ecb84e8a11c9200d15a1c8998ae2214a2897069da90fb355994570958a03cbe72a20055190330efbe062b75f086b6a6087e233188a3c9e042da4729141692583a27a0d9c1c5e262a93426c658a38217a93fdb579e4b07b42db527ec32e3
+
+algo=SHA256
+key_type=RSA_PRIV
+key=3082025d02010002818100b8e7b2cfb6263ab59563b2468d7a912695585fb91e61ed72e65167821572d36fc8c213339660e205b5a02f1f1c9f5adb0a5f0ba11f6b4f1ac6e6a7e3a0b0f322345811d062edfac670413cdf84541086d135d67442c0f8007d021f501fdd7b58f672f43a607e1aa2e4dbdec1b85924c075465fd48975ff1cb3c70a62eb21d859020301000102818023325f94304d08a1e604eb3b88d4caea7845313b70b01d5de0bfa01f5febd29995b273ab3f35c3f068494c8ef488d4e79b0aca90ea052832a5a7e44f6d1821bf8f3786fc31fa62c4b94bf459c1d2cf9959950a9a62cf84f175ebc38f5744ba7abd63b74c1f3a2b336b9a6aac44f140a4224b8bd92f85c1bd15aadb609fc6f3cd024100dc0030b906977e4fe63c5cea11bfaf3c6c674b8fb97b6d6221b6abfc37dec2c93bb011cd5d59943f8b351f052f75dfbef695ca25ee1e7ee50c8984af91467b2b024100d7295a9a1f1c94bcb84271f8cf386fe5f5c7aa08ee9b434ef166cb90eb3723722951bce56b42ae9e25a2450c2f4d7eb93dd98ff1111cfd70a7040aba87bae88b02400a44cc0166e85d51f76a2be015120068ee9a67b17eb3df282c70ad586977315a5939dfaad9479c1ed72d94941662071e8fbdf020931bc34a87aa47923652b6df02410096041155b0277f54edabf64722441950dec2edbcf8906ca7980cb21642c9d8fef9ec31a64bd8dc630b9e4e4226a103a0288d8e9ce7efac8d65059e6d5bc167ed024100da8ca5833e81132808890eb9cd6bbc6cd9b35f25cdc78dbe9e42ee463f8d115a0d6c086bb4fe489a343e7bc72ceb56532667a734477794913437b2d002f7e128
+repeats=1
+input=a
+output=131d083e6f355f50740ba80690bc62abc8061bc1e0330304be23862f5410f0034a700269c3026d7913b8021f361a9b80fe663e1acba00e80d53c0a04ec6a8da5d21cac839f7b23905e8414a2a0f3a2881eceaa9ff833d9e74221eb11a84a7e063626a69d714d06f4f642019cef2f6a90d002cbf6b80afd541a9b10569d1031df
+
+algo=SHA256
+key_type=RSA_PRIV
+key=3082025d02010002818100b8e7b2cfb6263ab59563b2468d7a912695585fb91e61ed72e65167821572d36fc8c213339660e205b5a02f1f1c9f5adb0a5f0ba11f6b4f1ac6e6a7e3a0b0f322345811d062edfac670413cdf84541086d135d67442c0f8007d021f501fdd7b58f672f43a607e1aa2e4dbdec1b85924c075465fd48975ff1cb3c70a62eb21d859020301000102818023325f94304d08a1e604eb3b88d4caea7845313b70b01d5de0bfa01f5febd29995b273ab3f35c3f068494c8ef488d4e79b0aca90ea052832a5a7e44f6d1821bf8f3786fc31fa62c4b94bf459c1d2cf9959950a9a62cf84f175ebc38f5744ba7abd63b74c1f3a2b336b9a6aac44f140a4224b8bd92f85c1bd15aadb609fc6f3cd024100dc0030b906977e4fe63c5cea11bfaf3c6c674b8fb97b6d6221b6abfc37dec2c93bb011cd5d59943f8b351f052f75dfbef695ca25ee1e7ee50c8984af91467b2b024100d7295a9a1f1c94bcb84271f8cf386fe5f5c7aa08ee9b434ef166cb90eb3723722951bce56b42ae9e25a2450c2f4d7eb93dd98ff1111cfd70a7040aba87bae88b02400a44cc0166e85d51f76a2be015120068ee9a67b17eb3df282c70ad586977315a5939dfaad9479c1ed72d94941662071e8fbdf020931bc34a87aa47923652b6df02410096041155b0277f54edabf64722441950dec2edbcf8906ca7980cb21642c9d8fef9ec31a64bd8dc630b9e4e4226a103a0288d8e9ce7efac8d65059e6d5bc167ed024100da8ca5833e81132808890eb9cd6bbc6cd9b35f25cdc78dbe9e42ee463f8d115a0d6c086bb4fe489a343e7bc72ceb56532667a734477794913437b2d002f7e128
+repeats=1
+input=message signature
+output=0b5e6e9e6679ea5a64bf5453aafd644351c8b93fb7558dbb85527ed9e37b26e9362d006f1dd306728bfe7c5b0f032b8c0ef539ba2578e7cc521d21e56c67cd2d14f1c23c6b27901581af379eba0621ae3619b56fde90175a49239e51fef011e0cd5816af05465b7238adbe42e9cd7b8107a266adfa06f6cdf124aa7a03f1b1e1
+
+algo=SHA256
+key_type=RSA_PRIV
+key=3082025d02010002818100b8e7b2cfb6263ab59563b2468d7a912695585fb91e61ed72e65167821572d36fc8c213339660e205b5a02f1f1c9f5adb0a5f0ba11f6b4f1ac6e6a7e3a0b0f322345811d062edfac670413cdf84541086d135d67442c0f8007d021f501fdd7b58f672f43a607e1aa2e4dbdec1b85924c075465fd48975ff1cb3c70a62eb21d859020301000102818023325f94304d08a1e604eb3b88d4caea7845313b70b01d5de0bfa01f5febd29995b273ab3f35c3f068494c8ef488d4e79b0aca90ea052832a5a7e44f6d1821bf8f3786fc31fa62c4b94bf459c1d2cf9959950a9a62cf84f175ebc38f5744ba7abd63b74c1f3a2b336b9a6aac44f140a4224b8bd92f85c1bd15aadb609fc6f3cd024100dc0030b906977e4fe63c5cea11bfaf3c6c674b8fb97b6d6221b6abfc37dec2c93bb011cd5d59943f8b351f052f75dfbef695ca25ee1e7ee50c8984af91467b2b024100d7295a9a1f1c94bcb84271f8cf386fe5f5c7aa08ee9b434ef166cb90eb3723722951bce56b42ae9e25a2450c2f4d7eb93dd98ff1111cfd70a7040aba87bae88b02400a44cc0166e85d51f76a2be015120068ee9a67b17eb3df282c70ad586977315a5939dfaad9479c1ed72d94941662071e8fbdf020931bc34a87aa47923652b6df02410096041155b0277f54edabf64722441950dec2edbcf8906ca7980cb21642c9d8fef9ec31a64bd8dc630b9e4e4226a103a0288d8e9ce7efac8d65059e6d5bc167ed024100da8ca5833e81132808890eb9cd6bbc6cd9b35f25cdc78dbe9e42ee463f8d115a0d6c086bb4fe489a343e7bc72ceb56532667a734477794913437b2d002f7e128
+repeats=1
+input=qwertyuiopasdfghjklzxcvbnm
+output=69993e483920296cc4b555681e36b3709b56671f5adf427a4e1e884b8dca95bd836af04b14b4f933bf466e616b932fb9eb0083f9059766b4f9e0aa9e623c828bd642c2632b2be5bfa9eabedd2f4497ad26a07c482a43e481745ba965276337c4066d33c9c1fed0c99c91937f01b0ce1e7368812d5c9d89ea62ea301c833f1081
+
+algo=SHA256
+key_type=RSA_PRIV
+key=3082025d02010002818100b8e7b2cfb6263ab59563b2468d7a912695585fb91e61ed72e65167821572d36fc8c213339660e205b5a02f1f1c9f5adb0a5f0ba11f6b4f1ac6e6a7e3a0b0f322345811d062edfac670413cdf84541086d135d67442c0f8007d021f501fdd7b58f672f43a607e1aa2e4dbdec1b85924c075465fd48975ff1cb3c70a62eb21d859020301000102818023325f94304d08a1e604eb3b88d4caea7845313b70b01d5de0bfa01f5febd29995b273ab3f35c3f068494c8ef488d4e79b0aca90ea052832a5a7e44f6d1821bf8f3786fc31fa62c4b94bf459c1d2cf9959950a9a62cf84f175ebc38f5744ba7abd63b74c1f3a2b336b9a6aac44f140a4224b8bd92f85c1bd15aadb609fc6f3cd024100dc0030b906977e4fe63c5cea11bfaf3c6c674b8fb97b6d6221b6abfc37dec2c93bb011cd5d59943f8b351f052f75dfbef695ca25ee1e7ee50c8984af91467b2b024100d7295a9a1f1c94bcb84271f8cf386fe5f5c7aa08ee9b434ef166cb90eb3723722951bce56b42ae9e25a2450c2f4d7eb93dd98ff1111cfd70a7040aba87bae88b02400a44cc0166e85d51f76a2be015120068ee9a67b17eb3df282c70ad586977315a5939dfaad9479c1ed72d94941662071e8fbdf020931bc34a87aa47923652b6df02410096041155b0277f54edabf64722441950dec2edbcf8906ca7980cb21642c9d8fef9ec31a64bd8dc630b9e4e4226a103a0288d8e9ce7efac8d65059e6d5bc167ed024100da8ca5833e81132808890eb9cd6bbc6cd9b35f25cdc78dbe9e42ee463f8d115a0d6c086bb4fe489a343e7bc72ceb56532667a734477794913437b2d002f7e128
+repeats=1
+input=1234567890qwertyuiop !@#$%^&*() POIUYTREWQ
+output=20316dc8be3c7f33f85c7c39d4e36132e76f6caa717faaada7cfd0911c85d60fffbc755f356cd760073b6e865a12e0eb60c73b461400a1f18ac3ceece401a97624a5cb7901adc00f01269f93664ebb620fa59c2aef05eadac268ac051c2acb2ebea8fa1ddf5f2a258cabeeaa63a7a451ff6f69d6098fdeb2b763963ad67921ea
+
+algo=SHA256
+key_type=RSA_PRIV
+key=3082025d02010002818100b8e7b2cfb6263ab59563b2468d7a912695585fb91e61ed72e65167821572d36fc8c213339660e205b5a02f1f1c9f5adb0a5f0ba11f6b4f1ac6e6a7e3a0b0f322345811d062edfac670413cdf84541086d135d67442c0f8007d021f501fdd7b58f672f43a607e1aa2e4dbdec1b85924c075465fd48975ff1cb3c70a62eb21d859020301000102818023325f94304d08a1e604eb3b88d4caea7845313b70b01d5de0bfa01f5febd29995b273ab3f35c3f068494c8ef488d4e79b0aca90ea052832a5a7e44f6d1821bf8f3786fc31fa62c4b94bf459c1d2cf9959950a9a62cf84f175ebc38f5744ba7abd63b74c1f3a2b336b9a6aac44f140a4224b8bd92f85c1bd15aadb609fc6f3cd024100dc0030b906977e4fe63c5cea11bfaf3c6c674b8fb97b6d6221b6abfc37dec2c93bb011cd5d59943f8b351f052f75dfbef695ca25ee1e7ee50c8984af91467b2b024100d7295a9a1f1c94bcb84271f8cf386fe5f5c7aa08ee9b434ef166cb90eb3723722951bce56b42ae9e25a2450c2f4d7eb93dd98ff1111cfd70a7040aba87bae88b02400a44cc0166e85d51f76a2be015120068ee9a67b17eb3df282c70ad586977315a5939dfaad9479c1ed72d94941662071e8fbdf020931bc34a87aa47923652b6df02410096041155b0277f54edabf64722441950dec2edbcf8906ca7980cb21642c9d8fef9ec31a64bd8dc630b9e4e4226a103a0288d8e9ce7efac8d65059e6d5bc167ed024100da8ca5833e81132808890eb9cd6bbc6cd9b35f25cdc78dbe9e42ee463f8d115a0d6c086bb4fe489a343e7bc72ceb56532667a734477794913437b2d002f7e128
+repeats=10
+input=repeat test
+output=1b95329c1d5ec811cde3de767d1c248227d7096c5572d2d077a30094e212f96e6b9d33cd7f5b1c5883815969f66dcb7470311a7e9d0fcfae13e45d26b2bd02c0c542d7ea5658d37968aac7d81c14d06a36a5199b7c7648b60b5ab2d76344047cf6d8533447db991d4c05e4260e8af0c21124554d4a7506272de6a6616e77feef
+
+algo=SHA256
+key_type=RSA_PRIV
+key=3082025d02010002818100b8e7b2cfb6263ab59563b2468d7a912695585fb91e61ed72e65167821572d36fc8c213339660e205b5a02f1f1c9f5adb0a5f0ba11f6b4f1ac6e6a7e3a0b0f322345811d062edfac670413cdf84541086d135d67442c0f8007d021f501fdd7b58f672f43a607e1aa2e4dbdec1b85924c075465fd48975ff1cb3c70a62eb21d859020301000102818023325f94304d08a1e604eb3b88d4caea7845313b70b01d5de0bfa01f5febd29995b273ab3f35c3f068494c8ef488d4e79b0aca90ea052832a5a7e44f6d1821bf8f3786fc31fa62c4b94bf459c1d2cf9959950a9a62cf84f175ebc38f5744ba7abd63b74c1f3a2b336b9a6aac44f140a4224b8bd92f85c1bd15aadb609fc6f3cd024100dc0030b906977e4fe63c5cea11bfaf3c6c674b8fb97b6d6221b6abfc37dec2c93bb011cd5d59943f8b351f052f75dfbef695ca25ee1e7ee50c8984af91467b2b024100d7295a9a1f1c94bcb84271f8cf386fe5f5c7aa08ee9b434ef166cb90eb3723722951bce56b42ae9e25a2450c2f4d7eb93dd98ff1111cfd70a7040aba87bae88b02400a44cc0166e85d51f76a2be015120068ee9a67b17eb3df282c70ad586977315a5939dfaad9479c1ed72d94941662071e8fbdf020931bc34a87aa47923652b6df02410096041155b0277f54edabf64722441950dec2edbcf8906ca7980cb21642c9d8fef9ec31a64bd8dc630b9e4e4226a103a0288d8e9ce7efac8d65059e6d5bc167ed024100da8ca5833e81132808890eb9cd6bbc6cd9b35f25cdc78dbe9e42ee463f8d115a0d6c086bb4fe489a343e7bc72ceb56532667a734477794913437b2d002f7e128
+repeats=1000
+input=qwerty
+output=1114f028cf35a5cfee025c7407ab6c849a336c529a50aa3785b9c8211f7ae972867925efb09babb5a3c0bbf687d2ced5cf6f41ea88720b0ddbd712d7dd13a235681c91816d75e0de42f8aed49fc781fdab5e2ea24bb91f1167ab5ccc724c4a4b7d324bf116689ad8410c4d82f2b024bdec4d8c16429472a3fc97a679610de072
index 66abb70a13bd7726e6485bdb1e55a92e16437e1a..6e2b7370176ffc537fef10ff7a242390f8cc8aa5 100644 (file)
@@ -27,6 +27,7 @@
 #include <yaca_types.h>
 
 #include "yaca-test-common.h"
+#include "yaca-test-vector.h"
 #include "lorem.h"
 
 
@@ -169,3 +170,56 @@ RUNNER_TEST(T6080_yaca_sign_get_output_length)
         for (const auto &k: keys)
             sign_length_test(d, k);
 }
+
+RUNNER_TEST(T6090_yaca_sign_test_vectors, YacaTest)
+{
+    auto tvv = loadTestVector("sign_ascii.txt");
+
+    for (const auto& tv : tvv) {
+        yaca_digest_algorithm_e algo;
+        yaca_key_type_e key_type;
+        Buffer key_data;
+        size_t repeats;
+        std::string input;
+        Buffer expected;
+
+        tv.get("algo", algo);
+        tv.get("key_type", key_type);
+        tv.get("key", key_data);
+        tv.get("repeats", repeats);
+        tv.get("input", input);
+        tv.get("output", expected);
+
+        KeyPtr key = import_key(key_type, nullptr, key_data.data(), key_data.size());
+
+        CtxPtr ctx = sign_init(algo, key);
+        size_t output_len = get_output_length(ctx);
+
+        if (input.size() > 0) {
+            for (size_t i = 0; i < repeats; i++)
+                YACA_SUCCESS(yaca_sign_update(ctx.get(),
+                                              input.c_str(),
+                                              input.size()));
+        }
+
+        Buffer output(output_len);
+        YACA_SUCCESS(yaca_sign_finalize(ctx.get(), output.data(), &output_len));
+        RUNNER_ASSERT_MSG(output.size() >= output_len,
+                          "Length returned from yaca_sign_finalize() (" << output_len <<
+                          ") is greater than the one returned from yaca_context_get_output_length() ("
+                          << output.size() << ")");
+        output.resize(output_len);
+
+        YACA_ASSERT_MSG(output.size() == expected.size(),
+                        "Signature calculated for \""  << truncate_str(input, 16) << "\" with "
+                        << digest2str(algo) << " and " << keytype2str(key_type)
+                        << " key is " << output.size() * 8
+                        <<" bits long. Expected " << expected.size() * 8 << " bits");
+
+        int ret = yaca_memcmp(output.data(), expected.data(), output.size());
+        YACA_ASSERT_MSG(YACA_ERROR_NONE == ret,
+                        "Signature calculated for \"" << truncate_str(input, 16) << "\" with "
+                        << digest2str(algo) << " and " << keytype2str(key_type)
+                        << "key is different than expected");
+    }
+}