int wc_DhParamsToDer(DhKey* key, byte* output, word32* outSz)
{
    word32 idx, total;

    if (key == NULL || outSz == NULL) {
        return BAD_FUNC_ARG;
    }

    /* determine size */
    /* integer - g */
    idx = SetASNIntMP(&key->g, -1, NULL);
    /* integer - p */
    idx += SetASNIntMP(&key->p, -1, NULL);
    total = idx;
     /* sequence */
    idx += SetSequence(idx, NULL);

    if (output == NULL) {
        *outSz = idx;
        return LENGTH_ONLY_E;
    }
    /* make sure output fits in buffer */
    if (idx > *outSz) {
        return BUFFER_E;
    }


    /* write DH parameters */
    /* sequence - for P and G only */
    idx = SetSequence(total, output);
    /* integer - p */
    idx += SetASNIntMP(&key->p, -1, output + idx);
    /* integer - g */
    idx += SetASNIntMP(&key->g, -1, output + idx);
    *outSz = idx;

    return idx;
}
int wc_DhParamsToDer(DhKey* key, byte* output, word32* outSz)
{
    word32 idx, total;

    if (key == NULL || outSz == NULL) {
        return BAD_FUNC_ARG;
    }

     
     
    idx = SetASNIntMP(&key->g, -1, NULL);
     
    idx += SetASNIntMP(&key->p, -1, NULL);
    total = idx;
      
    idx += SetSequence(idx, NULL);

    if (output == NULL) {
        *outSz = idx;
        return LENGTH_ONLY_E;
    }
     
    if (idx > *outSz) {
        return BUFFER_E;
    }


     
     
    idx = SetSequence(total, output);
     
    idx += SetASNIntMP(&key->p, -1, output + idx);
     
    idx += SetASNIntMP(&key->g, -1, output + idx);
    *outSz = idx;

    return idx;
}