1 /* $OpenBSD: ssl_ciph.c,v 1.96 2017/03/10 16:03:27 jsing Exp $ */
2 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
58 /* ====================================================================
59 * Copyright (c) 1998-2007 The OpenSSL Project. All rights reserved.
61 * Redistribution and use in source and binary forms, with or without
62 * modification, are permitted provided that the following conditions
65 * 1. Redistributions of source code must retain the above copyright
66 * notice, this list of conditions and the following disclaimer.
68 * 2. Redistributions in binary form must reproduce the above copyright
69 * notice, this list of conditions and the following disclaimer in
70 * the documentation and/or other materials provided with the
73 * 3. All advertising materials mentioning features or use of this
74 * software must display the following acknowledgment:
75 * "This product includes software developed by the OpenSSL Project
76 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
78 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
79 * endorse or promote products derived from this software without
80 * prior written permission. For written permission, please contact
81 * openssl-core@openssl.org.
83 * 5. Products derived from this software may not be called "OpenSSL"
84 * nor may "OpenSSL" appear in their names without prior written
85 * permission of the OpenSSL Project.
87 * 6. Redistributions of any form whatsoever must retain the following
89 * "This product includes software developed by the OpenSSL Project
90 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
92 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
93 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
94 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
95 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
96 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
97 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
98 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
99 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
100 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
101 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
102 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
103 * OF THE POSSIBILITY OF SUCH DAMAGE.
104 * ====================================================================
106 * This product includes cryptographic software written by Eric Young
107 * (eay@cryptsoft.com). This product includes software written by Tim
108 * Hudson (tjh@cryptsoft.com).
111 /* ====================================================================
112 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
113 * ECC cipher suite support in OpenSSL originally developed by
114 * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project.
116 /* ====================================================================
117 * Copyright 2005 Nokia. All rights reserved.
119 * The portions of the attached software ("Contribution") is developed by
120 * Nokia Corporation and is licensed pursuant to the OpenSSL open source
123 * The Contribution, originally written by Mika Kousa and Pasi Eronen of
124 * Nokia Corporation, consists of the "PSK" (Pre-Shared Key) ciphersuites
125 * support (see RFC 4279) to OpenSSL.
127 * No patent licenses or other rights except those expressly stated in
128 * the OpenSSL open source license shall be deemed granted or received
129 * expressly, by implication, estoppel, or otherwise.
131 * No assurances are provided by Nokia that the Contribution does not
132 * infringe the patent or other intellectual property rights of any third
133 * party or that the license provides you with all the necessary rights
134 * to make use of the Contribution.
136 * THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. IN
137 * ADDITION TO THE DISCLAIMERS INCLUDED IN THE LICENSE, NOKIA
138 * SPECIFICALLY DISCLAIMS ANY LIABILITY FOR CLAIMS BROUGHT BY YOU OR ANY
139 * OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS OR
145 #include <openssl/objects.h>
147 #ifndef OPENSSL_NO_ENGINE
148 #include <openssl/engine.h>
151 #include "ssl_locl.h"
153 #define SSL_ENC_DES_IDX 0
154 #define SSL_ENC_3DES_IDX 1
155 #define SSL_ENC_RC4_IDX 2
156 #define SSL_ENC_IDEA_IDX 3
157 #define SSL_ENC_NULL_IDX 4
158 #define SSL_ENC_AES128_IDX 5
159 #define SSL_ENC_AES256_IDX 6
160 #define SSL_ENC_CAMELLIA128_IDX 7
161 #define SSL_ENC_CAMELLIA256_IDX 8
162 #define SSL_ENC_GOST89_IDX 9
163 #define SSL_ENC_AES128GCM_IDX 10
164 #define SSL_ENC_AES256GCM_IDX 11
165 #define SSL_ENC_NUM_IDX 12
168 static const EVP_CIPHER
*ssl_cipher_methods
[SSL_ENC_NUM_IDX
] = {
169 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
172 #define SSL_MD_MD5_IDX 0
173 #define SSL_MD_SHA1_IDX 1
174 #define SSL_MD_GOST94_IDX 2
175 #define SSL_MD_GOST89MAC_IDX 3
176 #define SSL_MD_SHA256_IDX 4
177 #define SSL_MD_SHA384_IDX 5
178 #define SSL_MD_STREEBOG256_IDX 6
179 /*Constant SSL_MAX_DIGEST equal to size of digests array should be
182 #define SSL_MD_NUM_IDX SSL_MAX_DIGEST
183 static const EVP_MD
*ssl_digest_methods
[SSL_MD_NUM_IDX
] = {
184 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
187 static int ssl_mac_pkey_id
[SSL_MD_NUM_IDX
] = {
188 EVP_PKEY_HMAC
, EVP_PKEY_HMAC
, EVP_PKEY_HMAC
, EVP_PKEY_GOSTIMIT
,
189 EVP_PKEY_HMAC
, EVP_PKEY_HMAC
, EVP_PKEY_HMAC
,
192 static int ssl_mac_secret_size
[SSL_MD_NUM_IDX
] = {
197 #define CIPHER_KILL 2
200 #define CIPHER_SPECIAL 5
202 typedef struct cipher_order_st
{
203 const SSL_CIPHER
*cipher
;
206 struct cipher_order_st
*next
, *prev
;
209 static const SSL_CIPHER cipher_aliases
[] = {
211 /* "ALL" doesn't include eNULL (must be specifically enabled) */
214 .algorithm_enc
= ~SSL_eNULL
,
217 /* "COMPLEMENTOFALL" */
219 .name
= SSL_TXT_CMPALL
,
220 .algorithm_enc
= SSL_eNULL
,
224 * "COMPLEMENTOFDEFAULT"
225 * (does *not* include ciphersuites not found in ALL!)
228 .name
= SSL_TXT_CMPDEF
,
229 .algorithm_mkey
= SSL_kDHE
|SSL_kECDHE
,
230 .algorithm_auth
= SSL_aNULL
,
231 .algorithm_enc
= ~SSL_eNULL
,
235 * key exchange aliases
236 * (some of those using only a single bit here combine multiple key
237 * exchange algs according to the RFCs, e.g. kEDH combines DHE_DSS
241 .name
= SSL_TXT_kRSA
,
242 .algorithm_mkey
= SSL_kRSA
,
245 .name
= SSL_TXT_kEDH
,
246 .algorithm_mkey
= SSL_kDHE
,
250 .algorithm_mkey
= SSL_kDHE
,
253 .name
= SSL_TXT_kEECDH
,
254 .algorithm_mkey
= SSL_kECDHE
,
257 .name
= SSL_TXT_ECDH
,
258 .algorithm_mkey
= SSL_kECDHE
,
261 .name
= SSL_TXT_kGOST
,
262 .algorithm_mkey
= SSL_kGOST
,
265 /* server authentication aliases */
267 .name
= SSL_TXT_aRSA
,
268 .algorithm_auth
= SSL_aRSA
,
271 .name
= SSL_TXT_aDSS
,
272 .algorithm_auth
= SSL_aDSS
,
276 .algorithm_auth
= SSL_aDSS
,
279 .name
= SSL_TXT_aNULL
,
280 .algorithm_auth
= SSL_aNULL
,
283 .name
= SSL_TXT_aECDSA
,
284 .algorithm_auth
= SSL_aECDSA
,
287 .name
= SSL_TXT_ECDSA
,
288 .algorithm_auth
= SSL_aECDSA
,
291 .name
= SSL_TXT_aGOST01
,
292 .algorithm_auth
= SSL_aGOST01
,
295 .name
= SSL_TXT_aGOST
,
296 .algorithm_auth
= SSL_aGOST01
,
299 /* aliases combining key exchange and server authentication */
302 .algorithm_mkey
= SSL_kDHE
,
303 .algorithm_auth
= ~SSL_aNULL
,
307 .algorithm_mkey
= SSL_kDHE
,
308 .algorithm_auth
= ~SSL_aNULL
,
311 .name
= SSL_TXT_ECDHE
,
312 .algorithm_mkey
= SSL_kECDHE
,
313 .algorithm_auth
= ~SSL_aNULL
,
316 .name
= SSL_TXT_EECDH
,
317 .algorithm_mkey
= SSL_kECDHE
,
318 .algorithm_auth
= ~SSL_aNULL
,
321 .name
= SSL_TXT_NULL
,
322 .algorithm_enc
= SSL_eNULL
,
326 .algorithm_mkey
= SSL_kRSA
,
327 .algorithm_auth
= SSL_aRSA
,
331 .algorithm_mkey
= SSL_kDHE
,
332 .algorithm_auth
= SSL_aNULL
,
335 .name
= SSL_TXT_AECDH
,
336 .algorithm_mkey
= SSL_kECDHE
,
337 .algorithm_auth
= SSL_aNULL
,
340 /* symmetric encryption aliases */
343 .algorithm_enc
= SSL_DES
,
346 .name
= SSL_TXT_3DES
,
347 .algorithm_enc
= SSL_3DES
,
351 .algorithm_enc
= SSL_RC4
,
354 .name
= SSL_TXT_IDEA
,
355 .algorithm_enc
= SSL_IDEA
,
358 .name
= SSL_TXT_eNULL
,
359 .algorithm_enc
= SSL_eNULL
,
362 .name
= SSL_TXT_AES128
,
363 .algorithm_enc
= SSL_AES128
|SSL_AES128GCM
,
366 .name
= SSL_TXT_AES256
,
367 .algorithm_enc
= SSL_AES256
|SSL_AES256GCM
,
371 .algorithm_enc
= SSL_AES
,
374 .name
= SSL_TXT_AES_GCM
,
375 .algorithm_enc
= SSL_AES128GCM
|SSL_AES256GCM
,
378 .name
= SSL_TXT_CAMELLIA128
,
379 .algorithm_enc
= SSL_CAMELLIA128
,
382 .name
= SSL_TXT_CAMELLIA256
,
383 .algorithm_enc
= SSL_CAMELLIA256
,
386 .name
= SSL_TXT_CAMELLIA
,
387 .algorithm_enc
= SSL_CAMELLIA128
|SSL_CAMELLIA256
,
390 .name
= SSL_TXT_CHACHA20
,
391 .algorithm_enc
= SSL_CHACHA20POLY1305
|SSL_CHACHA20POLY1305_OLD
,
396 .name
= SSL_TXT_AEAD
,
397 .algorithm_mac
= SSL_AEAD
,
401 .algorithm_mac
= SSL_MD5
,
404 .name
= SSL_TXT_SHA1
,
405 .algorithm_mac
= SSL_SHA1
,
409 .algorithm_mac
= SSL_SHA1
,
412 .name
= SSL_TXT_GOST94
,
413 .algorithm_mac
= SSL_GOST94
,
416 .name
= SSL_TXT_GOST89MAC
,
417 .algorithm_mac
= SSL_GOST89MAC
,
420 .name
= SSL_TXT_SHA256
,
421 .algorithm_mac
= SSL_SHA256
,
424 .name
= SSL_TXT_SHA384
,
425 .algorithm_mac
= SSL_SHA384
,
428 .name
= SSL_TXT_STREEBOG256
,
429 .algorithm_mac
= SSL_STREEBOG256
,
432 /* protocol version aliases */
434 .name
= SSL_TXT_SSLV3
,
435 .algorithm_ssl
= SSL_SSLV3
,
438 .name
= SSL_TXT_TLSV1
,
439 .algorithm_ssl
= SSL_TLSV1
,
442 .name
= SSL_TXT_TLSV1_2
,
443 .algorithm_ssl
= SSL_TLSV1_2
,
446 /* strength classes */
449 .algo_strength
= SSL_LOW
,
452 .name
= SSL_TXT_MEDIUM
,
453 .algo_strength
= SSL_MEDIUM
,
456 .name
= SSL_TXT_HIGH
,
457 .algo_strength
= SSL_HIGH
,
462 ssl_load_ciphers(void)
464 ssl_cipher_methods
[SSL_ENC_DES_IDX
] =
465 EVP_get_cipherbyname(SN_des_cbc
);
466 ssl_cipher_methods
[SSL_ENC_3DES_IDX
] =
467 EVP_get_cipherbyname(SN_des_ede3_cbc
);
468 ssl_cipher_methods
[SSL_ENC_RC4_IDX
] =
469 EVP_get_cipherbyname(SN_rc4
);
470 ssl_cipher_methods
[SSL_ENC_IDEA_IDX
] = NULL
;
471 ssl_cipher_methods
[SSL_ENC_AES128_IDX
] =
472 EVP_get_cipherbyname(SN_aes_128_cbc
);
473 ssl_cipher_methods
[SSL_ENC_AES256_IDX
] =
474 EVP_get_cipherbyname(SN_aes_256_cbc
);
475 ssl_cipher_methods
[SSL_ENC_CAMELLIA128_IDX
] =
476 EVP_get_cipherbyname(SN_camellia_128_cbc
);
477 ssl_cipher_methods
[SSL_ENC_CAMELLIA256_IDX
] =
478 EVP_get_cipherbyname(SN_camellia_256_cbc
);
479 ssl_cipher_methods
[SSL_ENC_GOST89_IDX
] =
480 EVP_get_cipherbyname(SN_gost89_cnt
);
482 ssl_cipher_methods
[SSL_ENC_AES128GCM_IDX
] =
483 EVP_get_cipherbyname(SN_aes_128_gcm
);
484 ssl_cipher_methods
[SSL_ENC_AES256GCM_IDX
] =
485 EVP_get_cipherbyname(SN_aes_256_gcm
);
487 ssl_digest_methods
[SSL_MD_MD5_IDX
] =
488 EVP_get_digestbyname(SN_md5
);
489 ssl_mac_secret_size
[SSL_MD_MD5_IDX
] =
490 EVP_MD_size(ssl_digest_methods
[SSL_MD_MD5_IDX
]);
491 OPENSSL_assert(ssl_mac_secret_size
[SSL_MD_MD5_IDX
] >= 0);
492 ssl_digest_methods
[SSL_MD_SHA1_IDX
] =
493 EVP_get_digestbyname(SN_sha1
);
494 ssl_mac_secret_size
[SSL_MD_SHA1_IDX
] =
495 EVP_MD_size(ssl_digest_methods
[SSL_MD_SHA1_IDX
]);
496 OPENSSL_assert(ssl_mac_secret_size
[SSL_MD_SHA1_IDX
] >= 0);
497 ssl_digest_methods
[SSL_MD_GOST94_IDX
] =
498 EVP_get_digestbyname(SN_id_GostR3411_94
);
499 if (ssl_digest_methods
[SSL_MD_GOST94_IDX
]) {
500 ssl_mac_secret_size
[SSL_MD_GOST94_IDX
] =
501 EVP_MD_size(ssl_digest_methods
[SSL_MD_GOST94_IDX
]);
502 OPENSSL_assert(ssl_mac_secret_size
[SSL_MD_GOST94_IDX
] >= 0);
504 ssl_digest_methods
[SSL_MD_GOST89MAC_IDX
] =
505 EVP_get_digestbyname(SN_id_Gost28147_89_MAC
);
506 if (ssl_mac_pkey_id
[SSL_MD_GOST89MAC_IDX
]) {
507 ssl_mac_secret_size
[SSL_MD_GOST89MAC_IDX
] = 32;
510 ssl_digest_methods
[SSL_MD_SHA256_IDX
] =
511 EVP_get_digestbyname(SN_sha256
);
512 ssl_mac_secret_size
[SSL_MD_SHA256_IDX
] =
513 EVP_MD_size(ssl_digest_methods
[SSL_MD_SHA256_IDX
]);
514 ssl_digest_methods
[SSL_MD_SHA384_IDX
] =
515 EVP_get_digestbyname(SN_sha384
);
516 ssl_mac_secret_size
[SSL_MD_SHA384_IDX
] =
517 EVP_MD_size(ssl_digest_methods
[SSL_MD_SHA384_IDX
]);
518 ssl_digest_methods
[SSL_MD_STREEBOG256_IDX
] =
519 EVP_get_digestbyname(SN_id_tc26_gost3411_2012_256
);
520 ssl_mac_secret_size
[SSL_MD_STREEBOG256_IDX
] =
521 EVP_MD_size(ssl_digest_methods
[SSL_MD_STREEBOG256_IDX
]);
525 ssl_cipher_get_evp(const SSL_SESSION
*s
, const EVP_CIPHER
**enc
,
526 const EVP_MD
**md
, int *mac_pkey_type
, int *mac_secret_size
)
536 * This function does not handle EVP_AEAD.
537 * See ssl_cipher_get_aead_evp instead.
539 if (c
->algorithm2
& SSL_CIPHER_ALGORITHM2_AEAD
)
542 if ((enc
== NULL
) || (md
== NULL
))
545 switch (c
->algorithm_enc
) {
550 i
= SSL_ENC_3DES_IDX
;
556 i
= SSL_ENC_IDEA_IDX
;
559 i
= SSL_ENC_NULL_IDX
;
562 i
= SSL_ENC_AES128_IDX
;
565 i
= SSL_ENC_AES256_IDX
;
567 case SSL_CAMELLIA128
:
568 i
= SSL_ENC_CAMELLIA128_IDX
;
570 case SSL_CAMELLIA256
:
571 i
= SSL_ENC_CAMELLIA256_IDX
;
573 case SSL_eGOST2814789CNT
:
574 i
= SSL_ENC_GOST89_IDX
;
577 i
= SSL_ENC_AES128GCM_IDX
;
580 i
= SSL_ENC_AES256GCM_IDX
;
587 if ((i
< 0) || (i
>= SSL_ENC_NUM_IDX
))
590 if (i
== SSL_ENC_NULL_IDX
)
591 *enc
= EVP_enc_null();
593 *enc
= ssl_cipher_methods
[i
];
596 switch (c
->algorithm_mac
) {
604 i
= SSL_MD_SHA256_IDX
;
607 i
= SSL_MD_SHA384_IDX
;
610 i
= SSL_MD_GOST94_IDX
;
613 i
= SSL_MD_GOST89MAC_IDX
;
615 case SSL_STREEBOG256
:
616 i
= SSL_MD_STREEBOG256_IDX
;
622 if ((i
< 0) || (i
>= SSL_MD_NUM_IDX
)) {
625 if (mac_pkey_type
!= NULL
)
626 *mac_pkey_type
= NID_undef
;
627 if (mac_secret_size
!= NULL
)
628 *mac_secret_size
= 0;
629 if (c
->algorithm_mac
== SSL_AEAD
)
630 mac_pkey_type
= NULL
;
632 *md
= ssl_digest_methods
[i
];
633 if (mac_pkey_type
!= NULL
)
634 *mac_pkey_type
= ssl_mac_pkey_id
[i
];
635 if (mac_secret_size
!= NULL
)
636 *mac_secret_size
= ssl_mac_secret_size
[i
];
639 if ((*enc
!= NULL
) &&
640 (*md
!= NULL
|| (EVP_CIPHER_flags(*enc
)&EVP_CIPH_FLAG_AEAD_CIPHER
)) &&
641 (!mac_pkey_type
|| *mac_pkey_type
!= NID_undef
)) {
642 const EVP_CIPHER
*evp
;
644 if (s
->ssl_version
>> 8 != TLS1_VERSION_MAJOR
||
645 s
->ssl_version
< TLS1_VERSION
)
648 if (c
->algorithm_enc
== SSL_RC4
&&
649 c
->algorithm_mac
== SSL_MD5
&&
650 (evp
= EVP_get_cipherbyname("RC4-HMAC-MD5")))
651 *enc
= evp
, *md
= NULL
;
652 else if (c
->algorithm_enc
== SSL_AES128
&&
653 c
->algorithm_mac
== SSL_SHA1
&&
654 (evp
= EVP_get_cipherbyname("AES-128-CBC-HMAC-SHA1")))
655 *enc
= evp
, *md
= NULL
;
656 else if (c
->algorithm_enc
== SSL_AES256
&&
657 c
->algorithm_mac
== SSL_SHA1
&&
658 (evp
= EVP_get_cipherbyname("AES-256-CBC-HMAC-SHA1")))
659 *enc
= evp
, *md
= NULL
;
666 * ssl_cipher_get_evp_aead sets aead to point to the correct EVP_AEAD object
667 * for s->cipher. It returns 1 on success and 0 on error.
670 ssl_cipher_get_evp_aead(const SSL_SESSION
*s
, const EVP_AEAD
**aead
)
672 const SSL_CIPHER
*c
= s
->cipher
;
678 if ((c
->algorithm2
& SSL_CIPHER_ALGORITHM2_AEAD
) == 0)
681 switch (c
->algorithm_enc
) {
682 #ifndef OPENSSL_NO_AES
684 *aead
= EVP_aead_aes_128_gcm();
687 *aead
= EVP_aead_aes_256_gcm();
690 case SSL_CHACHA20POLY1305
:
691 *aead
= EVP_aead_chacha20_poly1305();
693 case SSL_CHACHA20POLY1305_OLD
:
694 *aead
= EVP_aead_chacha20_poly1305_old();
703 ssl_get_handshake_evp_md(SSL
*s
, const EVP_MD
**md
)
707 switch (ssl_get_algorithm2(s
) & SSL_HANDSHAKE_MAC_MASK
) {
708 case SSL_HANDSHAKE_MAC_DEFAULT
:
709 *md
= EVP_md5_sha1();
711 case SSL_HANDSHAKE_MAC_GOST94
:
712 *md
= EVP_gostr341194();
714 case SSL_HANDSHAKE_MAC_SHA256
:
717 case SSL_HANDSHAKE_MAC_SHA384
:
720 case SSL_HANDSHAKE_MAC_STREEBOG256
:
721 *md
= EVP_streebog256();
730 #define ITEM_SEP(a) \
731 (((a) == ':') || ((a) == ' ') || ((a) == ';') || ((a) == ','))
734 ll_append_tail(CIPHER_ORDER
**head
, CIPHER_ORDER
*curr
,
741 if (curr
->prev
!= NULL
)
742 curr
->prev
->next
= curr
->next
;
743 if (curr
->next
!= NULL
)
744 curr
->next
->prev
= curr
->prev
;
745 (*tail
)->next
= curr
;
752 ll_append_head(CIPHER_ORDER
**head
, CIPHER_ORDER
*curr
,
759 if (curr
->next
!= NULL
)
760 curr
->next
->prev
= curr
->prev
;
761 if (curr
->prev
!= NULL
)
762 curr
->prev
->next
= curr
->next
;
763 (*head
)->prev
= curr
;
770 ssl_cipher_get_disabled(unsigned long *mkey
, unsigned long *auth
,
771 unsigned long *enc
, unsigned long *mac
, unsigned long *ssl
)
780 * Check for the availability of GOST 34.10 public/private key
781 * algorithms. If they are not available disable the associated
782 * authentication and key exchange algorithms.
784 if (EVP_PKEY_meth_find(NID_id_GostR3410_2001
) == NULL
) {
785 *auth
|= SSL_aGOST01
;
789 #ifdef SSL_FORBID_ENULL
793 *enc
|= (ssl_cipher_methods
[SSL_ENC_DES_IDX
] == NULL
) ? SSL_DES
: 0;
794 *enc
|= (ssl_cipher_methods
[SSL_ENC_3DES_IDX
] == NULL
) ? SSL_3DES
: 0;
795 *enc
|= (ssl_cipher_methods
[SSL_ENC_RC4_IDX
] == NULL
) ? SSL_RC4
: 0;
796 *enc
|= (ssl_cipher_methods
[SSL_ENC_IDEA_IDX
] == NULL
) ? SSL_IDEA
: 0;
797 *enc
|= (ssl_cipher_methods
[SSL_ENC_AES128_IDX
] == NULL
) ? SSL_AES128
: 0;
798 *enc
|= (ssl_cipher_methods
[SSL_ENC_AES256_IDX
] == NULL
) ? SSL_AES256
: 0;
799 *enc
|= (ssl_cipher_methods
[SSL_ENC_AES128GCM_IDX
] == NULL
) ? SSL_AES128GCM
: 0;
800 *enc
|= (ssl_cipher_methods
[SSL_ENC_AES256GCM_IDX
] == NULL
) ? SSL_AES256GCM
: 0;
801 *enc
|= (ssl_cipher_methods
[SSL_ENC_CAMELLIA128_IDX
] == NULL
) ? SSL_CAMELLIA128
: 0;
802 *enc
|= (ssl_cipher_methods
[SSL_ENC_CAMELLIA256_IDX
] == NULL
) ? SSL_CAMELLIA256
: 0;
803 *enc
|= (ssl_cipher_methods
[SSL_ENC_GOST89_IDX
] == NULL
) ? SSL_eGOST2814789CNT
: 0;
805 *mac
|= (ssl_digest_methods
[SSL_MD_MD5_IDX
] == NULL
) ? SSL_MD5
: 0;
806 *mac
|= (ssl_digest_methods
[SSL_MD_SHA1_IDX
] == NULL
) ? SSL_SHA1
: 0;
807 *mac
|= (ssl_digest_methods
[SSL_MD_SHA256_IDX
] == NULL
) ? SSL_SHA256
: 0;
808 *mac
|= (ssl_digest_methods
[SSL_MD_SHA384_IDX
] == NULL
) ? SSL_SHA384
: 0;
809 *mac
|= (ssl_digest_methods
[SSL_MD_GOST94_IDX
] == NULL
) ? SSL_GOST94
: 0;
810 *mac
|= (ssl_digest_methods
[SSL_MD_GOST89MAC_IDX
] == NULL
) ? SSL_GOST89MAC
: 0;
811 *mac
|= (ssl_digest_methods
[SSL_MD_STREEBOG256_IDX
] == NULL
) ? SSL_STREEBOG256
: 0;
815 ssl_cipher_collect_ciphers(const SSL_METHOD
*ssl_method
, int num_of_ciphers
,
816 unsigned long disabled_mkey
, unsigned long disabled_auth
,
817 unsigned long disabled_enc
, unsigned long disabled_mac
,
818 unsigned long disabled_ssl
, CIPHER_ORDER
*co_list
,
819 CIPHER_ORDER
**head_p
, CIPHER_ORDER
**tail_p
)
825 * We have num_of_ciphers descriptions compiled in, depending on the
826 * method selected (SSLv3, TLSv1, etc). These will later be sorted in
827 * a linked list with at most num entries.
830 /* Get the initial list of ciphers */
831 co_list_num
= 0; /* actual count of ciphers */
832 for (i
= 0; i
< num_of_ciphers
; i
++) {
833 c
= ssl_method
->get_cipher(i
);
834 /* drop those that use any of that is not available */
835 if ((c
!= NULL
) && c
->valid
&&
836 !(c
->algorithm_mkey
& disabled_mkey
) &&
837 !(c
->algorithm_auth
& disabled_auth
) &&
838 !(c
->algorithm_enc
& disabled_enc
) &&
839 !(c
->algorithm_mac
& disabled_mac
) &&
840 !(c
->algorithm_ssl
& disabled_ssl
)) {
841 co_list
[co_list_num
].cipher
= c
;
842 co_list
[co_list_num
].next
= NULL
;
843 co_list
[co_list_num
].prev
= NULL
;
844 co_list
[co_list_num
].active
= 0;
847 if (!sk_push(ca_list,(char *)c)) goto err;
853 * Prepare linked list from list entries
855 if (co_list_num
> 0) {
856 co_list
[0].prev
= NULL
;
858 if (co_list_num
> 1) {
859 co_list
[0].next
= &co_list
[1];
861 for (i
= 1; i
< co_list_num
- 1; i
++) {
862 co_list
[i
].prev
= &co_list
[i
- 1];
863 co_list
[i
].next
= &co_list
[i
+ 1];
866 co_list
[co_list_num
- 1].prev
=
867 &co_list
[co_list_num
- 2];
870 co_list
[co_list_num
- 1].next
= NULL
;
872 *head_p
= &co_list
[0];
873 *tail_p
= &co_list
[co_list_num
- 1];
878 ssl_cipher_collect_aliases(const SSL_CIPHER
**ca_list
, int num_of_group_aliases
,
879 unsigned long disabled_mkey
, unsigned long disabled_auth
,
880 unsigned long disabled_enc
, unsigned long disabled_mac
,
881 unsigned long disabled_ssl
, CIPHER_ORDER
*head
)
883 CIPHER_ORDER
*ciph_curr
;
884 const SSL_CIPHER
**ca_curr
;
886 unsigned long mask_mkey
= ~disabled_mkey
;
887 unsigned long mask_auth
= ~disabled_auth
;
888 unsigned long mask_enc
= ~disabled_enc
;
889 unsigned long mask_mac
= ~disabled_mac
;
890 unsigned long mask_ssl
= ~disabled_ssl
;
893 * First, add the real ciphers as already collected
897 while (ciph_curr
!= NULL
) {
898 *ca_curr
= ciph_curr
->cipher
;
900 ciph_curr
= ciph_curr
->next
;
904 * Now we add the available ones from the cipher_aliases[] table.
905 * They represent either one or more algorithms, some of which
906 * in any affected category must be supported (set in enabled_mask),
907 * or represent a cipher strength value (will be added in any case because algorithms=0).
909 for (i
= 0; i
< num_of_group_aliases
; i
++) {
910 unsigned long algorithm_mkey
= cipher_aliases
[i
].algorithm_mkey
;
911 unsigned long algorithm_auth
= cipher_aliases
[i
].algorithm_auth
;
912 unsigned long algorithm_enc
= cipher_aliases
[i
].algorithm_enc
;
913 unsigned long algorithm_mac
= cipher_aliases
[i
].algorithm_mac
;
914 unsigned long algorithm_ssl
= cipher_aliases
[i
].algorithm_ssl
;
917 if ((algorithm_mkey
& mask_mkey
) == 0)
921 if ((algorithm_auth
& mask_auth
) == 0)
925 if ((algorithm_enc
& mask_enc
) == 0)
929 if ((algorithm_mac
& mask_mac
) == 0)
933 if ((algorithm_ssl
& mask_ssl
) == 0)
936 *ca_curr
= (SSL_CIPHER
*)(cipher_aliases
+ i
);
940 *ca_curr
= NULL
; /* end of list */
944 ssl_cipher_apply_rule(unsigned long cipher_id
, unsigned long alg_mkey
,
945 unsigned long alg_auth
, unsigned long alg_enc
, unsigned long alg_mac
,
946 unsigned long alg_ssl
, unsigned long algo_strength
,
947 int rule
, int strength_bits
, CIPHER_ORDER
**head_p
, CIPHER_ORDER
**tail_p
)
949 CIPHER_ORDER
*head
, *tail
, *curr
, *next
, *last
;
950 const SSL_CIPHER
*cp
;
954 if (rule
== CIPHER_DEL
)
955 reverse
= 1; /* needed to maintain sorting between currently deleted ciphers */
973 next
= reverse
? curr
->prev
: curr
->next
;
978 * Selection criteria is either the value of strength_bits
979 * or the algorithms used.
981 if (strength_bits
>= 0) {
982 if (strength_bits
!= cp
->strength_bits
)
986 if (alg_mkey
&& !(alg_mkey
& cp
->algorithm_mkey
))
988 if (alg_auth
&& !(alg_auth
& cp
->algorithm_auth
))
990 if (alg_enc
&& !(alg_enc
& cp
->algorithm_enc
))
992 if (alg_mac
&& !(alg_mac
& cp
->algorithm_mac
))
994 if (alg_ssl
&& !(alg_ssl
& cp
->algorithm_ssl
))
996 if ((algo_strength
& SSL_STRONG_MASK
) && !(algo_strength
& SSL_STRONG_MASK
& cp
->algo_strength
))
1001 /* add the cipher if it has not been added yet. */
1002 if (rule
== CIPHER_ADD
) {
1004 if (!curr
->active
) {
1005 ll_append_tail(&head
, curr
, &tail
);
1009 /* Move the added cipher to this location */
1010 else if (rule
== CIPHER_ORD
) {
1013 ll_append_tail(&head
, curr
, &tail
);
1015 } else if (rule
== CIPHER_DEL
) {
1018 /* most recently deleted ciphersuites get best positions
1019 * for any future CIPHER_ADD (note that the CIPHER_DEL loop
1020 * works in reverse to maintain the order) */
1021 ll_append_head(&head
, curr
, &tail
);
1024 } else if (rule
== CIPHER_KILL
) {
1029 curr
->prev
->next
= curr
->next
;
1033 if (curr
->next
!= NULL
)
1034 curr
->next
->prev
= curr
->prev
;
1035 if (curr
->prev
!= NULL
)
1036 curr
->prev
->next
= curr
->next
;
1047 ssl_cipher_strength_sort(CIPHER_ORDER
**head_p
, CIPHER_ORDER
**tail_p
)
1049 int max_strength_bits
, i
, *number_uses
;
1053 * This routine sorts the ciphers with descending strength. The sorting
1054 * must keep the pre-sorted sequence, so we apply the normal sorting
1055 * routine as '+' movement to the end of the list.
1057 max_strength_bits
= 0;
1059 while (curr
!= NULL
) {
1061 (curr
->cipher
->strength_bits
> max_strength_bits
))
1062 max_strength_bits
= curr
->cipher
->strength_bits
;
1066 number_uses
= calloc((max_strength_bits
+ 1), sizeof(int));
1068 SSLerrorx(ERR_R_MALLOC_FAILURE
);
1073 * Now find the strength_bits values actually used
1076 while (curr
!= NULL
) {
1078 number_uses
[curr
->cipher
->strength_bits
]++;
1082 * Go through the list of used strength_bits values in descending
1085 for (i
= max_strength_bits
; i
>= 0; i
--)
1086 if (number_uses
[i
] > 0)
1087 ssl_cipher_apply_rule(0, 0, 0, 0, 0, 0, 0, CIPHER_ORD
, i
, head_p
, tail_p
);
1094 ssl_cipher_process_rulestr(const char *rule_str
, CIPHER_ORDER
**head_p
,
1095 CIPHER_ORDER
**tail_p
, const SSL_CIPHER
**ca_list
)
1097 unsigned long alg_mkey
, alg_auth
, alg_enc
, alg_mac
, alg_ssl
;
1098 unsigned long algo_strength
;
1099 int j
, multi
, found
, rule
, retval
, ok
, buflen
;
1100 unsigned long cipher_id
= 0;
1101 const char *l
, *buf
;
1115 } else if (ch
== '+') {
1118 } else if (ch
== '!') {
1121 } else if (ch
== '@') {
1122 rule
= CIPHER_SPECIAL
;
1144 while (((ch
>= 'A') && (ch
<= 'Z')) ||
1145 ((ch
>= '0') && (ch
<= '9')) ||
1146 ((ch
>= 'a') && (ch
<= 'z')) ||
1147 (ch
== '-') || (ch
== '.')) {
1154 * We hit something we cannot deal with,
1155 * it is no command or separator nor
1156 * alphanumeric, so we call this an error.
1158 SSLerrorx(SSL_R_INVALID_COMMAND
);
1164 if (rule
== CIPHER_SPECIAL
) {
1165 /* unused -- avoid compiler warning */
1167 /* special treatment */
1171 /* check for multi-part specification */
1179 * Now search for the cipher alias in the ca_list.
1180 * Be careful with the strncmp, because the "buflen"
1181 * limitation will make the rule "ADH:SOME" and the
1182 * cipher "ADH-MY-CIPHER" look like a match for
1183 * buflen=3. So additionally check whether the cipher
1184 * name found has the correct length. We can save a
1185 * strlen() call: just checking for the '\0' at the
1186 * right place is sufficient, we have to strncmp()
1187 * anyway (we cannot use strcmp(), because buf is not
1192 while (ca_list
[j
]) {
1193 if (!strncmp(buf
, ca_list
[j
]->name
, buflen
) &&
1194 (ca_list
[j
]->name
[buflen
] == '\0')) {
1202 break; /* ignore this entry */
1204 if (ca_list
[j
]->algorithm_mkey
) {
1206 alg_mkey
&= ca_list
[j
]->algorithm_mkey
;
1212 alg_mkey
= ca_list
[j
]->algorithm_mkey
;
1215 if (ca_list
[j
]->algorithm_auth
) {
1217 alg_auth
&= ca_list
[j
]->algorithm_auth
;
1223 alg_auth
= ca_list
[j
]->algorithm_auth
;
1226 if (ca_list
[j
]->algorithm_enc
) {
1228 alg_enc
&= ca_list
[j
]->algorithm_enc
;
1234 alg_enc
= ca_list
[j
]->algorithm_enc
;
1237 if (ca_list
[j
]->algorithm_mac
) {
1239 alg_mac
&= ca_list
[j
]->algorithm_mac
;
1245 alg_mac
= ca_list
[j
]->algorithm_mac
;
1248 if (ca_list
[j
]->algo_strength
& SSL_STRONG_MASK
) {
1249 if (algo_strength
& SSL_STRONG_MASK
) {
1251 (ca_list
[j
]->algo_strength
&
1252 SSL_STRONG_MASK
) | ~SSL_STRONG_MASK
;
1253 if (!(algo_strength
&
1260 ca_list
[j
]->algo_strength
&
1264 if (ca_list
[j
]->valid
) {
1266 * explicit ciphersuite found; its protocol
1267 * version does not become part of the search
1270 cipher_id
= ca_list
[j
]->id
;
1273 * not an explicit ciphersuite; only in this
1274 * case, the protocol version is considered
1275 * part of the search pattern
1277 if (ca_list
[j
]->algorithm_ssl
) {
1280 ca_list
[j
]->algorithm_ssl
;
1287 ca_list
[j
]->algorithm_ssl
;
1296 * Ok, we have the rule, now apply it
1298 if (rule
== CIPHER_SPECIAL
) {
1299 /* special command */
1301 if ((buflen
== 8) && !strncmp(buf
, "STRENGTH", 8))
1302 ok
= ssl_cipher_strength_sort(head_p
, tail_p
);
1304 SSLerrorx(SSL_R_INVALID_COMMAND
);
1308 * We do not support any "multi" options
1309 * together with "@", so throw away the
1310 * rest of the command, if any left, until
1311 * end or ':' is found.
1313 while ((*l
!= '\0') && !ITEM_SEP(*l
))
1316 ssl_cipher_apply_rule(cipher_id
, alg_mkey
, alg_auth
,
1317 alg_enc
, alg_mac
, alg_ssl
, algo_strength
, rule
,
1318 -1, head_p
, tail_p
);
1320 while ((*l
!= '\0') && !ITEM_SEP(*l
))
1331 ssl_aes_is_accelerated(void)
1333 #if defined(__i386__) || defined(__x86_64__)
1334 return ((OPENSSL_cpu_caps() & (1ULL << 57)) != 0);
1340 STACK_OF(SSL_CIPHER
) *
1341 ssl_create_cipher_list(const SSL_METHOD
*ssl_method
,
1342 STACK_OF(SSL_CIPHER
) **cipher_list
,
1343 STACK_OF(SSL_CIPHER
) **cipher_list_by_id
,
1344 const char *rule_str
)
1346 int ok
, num_of_ciphers
, num_of_alias_max
, num_of_group_aliases
;
1347 unsigned long disabled_mkey
, disabled_auth
, disabled_enc
, disabled_mac
, disabled_ssl
;
1348 STACK_OF(SSL_CIPHER
) *cipherstack
, *tmp_cipher_list
;
1350 CIPHER_ORDER
*co_list
= NULL
, *head
= NULL
, *tail
= NULL
, *curr
;
1351 const SSL_CIPHER
**ca_list
= NULL
;
1354 * Return with error if nothing to do.
1356 if (rule_str
== NULL
|| cipher_list
== NULL
|| cipher_list_by_id
== NULL
)
1360 * To reduce the work to do we only want to process the compiled
1361 * in algorithms, so we first get the mask of disabled ciphers.
1363 ssl_cipher_get_disabled(&disabled_mkey
, &disabled_auth
, &disabled_enc
, &disabled_mac
, &disabled_ssl
);
1366 * Now we have to collect the available ciphers from the compiled
1367 * in ciphers. We cannot get more than the number compiled in, so
1368 * it is used for allocation.
1370 num_of_ciphers
= ssl_method
->num_ciphers();
1371 co_list
= reallocarray(NULL
, num_of_ciphers
, sizeof(CIPHER_ORDER
));
1372 if (co_list
== NULL
) {
1373 SSLerrorx(ERR_R_MALLOC_FAILURE
);
1374 return(NULL
); /* Failure */
1377 ssl_cipher_collect_ciphers(ssl_method
, num_of_ciphers
,
1378 disabled_mkey
, disabled_auth
, disabled_enc
, disabled_mac
, disabled_ssl
,
1379 co_list
, &head
, &tail
);
1382 /* Now arrange all ciphers by preference: */
1384 /* Everything else being equal, prefer ephemeral ECDH over other key exchange mechanisms */
1385 ssl_cipher_apply_rule(0, SSL_kECDHE
, 0, 0, 0, 0, 0, CIPHER_ADD
, -1, &head
, &tail
);
1386 ssl_cipher_apply_rule(0, SSL_kECDHE
, 0, 0, 0, 0, 0, CIPHER_DEL
, -1, &head
, &tail
);
1388 if (ssl_aes_is_accelerated() == 1) {
1390 * We have hardware assisted AES - prefer AES as a symmetric
1391 * cipher, with CHACHA20 second.
1393 ssl_cipher_apply_rule(0, 0, 0, SSL_AES
, 0, 0, 0,
1394 CIPHER_ADD
, -1, &head
, &tail
);
1395 ssl_cipher_apply_rule(0, 0, 0, SSL_CHACHA20POLY1305
,
1396 0, 0, 0, CIPHER_ADD
, -1, &head
, &tail
);
1397 ssl_cipher_apply_rule(0, 0, 0, SSL_CHACHA20POLY1305_OLD
,
1398 0, 0, 0, CIPHER_ADD
, -1, &head
, &tail
);
1401 * CHACHA20 is fast and safe on all hardware and is thus our
1402 * preferred symmetric cipher, with AES second.
1404 ssl_cipher_apply_rule(0, 0, 0, SSL_CHACHA20POLY1305
,
1405 0, 0, 0, CIPHER_ADD
, -1, &head
, &tail
);
1406 ssl_cipher_apply_rule(0, 0, 0, SSL_CHACHA20POLY1305_OLD
,
1407 0, 0, 0, CIPHER_ADD
, -1, &head
, &tail
);
1408 ssl_cipher_apply_rule(0, 0, 0, SSL_AES
, 0, 0, 0,
1409 CIPHER_ADD
, -1, &head
, &tail
);
1412 /* Temporarily enable everything else for sorting */
1413 ssl_cipher_apply_rule(0, 0, 0, 0, 0, 0, 0, CIPHER_ADD
, -1, &head
, &tail
);
1415 /* Low priority for MD5 */
1416 ssl_cipher_apply_rule(0, 0, 0, 0, SSL_MD5
, 0, 0, CIPHER_ORD
, -1, &head
, &tail
);
1418 /* Move anonymous ciphers to the end. Usually, these will remain disabled.
1419 * (For applications that allow them, they aren't too bad, but we prefer
1420 * authenticated ciphers.) */
1421 ssl_cipher_apply_rule(0, 0, SSL_aNULL
, 0, 0, 0, 0, CIPHER_ORD
, -1, &head
, &tail
);
1423 /* Move ciphers without forward secrecy to the end */
1424 ssl_cipher_apply_rule(0, SSL_kRSA
, 0, 0, 0, 0, 0, CIPHER_ORD
, -1, &head
, &tail
);
1426 /* RC4 is sort of broken - move it to the end */
1427 ssl_cipher_apply_rule(0, 0, 0, SSL_RC4
, 0, 0, 0, CIPHER_ORD
, -1, &head
, &tail
);
1429 /* Now sort by symmetric encryption strength. The above ordering remains
1430 * in force within each class */
1431 if (!ssl_cipher_strength_sort(&head
, &tail
)) {
1436 /* Now disable everything (maintaining the ordering!) */
1437 ssl_cipher_apply_rule(0, 0, 0, 0, 0, 0, 0, CIPHER_DEL
, -1, &head
, &tail
);
1441 * We also need cipher aliases for selecting based on the rule_str.
1442 * There might be two types of entries in the rule_str: 1) names
1443 * of ciphers themselves 2) aliases for groups of ciphers.
1444 * For 1) we need the available ciphers and for 2) the cipher
1445 * groups of cipher_aliases added together in one list (otherwise
1446 * we would be happy with just the cipher_aliases table).
1448 num_of_group_aliases
= sizeof(cipher_aliases
) / sizeof(SSL_CIPHER
);
1449 num_of_alias_max
= num_of_ciphers
+ num_of_group_aliases
+ 1;
1450 ca_list
= reallocarray(NULL
, num_of_alias_max
, sizeof(SSL_CIPHER
*));
1451 if (ca_list
== NULL
) {
1453 SSLerrorx(ERR_R_MALLOC_FAILURE
);
1454 return(NULL
); /* Failure */
1456 ssl_cipher_collect_aliases(ca_list
, num_of_group_aliases
,
1457 disabled_mkey
, disabled_auth
, disabled_enc
,
1458 disabled_mac
, disabled_ssl
, head
);
1461 * If the rule_string begins with DEFAULT, apply the default rule
1462 * before using the (possibly available) additional rules.
1466 if (strncmp(rule_str
, "DEFAULT", 7) == 0) {
1467 ok
= ssl_cipher_process_rulestr(SSL_DEFAULT_CIPHER_LIST
,
1468 &head
, &tail
, ca_list
);
1474 if (ok
&& (strlen(rule_p
) > 0))
1475 ok
= ssl_cipher_process_rulestr(rule_p
, &head
, &tail
, ca_list
);
1477 free((void *)ca_list
); /* Not needed anymore */
1480 /* Rule processing failure */
1486 * Allocate new "cipherstack" for the result, return with error
1487 * if we cannot get one.
1489 if ((cipherstack
= sk_SSL_CIPHER_new_null()) == NULL
) {
1495 * The cipher selection for the list is done. The ciphers are added
1496 * to the resulting precedence to the STACK_OF(SSL_CIPHER).
1498 for (curr
= head
; curr
!= NULL
; curr
= curr
->next
) {
1500 sk_SSL_CIPHER_push(cipherstack
, curr
->cipher
);
1503 free(co_list
); /* Not needed any longer */
1505 tmp_cipher_list
= sk_SSL_CIPHER_dup(cipherstack
);
1506 if (tmp_cipher_list
== NULL
) {
1507 sk_SSL_CIPHER_free(cipherstack
);
1510 sk_SSL_CIPHER_free(*cipher_list
);
1511 *cipher_list
= cipherstack
;
1512 sk_SSL_CIPHER_free(*cipher_list_by_id
);
1513 *cipher_list_by_id
= tmp_cipher_list
;
1514 (void)sk_SSL_CIPHER_set_cmp_func(*cipher_list_by_id
,
1515 ssl_cipher_ptr_id_cmp
);
1517 sk_SSL_CIPHER_sort(*cipher_list_by_id
);
1518 return (cipherstack
);
1522 SSL_CIPHER_get_by_id(unsigned int id
)
1524 return ssl3_get_cipher_by_id(id
);
1528 SSL_CIPHER_get_by_value(uint16_t value
)
1530 return ssl3_get_cipher_by_value(value
);
1534 SSL_CIPHER_description(const SSL_CIPHER
*cipher
, char *buf
, int len
)
1536 unsigned long alg_mkey
, alg_auth
, alg_enc
, alg_mac
, alg_ssl
, alg2
;
1537 const char *ver
, *kx
, *au
, *enc
, *mac
;
1541 alg_mkey
= cipher
->algorithm_mkey
;
1542 alg_auth
= cipher
->algorithm_auth
;
1543 alg_enc
= cipher
->algorithm_enc
;
1544 alg_mac
= cipher
->algorithm_mac
;
1545 alg_ssl
= cipher
->algorithm_ssl
;
1547 alg2
= cipher
->algorithm2
;
1549 if (alg_ssl
& SSL_SSLV3
)
1551 else if (alg_ssl
& SSL_TLSV1_2
)
1602 enc
= alg2
& SSL2_CF_8_BYTE_ENC
? "RC4(64)" : "RC4(128)";
1617 enc
= "AESGCM(128)";
1620 enc
= "AESGCM(256)";
1622 case SSL_CAMELLIA128
:
1623 enc
= "Camellia(128)";
1625 case SSL_CAMELLIA256
:
1626 enc
= "Camellia(256)";
1628 case SSL_CHACHA20POLY1305
:
1629 enc
= "ChaCha20-Poly1305";
1631 case SSL_CHACHA20POLY1305_OLD
:
1632 enc
= "ChaCha20-Poly1305-Old";
1634 case SSL_eGOST2814789CNT
:
1635 enc
= "GOST-28178-89-CNT";
1664 case SSL_STREEBOG256
:
1665 mac
= "STREEBOG256";
1672 if (asprintf(&ret
, "%-23s %s Kx=%-8s Au=%-4s Enc=%-9s Mac=%-4s\n",
1673 cipher
->name
, ver
, kx
, au
, enc
, mac
) == -1)
1674 return "OPENSSL_malloc Error";
1677 l
= strlcpy(buf
, ret
, len
);
1681 ret
= "Buffer too small";
1688 SSL_CIPHER_get_version(const SSL_CIPHER
*c
)
1692 if ((c
->id
>> 24) == 3)
1693 return("TLSv1/SSLv3");
1698 /* return the actual cipher being used */
1700 SSL_CIPHER_get_name(const SSL_CIPHER
*c
)
1707 /* number of bits for symmetric cipher */
1709 SSL_CIPHER_get_bits(const SSL_CIPHER
*c
, int *alg_bits
)
1714 if (alg_bits
!= NULL
)
1715 *alg_bits
= c
->alg_bits
;
1716 ret
= c
->strength_bits
;
1722 SSL_CIPHER_get_id(const SSL_CIPHER
*c
)
1728 SSL_CIPHER_get_value(const SSL_CIPHER
*c
)
1730 return ssl3_cipher_get_value(c
);
1734 SSL_COMP_get_compression_methods(void)
1740 SSL_COMP_add_compression_method(int id
, void *cm
)
1746 SSL_COMP_get_name(const void *comp
)