blob: aa34a5fc1b64a514e761d59fb30fdb7de257012b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
/*
* (C) 2014,2015 Jack Lloyd
*
* Botan is released under the Simplified BSD License (see license.txt)
*/
#include "tests.h"
#if defined(BOTAN_HAS_CURVE_25519)
#include "test_pubkey.h"
#include <botan/curve25519.h>
#include <botan/hex.h>
#include <iostream>
#include <fstream>
using namespace Botan;
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.data(), secret.data(), basepoint.data());
if(got != out)
{
std::cout << "Got " << hex_encode(got) << " exp " << hex_encode(out) << std::endl;
return 1;
}
return 0;
}
}
size_t test_curve25519()
{
size_t fails = 0;
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"]);
});
return fails;
}
#else
SKIP_TEST(curve25519);
#endif // BOTAN_HAS_CURVE_25519
|