mirror of
https://github.com/cryb-to/cryb-to.git
synced 2025-01-27 14:11:10 +00:00
Simplify test cases by a) using C99 VLAs and b) removing error checks for
allocation failures which are either harmless (e.g. failing to allocate the test description string) or will trigger a segfault which the driver now catches, allowing subequent test cases to run.
This commit is contained in:
parent
cbc2cd1112
commit
8351719b84
14 changed files with 21 additions and 98 deletions
|
@ -30,7 +30,6 @@
|
||||||
|
|
||||||
#include "cryb/impl.h"
|
#include "cryb/impl.h"
|
||||||
|
|
||||||
#include <err.h>
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
|
@ -30,7 +30,6 @@
|
||||||
|
|
||||||
#include "cryb/impl.h"
|
#include "cryb/impl.h"
|
||||||
|
|
||||||
#include <err.h>
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
|
@ -30,7 +30,6 @@
|
||||||
|
|
||||||
#include "cryb/impl.h"
|
#include "cryb/impl.h"
|
||||||
|
|
||||||
#include <err.h>
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
|
@ -30,7 +30,6 @@
|
||||||
|
|
||||||
#include "cryb/impl.h"
|
#include "cryb/impl.h"
|
||||||
|
|
||||||
#include <err.h>
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
|
@ -30,7 +30,6 @@
|
||||||
|
|
||||||
#include "cryb/impl.h"
|
#include "cryb/impl.h"
|
||||||
|
|
||||||
#include <err.h>
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
11
t/t_md2.c
11
t/t_md2.c
|
@ -30,7 +30,6 @@
|
||||||
|
|
||||||
#include "cryb/impl.h"
|
#include "cryb/impl.h"
|
||||||
|
|
||||||
#include <err.h>
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
@ -174,23 +173,17 @@ t_md2_perf(char **desc, void *arg)
|
||||||
struct timespec ts, te;
|
struct timespec ts, te;
|
||||||
unsigned long ns;
|
unsigned long ns;
|
||||||
uint8_t digest[MD2_DIGEST_LEN];
|
uint8_t digest[MD2_DIGEST_LEN];
|
||||||
char *msg, *comment;
|
|
||||||
size_t msglen = *(size_t *)arg;
|
size_t msglen = *(size_t *)arg;
|
||||||
|
char msg[msglen];
|
||||||
|
|
||||||
if ((msg = calloc(1, msglen)) == NULL)
|
|
||||||
err(1, "calloc()");
|
|
||||||
clock_gettime(CLOCK_MONOTONIC, &ts);
|
clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||||
for (int i = 0; i < T_PERF_ITERATIONS; ++i)
|
for (int i = 0; i < T_PERF_ITERATIONS; ++i)
|
||||||
t_md2_complete(msg, msglen, digest);
|
t_md2_complete(msg, msglen, digest);
|
||||||
clock_gettime(CLOCK_MONOTONIC, &te);
|
clock_gettime(CLOCK_MONOTONIC, &te);
|
||||||
free(msg);
|
|
||||||
ns = te.tv_sec * 1000000000LU + te.tv_nsec;
|
ns = te.tv_sec * 1000000000LU + te.tv_nsec;
|
||||||
ns -= ts.tv_sec * 1000000000LU + ts.tv_nsec;
|
ns -= ts.tv_sec * 1000000000LU + ts.tv_nsec;
|
||||||
asprintf(&comment, "%zu bytes: %d iterations in %'lu ns",
|
asprintf(desc, "%zu bytes: %d iterations in %'lu ns",
|
||||||
msglen, T_PERF_ITERATIONS, ns);
|
msglen, T_PERF_ITERATIONS, ns);
|
||||||
if (comment == NULL)
|
|
||||||
err(1, "asprintf()");
|
|
||||||
*desc = comment;
|
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
11
t/t_md4.c
11
t/t_md4.c
|
@ -30,7 +30,6 @@
|
||||||
|
|
||||||
#include "cryb/impl.h"
|
#include "cryb/impl.h"
|
||||||
|
|
||||||
#include <err.h>
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
@ -190,23 +189,17 @@ t_md4_perf(char **desc, void *arg)
|
||||||
struct timespec ts, te;
|
struct timespec ts, te;
|
||||||
unsigned long ns;
|
unsigned long ns;
|
||||||
uint8_t digest[MD4_DIGEST_LEN];
|
uint8_t digest[MD4_DIGEST_LEN];
|
||||||
char *msg, *comment;
|
|
||||||
size_t msglen = *(size_t *)arg;
|
size_t msglen = *(size_t *)arg;
|
||||||
|
char msg[msglen];
|
||||||
|
|
||||||
if ((msg = calloc(1, msglen)) == NULL)
|
|
||||||
err(1, "calloc()");
|
|
||||||
clock_gettime(CLOCK_MONOTONIC, &ts);
|
clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||||
for (int i = 0; i < T_PERF_ITERATIONS; ++i)
|
for (int i = 0; i < T_PERF_ITERATIONS; ++i)
|
||||||
t_md4_complete(msg, msglen, digest);
|
t_md4_complete(msg, msglen, digest);
|
||||||
clock_gettime(CLOCK_MONOTONIC, &te);
|
clock_gettime(CLOCK_MONOTONIC, &te);
|
||||||
free(msg);
|
|
||||||
ns = te.tv_sec * 1000000000LU + te.tv_nsec;
|
ns = te.tv_sec * 1000000000LU + te.tv_nsec;
|
||||||
ns -= ts.tv_sec * 1000000000LU + ts.tv_nsec;
|
ns -= ts.tv_sec * 1000000000LU + ts.tv_nsec;
|
||||||
asprintf(&comment, "%zu bytes: %d iterations in %'lu ns",
|
asprintf(desc, "%zu bytes: %d iterations in %'lu ns",
|
||||||
msglen, T_PERF_ITERATIONS, ns);
|
msglen, T_PERF_ITERATIONS, ns);
|
||||||
if (comment == NULL)
|
|
||||||
err(1, "asprintf()");
|
|
||||||
*desc = comment;
|
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
11
t/t_md5.c
11
t/t_md5.c
|
@ -30,7 +30,6 @@
|
||||||
|
|
||||||
#include "cryb/impl.h"
|
#include "cryb/impl.h"
|
||||||
|
|
||||||
#include <err.h>
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
@ -190,23 +189,17 @@ t_md5_perf(char **desc, void *arg)
|
||||||
struct timespec ts, te;
|
struct timespec ts, te;
|
||||||
unsigned long ns;
|
unsigned long ns;
|
||||||
uint8_t digest[MD5_DIGEST_LEN];
|
uint8_t digest[MD5_DIGEST_LEN];
|
||||||
char *msg, *comment;
|
|
||||||
size_t msglen = *(size_t *)arg;
|
size_t msglen = *(size_t *)arg;
|
||||||
|
char msg[msglen];
|
||||||
|
|
||||||
if ((msg = calloc(1, msglen)) == NULL)
|
|
||||||
err(1, "calloc()");
|
|
||||||
clock_gettime(CLOCK_MONOTONIC, &ts);
|
clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||||
for (int i = 0; i < T_PERF_ITERATIONS; ++i)
|
for (int i = 0; i < T_PERF_ITERATIONS; ++i)
|
||||||
t_md5_complete(msg, msglen, digest);
|
t_md5_complete(msg, msglen, digest);
|
||||||
clock_gettime(CLOCK_MONOTONIC, &te);
|
clock_gettime(CLOCK_MONOTONIC, &te);
|
||||||
free(msg);
|
|
||||||
ns = te.tv_sec * 1000000000LU + te.tv_nsec;
|
ns = te.tv_sec * 1000000000LU + te.tv_nsec;
|
||||||
ns -= ts.tv_sec * 1000000000LU + ts.tv_nsec;
|
ns -= ts.tv_sec * 1000000000LU + ts.tv_nsec;
|
||||||
asprintf(&comment, "%zu bytes: %d iterations in %'lu ns",
|
asprintf(desc, "%zu bytes: %d iterations in %'lu ns",
|
||||||
msglen, T_PERF_ITERATIONS, ns);
|
msglen, T_PERF_ITERATIONS, ns);
|
||||||
if (comment == NULL)
|
|
||||||
err(1, "asprintf()");
|
|
||||||
*desc = comment;
|
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
16
t/t_sha1.c
16
t/t_sha1.c
|
@ -30,7 +30,6 @@
|
||||||
|
|
||||||
#include "cryb/impl.h"
|
#include "cryb/impl.h"
|
||||||
|
|
||||||
#include <err.h>
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
@ -137,17 +136,14 @@ t_sha1_vector(char **desc CRYB_UNUSED, void *arg)
|
||||||
{
|
{
|
||||||
struct t_vector *vector = (struct t_vector *)arg;
|
struct t_vector *vector = (struct t_vector *)arg;
|
||||||
uint8_t digest[SHA1_DIGEST_LEN];
|
uint8_t digest[SHA1_DIGEST_LEN];
|
||||||
char *msg;
|
char msg[1000000];
|
||||||
|
|
||||||
if (vector->msg) {
|
if (vector->msg) {
|
||||||
t_sha1_complete(vector->msg, strlen(vector->msg), digest);
|
t_sha1_complete(vector->msg, strlen(vector->msg), digest);
|
||||||
} else {
|
} else {
|
||||||
/* special case for FIPS test vector 3 */
|
/* special case for FIPS test vector 3 */
|
||||||
if ((msg = malloc(1000000)) == NULL)
|
|
||||||
err(1, "malloc()");
|
|
||||||
memset(msg, 'a', 1000000);
|
memset(msg, 'a', 1000000);
|
||||||
t_sha1_complete(msg, 1000000, digest);
|
t_sha1_complete(msg, 1000000, digest);
|
||||||
free(msg);
|
|
||||||
}
|
}
|
||||||
return (t_compare_mem(vector->digest, digest, SHA1_DIGEST_LEN));
|
return (t_compare_mem(vector->digest, digest, SHA1_DIGEST_LEN));
|
||||||
}
|
}
|
||||||
|
@ -186,23 +182,17 @@ t_sha1_perf(char **desc, void *arg)
|
||||||
struct timespec ts, te;
|
struct timespec ts, te;
|
||||||
unsigned long ns;
|
unsigned long ns;
|
||||||
uint8_t digest[SHA1_DIGEST_LEN];
|
uint8_t digest[SHA1_DIGEST_LEN];
|
||||||
char *msg, *comment;
|
|
||||||
size_t msglen = *(size_t *)arg;
|
size_t msglen = *(size_t *)arg;
|
||||||
|
char msg[msglen];
|
||||||
|
|
||||||
if ((msg = calloc(1, msglen)) == NULL)
|
|
||||||
err(1, "calloc()");
|
|
||||||
clock_gettime(CLOCK_MONOTONIC, &ts);
|
clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||||
for (int i = 0; i < T_PERF_ITERATIONS; ++i)
|
for (int i = 0; i < T_PERF_ITERATIONS; ++i)
|
||||||
t_sha1_complete(msg, msglen, digest);
|
t_sha1_complete(msg, msglen, digest);
|
||||||
clock_gettime(CLOCK_MONOTONIC, &te);
|
clock_gettime(CLOCK_MONOTONIC, &te);
|
||||||
free(msg);
|
|
||||||
ns = te.tv_sec * 1000000000LU + te.tv_nsec;
|
ns = te.tv_sec * 1000000000LU + te.tv_nsec;
|
||||||
ns -= ts.tv_sec * 1000000000LU + ts.tv_nsec;
|
ns -= ts.tv_sec * 1000000000LU + ts.tv_nsec;
|
||||||
asprintf(&comment, "%zu bytes: %d iterations in %'lu ns",
|
asprintf(desc, "%zu bytes: %d iterations in %'lu ns",
|
||||||
msglen, T_PERF_ITERATIONS, ns);
|
msglen, T_PERF_ITERATIONS, ns);
|
||||||
if (comment == NULL)
|
|
||||||
err(1, "asprintf()");
|
|
||||||
*desc = comment;
|
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
16
t/t_sha224.c
16
t/t_sha224.c
|
@ -30,7 +30,6 @@
|
||||||
|
|
||||||
#include "cryb/impl.h"
|
#include "cryb/impl.h"
|
||||||
|
|
||||||
#include <err.h>
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
@ -146,17 +145,14 @@ t_sha224_vector(char **desc CRYB_UNUSED, void *arg)
|
||||||
{
|
{
|
||||||
struct t_vector *vector = (struct t_vector *)arg;
|
struct t_vector *vector = (struct t_vector *)arg;
|
||||||
uint8_t digest[SHA224_DIGEST_LEN];
|
uint8_t digest[SHA224_DIGEST_LEN];
|
||||||
char *msg;
|
char msg[1000000];
|
||||||
|
|
||||||
if (vector->msg) {
|
if (vector->msg) {
|
||||||
t_sha224_complete(vector->msg, strlen(vector->msg), digest);
|
t_sha224_complete(vector->msg, strlen(vector->msg), digest);
|
||||||
} else {
|
} else {
|
||||||
/* special case for FIPS test vector 3 */
|
/* special case for FIPS test vector 3 */
|
||||||
if ((msg = malloc(1000000)) == NULL)
|
|
||||||
err(1, "malloc()");
|
|
||||||
memset(msg, 'a', 1000000);
|
memset(msg, 'a', 1000000);
|
||||||
t_sha224_complete(msg, 1000000, digest);
|
t_sha224_complete(msg, 1000000, digest);
|
||||||
free(msg);
|
|
||||||
}
|
}
|
||||||
return (t_compare_mem(vector->digest, digest, SHA224_DIGEST_LEN));
|
return (t_compare_mem(vector->digest, digest, SHA224_DIGEST_LEN));
|
||||||
}
|
}
|
||||||
|
@ -195,23 +191,17 @@ t_sha224_perf(char **desc, void *arg)
|
||||||
struct timespec ts, te;
|
struct timespec ts, te;
|
||||||
unsigned long ns;
|
unsigned long ns;
|
||||||
uint8_t digest[SHA224_DIGEST_LEN];
|
uint8_t digest[SHA224_DIGEST_LEN];
|
||||||
char *msg, *comment;
|
|
||||||
size_t msglen = *(size_t *)arg;
|
size_t msglen = *(size_t *)arg;
|
||||||
|
char msg[msglen];
|
||||||
|
|
||||||
if ((msg = calloc(1, msglen)) == NULL)
|
|
||||||
err(1, "calloc()");
|
|
||||||
clock_gettime(CLOCK_MONOTONIC, &ts);
|
clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||||
for (int i = 0; i < T_PERF_ITERATIONS; ++i)
|
for (int i = 0; i < T_PERF_ITERATIONS; ++i)
|
||||||
t_sha224_complete(msg, msglen, digest);
|
t_sha224_complete(msg, msglen, digest);
|
||||||
clock_gettime(CLOCK_MONOTONIC, &te);
|
clock_gettime(CLOCK_MONOTONIC, &te);
|
||||||
free(msg);
|
|
||||||
ns = te.tv_sec * 1000000000LU + te.tv_nsec;
|
ns = te.tv_sec * 1000000000LU + te.tv_nsec;
|
||||||
ns -= ts.tv_sec * 1000000000LU + ts.tv_nsec;
|
ns -= ts.tv_sec * 1000000000LU + ts.tv_nsec;
|
||||||
asprintf(&comment, "%zu bytes: %d iterations in %'lu ns",
|
asprintf(desc, "%zu bytes: %d iterations in %'lu ns",
|
||||||
msglen, T_PERF_ITERATIONS, ns);
|
msglen, T_PERF_ITERATIONS, ns);
|
||||||
if (comment == NULL)
|
|
||||||
err(1, "asprintf()");
|
|
||||||
*desc = comment;
|
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
16
t/t_sha256.c
16
t/t_sha256.c
|
@ -30,7 +30,6 @@
|
||||||
|
|
||||||
#include "cryb/impl.h"
|
#include "cryb/impl.h"
|
||||||
|
|
||||||
#include <err.h>
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
@ -142,17 +141,14 @@ t_sha256_vector(char **desc CRYB_UNUSED, void *arg)
|
||||||
{
|
{
|
||||||
struct t_vector *vector = (struct t_vector *)arg;
|
struct t_vector *vector = (struct t_vector *)arg;
|
||||||
uint8_t digest[SHA256_DIGEST_LEN];
|
uint8_t digest[SHA256_DIGEST_LEN];
|
||||||
char *msg;
|
char msg[1000000];
|
||||||
|
|
||||||
if (vector->msg) {
|
if (vector->msg) {
|
||||||
t_sha256_complete(vector->msg, strlen(vector->msg), digest);
|
t_sha256_complete(vector->msg, strlen(vector->msg), digest);
|
||||||
} else {
|
} else {
|
||||||
/* special case for FIPS test vector 3 */
|
/* special case for FIPS test vector 3 */
|
||||||
if ((msg = malloc(1000000)) == NULL)
|
|
||||||
err(1, "malloc()");
|
|
||||||
memset(msg, 'a', 1000000);
|
memset(msg, 'a', 1000000);
|
||||||
t_sha256_complete(msg, 1000000, digest);
|
t_sha256_complete(msg, 1000000, digest);
|
||||||
free(msg);
|
|
||||||
}
|
}
|
||||||
return (t_compare_mem(vector->digest, digest, SHA256_DIGEST_LEN));
|
return (t_compare_mem(vector->digest, digest, SHA256_DIGEST_LEN));
|
||||||
}
|
}
|
||||||
|
@ -191,23 +187,17 @@ t_sha256_perf(char **desc, void *arg)
|
||||||
struct timespec ts, te;
|
struct timespec ts, te;
|
||||||
unsigned long ns;
|
unsigned long ns;
|
||||||
uint8_t digest[SHA256_DIGEST_LEN];
|
uint8_t digest[SHA256_DIGEST_LEN];
|
||||||
char *msg, *comment;
|
|
||||||
size_t msglen = *(size_t *)arg;
|
size_t msglen = *(size_t *)arg;
|
||||||
|
char msg[msglen];
|
||||||
|
|
||||||
if ((msg = calloc(1, msglen)) == NULL)
|
|
||||||
err(1, "calloc()");
|
|
||||||
clock_gettime(CLOCK_MONOTONIC, &ts);
|
clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||||
for (int i = 0; i < T_PERF_ITERATIONS; ++i)
|
for (int i = 0; i < T_PERF_ITERATIONS; ++i)
|
||||||
t_sha256_complete(msg, msglen, digest);
|
t_sha256_complete(msg, msglen, digest);
|
||||||
clock_gettime(CLOCK_MONOTONIC, &te);
|
clock_gettime(CLOCK_MONOTONIC, &te);
|
||||||
free(msg);
|
|
||||||
ns = te.tv_sec * 1000000000LU + te.tv_nsec;
|
ns = te.tv_sec * 1000000000LU + te.tv_nsec;
|
||||||
ns -= ts.tv_sec * 1000000000LU + ts.tv_nsec;
|
ns -= ts.tv_sec * 1000000000LU + ts.tv_nsec;
|
||||||
asprintf(&comment, "%zu bytes: %d iterations in %'lu ns",
|
asprintf(desc, "%zu bytes: %d iterations in %'lu ns",
|
||||||
msglen, T_PERF_ITERATIONS, ns);
|
msglen, T_PERF_ITERATIONS, ns);
|
||||||
if (comment == NULL)
|
|
||||||
err(1, "asprintf()");
|
|
||||||
*desc = comment;
|
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
16
t/t_sha384.c
16
t/t_sha384.c
|
@ -30,7 +30,6 @@
|
||||||
|
|
||||||
#include "cryb/impl.h"
|
#include "cryb/impl.h"
|
||||||
|
|
||||||
#include <err.h>
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
@ -157,17 +156,14 @@ t_sha384_vector(char **desc CRYB_UNUSED, void *arg)
|
||||||
{
|
{
|
||||||
struct t_vector *vector = (struct t_vector *)arg;
|
struct t_vector *vector = (struct t_vector *)arg;
|
||||||
uint8_t digest[SHA384_DIGEST_LEN];
|
uint8_t digest[SHA384_DIGEST_LEN];
|
||||||
char *msg;
|
char msg[1000000];
|
||||||
|
|
||||||
if (vector->msg) {
|
if (vector->msg) {
|
||||||
t_sha384_complete(vector->msg, strlen(vector->msg), digest);
|
t_sha384_complete(vector->msg, strlen(vector->msg), digest);
|
||||||
} else {
|
} else {
|
||||||
/* special case for FIPS test vector 3 */
|
/* special case for FIPS test vector 3 */
|
||||||
if ((msg = malloc(1000000)) == NULL)
|
|
||||||
err(1, "malloc()");
|
|
||||||
memset(msg, 'a', 1000000);
|
memset(msg, 'a', 1000000);
|
||||||
t_sha384_complete(msg, 1000000, digest);
|
t_sha384_complete(msg, 1000000, digest);
|
||||||
free(msg);
|
|
||||||
}
|
}
|
||||||
return (t_compare_mem(vector->digest, digest, SHA384_DIGEST_LEN));
|
return (t_compare_mem(vector->digest, digest, SHA384_DIGEST_LEN));
|
||||||
}
|
}
|
||||||
|
@ -207,23 +203,17 @@ t_sha384_perf(char **desc, void *arg)
|
||||||
struct timespec ts, te;
|
struct timespec ts, te;
|
||||||
unsigned long ns;
|
unsigned long ns;
|
||||||
uint8_t digest[SHA384_DIGEST_LEN];
|
uint8_t digest[SHA384_DIGEST_LEN];
|
||||||
char *msg, *comment;
|
|
||||||
size_t msglen = *(size_t *)arg;
|
size_t msglen = *(size_t *)arg;
|
||||||
|
char msg[msglen];
|
||||||
|
|
||||||
if ((msg = calloc(1, msglen)) == NULL)
|
|
||||||
err(1, "calloc()");
|
|
||||||
clock_gettime(CLOCK_MONOTONIC, &ts);
|
clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||||
for (int i = 0; i < T_PERF_ITERATIONS; ++i)
|
for (int i = 0; i < T_PERF_ITERATIONS; ++i)
|
||||||
t_sha384_complete(msg, msglen, digest);
|
t_sha384_complete(msg, msglen, digest);
|
||||||
clock_gettime(CLOCK_MONOTONIC, &te);
|
clock_gettime(CLOCK_MONOTONIC, &te);
|
||||||
free(msg);
|
|
||||||
ns = te.tv_sec * 1000000000LU + te.tv_nsec;
|
ns = te.tv_sec * 1000000000LU + te.tv_nsec;
|
||||||
ns -= ts.tv_sec * 1000000000LU + ts.tv_nsec;
|
ns -= ts.tv_sec * 1000000000LU + ts.tv_nsec;
|
||||||
asprintf(&comment, "%zu bytes: %d iterations in %'lu ns",
|
asprintf(desc, "%zu bytes: %d iterations in %'lu ns",
|
||||||
msglen, T_PERF_ITERATIONS, ns);
|
msglen, T_PERF_ITERATIONS, ns);
|
||||||
if (comment == NULL)
|
|
||||||
err(1, "asprintf()");
|
|
||||||
*desc = comment;
|
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
16
t/t_sha512.c
16
t/t_sha512.c
|
@ -30,7 +30,6 @@
|
||||||
|
|
||||||
#include "cryb/impl.h"
|
#include "cryb/impl.h"
|
||||||
|
|
||||||
#include <err.h>
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
@ -167,17 +166,14 @@ t_sha512_vector(char **desc CRYB_UNUSED, void *arg)
|
||||||
{
|
{
|
||||||
struct t_vector *vector = (struct t_vector *)arg;
|
struct t_vector *vector = (struct t_vector *)arg;
|
||||||
uint8_t digest[SHA512_DIGEST_LEN];
|
uint8_t digest[SHA512_DIGEST_LEN];
|
||||||
char *msg;
|
char msg[1000000];
|
||||||
|
|
||||||
if (vector->msg) {
|
if (vector->msg) {
|
||||||
t_sha512_complete(vector->msg, strlen(vector->msg), digest);
|
t_sha512_complete(vector->msg, strlen(vector->msg), digest);
|
||||||
} else {
|
} else {
|
||||||
/* special case for FIPS test vector 3 */
|
/* special case for FIPS test vector 3 */
|
||||||
if ((msg = malloc(1000000)) == NULL)
|
|
||||||
err(1, "malloc()");
|
|
||||||
memset(msg, 'a', 1000000);
|
memset(msg, 'a', 1000000);
|
||||||
t_sha512_complete(msg, 1000000, digest);
|
t_sha512_complete(msg, 1000000, digest);
|
||||||
free(msg);
|
|
||||||
}
|
}
|
||||||
return (t_compare_mem(vector->digest, digest, SHA512_DIGEST_LEN));
|
return (t_compare_mem(vector->digest, digest, SHA512_DIGEST_LEN));
|
||||||
}
|
}
|
||||||
|
@ -217,23 +213,17 @@ t_sha512_perf(char **desc, void *arg)
|
||||||
struct timespec ts, te;
|
struct timespec ts, te;
|
||||||
unsigned long ns;
|
unsigned long ns;
|
||||||
uint8_t digest[SHA512_DIGEST_LEN];
|
uint8_t digest[SHA512_DIGEST_LEN];
|
||||||
char *msg, *comment;
|
|
||||||
size_t msglen = *(size_t *)arg;
|
size_t msglen = *(size_t *)arg;
|
||||||
|
char msg[msglen];
|
||||||
|
|
||||||
if ((msg = calloc(1, msglen)) == NULL)
|
|
||||||
err(1, "calloc()");
|
|
||||||
clock_gettime(CLOCK_MONOTONIC, &ts);
|
clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||||
for (int i = 0; i < T_PERF_ITERATIONS; ++i)
|
for (int i = 0; i < T_PERF_ITERATIONS; ++i)
|
||||||
t_sha512_complete(msg, msglen, digest);
|
t_sha512_complete(msg, msglen, digest);
|
||||||
clock_gettime(CLOCK_MONOTONIC, &te);
|
clock_gettime(CLOCK_MONOTONIC, &te);
|
||||||
free(msg);
|
|
||||||
ns = te.tv_sec * 1000000000LU + te.tv_nsec;
|
ns = te.tv_sec * 1000000000LU + te.tv_nsec;
|
||||||
ns -= ts.tv_sec * 1000000000LU + ts.tv_nsec;
|
ns -= ts.tv_sec * 1000000000LU + ts.tv_nsec;
|
||||||
asprintf(&comment, "%zu bytes: %d iterations in %'lu ns",
|
asprintf(desc, "%zu bytes: %d iterations in %'lu ns",
|
||||||
msglen, T_PERF_ITERATIONS, ns);
|
msglen, T_PERF_ITERATIONS, ns);
|
||||||
if (comment == NULL)
|
|
||||||
err(1, "asprintf()");
|
|
||||||
*desc = comment;
|
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,6 @@
|
||||||
|
|
||||||
#include "cryb/impl.h"
|
#include "cryb/impl.h"
|
||||||
|
|
||||||
#include <err.h>
|
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
Loading…
Reference in a new issue