MCPcopy Create free account
hub / github.com/Moddable-OpenSource/moddable / fxBigInt_ec_norm

Function fxBigInt_ec_norm

modules/crypt/arith/xsBigIntEx.c:908–941  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

906}
907
908void fxBigInt_ec_norm(xsMachine *the, txECPoint *r, txECPoint *a, txECParam *ec)
909{
910 txBigInt *inv, *inv2, *inv3;
911 pool_t pool;
912
913 if (r->z == NULL)
914 r->z = fxBigInt_alloc(the, ec->m->size);
915 if (r->y == NULL)
916 r->y = fxBigInt_alloc(the, ec->m->size);
917 if (r->x == NULL)
918 r->x = fxBigInt_alloc(the, ec->m->size);
919
920 if (fxBigInt_iszero(a->z) || fxBigInt_ucomp(a->z, ec->one) == 0) {
921 fxBigInt_copy(r->x, a->x);
922 fxBigInt_copy(r->y, a->y);
923 fxBigInt_copy(r->z, a->z);
924 return;
925 }
926
927 pool_init(&pool);
928 inv = pool_get(the, ec->m->size, &pool);
929 inv2 = pool_get(the, ec->m->size, &pool);
930 inv3 = pool_get(the, ec->m->size, &pool);
931 inv = mont_out(the, inv, a->z, ec->m, ec->u);
932 inv = fxBigInt_mod_mulinv(the, inv, inv, ec->m);
933 inv = mont_in(the, inv, inv, ec->m);
934 inv2 = fxBigInt_mont_square(the, inv2, inv, ec->m, ec->u, &pool);
935 inv3 = fxBigInt_mont_mul(the, inv3, inv2, inv, ec->m, ec->u, &pool);
936
937 fxBigInt_mont_mul(the, r->x, a->x, inv2, ec->m, ec->u, &pool);
938 fxBigInt_mont_mul(the, r->y, a->y, inv3, ec->m, ec->u, &pool);
939 fxBigInt_copy(r->z, ec->one);
940 pool_dispose(the, &pool);
941}

Callers 3

xs_ec2_addFunction · 0.85
xs_ec2_mulFunction · 0.85
xs_ec2_mul2Function · 0.85

Calls 9

fxBigInt_allocFunction · 0.85
fxBigInt_iszeroFunction · 0.85
fxBigInt_ucompFunction · 0.85
fxBigInt_copyFunction · 0.85
pool_initFunction · 0.85
pool_getFunction · 0.85
mont_outFunction · 0.85
mont_inFunction · 0.85
pool_disposeFunction · 0.85

Tested by

no test coverage detected