src/wolfSSL/src/internal.c
static int QSH_GenerateSerCliSecret(WOLFSSL* ssl, byte isServer)
{
    int sz       = 0;
    int plainSz  = 48; /* lesser of 48 and max plain text able to encrypt */
    int offset   = 0;
    word32 tmpSz = 0;
    buffer* buf;
    QSHKey* current = ssl->peerQSHKey;
    QSHScheme* schmPre = NULL;
    QSHScheme* schm    = NULL;

    if (ssl == NULL)
        return -1;

    WOLFSSL_MSG("Generating QSH secret key material");

    /* get size of buffer needed */
    while (current) {
        if (current->pub.length != 0) {
            sz += plainSz;
        }
        current = (QSHKey*)current->next;
    }

    /* allocate memory for buffer */
    if (isServer) {
        buf = ssl->QSH_secret->SerSi;
    }
    else {
        buf = ssl->QSH_secret->CliSi;
    }
    buf->length = sz;
    buf->buffer = (byte*)XMALLOC(sz, buf->buffer, DYNAMIC_TYPE_TMP_BUFFER);
    if (buf->buffer == NULL) {
        WOLFSSL_ERROR(MEMORY_E);
    }

    /* create secret information */
    sz = 0;
    current = ssl->peerQSHKey;
    while (current) {
        schm = (QSHScheme*)XMALLOC(sizeof(QSHScheme), NULL,
                                                       DYNAMIC_TYPE_TMP_BUFFER);
        if (schm == NULL)
            return MEMORY_E;

        /* initialize variables */
        schm->name  = 0;
        schm->PK    = NULL;
        schm->PKLen = 0;
        schm->next  = NULL;
        if (ssl->QSH_secret->list == NULL) {
            ssl->QSH_secret->list = schm;
        }
        else {
            if (schmPre)
                schmPre->next = schm;
        }

        tmpSz = QSH_MaxSecret(current);

        if ((schm->PK = (byte*)XMALLOC(tmpSz, 0,
                                              DYNAMIC_TYPE_TMP_BUFFER)) == NULL)
            return -1;

        /* store info for writing extension */
        schm->name = current->name;

        /* no key to use for encryption */
        if (tmpSz == 0) {
            current = (QSHKey*)current->next;
            continue;
        }

        if (wc_RNG_GenerateBlock(ssl->rng, buf->buffer + offset, plainSz)
                                                                         != 0) {
            return -1;
        }
        if (QSH_Encrypt(current, buf->buffer + offset, plainSz, schm->PK,
                                                                 &tmpSz) != 0) {
            return -1;
        }
        schm->PKLen = tmpSz;

        sz += tmpSz;
        offset += plainSz;
        schmPre = schm;
        current = (QSHKey*)current->next;
    }

    return sz;
}
/* Generate the secret byte material for pms
   returns length on success and -1 on fail
 */
Generate the secret byte material for pms
returns length on success and -1 on fail
Generate the secret byte material for pms returns length on success and - 1 on fail
static int QSH_GenerateSerCliSecret(WOLFSSL* ssl, byte isServer)
{
    int sz       = 0;
    int plainSz  = 48; 
    int offset   = 0;
    word32 tmpSz = 0;
    buffer* buf;
    QSHKey* current = ssl->peerQSHKey;
    QSHScheme* schmPre = NULL;
    QSHScheme* schm    = NULL;
    if (ssl == NULL)
        return -1;
    WOLFSSL_MSG("Generating QSH secret key material");
    while (current) {
        if (current->pub.length != 0) {
            sz += plainSz;
        }
        current = (QSHKey*)current->next;
    }
    if (isServer) {
        buf = ssl->QSH_secret->SerSi;
    }
    else {
        buf = ssl->QSH_secret->CliSi;
    }
    buf->length = sz;
    buf->buffer = (byte*)XMALLOC(sz, buf->buffer, DYNAMIC_TYPE_TMP_BUFFER);
    if (buf->buffer == NULL) {
        WOLFSSL_ERROR(MEMORY_E);
    }
    sz = 0;
    current = ssl->peerQSHKey;
    while (current) {
        schm = (QSHScheme*)XMALLOC(sizeof(QSHScheme), NULL,
                                                       DYNAMIC_TYPE_TMP_BUFFER);
        if (schm == NULL)
            return MEMORY_E;
        schm->name  = 0;
        schm->PK    = NULL;
        schm->PKLen = 0;
        schm->next  = NULL;
        if (ssl->QSH_secret->list == NULL) {
            ssl->QSH_secret->list = schm;
        }
        else {
            if (schmPre)
                schmPre->next = schm;
        }
        tmpSz = QSH_MaxSecret(current);
        if ((schm->PK = (byte*)XMALLOC(tmpSz, 0,
                                              DYNAMIC_TYPE_TMP_BUFFER)) == NULL)
            return -1;
        schm->name = current->name;
        if (tmpSz == 0) {
            current = (QSHKey*)current->next;
            continue;
        }
        if (wc_RNG_GenerateBlock(ssl->rng, buf->buffer + offset, plainSz)
                                                                         != 0) {
            return -1;
        }
        if (QSH_Encrypt(current, buf->buffer + offset, plainSz, schm->PK,
                                                                 &tmpSz) != 0) {
            return -1;
        }
        schm->PKLen = tmpSz;
        sz += tmpSz;
        offset += plainSz;
        schmPre = schm;
        current = (QSHKey*)current->next;
    }
    return sz;
}
static int QSH_GenerateSerCliSecret ( WOLFSSL * ssl , byte isServer ) { int sz = 0 ; int plainSz = 48 ; int offset = 0 ; word32 tmpSz = 0 ; buffer * buf ; QSHKey * current = ssl -> peerQSHKey ; QSHScheme * schmPre = NULL ; QSHScheme * schm = NULL ; if ( ssl == NULL ) return -1 ; WOLFSSL_MSG ( " " ) ; while ( current ) { if ( current -> pub . length != 0 ) { sz += plainSz ; } current = ( QSHKey * ) current -> next ; } if ( isServer ) { buf = ssl -> QSH_secret -> SerSi ; } else { buf = ssl -> QSH_secret -> CliSi ; } buf -> length = sz ; buf -> buffer = ( byte * ) XMALLOC ( sz , buf -> buffer , DYNAMIC_TYPE_TMP_BUFFER ) ; if ( buf -> buffer == NULL ) { WOLFSSL_ERROR ( MEMORY_E ) ; } sz = 0 ; current = ssl -> peerQSHKey ; while ( current ) { schm = ( QSHScheme * ) XMALLOC ( sizeof ( QSHScheme ) , NULL , DYNAMIC_TYPE_TMP_BUFFER ) ; if ( schm == NULL ) return MEMORY_E ; schm -> name = 0 ; schm -> PK = NULL ; schm -> PKLen = 0 ; schm -> next = NULL ; if ( ssl -> QSH_secret -> list == NULL ) { ssl -> QSH_secret -> list = schm ; } else { if ( schmPre ) schmPre -> next = schm ; } tmpSz = QSH_MaxSecret ( current ) ; if ( ( schm -> PK = ( byte * ) XMALLOC ( tmpSz , 0 , DYNAMIC_TYPE_TMP_BUFFER ) ) == NULL ) return -1 ; schm -> name = current -> name ; if ( tmpSz == 0 ) { current = ( QSHKey * ) current -> next ; continue ; } if ( wc_RNG_GenerateBlock ( ssl -> rng , buf -> buffer + offset , plainSz ) != 0 ) { return -1 ; } if ( QSH_Encrypt ( current , buf -> buffer + offset , plainSz , schm -> PK , & tmpSz ) != 0 ) { return -1 ; } schm -> PKLen = tmpSz ; sz += tmpSz ; offset += plainSz ; schmPre = schm ; current = ( QSHKey * ) current -> next ; } return sz ; }
Generate the secret byte material for pms
returns length on success and -1 on fail
Generate the secret byte material for pms returns length on success and - 1 on fail
/* lesser of 48 and max plain text able to encrypt */ /* get size of buffer needed */ /* allocate memory for buffer */ /* create secret information */ /* initialize variables */ /* store info for writing extension */ /* no key to use for encryption */