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

randombit / botan / 21747534840

06 Feb 2026 10:36AM UTC coverage: 91.639% (+1.6%) from 90.073%
21747534840

push

github

web-flow
Merge pull request #5284 from randombit/jack/rng-no-chrono

Avoid <chrono> in rng.h

104013 of 113503 relevant lines covered (91.64%)

11308702.41 hits per line

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

95.83
/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
   #include <algorithm>
18

19
namespace Botan_Tests {
20
namespace {
21

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

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

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

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

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

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

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

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

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

58
         return sk;
19✔
59
      }
76✔
60

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

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

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

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

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

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

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

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

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

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

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

107
         return result;
19✔
108
      }
×
109

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

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

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

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

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

144
         return result;
1✔
145
      }
1✔
146

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

151
}  // namespace
152

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

159
}  // namespace Botan_Tests
160

161
#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