]> git.ipfire.org Git - thirdparty/openssl.git/blame - test/mdc2test.c
Create provider errors and use them
[thirdparty/openssl.git] / test / mdc2test.c
CommitLineData
440e5d80 1/*
850b55a9 2 * Copyright 1995-2017 The OpenSSL Project Authors. All Rights Reserved.
d02b48c6 3 *
909f1a2e 4 * Licensed under the Apache License 2.0 (the "License"). You may not use
440e5d80
RS
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
d02b48c6
RE
8 */
9
d02b48c6 10#include <string.h>
f5d7a031 11
176db6dc 12#include "internal/nelem.h"
850b55a9 13#include "testutil.h"
55f78baf 14
cf1b7d96 15#if defined(OPENSSL_NO_DES) && !defined(OPENSSL_NO_MDC2)
0f113f3e 16# define OPENSSL_NO_MDC2
f5d7a031
UM
17#endif
18
850b55a9 19#ifndef OPENSSL_NO_MDC2
0f113f3e
MC
20# include <openssl/evp.h>
21# include <openssl/mdc2.h>
d02b48c6 22
0f113f3e
MC
23# ifdef CHARSET_EBCDIC
24# include <openssl/ebcdic.h>
25# endif
a53955d8 26
0f113f3e
MC
27static unsigned char pad1[16] = {
28 0x42, 0xE5, 0x0C, 0xD2, 0x24, 0xBA, 0xCE, 0xBA,
29 0x76, 0x0B, 0xDD, 0x2B, 0xD4, 0x09, 0x28, 0x1A
30};
d02b48c6 31
0f113f3e
MC
32static unsigned char pad2[16] = {
33 0x2E, 0x46, 0x79, 0xB5, 0xAD, 0xD9, 0xCA, 0x75,
34 0x35, 0xD8, 0x7A, 0xFE, 0xAB, 0x33, 0xBE, 0xE2
35};
d02b48c6 36
850b55a9 37static int test_mdc2(void)
0f113f3e 38{
850b55a9 39 int testresult = 0;
0f113f3e 40 unsigned char md[MDC2_DIGEST_LENGTH];
6e59a892 41 EVP_MD_CTX *c;
a1f41284 42 static char text[] = "Now is the time for all ";
850b55a9 43 size_t tlen = strlen(text);
d02b48c6 44
0f113f3e 45# ifdef CHARSET_EBCDIC
850b55a9 46 ebcdic2ascii(text, text, tlen);
0f113f3e 47# endif
a53955d8 48
bfb0641f 49 c = EVP_MD_CTX_new();
850b55a9
P
50 if (!TEST_ptr(c)
51 || !TEST_true(EVP_DigestInit_ex(c, EVP_mdc2(), NULL))
52 || !TEST_true(EVP_DigestUpdate(c, (unsigned char *)text, tlen))
53 || !TEST_true(EVP_DigestFinal_ex(c, &(md[0]), NULL))
54 || !TEST_mem_eq(md, MDC2_DIGEST_LENGTH, pad1, MDC2_DIGEST_LENGTH)
55 || !TEST_true(EVP_DigestInit_ex(c, EVP_mdc2(), NULL)))
56 goto end;
d02b48c6 57
0f113f3e 58 /* FIXME: use a ctl function? */
6e59a892 59 ((MDC2_CTX *)EVP_MD_CTX_md_data(c))->pad_type = 2;
850b55a9
P
60 if (!TEST_true(EVP_DigestUpdate(c, (unsigned char *)text, tlen))
61 || !TEST_true(EVP_DigestFinal_ex(c, &(md[0]), NULL))
62 || !TEST_mem_eq(md, MDC2_DIGEST_LENGTH, pad2, MDC2_DIGEST_LENGTH))
63 goto end;
d02b48c6 64
850b55a9
P
65 testresult = 1;
66 end:
bfb0641f 67 EVP_MD_CTX_free(c);
850b55a9 68 return testresult;
0f113f3e 69}
f5d7a031 70#endif
850b55a9 71
ad887416 72int setup_tests(void)
850b55a9
P
73{
74#ifndef OPENSSL_NO_MDC2
75 ADD_TEST(test_mdc2);
76#endif
ad887416 77 return 1;
850b55a9 78}