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

randombit / botan / 20579846577

29 Dec 2025 06:24PM UTC coverage: 90.415% (+0.2%) from 90.243%
20579846577

push

github

web-flow
Merge pull request #5167 from randombit/jack/src-size-reductions

Changes to reduce unnecessary inclusions

101523 of 112285 relevant lines covered (90.42%)

12817276.56 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/rng.h>
14
#endif
15

16
namespace Botan_Tests {
17

18
namespace {
19

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

22
using Flags = Botan::ECIES_Flags;
23

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

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

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

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

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

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

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

101
class ECIES_ISO_Tests final : public Text_Based_Test {
×
102
   public:
103
      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✔
104

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

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

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

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

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

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

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

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

150
         // test encryption / decryption
151

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

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

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

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

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

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

200
   #endif
201

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

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

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

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

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

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

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

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

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

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

274
         return result;
22✔
275
      }
42✔
276

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

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

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

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

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

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

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

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

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

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

313
   return result;
2✔
314
}
2✔
315

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

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

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

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

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

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

344
   return result;
2✔
345
}
2✔
346

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

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

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

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

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

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

375
   return result;
2✔
376
}
2✔
377

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

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

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

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

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

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

406
   return result;
2✔
407
}
2✔
408

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

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

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

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

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

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

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

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

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

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

449
   return result;
1✔
450
}
4✔
451

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

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

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

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

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

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

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

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

479
   return result;
1✔
480
}
2✔
481

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

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

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

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

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

508
   #endif
509

510
#endif
511

512
}  // namespace
513

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