Botan  2.8.0
Crypto and TLS for C++11
Public Member Functions | List of all members
Botan::ECIES_KA_Operation Class Reference

#include <ecies.h>

Public Member Functions

SymmetricKey derive_secret (const std::vector< uint8_t > &eph_public_key_bin, const PointGFp &other_public_key_point) const
 ECIES_KA_Operation (const PK_Key_Agreement_Key &private_key, const ECIES_KA_Params &ecies_params, bool for_encryption, RandomNumberGenerator &rng)

Detailed Description

ECIES secret derivation according to ISO 18033-2

Definition at line 184 of file ecies.h.

Constructor & Destructor Documentation

◆ ECIES_KA_Operation()

Botan::ECIES_KA_Operation::ECIES_KA_Operation ( const PK_Key_Agreement_Key private_key,
const ECIES_KA_Params ecies_params,
bool  for_encryption,
RandomNumberGenerator rng 
private_keythe (ephemeral) private key which is used to derive the secret
ecies_paramssettings for ecies
for_encryptiondisable cofactor mode if the secret will be used for encryption (according to ISO 18033 cofactor mode is only used during decryption)
rngthe RNG to use

Definition at line 134 of file ecies.cpp.

137  :
138  m_ka(create_key_agreement(private_key, ecies_params, for_encryption, rng)),
139  m_params(ecies_params)
140  {
141  }

Member Function Documentation

◆ derive_secret()

SymmetricKey Botan::ECIES_KA_Operation::derive_secret ( const std::vector< uint8_t > &  eph_public_key_bin,
const PointGFp other_public_key_point 
) const

Performs a key agreement with the provided keys and derives the secret from the result

eph_public_key_binthe encoded (ephemeral) public key which belongs to the used (ephemeral) private key
other_public_key_pointpublic key point of the other party

ECIES secret derivation according to ISO 18033-2

Definition at line 146 of file ecies.cpp.

References Botan::OctetString::begin(), Botan::BigInt::bytes(), Botan::ECIES_KA_Params::compression_type(), Botan::KDF::create_or_throw(), Botan::PK_Key_Agreement::derive_key(), Botan::ECIES_KA_Params::domain(), Botan::BigInt::encode(), Botan::OctetString::end(), Botan::EC_Group::get_cofactor(), Botan::EC_Group::get_order(), Botan::PointGFp::is_zero(), Botan::ECIES_KA_Params::kdf_spec(), Botan::ECIES_KA_Params::old_cofactor_mode(), Botan::ECIES_KA_Params::secret_length(), and Botan::ECIES_KA_Params::single_hash_mode().

148  {
149  if(other_public_key_point.is_zero())
150  {
151  throw Invalid_Argument("ECIES: other public key point is zero");
152  }
154  std::unique_ptr<KDF> kdf = Botan::KDF::create_or_throw(m_params.kdf_spec());
156  PointGFp other_point = other_public_key_point;
158  // ISO 18033: step b
159  if(m_params.old_cofactor_mode())
160  {
161  other_point *= m_params.domain().get_cofactor();
162  }
164  secure_vector<uint8_t> derivation_input;
166  // ISO 18033: encryption step e / decryption step g
167  if(!m_params.single_hash_mode())
168  {
169  derivation_input += eph_public_key_bin;
170  }
172  // ISO 18033: encryption step f / decryption step h
173  std::vector<uint8_t> other_public_key_bin = other_point.encode(m_params.compression_type());
174  // Note: the argument `m_params.secret_length()` passed for `key_len` will only be used by providers because
175  // "Raw" is passed to the `PK_Key_Agreement` if the implementation of botan is used.
176  const SymmetricKey peh = m_ka.derive_key(m_params.domain().get_order().bytes(),, other_public_key_bin.size());
177  derivation_input.insert(derivation_input.end(), peh.begin(), peh.end());
179  // ISO 18033: encryption step g / decryption step i
180  return kdf->derive_key(m_params.secret_length(), derivation_input);
181  }
const BigInt & get_order() const
Definition: ec_group.cpp:479
static std::vector< uint8_t > encode(const BigInt &n)
Definition: bigint.h:678
PointGFp::Compression_Type compression_type() const
Definition: ecies.h:104
const std::string & kdf_spec() const
Definition: ecies.h:109
bool single_hash_mode() const
Definition: ecies.h:84
const BigInt & get_cofactor() const
Definition: ec_group.cpp:494
SymmetricKey derive_key(size_t key_len, const uint8_t in[], size_t in_len, const uint8_t params[], size_t params_len) const
Definition: pubkey.cpp:218
OctetString SymmetricKey
Definition: symkey.h:136
size_t bytes() const
Definition: bigint.cpp:221
bool old_cofactor_mode() const
Definition: ecies.h:94
const EC_Group & domain() const
Definition: ecies.h:74
size_t secret_length() const
Definition: ecies.h:79
static std::unique_ptr< KDF > create_or_throw(const std::string &algo_spec, const std::string &provider="")
Definition: kdf.cpp:222

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