i am working with GMP lib for the first time and it looks like this code does some dirty memory cheats:
void addition (const point p,const point q,const mpz_t fp, point* result){
mpz_t ld;
mpz_init(ld);
lambda_add(p,q,fp,ld);
gmp_printf( "WTFCHECK1: %Zx, %Zx\n", p.x ,p.y);
mpz_mul(result->x,ld,ld);
gmp_printf( "WTFCHECK2: %Zx, %Zx\n", p.x ,p.y);
mpz_sub(result->x,result->x,p.x);
gmp_printf( "WTFCHECK3: %Zx, %Zx\n", p.x ,p.y);
...
}
where lambda looks like
void lambda_add (const point p,const point q,const mpz_t fp, mpz_t result){
mpz_t ydiff,xdiff;
mpz_init (ydiff);
mpz_init (xdiff);
mpz_sub (ydiff,q.y,p.y);
mpz_sub (xdiff,q.x,p.x);
...//no more usage of p or q
}
But program output still looks like this:
WTFCHECK1: 7cf27b188d034f7e8a52380304b51ac3c08969e277f21b35a60b48fc47669978, 7775510db8ed040293d9ac69f7430dbba7dade63ce982299e04b79d227873d1
WTFCHECK2: de8a6886d284cb85d49a93b707475ed3d277242444ba9e860207f9a59a9ef351, 7775510db8ed040293d9ac69f7430dbba7dade63ce982299e04b79d227873d1
As you can see, variable p.x of type mpz_t (x and y are mpz_t type in typedef structure point) has changed without me assigning anything into it. What is the reason of this behavior? Thanks.
p
,q
, andresult
as well as the call toaddition
. What happens if you comment out the call tolambda_add
? – Craig Estey<gmpxx.h>
that comes with GMP, and the typempz_class
it provides. – Marc Glisse