Changeset View
Changeset View
Standalone View
Standalone View
src/secp256k1/src/modinv64_impl.h
Show First 20 Lines • Show All 332 Lines • ▼ Show 20 Lines | #endif | ||||
cd += (int128_t)modinfo->modulus.v[0] * md; | cd += (int128_t)modinfo->modulus.v[0] * md; | ||||
ce += (int128_t)modinfo->modulus.v[0] * me; | ce += (int128_t)modinfo->modulus.v[0] * me; | ||||
/* Verify that the low 62 bits of the computation are indeed zero, and then throw them away. */ | /* Verify that the low 62 bits of the computation are indeed zero, and then throw them away. */ | ||||
VERIFY_CHECK(((int64_t)cd & M62) == 0); cd >>= 62; | VERIFY_CHECK(((int64_t)cd & M62) == 0); cd >>= 62; | ||||
VERIFY_CHECK(((int64_t)ce & M62) == 0); ce >>= 62; | VERIFY_CHECK(((int64_t)ce & M62) == 0); ce >>= 62; | ||||
/* Compute limb 1 of t*[d,e]+modulus*[md,me], and store it as output limb 0 (= down shift). */ | /* Compute limb 1 of t*[d,e]+modulus*[md,me], and store it as output limb 0 (= down shift). */ | ||||
cd += (int128_t)u * d1 + (int128_t)v * e1; | cd += (int128_t)u * d1 + (int128_t)v * e1; | ||||
ce += (int128_t)q * d1 + (int128_t)r * e1; | ce += (int128_t)q * d1 + (int128_t)r * e1; | ||||
if (modinfo->modulus.v[1]) { /* Optimize for the case where limb of modulus is zero. */ | |||||
cd += (int128_t)modinfo->modulus.v[1] * md; | cd += (int128_t)modinfo->modulus.v[1] * md; | ||||
ce += (int128_t)modinfo->modulus.v[1] * me; | ce += (int128_t)modinfo->modulus.v[1] * me; | ||||
} | |||||
d->v[0] = (int64_t)cd & M62; cd >>= 62; | d->v[0] = (int64_t)cd & M62; cd >>= 62; | ||||
e->v[0] = (int64_t)ce & M62; ce >>= 62; | e->v[0] = (int64_t)ce & M62; ce >>= 62; | ||||
/* Compute limb 2 of t*[d,e]+modulus*[md,me], and store it as output limb 1. */ | /* Compute limb 2 of t*[d,e]+modulus*[md,me], and store it as output limb 1. */ | ||||
cd += (int128_t)u * d2 + (int128_t)v * e2; | cd += (int128_t)u * d2 + (int128_t)v * e2; | ||||
ce += (int128_t)q * d2 + (int128_t)r * e2; | ce += (int128_t)q * d2 + (int128_t)r * e2; | ||||
if (modinfo->modulus.v[2]) { /* Optimize for the case where limb of modulus is zero. */ | |||||
cd += (int128_t)modinfo->modulus.v[2] * md; | cd += (int128_t)modinfo->modulus.v[2] * md; | ||||
ce += (int128_t)modinfo->modulus.v[2] * me; | ce += (int128_t)modinfo->modulus.v[2] * me; | ||||
} | |||||
d->v[1] = (int64_t)cd & M62; cd >>= 62; | d->v[1] = (int64_t)cd & M62; cd >>= 62; | ||||
e->v[1] = (int64_t)ce & M62; ce >>= 62; | e->v[1] = (int64_t)ce & M62; ce >>= 62; | ||||
/* Compute limb 3 of t*[d,e]+modulus*[md,me], and store it as output limb 2. */ | /* Compute limb 3 of t*[d,e]+modulus*[md,me], and store it as output limb 2. */ | ||||
cd += (int128_t)u * d3 + (int128_t)v * e3; | cd += (int128_t)u * d3 + (int128_t)v * e3; | ||||
ce += (int128_t)q * d3 + (int128_t)r * e3; | ce += (int128_t)q * d3 + (int128_t)r * e3; | ||||
if (modinfo->modulus.v[3]) { /* Optimize for the case where limb of modulus is zero. */ | |||||
cd += (int128_t)modinfo->modulus.v[3] * md; | cd += (int128_t)modinfo->modulus.v[3] * md; | ||||
ce += (int128_t)modinfo->modulus.v[3] * me; | ce += (int128_t)modinfo->modulus.v[3] * me; | ||||
} | |||||
d->v[2] = (int64_t)cd & M62; cd >>= 62; | d->v[2] = (int64_t)cd & M62; cd >>= 62; | ||||
e->v[2] = (int64_t)ce & M62; ce >>= 62; | e->v[2] = (int64_t)ce & M62; ce >>= 62; | ||||
/* Compute limb 4 of t*[d,e]+modulus*[md,me], and store it as output limb 3. */ | /* Compute limb 4 of t*[d,e]+modulus*[md,me], and store it as output limb 3. */ | ||||
cd += (int128_t)u * d4 + (int128_t)v * e4; | cd += (int128_t)u * d4 + (int128_t)v * e4; | ||||
ce += (int128_t)q * d4 + (int128_t)r * e4; | ce += (int128_t)q * d4 + (int128_t)r * e4; | ||||
cd += (int128_t)modinfo->modulus.v[4] * md; | cd += (int128_t)modinfo->modulus.v[4] * md; | ||||
ce += (int128_t)modinfo->modulus.v[4] * me; | ce += (int128_t)modinfo->modulus.v[4] * me; | ||||
d->v[3] = (int64_t)cd & M62; cd >>= 62; | d->v[3] = (int64_t)cd & M62; cd >>= 62; | ||||
▲ Show 20 Lines • Show All 174 Lines • Show Last 20 Lines |