FreeRTOS-Plus/ThirdParty/WolfSSL-FIPS-Ready/wolfcrypt/src/dh.c
/* Export raw DH parameters from DhKey structure
 *
 * dh   - pointer to initialized DhKey structure
 * p    - output location for DH (p) parameter
 * pSz  - [IN/OUT] size of output buffer for p, size of p
 * q    - output location for DH (q) parameter
 * qSz  - [IN/OUT] size of output buffer for q, size of q
 * g    - output location for DH (g) parameter
 * gSz  - [IN/OUT] size of output buffer for g, size of g
 *
 * If p, q, and g pointers are all passed in as NULL, the function
 * will set pSz, qSz, and gSz to the required output buffer sizes for p,
 * q, and g. In this case, the function will return LENGTH_ONLY_E.
 *
 * returns 0 on success, negative upon failure
 */


If p, q, and g pointers are all passed in as NULL, the function
will set pSz, qSz, and gSz to the required output buffer sizes for p,
q, and g. In this case, the function will return LENGTH_ONLY_E.

returns 0 on success, negative upon failure
If p q and g pointers are all passed in as NULL the function will set pSz qSz and gSz to the required output buffer sizes for p q and g . In this case the function will return LENGTH_ONLY_E . returns 0 on success negative upon failure
int wc_DhExportParamsRaw(DhKey* dh, byte* p, word32* pSz,
                         byte* q, word32* qSz, byte* g, word32* gSz)
{
    int ret = 0;
    word32 pLen = 0, qLen = 0, gLen = 0;
    if (dh == NULL || pSz == NULL || qSz == NULL || gSz == NULL)
        ret = BAD_FUNC_ARG;
    if (ret == 0) {
        pLen = mp_unsigned_bin_size(&dh->p);
        qLen = mp_unsigned_bin_size(&dh->q);
        gLen = mp_unsigned_bin_size(&dh->g);
        if (p == NULL && q == NULL && g == NULL) {
            *pSz = pLen;
            *qSz = qLen;
            *gSz = gLen;
            ret = LENGTH_ONLY_E;
        }
    }
    if (ret == 0) {
        if (p == NULL || q == NULL || g == NULL)
            ret = BAD_FUNC_ARG;
    }
    if (ret == 0) {
        if (*pSz < pLen) {
            WOLFSSL_MSG("Output buffer for DH p parameter too small, "
                        "required size placed into pSz");
            *pSz = pLen;
            ret = BUFFER_E;
        }
    }
    if (ret == 0) {
        *pSz = pLen;
        if (mp_to_unsigned_bin(&dh->p, p) != MP_OKAY)
            ret = MP_TO_E;
    }
    if (ret == 0) {
        if (*qSz < qLen) {
            WOLFSSL_MSG("Output buffer for DH q parameter too small, "
                        "required size placed into qSz");
            *qSz = qLen;
            ret = BUFFER_E;
        }
    }
    if (ret == 0) {
        *qSz = qLen;
        if (mp_to_unsigned_bin(&dh->q, q) != MP_OKAY)
            ret = MP_TO_E;
    }
    if (ret == 0) {
        if (*gSz < gLen) {
            WOLFSSL_MSG("Output buffer for DH g parameter too small, "
                        "required size placed into gSz");
            *gSz = gLen;
            ret = BUFFER_E;
        }
    }
    if (ret == 0) {
        *gSz = gLen;
        if (mp_to_unsigned_bin(&dh->g, g) != MP_OKAY)
            ret = MP_TO_E;
    }
    return ret;
}
int wc_DhExportParamsRaw ( DhKey * dh , byte * p , word32 * pSz , byte * q , word32 * qSz , byte * g , word32 * gSz ) { int ret = 0 ; word32 pLen = 0 , qLen = 0 , gLen = 0 ; if ( dh == NULL || pSz == NULL || qSz == NULL || gSz == NULL ) ret = BAD_FUNC_ARG ; if ( ret == 0 ) { pLen = mp_unsigned_bin_size ( & dh -> p ) ; qLen = mp_unsigned_bin_size ( & dh -> q ) ; gLen = mp_unsigned_bin_size ( & dh -> g ) ; if ( p == NULL && q == NULL && g == NULL ) { * pSz = pLen ; * qSz = qLen ; * gSz = gLen ; ret = LENGTH_ONLY_E ; } } if ( ret == 0 ) { if ( p == NULL || q == NULL || g == NULL ) ret = BAD_FUNC_ARG ; } if ( ret == 0 ) { if ( * pSz < pLen ) { WOLFSSL_MSG ( " " " " ) ; * pSz = pLen ; ret = BUFFER_E ; } } if ( ret == 0 ) { * pSz = pLen ; if ( mp_to_unsigned_bin ( & dh -> p , p ) != MP_OKAY ) ret = MP_TO_E ; } if ( ret == 0 ) { if ( * qSz < qLen ) { WOLFSSL_MSG ( " " " " ) ; * qSz = qLen ; ret = BUFFER_E ; } } if ( ret == 0 ) { * qSz = qLen ; if ( mp_to_unsigned_bin ( & dh -> q , q ) != MP_OKAY ) ret = MP_TO_E ; } if ( ret == 0 ) { if ( * gSz < gLen ) { WOLFSSL_MSG ( " " " " ) ; * gSz = gLen ; ret = BUFFER_E ; } } if ( ret == 0 ) { * gSz = gLen ; if ( mp_to_unsigned_bin ( & dh -> g , g ) != MP_OKAY ) ret = MP_TO_E ; } return ret ; }
Export raw DH parameters from DhKey structure
 dh   - pointer to initialized DhKey structure
 p    - output location for DH (p) parameter
 pSz  - [IN/OUT] size of output buffer for p, size of p
 q    - output location for DH (q) parameter
 qSz  - [IN/OUT] size of output buffer for q, size of q
 g    - output location for DH (g) parameter
 gSz  - [IN/OUT] size of output buffer for g, size of g
Export raw DH parameters from DhKey structure dh - pointer to initialized DhKey structure p - output location for DH ( p ) parameter pSz - [ IN / OUT ] size of output buffer for p size of p q - output location for DH ( q ) parameter qSz - [ IN / OUT ] size of output buffer for q size of q g - output location for DH ( g ) parameter gSz - [ IN / OUT ] size of output buffer for g size of g
/* get required output buffer sizes */ /* return buffer sizes and LENGTH_ONLY_E if buffers are NULL */ /* export p */ /* export q */ /* export g */