segmentation error while using mpz_powm in a loop
shrims . .... ..
shrims4u at gmail.com
Fri May 8 14:59:39 CEST 2009
---------- Forwarded message ----------
From: shrims . .... .. <shrims4u at gmail.com>
Date: Fri, May 8, 2009 at 3:06 PM
Subject: Re: segmentation error while using mpz_powm in a loop
To: Paul Zimmermann <Paul.Zimmermann at loria.fr>
okay.....
Actually i am writing a milter which decrypts the email message.
For decryption i am using GMP library...
The code which gives the error is as follows:
mpz_t bigbody,encbody,decbody,n,d,e;
mpz_init_set_str (e, "5", 10);
mpz_init_set_str (n,
"81072118814004638617775947138239917744589505176471539666269773100315781097546894455560658571445286325125766632676152452856383447352821337178984474781813475276075048299705214136395672502245955793627681061360075723595075874516950614187016991430293887968216015097675955399134514678660046996064181098182893072761",
10);
mpz_init_set_str (d,
"32428847525601855447110378855295967097835802070588615866507909240126312439018757782224263428578114530050306653070460981142553378941128534871593789912725382636961637010791821646038659077539848411532121133465246631106852802485583932352673149866783600963924490576147444236696494852521901563664557493382382127469",
10);
char *STR;
STR=(char*)malloc(1000);
mpz_t array[10];
//mpz_array_init (array, 10, 308);
mpz_t array1[10];
//mpz_array_init (array1, 10, 100000);
char substring[400];
int i=0,lower=0,upper=308;
while(i<noOfBlocks)
{
strncpy(substring, data_buffer + lower, upper);
*(substring+308)='\0';
syslog( LOG_INFO, "conn# %d - substring = %s", cd->connection_num,
substring );
lower=upper;
upper=upper+308;
mpz_init_set_str(array[i],substring,10);
mpz_get_str (STR, 10, array[i]);
strcat(STR,"\0");
syslog( LOG_INFO, "conn# %d - Encrypted-Biginteger = %s",
cd->connection_num, STR );
mpz_init(array1[i]);
mpz_powm (array1[i], array[i], d, n);
mpz_get_str (STR, 10, array1[i]);
syslog( LOG_INFO, "conn# %d - Decrypted-Biginteger = %s",
cd->connection_num, STR );
size_t length;
void *ret;
char *decrypted;
decrypted=(char*)malloc(1000);
ret=mpz_export (decrypted, &length, 1,sizeof(data_buffer[0]), 0, 0,
array1[i]);
//ret=mpz_export (decrypted, &length, 1,sizeof(data_buffer[0]), 0, 0,
array1[i]);
strncpy(decrypted,ret,length);
*(decrypted+length)='\0';
syslog( LOG_INFO, "conn# %d - size decrypted = %d Decrypted = %s",
cd->connection_num,length, (char *)ret );
fflush(stdout);
free(decrypted);
fflush(stdin);
mpz_clear(array[i]);
mpz_clear(array1[i]);
i++;
}
This code executes for 2 iterations and then give segmentation fault
at *mpz_powm(
)*
On Fri, May 8, 2009 at 1:40 PM, Paul Zimmermann <Paul.Zimmermann at loria.fr>wrote:
> > I am getting segmentation fault in the program below.
> > I have initialised all the GMP variables properly...
> > But still i am getting segmentation fault at *mpz_powm( );
> > *The loop runs only once and second time it gives segmentation fault at
> > mpz_powm...
> > *
> > The code is as follows: [...]
>
> without a complete code we cannot reproduce your problem. I suggest you try
> to print the values of your variables before the mpz_powm call, with say
> gmp_printf. If you still get a segmentation fault *inside* the mpz_powm
> call,
> please send your complete program to the list.
>
> Paul Zimmermann
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://gmplib.org/list-archives/gmp-bugs/attachments/20090508/bb9fefbb/attachment.html>
More information about the gmp-bugs
mailing list