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

randombit / botan / 11844561993

14 Nov 2024 07:58PM UTC coverage: 91.178% (+0.1%) from 91.072%
11844561993

Pull #4435

github

web-flow
Merge 81dcb29da into e430f157a
Pull Request #4435: Test duration values ​​are now presented in seconds with six digits of precision. Tests without time measurements have been edited.

91856 of 100744 relevant lines covered (91.18%)

9311006.71 hits per line

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

94.23
/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
         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

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

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

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

83
         Test::Result result("Ed25519 CURDLE format");
1✔
84
         result.start_timer();
1✔
85

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

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

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

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

102
         result.end_timer();
1✔
103
         return std::vector<Test::Result>{result};
2✔
104
      }
7✔
105
};
106

107
class Ed25519_Keygen_Tests final : public PK_Key_Generation_Test {
×
108
   public:
109
      std::vector<std::string> keygen_params() const override { return {""}; }
1✔
110

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

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

120
BOTAN_REGISTER_TEST("pubkey", "ed25519_key_valid", Ed25519_Key_Validity_Tests);
121
BOTAN_REGISTER_TEST("pubkey", "ed25519_verify", Ed25519_Verification_Tests);
122
BOTAN_REGISTER_TEST("pubkey", "ed25519_sign", Ed25519_Signature_Tests);
123
BOTAN_REGISTER_TEST("pubkey", "ed25519_curdle", Ed25519_Curdle_Format_Tests);
124
BOTAN_REGISTER_TEST("pubkey", "ed25519_keygen", Ed25519_Keygen_Tests);
125

126
#endif
127

128
}  // namespace
129

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