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
Brian Smith
nettle
Commits
d2af04a6
Commit
d2af04a6
authored
Feb 07, 2004
by
Niels Möller
Browse files
(xalloc): New function. Use instead
of alloca, for better portability. Rev: src/nettle/examples/nettle-benchmark.c:1.11
parent
a45c20c8
Changes
1
Hide whitespace changes
Inline
Side-by-side
examples/nettle-benchmark.c
View file @
d2af04a6
...
...
@@ -169,12 +169,25 @@ display(const char *name, const char *mode,
1
/
(
speed
*
1048576
.
0
/
BENCH_BLOCK
));
}
static
void
*
xalloc
(
size_t
size
)
{
void
*
p
=
malloc
(
size
);
if
(
!
p
)
{
fprintf
(
stderr
,
"Virtual memory exhausted.
\n
"
);
abort
();
}
return
p
;
}
static
void
time_hash
(
const
struct
nettle_hash
*
hash
)
{
static
uint8_t
data
[
BENCH_BLOCK
];
struct
bench_hash_info
info
;
info
.
ctx
=
alloc
a
(
hash
->
context_size
);
info
.
ctx
=
x
alloc
(
hash
->
context_size
);
info
.
update
=
hash
->
update
;
info
.
data
=
data
;
...
...
@@ -183,13 +196,15 @@ time_hash(const struct nettle_hash *hash)
display
(
hash
->
name
,
"Update"
,
time_function
(
bench_hash
,
&
info
));
free
(
info
.
ctx
);
}
static
void
time_cipher
(
const
struct
nettle_cipher
*
cipher
)
{
void
*
ctx
=
alloc
a
(
cipher
->
context_size
);
uint8_t
*
key
=
alloc
a
(
cipher
->
key_size
);
void
*
ctx
=
x
alloc
(
cipher
->
context_size
);
uint8_t
*
key
=
x
alloc
(
cipher
->
key_size
);
static
uint8_t
data
[
BENCH_BLOCK
];
...
...
@@ -226,7 +241,7 @@ time_cipher(const struct nettle_cipher *cipher)
if
(
cipher
->
block_size
)
{
uint8_t
*
iv
=
alloc
a
(
cipher
->
block_size
);
uint8_t
*
iv
=
x
alloc
(
cipher
->
block_size
);
/* Do CBC mode */
{
...
...
@@ -260,7 +275,10 @@ time_cipher(const struct nettle_cipher *cipher)
display
(
cipher
->
name
,
"CBC decrypt"
,
time_function
(
bench_cbc_decrypt
,
&
info
));
}
free
(
iv
);
}
free
(
ctx
);
free
(
key
);
}
#if HAVE_LIBCRYPTO
...
...
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