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:
Dag-Erling Smørgrav 2015-08-19 11:27:48 +00:00 committed by des
parent cbc2cd1112
commit 8351719b84
14 changed files with 21 additions and 98 deletions

View file

@ -30,7 +30,6 @@
#include "cryb/impl.h"
#include <err.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>

View file

@ -30,7 +30,6 @@
#include "cryb/impl.h"
#include <err.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>

View file

@ -30,7 +30,6 @@
#include "cryb/impl.h"
#include <err.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>

View file

@ -30,7 +30,6 @@
#include "cryb/impl.h"
#include <err.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>

View file

@ -30,7 +30,6 @@
#include "cryb/impl.h"
#include <err.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>

View file

@ -30,7 +30,6 @@
#include "cryb/impl.h"
#include <err.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
@ -174,23 +173,17 @@ t_md2_perf(char **desc, void *arg)
struct timespec ts, te;
unsigned long ns;
uint8_t digest[MD2_DIGEST_LEN];
char *msg, *comment;
size_t msglen = *(size_t *)arg;
char msg[msglen];
if ((msg = calloc(1, msglen)) == NULL)
err(1, "calloc()");
clock_gettime(CLOCK_MONOTONIC, &ts);
for (int i = 0; i < T_PERF_ITERATIONS; ++i)
t_md2_complete(msg, msglen, digest);
clock_gettime(CLOCK_MONOTONIC, &te);
free(msg);
ns = te.tv_sec * 1000000000LU + te.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);
if (comment == NULL)
err(1, "asprintf()");
*desc = comment;
return (1);
}

View file

@ -30,7 +30,6 @@
#include "cryb/impl.h"
#include <err.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
@ -190,23 +189,17 @@ t_md4_perf(char **desc, void *arg)
struct timespec ts, te;
unsigned long ns;
uint8_t digest[MD4_DIGEST_LEN];
char *msg, *comment;
size_t msglen = *(size_t *)arg;
char msg[msglen];
if ((msg = calloc(1, msglen)) == NULL)
err(1, "calloc()");
clock_gettime(CLOCK_MONOTONIC, &ts);
for (int i = 0; i < T_PERF_ITERATIONS; ++i)
t_md4_complete(msg, msglen, digest);
clock_gettime(CLOCK_MONOTONIC, &te);
free(msg);
ns = te.tv_sec * 1000000000LU + te.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);
if (comment == NULL)
err(1, "asprintf()");
*desc = comment;
return (1);
}

View file

@ -30,7 +30,6 @@
#include "cryb/impl.h"
#include <err.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
@ -190,23 +189,17 @@ t_md5_perf(char **desc, void *arg)
struct timespec ts, te;
unsigned long ns;
uint8_t digest[MD5_DIGEST_LEN];
char *msg, *comment;
size_t msglen = *(size_t *)arg;
char msg[msglen];
if ((msg = calloc(1, msglen)) == NULL)
err(1, "calloc()");
clock_gettime(CLOCK_MONOTONIC, &ts);
for (int i = 0; i < T_PERF_ITERATIONS; ++i)
t_md5_complete(msg, msglen, digest);
clock_gettime(CLOCK_MONOTONIC, &te);
free(msg);
ns = te.tv_sec * 1000000000LU + te.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);
if (comment == NULL)
err(1, "asprintf()");
*desc = comment;
return (1);
}

View file

@ -30,7 +30,6 @@
#include "cryb/impl.h"
#include <err.h>
#include <stdint.h>
#include <stdio.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;
uint8_t digest[SHA1_DIGEST_LEN];
char *msg;
char msg[1000000];
if (vector->msg) {
t_sha1_complete(vector->msg, strlen(vector->msg), digest);
} else {
/* special case for FIPS test vector 3 */
if ((msg = malloc(1000000)) == NULL)
err(1, "malloc()");
memset(msg, 'a', 1000000);
t_sha1_complete(msg, 1000000, digest);
free(msg);
}
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;
unsigned long ns;
uint8_t digest[SHA1_DIGEST_LEN];
char *msg, *comment;
size_t msglen = *(size_t *)arg;
char msg[msglen];
if ((msg = calloc(1, msglen)) == NULL)
err(1, "calloc()");
clock_gettime(CLOCK_MONOTONIC, &ts);
for (int i = 0; i < T_PERF_ITERATIONS; ++i)
t_sha1_complete(msg, msglen, digest);
clock_gettime(CLOCK_MONOTONIC, &te);
free(msg);
ns = te.tv_sec * 1000000000LU + te.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);
if (comment == NULL)
err(1, "asprintf()");
*desc = comment;
return (1);
}

View file

@ -30,7 +30,6 @@
#include "cryb/impl.h"
#include <err.h>
#include <stdint.h>
#include <stdio.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;
uint8_t digest[SHA224_DIGEST_LEN];
char *msg;
char msg[1000000];
if (vector->msg) {
t_sha224_complete(vector->msg, strlen(vector->msg), digest);
} else {
/* special case for FIPS test vector 3 */
if ((msg = malloc(1000000)) == NULL)
err(1, "malloc()");
memset(msg, 'a', 1000000);
t_sha224_complete(msg, 1000000, digest);
free(msg);
}
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;
unsigned long ns;
uint8_t digest[SHA224_DIGEST_LEN];
char *msg, *comment;
size_t msglen = *(size_t *)arg;
char msg[msglen];
if ((msg = calloc(1, msglen)) == NULL)
err(1, "calloc()");
clock_gettime(CLOCK_MONOTONIC, &ts);
for (int i = 0; i < T_PERF_ITERATIONS; ++i)
t_sha224_complete(msg, msglen, digest);
clock_gettime(CLOCK_MONOTONIC, &te);
free(msg);
ns = te.tv_sec * 1000000000LU + te.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);
if (comment == NULL)
err(1, "asprintf()");
*desc = comment;
return (1);
}

View file

@ -30,7 +30,6 @@
#include "cryb/impl.h"
#include <err.h>
#include <stdint.h>
#include <stdio.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;
uint8_t digest[SHA256_DIGEST_LEN];
char *msg;
char msg[1000000];
if (vector->msg) {
t_sha256_complete(vector->msg, strlen(vector->msg), digest);
} else {
/* special case for FIPS test vector 3 */
if ((msg = malloc(1000000)) == NULL)
err(1, "malloc()");
memset(msg, 'a', 1000000);
t_sha256_complete(msg, 1000000, digest);
free(msg);
}
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;
unsigned long ns;
uint8_t digest[SHA256_DIGEST_LEN];
char *msg, *comment;
size_t msglen = *(size_t *)arg;
char msg[msglen];
if ((msg = calloc(1, msglen)) == NULL)
err(1, "calloc()");
clock_gettime(CLOCK_MONOTONIC, &ts);
for (int i = 0; i < T_PERF_ITERATIONS; ++i)
t_sha256_complete(msg, msglen, digest);
clock_gettime(CLOCK_MONOTONIC, &te);
free(msg);
ns = te.tv_sec * 1000000000LU + te.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);
if (comment == NULL)
err(1, "asprintf()");
*desc = comment;
return (1);
}

View file

@ -30,7 +30,6 @@
#include "cryb/impl.h"
#include <err.h>
#include <stdint.h>
#include <stdio.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;
uint8_t digest[SHA384_DIGEST_LEN];
char *msg;
char msg[1000000];
if (vector->msg) {
t_sha384_complete(vector->msg, strlen(vector->msg), digest);
} else {
/* special case for FIPS test vector 3 */
if ((msg = malloc(1000000)) == NULL)
err(1, "malloc()");
memset(msg, 'a', 1000000);
t_sha384_complete(msg, 1000000, digest);
free(msg);
}
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;
unsigned long ns;
uint8_t digest[SHA384_DIGEST_LEN];
char *msg, *comment;
size_t msglen = *(size_t *)arg;
char msg[msglen];
if ((msg = calloc(1, msglen)) == NULL)
err(1, "calloc()");
clock_gettime(CLOCK_MONOTONIC, &ts);
for (int i = 0; i < T_PERF_ITERATIONS; ++i)
t_sha384_complete(msg, msglen, digest);
clock_gettime(CLOCK_MONOTONIC, &te);
free(msg);
ns = te.tv_sec * 1000000000LU + te.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);
if (comment == NULL)
err(1, "asprintf()");
*desc = comment;
return (1);
}

View file

@ -30,7 +30,6 @@
#include "cryb/impl.h"
#include <err.h>
#include <stdint.h>
#include <stdio.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;
uint8_t digest[SHA512_DIGEST_LEN];
char *msg;
char msg[1000000];
if (vector->msg) {
t_sha512_complete(vector->msg, strlen(vector->msg), digest);
} else {
/* special case for FIPS test vector 3 */
if ((msg = malloc(1000000)) == NULL)
err(1, "malloc()");
memset(msg, 'a', 1000000);
t_sha512_complete(msg, 1000000, digest);
free(msg);
}
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;
unsigned long ns;
uint8_t digest[SHA512_DIGEST_LEN];
char *msg, *comment;
size_t msglen = *(size_t *)arg;
char msg[msglen];
if ((msg = calloc(1, msglen)) == NULL)
err(1, "calloc()");
clock_gettime(CLOCK_MONOTONIC, &ts);
for (int i = 0; i < T_PERF_ITERATIONS; ++i)
t_sha512_complete(msg, msglen, digest);
clock_gettime(CLOCK_MONOTONIC, &te);
free(msg);
ns = te.tv_sec * 1000000000LU + te.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);
if (comment == NULL)
err(1, "asprintf()");
*desc = comment;
return (1);
}

View file

@ -29,7 +29,6 @@
#include "cryb/impl.h"
#include <err.h>
#include <inttypes.h>
#include <stdarg.h>
#include <stdint.h>