security_ecc Class Reference

This class implements the generation of a key pair private/public. More...

`#include <security_ecc.hh>`

## Public Member Functions

| security_ecc (const ec_elliptic_curves p_elliptic_curve)
| Default constructor. More...
| security_ecc (const ec_elliptic_curves p_elliptic_curve, const std::vector< unsigned char > &p_private_key)
| Constructor based on the private key only. More...
| security_ecc (const ec_elliptic_curves p_elliptic_curve, const std::vector< unsigned char > &p_public_key_x, const std::vector< unsigned char > &p_public_key_y)
| Constructor based on the public keys only. More...
virtual | ~security_ecc ()
| Destructor. More...
int | generate ()
| Generate a pair (PrivateK, PublicK) of keys for signature or encryption. More...
int | sign (const std::vector< unsigned char > &p_data, std::vector< unsigned char > &p_r_sig, std::vector< unsigned char > &p_s_sig)
| Signed the data using ECDSA algorithm. More...
int | sign_verif (const std::vector< unsigned char > &p_data, const std::vector< unsigned char > &p_signature)
| Verifiy an ECDSA signature. More...
int | generate_and_derive_ephemeral_key (const encryption_algotithm p_enc_algorithm, const std::vector< unsigned char > &p_recipients_public_key_x, const std::vector< unsigned char > &p_recipients_public_key_y)
| Generate a shared secret key and derive it using KDF2 algorithm. This method shall be used by the sender. Fresh keys will be genrated for each cyphering operation. More...

int

generate_and_derive_ephemeral_key (const encryption_algotithm p_enc_algorithm, const std::vector< unsigned char > &p_private_enc_key, const std::vector< unsigned char > &p_ephemeral_public_key_x, const std::vector< unsigned char > &p_ephemeral_public_key_y, const std::vector< unsigned char > &p_enc_sym_key, const std::vector< unsigned char > &p_expected_nonce, const std::vector< unsigned char > &p_authentication_vector)

int | encrypt (const encryption_algotithm p_enc_algorithm, const std::vector< unsigned char > &p_message, std::vector< unsigned char > &p_enc_message)
| Encryption using the specified algorithm, the encryption parameters are generated automatically. More...
int | encrypt (const encryption_algotithm p_enc_algorithm, const std::vector< unsigned char > &p_symmetric_key, const std::vector< unsigned char > &p_nonce, const std::vector< unsigned char > &p_message, std::vector< unsigned char > &p_enc_message)
| Encryption using the specified algorithm. The encryption parameters are provided by the caller (e.g. ECIES encryption). More...
int | decrypt (const encryption_algotithm p_enc_algorithm, const std::vector< unsigned char > &p_symmetric_key, const std::vector< unsigned char > &p_nonce, const std::vector< unsigned char > &p_tag, const std::vector< unsigned char > &p_enc_message, std::vector< unsigned char > &p_message)
| Decryption using the specified parameters. More...
int | decrypt (const std::vector< unsigned char > &p_tag, const std::vector< unsigned char > &p_enc_message, std::vector< unsigned char > &p_message)
const std::vector< unsigned char > & | private_key () const
const std::vector< unsigned char > & | public_key_x () const
const std::vector< unsigned char > & | public_key_y () const
const std::vector< unsigned char > & | secret_key () const
const std::vector< unsigned char > & | encryption_key_x () const
const std::vector< unsigned char > & | encryption_key_y () const
const std::vector< unsigned char > & | encrypted_symmetric_key () const
const std::vector< unsigned char > & | symmetric_encryption_key () const
const std::vector< unsigned char > & | nonce () const
const std::vector< unsigned char > & | tag () const

## Private Member Functions

const int | init ()
| Called by the constructors to set up encryption environment. More...
int | bin_to_ec_point (const std::vector< unsigned char > &p_public_key_x, const std::vector< unsigned char > &p_public_key_y, EC_POINT **p_ec_point)
| Convert a big number object into a public key. More...
int | public_key_to_bin (std::vector< unsigned char > &p_bin_key)
| Convert a public key into a big number object. More...

## Private Attributes

ec_elliptic_curves | _elliptic_curve
encryption_algotithm | _encryption_algotithm
EC_KEY * | _ec_key
const EC_GROUP * | _ec_group
BN_CTX * | _bn_ctx
std::vector< unsigned char > | _pri_key
std::vector< unsigned char > | _pub_key_x
std::vector< unsigned char > | _pub_key_y
std::vector< unsigned char > | _secret_key
std::vector< unsigned char > | _enc_key_x
std::vector< unsigned char > | _enc_key_y
std::vector< unsigned char > | _sym_key
std::vector< unsigned char > | _enc_sym_key
std::vector< unsigned char > | _nonce
std::vector< unsigned char > | _tag

## Detailed Description

This class implements the generation of a key pair private/public.

## Constructor & Destructor Documentation

## security_ecc() [1/3]

security_ecc::security_ecc | ( | const ec_elliptic_curves | p_elliptic_curve | ) |

Default constructor.

Parameters

  [in] | p_elliptic_curve | The ECDSA curve family to be used

Remarks
  Call the method security_ecc::generate() to initialise the private/public key pair

## security_ecc() [2/3]

security_ecc::security_ecc | ( | const ec_elliptic_curves | p_elliptic_curve,
|  | const std::vector< unsigned char > & | p_private_key
| ) |  |

Constructor based on the private key only.

Parameters

  [in] | p_elliptic_curve | The ECDSA curve family to be used
  [in] | p_private_key | The private key

Remarks
  Some public key are created based on the provided private keys

## security_ecc() [3/3]

security_ecc::security_ecc | ( | const ec_elliptic_curves | p_elliptic_curve,
|  | const std::vector< unsigned char > & | p_public_key_x,
|  | const std::vector< unsigned char > & | p_public_key_y
| ) |  |

Constructor based on the public keys only.

Parameters

  [in] | p_elliptic_curve | The ECDSA curve family to be used

Remarks
  The call to the method security_ecc::sign() will failed
  The call to the method security_ecc::generate() will overwrite the provided public keys

## ~security_ecc()

security_ecc::~security_ecc | ( |  | ) |

virtual

Destructor.

## Member Function Documentation

## bin_to_ec_point()

int security_ecc::bin_to_ec_point | ( | const std::vector< unsigned char > & | p_public_key_x,
|  | const std::vector< unsigned char > & | p_public_key_y,
|  | EC_POINT ** | p_ec_point
| ) |  |

private

Convert a big number object into a public key.

Returns
  0 on success, -1 otherwise

## decrypt() [1/2]

int security_ecc::decrypt | ( | const encryption_algotithm | p_enc_algorithm,
|  | const std::vector< unsigned char > & | p_key,
|  | const std::vector< unsigned char > & | p_nonce,
|  | const std::vector< unsigned char > & | p_tag,
|  | const std::vector< unsigned char > & | p_enc_message,
|  | std::vector< unsigned char > & | p_message
| ) |  |

Decryption using the specified parameters.

Decryption using default parameters.

Parameters

  [in] | p_enc_algorithm | The algorithm to use for the decryption
  [in] | p_nonce | The algorithm to use for the encryption
  [in] | p_tag | The algorithm to use for the encryption
  [in] | p_enc_message | The message to be decrypted
  [out] | p_message | The decrypted message

Remarks
  To get the generated symmetric encryption key, uses

See also
  symmetric_encryption_key method

Remarks
  To get the generated nonce vector, uses

See also
  nonce method

Remarks
  To get the generated tag, uses

See also
  tag method

Returns
  0 on success, -1 otherwise

Parameters

  [in] | p_tag | The algorithm to use for the encryption
  [in] | p_enc_message | The message to be decrypted
  [out] | p_message | The decrypted message

Remarks
  To get the generated symmetric encryption key, uses

See also
  symmetric_encryption_key method

Remarks
  To get the generated nonce vector, uses

See also
  nonce method

Remarks
  To get the generated tag, uses

See also
  tag method

Returns
  0 on success, -1 otherwise

## decrypt() [2/2]

int security_ecc::decrypt | ( | const std::vector< unsigned char > & | p_tag,
|  | const std::vector< unsigned char > & | p_enc_message,
|  | std::vector< unsigned char > & | p_message
| ) |  |

## encrypt() [1/2]

int security_ecc::encrypt | ( | const encryption_algotithm | p_enc_algorithm,
|  | const std::vector< unsigned char > & | p_message,
|  | std::vector< unsigned char > & | p_enc_message
| ) |  |

Encryption using the specified algorithm, the encryption parameters are generated automatically.

Parameters

  [in] | p_enc_algorithm | The algorithm to use for the encryption
  [in] | p_message | The message to be encrypted
  [out] | p_enc_message | The encrypted message

Remarks
  To get the generated symmetric encryption key, uses

See also
  symmetric_encryption_key method

Remarks
  To get the generated nonce vector, uses

See also
  nonce method

Remarks
  To get the generated tag, uses

See also
  tag method

Returns
  0 on success, -1 otherwise

## encrypt() [2/2]

int security_ecc::encrypt | ( | const encryption_algotithm | p_enc_algorithm,
|  | const std::vector< unsigned char > & | p_symmetric_key,
|  | const std::vector< unsigned char > & | p_nonce,
|  | const std::vector< unsigned char > & | p_message,
|  | std::vector< unsigned char > & | p_enc_message
| ) |  |

Encryption using the specified algorithm. The encryption parameters are provided by the caller (e.g. ECIES encryption).

Parameters

  [in] | p_enc_algorithm | The algorithm to use for the encryption
  [in] | p_symmetric_key |
  [in] | p_nonce |
  [in] | p_message | The message to be encrypted
  [out] | p_enc_message | The encrypted message

Remarks
  To get the generated symmetric encryption key, uses

See also
  symmetric_encryption_key method

Remarks
  To get the generated nonce vector, uses

See also
  nonce method

Remarks
  To get the generated tag, uses

See also
  tag method

Returns
  0 on success, -1 otherwise

## encrypted_symmetric_key()

const std::vector<unsigned char>& security_ecc::encrypted_symmetric_key | ( |  | ) | const

inline

## encryption_key_x()

const std::vector<unsigned char>& security_ecc::encryption_key_x | ( |  | ) | const

inline

## encryption_key_y()

const std::vector<unsigned char>& security_ecc::encryption_key_y | ( |  | ) | const

inline

## generate()

int security_ecc::generate | ( |  | ) |

Generate a pair (PrivateK, PublicK) of keys for signature or encryption.

Returns
  0 on success, -1 otherwise

Remarks
  To get the generated keys,

See also
  private_key, public_key_x and public_key_y methods

## generate_and_derive_ephemeral_key() [1/2]

int security_ecc::generate_and_derive_ephemeral_key | ( | const encryption_algotithm | p_enc_algorithm,
|  | const std::vector< unsigned char > & | p_recipients_public_key_x,
|  | const std::vector< unsigned char > & | p_recipients_public_key_y
| ) |  |

Generate a shared secret key and derive it using KDF2 algorithm. This method shall be used by the sender. Fresh keys will be genrated for each cyphering operation.

Parameters

  [in] | p_enc_algorithm | The encryption algorithm to be used
  [in] | p_recipients_public_key_x | The recipient public key X-coordinate
  [in] | p_recipients_public_key_x | The recipient public key Y-coordinate

Remarks
  To get the secret key, uses

See also
  secret_key method

Remarks
  To get the generated symmetric encryption key, uses

See also
  symmetric_encryption_key method

Remarks
  To get the generated nonce vector, uses

See also
  nonce method
  encrypt methog to encrypt a message based of the generated symetric encryption key

Returns
  0 on success, -1 otherwise

## generate_and_derive_ephemeral_key() [2/2]

int security_ecc::generate_and_derive_ephemeral_key | ( | const encryption_algotithm | p_enc_algorithm,
|  | const std::vector< unsigned char > & | p_private_enc_key,
|  | const std::vector< unsigned char > & | p_ephemeral_public_key_x,
|  | const std::vector< unsigned char > & | p_ephemeral_public_key_y,
|  | const std::vector< unsigned char > & | p_enc_sym_key,
|  | const std::vector< unsigned char > & | p_expected_nonce,
|  | const std::vector< unsigned char > & | p_authentication_vector
| ) |  |

## init()

const int security_ecc::init | ( |  | ) |

private

Called by the constructors to set up encryption environment.

Returns
  0 on success, -1 otherwise

## nonce()

const std::vector<unsigned char>& security_ecc::nonce | ( |  | ) | const

inline

## private_key()

const std::vector<unsigned char>& security_ecc::private_key | ( |  | ) | const

inline

## public_key_to_bin()

int security_ecc::public_key_to_bin | ( | std::vector< unsigned char > & | p_bin_key | ) |

private

Convert a public key into a big number object.

Returns
  0 on success, -1 otherwise

## public_key_x()

const std::vector<unsigned char>& security_ecc::public_key_x | ( |  | ) | const

inline

## public_key_y()

const std::vector<unsigned char>& security_ecc::public_key_y | ( |  | ) | const

inline

## secret_key()

const std::vector<unsigned char>& security_ecc::secret_key | ( |  | ) | const

inline

## sign()

int security_ecc::sign | ( | const std::vector< unsigned char > & | p_data,
|  | std::vector< unsigned char > & | p_r_sig,
|  | std::vector< unsigned char > & | p_s_sig
| ) |  |

Signed the data using ECDSA algorithm.

Parameters

  [in] | p_data | The data to be signed
  [out] | p_r_sig | Part of the signature
  [out] | p_s_sig | Part of the signature

Returns
  0 on success, -1 otherwise

## sign_verif()

int security_ecc::sign_verif | ( | const std::vector< unsigned char > & | p_data,
|  | const std::vector< unsigned char > & | p_signature
| ) |  |

Verifiy an ECDSA signature.

Parameters

  [in] | p_data | The signed data
  [in] | p_signature | The signature part, based on r_sig part and s_sig part

Returns
  0 on success, -1 otherwise

## symmetric_encryption_key()

const std::vector<unsigned char>& security_ecc::symmetric_encryption_key | ( |  | ) | const

inline

## tag()

const std::vector<unsigned char>& security_ecc::tag | ( |  | ) | const

inline

## Member Data Documentation

## _bn_ctx

BN_CTX* security_ecc::_bn_ctx

private

Pre-alocated memory used to increase OpenSSL processing

## _ec_group

const EC_GROUP* security_ecc::_ec_group

private

EC_GROUP reference

## _ec_key

EC_KEY* security_ecc::_ec_key

private

EC_KEY reference

## _elliptic_curve

ec_elliptic_curves security_ecc::_elliptic_curve

private

Selected elleptic curve

## _enc_key_x

std::vector<unsigned char> security_ecc::_enc_key_x

private

Ephemeral public key X-coordinate storage

## _enc_key_y

std::vector<unsigned char> security_ecc::_enc_key_y

private

Ephemeral public key Y-coordinate storage

## _enc_sym_key

std::vector<unsigned char> security_ecc::_enc_sym_key

private

Encrypted AES symmetric encryption key generated by encryption method

## _encryption_algotithm

encryption_algotithm security_ecc::_encryption_algotithm

private

Selected encryption algotithm

## _nonce

std::vector<unsigned char> security_ecc::_nonce

private

Initial Vector generated by encryption method

## _pri_key

std::vector<unsigned char> security_ecc::_pri_key

private

Private key storage

## _pub_key_x

std::vector<unsigned char> security_ecc::_pub_key_x

private

Public key X-coordinate storage

## _pub_key_y

std::vector<unsigned char> security_ecc::_pub_key_y

private

Public key Y-coordinate storage

## _secret_key

std::vector<unsigned char> security_ecc::_secret_key

private

Shared secret key generated by ECIES encryption method

## _sym_key

std::vector<unsigned char> security_ecc::_sym_key

private

AES symmetric encryption key generated by encryption method

## _tag

std::vector<unsigned char> security_ecc::_tag

private

Tag vector generated by encryption method

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

- /home/vagrant/TriesAndDelete/etsi_its/framework/include/security_ecc.hh
- /home/vagrant/TriesAndDelete/etsi_its/framework/src/security_ecc.cc