xref: /netbsd-src/crypto/external/bsd/openssl/dist/test/mdc2_internal_test.c (revision b0d1725196a7921d003d2c66a14f186abda4176b)
113d40330Schristos /*
2*b0d17251Schristos  * Copyright 2016-2020 The OpenSSL Project Authors. All Rights Reserved.
313d40330Schristos  *
4*b0d17251Schristos  * Licensed under the Apache License 2.0 (the "License").  You may not use
513d40330Schristos  * this file except in compliance with the License.  You can obtain a copy
613d40330Schristos  * in the file LICENSE in the source distribution or at
713d40330Schristos  * https://www.openssl.org/source/license.html
813d40330Schristos  */
913d40330Schristos 
1013d40330Schristos /* Internal tests for the mdc2 module */
1113d40330Schristos 
12*b0d17251Schristos /*
13*b0d17251Schristos  * MDC2 low level APIs are deprecated for public use, but still ok for
14*b0d17251Schristos  * internal use.
15*b0d17251Schristos  */
16*b0d17251Schristos #include "internal/deprecated.h"
17*b0d17251Schristos 
1813d40330Schristos #include <stdio.h>
1913d40330Schristos #include <string.h>
2013d40330Schristos 
2113d40330Schristos #include <openssl/mdc2.h>
2213d40330Schristos #include "testutil.h"
2313d40330Schristos #include "internal/nelem.h"
2413d40330Schristos 
2513d40330Schristos typedef struct {
2613d40330Schristos     const char *input;
2713d40330Schristos     const unsigned char expected[MDC2_DIGEST_LENGTH];
2813d40330Schristos } TESTDATA;
2913d40330Schristos 
3013d40330Schristos 
3113d40330Schristos /**********************************************************************
3213d40330Schristos  *
3313d40330Schristos  * Test driver
3413d40330Schristos  *
3513d40330Schristos  ***/
3613d40330Schristos 
3713d40330Schristos static TESTDATA tests[] = {
3813d40330Schristos     {
3913d40330Schristos         "Now is the time for all ",
4013d40330Schristos         {
4113d40330Schristos             0x42, 0xE5, 0x0C, 0xD2, 0x24, 0xBA, 0xCE, 0xBA,
4213d40330Schristos             0x76, 0x0B, 0xDD, 0x2B, 0xD4, 0x09, 0x28, 0x1A
4313d40330Schristos         }
4413d40330Schristos     }
4513d40330Schristos };
4613d40330Schristos 
4713d40330Schristos /**********************************************************************
4813d40330Schristos  *
4913d40330Schristos  * Test of mdc2 internal functions
5013d40330Schristos  *
5113d40330Schristos  ***/
5213d40330Schristos 
test_mdc2(int idx)5313d40330Schristos static int test_mdc2(int idx)
5413d40330Schristos {
5513d40330Schristos     unsigned char md[MDC2_DIGEST_LENGTH];
5613d40330Schristos     MDC2_CTX c;
5713d40330Schristos     const TESTDATA testdata = tests[idx];
5813d40330Schristos 
5913d40330Schristos     MDC2_Init(&c);
6013d40330Schristos     MDC2_Update(&c, (const unsigned char *)testdata.input,
6113d40330Schristos                 strlen(testdata.input));
6213d40330Schristos     MDC2_Final(&(md[0]), &c);
6313d40330Schristos 
6413d40330Schristos     if (!TEST_mem_eq(testdata.expected, MDC2_DIGEST_LENGTH,
6513d40330Schristos                      md, MDC2_DIGEST_LENGTH)) {
6613d40330Schristos         TEST_info("mdc2 test %d: unexpected output", idx);
6713d40330Schristos         return 0;
6813d40330Schristos     }
6913d40330Schristos 
7013d40330Schristos     return 1;
7113d40330Schristos }
7213d40330Schristos 
setup_tests(void)7313d40330Schristos int setup_tests(void)
7413d40330Schristos {
7513d40330Schristos     ADD_ALL_TESTS(test_mdc2, OSSL_NELEM(tests));
7613d40330Schristos     return 1;
7713d40330Schristos }
78