static int cast_test(void)
{
- static char *hex = "0123456789ABCDEF";
long l;
- int i, z, testresult = 1;
+ int z, testresult = 1;
CAST_KEY key, key_b;
unsigned char out_a[16], out_b[16];
for (z = 0; z < 3; z++) {
CAST_set_key(&key, k_len[z], k);
CAST_ecb_encrypt(in, out, &key, CAST_ENCRYPT);
- if (!TEST_mem_eq(out, sizeof(c[z]), c[z], sizeof(c[z])))
+ if (!TEST_mem_eq(out, sizeof(c[z]), c[z], sizeof(c[z]))) {
+ TEST_info("CAST_ENCRYPT iteration %d failed (len=%d)", z, k_len[z]);
testresult = 0;
+ }
CAST_ecb_encrypt(out, out, &key, CAST_DECRYPT);
- if (!TEST_mem_eq(out, sizeof(in), in, sizeof(in)))
+ if (!TEST_mem_eq(out, sizeof(in), in, sizeof(in))) {
+ TEST_info("CAST_DECRYPT iteration %d failed (len=%d)", z, k_len[z]);
testresult = 0;
+ }
}
- if (testresult)
- TEST_info("ecb cast5 ok");
-
memcpy(out_a, in_a, sizeof(in_a));
memcpy(out_b, in_b, sizeof(in_b));
- i = 1;
for (l = 0; l < 1000000L; l++) {
CAST_set_key(&key_b, 16, out_b);
CAST_ecb_encrypt(&(out_a[0]), &(out_a[0]), &key_b, CAST_ENCRYPT);
CAST_set_key(&key, 16, out_a);
CAST_ecb_encrypt(&(out_b[0]), &(out_b[0]), &key, CAST_ENCRYPT);
CAST_ecb_encrypt(&(out_b[8]), &(out_b[8]), &key, CAST_ENCRYPT);
- if ((l & 0xffff) == 0xffff) {
- TEST_info("%c", hex[i & 0x0f]);
- i++;
- }
}
if (!TEST_mem_eq(out_a, sizeof(c_a), c_a, sizeof(c_a))
#include "test_main_custom.h"
#include "testutil.h"
-static int test_certs(BIO *fp)
+
+/* List of files, from argv */
+static char **files;
+
+static int test_certs(int num)
{
int count;
char *name = 0;
typedef X509 *(*d2i_X509_t)(X509 **, const unsigned char **, long);
typedef int (*i2d_X509_t)(X509 *, unsigned char **);
int err = 0;
+ BIO *fp = BIO_new_file(files[num], "r");
+
+ if (!TEST_ptr(fp))
+ return 0;
for (count = 0;
!err && PEM_read_bio(fp, &name, &header, &data, &len);
OPENSSL_free(header);
OPENSSL_free(data);
}
+ BIO_free(fp);
if (ERR_GET_REASON(ERR_peek_last_error()) == PEM_R_NO_START_LINE) {
/* Reached end of PEM file */
int test_main(int argc, char *argv[])
{
- BIO *bio_err;
- int ret = 1;
-
- if (argc < 2)
+ if (argc < 2) {
TEST_error("usage: %s certfile...", argv[0]);
-
- bio_err = BIO_new_fp(stderr, BIO_NOCLOSE | BIO_FP_TEXT);
-
- for (argv++; *argv; argv++) {
- BIO *f = BIO_new_file(*argv, "r");
- int ok;
-
- TEST_check(f != NULL);
- ok = test_certs(f);
- BIO_free(f);
-
- if (!TEST_int_eq(ok, 1))
- break;
- ret = 0;
+ return 0;
}
- BIO_free(bio_err);
- return ret;
+
+ files = &argv[1];
+ ADD_ALL_TESTS(test_certs, argc - 1);
+ return run_tests(argv[0]);
}