int tls_choose_sigalg(SSL *s)
{
    if (SSL_IS_TLS13(s)) {
        size_t i;
#ifndef OPENSSL_NO_EC
        int curve = -1;
#endif
        for (i = 0; i < s->cert->shared_sigalgslen; i++) {
            const SIGALG_LOOKUP *lu = s->cert->shared_sigalgs[i];
            int idx;
            const EVP_MD *md;
            CERT_PKEY *c;
            if (lu->sig == EVP_PKEY_RSA)
                continue;
            md = ssl_md(lu->hash_idx);
            if (md == NULL)
                continue;
            idx = lu->sig_idx;
            c = &s->cert->pkeys[idx];
            if (c->x509 == NULL || c->privatekey == NULL) {
                if (idx != SSL_PKEY_RSA_SIGN)
                    continue;
                idx = SSL_PKEY_RSA_ENC;
                c = s->cert->pkeys + idx;
                if (c->x509 == NULL || c->privatekey == NULL)
                    continue;
            }
            if (lu->sig == EVP_PKEY_EC) {
#ifndef OPENSSL_NO_EC
                if (curve == -1) {
                    EC_KEY *ec = EVP_PKEY_get0_EC_KEY(c->privatekey);
                    curve = EC_GROUP_get_curve_name(EC_KEY_get0_group(ec));
                }
                if (curve != lu->curve)
                    continue;
#else
                continue;
#endif
            }
            s->s3->tmp.sigalg = lu;
            s->s3->tmp.cert_idx = idx;
            s->s3->tmp.md[idx] = md;
            s->cert->key = s->cert->pkeys + idx;
            return 1;
        }
        return 0;
    }
    return 1;
}
['int tls_choose_sigalg(SSL *s)\n{\n    if (SSL_IS_TLS13(s)) {\n        size_t i;\n#ifndef OPENSSL_NO_EC\n        int curve = -1;\n#endif\n        for (i = 0; i < s->cert->shared_sigalgslen; i++) {\n            const SIGALG_LOOKUP *lu = s->cert->shared_sigalgs[i];\n            int idx;\n            const EVP_MD *md;\n            CERT_PKEY *c;\n            if (lu->sig == EVP_PKEY_RSA)\n                continue;\n            md = ssl_md(lu->hash_idx);\n            if (md == NULL)\n                continue;\n            idx = lu->sig_idx;\n            c = &s->cert->pkeys[idx];\n            if (c->x509 == NULL || c->privatekey == NULL) {\n                if (idx != SSL_PKEY_RSA_SIGN)\n                    continue;\n                idx = SSL_PKEY_RSA_ENC;\n                c = s->cert->pkeys + idx;\n                if (c->x509 == NULL || c->privatekey == NULL)\n                    continue;\n            }\n            if (lu->sig == EVP_PKEY_EC) {\n#ifndef OPENSSL_NO_EC\n                if (curve == -1) {\n                    EC_KEY *ec = EVP_PKEY_get0_EC_KEY(c->privatekey);\n                    curve = EC_GROUP_get_curve_name(EC_KEY_get0_group(ec));\n                }\n                if (curve != lu->curve)\n                    continue;\n#else\n                continue;\n#endif\n            }\n            s->s3->tmp.sigalg = lu;\n            s->s3->tmp.cert_idx = idx;\n            s->s3->tmp.md[idx] = md;\n            s->cert->key = s->cert->pkeys + idx;\n            return 1;\n        }\n        return 0;\n    }\n    return 1;\n}', 'const EVP_MD *ssl_md(int idx)\n{\n    idx &= SSL_HANDSHAKE_MAC_MASK;\n    if (idx < 0 || idx >= SSL_MD_NUM_IDX)\n        return NULL;\n    return ssl_digest_methods[idx];\n}', 'EC_KEY *EVP_PKEY_get0_EC_KEY(EVP_PKEY *pkey)\n{\n    if (pkey->type != EVP_PKEY_EC) {\n        EVPerr(EVP_F_EVP_PKEY_GET0_EC_KEY, EVP_R_EXPECTING_A_EC_KEY);\n        return NULL;\n    }\n    return pkey->pkey.ec;\n}', 'const EC_GROUP *EC_KEY_get0_group(const EC_KEY *key)\n{\n    return key->group;\n}']