Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
libdap
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
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
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
cellframe
libdap
Commits
e9977e05
Commit
e9977e05
authored
6 years ago
by
armatusmiles
Browse files
Options
Downloads
Patches
Plain Diff
Code review
parent
03fede6a
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
test/CMakeLists.txt
+3
-1
3 additions, 1 deletion
test/CMakeLists.txt
test/crypto/dap_enc_aes_test.c
+53
-26
53 additions, 26 deletions
test/crypto/dap_enc_aes_test.c
test/crypto/dap_enc_aes_test.h
+1
-7
1 addition, 7 deletions
test/crypto/dap_enc_aes_test.h
with
57 additions
and
34 deletions
test/CMakeLists.txt
+
3
−
1
View file @
e9977e05
cmake_minimum_required
(
VERSION 3.0
)
project
(
test
)
set
(
CMAKE_C_STANDARD 11
)
add_subdirectory
(
libdap-test
)
add_subdirectory
(
core
)
add_subdirectory
(
crypto
)
This diff is collapsed.
Click to expand it.
test/crypto/dap_enc_aes_test.c
+
53
−
26
View file @
e9977e05
#include
"dap_enc_aes_test.h"
static
const
size_
t
BYTE_SIZE
=
256
;
static
const
in
t
BYTE_SIZE
=
256
;
void
generate_random_byte_array
(
uint8_t
*
array
,
int
size
){
srand
(
time
(
NULL
));
for
(
int
i
=
0
;
i
<
size
;
i
++
){
array
[
i
]
=
rand
()
%
BYTE_SIZE
;
void
generate_random_byte_array
(
uint8_t
*
array
,
const
size_t
size
)
{
for
(
size_t
i
=
0
;
i
<
size
;
i
++
)
{
array
[
i
]
=
(
uint8_t
)
rand
()
%
BYTE_SIZE
;
}
}
void
test_encode_decode
(
in
t
source_size
){
void
test_encode_decode
(
const
size_
t
source_size
)
{
dap_enc_key_t
*
key
=
dap_enc_key_new_generate
(
DAP_ENC_KEY_TYPE_AES
,
0
);
uint8_t
*
source
=
(
uint8_t
*
)
malloc
(
source_size
);
uint8_t
*
encrypted
=
(
uint8_t
*
)
malloc
(
source_size
+
16
);
uint8_t
*
result
=
(
uint8_t
*
)
malloc
(
source_size
+
16
);
generate_random_byte_array
(
source
,
source_size
);
size_t
encrypted_size
=
dap_enc_aes_encode
(
key
,
source
,
source_size
,
encrypted
);
size_t
result_size
=
dap_enc_aes_decode
(
key
,
encrypted
,
encrypted_size
,
result
);
dap_assert
(
source_size
==
result_size
,
"Size error"
);
dap_assert
(
memcmp
(
source
,
result
,
source_size
)
==
0
,
"Encryption error"
);
free
(
source
);
free
(
encrypted
);
free
(
result
);
dap_enc_key_delete
(
key
);
uint8_t
source
[
source_size
];
uint8_t
encrypted
[
source_size
+
AES_BLOCK_SIZE
];
uint8_t
result
[
source_size
+
AES_BLOCK_SIZE
];
generate_random_byte_array
(
source
,
source_size
);
size_t
encrypted_size
=
dap_enc_aes_encode
(
key
,
source
,
source_size
,
encrypted
);
size_t
result_size
=
dap_enc_aes_decode
(
key
,
encrypted
,
encrypted_size
,
result
);
dap_assert_PIF
(
source_size
==
result_size
,
"Check result decode size"
);
dap_assert_PIF
(
memcmp
(
source
,
result
,
source_size
)
==
0
,
"Check source and encode->decode data"
);
dap_enc_key_delete
(
key
);
}
//void test_encode_decode(int source_size){
// dap_enc_key_t* key = dap_enc_key_new_generate(DAP_ENC_KEY_TYPE_AES, 0);
// uint8_t* source = (uint8_t*)malloc(source_size);
// uint8_t* encrypted = (uint8_t*)malloc(source_size+16);
// uint8_t* result = (uint8_t*)malloc(source_size+16);
// generate_random_byte_array(source,source_size);
// size_t encrypted_size = dap_enc_aes_encode(key,source,source_size,encrypted);
// size_t result_size = dap_enc_aes_decode(key,encrypted,encrypted_size,result);
// if(source_size != result_size) {
// dap_test_msg("FAIL");
// }
// dap_assert(source_size == result_size,"Size error");
// dap_assert(memcmp(source,result,source_size) == 0,"Encryption error");
// free(source);
// free(encrypted);
// free(result);
// dap_enc_key_delete(key);
//}
void
init_test_case
()
{
dap_enc_key_init
();
srand
((
uint
)
time
(
NULL
));
dap_enc_key_init
();
}
void
cleanup_test_case
()
{
...
...
@@ -37,11 +63,12 @@ void cleanup_test_case() {
void
dap_enc_aes_tests_run
()
{
dap_print_module_name
(
"dap_enc_aes"
);
init_test_case
();
test_encode_decode
(
10
);
test_encode_decode
(
100
);
test_encode_decode
(
1000
);
test_encode_decode
(
10000
);
test_encode_decode
(
100000
);
test_encode_decode
(
1000000
);
const
size_t
step
=
3
,
count_steps
=
1000
;
for
(
size_t
i
=
1
;
i
<=
count_steps
;
i
++
)
{
//test_encode_decode(231);
test_encode_decode
(
step
*
i
);
}
cleanup_test_case
();
}
\ No newline at end of file
}
This diff is collapsed.
Click to expand it.
test/crypto/dap_enc_aes_test.h
+
1
−
7
View file @
e9977e05
...
...
@@ -2,11 +2,5 @@
#include
"dap_enc_aes.h"
#include
"dap_enc_key.h"
#include
"dap_test.h"
#include
"assert.h"
#include
"stdbool.h"
#include
"stdlib.h"
#include
"time.h"
#include
"stdio.h"
#include
"string.h"
extern
void
dap_enc_aes_tests_run
(
void
);
\ No newline at end of file
extern
void
dap_enc_aes_tests_run
(
void
);
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