Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
FFmpeg
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
libremedia
Tethys
FFmpeg
Commits
8131bd4c
Commit
8131bd4c
authored
8 years ago
by
Diego Biurrun
Browse files
Options
Downloads
Patches
Plain Diff
blowfish-test: Use struct allocation functions from the API
parent
a86ef804
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
libavutil/tests/blowfish.c
+17
-13
17 additions, 13 deletions
libavutil/tests/blowfish.c
with
17 additions
and
13 deletions
libavutil/tests/blowfish.c
+
17
−
13
View file @
8131bd4c
...
...
@@ -21,6 +21,7 @@
#include
<stdlib.h>
#include
<string.h>
#include
"libavutil/mem.h"
#include
"libavutil/blowfish.h"
#define NUM_VARIABLE_KEY_TESTS 34
...
...
@@ -144,46 +145,49 @@ static void test_blowfish(AVBlowfish *ctx, uint8_t *dst, const uint8_t *src,
int
main
(
void
)
{
AVBlowfish
ctx
;
uint32_t
tmptext_l
[
NUM_VARIABLE_KEY_TESTS
];
uint32_t
tmptext_r
[
NUM_VARIABLE_KEY_TESTS
];
uint8_t
tmp
[
16
],
iv
[
8
];
int
i
;
AVBlowfish
*
ctx
=
av_blowfish_alloc
();
if
(
!
ctx
)
return
1
;
av_blowfish_init
(
&
ctx
,
"abcdefghijklmnopqrstuvwxyz"
,
26
);
av_blowfish_init
(
ctx
,
"abcdefghijklmnopqrstuvwxyz"
,
26
);
test_blowfish
(
&
ctx
,
tmp
,
plaintext
,
ciphertext
,
1
,
NULL
,
0
,
"encryption"
);
test_blowfish
(
&
ctx
,
tmp
,
ciphertext
,
plaintext
,
1
,
NULL
,
1
,
"decryption"
);
test_blowfish
(
&
ctx
,
tmp
,
tmp
,
ciphertext
,
1
,
NULL
,
0
,
"Inplace encryption"
);
test_blowfish
(
&
ctx
,
tmp
,
tmp
,
plaintext
,
1
,
NULL
,
1
,
"Inplace decryption"
);
test_blowfish
(
ctx
,
tmp
,
plaintext
,
ciphertext
,
1
,
NULL
,
0
,
"encryption"
);
test_blowfish
(
ctx
,
tmp
,
ciphertext
,
plaintext
,
1
,
NULL
,
1
,
"decryption"
);
test_blowfish
(
ctx
,
tmp
,
tmp
,
ciphertext
,
1
,
NULL
,
0
,
"Inplace encryption"
);
test_blowfish
(
ctx
,
tmp
,
tmp
,
plaintext
,
1
,
NULL
,
1
,
"Inplace decryption"
);
memcpy
(
iv
,
IV
,
8
);
test_blowfish
(
&
ctx
,
tmp
,
plaintext2
,
ciphertext2
,
2
,
iv
,
0
,
"CBC encryption"
);
test_blowfish
(
ctx
,
tmp
,
plaintext2
,
ciphertext2
,
2
,
iv
,
0
,
"CBC encryption"
);
memcpy
(
iv
,
IV
,
8
);
test_blowfish
(
&
ctx
,
tmp
,
ciphertext2
,
plaintext2
,
2
,
iv
,
1
,
"CBC decryption"
);
test_blowfish
(
ctx
,
tmp
,
ciphertext2
,
plaintext2
,
2
,
iv
,
1
,
"CBC decryption"
);
memcpy
(
iv
,
IV
,
8
);
test_blowfish
(
&
ctx
,
tmp
,
tmp
,
ciphertext2
,
2
,
iv
,
0
,
"Inplace CBC encryption"
);
test_blowfish
(
ctx
,
tmp
,
tmp
,
ciphertext2
,
2
,
iv
,
0
,
"Inplace CBC encryption"
);
memcpy
(
iv
,
IV
,
8
);
test_blowfish
(
&
ctx
,
tmp
,
tmp
,
plaintext2
,
2
,
iv
,
1
,
"Inplace CBC decryption"
);
test_blowfish
(
ctx
,
tmp
,
tmp
,
plaintext2
,
2
,
iv
,
1
,
"Inplace CBC decryption"
);
memcpy
(
tmptext_l
,
plaintext_l
,
sizeof
(
*
plaintext_l
)
*
NUM_VARIABLE_KEY_TESTS
);
memcpy
(
tmptext_r
,
plaintext_r
,
sizeof
(
*
plaintext_r
)
*
NUM_VARIABLE_KEY_TESTS
);
for
(
i
=
0
;
i
<
NUM_VARIABLE_KEY_TESTS
;
i
++
)
{
av_blowfish_init
(
&
ctx
,
variable_key
[
i
],
8
);
av_blowfish_init
(
ctx
,
variable_key
[
i
],
8
);
av_blowfish_crypt_ecb
(
&
ctx
,
&
tmptext_l
[
i
],
&
tmptext_r
[
i
],
0
);
av_blowfish_crypt_ecb
(
ctx
,
&
tmptext_l
[
i
],
&
tmptext_r
[
i
],
0
);
if
(
tmptext_l
[
i
]
!=
ciphertext_l
[
i
]
||
tmptext_r
[
i
]
!=
ciphertext_r
[
i
])
{
printf
(
"Test encryption failed.
\n
"
);
return
2
;
}
av_blowfish_crypt_ecb
(
&
ctx
,
&
tmptext_l
[
i
],
&
tmptext_r
[
i
],
1
);
av_blowfish_crypt_ecb
(
ctx
,
&
tmptext_l
[
i
],
&
tmptext_r
[
i
],
1
);
if
(
tmptext_l
[
i
]
!=
plaintext_l
[
i
]
||
tmptext_r
[
i
]
!=
plaintext_r
[
i
])
{
printf
(
"Test decryption failed.
\n
"
);
return
3
;
}
}
printf
(
"Test encryption/decryption success.
\n
"
);
av_free
(
ctx
);
return
0
;
}
...
...
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