Fix CVE-2017-6891 in minitasn1 code
[platform/upstream/gnutls.git] / tests / sec-params.c
1 /*
2  * Copyright (C) 2014 Red Hat
3  *
4  * Author: Nikos Mavrogiannopoulos
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 #include <stdlib.h>
29 #include <string.h>
30 #include <utils.h>
31
32 #include <gnutls/gnutls.h>
33
34 int main(int argc, char *argv[])
35 {
36 int ret;
37 gnutls_sec_param_t p;
38
39         ret = global_init();
40         if (ret != 0) {
41                 printf("%d: %s\n", ret, gnutls_strerror(ret));
42                 return EXIT_FAILURE;
43         }
44         
45         p = gnutls_pk_bits_to_sec_param(GNUTLS_PK_EC, 160);
46         if (p != GNUTLS_SEC_PARAM_LOW) {
47                 fprintf(stderr, "%d: error in sec param, p:%u\n", __LINE__, (unsigned)p);
48                 return 1;
49         }
50
51         p = gnutls_pk_bits_to_sec_param(GNUTLS_PK_EC, 192);
52         if (p != GNUTLS_SEC_PARAM_LEGACY) {
53                 fprintf(stderr, "%d: error in sec param, p:%u\n", __LINE__, (unsigned)p);
54                 return 1;
55         }
56
57         p = gnutls_pk_bits_to_sec_param(GNUTLS_PK_EC, 256);
58         if (p != GNUTLS_SEC_PARAM_HIGH) {
59                 fprintf(stderr, "%d: error in sec param, p:%u\n", __LINE__, (unsigned)p);
60                 return 1;
61         }
62
63         p = gnutls_pk_bits_to_sec_param(GNUTLS_PK_EC, 384);
64         if (p != GNUTLS_SEC_PARAM_HIGH) {
65                 fprintf(stderr, "%d: error in sec param, p:%u\n", __LINE__, (unsigned)p);
66                 return 1;
67         }
68
69         p = gnutls_pk_bits_to_sec_param(GNUTLS_PK_RSA, 1024);
70 #ifdef ENABLE_FIPS140
71         if (p != GNUTLS_SEC_PARAM_LEGACY) {
72 #else
73         if (p != GNUTLS_SEC_PARAM_LOW) {
74 #endif
75                 fprintf(stderr, "%d: error in sec param, p:%u\n", __LINE__, (unsigned)p);
76                 return 1;
77         }
78
79         p = gnutls_pk_bits_to_sec_param(GNUTLS_PK_RSA, 2048);
80         if (p != GNUTLS_SEC_PARAM_MEDIUM) {
81                 fprintf(stderr, "%d: error in sec param, p:%u\n", __LINE__, (unsigned)p);
82                 return 1;
83         }
84
85         p = gnutls_pk_bits_to_sec_param(GNUTLS_PK_DH, 1024);
86 #ifdef ENABLE_FIPS140
87         if (p != GNUTLS_SEC_PARAM_LEGACY) {
88 #else
89         if (p != GNUTLS_SEC_PARAM_LOW) {
90 #endif
91                 fprintf(stderr, "%d: error in sec param, p:%u\n", __LINE__, (unsigned)p);
92                 return 1;
93         }
94
95         p = gnutls_pk_bits_to_sec_param(GNUTLS_PK_DH, 2048);
96         if (p != GNUTLS_SEC_PARAM_MEDIUM) {
97                 fprintf(stderr, "%d: error in sec param, p:%u\n", __LINE__, (unsigned)p);
98                 return 1;
99         }
100
101         gnutls_global_deinit();
102
103         return 0;
104 }