Reset executable bits on files where not needed.
[openssl.git] / test / md2test.c
1 /*
2  * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
3  *
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
8  */
9
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <string.h>
13
14 #include "../e_os.h"
15
16 #ifdef OPENSSL_NO_MD2
17 int main(int argc, char *argv[])
18 {
19     printf("No MD2 support\n");
20     return (0);
21 }
22 #else
23 # include <openssl/evp.h>
24 # include <openssl/md2.h>
25
26 # ifdef CHARSET_EBCDIC
27 #  include <openssl/ebcdic.h>
28 # endif
29
30 static char *test[] = {
31     "",
32     "a",
33     "abc",
34     "message digest",
35     "abcdefghijklmnopqrstuvwxyz",
36     "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
37     "12345678901234567890123456789012345678901234567890123456789012345678901234567890",
38     NULL,
39 };
40
41 static char *ret[] = {
42     "8350e5a3e24c153df2275c9f80692773",
43     "32ec01ec4a6dac72c0ab96fb34c0b5d1",
44     "da853b0d3f88d99b30283a69e6ded6bb",
45     "ab4f496bfb2a530b219ff33031fe06b0",
46     "4e8ddff3650292ab5a4108c3aa47940b",
47     "da33def2a42df13975352846c30338cd",
48     "d5976f79d83d3a0dc9806c3c66f3efd8",
49 };
50
51 static char *pt(unsigned char *md);
52 int main(int argc, char *argv[])
53 {
54     int i, err = 0;
55     char **P, **R;
56     char *p;
57     unsigned char md[MD2_DIGEST_LENGTH];
58
59     P = test;
60     R = ret;
61     i = 1;
62     while (*P != NULL) {
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         }
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     }
79     EXIT(err);
80     return err;
81 }
82
83 static char *pt(unsigned char *md)
84 {
85     int i;
86     static char buf[80];
87
88     for (i = 0; i < MD2_DIGEST_LENGTH; i++)
89         sprintf(&(buf[i * 2]), "%02x", md[i]);
90     return (buf);
91 }
92 #endif