diff options
author | Jack Lloyd <[email protected]> | 2016-07-27 15:58:07 -0400 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2016-07-27 15:58:07 -0400 |
commit | 17677f9981005b68201653b45de42c5958f32b70 (patch) | |
tree | 89cd791389f3de66ab5cc0d70d91311464b79cde /src/tests | |
parent | 376a7900377cae31623e81273cae4cdc03f63e83 (diff) | |
parent | 923be75ef7ba4c21968291333402a7bc6eafedfd (diff) |
Merge GH #556 Add DH negative tests. Fix DH keygen, did not call gen_check due to setting m_x earlier
Diffstat (limited to 'src/tests')
-rw-r--r-- | src/tests/test_dh.cpp | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/src/tests/test_dh.cpp b/src/tests/test_dh.cpp index 4414d2c75..e82ce522a 100644 --- a/src/tests/test_dh.cpp +++ b/src/tests/test_dh.cpp @@ -52,8 +52,41 @@ class Diffie_Hellman_KAT_Tests : public PK_Key_Agreement_Test Botan::DH_PublicKey key(grp, y); return key.public_value(); } + + std::vector<Test::Result> run_final_tests() override + { + using namespace Botan; + + Test::Result result("DH negative tests"); + + const BigInt g("2"); + const BigInt p("58458002095536094658683755258523362961421200751439456159756164191494576279467"); + const DL_Group grp(p, g); + + const Botan::BigInt x("46205663093589612668746163860870963912226379131190812163519349848291472898748"); + std::unique_ptr<Private_Key> privkey(new DH_PrivateKey(Test::rng(), grp, x)); + + std::unique_ptr<PK_Key_Agreement> kas(new PK_Key_Agreement(*privkey, "Raw")); + + result.test_throws("agreement input too big", [&kas]() + { + const BigInt too_big("584580020955360946586837552585233629614212007514394561597561641914945762794672"); + kas->derive_key(16, BigInt::encode(too_big)); + }); + + result.test_throws("agreement input too small", [&kas]() + { + const BigInt too_small("1"); + kas->derive_key(16, BigInt::encode(too_small)); + }); + + return{result}; + } + }; +BOTAN_REGISTER_TEST("dh_kat", Diffie_Hellman_KAT_Tests); + class Diffie_Hellman_Keygen_Tests : public PK_Key_Generation_Test { public: @@ -69,7 +102,6 @@ class Diffie_Hellman_Keygen_Tests : public PK_Key_Generation_Test }; -BOTAN_REGISTER_TEST("dh_kat", Diffie_Hellman_KAT_Tests); BOTAN_REGISTER_TEST("dh_keygen", Diffie_Hellman_Keygen_Tests); #endif |