1*e0c4386eSCy Schubert /*
2*e0c4386eSCy Schubert * Copyright 2016-2020 The OpenSSL Project Authors. All Rights Reserved.
3*e0c4386eSCy Schubert *
4*e0c4386eSCy Schubert * Licensed under the Apache License 2.0 (the "License"). You may not use
5*e0c4386eSCy Schubert * this file except in compliance with the License. You can obtain a copy
6*e0c4386eSCy Schubert * in the file LICENSE in the source distribution or at
7*e0c4386eSCy Schubert * https://www.openssl.org/source/license.html
8*e0c4386eSCy Schubert */
9*e0c4386eSCy Schubert
10*e0c4386eSCy Schubert /* Internal tests for the mdc2 module */
11*e0c4386eSCy Schubert
12*e0c4386eSCy Schubert /*
13*e0c4386eSCy Schubert * MDC2 low level APIs are deprecated for public use, but still ok for
14*e0c4386eSCy Schubert * internal use.
15*e0c4386eSCy Schubert */
16*e0c4386eSCy Schubert #include "internal/deprecated.h"
17*e0c4386eSCy Schubert
18*e0c4386eSCy Schubert #include <stdio.h>
19*e0c4386eSCy Schubert #include <string.h>
20*e0c4386eSCy Schubert
21*e0c4386eSCy Schubert #include <openssl/mdc2.h>
22*e0c4386eSCy Schubert #include "testutil.h"
23*e0c4386eSCy Schubert #include "internal/nelem.h"
24*e0c4386eSCy Schubert
25*e0c4386eSCy Schubert typedef struct {
26*e0c4386eSCy Schubert const char *input;
27*e0c4386eSCy Schubert const unsigned char expected[MDC2_DIGEST_LENGTH];
28*e0c4386eSCy Schubert } TESTDATA;
29*e0c4386eSCy Schubert
30*e0c4386eSCy Schubert
31*e0c4386eSCy Schubert /**********************************************************************
32*e0c4386eSCy Schubert *
33*e0c4386eSCy Schubert * Test driver
34*e0c4386eSCy Schubert *
35*e0c4386eSCy Schubert ***/
36*e0c4386eSCy Schubert
37*e0c4386eSCy Schubert static TESTDATA tests[] = {
38*e0c4386eSCy Schubert {
39*e0c4386eSCy Schubert "Now is the time for all ",
40*e0c4386eSCy Schubert {
41*e0c4386eSCy Schubert 0x42, 0xE5, 0x0C, 0xD2, 0x24, 0xBA, 0xCE, 0xBA,
42*e0c4386eSCy Schubert 0x76, 0x0B, 0xDD, 0x2B, 0xD4, 0x09, 0x28, 0x1A
43*e0c4386eSCy Schubert }
44*e0c4386eSCy Schubert }
45*e0c4386eSCy Schubert };
46*e0c4386eSCy Schubert
47*e0c4386eSCy Schubert /**********************************************************************
48*e0c4386eSCy Schubert *
49*e0c4386eSCy Schubert * Test of mdc2 internal functions
50*e0c4386eSCy Schubert *
51*e0c4386eSCy Schubert ***/
52*e0c4386eSCy Schubert
test_mdc2(int idx)53*e0c4386eSCy Schubert static int test_mdc2(int idx)
54*e0c4386eSCy Schubert {
55*e0c4386eSCy Schubert unsigned char md[MDC2_DIGEST_LENGTH];
56*e0c4386eSCy Schubert MDC2_CTX c;
57*e0c4386eSCy Schubert const TESTDATA testdata = tests[idx];
58*e0c4386eSCy Schubert
59*e0c4386eSCy Schubert MDC2_Init(&c);
60*e0c4386eSCy Schubert MDC2_Update(&c, (const unsigned char *)testdata.input,
61*e0c4386eSCy Schubert strlen(testdata.input));
62*e0c4386eSCy Schubert MDC2_Final(&(md[0]), &c);
63*e0c4386eSCy Schubert
64*e0c4386eSCy Schubert if (!TEST_mem_eq(testdata.expected, MDC2_DIGEST_LENGTH,
65*e0c4386eSCy Schubert md, MDC2_DIGEST_LENGTH)) {
66*e0c4386eSCy Schubert TEST_info("mdc2 test %d: unexpected output", idx);
67*e0c4386eSCy Schubert return 0;
68*e0c4386eSCy Schubert }
69*e0c4386eSCy Schubert
70*e0c4386eSCy Schubert return 1;
71*e0c4386eSCy Schubert }
72*e0c4386eSCy Schubert
setup_tests(void)73*e0c4386eSCy Schubert int setup_tests(void)
74*e0c4386eSCy Schubert {
75*e0c4386eSCy Schubert ADD_ALL_TESTS(test_mdc2, OSSL_NELEM(tests));
76*e0c4386eSCy Schubert return 1;
77*e0c4386eSCy Schubert }
78