int WPACKET_reserve_bytes(WPACKET *pkt, size_t len, unsigned char **allocbytes)
{
    if (!ossl_assert(pkt->subs != NULL && len != 0))
        return 0;
    if (pkt->maxsize - pkt->written < len)
        return 0;
    if (pkt->staticbuf == NULL && (pkt->buf->length - pkt->written < len)) {
        size_t newlen;
        size_t reflen;
        reflen = (len > pkt->buf->length) ? len : pkt->buf->length;
        if (reflen > SIZE_MAX / 2) {
            newlen = SIZE_MAX;
        } else {
            newlen = reflen * 2;
            if (newlen < DEFAULT_BUF_SIZE)
                newlen = DEFAULT_BUF_SIZE;
        }
        if (BUF_MEM_grow(pkt->buf, newlen) == 0)
            return 0;
    }
    if (allocbytes != NULL)
        *allocbytes = WPACKET_get_curr(pkt);
    return 1;
}
['EXT_RETURN tls_construct_ctos_early_data(SSL *s, WPACKET *pkt,\n                                         unsigned int context, X509 *x,\n                                         size_t chainidx, int *al)\n{\n    const unsigned char *id;\n    size_t idlen = 0;\n    SSL_SESSION *psksess = NULL;\n    SSL_SESSION *edsess = NULL;\n    const EVP_MD *handmd = NULL;\n    if (s->hello_retry_request)\n        handmd = ssl_handshake_md(s);\n    if (s->psk_use_session_cb != NULL\n            && (!s->psk_use_session_cb(s, handmd, &id, &idlen, &psksess)\n                || (psksess != NULL\n                    && psksess->ssl_version != TLS1_3_VERSION))) {\n        SSL_SESSION_free(psksess);\n        SSLerr(SSL_F_TLS_CONSTRUCT_CTOS_EARLY_DATA, SSL_R_BAD_PSK);\n        return EXT_RETURN_FAIL;\n    }\n    SSL_SESSION_free(s->psksession);\n    s->psksession = psksess;\n    if (psksess != NULL) {\n        OPENSSL_free(s->psksession_id);\n        s->psksession_id = OPENSSL_memdup(id, idlen);\n        if (s->psksession_id == NULL) {\n            SSLerr(SSL_F_TLS_CONSTRUCT_CTOS_EARLY_DATA, ERR_R_INTERNAL_ERROR);\n            return EXT_RETURN_FAIL;\n        }\n        s->psksession_id_len = idlen;\n    }\n    if (s->early_data_state != SSL_EARLY_DATA_CONNECTING\n            || (s->session->ext.max_early_data == 0\n                && (psksess == NULL || psksess->ext.max_early_data == 0))) {\n        s->max_early_data = 0;\n        return EXT_RETURN_NOT_SENT;\n    }\n    edsess = s->session->ext.max_early_data != 0 ? s->session : psksess;\n    s->max_early_data = edsess->ext.max_early_data;\n    if ((s->ext.hostname == NULL && edsess->ext.hostname != NULL)\n            || (s->ext.hostname != NULL\n                && (edsess->ext.hostname == NULL\n                    || strcmp(s->ext.hostname, edsess->ext.hostname) != 0))) {\n        SSLerr(SSL_F_TLS_CONSTRUCT_CTOS_EARLY_DATA,\n               SSL_R_INCONSISTENT_EARLY_DATA_SNI);\n        return EXT_RETURN_FAIL;\n    }\n    if ((s->ext.alpn == NULL && edsess->ext.alpn_selected != NULL)) {\n        SSLerr(SSL_F_TLS_CONSTRUCT_CTOS_EARLY_DATA,\n               SSL_R_INCONSISTENT_EARLY_DATA_ALPN);\n        return EXT_RETURN_FAIL;\n    }\n    if (edsess->ext.alpn_selected != NULL) {\n        PACKET prots, alpnpkt;\n        int found = 0;\n        if (!PACKET_buf_init(&prots, s->ext.alpn, s->ext.alpn_len)) {\n            SSLerr(SSL_F_TLS_CONSTRUCT_CTOS_EARLY_DATA, ERR_R_INTERNAL_ERROR);\n            return EXT_RETURN_FAIL;\n        }\n        while (PACKET_get_length_prefixed_1(&prots, &alpnpkt)) {\n            if (PACKET_equal(&alpnpkt, edsess->ext.alpn_selected,\n                             edsess->ext.alpn_selected_len)) {\n                found = 1;\n                break;\n            }\n        }\n        if (!found) {\n            SSLerr(SSL_F_TLS_CONSTRUCT_CTOS_EARLY_DATA,\n                   SSL_R_INCONSISTENT_EARLY_DATA_ALPN);\n            return EXT_RETURN_FAIL;\n        }\n    }\n    if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_early_data)\n            || !WPACKET_start_sub_packet_u16(pkt)\n            || !WPACKET_close(pkt)) {\n        SSLerr(SSL_F_TLS_CONSTRUCT_CTOS_EARLY_DATA, ERR_R_INTERNAL_ERROR);\n        return EXT_RETURN_FAIL;\n    }\n    s->ext.early_data = SSL_EARLY_DATA_REJECTED;\n    s->ext.early_data_ok = 1;\n    return EXT_RETURN_SENT;\n}', 'int WPACKET_put_bytes__(WPACKET *pkt, unsigned int val, size_t size)\n{\n    unsigned char *data;\n    if (!ossl_assert(size <= sizeof(unsigned int))\n            || !WPACKET_allocate_bytes(pkt, size, &data)\n            || !put_value(data, val, size))\n        return 0;\n    return 1;\n}', 'int WPACKET_start_sub_packet_len__(WPACKET *pkt, size_t lenbytes)\n{\n    WPACKET_SUB *sub;\n    unsigned char *lenchars;\n    if (!ossl_assert(pkt->subs != NULL))\n        return 0;\n    sub = OPENSSL_zalloc(sizeof(*sub));\n    if (sub == NULL)\n        return 0;\n    sub->parent = pkt->subs;\n    pkt->subs = sub;\n    sub->pwritten = pkt->written + lenbytes;\n    sub->lenbytes = lenbytes;\n    if (lenbytes == 0) {\n        sub->packet_len = 0;\n        return 1;\n    }\n    if (!WPACKET_allocate_bytes(pkt, lenbytes, &lenchars))\n        return 0;\n    sub->packet_len = lenchars - GETBUF(pkt);\n    return 1;\n}', 'int WPACKET_allocate_bytes(WPACKET *pkt, size_t len, unsigned char **allocbytes)\n{\n    if (!WPACKET_reserve_bytes(pkt, len, allocbytes))\n        return 0;\n    pkt->written += len;\n    pkt->curr += len;\n    return 1;\n}', 'int WPACKET_reserve_bytes(WPACKET *pkt, size_t len, unsigned char **allocbytes)\n{\n    if (!ossl_assert(pkt->subs != NULL && len != 0))\n        return 0;\n    if (pkt->maxsize - pkt->written < len)\n        return 0;\n    if (pkt->staticbuf == NULL && (pkt->buf->length - pkt->written < len)) {\n        size_t newlen;\n        size_t reflen;\n        reflen = (len > pkt->buf->length) ? len : pkt->buf->length;\n        if (reflen > SIZE_MAX / 2) {\n            newlen = SIZE_MAX;\n        } else {\n            newlen = reflen * 2;\n            if (newlen < DEFAULT_BUF_SIZE)\n                newlen = DEFAULT_BUF_SIZE;\n        }\n        if (BUF_MEM_grow(pkt->buf, newlen) == 0)\n            return 0;\n    }\n    if (allocbytes != NULL)\n        *allocbytes = WPACKET_get_curr(pkt);\n    return 1;\n}']