/*
- * Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 2016-2020 The OpenSSL Project Authors. All Rights Reserved.
*
- * Licensed under the OpenSSL license (the "License"). You may not use
+ * Licensed under the Apache License 2.0 (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
/* Internal tests for the mdc2 module */
+/*
+ * MDC2 low level APIs are deprecated for public use, but still ok for
+ * internal use.
+ */
+#include "internal/deprecated.h"
+
#include <stdio.h>
#include <string.h>
#include <openssl/mdc2.h>
#include "testutil.h"
-#include "e_os.h"
+#include "internal/nelem.h"
typedef struct {
const char *input;
const unsigned char expected[MDC2_DIGEST_LENGTH];
} TESTDATA;
-typedef struct {
- const char *case_name;
- int num;
- const TESTDATA *data;
-} SIMPLE_FIXTURE;
-
-/**********************************************************************
- *
- * Test of mdc2 internal functions
- *
- ***/
-
-static SIMPLE_FIXTURE setup_mdc2(const char *const test_case_name)
-{
- SIMPLE_FIXTURE fixture;
- fixture.case_name = test_case_name;
- return fixture;
-}
-
-static int execute_mdc2(SIMPLE_FIXTURE fixture)
-{
- unsigned char md[MDC2_DIGEST_LENGTH];
- MDC2_CTX c;
-
- MDC2_Init(&c);
- MDC2_Update(&c, (const unsigned char *)fixture.data->input,
- strlen(fixture.data->input));
- MDC2_Final(&(md[0]), &c);
-
- if (memcmp(fixture.data->expected, md, MDC2_DIGEST_LENGTH)) {
- fprintf(stderr, "mdc2 test %d: unexpected output\n", fixture.num);
- return 0;
- }
-
- return 1;
-}
-
-static void teardown_mdc2(SIMPLE_FIXTURE fixture)
-{
- ERR_print_errors_fp(stderr);
-}
/**********************************************************************
*
}
};
-static int drive_tests(int idx)
+/**********************************************************************
+ *
+ * Test of mdc2 internal functions
+ *
+ ***/
+
+static int test_mdc2(int idx)
{
- SETUP_TEST_FIXTURE(SIMPLE_FIXTURE, setup_mdc2);
- fixture.num = idx;
- fixture.data = &tests[idx];
- EXECUTE_TEST(execute_mdc2, teardown_mdc2);
+ unsigned char md[MDC2_DIGEST_LENGTH];
+ MDC2_CTX c;
+ const TESTDATA testdata = tests[idx];
+
+ MDC2_Init(&c);
+ MDC2_Update(&c, (const unsigned char *)testdata.input,
+ strlen(testdata.input));
+ MDC2_Final(&(md[0]), &c);
+
+ if (!TEST_mem_eq(testdata.expected, MDC2_DIGEST_LENGTH,
+ md, MDC2_DIGEST_LENGTH)) {
+ TEST_info("mdc2 test %d: unexpected output", idx);
+ return 0;
+ }
+
+ return 1;
}
-int main(int argc, char **argv)
+int setup_tests(void)
{
- ADD_ALL_TESTS(drive_tests, OSSL_NELEM(tests));
-
- return run_tests(argv[0]);
+ ADD_ALL_TESTS(test_mdc2, OSSL_NELEM(tests));
+ return 1;
}