Botan 3.14.1
Crypto and TLS for C&
Botan::ECIES_Encryptor Class Referencefinal

#include <ecies.h>

Inheritance diagram for Botan::ECIES_Encryptor:
Botan::PK_Encryptor

Public Member Functions

 ECIES_Encryptor (const PK_Key_Agreement_Key &private_key, const ECIES_System_Params &ecies_params, RandomNumberGenerator &rng)
 ECIES_Encryptor (RandomNumberGenerator &rng, const ECIES_System_Params &ecies_params)
std::vector< uint8_t > encrypt (const uint8_t in[], size_t length, RandomNumberGenerator &rng) const
std::vector< uint8_t > encrypt (std::span< const uint8_t > in, RandomNumberGenerator &rng) const
void set_initialization_vector (const InitializationVector &iv)
void set_label (std::string_view label)
 Set the label which is appended to the input for the message authentication code.
void set_other_key (const EC_AffinePoint &pt)
 Set the public key of the other party.

Detailed Description

ECIES Encryption according to ISO 18033-2

Warning
ECIES is a complicated and poorly specified scheme which, while standardized, in practice has significant interop difficulties. Prefer HPKE in new systems.

TODO(Botan4) remove derivation on PK_Encryptor and provide a direct API for encryption taking all relevant params, avoiding setters/implicit state

Definition at line 287 of file ecies.h.

Constructor & Destructor Documentation

◆ ECIES_Encryptor() [1/2]

Botan::ECIES_Encryptor::ECIES_Encryptor ( const PK_Key_Agreement_Key & private_key,
const ECIES_System_Params & ecies_params,
RandomNumberGenerator & rng )
Parameters
private_keythe (ephemeral) private key which is used for the key agreement
ecies_paramssettings for ecies
Random Number Generatorsrandom generator to use

Definition at line 289 of file ecies.cpp.

291 :
292 m_ka(private_key, ecies_params, true, rng),
293 m_params(ecies_params),
294 m_eph_public_key_bin(private_key.public_value()) {
295 if(ecies_params.point_format() != EC_Point_Format::Uncompressed) {
296 // ISO 18033: step d
297 // convert only if necessary; m_eph_public_key_bin has been initialized with the uncompressed format
298 m_eph_public_key_bin =
299 EC_AffinePoint(m_params.group(), m_eph_public_key_bin).serialize(ecies_params.point_format());
300 }
301 m_mac = m_params.create_mac();
302 m_cipher = m_params.create_cipher(Cipher_Dir::Encryption);
303}

References Botan::Encryption, Botan::ECIES_KA_Params::point_format(), and Botan::Uncompressed.

Referenced by ECIES_Encryptor().

◆ ECIES_Encryptor() [2/2]

Botan::ECIES_Encryptor::ECIES_Encryptor ( RandomNumberGenerator & rng,
const ECIES_System_Params & ecies_params )

Creates an ephemeral private key which is used for the key agreement

Parameters
Random Number Generatorsrandom generator used during private key generation
ecies_paramssettings for ecies

Definition at line 308 of file ecies.cpp.

308 :
309 ECIES_Encryptor(ECDH_PrivateKey(rng, ecies_params.group()), ecies_params, rng) {}
ECIES_Encryptor(const PK_Key_Agreement_Key &private_key, const ECIES_System_Params &ecies_params, RandomNumberGenerator &rng)
Definition ecies.cpp:289

References ECIES_Encryptor().

Member Function Documentation

◆ encrypt() [1/2]

std::vector< uint8_t > Botan::PK_Encryptor::encrypt ( const uint8_t in[],
size_t length,
RandomNumberGenerator & rng ) const
inlineinherited

Encrypt a message.

Parameters
inthe message as a byte array
lengththe length of the above byte array
Random Number Generatorsthe random number source to use
Returns
encrypted message

Definition at line 37 of file pubkey.h.

37 {
38 return enc(in, length, rng);
39 }

Referenced by Botan::TLS::Client_Key_Exchange::Client_Key_Exchange(), and Botan::KeyPair::encryption_consistency_check().

◆ encrypt() [2/2]

std::vector< uint8_t > Botan::PK_Encryptor::encrypt ( std::span< const uint8_t > in,
RandomNumberGenerator & rng ) const
inlineinherited

Encrypt a message.

Parameters
inthe message
Random Number Generatorsthe random number source to use
Returns
encrypted message

Definition at line 47 of file pubkey.h.

47 {
48 return enc(in.data(), in.size(), rng);
49 }

◆ set_initialization_vector()

void Botan::ECIES_Encryptor::set_initialization_vector ( const InitializationVector & iv)
inline

Set the initialization vector for the data encryption method

A new IV must be provided for each message; it is not included in the serialized ciphertext and must be conveyed separately

Warning
in ECIES the initialization vector is not authenticated. This has the effect that for non-AEAD uses it is possible to corrupt ciphertexts without detection. Workarounds for this include using an AEAD mode (such as GCM), or including the initialization vector as part of the "label" (associated data, which will be additionally authenticated). This limitation of ECIES is intrinsic to the specification and cannot be fixed by the library. Prefer HPKE in new designs.

Definition at line 328 of file ecies.h.

328{ m_iv = iv; }

◆ set_label()

void Botan::ECIES_Encryptor::set_label ( std::string_view label)
inline

Set the label which is appended to the input for the message authentication code.

Definition at line 331 of file ecies.h.

331{ m_label.assign(label.begin(), label.end()); }

◆ set_other_key()

void Botan::ECIES_Encryptor::set_other_key ( const EC_AffinePoint & pt)
inline

Set the public key of the other party.

Definition at line 313 of file ecies.h.

313{ m_other_point = pt; }

The documentation for this class was generated from the following files: