void *OPENSSL_LH_delete(OPENSSL_LHASH *lh, const void *data)
{
    unsigned long hash;
    OPENSSL_LH_NODE *nn, **rn;
    void *ret;
    lh->error = 0;
    rn = getrn(lh, data, &hash);
    if (*rn == NULL) {
        lh->num_no_delete++;
        return (NULL);
    } else {
        nn = *rn;
        *rn = nn->next;
        ret = nn->data;
        OPENSSL_free(nn);
        lh->num_delete++;
    }
    lh->num_items--;
    if ((lh->num_nodes > MIN_NODES) &&
        (lh->down_load >= (lh->num_items * LH_LOAD_MULT / lh->num_nodes)))
        contract(lh);
    return (ret);
}
['static int state_machine(SSL *s, int server)\n{\n    BUF_MEM *buf = NULL;\n    unsigned long Time = (unsigned long)time(NULL);\n    void (*cb) (const SSL *ssl, int type, int val) = NULL;\n    OSSL_STATEM *st = &s->statem;\n    int ret = -1;\n    int ssret;\n    if (st->state == MSG_FLOW_ERROR) {\n        return -1;\n    }\n    RAND_add(&Time, sizeof(Time), 0);\n    ERR_clear_error();\n    clear_sys_error();\n    cb = get_callback(s);\n    st->in_handshake++;\n    if (!SSL_in_init(s) || SSL_in_before(s)) {\n        if (!SSL_clear(s))\n            return -1;\n    }\n#ifndef OPENSSL_NO_SCTP\n    if (SSL_IS_DTLS(s)) {\n        BIO_ctrl(SSL_get_wbio(s), BIO_CTRL_DGRAM_SCTP_SET_IN_HANDSHAKE,\n                 st->in_handshake, NULL);\n    }\n#endif\n    if (st->state == MSG_FLOW_UNINITED\n            || st->state == MSG_FLOW_FINISHED) {\n        if (st->state == MSG_FLOW_UNINITED) {\n            st->hand_state = TLS_ST_BEFORE;\n            st->request_state = TLS_ST_BEFORE;\n        }\n        s->server = server;\n        if (cb != NULL)\n            cb(s, SSL_CB_HANDSHAKE_START, 1);\n        if (SSL_IS_DTLS(s)) {\n            if ((s->version & 0xff00) != (DTLS1_VERSION & 0xff00) &&\n                (server || (s->version & 0xff00) != (DTLS1_BAD_VER & 0xff00))) {\n                SSLerr(SSL_F_STATE_MACHINE, ERR_R_INTERNAL_ERROR);\n                goto end;\n            }\n        } else {\n            if ((s->version >> 8) != SSL3_VERSION_MAJOR) {\n                SSLerr(SSL_F_STATE_MACHINE, ERR_R_INTERNAL_ERROR);\n                goto end;\n            }\n        }\n        if (!ssl_security(s, SSL_SECOP_VERSION, 0, s->version, NULL)) {\n            SSLerr(SSL_F_STATE_MACHINE, SSL_R_VERSION_TOO_LOW);\n            goto end;\n        }\n        if (s->init_buf == NULL) {\n            if ((buf = BUF_MEM_new()) == NULL) {\n                goto end;\n            }\n            if (!BUF_MEM_grow(buf, SSL3_RT_MAX_PLAIN_LENGTH)) {\n                goto end;\n            }\n            s->init_buf = buf;\n            buf = NULL;\n        }\n        if (!ssl3_setup_buffers(s)) {\n            goto end;\n        }\n        s->init_num = 0;\n        s->s3->change_cipher_spec = 0;\n#ifndef OPENSSL_NO_SCTP\n        if (!SSL_IS_DTLS(s) || !BIO_dgram_is_sctp(SSL_get_wbio(s)))\n#endif\n            if (!ssl_init_wbio_buffer(s)) {\n                goto end;\n            }\n        if ((SSL_in_before(s))\n                || s->renegotiate) {\n            if (!tls_setup_handshake(s)) {\n                ossl_statem_set_error(s);\n                goto end;\n            }\n            if (SSL_IS_FIRST_HANDSHAKE(s))\n                st->read_state_first_init = 1;\n        }\n        st->state = MSG_FLOW_WRITING;\n        init_write_state_machine(s);\n    }\n    while (st->state != MSG_FLOW_FINISHED) {\n        if (st->state == MSG_FLOW_READING) {\n            ssret = read_state_machine(s);\n            if (ssret == SUB_STATE_FINISHED) {\n                st->state = MSG_FLOW_WRITING;\n                init_write_state_machine(s);\n            } else {\n                goto end;\n            }\n        } else if (st->state == MSG_FLOW_WRITING) {\n            ssret = write_state_machine(s);\n            if (ssret == SUB_STATE_FINISHED) {\n                st->state = MSG_FLOW_READING;\n                init_read_state_machine(s);\n            } else if (ssret == SUB_STATE_END_HANDSHAKE) {\n                st->state = MSG_FLOW_FINISHED;\n            } else {\n                goto end;\n            }\n        } else {\n            ossl_statem_set_error(s);\n            goto end;\n        }\n    }\n    ret = 1;\n end:\n    st->in_handshake--;\n#ifndef OPENSSL_NO_SCTP\n    if (SSL_IS_DTLS(s)) {\n        BIO_ctrl(SSL_get_wbio(s), BIO_CTRL_DGRAM_SCTP_SET_IN_HANDSHAKE,\n                 st->in_handshake, NULL);\n    }\n#endif\n    BUF_MEM_free(buf);\n    if (cb != NULL) {\n        if (server)\n            cb(s, SSL_CB_ACCEPT_EXIT, ret);\n        else\n            cb(s, SSL_CB_CONNECT_EXIT, ret);\n    }\n    return ret;\n}', 'int tls_setup_handshake(SSL *s)\n{\n    if (!ssl3_init_finished_mac(s))\n        return 0;\n    if (s->server) {\n        STACK_OF(SSL_CIPHER) *ciphers = SSL_get_ciphers(s);\n        int i, ver_min, ver_max, ok = 0;\n        if (ssl_get_min_max_version(s, &ver_min, &ver_max) != 0) {\n            SSLerr(SSL_F_TLS_SETUP_HANDSHAKE, ERR_R_INTERNAL_ERROR);\n            ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_INTERNAL_ERROR);\n            return 0;\n        }\n        for (i = 0; i < sk_SSL_CIPHER_num(ciphers); i++) {\n            const SSL_CIPHER *c = sk_SSL_CIPHER_value(ciphers, i);\n            if (SSL_IS_DTLS(s)) {\n                if (DTLS_VERSION_GE(ver_max, c->min_dtls) &&\n                        DTLS_VERSION_LE(ver_max, c->max_dtls))\n                    ok = 1;\n            } else if (ver_max >= c->min_tls && ver_max <= c->max_tls) {\n                ok = 1;\n            }\n            if (ok)\n                break;\n        }\n        if (!ok) {\n            SSLerr(SSL_F_TLS_SETUP_HANDSHAKE, SSL_R_NO_CIPHERS_AVAILABLE);\n            ERR_add_error_data(1, "No ciphers enabled for max supported "\n                                  "SSL/TLS version");\n            ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_HANDSHAKE_FAILURE);\n            return 0;\n        }\n        if (SSL_IS_FIRST_HANDSHAKE(s)) {\n            s->ctx->stats.sess_accept++;\n        } else if (!s->s3->send_connection_binding &&\n                   !(s->options &\n                     SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION)) {\n            SSLerr(SSL_F_TLS_SETUP_HANDSHAKE,\n                   SSL_R_UNSAFE_LEGACY_RENEGOTIATION_DISABLED);\n            ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_HANDSHAKE_FAILURE);\n            return 0;\n        } else {\n            s->ctx->stats.sess_accept_renegotiate++;\n            s->s3->tmp.cert_request = 0;\n        }\n    } else {\n        if (SSL_IS_FIRST_HANDSHAKE(s))\n            s->ctx->stats.sess_connect++;\n        else\n            s->ctx->stats.sess_connect_renegotiate++;\n        memset(s->s3->client_random, 0, sizeof(s->s3->client_random));\n        s->hit = 0;\n        s->s3->tmp.cert_req = 0;\n        if (SSL_IS_DTLS(s))\n            s->statem.use_timer = 1;\n    }\n    return 1;\n}', 'int ssl3_send_alert(SSL *s, int level, int desc)\n{\n    if (SSL_TREAT_AS_TLS13(s))\n        desc = tls13_alert_code(desc);\n    else\n        desc = s->method->ssl3_enc->alert_value(desc);\n    if (s->version == SSL3_VERSION && desc == SSL_AD_PROTOCOL_VERSION)\n        desc = SSL_AD_HANDSHAKE_FAILURE;\n    if (desc < 0)\n        return -1;\n    if ((level == SSL3_AL_FATAL) && (s->session != NULL))\n        SSL_CTX_remove_session(s->session_ctx, s->session);\n    s->s3->alert_dispatch = 1;\n    s->s3->send_alert[0] = level;\n    s->s3->send_alert[1] = desc;\n    if (!RECORD_LAYER_write_pending(&s->rlayer)) {\n        return s->method->ssl_dispatch_alert(s);\n    }\n    return -1;\n}', 'int SSL_CTX_remove_session(SSL_CTX *ctx, SSL_SESSION *c)\n{\n    return remove_session_lock(ctx, c, 1);\n}', 'static int remove_session_lock(SSL_CTX *ctx, SSL_SESSION *c, int lck)\n{\n    SSL_SESSION *r;\n    int ret = 0;\n    if ((c != NULL) && (c->session_id_length != 0)) {\n        if (lck)\n            CRYPTO_THREAD_write_lock(ctx->lock);\n        if ((r = lh_SSL_SESSION_retrieve(ctx->sessions, c)) == c) {\n            ret = 1;\n            r = lh_SSL_SESSION_delete(ctx->sessions, c);\n            SSL_SESSION_list_remove(ctx, c);\n        }\n        c->not_resumable = 1;\n        if (lck)\n            CRYPTO_THREAD_unlock(ctx->lock);\n        if (ret)\n            SSL_SESSION_free(r);\n        if (ctx->remove_session_cb != NULL)\n            ctx->remove_session_cb(ctx, c);\n    } else\n        ret = 0;\n    return (ret);\n}', 'DEFINE_LHASH_OF(SSL_SESSION)', 'void *OPENSSL_LH_delete(OPENSSL_LHASH *lh, const void *data)\n{\n    unsigned long hash;\n    OPENSSL_LH_NODE *nn, **rn;\n    void *ret;\n    lh->error = 0;\n    rn = getrn(lh, data, &hash);\n    if (*rn == NULL) {\n        lh->num_no_delete++;\n        return (NULL);\n    } else {\n        nn = *rn;\n        *rn = nn->next;\n        ret = nn->data;\n        OPENSSL_free(nn);\n        lh->num_delete++;\n    }\n    lh->num_items--;\n    if ((lh->num_nodes > MIN_NODES) &&\n        (lh->down_load >= (lh->num_items * LH_LOAD_MULT / lh->num_nodes)))\n        contract(lh);\n    return (ret);\n}']