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

randombit / botan / 16581714815

28 Jul 2025 10:25PM UTC coverage: 90.475% (-0.2%) from 90.685%
16581714815

Pull #5021

github

web-flow
Merge 072983077 into 1eacc5b05
Pull Request #5021: Add PK_Signature_Options

99366 of 109827 relevant lines covered (90.48%)

12349417.34 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
   #include <botan/internal/pk_options.h>
16
#endif
17

18
namespace Botan_Tests {
19

20
namespace {
21

22
#if defined(BOTAN_HAS_ED25519)
23

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

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

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

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

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

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

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

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

58
         auto key = std::make_unique<Botan::Ed25519_PrivateKey>(Botan::Ed25519_PrivateKey::from_seed(privkey));
1,422✔
59

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

64
         return key;
711✔
65
      }
2,133✔
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, this->rng(), Botan::PK_Signature_Options());
1✔
93
         signer.update("message");
1✔
94
         std::vector<uint8_t> sig = signer.signature(this->rng());
1✔
95

96
         Botan::PK_Verifier verifier(*pub_key, Botan::PK_Signature_Options());
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
      }
6✔
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 {""}; }
1✔
107

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

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

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

123
#endif
124

125
}  // namespace
126

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