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

randombit / botan / 16265592430

14 Jul 2025 11:26AM UTC coverage: 90.624% (-0.001%) from 90.625%
16265592430

push

github

web-flow
Merge pull request #4989 from randombit/jack/fix-more-named-parameters

Fix more readability-named-parameter warnings from clang-tidy

99627 of 109934 relevant lines covered (90.62%)

12300021.1 hits per line

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

93.06
/src/tests/test_ed448.cpp
1
/*
2
 * Ed448 Signature Algorithm Tests
3
 * (C) 2024 Jack Lloyd
4
 *     2024 Fabian Albert - Rohde & Schwarz Cybersecurity
5
 *
6
 * Botan is released under the Simplified BSD License (see license.txt)
7
 */
8

9
#include "tests.h"
10

11
#if defined(BOTAN_HAS_ED448)
12
   #include "test_pubkey.h"
13
   #include <botan/bigint.h>
14
   #include <botan/ed448.h>
15
   #include <botan/internal/curve448_scalar.h>
16
   #include <botan/internal/ed448_internal.h>
17

18
namespace Botan_Tests {
19
namespace {
20

21
class Ed448_Keygen_Tests final : public PK_Key_Generation_Test {
×
22
   public:
23
      std::vector<std::string> keygen_params() const override {
1✔
24
         // Test without prehash and Ed448ph with default (SHAKE256(64)) and
25
         // a custom hash function (SHAKE256(72))
26
         return {"", "Ed448ph", "SHAKE-256(72)"};
1✔
27
      }
28

29
      std::string algo_name() const override { return "Ed448"; }
3✔
30

31
      std::unique_ptr<Botan::Public_Key> public_key_from_raw(std::string_view /* keygen_params */,
3✔
32
                                                             std::string_view /* provider */,
33
                                                             std::span<const uint8_t> raw_pk) const override {
34
         return std::make_unique<Botan::Ed448_PublicKey>(raw_pk);
3✔
35
      }
36
};
37

38
class Ed448_Signature_Tests final : public PK_Signature_Generation_Test {
39
   public:
40
      Ed448_Signature_Tests() :
1✔
41
            PK_Signature_Generation_Test("Ed448", "pubkey/ed448.vec", "Msg,PrivateKey,PublicKey,Valid,Signature") {}
2✔
42

43
      bool clear_between_callbacks() const override { return false; }
19✔
44

45
      std::unique_ptr<Botan::Private_Key> load_private_key(const VarMap& vars) override {
19✔
46
         const std::vector<uint8_t> privkey = vars.get_req_bin("PrivateKey");
19✔
47
         const std::vector<uint8_t> pubkey = vars.get_req_bin("PublicKey");
19✔
48

49
         const Botan::secure_vector<uint8_t> seed(privkey.begin(), privkey.end());
19✔
50

51
         auto sk = std::make_unique<Botan::Ed448_PrivateKey>(seed);
19✔
52

53
         if(sk->public_key_bits() != pubkey) {
38✔
54
            throw Test_Error("Invalid Ed448 key in test data");
×
55
         }
56

57
         return sk;
19✔
58
      }
76✔
59

60
      bool skip_this_test(const std::string& /*header*/, const VarMap& vars) override {
88✔
61
         return vars.get_req_sz("Valid") != 1;
88✔
62
      }
63
};
64

65
class Ed448_Verification_Tests : public PK_Signature_Verification_Test {
66
   public:
67
      Ed448_Verification_Tests() :
1✔
68
            PK_Signature_Verification_Test("Ed448", "pubkey/ed448.vec", "Msg,PrivateKey,PublicKey,Valid,Signature") {}
2✔
69

70
      std::unique_ptr<Botan::Public_Key> load_public_key(const VarMap& vars) override {
88✔
71
         const std::vector<uint8_t> pk = vars.get_req_bin("PublicKey");
88✔
72
         return std::make_unique<Botan::Ed448_PublicKey>(pk);
176✔
73
      }
88✔
74
};
75

76
class Ed448_General_Test final : public Text_Based_Test {
×
77
   private:
78
      template <size_t S>
79
      std::array<uint8_t, S> to_array(std::span<const uint8_t> sp) {
38✔
80
         BOTAN_ASSERT_NOMSG(sp.size() == S);
38✔
81
         std::array<uint8_t, S> arr{};
38✔
82
         Botan::copy_mem(arr.data(), sp.data(), S);
38✔
83
         return arr;
38✔
84
      }
85

86
   public:
87
      Ed448_General_Test() : Text_Based_Test("pubkey/ed448.vec", "Msg,PrivateKey,PublicKey,Valid,Signature") {}
2✔
88

89
      Test::Result run_one_test(const std::string& /*header*/, const VarMap& vars) final {
19✔
90
         Test::Result result("Ed448 general tests");
19✔
91

92
         const auto pub_key_ref = to_array<57>(vars.get_req_bin("PublicKey"));
38✔
93
         const auto sk = to_array<57>(vars.get_req_bin("PrivateKey"));
38✔
94

95
         // Test encoding and decoding
96
         const auto p = Botan::Ed448Point::decode(pub_key_ref);
19✔
97
         const auto reencoded_point_data = p.encode();
19✔
98

99
         result.test_is_eq("Enc- and decoding roundtrip", reencoded_point_data, pub_key_ref);
19✔
100

101
         // Test public key creation
102
         const auto pub_key = Botan::create_pk_from_sk(sk);
19✔
103

104
         result.test_is_eq("Public key from secret key", pub_key, pub_key_ref);
19✔
105

106
         return result;
19✔
107
      }
×
108

109
      bool skip_this_test(const std::string& /*header*/, const VarMap& vars) override {
88✔
110
         return vars.get_req_sz("Valid") != 1;
88✔
111
      }
112
};
113

114
class Ed448_Utils_Test final : public Test {
×
115
   private:
116
      std::array<uint8_t, 56> reduce_mod_L_ref(std::span<const uint8_t> t) {
3✔
117
         const std::vector<uint8_t> t_bytes(t.rbegin(), t.rend());
3✔
118
         const Botan::BigInt t_int(t_bytes.data(), t_bytes.size());
3✔
119
         const BigInt L(
3✔
120
            "0x3fffffffffffffffffffffffffffffffffffffffffffffffffffffff7cca23e9c44edb49aed63690216cc2728dc58f552378c292ab5844f3");
3✔
121
         const auto res = t_int % L;
3✔
122
         std::array<uint8_t, 56> res_bytes = {0};
3✔
123
         res.serialize_to(res_bytes);
3✔
124
         std::reverse(res_bytes.begin(), res_bytes.end());
3✔
125
         return res_bytes;
6✔
126
      }
6✔
127

128
      Test::Result test_reduce_mod_L() {
1✔
129
         Test::Result result("Reduce mod L test");
1✔
130
         std::array<uint8_t, 114> full = {0};
1✔
131
         std::memset(full.data(), 0xff, full.size());
1✔
132

133
         const std::vector<std::array<uint8_t, 114>> test_vectors = {
1✔
134
            full, std::array<uint8_t, 114>{0x42}, std::array<uint8_t, 114>{0}};
1✔
135

136
         for(const auto& t : test_vectors) {
4✔
137
            const auto ref = reduce_mod_L_ref(t);
3✔
138
            std::array<uint8_t, 56> res{};
3✔
139
            result.test_no_throw("Reduce mod L does not throw", [&] { res = Botan::Scalar448(t).to_bytes<56>(); });
9✔
140
            result.test_is_eq("Reduce mod L result", res, ref);
6✔
141
         }
142

143
         return result;
1✔
144
      }
1✔
145

146
   public:
147
      std::vector<Test::Result> run() override { return {test_reduce_mod_L()}; }
2✔
148
};
149

150
}  // namespace
151

152
BOTAN_REGISTER_TEST("ed448", "ed448_keygen", Ed448_Keygen_Tests);
153
BOTAN_REGISTER_TEST("ed448", "ed448_sign", Ed448_Signature_Tests);
154
BOTAN_REGISTER_TEST("ed448", "ed448_verify", Ed448_Verification_Tests);
155
BOTAN_REGISTER_TEST("ed448", "ed448_general", Ed448_General_Test);
156
BOTAN_REGISTER_TEST("ed448", "ed448_utils", Ed448_Utils_Test);
157

158
}  // namespace Botan_Tests
159

160
#endif
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