]> git.ipfire.org Git - thirdparty/openssl.git/blame - test/md2test.c
Exdata test was never enabled.
[thirdparty/openssl.git] / test / md2test.c
CommitLineData
440e5d80
RS
1/*
2 * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
58964a49 3 *
440e5d80
RS
4 * Licensed under the OpenSSL license (the "License"). You may not use
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
58964a49
RE
8 */
9
10#include <stdio.h>
11#include <stdlib.h>
12#include <string.h>
f5d7a031 13
55f78baf
RL
14#include "../e_os.h"
15
cf1b7d96 16#ifdef OPENSSL_NO_MD2
f5d7a031
UM
17int main(int argc, char *argv[])
18{
19 printf("No MD2 support\n");
0f113f3e 20 return (0);
f5d7a031
UM
21}
22#else
0f113f3e
MC
23# include <openssl/evp.h>
24# include <openssl/md2.h>
58964a49 25
0f113f3e
MC
26# ifdef CHARSET_EBCDIC
27# include <openssl/ebcdic.h>
28# endif
a53955d8 29
0f113f3e
MC
30static char *test[] = {
31 "",
32 "a",
33 "abc",
34 "message digest",
35 "abcdefghijklmnopqrstuvwxyz",
36 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
37 "12345678901234567890123456789012345678901234567890123456789012345678901234567890",
38 NULL,
39};
58964a49 40
0f113f3e
MC
41static char *ret[] = {
42 "8350e5a3e24c153df2275c9f80692773",
43 "32ec01ec4a6dac72c0ab96fb34c0b5d1",
44 "da853b0d3f88d99b30283a69e6ded6bb",
45 "ab4f496bfb2a530b219ff33031fe06b0",
46 "4e8ddff3650292ab5a4108c3aa47940b",
47 "da33def2a42df13975352846c30338cd",
48 "d5976f79d83d3a0dc9806c3c66f3efd8",
49};
58964a49 50
58964a49 51static char *pt(unsigned char *md);
6b691a5c 52int main(int argc, char *argv[])
0f113f3e
MC
53{
54 int i, err = 0;
55 char **P, **R;
56 char *p;
57 unsigned char md[MD2_DIGEST_LENGTH];
58964a49 58
0f113f3e
MC
59 P = test;
60 R = ret;
61 i = 1;
62 while (*P != NULL) {
d166ed8c
DSH
63 if (!EVP_Digest((unsigned char *)*P, strlen(*P), md, NULL, EVP_md2(),
64 NULL)) {
65 printf("EVP Digest error.\n");
66 EXIT(1);
67 }
0f113f3e
MC
68 p = pt(md);
69 if (strcmp(p, *R) != 0) {
70 printf("error calculating MD2 on '%s'\n", *P);
71 printf("got %s instead of %s\n", p, *R);
72 err++;
73 } else
74 printf("test %d ok\n", i);
75 i++;
76 R++;
77 P++;
78 }
0f113f3e
MC
79 EXIT(err);
80 return err;
81}
58964a49 82
6b691a5c 83static char *pt(unsigned char *md)
0f113f3e
MC
84{
85 int i;
86 static char buf[80];
58964a49 87
0f113f3e
MC
88 for (i = 0; i < MD2_DIGEST_LENGTH; i++)
89 sprintf(&(buf[i * 2]), "%02x", md[i]);
90 return (buf);
91}
f5d7a031 92#endif