Fix CVE-2017-6891 in minitasn1 code
[platform/upstream/gnutls.git] / tests / openssl.c
1 /*
2  * Copyright (C) 2004-2012 Free Software Foundation, Inc.
3  *
4  * Author: Simon Josefsson
5  *
6  * This file is part of GnuTLS.
7  *
8  * GnuTLS is free software; you can redistribute it and/or modify it
9  * under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * GnuTLS is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with GnuTLS; if not, write to the Free Software Foundation,
20  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
21  */
22
23 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
26
27 #include <stdio.h>
28
29 #include "utils.h"
30
31 #include <gnutls/openssl.h>
32
33 void doit(void)
34 {
35         MD5_CTX c;
36         unsigned char md[MD5_DIGEST_LENGTH];
37
38         if (global_init() != 0)
39                 fail("global_init\n");
40
41         if (!gnutls_check_version(GNUTLS_VERSION))
42                 success("gnutls_check_version ERROR\n");
43
44         MD5_Init(&c);
45         MD5_Update(&c, "abc", 3);
46         MD5_Final(&(md[0]), &c);
47
48         if (memcmp(md, "\x90\x01\x50\x98\x3c\xd2\x4f\xb0"
49                    "\xd6\x96\x3f\x7d\x28\xe1\x7f\x72", sizeof(md)) != 0) {
50                 hexprint(md, sizeof(md));
51                 fail("MD5 failure\n");
52         } else if (debug)
53                 success("MD5 OK\n");
54
55         gnutls_global_deinit();
56 }