*** empty log message ***
[gnutls.git] / lib / gnutls_priority.c
blob9c908bf6415e82be7928f5dc496ed9ebd637e9d4
1 /*
2 * Copyright (C) 2000 Nikos Mavroyanopoulos
4 * This file is part of GNUTLS.
6 * GNUTLS is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * GNUTLS is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
21 #include "gnutls_int.h"
22 #include "gnutls_algorithms.h"
23 #include "gnutls_errors.h"
24 #include <gnutls_num.h>
26 /**
27 * gnutls_cipher_set_priority - Sets the priority on the ciphers supported by gnutls.
28 * @state: is a &GNUTLS_STATE structure.
29 * @list: is a 0 terminated list of BulkCipherAlgorithm elements.
31 * Sets the priority on the ciphers supported by gnutls.
32 * Priority is higher for ciphers specified before others.
33 * After specifying the ciphers you want, you should add 0.
34 * Note that the priority is set on the client. The server does
35 * not use the algorithm's priority except for disabling
36 * algorithms that were not specified.
37 **/
38 int gnutls_cipher_set_priority( GNUTLS_STATE state, GNUTLS_LIST list) {
39 GNUTLS_LIST _list = list;
40 int num=0, i;
42 while( *_list != 0) {
43 num++;
44 ++_list;
47 num = GMIN( MAX_ALGOS, num);
48 state->gnutls_internals.BulkCipherAlgorithmPriority.algorithms = num;
50 for (i=0;i<num;i++) {
51 state->gnutls_internals.BulkCipherAlgorithmPriority.algorithm_priority[i] = list[i];
54 return 0;
57 /**
58 * gnutls_kx_set_priority - Sets the priority on the key exchange algorithms supported by gnutls.
59 * @state: is a &GNUTLS_STATE structure.
60 * @list: is a 0 terminated list of KXAlgorithm elements.
62 * Sets the priority on the key exchange algorithms supported by gnutls.
63 * Priority is higher for algorithms specified before others.
64 * After specifying the algorithms you want, you should add 0.
65 * Note that the priority is set on the client. The server does
66 * not use the algorithm's priority except for disabling
67 * algorithms that were not specified.
68 **/
69 int gnutls_kx_set_priority( GNUTLS_STATE state, GNUTLS_LIST list) {
70 GNUTLS_LIST _list = list;
71 int num=0, i;
73 while( *_list != 0) {
74 num++;
75 ++_list;
79 num = GMIN( MAX_ALGOS, num);
80 state->gnutls_internals.KXAlgorithmPriority.algorithms = num;
82 for (i=0;i<num;i++) {
83 state->gnutls_internals.KXAlgorithmPriority.algorithm_priority[i] = list[i];
86 return 0;
89 /**
90 * gnutls_mac_set_priority - Sets the priority on the mac algorithms supported by gnutls.
91 * @state: is a &GNUTLS_STATE structure.
92 * @list: is a 0 terminated list of MACAlgorithm elements.
94 * Sets the priority on the mac algorithms supported by gnutls.
95 * Priority is higher for algorithms specified before others.
96 * After specifying the algorithms you want, you should add 0.
97 * Note that the priority is set on the client. The server does
98 * not use the algorithm's priority except for disabling
99 * algorithms that were not specified.
101 int gnutls_mac_set_priority( GNUTLS_STATE state, GNUTLS_LIST list) {
102 GNUTLS_LIST _list = list;
103 int num=0, i;
105 while( *_list != 0) {
106 num++;
107 ++_list;
111 num = GMIN( MAX_ALGOS, num);
112 state->gnutls_internals.MACAlgorithmPriority.algorithms = num;
114 for (i=0;i<num;i++) {
115 state->gnutls_internals.MACAlgorithmPriority.algorithm_priority[i] = list[i];
118 return 0;
122 * gnutls_compression_set_priority - Sets the priority on the compression algorithms supported by gnutls.
123 * @state: is a &GNUTLS_STATE structure.
124 * @list: is a 0 terminated list of CompressionMethod elements.
126 * Sets the priority on the compression algorithms supported by gnutls.
127 * Priority is higher for algorithms specified before others.
128 * After specifying the algorithms you want, you should add 0.
129 * Note that the priority is set on the client. The server does
130 * not use the algorithm's priority except for disabling
131 * algorithms that were not specified.
133 * TLS 1.0 does not define any compression algorithms except
134 * NULL. Other compression algorithms are to be considered
135 * as gnutls extensions.
138 int gnutls_compression_set_priority( GNUTLS_STATE state, GNUTLS_LIST list) {
139 GNUTLS_LIST _list = list;
140 int num=0, i;
142 while( *_list != 0) {
143 num++;
144 ++_list;
147 num = GMIN( MAX_ALGOS, num);
148 state->gnutls_internals.CompressionMethodPriority.algorithms = num;
150 for (i=0;i<num;i++) {
151 state->gnutls_internals.CompressionMethodPriority.algorithm_priority[i] = list[i];
153 return 0;
157 * gnutls_protocol_set_priority - Sets the priority on the protocol versions supported by gnutls.
158 * @state: is a &GNUTLS_STATE structure.
159 * @list: is a 0 terminated list of GNUTLS_Version elements.
161 * Sets the priority on the protocol versions supported by gnutls.
162 * This function actually enables or disables protocols. Newer protocol
163 * versions always have highest priority.
166 int gnutls_protocol_set_priority( GNUTLS_STATE state, GNUTLS_LIST list) {
167 GNUTLS_LIST _list = list;
168 int num=0, i;
170 while( *_list != 0) {
171 num++;
172 ++_list;
176 num = GMIN( MAX_ALGOS, num);
177 state->gnutls_internals.ProtocolPriority.algorithms = num;
179 for (i=0;i<num;i++) {
180 state->gnutls_internals.ProtocolPriority.algorithm_priority[i] = list[i];
183 /* set the current version to the first in the chain.
184 * This will be overriden later.
186 if (num > 0)
187 _gnutls_set_current_version( state, state->gnutls_internals.ProtocolPriority.algorithm_priority[0]);
189 return 0;
193 * gnutls_cert_type_set_priority - Sets the priority on the certificate types supported by gnutls.
194 * @state: is a &GNUTLS_STATE structure.
195 * @list: is a 0 terminated list of GNUTLS_CertificateType elements.
197 * Sets the priority on the certificate types supported by gnutls.
198 * Priority is higher for types specified before others.
199 * After specifying the types you want, you should add 0.
200 * Note that the certificate type priority is set on the client.
201 * The server does not use the cert type priority except for disabling
202 * types that were not specified.
204 int gnutls_cert_type_set_priority( GNUTLS_STATE state, GNUTLS_LIST list) {
205 GNUTLS_LIST _list = list;
206 int num=0, i;
208 #ifdef HAVE_LIBOPENCDK
210 while( *_list != 0) {
211 num++;
212 ++_list;
215 num = GMIN( MAX_ALGOS, num);
216 state->gnutls_internals.cert_type_priority.algorithms = num;
218 for (i=0;i<num;i++) {
219 state->gnutls_internals.cert_type_priority.algorithm_priority[i] = list[i];
222 return 0;
224 #endif
226 return GNUTLS_E_UNIMPLEMENTED_FEATURE;