Update from 0.9.8-stable.
[openssl.git] / ssl / ssl_ciph.c
index e60a490a52cc41d0b300ec508c021783c099ab30..87c5f61670007305f8c7777068b9c6fb294e2056 100644 (file)
 
 #include <stdio.h>
 #include <openssl/objects.h>
+#ifndef OPENSSL_NO_COMP
 #include <openssl/comp.h>
+#endif
+#ifndef OPENSSL_NO_ENGINE
 #include <openssl/engine.h>
+#endif
 #include "ssl_locl.h"
 
 #define SSL_ENC_DES_IDX                0
@@ -314,20 +318,38 @@ static const SSL_CIPHER cipher_aliases[]={
 /* Search for public key algorithm with given name and 
  * return its pkey_id if it is available. Otherwise return 0
  */
+#ifdef OPENSSL_NO_ENGINE
+
 static int get_optional_pkey_id(const char *pkey_name)
        {
        const EVP_PKEY_ASN1_METHOD *ameth;
-       ENGINE *tmpeng = NULL;
        int pkey_id=0;
-       ameth = EVP_PKEY_asn1_find_str(&tmpeng,pkey_name,-1);
+       ameth = EVP_PKEY_asn1_find_str(NULL,pkey_name,-1);
        if (ameth) 
                {
                EVP_PKEY_asn1_get0_info(&pkey_id, NULL,NULL,NULL,NULL,ameth);
                }               
-       if (tmpeng) ENGINE_finish(tmpeng);      
        return pkey_id;
        }
 
+#else
+
+static int get_optional_pkey_id(const char *pkey_name)
+       {
+       const EVP_PKEY_ASN1_METHOD *ameth;
+       ENGINE *tmpeng = NULL;
+       int pkey_id=0;
+       ameth = EVP_PKEY_asn1_find_str(&tmpeng,pkey_name,-1);
+       if (ameth)
+               {
+               EVP_PKEY_asn1_get0_info(&pkey_id, NULL,NULL,NULL,NULL,ameth);
+               }
+       if (tmpeng) ENGINE_finish(tmpeng);
+       return pkey_id;
+       }
+
+#endif
+
 void ssl_load_ciphers(void)
        {
        ssl_cipher_methods[SSL_ENC_DES_IDX]= 
@@ -361,16 +383,19 @@ void ssl_load_ciphers(void)
                EVP_get_digestbyname(SN_md5);
        ssl_mac_secret_size[SSL_MD_MD5_IDX]=
                EVP_MD_size(ssl_digest_methods[SSL_MD_MD5_IDX]);
+       OPENSSL_assert(ssl_mac_secret_size[SSL_MD_MD5_IDX] >= 0);
        ssl_digest_methods[SSL_MD_SHA1_IDX]=
                EVP_get_digestbyname(SN_sha1);
        ssl_mac_secret_size[SSL_MD_SHA1_IDX]=
                EVP_MD_size(ssl_digest_methods[SSL_MD_SHA1_IDX]);
+       OPENSSL_assert(ssl_mac_secret_size[SSL_MD_SHA1_IDX] >= 0);
        ssl_digest_methods[SSL_MD_GOST94_IDX]=
                EVP_get_digestbyname(SN_id_GostR3411_94);
        if (ssl_digest_methods[SSL_MD_GOST94_IDX])
                {       
                ssl_mac_secret_size[SSL_MD_GOST94_IDX]=
                        EVP_MD_size(ssl_digest_methods[SSL_MD_GOST94_IDX]);
+               OPENSSL_assert(ssl_mac_secret_size[SSL_MD_GOST94_IDX] >= 0);
                }
        ssl_digest_methods[SSL_MD_GOST89MAC_IDX]=
                EVP_get_digestbyname(SN_id_Gost28147_89_MAC);
@@ -1353,8 +1378,8 @@ STACK_OF(SSL_CIPHER) *ssl_create_cipher_list(const SSL_METHOD *ssl_method,
                return(NULL);   /* Failure */
                }
        ssl_cipher_collect_aliases(ca_list, num_of_group_aliases,
-                                  disabled_mkey, disabled_auth, disabled_enc, disabled_mac, disabled_ssl,
-                                  head);
+                                  disabled_mkey, disabled_auth, disabled_enc,
+                                  disabled_mac, disabled_ssl, head);
 
        /*
         * If the rule_string begins with DEFAULT, apply the default rule
@@ -1374,7 +1399,7 @@ STACK_OF(SSL_CIPHER) *ssl_create_cipher_list(const SSL_METHOD *ssl_method,
        if (ok && (strlen(rule_p) > 0))
                ok = ssl_cipher_process_rulestr(rule_p, &head, &tail, ca_list);
 
-       OPENSSL_free(ca_list);  /* Not needed anymore */
+       OPENSSL_free((void *)ca_list);  /* Not needed anymore */
 
        if (!ok)
                {       /* Rule processing failure */
@@ -1422,6 +1447,7 @@ STACK_OF(SSL_CIPHER) *ssl_create_cipher_list(const SSL_METHOD *ssl_method,
        *cipher_list_by_id = tmp_cipher_list;
        (void)sk_SSL_CIPHER_set_cmp_func(*cipher_list_by_id,ssl_cipher_ptr_id_cmp);
 
+       sk_SSL_CIPHER_sort(*cipher_list_by_id);
        return(cipherstack);
        }
 
@@ -1690,7 +1716,7 @@ int SSL_COMP_add_compression_method(int id, COMP_METHOD *cm)
        comp->method=cm;
        load_builtin_compressions();
        if (ssl_comp_methods
-               && !sk_SSL_COMP_find(ssl_comp_methods,comp))
+               && sk_SSL_COMP_find(ssl_comp_methods,comp) >= 0)
                {
                OPENSSL_free(comp);
                MemCheck_on();