Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
N
nettle
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Nettle
nettle
Commits
a0b72cf1
Commit
a0b72cf1
authored
Sep 30, 2019
by
Niels Möller
Browse files
Options
Downloads
Patches
Plain Diff
siv-test: Smaller cleanups. Call FAIL on all errors.
parent
26d8ed95
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
ChangeLog
+3
-0
3 additions, 0 deletions
ChangeLog
testsuite/siv-test.c
+19
-26
19 additions, 26 deletions
testsuite/siv-test.c
with
22 additions
and
26 deletions
ChangeLog
+
3
−
0
View file @
a0b72cf1
2019-09-30 Niels Möller <nisse@lysator.liu.se>
2019-09-30 Niels Möller <nisse@lysator.liu.se>
* testsuite/siv-test.c (test_cipher_siv): Fix out-of-bounds read.
* testsuite/siv-test.c (test_cipher_siv): Fix out-of-bounds read.
Trim allocation size for de_data, drop some uses of
SIV_DIGEST_SIZE, call FAIL for unexpected returned values.
(test_compare_results): Delete digest argument.
2019-09-15 Niels Möller <nisse@lysator.liu.se>
2019-09-15 Niels Möller <nisse@lysator.liu.se>
...
...
This diff is collapsed.
Click to expand it.
testsuite/siv-test.c
+
19
−
26
View file @
a0b72cf1
...
@@ -63,22 +63,8 @@ test_compare_results(const char *name,
...
@@ -63,22 +63,8 @@ test_compare_results(const char *name,
const
struct
tstring
*
e_cipher
,
const
struct
tstring
*
e_cipher
,
/* Actual results. */
/* Actual results. */
const
void
*
clear
,
const
void
*
clear
,
const
void
*
cipher
,
const
void
*
cipher
)
const
void
*
digest
)
/* digest optional. */
{
{
if
(
digest
&&
!
MEMEQ
(
SIV_DIGEST_SIZE
,
e_cipher
->
data
,
digest
))
{
fprintf
(
stderr
,
"%s digest failed:
\n
Adata:"
,
name
);
tstring_print_hex
(
adata
);
fprintf
(
stderr
,
"
\n
Input: "
);
tstring_print_hex
(
e_clear
);
fprintf
(
stderr
,
"
\n
Output: "
);
print_hex
(
SIV_DIGEST_SIZE
,
digest
);
fprintf
(
stderr
,
"
\n
Expected:"
);
print_hex
(
SIV_DIGEST_SIZE
,
e_cipher
->
data
);
fprintf
(
stderr
,
"
\n
"
);
FAIL
();
}
if
(
!
MEMEQ
(
e_cipher
->
length
,
e_cipher
->
data
,
cipher
))
if
(
!
MEMEQ
(
e_cipher
->
length
,
e_cipher
->
data
,
cipher
))
{
{
fprintf
(
stderr
,
"%s: encryption failed
\n
Adata: "
,
name
);
fprintf
(
stderr
,
"%s: encryption failed
\n
Adata: "
,
name
);
...
@@ -127,7 +113,7 @@ test_cipher_siv(const char *name,
...
@@ -127,7 +113,7 @@ test_cipher_siv(const char *name,
ASSERT
(
key
->
length
==
key_size
);
ASSERT
(
key
->
length
==
key_size
);
ASSERT
(
cleartext
->
length
+
SIV_DIGEST_SIZE
==
ciphertext
->
length
);
ASSERT
(
cleartext
->
length
+
SIV_DIGEST_SIZE
==
ciphertext
->
length
);
de_data
=
xalloc
(
cleartext
->
length
+
SIV_DIGEST_SIZE
);
de_data
=
xalloc
(
cleartext
->
length
);
en_data
=
xalloc
(
ciphertext
->
length
);
en_data
=
xalloc
(
ciphertext
->
length
);
/* Ensure we get the same answers using the all-in-one API. */
/* Ensure we get the same answers using the all-in-one API. */
...
@@ -137,26 +123,30 @@ test_cipher_siv(const char *name,
...
@@ -137,26 +123,30 @@ test_cipher_siv(const char *name,
siv_set_key
(
ctx
,
key
->
data
);
siv_set_key
(
ctx
,
key
->
data
);
siv_encrypt
(
ctx
,
nonce
->
length
,
nonce
->
data
,
siv_encrypt
(
ctx
,
nonce
->
length
,
nonce
->
data
,
authdata
->
length
,
authdata
->
data
,
authdata
->
length
,
authdata
->
data
,
c
lea
rtext
->
length
+
SIV_DIGEST_SIZE
,
en_data
,
cleartext
->
data
);
c
iphe
rtext
->
length
,
en_data
,
cleartext
->
data
);
ret
=
siv_decrypt
(
ctx
,
nonce
->
length
,
nonce
->
data
,
ret
=
siv_decrypt
(
ctx
,
nonce
->
length
,
nonce
->
data
,
authdata
->
length
,
authdata
->
data
,
authdata
->
length
,
authdata
->
data
,
cleartext
->
length
,
de_data
,
ciphertext
->
data
);
cleartext
->
length
,
de_data
,
ciphertext
->
data
);
if
(
ret
!=
1
)
fprintf
(
stderr
,
"siv_decrypt_message failed to validate message
\n
"
);
if
(
ret
!=
1
)
test_compare_results
(
name
,
authdata
,
{
cleartext
,
ciphertext
,
de_data
,
en_data
,
NULL
);
fprintf
(
stderr
,
"siv_decrypt_message failed to validate message
\n
"
);
FAIL
();
}
test_compare_results
(
name
,
authdata
,
test_compare_results
(
name
,
authdata
,
cleartext
,
ciphertext
,
de_data
,
en_data
,
en_data
);
cleartext
,
ciphertext
,
de_data
,
en_data
);
/* Ensure that we can detect corrupted message or tag data. */
/* Ensure that we can detect corrupted message or tag data. */
en_data
[
0
]
^=
1
;
en_data
[
0
]
^=
1
;
ret
=
siv_decrypt
(
ctx
,
nonce
->
length
,
nonce
->
data
,
ret
=
siv_decrypt
(
ctx
,
nonce
->
length
,
nonce
->
data
,
authdata
->
length
,
authdata
->
data
,
authdata
->
length
,
authdata
->
data
,
cleartext
->
length
,
de_data
,
en_data
);
cleartext
->
length
,
de_data
,
en_data
);
if
(
ret
!=
0
)
fprintf
(
stderr
,
"siv_decrypt_message failed to detect corrupted message
\n
"
);
if
(
ret
!=
0
)
{
fprintf
(
stderr
,
"siv_decrypt_message failed to detect corrupted message
\n
"
);
FAIL
();
}
/* Ensure we can detect corrupted adata. */
/* Ensure we can detect corrupted adata. */
if
(
authdata
->
length
)
{
if
(
authdata
->
length
)
{
...
@@ -164,9 +154,12 @@ test_cipher_siv(const char *name,
...
@@ -164,9 +154,12 @@ test_cipher_siv(const char *name,
ret
=
siv_decrypt
(
ctx
,
nonce
->
length
,
nonce
->
data
,
ret
=
siv_decrypt
(
ctx
,
nonce
->
length
,
nonce
->
data
,
authdata
->
length
-
1
,
authdata
->
data
,
authdata
->
length
-
1
,
authdata
->
data
,
cleartext
->
length
,
de_data
,
en_data
);
cleartext
->
length
,
de_data
,
en_data
);
if
(
ret
!=
0
)
fprintf
(
stderr
,
"siv_decrypt_message failed to detect corrupted message
\n
"
);
if
(
ret
!=
0
)
{
fprintf
(
stderr
,
"siv_decrypt_message failed to detect corrupted message
\n
"
);
FAIL
();
}
}
}
free
(
ctx
);
free
(
ctx
);
free
(
en_data
);
free
(
en_data
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment