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

randombit / botan / 5123321399

30 May 2023 04:06PM UTC coverage: 92.213% (+0.004%) from 92.209%
5123321399

Pull #3558

github

web-flow
Merge dd72f7389 into 057bcbc35
Pull Request #3558: Add braces around all if/else statements

75602 of 81986 relevant lines covered (92.21%)

11859779.3 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

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

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

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

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

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

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

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

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

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

118
#endif
119

120
}  // namespace
121

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