security_ecc.hh
Go to the documentation of this file.
#pragma once
#include <vector>
#include <openssl/err.h>
#include <openssl/ec.h>
#include <openssl/pem.h>
#include <openssl/bn.h>
enum class ec_elliptic_curves: unsigned char {
nist_p_256,
brainpool_p_256_r1,
brainpool_p_384_r1
}; // End of class ec_elliptic_curves
enum class encryption_algotithm: unsigned char {
aes_128_ccm,
aes_256_ccm,
aes_128_gcm,
aes_256_gcm
}; // End of class encryption_algotithm
class security_ecc {
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;
public:
security_ecc(const ec_elliptic_curves p_elliptic_curve);
security_ecc(const ec_elliptic_curves p_elliptic_curve, const std::vector<unsigned char>& p_private_key);
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);
virtual ~security_ecc();
int generate();
int sign(const std::vector<unsigned char>& p_data, std::vector<unsigned char>& p_r_sig, std::vector<unsigned char>& p_s_sig);
int sign_verif(const std::vector<unsigned char>& p_data, const std::vector<unsigned char>& p_signature);
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);
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);
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);
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);
int decrypt(const std::vector<unsigned char>& p_tag, const std::vector<unsigned char>& p_enc_message, std::vector<unsigned char>& p_message);
inline const std::vector<unsigned char>& private_key() const { return _pri_key; };
inline const std::vector<unsigned char>& public_key_x() const { return _pub_key_x; };
inline const std::vector<unsigned char>& public_key_y() const { return _pub_key_y; };
inline const std::vector<unsigned char>& secret_key() const { return _secret_key; };
inline const std::vector<unsigned char>& encryption_key_x() const { return _enc_key_x; };
inline const std::vector<unsigned char>& encryption_key_y() const { return _enc_key_y; };
inline const std::vector<unsigned char>& encrypted_symmetric_key() const { return _enc_sym_key; };
inline const std::vector<unsigned char>& symmetric_encryption_key() const { return _sym_key; };
inline const std::vector<unsigned char>& nonce() const { return _nonce; };
inline const std::vector<unsigned char>& tag() const { return _tag; };
private:
const int init();
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);
int public_key_to_bin(std::vector<unsigned char>& p_bin_key);
/*int multiply_point_with_bn(const EC_POINT &a, const BIGNUM* b, EC_POINT **P);
// R: XY-coordinate compressed, S: Share Secret
int derive_s_from_private_key(BIGNUM *S, BIGNUM *R);
// R: XY-coordinate compressed, S: Share Secret
int derive_s_from_public_key(BIGNUM *S, BIGNUM *R);*/
}; // End of class security_ecc
security_ecc::_pub_key_x
std::vector< unsigned char > _pub_key_x
Definition: security_ecc.hh:50
security_ecc::encryption_key_x
const std::vector< unsigned char > & encryption_key_x() const
Definition: security_ecc.hh:196
security_ecc::_nonce
std::vector< unsigned char > _nonce
Definition: security_ecc.hh:57
security_ecc::nonce
const std::vector< unsigned char > & nonce() const
Definition: security_ecc.hh:200
encryption_algotithm::aes_128_gcm
security_ecc::public_key_x
const std::vector< unsigned char > & public_key_x() const
Definition: security_ecc.hh:193
security_ecc::tag
const std::vector< unsigned char > & tag() const
Definition: security_ecc.hh:201
security_ecc::_bn_ctx
BN_CTX * _bn_ctx
Definition: security_ecc.hh:48
ec_elliptic_curves::brainpool_p_256_r1
security_ecc::private_key
const std::vector< unsigned char > & private_key() const
Definition: security_ecc.hh:192
ec_elliptic_curves::nist_p_256
security_ecc::encryption_key_y
const std::vector< unsigned char > & encryption_key_y() const
Definition: security_ecc.hh:197
security_ecc::encrypted_symmetric_key
const std::vector< unsigned char > & encrypted_symmetric_key() const
Definition: security_ecc.hh:198
security_ecc::_ec_group
const EC_GROUP * _ec_group
Definition: security_ecc.hh:47
security_ecc::_enc_sym_key
std::vector< unsigned char > _enc_sym_key
Definition: security_ecc.hh:56
ec_elliptic_curves::brainpool_p_384_r1
ec_elliptic_curves
ec_elliptic_curves
Definition: security_ecc.hh:23
security_ecc::public_key_y
const std::vector< unsigned char > & public_key_y() const
Definition: security_ecc.hh:194
security_ecc::_sym_key
std::vector< unsigned char > _sym_key
Definition: security_ecc.hh:55
security_ecc
This class implements the generation of a key pair private/public.
Definition: security_ecc.hh:43
encryption_algotithm::aes_256_ccm
encryption_algotithm::aes_128_ccm
security_ecc::_pri_key
std::vector< unsigned char > _pri_key
Definition: security_ecc.hh:49
security_ecc::_pub_key_y
std::vector< unsigned char > _pub_key_y
Definition: security_ecc.hh:51
security_ecc::symmetric_encryption_key
const std::vector< unsigned char > & symmetric_encryption_key() const
Definition: security_ecc.hh:199
security_ecc::_encryption_algotithm
encryption_algotithm _encryption_algotithm
Definition: security_ecc.hh:45
security_ecc::_enc_key_x
std::vector< unsigned char > _enc_key_x
Definition: security_ecc.hh:53
security_ecc::_ec_key
EC_KEY * _ec_key
Definition: security_ecc.hh:46
encryption_algotithm::aes_256_gcm
security_ecc::_elliptic_curve
ec_elliptic_curves _elliptic_curve
Definition: security_ecc.hh:44
encryption_algotithm
encryption_algotithm
Definition: security_ecc.hh:32
security_ecc::_secret_key
std::vector< unsigned char > _secret_key
Definition: security_ecc.hh:52
security_ecc::secret_key
const std::vector< unsigned char > & secret_key() const
Definition: security_ecc.hh:195
security_ecc::_enc_key_y
std::vector< unsigned char > _enc_key_y
Definition: security_ecc.hh:54
security_ecc::_tag
std::vector< unsigned char > _tag
Definition: security_ecc.hh:58