Add test cases for DTLS_get_data_mtu()
[openssl.git] / test / md5test.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 <string.h>
12 #include <stdlib.h>
13
14 #include "../e_os.h"
15
16 #ifdef OPENSSL_NO_MD5
17 int main(int argc, char *argv[])
18 {
19     printf("No MD5 support\n");
20     return (0);
21 }
22 #else
23 # include <openssl/evp.h>
24 # include <openssl/md5.h>
25
26 static char *test[] = {
27     "",
28     "a",
29     "abc",
30     "message digest",
31     "abcdefghijklmnopqrstuvwxyz",
32     "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
33     "12345678901234567890123456789012345678901234567890123456789012345678901234567890",
34     NULL,
35 };
36
37 static char *ret[] = {
38     "d41d8cd98f00b204e9800998ecf8427e",
39     "0cc175b9c0f1b6a831c399e269772661",
40     "900150983cd24fb0d6963f7d28e17f72",
41     "f96b697d7cb7938d525a2f31aaf161d0",
42     "c3fcd3d76192e4007dfb496cca67e13b",
43     "d174ab98d277d9f5a5611c2c9f419d9f",
44     "57edf4a22be3c955ac49da2e2107b67a",
45 };
46
47 static char *pt(unsigned char *md);
48 int main(int argc, char *argv[])
49 {
50     int i, err = 0;
51     char **P, **R;
52     char *p;
53     unsigned char md[MD5_DIGEST_LENGTH];
54
55     P = test;
56     R = ret;
57     i = 1;
58     while (*P != NULL) {
59         if (!EVP_Digest(&(P[0][0]), strlen((char *)*P), md, NULL, EVP_md5(),
60             NULL)) {
61             printf("EVP Digest error.\n");
62             EXIT(1);
63         }
64         p = pt(md);
65         if (strcmp(p, (char *)*R) != 0) {
66             printf("error calculating MD5 on '%s'\n", *P);
67             printf("got %s instead of %s\n", p, *R);
68             err++;
69         } else
70             printf("test %d ok\n", i);
71         i++;
72         R++;
73         P++;
74     }
75
76     EXIT(err);
77 }
78
79 static char *pt(unsigned char *md)
80 {
81     int i;
82     static char buf[80];
83
84     for (i = 0; i < MD5_DIGEST_LENGTH; i++)
85         sprintf(&(buf[i * 2]), "%02x", md[i]);
86     return (buf);
87 }
88 #endif