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
5939bb3c
Commit
5939bb3c
authored
Jan 17, 2024
by
Stefan Westerfeld
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Key: support loading key names from key file.
Signed-off-by:
Stefan Westerfeld
<
stefan@space.twc.de
>
parent
b67f7e03
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
109 additions
and
19 deletions
+109
-19
random.cc
src/random.cc
+109
-19
No files found.
src/random.cc
View file @
5939bb3c
...
@@ -207,6 +207,92 @@ Key::set_test_key (uint64_t key)
...
@@ -207,6 +207,92 @@ Key::set_test_key (uint64_t key)
m_name
=
string_printf
(
"test-key-%"
PRId64
,
key
);
m_name
=
string_printf
(
"test-key-%"
PRId64
,
key
);
}
}
static
bool
string_chars
(
char
ch
)
{
if
((
ch
>=
'A'
&&
ch
<=
'Z'
)
||
(
ch
>=
'0'
&&
ch
<=
'9'
)
||
(
ch
>=
'a'
&&
ch
<=
'z'
)
||
(
ch
==
'.'
)
||
(
ch
==
':'
)
||
(
ch
==
'='
)
||
(
ch
==
'/'
)
||
(
ch
==
'-'
)
||
(
ch
==
'_'
))
return
true
;
return
false
;
}
static
bool
white_space
(
char
ch
)
{
return
(
ch
==
' '
||
ch
==
'\n'
||
ch
==
'\t'
||
ch
==
'\r'
);
}
static
bool
tokenize
(
const
string
&
line
,
vector
<
string
>&
tokens
)
{
enum
{
BLANK
,
STRING
,
QUOTED_STRING
,
QUOTED_STRING_ESCAPED
,
COMMENT
}
state
=
BLANK
;
string
s
;
string
xline
=
line
+
'\n'
;
tokens
.
clear
();
for
(
string
::
const_iterator
i
=
xline
.
begin
();
i
!=
xline
.
end
();
i
++
)
{
if
(
state
==
BLANK
&&
string_chars
(
*
i
))
{
state
=
STRING
;
s
+=
*
i
;
}
else
if
(
state
==
BLANK
&&
*
i
==
'"'
)
{
state
=
QUOTED_STRING
;
}
else
if
(
state
==
BLANK
&&
white_space
(
*
i
))
{
// ignore more whitespaces if we've already seen one
}
else
if
(
state
==
STRING
&&
string_chars
(
*
i
))
{
s
+=
*
i
;
}
else
if
((
state
==
STRING
&&
white_space
(
*
i
))
||
(
state
==
QUOTED_STRING
&&
*
i
==
'"'
))
{
tokens
.
push_back
(
s
);
s
=
""
;
state
=
BLANK
;
}
else
if
(
state
==
QUOTED_STRING
&&
*
i
==
'\\'
)
{
state
=
QUOTED_STRING_ESCAPED
;
}
else
if
(
state
==
QUOTED_STRING
)
{
s
+=
*
i
;
}
else
if
(
state
==
QUOTED_STRING_ESCAPED
)
{
s
+=
*
i
;
state
=
QUOTED_STRING
;
}
else
if
(
*
i
==
'#'
)
{
state
=
COMMENT
;
}
else
if
(
state
==
COMMENT
)
{
// ignore comments
}
else
{
return
false
;
}
}
return
state
==
BLANK
||
state
==
COMMENT
;
}
void
void
Key
::
load_key
(
const
string
&
key_file
)
Key
::
load_key
(
const
string
&
key_file
)
{
{
...
@@ -222,25 +308,18 @@ Key::load_key (const string& key_file)
...
@@ -222,25 +308,18 @@ Key::load_key (const string& key_file)
if
(
sep
!=
string
::
npos
)
if
(
sep
!=
string
::
npos
)
m_name
=
m_name
.
substr
(
sep
+
1
);
m_name
=
m_name
.
substr
(
sep
+
1
);
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
];
char
buffer
[
1024
];
int
line
=
1
;
int
line
=
1
;
int
keys
=
0
;
int
keys
=
0
;
while
(
fgets
(
buffer
,
1024
,
f
))
while
(
fgets
(
buffer
,
1024
,
f
))
{
{
string
s
=
buffer
;
vector
<
string
>
tokens
;
bool
parse_ok
=
false
;
std
::
smatch
match
;
if
(
tokenize
(
buffer
,
tokens
))
if
(
regex_match
(
s
,
blank_re
))
{
{
/* blank line or comment */
if
(
tokens
.
size
()
==
2
&&
tokens
[
0
]
==
"key"
)
/* line containing aes key */
}
else
if
(
regex_match
(
s
,
match
,
key_re
))
{
{
/* line containing aes key */
vector
<
unsigned
char
>
key
=
hex_str_to_vec
(
tokens
[
1
]);
vector
<
unsigned
char
>
key
=
hex_str_to_vec
(
match
[
1
].
str
());
if
(
key
.
size
()
!=
Key
::
SIZE
)
if
(
key
.
size
()
!=
Key
::
SIZE
)
{
{
error
(
"audiowmark: wrong key length in key file '%s', line %d
\n
=> required key length is %zd bits
\n
"
,
key_file
.
c_str
(),
line
,
Key
::
SIZE
*
8
);
error
(
"audiowmark: wrong key length in key file '%s', line %d
\n
=> required key length is %zd bits
\n
"
,
key_file
.
c_str
(),
line
,
Key
::
SIZE
*
8
);
...
@@ -248,8 +327,19 @@ Key::load_key (const string& key_file)
...
@@ -248,8 +327,19 @@ Key::load_key (const string& key_file)
}
}
m_aes_key
=
key
;
m_aes_key
=
key
;
keys
++
;
keys
++
;
parse_ok
=
true
;
}
}
else
if
(
tokens
.
size
()
==
2
&&
tokens
[
0
]
==
"name"
)
/* key name */
{
m_name
=
tokens
[
1
];
parse_ok
=
true
;
}
if
(
tokens
.
empty
())
/* blank line or comment */
{
parse_ok
=
true
;
}
}
if
(
!
parse_ok
)
{
{
error
(
"audiowmark: parse error in key file '%s', line %d
\n
"
,
key_file
.
c_str
(),
line
);
error
(
"audiowmark: parse error in key file '%s', line %d
\n
"
,
key_file
.
c_str
(),
line
);
exit
(
1
);
exit
(
1
);
...
...
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