• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

randombit / botan / 5111374265

29 May 2023 11:19AM UTC coverage: 92.227% (+0.5%) from 91.723%
5111374265

push

github

randombit
Next release will be 3.1.0. Update release notes

75588 of 81959 relevant lines covered (92.23%)

11886470.91 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

88.24
/src/tests/test_ed25519.cpp
1
/*
2
* (C) 2014,2015 Jack Lloyd
3
*
4
* Botan is released under the Simplified BSD License (see license.txt)
5
*/
6

7
#include "tests.h"
8

9
#if defined(BOTAN_HAS_ED25519)
10
   #include "test_pubkey.h"
11
   #include <botan/data_src.h>
12
   #include <botan/ed25519.h>
13
   #include <botan/pkcs8.h>
14
   #include <botan/x509_key.h>
15
#endif
16

17
namespace Botan_Tests {
18

19
namespace {
20

21
#if defined(BOTAN_HAS_ED25519)
22

23
class Ed25519_Key_Validity_Tests : public PK_Key_Validity_Test {
×
24
   public:
25
      Ed25519_Key_Validity_Tests() : PK_Key_Validity_Test("Ed25519", "pubkey/ed25519_key_valid.vec", "Pubkey") {}
3✔
26

27
      std::unique_ptr<Botan::Public_Key> load_public_key(const VarMap& vars) override {
9✔
28
         const std::vector<uint8_t> pubkey = vars.get_req_bin("Pubkey");
9✔
29
         return std::make_unique<Botan::Ed25519_PublicKey>(pubkey);
18✔
30
      }
9✔
31
};
32

33
class Ed25519_Verification_Tests : public PK_Signature_Verification_Test {
×
34
   public:
35
      Ed25519_Verification_Tests() :
1✔
36
            PK_Signature_Verification_Test("Ed25519", "pubkey/ed25519_verify.vec", "Pubkey,Msg,Signature", "Valid") {}
4✔
37

38
      bool clear_between_callbacks() const override { return false; }
60✔
39

40
      std::unique_ptr<Botan::Public_Key> load_public_key(const VarMap& vars) override {
60✔
41
         const std::vector<uint8_t> pubkey = vars.get_req_bin("Pubkey");
60✔
42
         return std::make_unique<Botan::Ed25519_PublicKey>(pubkey);
120✔
43
      }
60✔
44
};
45

46
class Ed25519_Signature_Tests final : public PK_Signature_Generation_Test {
×
47
   public:
48
      Ed25519_Signature_Tests() :
1✔
49
            PK_Signature_Generation_Test("Ed25519", "pubkey/ed25519.vec", "Privkey,Pubkey,Msg,Signature") {}
4✔
50

51
      bool clear_between_callbacks() const override { return false; }
711✔
52

53
      std::unique_ptr<Botan::Private_Key> load_private_key(const VarMap& vars) override {
711✔
54
         const std::vector<uint8_t> privkey = vars.get_req_bin("Privkey");
711✔
55
         const std::vector<uint8_t> pubkey = vars.get_req_bin("Pubkey");
711✔
56

57
         Botan::secure_vector<uint8_t> seed(privkey.begin(), privkey.end());
711✔
58

59
         auto key = std::make_unique<Botan::Ed25519_PrivateKey>(seed);
711✔
60

61
         if(key->get_public_key() != pubkey)
711✔
62
            throw Test_Error("Invalid Ed25519 key in test data");
×
63

64
         return key;
711✔
65
      }
2,844✔
66
};
67

68
class Ed25519_Curdle_Format_Tests final : public Test {
×
69
   public:
70
      std::vector<Test::Result> run() override {
1✔
71
         // Keys from draft-ietf-curdle-pkix-04.txt
72
         const std::string priv_key_str =
1✔
73
            "-----BEGIN PRIVATE KEY-----\n"
74
            "MC4CAQAwBQYDK2VwBCIEINTuctv5E1hK1bbY8fdp+K06/nwoy/HU++CXqI9EdVhC\n"
75
            "-----END PRIVATE KEY-----\n";
1✔
76

77
         const std::string pub_key_str =
1✔
78
            "-----BEGIN PUBLIC KEY-----\n"
79
            "MCowBQYDK2VwAyEAGb9ECWmEzf6FQbrBZ9w7lshQhqowtrbLDFw4rXAxZuE=\n"
80
            "-----END PUBLIC KEY-----\n";
1✔
81

82
         Test::Result result("Ed25519 CURDLE format");
1✔
83

84
         Botan::DataSource_Memory priv_data(priv_key_str);
1✔
85
         auto priv_key = Botan::PKCS8::load_key(priv_data);
1✔
86
         result.confirm("Private key loaded", priv_key != nullptr);
2✔
87

88
         Botan::DataSource_Memory pub_data(pub_key_str);
1✔
89
         auto pub_key = Botan::X509::load_key(pub_data);
1✔
90
         result.confirm("Public key loaded", pub_key != nullptr);
2✔
91

92
         Botan::PK_Signer signer(*priv_key, Test::rng(), "Pure");
1✔
93
         signer.update("message");
1✔
94
         std::vector<uint8_t> sig = signer.signature(Test::rng());
1✔
95

96
         Botan::PK_Verifier verifier(*pub_key, "Pure");
1✔
97
         verifier.update("message");
1✔
98
         result.confirm("Signature valid", verifier.check_signature(sig));
2✔
99

100
         return std::vector<Test::Result>{result};
2✔
101
      }
8✔
102
};
103

104
class Ed25519_Keygen_Tests final : public PK_Key_Generation_Test {
×
105
   public:
106
      std::vector<std::string> keygen_params() const override { return {""}; }
2✔
107

108
      std::string algo_name() const override { return "Ed25519"; }
3✔
109
};
110

111
BOTAN_REGISTER_TEST("pubkey", "ed25519_key_valid", Ed25519_Key_Validity_Tests);
112
BOTAN_REGISTER_TEST("pubkey", "ed25519_verify", Ed25519_Verification_Tests);
113
BOTAN_REGISTER_TEST("pubkey", "ed25519_sign", Ed25519_Signature_Tests);
114
BOTAN_REGISTER_TEST("pubkey", "ed25519_curdle", Ed25519_Curdle_Format_Tests);
115
BOTAN_REGISTER_TEST("pubkey", "ed25519_keygen", Ed25519_Keygen_Tests);
116

117
#endif
118

119
}  // namespace
120

121
}  // namespace Botan_Tests
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc