int CG21_SIGN_ROUND2()

in src/cg21/cg21_sign.c [127:173]


int CG21_SIGN_ROUND2(const CG21_SIGN_ROUND1_STORE *mystore,
                     const CG21_SIGN_ROUND1_OUTPUT *hisout,
                     CG21_SIGN_ROUND2_OUTPUT *out,
                     int status){
    /*
     * status = 0      first call
     * status = 1      neither first call, nor last call
     * status = 2      last call
     * status = 3      first and last call (t=2)
     */


    /* ---------STEP 1: generate sigma ----------
    * sigma:          \sum sigma_j
    */

    BIG_256_56 q;
    BIG_256_56 s;
    BIG_256_56 accum;

    // Curve order
    BIG_256_56_rcopy(q, CURVE_Order_SECP256K1);

    if (status==0 || status ==3){
        OCT_copy(out->sigma, mystore->sigma);

    }

    BIG_256_56_fromBytesLen(accum, out->sigma->val, out->sigma->len);
    BIG_256_56_fromBytesLen(s, hisout->sigma->val, hisout->sigma->len);

    BIG_256_56_add(accum, accum, s);
    BIG_256_56_mod(accum, q);

    out->sigma->len = EGS_SECP256K1;
    BIG_256_56_toBytes(out->sigma->val, accum);

    if (status==2 || status ==3){
        OCT_copy(out->r, mystore->r);
    }

    // clean memory
    BIG_256_56_zero(accum);
    BIG_256_56_zero(s);

    return CG21_OK;
}