ETSI STF525 / Internal Testing test suite This project provides an internal testing test suite and its associated Test Adapter/Codec

security_ecc.hh
Go to the documentation of this file.
1
11 #pragma once
12
13 #include <vector>
14
15 #include <openssl/err.h>
16 #include <openssl/ec.h>
17 #include <openssl/pem.h>
18 #include <openssl/bn.h>
19
23 enum class ec_elliptic_curves: unsigned char {
24 nist_p_256,
25 brainpool_p_256_r1,
26 brainpool_p_384_r1
27 }; // End of class ec_elliptic_curves
28
32 enum class encryption_algotithm: unsigned char {
33 aes_128_ccm,
34 aes_256_ccm,
35 aes_128_gcm,
36 aes_256_gcm
37 }; // End of class encryption_algotithm
38
43 class security_ecc {
44 ec_elliptic_curves _elliptic_curve;
45 encryption_algotithm _encryption_algotithm;
46 EC_KEY* _ec_key;
47 const EC_GROUP* _ec_group;
48 BN_CTX* _bn_ctx;
49 std::vector<unsigned char> _pri_key;
50 std::vector<unsigned char> _pub_key_x;
51 std::vector<unsigned char> _pub_key_y;
52 std::vector<unsigned char> _secret_key;
53 std::vector<unsigned char> _enc_key_x;
54 std::vector<unsigned char> _enc_key_y;
55 std::vector<unsigned char> _sym_key;
56 std::vector<unsigned char> _enc_sym_key;
57 std::vector<unsigned char> _nonce;
58 std::vector<unsigned char> _tag;
60 public:
61
66 security_ecc(const ec_elliptic_curves p_elliptic_curve);
73 security_ecc(const ec_elliptic_curves p_elliptic_curve, const std::vector<unsigned char>& p_private_key);
80 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);
84 virtual ~security_ecc();
85
92 int generate();
101 int sign(const std::vector<unsigned char>& p_data, std::vector<unsigned char>& p_r_sig, std::vector<unsigned char>& p_s_sig);
109 int sign_verif(const std::vector<unsigned char>& p_data, const std::vector<unsigned char>& p_signature);
110
124 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);
125
137 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);
138
150 int encrypt(const encryption_algotithm p_enc_algorithm, const std::vector<unsigned char>& p_message, std::vector<unsigned char>& p_enc_message);
164 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);
178 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);
190 int decrypt(const std::vector<unsigned char>& p_tag, const std::vector<unsigned char>& p_enc_message, std::vector<unsigned char>& p_message);
191
192 inline const std::vector<unsigned char>& private_key() const { return _pri_key; };
193 inline const std::vector<unsigned char>& public_key_x() const { return _pub_key_x; };
194 inline const std::vector<unsigned char>& public_key_y() const { return _pub_key_y; };
195 inline const std::vector<unsigned char>& secret_key() const { return _secret_key; };
196 inline const std::vector<unsigned char>& encryption_key_x() const { return _enc_key_x; };
197 inline const std::vector<unsigned char>& encryption_key_y() const { return _enc_key_y; };
198 inline const std::vector<unsigned char>& encrypted_symmetric_key() const { return _enc_sym_key; };
199 inline const std::vector<unsigned char>& symmetric_encryption_key() const { return _sym_key; };
200 inline const std::vector<unsigned char>& nonce() const { return _nonce; };
201 inline const std::vector<unsigned char>& tag() const { return _tag; };
202
203 private:
204
209 const int init();
215 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);
221 int public_key_to_bin(std::vector<unsigned char>& p_bin_key);
222
223 /*int multiply_point_with_bn(const EC_POINT &a, const BIGNUM* b, EC_POINT **P);
224 // R: XY-coordinate compressed, S: Share Secret
225 int derive_s_from_private_key(BIGNUM *S, BIGNUM *R);
226 // R: XY-coordinate compressed, S: Share Secret
227 int derive_s_from_public_key(BIGNUM *S, BIGNUM *R);*/
228
229 }; // 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