Commit 7e8980f5 authored by Stefan Westerfeld's avatar Stefan Westerfeld

Implement audiowmark gen-key command.

Signed-off-by: Stefan Westerfeld's avatarStefan Westerfeld <stefan@space.twc.de>
parent 90a47bf9
key:
- --key loading
- multiple values per block
- avoid reroll in up_down generation
- move shuffle function to Random class
possible improvements:
- dynamic bit strength
- mp3 support with libmad
......@@ -56,6 +56,9 @@ print_usage()
printf (" * compute bit error rate for decoding with original file\n");
printf (" audiowmark cmp-delta <input_wav> <watermarked_wav> <message_hex>\n");
printf ("\n");
printf (" * generate 128-bit watermarking key, to be used with --key option\n");
printf (" audiowmark gen-key <key_file>\n");
printf ("\n");
printf ("Global options:\n");
printf (" --frame-size frame size (must be power of 2) [%zd]\n", Params::frame_size);
printf (" --frames-per-bit number of frames per bit [%d]\n", Params::frames_per_bit);
......@@ -884,6 +887,20 @@ get_snr (const string& origfile, const string& wmfile)
return 0;
}
int
gen_key (const string& outfile)
{
FILE *f = fopen (outfile.c_str(), "w");
if (!f)
{
fprintf (stderr, "audiowmark: error writing to file %s\n", outfile.c_str());
return 1;
}
fprintf (f, "# watermarking key for audiowmark\n\nkey %s\n", Random::gen_key().c_str());
fclose (f);
return 0;
}
int
main (int argc, char **argv)
{
......@@ -928,9 +945,13 @@ main (int argc, char **argv)
{
return get_watermark_delta (argv[2], argv[3], argv[4]);
}
else if (op == "gen-key" && argc == 3)
{
return gen_key (argv[2]);
}
else
{
fprintf (stderr, "audiowmark: error parsing commandline args\n");
fprintf (stderr, "audiowmark: error parsing commandline args (use audiowmark -h)\n");
return 1;
}
}
#include "random.hh"
using std::string;
static std::vector<unsigned char> aes_key (16);
static constexpr auto GCRY_CIPHER = GCRY_CIPHER_AES128;
......@@ -123,3 +125,19 @@ Random::set_global_test_key (uint64_t key)
{
uint64_to_buffer (key, &aes_key[0]);
}
std::string
Random::gen_key()
{
unsigned char key[16];
gcry_randomize (key, 16, /* long term key material strength */ GCRY_VERY_STRONG_RANDOM);
string s;
for (auto k : key)
{
char buffer[256];
sprintf (buffer, "%02x", k);
s += buffer;
}
return s;
}
......@@ -5,6 +5,7 @@
#include <stdint.h>
#include <vector>
#include <string>
class Random
{
......@@ -33,7 +34,8 @@ public:
~Random();
uint64_t operator()();
static void set_global_test_key (uint64_t seed);
static void set_global_test_key (uint64_t seed);
static std::string gen_key();
};
#endif /* AUDIOWMARK_RANDOM_HH */
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