2 * Copyright (C) 2012 Free Software Foundation, Inc.
3 * Copyright (C) 2012-2015 Nikos Mavrogiannopoulos
5 * Author: Nikos Mavrogiannopoulos
7 * This file is part of GnuTLS.
9 * GnuTLS is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
14 * GnuTLS is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with GnuTLS; if not, write to the Free Software Foundation,
21 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
31 #include <gnutls/gnutls.h>
44 try_prio(const char *prio, unsigned expected_cs, unsigned expected_ciphers, unsigned line)
49 const unsigned int *t;
50 unsigned i, si, count = 0;
52 /* this must be called once in the program
56 ret = gnutls_priority_init(&p, prio, &err);
58 fprintf(stderr, "error: %s: %s\n", gnutls_strerror(ret),
64 ret = gnutls_priority_get_cipher_suite_index(p, i, &si);
65 if (ret == GNUTLS_E_UNKNOWN_CIPHER_SUITE)
67 else if (ret == GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE)
71 /* fprintf(stderr, "%s\n", gnutls_cipher_suite_info(si, NULL, NULL, NULL, NULL, NULL)); */
76 ret = gnutls_priority_cipher_list(p, &t);
77 if ((unsigned) ret != expected_ciphers) {
79 for (i = 0; i < ret; i++)
80 fprintf(stderr, "%s\n",
81 gnutls_cipher_get_name(t[i]));
83 fail("%s:%d: expected %d ciphers, found %d\n", prio, line, expected_ciphers,
88 gnutls_priority_deinit(p);
90 /* fprintf(stderr, "count: %d\n", count); */
93 success("finished: %s\n", prio);
95 if (count != expected_cs) {
96 fail("%s:%d: expected %d ciphersuites, found %d\n", prio, line, expected_cs,
104 const int normal = 54;
106 const int sec128 = 50;
108 try_prio("NORMAL", normal, 11, __LINE__);
109 try_prio("NORMAL:-MAC-ALL:+MD5:+MAC-ALL", normal, 11, __LINE__);
110 try_prio("NORMAL:+CIPHER-ALL", normal, 11, __LINE__); /* all (except null) */
111 try_prio("NORMAL:-CIPHER-ALL:+NULL", null, 1, __LINE__); /* null */
112 try_prio("NORMAL:-CIPHER-ALL:+NULL:+CIPHER-ALL", normal + null, 12, __LINE__); /* should be null + all */
113 try_prio("NORMAL:-CIPHER-ALL:+NULL:+CIPHER-ALL:-CIPHER-ALL:+AES-128-CBC", 8, 1, __LINE__); /* should be null + all */
114 try_prio("PERFORMANCE", normal, 11, __LINE__);
115 try_prio("SECURE256", 19, 5, __LINE__);
116 try_prio("SECURE128", sec128, 10, __LINE__);
117 try_prio("SECURE128:+SECURE256", sec128, 10, __LINE__); /* should be the same as SECURE128 */
118 try_prio("SECURE128:+SECURE256:+NORMAL", normal, 11, __LINE__); /* should be the same as NORMAL */
119 try_prio("SUITEB192", 1, 1, __LINE__);