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

randombit / botan / 13466437408

21 Feb 2025 10:38PM UTC coverage: 91.627% (-0.04%) from 91.666%
13466437408

push

github

web-flow
Merge pull request #4702 from randombit/jack/ed25519-constructor-fn

Add named pseudo-constructors for Ed25519_PrivateKey

94977 of 103656 relevant lines covered (91.63%)

11428202.21 hits per line

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

93.88
/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") {}
2✔
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") {}
2✔
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") {}
2✔
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
         auto key = std::make_unique<Botan::Ed25519_PrivateKey>(Botan::Ed25519_PrivateKey::from_seed(privkey));
1,422✔
58

59
         if(key->raw_public_key_bits() != pubkey) {
1,422✔
60
            throw Test_Error("Invalid Ed25519 key in test data");
×
61
         }
62

63
         return key;
711✔
64
      }
2,133✔
65
};
66

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

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

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

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

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

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

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

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

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

107
      std::string algo_name() const override { return "Ed25519"; }
1✔
108

109
      std::unique_ptr<Botan::Public_Key> public_key_from_raw(std::string_view /* keygen_params */,
1✔
110
                                                             std::string_view /* provider */,
111
                                                             std::span<const uint8_t> raw_pk) const override {
112
         return std::make_unique<Botan::Ed25519_PublicKey>(raw_pk);
1✔
113
      }
114
};
115

116
BOTAN_REGISTER_TEST("pubkey", "ed25519_key_valid", Ed25519_Key_Validity_Tests);
117
BOTAN_REGISTER_TEST("pubkey", "ed25519_verify", Ed25519_Verification_Tests);
118
BOTAN_REGISTER_TEST("pubkey", "ed25519_sign", Ed25519_Signature_Tests);
119
BOTAN_REGISTER_TEST("pubkey", "ed25519_curdle", Ed25519_Curdle_Format_Tests);
120
BOTAN_REGISTER_TEST("pubkey", "ed25519_keygen", Ed25519_Keygen_Tests);
121

122
#endif
123

124
}  // namespace
125

126
}  // 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

© 2026 Coveralls, Inc