diff options
author | Jack Lloyd <[email protected]> | 2016-06-20 01:23:34 -0400 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2016-06-20 01:37:01 -0400 |
commit | 9a6621f473de4d2a49ed47e9a3db7cbf574b9236 (patch) | |
tree | c2f025bd0179d6568a3e46b1713c2dbf69629067 /src/tests | |
parent | 17741e56503bf538b5cceb29269c1f4981f649fb (diff) | |
parent | 70a61c082408a22b516fbe0f3a81441c6c5f165e (diff) |
Merge GH #504 Add ECKCDSA
Diffstat (limited to 'src/tests')
-rw-r--r-- | src/tests/data/pubkey/eckcdsa.vec | 29 | ||||
-rw-r--r-- | src/tests/test_eckcdsa.cpp | 77 |
2 files changed, 106 insertions, 0 deletions
diff --git a/src/tests/data/pubkey/eckcdsa.vec b/src/tests/data/pubkey/eckcdsa.vec new file mode 100644 index 000000000..d9bd659e2 --- /dev/null +++ b/src/tests/data/pubkey/eckcdsa.vec @@ -0,0 +1,29 @@ + +# Taken from Korean TTA Standard TTAK.KO-12.0015/R2 +# "Digital Signature Mechanism with Appendix - Part 3: Korean Certificate-based Digitial Signature Algorithm using Elliptic Curves (EC-KCDSA)" +# http://www.tta.or.kr/include/Download.jsp?filename=stnfile/TTAK.KO-12.0015_R2.pdf + +Group = secp224r1 +X = 0x562A6F64E162FFCB51CD4707774AE36681B6CEF205FE5D43912956A2 + +Msg = 5468697320697320612073616D706C65206D65737361676520666F722045432D4B4344534120696D706C656D656E746174696F6E2076616C69646174696F6E2E +Hash = SHA-224 +Nonce = 76A0AFC18646D1B620A079FB223865A7BCB447F3C03A35D878EA4CDA +Signature = EEA58C91E0CDCEB5799B00D2412D928FDD23122A1C2BDF43C2F8DAFAAEBAB53C7A44A8B22F35FDB9DE265F23B89F65A69A8B7BD4061911A6 + +Group = secp256r1 +X = 0x9051A275AA4D98439EDDED13FA1C6CBBCCE775D8CC9433DEE69C59848B3594DF + +Hash = SHA-256 +Nonce = 71B88F398916DA9C90F555F1B5732B7DC636B49C638150BAC11BF05CFE16596A +Signature = 0EDDF680601266EE1DA83E55A6D9445FC781DAEB14C765E7E5D0CDBAF1F14A689B333457661C7CF741BDDBC0835553DFBB37EE74F53DB699E0A17780C7B6F1D0 + +# Taken from ISO/IEC 14888-3:2006, with corrections from ISO/IEC 14888-3:2006/Cor.2:2009 + +Group = secp192r1 +X = 0x444811A323E03C28A34CD859EE2FF1A34D1AAF3CB0B5603B + +Msg = 616263 +Hash = SHA-1 +Nonce = 4B19A0725424CD3310B02D8C8416C98D64C618BFE935597D +Signature = 3CA29800D425FCAA51CCB209B4ED5D6C352108223143B2EA5A0E8644CE8F768A6FA4D193C726AD08019788E5
\ No newline at end of file diff --git a/src/tests/test_eckcdsa.cpp b/src/tests/test_eckcdsa.cpp new file mode 100644 index 000000000..96c28383a --- /dev/null +++ b/src/tests/test_eckcdsa.cpp @@ -0,0 +1,77 @@ +/* +* (C) 2016 René Korthaus, Sirrix AG +* +* Botan is released under the Simplified BSD License (see license.txt) +*/ + +#include "tests.h" + +#include "test_rng.h" + +#if defined(BOTAN_HAS_ECKCDSA) + #include "test_pubkey.h" + #include <botan/eckcdsa.h> + #include <botan/oids.h> +#endif + +namespace Botan_Tests { + +namespace { + +#if defined(BOTAN_HAS_ECKCDSA) + +class ECKCDSA_Signature_KAT_Tests : public PK_Signature_Generation_Test + { + public: + ECKCDSA_Signature_KAT_Tests() : PK_Signature_Generation_Test( + "ECKCDSA", + "pubkey/eckcdsa.vec", + {"Group", "X", "Hash", "Msg", "Nonce", "Signature"}) + {} + + bool clear_between_callbacks() const override { return false; } + + std::unique_ptr<Botan::Private_Key> load_private_key(const VarMap& vars) override + { + const std::string group_id = get_req_str(vars, "Group"); + const BigInt x = get_req_bn(vars, "X"); + Botan::EC_Group group(Botan::OIDS::lookup(group_id)); + + std::unique_ptr<Botan::Private_Key> key(new Botan::ECKCDSA_PrivateKey(Test::rng(), group, x)); + return key; + } + + std::string default_padding(const VarMap& vars) const override + { + return "EMSA1(" + get_req_str(vars, "Hash") + ")"; + } + + Botan::RandomNumberGenerator* test_rng(const std::vector<uint8_t>& nonce) const override + { + // eckcdsa signature generation extracts more random than just the nonce, + // but the nonce is extracted first + return new Fixed_Output_Position_RNG(nonce, 1); + } + }; + +class ECKCDSA_Keygen_Tests : public PK_Key_Generation_Test + { + public: + std::vector<std::string> keygen_params() const override { return { "secp256r1", "secp384r1", "secp521r1" }; } + + std::unique_ptr<Botan::Private_Key> make_key(Botan::RandomNumberGenerator& rng, + const std::string& param) const override + { + Botan::EC_Group group(param); + return std::unique_ptr<Botan::Private_Key>(new Botan::ECKCDSA_PrivateKey(rng, group)); + } + }; + +BOTAN_REGISTER_TEST("eckcdsa", ECKCDSA_Signature_KAT_Tests); +BOTAN_REGISTER_TEST("eckcdsa_keygen", ECKCDSA_Keygen_Tests); + +#endif + +} + +} |