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

randombit / botan / 21753596263

06 Feb 2026 02:13PM UTC coverage: 90.063% (-0.01%) from 90.073%
21753596263

Pull #5289

github

web-flow
Merge 587099284 into 8ea0ca252
Pull Request #5289: Further misc header reductions, forward declarations, etc

102237 of 113517 relevant lines covered (90.06%)

11402137.11 hits per line

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

94.94
/src/tests/test_ecies.cpp
1
/*
2
* (C) 2016 Philipp Weber
3
* (C) 2016 Daniel Neus
4
*
5
* Botan is released under the Simplified BSD License (see license.txt)
6
*/
7

8
#include "tests.h"
9

10
#if defined(BOTAN_HAS_ECIES)
11
   #include <botan/ecdh.h>
12
   #include <botan/ecies.h>
13
   #include <botan/hex.h>
14
   #include <botan/rng.h>
15
#endif
16

17
namespace Botan_Tests {
18

19
namespace {
20

21
#if defined(BOTAN_HAS_ECIES) && defined(BOTAN_HAS_AES) && defined(BOTAN_HAS_MODE_CBC)
22

23
using Flags = Botan::ECIES_Flags;
24

25
Botan::EC_Point_Format get_compression_type(const std::string& format) {
13✔
26
   if(format == "uncompressed") {
13✔
27
      return Botan::EC_Point_Format::Uncompressed;
28
   } else if(format == "compressed") {
6✔
29
      return Botan::EC_Point_Format::Compressed;
30
   } else if(format == "hybrid") {
×
31
      return Botan::EC_Point_Format::Hybrid;
32
   }
33
   throw Botan::Invalid_Argument("invalid compression format");
×
34
}
35

36
Flags ecies_flags(bool cofactor_mode, bool old_cofactor_mode, bool check_mode, bool single_hash_mode) {
107✔
37
   return (cofactor_mode ? Flags::CofactorMode : Flags::None) |
107✔
38
          (single_hash_mode ? Flags::SingleHashMode : Flags::None) |
39
          (old_cofactor_mode ? Flags::OldCofactorMode : Flags::None) | (check_mode ? Flags::CheckMode : Flags::None);
214✔
40
}
41

42
void check_encrypt_decrypt(Test::Result& result,
60✔
43
                           const Botan::ECDH_PrivateKey& private_key,
44
                           const Botan::ECDH_PrivateKey& other_private_key,
45
                           const Botan::ECIES_System_Params& ecies_params,
46
                           const Botan::InitializationVector& iv,
47
                           const std::string& label,
48
                           const std::vector<uint8_t>& plaintext,
49
                           const std::vector<uint8_t>& ciphertext,
50
                           Botan::RandomNumberGenerator& rng) {
51
   try {
60✔
52
      Botan::ECIES_Encryptor ecies_enc(private_key, ecies_params, rng);
60✔
53
      ecies_enc.set_other_key(
120✔
54
         Botan::EC_AffinePoint(other_private_key.domain(), other_private_key.raw_public_key_bits()));
120✔
55
      Botan::ECIES_Decryptor ecies_dec(other_private_key, ecies_params, rng);
60✔
56
      if(!iv.bits_of().empty()) {
118✔
57
         ecies_enc.set_initialization_vector(iv);
58✔
58
         ecies_dec.set_initialization_vector(iv);
58✔
59
      }
60
      if(!label.empty()) {
60✔
61
         ecies_enc.set_label(label);
10✔
62
         ecies_dec.set_label(label);
10✔
63
      }
64

65
      const std::vector<uint8_t> encrypted = ecies_enc.encrypt(plaintext, rng);
60✔
66
      if(!ciphertext.empty()) {
60✔
67
         result.test_eq("encrypted data", encrypted, ciphertext);
24✔
68
      }
69
      const Botan::secure_vector<uint8_t> decrypted = ecies_dec.decrypt(encrypted);
60✔
70
      result.test_eq("decrypted data equals plaintext", decrypted, plaintext);
120✔
71

72
      std::vector<uint8_t> invalid_encrypted = encrypted;
60✔
73
      uint8_t& last_byte = invalid_encrypted[invalid_encrypted.size() - 1];
60✔
74
      last_byte = ~last_byte;
60✔
75
      result.test_throws("throw on invalid ciphertext",
180✔
76
                         [&ecies_dec, &invalid_encrypted] { ecies_dec.decrypt(invalid_encrypted); });
120✔
77
   } catch(Botan::Lookup_Error& e) {
180✔
78
      result.test_note(std::string("Test not executed: ") + e.what());
×
79
   }
×
80
}
60✔
81

82
[[maybe_unused]] void check_encrypt_decrypt(Test::Result& result,
48✔
83
                                            const Botan::ECDH_PrivateKey& private_key,
84
                                            const Botan::ECDH_PrivateKey& other_private_key,
85
                                            const Botan::ECIES_System_Params& ecies_params,
86
                                            size_t iv_length,
87
                                            Botan::RandomNumberGenerator& rng) {
88
   const std::vector<uint8_t> plaintext{1, 2, 3};
48✔
89
   check_encrypt_decrypt(result,
144✔
90
                         private_key,
91
                         other_private_key,
92
                         ecies_params,
93
                         Botan::InitializationVector(std::vector<uint8_t>(iv_length, 0)),
144✔
94
                         "",
95
                         plaintext,
96
                         std::vector<uint8_t>(),
48✔
97
                         rng);
98
}
48✔
99

100
   #if defined(BOTAN_HAS_KDF1_18033) && defined(BOTAN_HAS_SHA1)
101

102
class ECIES_ISO_Tests final : public Text_Based_Test {
×
103
   public:
104
      ECIES_ISO_Tests() : Text_Based_Test("pubkey/ecies-18033.vec", "format,p,a,b,Order,Gx,Gy,Oid,hx,hy,x,r,C0,K") {}
2✔
105

106
      bool clear_between_callbacks() const override { return false; }
2✔
107

108
      bool skip_this_test(const std::string& /*header*/, const VarMap& /*vars*/) override {
2✔
109
         return !Botan::EC_Group::supports_application_specific_group();
2✔
110
      }
111

112
      Test::Result run_one_test(const std::string& /*header*/, const VarMap& vars) override {
2✔
113
         Test::Result result("ECIES-ISO");
2✔
114

115
         // get test vectors defined by ISO 18033
116
         const Botan::EC_Point_Format compression_type = get_compression_type(vars.get_req_str("format"));
2✔
117
         const Botan::BigInt p = vars.get_req_bn("p");
2✔
118
         const Botan::BigInt a = vars.get_req_bn("a");
2✔
119
         const Botan::BigInt b = vars.get_req_bn("b");
2✔
120
         const Botan::BigInt order = vars.get_req_bn("Order");  // order
2✔
121
         const Botan::BigInt gx = vars.get_req_bn("Gx");        // base point x
2✔
122
         const Botan::BigInt gy = vars.get_req_bn("Gy");        // base point y
2✔
123
         const Botan::OID oid(vars.get_req_str("Oid"));
4✔
124
         const Botan::BigInt hx = vars.get_req_bn("hx");          // x of public point of bob
2✔
125
         const Botan::BigInt hy = vars.get_req_bn("hy");          // y of public point of bob
2✔
126
         const Botan::BigInt x = vars.get_req_bn("x");            // private key of bob
2✔
127
         const Botan::BigInt r = vars.get_req_bn("r");            // (ephemeral) private key of alice
2✔
128
         const std::vector<uint8_t> c0 = vars.get_req_bin("C0");  // expected encoded (ephemeral) public key
2✔
129
         const std::vector<uint8_t> k = vars.get_req_bin("K");    // expected derived secret
2✔
130

131
         const Botan::EC_Group domain(oid, p, a, b, gx, gy, order);
2✔
132

133
         // keys of bob
134
         const Botan::ECDH_PrivateKey other_private_key(this->rng(), domain, x);
2✔
135
         const auto other_public_key_point = Botan::EC_AffinePoint::from_bigint_xy(domain, hx, hy).value();
4✔
136
         const Botan::ECDH_PublicKey other_public_key(domain, other_public_key_point);
2✔
137

138
         // (ephemeral) keys of alice
139
         const Botan::ECDH_PrivateKey eph_private_key(this->rng(), domain, r);
2✔
140
         const auto eph_public_key_bin = eph_private_key.public_value(compression_type);
2✔
141
         result.test_eq("encoded (ephemeral) public key", eph_public_key_bin, c0);
4✔
142

143
         // test secret derivation: ISO 18033 test vectors use KDF1 from ISO 18033
144
         // no cofactor-/oldcofactor-/singlehash-/check-mode and 128 byte secret length
145
         const Botan::ECIES_KA_Params ka_params(
2✔
146
            eph_private_key.domain(), "KDF1-18033(SHA-1)", 128, compression_type, Flags::None);
2✔
147
         const Botan::ECIES_KA_Operation ka(eph_private_key, ka_params, true, this->rng());
2✔
148
         const Botan::SymmetricKey secret_key = ka.derive_secret(eph_public_key_bin, other_public_key_point);
2✔
149
         result.test_eq("derived secret key", secret_key.bits_of(), k);
4✔
150

151
         // test encryption / decryption
152

153
         // TODO(Botan4) clean this up after removing cofactor support
154

155
         for(auto comp_type : {Botan::EC_Point_Format::Uncompressed,
6✔
156
                               Botan::EC_Point_Format::Compressed,
157
                               Botan::EC_Point_Format::Hybrid}) {
8✔
158
            for(const bool cofactor_mode : {true, false}) {
18✔
159
               for(const bool single_hash_mode : {true, false}) {
36✔
160
                  for(const bool old_cofactor_mode : {true, false}) {
72✔
161
                     for(const bool check_mode : {true, false}) {
144✔
162
                        Flags flags = ecies_flags(cofactor_mode, old_cofactor_mode, check_mode, single_hash_mode);
96✔
163

164
                        if(size_t(cofactor_mode) + size_t(check_mode) + size_t(old_cofactor_mode) > 1) {
96✔
165
                           auto onThrow = [&]() {
96✔
166
                              Botan::ECIES_System_Params(eph_private_key.domain(),
48✔
167
                                                         "KDF2(SHA-1)",
168
                                                         "AES-256/CBC",
169
                                                         32,
170
                                                         "HMAC(SHA-1)",
171
                                                         20,
172
                                                         comp_type,
173
                                                         flags);
174
                           };
48✔
175
                           result.test_throws("throw on invalid ECIES_Flags", onThrow);
96✔
176
                           continue;
48✔
177
                        }
48✔
178

179
                        const Botan::ECIES_System_Params ecies_params(eph_private_key.domain(),
48✔
180
                                                                      "KDF2(SHA-1)",
181
                                                                      "AES-256/CBC",
182
                                                                      32,
183
                                                                      "HMAC(SHA-1)",
184
                                                                      20,
185
                                                                      comp_type,
186
                                                                      flags);
48✔
187
                        check_encrypt_decrypt(
48✔
188
                           result, eph_private_key, other_private_key, ecies_params, 16, this->rng());
189
                     }
48✔
190
                  }
191
               }
192
            }
193
         }
194

195
         return result;
4✔
196
      }
10✔
197
};
198

199
BOTAN_REGISTER_TEST("pubkey", "ecies_iso", ECIES_ISO_Tests);
200

201
   #endif
202

203
class ECIES_Tests final : public Text_Based_Test {
204
   public:
205
      ECIES_Tests() :
1✔
206
            Text_Based_Test("pubkey/ecies.vec",
207
                            "Curve,PrivateKey,OtherPrivateKey,Kdf,Dem,DemKeyLen,Mac,MacKeyLen,Format,"
208
                            "CofactorMode,OldCofactorMode,CheckMode,SingleHashMode,Label,Plaintext,Ciphertext",
209
                            "Iv") {
2✔
210
         // In order to test cofactor handling flags some of the tests use secp112r2 which has a cofactor of 4
211
         // TODO(Botan4) kill it with fire
212
         if(Botan::EC_Group::supports_application_specific_group_with_cofactor()) {
1✔
213
            auto p = Botan::BigInt::from_string("0xDB7C2ABF62E35E668076BEAD208B");
1✔
214
            auto a = Botan::BigInt::from_string("0x6127C24C05F38A0AAAF65C0EF02C");
1✔
215
            auto b = Botan::BigInt::from_string("0x51DEF1815DB5ED74FCC34C85D709");
1✔
216

217
            auto g_x = Botan::BigInt::from_string("0x4BA30AB5E892B4E1649DD0928643");
1✔
218
            auto g_y = Botan::BigInt::from_string("0xADCD46F5882E3747DEF36E956E97");
1✔
219
            auto order = Botan::BigInt::from_string("0x36DF0AAFD8B8D7597CA10520D04B");
1✔
220
            auto cofactor = Botan::BigInt::from_u64(4);
1✔
221
            m_secp112r2 = std::make_unique<Botan::EC_Group>(p, a, b, g_x, g_y, order, cofactor);
1✔
222
         }
1✔
223
      }
1✔
224

225
      bool skip_this_test(const std::string& /*header*/, const VarMap& vars) override {
12✔
226
         const auto curve = vars.get_req_str("Curve");
12✔
227

228
         // TODO(Botan4) remove this since cofactors no longer supported
229
         if(curve == "secp112r2") {
12✔
230
            return !Botan::EC_Group::supports_application_specific_group_with_cofactor();
4✔
231
         } else {
232
            return !Botan::EC_Group::supports_named_group(curve);
8✔
233
         }
234
      }
12✔
235

236
      Test::Result run_one_test(const std::string& /*header*/, const VarMap& vars) override {
11✔
237
         Test::Result result("ECIES");
11✔
238

239
         const std::string curve = vars.get_req_str("Curve");
11✔
240
         const Botan::BigInt private_key_value = vars.get_req_bn("PrivateKey");
11✔
241
         const Botan::BigInt other_private_key_value = vars.get_req_bn("OtherPrivateKey");
11✔
242
         const std::string kdf = vars.get_req_str("Kdf");
11✔
243
         const std::string dem = vars.get_req_str("Dem");
11✔
244
         const size_t dem_key_len = vars.get_req_sz("DemKeyLen");
11✔
245
         const Botan::InitializationVector iv = Botan::InitializationVector(vars.get_opt_bin("Iv"));
20✔
246
         const std::string mac = vars.get_req_str("Mac");
11✔
247
         const size_t mac_key_len = vars.get_req_sz("MacKeyLen");
11✔
248
         const Botan::EC_Point_Format compression_type = get_compression_type(vars.get_req_str("Format"));
11✔
249
         const bool cofactor_mode = vars.get_req_sz("CofactorMode") != 0;
11✔
250
         const bool old_cofactor_mode = vars.get_req_sz("OldCofactorMode") != 0;
11✔
251
         const bool check_mode = vars.get_req_sz("CheckMode") != 0;
11✔
252
         const bool single_hash_mode = vars.get_req_sz("SingleHashMode") != 0;
11✔
253
         const std::string label = vars.get_req_str("Label");
11✔
254
         const std::vector<uint8_t> plaintext = vars.get_req_bin("Plaintext");
11✔
255
         const std::vector<uint8_t> ciphertext = vars.get_req_bin("Ciphertext");
11✔
256

257
         const Flags flags = ecies_flags(cofactor_mode, old_cofactor_mode, check_mode, single_hash_mode);
11✔
258

259
         const auto group = [&]() {
×
260
            if(curve == "secp112r2") {
11✔
261
               return *m_secp112r2;
4✔
262
            } else {
263
               return Botan::EC_Group::from_name(curve);
7✔
264
            }
265
         }();
11✔
266

267
         const Botan::ECDH_PrivateKey private_key(this->rng(), group, private_key_value);
11✔
268
         const Botan::ECDH_PrivateKey other_private_key(this->rng(), group, other_private_key_value);
11✔
269

270
         const Botan::ECIES_System_Params ecies_params(
11✔
271
            private_key.domain(), kdf, dem, dem_key_len, mac, mac_key_len, compression_type, flags);
11✔
272
         check_encrypt_decrypt(
11✔
273
            result, private_key, other_private_key, ecies_params, iv, label, plaintext, ciphertext, this->rng());
274

275
         return result;
22✔
276
      }
42✔
277

278
   private:
279
      std::unique_ptr<Botan::EC_Group> m_secp112r2;
280
};
281

282
BOTAN_REGISTER_TEST("pubkey", "ecies", ECIES_Tests);
283

284
   #if defined(BOTAN_HAS_KDF1_18033) && defined(BOTAN_HAS_HMAC) && defined(BOTAN_HAS_AES) && defined(BOTAN_HAS_SHA2_64)
285

286
Test::Result test_other_key_not_set() {
1✔
287
   Test::Result result("ECIES other key not set");
1✔
288

289
   auto rng = Test::new_rng("ecies_other_key_not_set");
1✔
290

291
   const Flags flags = ecies_flags(false, false, false, true);
1✔
292
   const auto domain = Botan::EC_Group::from_name("secp521r1");
1✔
293

294
   const Botan::BigInt private_key_value(
1✔
295
      "405029866705438137604064977397053031159826489755682166267763407"
296
      "5002761777100287880684822948852132235484464537021197213998300006"
297
      "547176718172344447619746779823");
1✔
298

299
   const Botan::ECDH_PrivateKey private_key(*rng, domain, private_key_value);
1✔
300
   const Botan::ECIES_System_Params ecies_params(private_key.domain(),
1✔
301
                                                 "KDF1-18033(SHA-512)",
302
                                                 "AES-256/CBC",
303
                                                 32,
304
                                                 "HMAC(SHA-512)",
305
                                                 20,
306
                                                 Botan::EC_Point_Format::Compressed,
307
                                                 flags);
1✔
308

309
   Botan::ECIES_Encryptor ecies_enc(private_key, ecies_params, *rng);
1✔
310

311
   result.test_throws("encrypt not possible without setting other public key",
2✔
312
                      [&ecies_enc, &rng]() { ecies_enc.encrypt(std::vector<uint8_t>(8), *rng); });
2✔
313

314
   return result;
2✔
315
}
2✔
316

317
Test::Result test_kdf_not_found() {
1✔
318
   Test::Result result("ECIES kdf not found");
1✔
319

320
   auto rng = Test::new_rng("ecies_kdf_not_found");
1✔
321

322
   const Flags flags = ecies_flags(false, false, false, true);
1✔
323
   const auto domain = Botan::EC_Group::from_name("secp521r1");
1✔
324

325
   const Botan::BigInt private_key_value(
1✔
326
      "405029866705438137604064977397053031159826489755682166267763407"
327
      "5002761777100287880684822948852132235484464537021197213998300006"
328
      "547176718172344447619746779823");
1✔
329

330
   const Botan::ECDH_PrivateKey private_key(*rng, domain, private_key_value);
1✔
331
   const Botan::ECIES_System_Params ecies_params(private_key.domain(),
1✔
332
                                                 "KDF-XYZ(SHA-512)",
333
                                                 "AES-256/CBC",
334
                                                 32,
335
                                                 "HMAC(SHA-512)",
336
                                                 20,
337
                                                 Botan::EC_Point_Format::Compressed,
338
                                                 flags);
1✔
339

340
   result.test_throws("kdf not found", [&]() {
2✔
341
      const Botan::ECIES_Encryptor ecies_enc(private_key, ecies_params, *rng);
1✔
342
      ecies_enc.encrypt(std::vector<uint8_t>(8), *rng);
2✔
343
   });
1✔
344

345
   return result;
2✔
346
}
2✔
347

348
Test::Result test_mac_not_found() {
1✔
349
   Test::Result result("ECIES mac not found");
1✔
350

351
   auto rng = Test::new_rng("ecies_mac_not_found");
1✔
352

353
   const Flags flags = ecies_flags(false, false, false, true);
1✔
354
   const auto domain = Botan::EC_Group::from_name("secp521r1");
1✔
355

356
   const Botan::BigInt private_key_value(
1✔
357
      "405029866705438137604064977397053031159826489755682166267763407"
358
      "5002761777100287880684822948852132235484464537021197213998300006"
359
      "547176718172344447619746779823");
1✔
360

361
   const Botan::ECDH_PrivateKey private_key(*rng, domain, private_key_value);
1✔
362
   const Botan::ECIES_System_Params ecies_params(private_key.domain(),
1✔
363
                                                 "KDF1-18033(SHA-512)",
364
                                                 "AES-256/CBC",
365
                                                 32,
366
                                                 "XYZMAC(SHA-512)",
367
                                                 20,
368
                                                 Botan::EC_Point_Format::Compressed,
369
                                                 flags);
1✔
370

371
   result.test_throws("mac not found", [&]() {
2✔
372
      const Botan::ECIES_Encryptor ecies_enc(private_key, ecies_params, *rng);
1✔
373
      ecies_enc.encrypt(std::vector<uint8_t>(8), *rng);
×
374
   });
×
375

376
   return result;
2✔
377
}
2✔
378

379
Test::Result test_cipher_not_found() {
1✔
380
   Test::Result result("ECIES cipher not found");
1✔
381

382
   auto rng = Test::new_rng("ecies_cipher_not_found");
1✔
383

384
   const Flags flags = ecies_flags(false, false, false, true);
1✔
385
   const auto domain = Botan::EC_Group::from_name("secp521r1");
1✔
386

387
   const Botan::BigInt private_key_value(
1✔
388
      "405029866705438137604064977397053031159826489755682166267763407"
389
      "5002761777100287880684822948852132235484464537021197213998300006"
390
      "547176718172344447619746779823");
1✔
391

392
   const Botan::ECDH_PrivateKey private_key(*rng, domain, private_key_value);
1✔
393
   const Botan::ECIES_System_Params ecies_params(private_key.domain(),
1✔
394
                                                 "KDF1-18033(SHA-512)",
395
                                                 "AES-XYZ-256/CBC",
396
                                                 32,
397
                                                 "HMAC(SHA-512)",
398
                                                 20,
399
                                                 Botan::EC_Point_Format::Compressed,
400
                                                 flags);
1✔
401

402
   result.test_throws("cipher not found", [&]() {
2✔
403
      const Botan::ECIES_Encryptor ecies_enc(private_key, ecies_params, *rng);
1✔
404
      ecies_enc.encrypt(std::vector<uint8_t>(8), *rng);
×
405
   });
×
406

407
   return result;
2✔
408
}
2✔
409

410
Test::Result test_system_params_short_ctor() {
1✔
411
   Test::Result result("ECIES short system params ctor");
1✔
412

413
   auto rng = Test::new_rng("ecies_params_short_ctor");
1✔
414

415
   const auto domain = Botan::EC_Group::from_name("secp521r1");
1✔
416
   const Botan::BigInt private_key_value(
1✔
417
      "405029866705438137604064977397053031159826489755682166267763407"
418
      "5002761777100287880684822948852132235484464537021197213998300006"
419
      "547176718172344447619746779823");
1✔
420

421
   const Botan::BigInt other_private_key_value(
1✔
422
      "2294226772740614508941417891614236736606752960073669253551166842"
423
      "5866095315090327914760325168219669828915074071456176066304457448"
424
      "25404691681749451640151380153");
1✔
425

426
   const Botan::ECDH_PrivateKey private_key(*rng, domain, private_key_value);
1✔
427
   const Botan::ECDH_PrivateKey other_private_key(*rng, domain, other_private_key_value);
1✔
428

429
   const Botan::ECIES_System_Params ecies_params(
1✔
430
      private_key.domain(), "KDF1-18033(SHA-512)", "AES-256/CBC", 32, "HMAC(SHA-512)", 16);
1✔
431

432
   const Botan::InitializationVector iv("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF");
1✔
433
   const std::string label = "Test";
1✔
434

435
   const std::vector<uint8_t> plaintext = Botan::hex_decode("000102030405060708090A0B0C0D0E0F");
1✔
436

437
   // generated with botan
438
   const std::vector<uint8_t> ciphertext = Botan::hex_decode(
1✔
439
      "0401519EAA0489FF9D51E98E4C22349463E2001CD06F8CE47D81D4007A"
440
      "79ACF98E92C814686477CEA666EFC277DC84E15FC95E38AFF8E16D478A"
441
      "44CD5C5F1517F8B1F300000591317F261C3D04A7207F01EAE3EC70F2360"
442
      "0F82C53CC0B85BE7AC9F6CE79EF2AB416E5934D61BA9D346385D7545C57F"
443
      "77C7EA7C58E18C70CBFB0A24AE1B9943EC5A8D0657522CCDF30BA95674D81"
444
      "B397635D215178CD13BD9504AE957A9888F4128FFC0F0D3F1CEC646AEC8CE"
445
      "3F2463D233B22A7A12B679F4C06501F584D4DEFF6D26592A8D873398BD892"
446
      "B477B3468813C053DA43C4F3D49009F7A12D6EF7");
1✔
447

448
   check_encrypt_decrypt(result, private_key, other_private_key, ecies_params, iv, label, plaintext, ciphertext, *rng);
1✔
449

450
   return result;
1✔
451
}
4✔
452

453
Test::Result test_ciphertext_too_short() {
1✔
454
   Test::Result result("ECIES ciphertext too short");
1✔
455

456
   const auto domain = Botan::EC_Group::from_name("secp521r1");
1✔
457
   const Botan::BigInt private_key_value(
1✔
458
      "405029866705438137604064977397053031159826489755682166267763407"
459
      "5002761777100287880684822948852132235484464537021197213998300006"
460
      "547176718172344447619746779823");
1✔
461

462
   const Botan::BigInt other_private_key_value(
1✔
463
      "2294226772740614508941417891614236736606752960073669253551166842"
464
      "5866095315090327914760325168219669828915074071456176066304457448"
465
      "25404691681749451640151380153");
1✔
466

467
   auto rng = Test::new_rng("ecies_ciphertext_too_short");
1✔
468

469
   const Botan::ECDH_PrivateKey private_key(*rng, domain, private_key_value);
1✔
470
   const Botan::ECDH_PrivateKey other_private_key(*rng, domain, other_private_key_value);
1✔
471

472
   const Botan::ECIES_System_Params ecies_params(
1✔
473
      private_key.domain(), "KDF1-18033(SHA-512)", "AES-256/CBC", 32, "HMAC(SHA-512)", 16);
1✔
474

475
   Botan::ECIES_Decryptor ecies_dec(other_private_key, ecies_params, *rng);
1✔
476

477
   result.test_throws("ciphertext too short",
2✔
478
                      [&ecies_dec]() { ecies_dec.decrypt(Botan::hex_decode("0401519EAA0489FF9D51E98E4C22349A")); });
2✔
479

480
   return result;
1✔
481
}
2✔
482

483
class ECIES_Unit_Tests final : public Test {
1✔
484
   public:
485
      std::vector<Test::Result> run() override {
1✔
486
         std::vector<Test::Result> results;
1✔
487

488
         std::vector<std::function<Test::Result()>> fns = {test_other_key_not_set,
1✔
489
                                                           test_kdf_not_found,
490
                                                           test_mac_not_found,
491
                                                           test_cipher_not_found,
492
                                                           test_system_params_short_ctor,
493
                                                           test_ciphertext_too_short};
7✔
494

495
         for(size_t i = 0; i != fns.size(); ++i) {
7✔
496
            try {
6✔
497
               results.emplace_back(fns[i]());
12✔
498
            } catch(std::exception& e) {
×
499
               results.emplace_back(Test::Result::Failure("ECIES unit tests " + std::to_string(i), e.what()));
×
500
            }
×
501
         }
502

503
         return results;
1✔
504
      }
2✔
505
};
506

507
BOTAN_REGISTER_TEST("pubkey", "ecies_unit", ECIES_Unit_Tests);
508

509
   #endif
510

511
#endif
512

513
}  // namespace
514

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