diff options
author | lloyd <[email protected]> | 2014-12-27 17:50:57 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2014-12-27 17:50:57 +0000 |
commit | d0daf875978848c3edf65c7b3683a21605f72e64 (patch) | |
tree | 46690afadfb5e9acb766468f7f7481bb1244049d /src/tests/test_c25519.cpp | |
parent | 675c2e324268ebce7e2c665389ebd57d38083200 (diff) |
Add Curve25519 based on curve25519-donna by Adam Langley.
This uses only the c64 version from curve25519-donna; on systems that
don't have a native uint128_t type, a donna128 type stands in for just
enough 128-bit operations to satisfy donna.cpp
Diffstat (limited to 'src/tests/test_c25519.cpp')
-rw-r--r-- | src/tests/test_c25519.cpp | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/src/tests/test_c25519.cpp b/src/tests/test_c25519.cpp new file mode 100644 index 000000000..cb03ebf69 --- /dev/null +++ b/src/tests/test_c25519.cpp @@ -0,0 +1,56 @@ +#include "tests.h" +#include "test_pubkey.h" + +#if defined(BOTAN_HAS_CURVE_25519) +#include <botan/curve25519.h> +#include <botan/hex.h> +#include <iostream> +#include <fstream> +#endif + +using namespace Botan; + +#if defined(BOTAN_HAS_CURVE_25519) + +namespace { + +size_t curve25519_scalar_kat(const std::string& secret_h, + const std::string& basepoint_h, + const std::string& out_h) + { + const std::vector<byte> secret = hex_decode(secret_h); + const std::vector<byte> basepoint = hex_decode(basepoint_h); + const std::vector<byte> out = hex_decode(out_h); + + std::vector<byte> got(32); + curve25519_donna(&got[0], &secret[0], &basepoint[0]); + + if(got != out) + { + std::cout << "Got " << hex_encode(got) << " exp " << hex_encode(out) << "\n"; + return 1; + } + + return 0; + } + +} +#endif + +size_t test_curve25519() + { + size_t fails = 0; + +#if defined(BOTAN_HAS_CURVE_25519) + std::ifstream c25519_scalar(PK_TEST_DATA_DIR "/c25519_scalar.vec"); + + fails += run_tests_bb(c25519_scalar, "Curve25519 ScalarMult", "Out", true, + [](std::map<std::string, std::string> m) -> size_t + { + return curve25519_scalar_kat(m["Secret"], m["Basepoint"], m["Out"]); + }); +#endif + + return fails; + } + |