static int test_export_key_mat(int tst)
{
    int testresult = 0;
    SSL_CTX *cctx = NULL, *sctx = NULL, *sctx2 = NULL;
    SSL *clientssl = NULL, *serverssl = NULL;
    const char label[LONG_LABEL_LEN + 1] = "test label";
    const unsigned char context[] = "context";
    const unsigned char *emptycontext = NULL;
    unsigned char ckeymat1[80], ckeymat2[80], ckeymat3[80];
    unsigned char skeymat1[80], skeymat2[80], skeymat3[80];
    size_t labellen;
    const int protocols[] = {
        TLS1_VERSION,
        TLS1_1_VERSION,
        TLS1_2_VERSION,
        TLS1_3_VERSION,
        TLS1_3_VERSION,
        TLS1_3_VERSION
    };
#ifdef OPENSSL_NO_TLS1
    if (tst == 0)
        return 1;
#endif
#ifdef OPENSSL_NO_TLS1_1
    if (tst == 1)
        return 1;
#endif
#ifdef OPENSSL_NO_TLS1_2
    if (tst == 2)
        return 1;
#endif
#ifdef OPENSSL_NO_TLS1_3
    if (tst >= 3)
        return 1;
#endif
    if (!TEST_true(create_ssl_ctx_pair(TLS_server_method(), TLS_client_method(),
                                       TLS1_VERSION, 0,
                                       &sctx, &cctx, cert, privkey)))
        goto end;
    OPENSSL_assert(tst >= 0 && (size_t)tst < OSSL_NELEM(protocols));
    SSL_CTX_set_max_proto_version(cctx, protocols[tst]);
    SSL_CTX_set_min_proto_version(cctx, protocols[tst]);
    if (!TEST_true(create_ssl_objects(sctx, cctx, &serverssl, &clientssl, NULL,
                                      NULL))
            || !TEST_true(create_ssl_connection(serverssl, clientssl,
                                                SSL_ERROR_NONE)))
        goto end;
    if (tst == 5) {
        if (!TEST_int_le(SSL_export_keying_material(clientssl, ckeymat1,
                                                    sizeof(ckeymat1), label,
                                                    LONG_LABEL_LEN + 1, context,
                                                    sizeof(context) - 1, 1), 0))
            goto end;
        testresult = 1;
        goto end;
    } else if (tst == 4) {
        labellen = LONG_LABEL_LEN;
    } else {
        labellen = SMALL_LABEL_LEN;
    }
    if (!TEST_int_eq(SSL_export_keying_material(clientssl, ckeymat1,
                                                sizeof(ckeymat1), label,
                                                labellen, context,
                                                sizeof(context) - 1, 1), 1)
            || !TEST_int_eq(SSL_export_keying_material(clientssl, ckeymat2,
                                                       sizeof(ckeymat2), label,
                                                       labellen,
                                                       emptycontext,
                                                       0, 1), 1)
            || !TEST_int_eq(SSL_export_keying_material(clientssl, ckeymat3,
                                                       sizeof(ckeymat3), label,
                                                       labellen,
                                                       NULL, 0, 0), 1)
            || !TEST_int_eq(SSL_export_keying_material(serverssl, skeymat1,
                                                       sizeof(skeymat1), label,
                                                       labellen,
                                                       context,
                                                       sizeof(context) -1, 1),
                            1)
            || !TEST_int_eq(SSL_export_keying_material(serverssl, skeymat2,
                                                       sizeof(skeymat2), label,
                                                       labellen,
                                                       emptycontext,
                                                       0, 1), 1)
            || !TEST_int_eq(SSL_export_keying_material(serverssl, skeymat3,
                                                       sizeof(skeymat3), label,
                                                       labellen,
                                                       NULL, 0, 0), 1)
            || !TEST_mem_eq(ckeymat1, sizeof(ckeymat1), skeymat1,
                            sizeof(skeymat1))
            || !TEST_mem_eq(ckeymat2, sizeof(ckeymat2), skeymat2,
                            sizeof(skeymat2))
            || !TEST_mem_eq(ckeymat3, sizeof(ckeymat3), skeymat3,
                            sizeof(skeymat3))
            || !TEST_mem_ne(ckeymat1, sizeof(ckeymat1), ckeymat2,
                            sizeof(ckeymat2)))
        goto end;
    if ((tst < 3 && !TEST_mem_ne(ckeymat2, sizeof(ckeymat2), ckeymat3,
                                  sizeof(ckeymat3)))
            || (tst >= 3 && !TEST_mem_eq(ckeymat2, sizeof(ckeymat2), ckeymat3,
                                         sizeof(ckeymat3))))
        goto end;
    testresult = 1;
 end:
    SSL_free(serverssl);
    SSL_free(clientssl);
    SSL_CTX_free(sctx2);
    SSL_CTX_free(sctx);
    SSL_CTX_free(cctx);
    return testresult;
}
['static int test_export_key_mat(int tst)\n{\n    int testresult = 0;\n    SSL_CTX *cctx = NULL, *sctx = NULL, *sctx2 = NULL;\n    SSL *clientssl = NULL, *serverssl = NULL;\n    const char label[LONG_LABEL_LEN + 1] = "test label";\n    const unsigned char context[] = "context";\n    const unsigned char *emptycontext = NULL;\n    unsigned char ckeymat1[80], ckeymat2[80], ckeymat3[80];\n    unsigned char skeymat1[80], skeymat2[80], skeymat3[80];\n    size_t labellen;\n    const int protocols[] = {\n        TLS1_VERSION,\n        TLS1_1_VERSION,\n        TLS1_2_VERSION,\n        TLS1_3_VERSION,\n        TLS1_3_VERSION,\n        TLS1_3_VERSION\n    };\n#ifdef OPENSSL_NO_TLS1\n    if (tst == 0)\n        return 1;\n#endif\n#ifdef OPENSSL_NO_TLS1_1\n    if (tst == 1)\n        return 1;\n#endif\n#ifdef OPENSSL_NO_TLS1_2\n    if (tst == 2)\n        return 1;\n#endif\n#ifdef OPENSSL_NO_TLS1_3\n    if (tst >= 3)\n        return 1;\n#endif\n    if (!TEST_true(create_ssl_ctx_pair(TLS_server_method(), TLS_client_method(),\n                                       TLS1_VERSION, 0,\n                                       &sctx, &cctx, cert, privkey)))\n        goto end;\n    OPENSSL_assert(tst >= 0 && (size_t)tst < OSSL_NELEM(protocols));\n    SSL_CTX_set_max_proto_version(cctx, protocols[tst]);\n    SSL_CTX_set_min_proto_version(cctx, protocols[tst]);\n    if (!TEST_true(create_ssl_objects(sctx, cctx, &serverssl, &clientssl, NULL,\n                                      NULL))\n            || !TEST_true(create_ssl_connection(serverssl, clientssl,\n                                                SSL_ERROR_NONE)))\n        goto end;\n    if (tst == 5) {\n        if (!TEST_int_le(SSL_export_keying_material(clientssl, ckeymat1,\n                                                    sizeof(ckeymat1), label,\n                                                    LONG_LABEL_LEN + 1, context,\n                                                    sizeof(context) - 1, 1), 0))\n            goto end;\n        testresult = 1;\n        goto end;\n    } else if (tst == 4) {\n        labellen = LONG_LABEL_LEN;\n    } else {\n        labellen = SMALL_LABEL_LEN;\n    }\n    if (!TEST_int_eq(SSL_export_keying_material(clientssl, ckeymat1,\n                                                sizeof(ckeymat1), label,\n                                                labellen, context,\n                                                sizeof(context) - 1, 1), 1)\n            || !TEST_int_eq(SSL_export_keying_material(clientssl, ckeymat2,\n                                                       sizeof(ckeymat2), label,\n                                                       labellen,\n                                                       emptycontext,\n                                                       0, 1), 1)\n            || !TEST_int_eq(SSL_export_keying_material(clientssl, ckeymat3,\n                                                       sizeof(ckeymat3), label,\n                                                       labellen,\n                                                       NULL, 0, 0), 1)\n            || !TEST_int_eq(SSL_export_keying_material(serverssl, skeymat1,\n                                                       sizeof(skeymat1), label,\n                                                       labellen,\n                                                       context,\n                                                       sizeof(context) -1, 1),\n                            1)\n            || !TEST_int_eq(SSL_export_keying_material(serverssl, skeymat2,\n                                                       sizeof(skeymat2), label,\n                                                       labellen,\n                                                       emptycontext,\n                                                       0, 1), 1)\n            || !TEST_int_eq(SSL_export_keying_material(serverssl, skeymat3,\n                                                       sizeof(skeymat3), label,\n                                                       labellen,\n                                                       NULL, 0, 0), 1)\n            || !TEST_mem_eq(ckeymat1, sizeof(ckeymat1), skeymat1,\n                            sizeof(skeymat1))\n            || !TEST_mem_eq(ckeymat2, sizeof(ckeymat2), skeymat2,\n                            sizeof(skeymat2))\n            || !TEST_mem_eq(ckeymat3, sizeof(ckeymat3), skeymat3,\n                            sizeof(skeymat3))\n            || !TEST_mem_ne(ckeymat1, sizeof(ckeymat1), ckeymat2,\n                            sizeof(ckeymat2)))\n        goto end;\n    if ((tst < 3 && !TEST_mem_ne(ckeymat2, sizeof(ckeymat2), ckeymat3,\n                                  sizeof(ckeymat3)))\n            || (tst >= 3 && !TEST_mem_eq(ckeymat2, sizeof(ckeymat2), ckeymat3,\n                                         sizeof(ckeymat3))))\n        goto end;\n    testresult = 1;\n end:\n    SSL_free(serverssl);\n    SSL_free(clientssl);\n    SSL_CTX_free(sctx2);\n    SSL_CTX_free(sctx);\n    SSL_CTX_free(cctx);\n    return testresult;\n}', 'IMPLEMENT_tls_meth_func(TLS_ANY_VERSION, 0, 0,\n                        TLS_server_method,\n                        ossl_statem_accept,\n                        ssl_undefined_function, TLSv1_2_enc_data)', 'IMPLEMENT_tls_meth_func(TLS_ANY_VERSION, 0, 0,\n                        TLS_client_method,\n                        ssl_undefined_function,\n                        ossl_statem_connect, TLSv1_2_enc_data)', 'int test_true(const char *file, int line, const char *s, int b)\n{\n    if (b)\n        return 1;\n    test_fail_message(NULL, file, line, "bool", s, "true", "==", "false");\n    return 0;\n}', 'int create_ssl_connection(SSL *serverssl, SSL *clientssl, int want)\n{\n    int i;\n    unsigned char buf;\n    size_t readbytes;\n    if (!create_bare_ssl_connection(serverssl, clientssl, want, 1))\n        return 0;\n    for (i = 0; i < 2; i++) {\n        if (SSL_read_ex(clientssl, &buf, sizeof(buf), &readbytes) > 0) {\n            if (!TEST_ulong_eq(readbytes, 0))\n                return 0;\n        } else if (!TEST_int_eq(SSL_get_error(clientssl, 0),\n                                SSL_ERROR_WANT_READ)) {\n            return 0;\n        }\n    }\n    return 1;\n}', 'void SSL_CTX_free(SSL_CTX *a)\n{\n    int i;\n    if (a == NULL)\n        return;\n    CRYPTO_DOWN_REF(&a->references, &i, a->lock);\n    REF_PRINT_COUNT("SSL_CTX", a);\n    if (i > 0)\n        return;\n    REF_ASSERT_ISNT(i < 0);\n    X509_VERIFY_PARAM_free(a->param);\n    dane_ctx_final(&a->dane);\n    if (a->sessions != NULL)\n        SSL_CTX_flush_sessions(a, 0);\n    CRYPTO_free_ex_data(CRYPTO_EX_INDEX_SSL_CTX, a, &a->ex_data);\n    lh_SSL_SESSION_free(a->sessions);\n    X509_STORE_free(a->cert_store);\n#ifndef OPENSSL_NO_CT\n    CTLOG_STORE_free(a->ctlog_store);\n#endif\n    sk_SSL_CIPHER_free(a->cipher_list);\n    sk_SSL_CIPHER_free(a->cipher_list_by_id);\n    sk_SSL_CIPHER_free(a->tls13_ciphersuites);\n    ssl_cert_free(a->cert);\n    sk_X509_NAME_pop_free(a->ca_names, X509_NAME_free);\n    sk_X509_NAME_pop_free(a->client_ca_names, X509_NAME_free);\n    sk_X509_pop_free(a->extra_certs, X509_free);\n    a->comp_methods = NULL;\n#ifndef OPENSSL_NO_SRTP\n    sk_SRTP_PROTECTION_PROFILE_free(a->srtp_profiles);\n#endif\n#ifndef OPENSSL_NO_SRP\n    SSL_CTX_SRP_CTX_free(a);\n#endif\n#ifndef OPENSSL_NO_ENGINE\n    ENGINE_finish(a->client_cert_engine);\n#endif\n#ifndef OPENSSL_NO_EC\n    OPENSSL_free(a->ext.ecpointformats);\n    OPENSSL_free(a->ext.supportedgroups);\n#endif\n    OPENSSL_free(a->ext.alpn);\n    OPENSSL_secure_free(a->ext.secure);\n    CRYPTO_THREAD_lock_free(a->lock);\n    OPENSSL_free(a);\n}', 'static inline int CRYPTO_DOWN_REF(_Atomic int *val, int *ret, void *lock)\n{\n    *ret = atomic_fetch_sub_explicit(val, 1, memory_order_relaxed) - 1;\n    if (*ret == 0)\n        atomic_thread_fence(memory_order_acquire);\n    return 1;\n}']