int wc_ecc_sig_to_rs(const byte* sig, word32 sigLen, byte* r, word32* rLen,
                     byte* s, word32* sLen)
{
    int err;
    word32 x = 0;
    mp_int rtmp;
    mp_int stmp;

    if (sig == NULL || r == NULL || rLen == NULL || s == NULL || sLen == NULL)
        return ECC_BAD_ARG_E;

    err = DecodeECC_DSA_Sig(sig, sigLen, &rtmp, &stmp);

    /* extract r */
    if (err == MP_OKAY) {
        x = mp_unsigned_bin_size(&rtmp);
        if (*rLen < x)
            err = BUFFER_E;

        if (err == MP_OKAY) {
            *rLen = x;
            err = mp_to_unsigned_bin(&rtmp, r);
        }
    }

    /* extract s */
    if (err == MP_OKAY) {
        x = mp_unsigned_bin_size(&stmp);
        if (*sLen < x)
            err = BUFFER_E;

        if (err == MP_OKAY) {
            *sLen = x;
            err = mp_to_unsigned_bin(&stmp, s);
        }
    }

    mp_clear(&rtmp);
    mp_clear(&stmp);

    return err;
}
int wc_ecc_sig_to_rs(const byte* sig, word32 sigLen, byte* r, word32* rLen,
                     byte* s, word32* sLen)
{
    int err;
    word32 x = 0;
    mp_int rtmp;
    mp_int stmp;

    if (sig == NULL || r == NULL || rLen == NULL || s == NULL || sLen == NULL)
        return ECC_BAD_ARG_E;

    err = DecodeECC_DSA_Sig(sig, sigLen, &rtmp, &stmp);

     
    if (err == MP_OKAY) {
        x = mp_unsigned_bin_size(&rtmp);
        if (*rLen < x)
            err = BUFFER_E;

        if (err == MP_OKAY) {
            *rLen = x;
            err = mp_to_unsigned_bin(&rtmp, r);
        }
    }

     
    if (err == MP_OKAY) {
        x = mp_unsigned_bin_size(&stmp);
        if (*sLen < x)
            err = BUFFER_E;

        if (err == MP_OKAY) {
            *sLen = x;
            err = mp_to_unsigned_bin(&stmp, s);
        }
    }

    mp_clear(&rtmp);
    mp_clear(&stmp);

    return err;
}