Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Dmitry Baryshkov
nettle
Commits
6ce79cc7
Commit
6ce79cc7
authored
Jan 08, 2018
by
Niels Möller
Browse files
Benchmark in-place operation separately, for cbc_decrypt and ctr_crypt.
parent
140156d1
Changes
2
Hide whitespace changes
Inline
Side-by-side
ChangeLog
View file @
6ce79cc7
2018-01-08 Niels Möller <nisse@lysator.liu.se>
* examples/nettle-benchmark.c (time_cipher): Benchmark in-place
operation separately, for cbc_decrypt and ctr_crypt.
* cbc.c (cbc_decrypt): For in-place operation (src == dst case),
eliminate use of src variable.
* cfb.c (cfb_decrypt): Likewise.
...
...
examples/nettle-benchmark.c
View file @
6ce79cc7
...
...
@@ -209,8 +209,9 @@ struct bench_cbc_info
void
*
ctx
;
nettle_cipher_func
*
crypt
;
uint8_t
*
data
;
const
uint8_t
*
src
;
uint8_t
*
dst
;
unsigned
block_size
;
uint8_t
*
iv
;
};
...
...
@@ -221,7 +222,7 @@ bench_cbc_encrypt(void *arg)
struct
bench_cbc_info
*
info
=
arg
;
cbc_encrypt
(
info
->
ctx
,
info
->
crypt
,
info
->
block_size
,
info
->
iv
,
BENCH_BLOCK
,
info
->
d
ata
,
info
->
data
);
BENCH_BLOCK
,
info
->
d
st
,
info
->
src
);
}
static
void
...
...
@@ -230,7 +231,7 @@ bench_cbc_decrypt(void *arg)
struct
bench_cbc_info
*
info
=
arg
;
cbc_decrypt
(
info
->
ctx
,
info
->
crypt
,
info
->
block_size
,
info
->
iv
,
BENCH_BLOCK
,
info
->
d
ata
,
info
->
data
);
BENCH_BLOCK
,
info
->
d
st
,
info
->
src
);
}
static
void
...
...
@@ -239,7 +240,7 @@ bench_ctr(void *arg)
struct
bench_cbc_info
*
info
=
arg
;
ctr_crypt
(
info
->
ctx
,
info
->
crypt
,
info
->
block_size
,
info
->
iv
,
BENCH_BLOCK
,
info
->
d
ata
,
info
->
data
);
BENCH_BLOCK
,
info
->
d
st
,
info
->
src
);
}
struct
bench_aead_info
...
...
@@ -298,7 +299,7 @@ init_nonce(unsigned length,
static
void
header
(
void
)
{
printf
(
"%18s %1
1
s Mbyte/s%s
\n
"
,
printf
(
"%18s %1
2
s Mbyte/s%s
\n
"
,
"Algorithm"
,
"mode"
,
frequency
>
0
.
0
?
" cycles/byte cycles/block"
:
""
);
}
...
...
@@ -307,7 +308,7 @@ static void
display
(
const
char
*
name
,
const
char
*
mode
,
unsigned
block_size
,
double
time
)
{
printf
(
"%18s %1
1
s %7.2f"
,
printf
(
"%18s %1
2
s %7.2f"
,
name
,
mode
,
BENCH_BLOCK
/
(
time
*
1048576
.
0
));
if
(
frequency
>
0
.
0
)
...
...
@@ -478,11 +479,13 @@ time_cipher(const struct nettle_cipher *cipher)
void
*
ctx
=
xalloc
(
cipher
->
context_size
);
uint8_t
*
key
=
xalloc
(
cipher
->
key_size
);
static
uint8_t
src_data
[
BENCH_BLOCK
];
static
uint8_t
data
[
BENCH_BLOCK
];
printf
(
"
\n
"
);
init_data
(
data
);
init_data
(
src_data
);
{
/* Decent initializers are a GNU extension, so don't use it here. */
...
...
@@ -520,7 +523,8 @@ time_cipher(const struct nettle_cipher *cipher)
struct
bench_cbc_info
info
;
info
.
ctx
=
ctx
;
info
.
crypt
=
cipher
->
encrypt
;
info
.
data
=
data
;
info
.
src
=
src_data
;
info
.
dst
=
data
;
info
.
block_size
=
cipher
->
block_size
;
info
.
iv
=
iv
;
...
...
@@ -536,7 +540,8 @@ time_cipher(const struct nettle_cipher *cipher)
struct
bench_cbc_info
info
;
info
.
ctx
=
ctx
;
info
.
crypt
=
cipher
->
decrypt
;
info
.
data
=
data
;
info
.
src
=
src_data
;
info
.
dst
=
data
;
info
.
block_size
=
cipher
->
block_size
;
info
.
iv
=
iv
;
...
...
@@ -546,6 +551,12 @@ time_cipher(const struct nettle_cipher *cipher)
display
(
cipher
->
name
,
"CBC decrypt"
,
cipher
->
block_size
,
time_function
(
bench_cbc_decrypt
,
&
info
));
memset
(
iv
,
0
,
cipher
->
block_size
);
info
.
src
=
data
;
display
(
cipher
->
name
,
" (in-place)"
,
cipher
->
block_size
,
time_function
(
bench_cbc_decrypt
,
&
info
));
}
/* Do CTR mode */
...
...
@@ -553,7 +564,8 @@ time_cipher(const struct nettle_cipher *cipher)
struct
bench_cbc_info
info
;
info
.
ctx
=
ctx
;
info
.
crypt
=
cipher
->
encrypt
;
info
.
data
=
data
;
info
.
src
=
src_data
;
info
.
dst
=
data
;
info
.
block_size
=
cipher
->
block_size
;
info
.
iv
=
iv
;
...
...
@@ -563,6 +575,12 @@ time_cipher(const struct nettle_cipher *cipher)
display
(
cipher
->
name
,
"CTR"
,
cipher
->
block_size
,
time_function
(
bench_ctr
,
&
info
));
memset
(
iv
,
0
,
cipher
->
block_size
);
info
.
src
=
data
;
display
(
cipher
->
name
,
" (in-place)"
,
cipher
->
block_size
,
time_function
(
bench_ctr
,
&
info
));
}
free
(
iv
);
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment