Commit 76622bde authored by Stefan Westerfeld's avatar Stefan Westerfeld

Add missing gcrypt initialization.

Signed-off-by: Stefan Westerfeld's avatarStefan Westerfeld <stefan@space.twc.de>
parent 1d703405
...@@ -10,6 +10,23 @@ using std::vector; ...@@ -10,6 +10,23 @@ using std::vector;
using std::regex; using std::regex;
using std::regex_match; using std::regex_match;
static void
gcrypt_init()
{
static bool init_ok = false;
if (!init_ok)
{
if (!gcry_check_version (GCRYPT_VERSION))
{
fprintf (stderr, "audiowmark: libgcrypt version mismatch\n");
exit (1);
}
init_ok = true;
}
}
static vector<unsigned char> aes_key (16); // 128 bits static vector<unsigned char> aes_key (16); // 128 bits
static constexpr auto GCRY_CIPHER = GCRY_CIPHER_AES128; static constexpr auto GCRY_CIPHER = GCRY_CIPHER_AES128;
...@@ -55,6 +72,8 @@ print (const string& label, const vector<unsigned char>& data) ...@@ -55,6 +72,8 @@ print (const string& label, const vector<unsigned char>& data)
Random::Random (uint64_t seed, Stream stream) Random::Random (uint64_t seed, Stream stream)
{ {
gcrypt_init();
vector<unsigned char> ctr = get_start_counter (seed, stream); vector<unsigned char> ctr = get_start_counter (seed, stream);
// print ("CTR", ctr); // print ("CTR", ctr);
...@@ -201,6 +220,8 @@ Random::load_global_key (const string& key_file) ...@@ -201,6 +220,8 @@ Random::load_global_key (const string& key_file)
string string
Random::gen_key() Random::gen_key()
{ {
gcrypt_init();
vector<unsigned char> key (16); vector<unsigned char> key (16);
gcry_randomize (&key[0], 16, /* long term key material strength */ GCRY_VERY_STRONG_RANDOM); gcry_randomize (&key[0], 16, /* long term key material strength */ GCRY_VERY_STRONG_RANDOM);
return vec_to_hex_str (key); return vec_to_hex_str (key);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment