src/wolfSSL/src/internal.c
static int CreateTicket(WOLFSSL* ssl)
    {
        InternalTicket  it;
        ExternalTicket* et = (ExternalTicket*)ssl->session.ticket;
        int encLen;
        int ret;
        byte zeros[WOLFSSL_TICKET_MAC_SZ];   /* biggest cmp size */

        /* build internal */
        it.pv.major = ssl->version.major;
        it.pv.minor = ssl->version.minor;

        it.suite[0] = ssl->options.cipherSuite0;
        it.suite[1] = ssl->options.cipherSuite;

        XMEMCPY(it.msecret, ssl->arrays->masterSecret, SECRET_LEN);
        c32toa(LowResTimer(), (byte*)&it.timestamp);

        /* build external */
        XMEMCPY(et->enc_ticket, &it, sizeof(InternalTicket));

        /* encrypt */
        encLen = WOLFSSL_TICKET_ENC_SZ;  /* max size user can use */
        ret = ssl->ctx->ticketEncCb(ssl, et->key_name, et->iv, et->mac, 1,
                                    et->enc_ticket, sizeof(InternalTicket),
                                    &encLen, ssl->ctx->ticketEncCtx);
        if (ret == WOLFSSL_TICKET_RET_OK) {
            if (encLen < (int)sizeof(InternalTicket) ||
                encLen > WOLFSSL_TICKET_ENC_SZ) {
                WOLFSSL_MSG("Bad user ticket encrypt size");
                return BAD_TICKET_KEY_CB_SZ;
            }

            /* sanity checks on encrypt callback */

            /* internal ticket can't be the same if encrypted */
            if (XMEMCMP(et->enc_ticket, &it, sizeof(InternalTicket)) == 0) {
                WOLFSSL_MSG("User ticket encrypt didn't encrypt");
                return BAD_TICKET_ENCRYPT;
            }

            XMEMSET(zeros, 0, sizeof(zeros));

            /* name */
            if (XMEMCMP(et->key_name, zeros, WOLFSSL_TICKET_NAME_SZ) == 0) {
                WOLFSSL_MSG("User ticket encrypt didn't set name");
                return BAD_TICKET_ENCRYPT;
            }

            /* iv */
            if (XMEMCMP(et->iv, zeros, WOLFSSL_TICKET_IV_SZ) == 0) {
                WOLFSSL_MSG("User ticket encrypt didn't set iv");
                return BAD_TICKET_ENCRYPT;
            }

            /* mac */
            if (XMEMCMP(et->mac, zeros, WOLFSSL_TICKET_MAC_SZ) == 0) {
                WOLFSSL_MSG("User ticket encrypt didn't set mac");
                return BAD_TICKET_ENCRYPT;
            }

            /* set size */
            c16toa((word16)encLen, et->enc_len);
            ssl->session.ticketLen = (word16)(encLen + WOLFSSL_TICKET_FIXED_SZ);
            if (encLen < WOLFSSL_TICKET_ENC_SZ) {
                /* move mac up since whole enc buffer not used */
                XMEMMOVE(et->enc_ticket +encLen, et->mac,WOLFSSL_TICKET_MAC_SZ);
            }
        }

        return ret;
    }
/* create a new session ticket, 0 on success */
create a new session ticket, 0 on success
create a new session ticket 0 on success
static int CreateTicket(WOLFSSL* ssl)
    {
        InternalTicket  it;
        ExternalTicket* et = (ExternalTicket*)ssl->session.ticket;
        int encLen;
        int ret;
        byte zeros[WOLFSSL_TICKET_MAC_SZ];   
        it.pv.major = ssl->version.major;
        it.pv.minor = ssl->version.minor;
        it.suite[0] = ssl->options.cipherSuite0;
        it.suite[1] = ssl->options.cipherSuite;
        XMEMCPY(it.msecret, ssl->arrays->masterSecret, SECRET_LEN);
        c32toa(LowResTimer(), (byte*)&it.timestamp);
        XMEMCPY(et->enc_ticket, &it, sizeof(InternalTicket));
        encLen = WOLFSSL_TICKET_ENC_SZ;  
        ret = ssl->ctx->ticketEncCb(ssl, et->key_name, et->iv, et->mac, 1,
                                    et->enc_ticket, sizeof(InternalTicket),
                                    &encLen, ssl->ctx->ticketEncCtx);
        if (ret == WOLFSSL_TICKET_RET_OK) {
            if (encLen < (int)sizeof(InternalTicket) ||
                encLen > WOLFSSL_TICKET_ENC_SZ) {
                WOLFSSL_MSG("Bad user ticket encrypt size");
                return BAD_TICKET_KEY_CB_SZ;
            }
            if (XMEMCMP(et->enc_ticket, &it, sizeof(InternalTicket)) == 0) {
                WOLFSSL_MSG("User ticket encrypt didn't encrypt");
                return BAD_TICKET_ENCRYPT;
            }
            XMEMSET(zeros, 0, sizeof(zeros));
            if (XMEMCMP(et->key_name, zeros, WOLFSSL_TICKET_NAME_SZ) == 0) {
                WOLFSSL_MSG("User ticket encrypt didn't set name");
                return BAD_TICKET_ENCRYPT;
            }
            if (XMEMCMP(et->iv, zeros, WOLFSSL_TICKET_IV_SZ) == 0) {
                WOLFSSL_MSG("User ticket encrypt didn't set iv");
                return BAD_TICKET_ENCRYPT;
            }
            if (XMEMCMP(et->mac, zeros, WOLFSSL_TICKET_MAC_SZ) == 0) {
                WOLFSSL_MSG("User ticket encrypt didn't set mac");
                return BAD_TICKET_ENCRYPT;
            }
            c16toa((word16)encLen, et->enc_len);
            ssl->session.ticketLen = (word16)(encLen + WOLFSSL_TICKET_FIXED_SZ);
            if (encLen < WOLFSSL_TICKET_ENC_SZ) {
                XMEMMOVE(et->enc_ticket +encLen, et->mac,WOLFSSL_TICKET_MAC_SZ);
            }
        }
        return ret;
    }
static int CreateTicket ( WOLFSSL * ssl ) { InternalTicket it ; ExternalTicket * et = ( ExternalTicket * ) ssl -> session . ticket ; int encLen ; int ret ; byte zeros [ WOLFSSL_TICKET_MAC_SZ ] ; it . pv . major = ssl -> version . major ; it . pv . minor = ssl -> version . minor ; it . suite [ 0 ] = ssl -> options . cipherSuite0 ; it . suite [ 1 ] = ssl -> options . cipherSuite ; XMEMCPY ( it . msecret , ssl -> arrays -> masterSecret , SECRET_LEN ) ; c32toa ( LowResTimer ( ) , ( byte * ) & it . timestamp ) ; XMEMCPY ( et -> enc_ticket , & it , sizeof ( InternalTicket ) ) ; encLen = WOLFSSL_TICKET_ENC_SZ ; ret = ssl -> ctx -> ticketEncCb ( ssl , et -> key_name , et -> iv , et -> mac , 1 , et -> enc_ticket , sizeof ( InternalTicket ) , & encLen , ssl -> ctx -> ticketEncCtx ) ; if ( ret == WOLFSSL_TICKET_RET_OK ) { if ( encLen < ( int ) sizeof ( InternalTicket ) || encLen > WOLFSSL_TICKET_ENC_SZ ) { WOLFSSL_MSG ( " " ) ; return BAD_TICKET_KEY_CB_SZ ; } if ( XMEMCMP ( et -> enc_ticket , & it , sizeof ( InternalTicket ) ) == 0 ) { WOLFSSL_MSG ( " " ) ; return BAD_TICKET_ENCRYPT ; } XMEMSET ( zeros , 0 , sizeof ( zeros ) ) ; if ( XMEMCMP ( et -> key_name , zeros , WOLFSSL_TICKET_NAME_SZ ) == 0 ) { WOLFSSL_MSG ( " " ) ; return BAD_TICKET_ENCRYPT ; } if ( XMEMCMP ( et -> iv , zeros , WOLFSSL_TICKET_IV_SZ ) == 0 ) { WOLFSSL_MSG ( " " ) ; return BAD_TICKET_ENCRYPT ; } if ( XMEMCMP ( et -> mac , zeros , WOLFSSL_TICKET_MAC_SZ ) == 0 ) { WOLFSSL_MSG ( " " ) ; return BAD_TICKET_ENCRYPT ; } c16toa ( ( word16 ) encLen , et -> enc_len ) ; ssl -> session . ticketLen = ( word16 ) ( encLen + WOLFSSL_TICKET_FIXED_SZ ) ; if ( encLen < WOLFSSL_TICKET_ENC_SZ ) { XMEMMOVE ( et -> enc_ticket + encLen , et -> mac , WOLFSSL_TICKET_MAC_SZ ) ; } } return ret ; }
create a new session ticket, 0 on success
create a new session ticket 0 on success
/* biggest cmp size */ /* build internal */ /* build external */ /* encrypt */ /* max size user can use */ /* sanity checks on encrypt callback */ /* internal ticket can't be the same if encrypted */ /* name */ /* iv */ /* mac */ /* set size */ /* move mac up since whole enc buffer not used */