19 #ifndef GNSS_SDR_GNSS_CRYPTO_H 20 #define GNSS_SDR_GNSS_CRYPTO_H 25 #if USE_GNUTLS_FALLBACK 26 #include <gnutls/abstract.h> 27 #include <gnutls/gnutls.h> 29 #include <openssl/ec.h> 51 Gnss_Crypto(
const std::string& certFilePath,
const std::string& merkleTreePath);
64 std::vector<uint8_t>
compute_SHA_256(
const std::vector<uint8_t>& input)
const;
65 std::vector<uint8_t>
compute_SHA3_256(
const std::vector<uint8_t>& input)
const;
66 std::vector<uint8_t>
compute_HMAC_SHA_256(
const std::vector<uint8_t>& key,
const std::vector<uint8_t>& input)
const;
67 std::vector<uint8_t>
compute_CMAC_AES(
const std::vector<uint8_t>& key,
const std::vector<uint8_t>& input)
const;
75 void read_merkle_xml(
const std::string& merkleFilePath);
78 void readPublicKeyFromPEM(
const std::string& pemFilePath);
79 bool readPublicKeyFromCRT(
const std::string& crtFilePath);
80 bool convert_raw_to_der_ecdsa(
const std::vector<uint8_t>& raw_signature, std::vector<uint8_t>& der_signature)
const;
81 std::vector<uint8_t> convert_from_hex_str(
const std::string& input)
const;
82 #if USE_GNUTLS_FALLBACK 83 void decompress_public_key_secp256r1(
const std::vector<uint8_t>& compressed_key, std::vector<uint8_t>& x, std::vector<uint8_t>& y)
const;
84 void decompress_public_key_secp521r1(
const std::vector<uint8_t>& compressed_key, std::vector<uint8_t>& x, std::vector<uint8_t>& y)
const;
85 bool pubkey_copy(gnutls_pubkey_t src, gnutls_pubkey_t* dest);
86 gnutls_pubkey_t d_PublicKey{};
89 bool pubkey_copy(EVP_PKEY* src, EVP_PKEY** dest);
90 EVP_PKEY* d_PublicKey{};
92 bool pubkey_copy(EC_KEY* src, EC_KEY** dest);
93 EC_KEY* d_PublicKey =
nullptr;
96 std::vector<uint8_t> d_x_4_0;
97 std::string d_PublicKeyType;
103 #endif // GNSS_SDR_GNSS_CRYPTO_H Class implementing cryptographic functions for Navigation Message Authentication. ...
bool verify_signature_ecdsa_p521(const std::vector< uint8_t > &message, const std::vector< uint8_t > &signature) const
Verify ECDSA-P521 signature (message in plain hex, signature in raw format)
void set_merkle_root(const std::vector< uint8_t > &v)
Sets the Merkle Tree root node x( )
bool verify_signature_ecdsa_p256(const std::vector< uint8_t > &message, const std::vector< uint8_t > &signature) const
Verify ECDSA-P256 signature (message in plain hex, signature in raw format)
std::vector< uint8_t > compute_SHA3_256(const std::vector< uint8_t > &input) const
Computes SHA3-256 hash.
std::vector< uint8_t > get_merkle_root() const
Gets the Merkle Tree root node ( )
Gnss_Crypto()
Default constructor.
~Gnss_Crypto()
Default destructor.
std::string get_public_key_type() const
Gets the ECDSA Public Key type (ECDSA P-256 / ECDSA P-521 / Unknown)
bool have_public_key() const
Returns true if the ECDSA Public Key is already loaded.
void set_public_key_type(const std::string &public_key_type)
Sets the ECDSA Public Key type (ECDSA P-256 / ECDSA P-521)
std::vector< uint8_t > compute_CMAC_AES(const std::vector< uint8_t > &key, const std::vector< uint8_t > &input) const
Computes CMAC-AES message authentication code.
void set_public_key(const std::vector< uint8_t > &publickey)
Sets the ECDSA Public Key (publickey compressed format)
std::vector< uint8_t > compute_HMAC_SHA_256(const std::vector< uint8_t > &key, const std::vector< uint8_t > &input) const
Computes HMAC-SHA-256 message authentication code.
bool store_public_key(const std::string &pubKeyFilePath) const
std::vector< uint8_t > compute_SHA_256(const std::vector< uint8_t > &input) const
Computes SHA-256 hash.