diff options
author | Jack Lloyd <[email protected]> | 2016-02-09 07:15:20 -0500 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2016-02-09 07:15:20 -0500 |
commit | 86dd5511d873846f57b235531dda428b9498cf6a (patch) | |
tree | 5eedb27dea290abbeaa5f8d870e6064df48f46bf | |
parent | 2becd2b8b7fe1cda319789fd96ddd7bf51b433cb (diff) |
Check result of dynamic_cast
Unlikely to fail in this case but anything's possible.
Found by Coverity
-rw-r--r-- | src/tests/test_c25519.cpp | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/src/tests/test_c25519.cpp b/src/tests/test_c25519.cpp index 43be2258b..67e2104c3 100644 --- a/src/tests/test_c25519.cpp +++ b/src/tests/test_c25519.cpp @@ -81,17 +81,24 @@ class Curve25519_Roundtrip_Test : public Test Botan::Curve25519_PublicKey* a_pub_key = dynamic_cast<Botan::Curve25519_PublicKey*>(a_pub.get()); Botan::Curve25519_PublicKey* b_pub_key = dynamic_cast<Botan::Curve25519_PublicKey*>(b_pub.get()); - Botan::PK_Key_Agreement a_ka(*a_priv, "KDF2(SHA-256)"); - Botan::PK_Key_Agreement b_ka(*b_priv, "KDF2(SHA-256)"); - - const std::string context = "shared context value"; - Botan::SymmetricKey a_key = a_ka.derive_key(32, b_pub_key->public_value(), context); - Botan::SymmetricKey b_key = b_ka.derive_key(32, a_pub_key->public_value(), context); - - if(!result.test_eq("key agreement", a_key.bits_of(), b_key.bits_of())) + if(a_pub_key && b_pub_key) + { + Botan::PK_Key_Agreement a_ka(*a_priv, "KDF2(SHA-256)"); + Botan::PK_Key_Agreement b_ka(*b_priv, "KDF2(SHA-256)"); + + const std::string context = "shared context value"; + Botan::SymmetricKey a_key = a_ka.derive_key(32, b_pub_key->public_value(), context); + Botan::SymmetricKey b_key = b_ka.derive_key(32, a_pub_key->public_value(), context); + + if(!result.test_eq("key agreement", a_key.bits_of(), b_key.bits_of())) + { + result.test_note(a_priv_pem); + result.test_note(b_priv_pem); + } + } + else { - result.test_note(a_priv_pem); - result.test_note(b_priv_pem); + result.test_failure("Cast back to Curve25519 failed"); } results.push_back(result); |