Commit 90a47bf9 authored by Stefan Westerfeld's avatar Stefan Westerfeld

Allow setting AES key for test purposes using --test-key.

Old style --seed is no longer supported; replaced it with --test-key in
test scripts.
Signed-off-by: Stefan Westerfeld's avatarStefan Westerfeld <stefan@space.twc.de>
parent 418b3932
...@@ -31,7 +31,7 @@ namespace Params ...@@ -31,7 +31,7 @@ namespace Params
static bool mix = true; static bool mix = true;
static bool hard = false; // hard decode bits? (soft decoding is better) static bool hard = false; // hard decode bits? (soft decoding is better)
static int block_size = 32; // block size for mix step (non-linear bit storage) static int block_size = 32; // block size for mix step (non-linear bit storage)
static unsigned int seed = 0; static int have_key = 0;
static size_t payload_size = 128; // number of payload bits for the watermark static size_t payload_size = 128; // number of payload bits for the watermark
} }
...@@ -158,9 +158,10 @@ parse_options (int *argc_p, ...@@ -158,9 +158,10 @@ parse_options (int *argc_p,
{ {
Params::hard = true; Params::hard = true;
} }
else if (check_arg (argc, argv, &i, "--seed", &opt_arg)) else if (check_arg (argc, argv, &i, "--test-key", &opt_arg))
{ {
Params::seed = atoi (opt_arg); Params::have_key++;
Random::set_global_test_key (atoi (opt_arg));
} }
} }
...@@ -888,6 +889,11 @@ main (int argc, char **argv) ...@@ -888,6 +889,11 @@ main (int argc, char **argv)
{ {
parse_options (&argc, &argv); parse_options (&argc, &argv);
if (Params::have_key > 1)
{
fprintf (stderr, "audiowmark: watermark key can at most be set once (--key / --test-key option)\n");
return 1;
}
string op = (argc >= 2) ? argv[1] : ""; string op = (argc >= 2) ? argv[1] : "";
if (op == "add" && argc == 5) if (op == "add" && argc == 5)
......
...@@ -44,7 +44,7 @@ do ...@@ -44,7 +44,7 @@ do
PATTERN=4e1243bd22c66e76c2ba9eddc1f91394 PATTERN=4e1243bd22c66e76c2ba9eddc1f91394
fi fi
audiowmark add "$i" ${AWM_FILE}.wav $PATTERN $AWM_PARAMS --seed $SEED >/dev/null audiowmark add "$i" ${AWM_FILE}.wav $PATTERN $AWM_PARAMS --test-key $SEED >/dev/null
if [ "x$TRANSFORM" == "xmp3" ]; then if [ "x$TRANSFORM" == "xmp3" ]; then
if [ "x$2" == "x" ]; then if [ "x$2" == "x" ]; then
echo "need mp3 bitrate" >&2 echo "need mp3 bitrate" >&2
...@@ -93,9 +93,9 @@ do ...@@ -93,9 +93,9 @@ do
exit 1 exit 1
fi fi
# blind decoding # blind decoding
audiowmark cmp ${AWM_FILE}.wav $PATTERN $AWM_PARAMS --seed $SEED audiowmark cmp ${AWM_FILE}.wav $PATTERN $AWM_PARAMS --test-key $SEED
# decoding with original # decoding with original
# audiowmark cmp-delta "$i" t.wav $PATTERN $AWM_PARAMS --seed $SEED # audiowmark cmp-delta "$i" t.wav $PATTERN $AWM_PARAMS --test-key $SEED
done done
done | grep bit_error_rate | { done | grep bit_error_rate | {
if [ "x$AWM_REPORT" == "xber" ]; then if [ "x$AWM_REPORT" == "xber" ]; then
......
#include "random.hh" #include "random.hh"
static std::vector<unsigned char> aes_key (16);
static constexpr auto GCRY_CIPHER = GCRY_CIPHER_AES128;
static void
uint64_to_buffer (uint64_t u,
unsigned char *buffer)
{
/* this has to be endian independent: use big endian order */
buffer[0] = u >> 56;
buffer[1] = u >> 48;
buffer[2] = u >> 40;
buffer[3] = u >> 32;
buffer[4] = u >> 24;
buffer[5] = u >> 16;
buffer[6] = u >> 8;
buffer[7] = u;
}
static uint64_t
uint64_from_buffer (unsigned char *buffer)
{
/* this has to be endian independent: use big endian order */
return (uint64_t (buffer[0]) << 56)
+ (uint64_t (buffer[1]) << 48)
+ (uint64_t (buffer[2]) << 40)
+ (uint64_t (buffer[3]) << 32)
+ (uint64_t (buffer[4]) << 24)
+ (uint64_t (buffer[5]) << 16)
+ (uint64_t (buffer[6]) << 8)
+ buffer[7];
}
Random::Random (uint64_t seed, Stream stream) Random::Random (uint64_t seed, Stream stream)
{ {
std::vector<unsigned char> ctr = get_start_counter (seed, stream); std::vector<unsigned char> ctr = get_start_counter (seed, stream);
...@@ -40,15 +72,7 @@ Random::get_start_counter (uint64_t seed, Stream stream) ...@@ -40,15 +72,7 @@ Random::get_start_counter (uint64_t seed, Stream stream)
std::vector<unsigned char> cipher_text (16); std::vector<unsigned char> cipher_text (16);
std::vector<unsigned char> plain_text (16); std::vector<unsigned char> plain_text (16);
/* this has to be endian independent: use big endian order */ uint64_to_buffer (seed, &plain_text[0]);
plain_text[0] = seed >> 56;
plain_text[1] = seed >> 48;
plain_text[2] = seed >> 40;
plain_text[3] = seed >> 32;
plain_text[4] = seed >> 24;
plain_text[5] = seed >> 16;
plain_text[6] = seed >> 8;
plain_text[7] = seed;
plain_text[8] = uint8_t (stream); plain_text[8] = uint8_t (stream);
...@@ -91,14 +115,11 @@ Random::operator()() ...@@ -91,14 +115,11 @@ Random::operator()()
printf ("%02x ", ch); printf ("%02x ", ch);
printf (" ]]\n"); printf (" ]]\n");
#endif #endif
/* this has to be endian independent: use big endian order */ return uint64_from_buffer (&cipher_text[0]);
uint64_t result = (uint64_t (cipher_text[0]) << 56) }
+ (uint64_t (cipher_text[1]) << 48)
+ (uint64_t (cipher_text[2]) << 40) void
+ (uint64_t (cipher_text[3]) << 32) Random::set_global_test_key (uint64_t key)
+ (uint64_t (cipher_text[4]) << 24) {
+ (uint64_t (cipher_text[5]) << 16) uint64_to_buffer (key, &aes_key[0]);
+ (uint64_t (cipher_text[6]) << 8)
+ cipher_text[7];
return result;
} }
...@@ -15,11 +15,8 @@ public: ...@@ -15,11 +15,8 @@ public:
bit_order = 3 bit_order = 3
}; };
private: private:
std::vector<unsigned char> aes_key = std::vector<unsigned char> (16);
gcry_cipher_hd_t aes_ctr_cipher; gcry_cipher_hd_t aes_ctr_cipher;
static constexpr auto GCRY_CIPHER = GCRY_CIPHER_AES128;
void void
die_on_error (const char *func, gcry_error_t error) die_on_error (const char *func, gcry_error_t error)
{ {
...@@ -35,6 +32,8 @@ public: ...@@ -35,6 +32,8 @@ public:
Random (uint64_t seed, Stream stream); Random (uint64_t seed, Stream stream);
~Random(); ~Random();
uint64_t operator()(); uint64_t operator()();
static void set_global_test_key (uint64_t seed);
}; };
#endif /* AUDIOWMARK_RANDOM_HH */ #endif /* AUDIOWMARK_RANDOM_HH */
...@@ -24,4 +24,16 @@ main (int argc, char **argv) ...@@ -24,4 +24,16 @@ main (int argc, char **argv)
uint64_t x = rng(); uint64_t x = rng();
printf ("%016lx\n", x); printf ("%016lx\n", x);
} }
uint64_t s = 0;
double t_start = gettime();
size_t runs = 1000000;
for (size_t i = 0; i < runs; i++)
{
s += rng();
}
double t_end = gettime();
printf ("s=%016lx\n\n", s);
printf ("%f Mvalues/sec\n", runs / (t_end - t_start) / 1000000);
} }
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