DH *ssl_get_auto_dh(SSL *s)
{
    int dh_secbits = 80;
    if (s->cert->dh_tmp_auto == 2)
        return DH_get_1024_160();
    if (s->s3->tmp.new_cipher->algorithm_auth & (SSL_aNULL | SSL_aPSK)) {
        if (s->s3->tmp.new_cipher->strength_bits == 256)
            dh_secbits = 128;
        else
            dh_secbits = 80;
    } else {
        CERT_PKEY *cpk = ssl_get_server_send_pkey(s);
        dh_secbits = EVP_PKEY_security_bits(cpk->privatekey);
    }
    if (dh_secbits >= 128) {
        DH *dhp = DH_new();
        if (dhp == NULL)
            return NULL;
        dhp->g = BN_new();
        if (dhp->g != NULL)
            BN_set_word(dhp->g, 2);
        if (dh_secbits >= 192)
            dhp->p = get_rfc3526_prime_8192(NULL);
        else
            dhp->p = get_rfc3526_prime_3072(NULL);
        if (dhp->p == NULL || dhp->g == NULL) {
            DH_free(dhp);
            return NULL;
        }
        return dhp;
    }
    if (dh_secbits >= 112)
        return DH_get_2048_224();
    return DH_get_1024_160();
}
['DH *ssl_get_auto_dh(SSL *s)\n{\n    int dh_secbits = 80;\n    if (s->cert->dh_tmp_auto == 2)\n        return DH_get_1024_160();\n    if (s->s3->tmp.new_cipher->algorithm_auth & (SSL_aNULL | SSL_aPSK)) {\n        if (s->s3->tmp.new_cipher->strength_bits == 256)\n            dh_secbits = 128;\n        else\n            dh_secbits = 80;\n    } else {\n        CERT_PKEY *cpk = ssl_get_server_send_pkey(s);\n        dh_secbits = EVP_PKEY_security_bits(cpk->privatekey);\n    }\n    if (dh_secbits >= 128) {\n        DH *dhp = DH_new();\n        if (dhp == NULL)\n            return NULL;\n        dhp->g = BN_new();\n        if (dhp->g != NULL)\n            BN_set_word(dhp->g, 2);\n        if (dh_secbits >= 192)\n            dhp->p = get_rfc3526_prime_8192(NULL);\n        else\n            dhp->p = get_rfc3526_prime_3072(NULL);\n        if (dhp->p == NULL || dhp->g == NULL) {\n            DH_free(dhp);\n            return NULL;\n        }\n        return dhp;\n    }\n    if (dh_secbits >= 112)\n        return DH_get_2048_224();\n    return DH_get_1024_160();\n}', 'CERT_PKEY *ssl_get_server_send_pkey(SSL *s)\n{\n    CERT *c;\n    int i;\n    c = s->cert;\n    if (!s->s3 || !s->s3->tmp.new_cipher)\n        return NULL;\n    ssl_set_masks(s, s->s3->tmp.new_cipher);\n#ifdef OPENSSL_SSL_DEBUG_BROKEN_PROTOCOL\n    if (c->cert_flags & SSL_CERT_FLAG_BROKEN_PROTOCOL)\n        return c->key;\n#endif\n    i = ssl_get_server_cert_index(s);\n    if (i < 0)\n        return NULL;\n    return &c->pkeys[i];\n}', 'static int ssl_get_server_cert_index(const SSL *s)\n{\n    int idx;\n    idx = ssl_cipher_get_cert_index(s->s3->tmp.new_cipher);\n    if (idx == SSL_PKEY_RSA_ENC && !s->cert->pkeys[SSL_PKEY_RSA_ENC].x509)\n        idx = SSL_PKEY_RSA_SIGN;\n    if (idx == SSL_PKEY_GOST_EC) {\n        if (s->cert->pkeys[SSL_PKEY_GOST12_512].x509)\n            idx = SSL_PKEY_GOST12_512;\n        else if (s->cert->pkeys[SSL_PKEY_GOST12_256].x509)\n            idx = SSL_PKEY_GOST12_256;\n        else if (s->cert->pkeys[SSL_PKEY_GOST01].x509)\n            idx = SSL_PKEY_GOST01;\n        else\n            idx = -1;\n    }\n    if (idx == -1)\n        SSLerr(SSL_F_SSL_GET_SERVER_CERT_INDEX, ERR_R_INTERNAL_ERROR);\n    return idx;\n}', 'int ssl_cipher_get_cert_index(const SSL_CIPHER *c)\n{\n    uint32_t alg_k, alg_a;\n    alg_k = c->algorithm_mkey;\n    alg_a = c->algorithm_auth;\n    if (alg_k & (SSL_kECDHr | SSL_kECDHe)) {\n        return SSL_PKEY_ECC;\n    } else if (alg_a & SSL_aECDSA)\n        return SSL_PKEY_ECC;\n    else if (alg_a & SSL_aDSS)\n        return SSL_PKEY_DSA_SIGN;\n    else if (alg_a & SSL_aRSA)\n        return SSL_PKEY_RSA_ENC;\n    else if (alg_a & SSL_aGOST12)\n        return SSL_PKEY_GOST_EC;\n    else if (alg_a & SSL_aGOST01)\n        return SSL_PKEY_GOST01;\n    return -1;\n}']