Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
audiowmark
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Stefan Westerfeld
audiowmark
Commits
ee46a524
Commit
ee46a524
authored
Jan 04, 2019
by
Stefan Westerfeld
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support loading watermarking key from file (using --key <file>).
Signed-off-by:
Stefan Westerfeld
<
stefan@space.twc.de
>
parent
b582c712
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
74 additions
and
12 deletions
+74
-12
TODO
src/TODO
+0
-1
audiowmark.cc
src/audiowmark.cc
+6
-0
random.cc
src/random.cc
+67
-11
random.hh
src/random.hh
+1
-0
No files found.
src/TODO
View file @
ee46a524
key:
- --key loading
- multiple values per block
- avoid reroll in up_down generation
- move shuffle function to Random class
...
...
src/audiowmark.cc
View file @
ee46a524
...
...
@@ -65,6 +65,7 @@ print_usage()
printf
(
" --water-delta set watermarking delta [%.4f]
\n
"
,
Params
::
water_delta
);
printf
(
" --pre-scale set scaling used for normalization [%.3f]
\n
"
,
Params
::
pre_scale
);
printf
(
" --linear disable non-linear bit storage
\n
"
);
printf
(
" --key <file> load watermarking key from file
\n
"
);
}
static
bool
...
...
@@ -166,6 +167,11 @@ parse_options (int *argc_p,
Params
::
have_key
++
;
Random
::
set_global_test_key
(
atoi
(
opt_arg
));
}
else
if
(
check_arg
(
argc
,
argv
,
&
i
,
"--key"
,
&
opt_arg
))
{
Params
::
have_key
++
;
Random
::
load_global_key
(
opt_arg
);
}
}
/* resort argc/argv */
...
...
src/random.cc
View file @
ee46a524
#include "random.hh"
#include "utils.hh"
#include <regex>
using
std
::
string
;
using
std
::
vector
;
using
std
::
regex
;
using
std
::
regex_match
;
static
std
::
vector
<
unsigned
char
>
aes_key
(
16
);
static
std
::
vector
<
unsigned
char
>
aes_key
(
16
);
// 128 bits
static
constexpr
auto
GCRY_CIPHER
=
GCRY_CIPHER_AES128
;
static
void
...
...
@@ -126,18 +132,68 @@ Random::set_global_test_key (uint64_t key)
uint64_to_buffer
(
key
,
&
aes_key
[
0
]);
}
std
::
string
Random
::
gen_key
(
)
void
Random
::
load_global_key
(
const
string
&
key_file
)
{
unsigned
char
key
[
16
];
gcry_randomize
(
key
,
16
,
/* long term key material strength */
GCRY_VERY_STRONG_RANDOM
);
string
s
;
for
(
auto
k
:
key
)
FILE
*
f
=
fopen
(
key_file
.
c_str
(),
"r"
);
if
(
!
f
)
{
char
buffer
[
256
];
fprintf
(
stderr
,
"audiowmark: error opening key file: '%s'
\n
"
,
key_file
.
c_str
());
exit
(
1
);
}
sprintf
(
buffer
,
"%02x"
,
k
);
s
+=
buffer
;
const
regex
blank_re
(
R"(\s*(#.*)?[\r\n]+)"
);
const
regex
key_re
(
R"(\s*key\s+([0-9a-f]+)\s*(#.*)?[\r\n]+)"
);
char
buffer
[
1024
];
int
line
=
1
;
int
keys
=
0
;
while
(
fgets
(
buffer
,
1024
,
f
))
{
string
s
=
buffer
;
std
::
smatch
match
;
if
(
regex_match
(
s
,
blank_re
))
{
/* blank line or comment */
}
else
if
(
regex_match
(
s
,
match
,
key_re
))
{
/* line containing aes key */
vector
<
unsigned
char
>
key
=
hex_str_to_vec
(
match
[
1
].
str
());
if
(
key
.
size
()
!=
aes_key
.
size
())
{
fprintf
(
stderr
,
"audiowmark: wrong key length in key file '%s', line %d
\n
=> required key length is %zd bits
\n
"
,
key_file
.
c_str
(),
line
,
aes_key
.
size
()
*
8
);
exit
(
1
);
}
aes_key
=
key
;
keys
++
;
}
else
{
fprintf
(
stderr
,
"audiowmark: parse error in key file '%s', line %d
\n
"
,
key_file
.
c_str
(),
line
);
exit
(
1
);
}
line
++
;
}
return
s
;
fclose
(
f
);
if
(
keys
>
1
)
{
fprintf
(
stderr
,
"audiowmark: key file '%s' contains more than one key
\n
"
,
key_file
.
c_str
());
exit
(
1
);
}
if
(
keys
==
0
)
{
fprintf
(
stderr
,
"audiowmark: key file '%s' contains no key
\n
"
,
key_file
.
c_str
());
exit
(
1
);
}
}
std
::
string
Random
::
gen_key
()
{
vector
<
unsigned
char
>
key
(
16
);
gcry_randomize
(
&
key
[
0
],
16
,
/* long term key material strength */
GCRY_VERY_STRONG_RANDOM
);
return
vec_to_hex_str
(
key
);
}
src/random.hh
View file @
ee46a524
...
...
@@ -35,6 +35,7 @@ public:
uint64_t
operator
()();
static
void
set_global_test_key
(
uint64_t
seed
);
static
void
load_global_key
(
const
std
::
string
&
key_file
);
static
std
::
string
gen_key
();
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment