<br><br><div class="gmail_quote">---------- Forwarded message ----------<br>From: <b class="gmail_sendername">shrims . .... ..</b> <span dir="ltr"><<a href="mailto:shrims4u@gmail.com">shrims4u@gmail.com</a>></span><br>
Date: Fri, May 8, 2009 at 3:06 PM<br>Subject: Re: segmentation error while using mpz_powm in a loop<br>To: Paul Zimmermann <<a href="mailto:Paul.Zimmermann@loria.fr">Paul.Zimmermann@loria.fr</a>><br><br><br>okay..... <br>
Actually i am writing a milter which decrypts the email message.<br>For decryption i am using GMP library...<br><br>The code which gives the error is as follows:<div class="im"><br><br>mpz_t bigbody,encbody,decbody,n,d,e;<br>
<br> <br><br></div> mpz_init_set_str (e, "5", 10);<br><br> mpz_init_set_str (n, "81072118814004638617775947138239917744589505176471539666269773100315781097546894455560658571445286325125766632676152452856383447352821337178984474781813475276075048299705214136395672502245955793627681061360075723595075874516950614187016991430293887968216015097675955399134514678660046996064181098182893072761", 10);<br>
<br> mpz_init_set_str (d, "32428847525601855447110378855295967097835802070588615866507909240126312439018757782224263428578114530050306653070460981142553378941128534871593789912725382636961637010791821646038659077539848411532121133465246631106852802485583932352673149866783600963924490576147444236696494852521901563664557493382382127469", 10);<br>
<br><br><br>char *STR;<br>STR=(char*)malloc(1000);<div class="im"><br><br><br><br>mpz_t array[10];<br>//mpz_array_init (array, 10, 308);<br>mpz_t array1[10];<br></div>//mpz_array_init (array1, 10, 100000);<br><br>char substring[400];<br>
int i=0,lower=0,upper=308;<div class="im"><br>
while(i<noOfBlocks)<br>{ <br><br> strncpy(substring, data_buffer + lower, upper);<br></div> *(substring+308)='\0';<br> syslog( LOG_INFO, "conn# %d - substring = %s", cd->connection_num, substring );<div class="im">
<br>
lower=upper;<br> upper=upper+308;<br> <br> mpz_init_set_str(array[i],substring,10);<br><br> mpz_get_str (STR, 10, array[i]);<br> strcat(STR,"\0");<br> syslog( LOG_INFO, "conn# %d - Encrypted-Biginteger = %s", cd->connection_num, STR );<br>
<br> <br> mpz_init(array1[i]);<br> mpz_powm (array1[i], array[i], d, n);<br><br></div> mpz_get_str (STR, 10, array1[i]);<br> syslog( LOG_INFO, "conn# %d - Decrypted-Biginteger = %s", cd->connection_num, STR );<br>
<br> size_t length;<br> void *ret;<br> char *decrypted;<br> decrypted=(char*)malloc(1000);<br> <br> ret=mpz_export (decrypted, &length, 1,sizeof(data_buffer[0]), 0, 0, array1[i]);<br> //ret=mpz_export (decrypted, &length, 1,sizeof(data_buffer[0]), 0, 0, array1[i]);<br>
<br> strncpy(decrypted,ret,length);<br> *(decrypted+length)='\0';<br><br><br> syslog( LOG_INFO, "conn# %d - size decrypted = %d Decrypted = %s", cd->connection_num,length, (char *)ret );<br>
fflush(stdout);<br>
<br> <br> free(decrypted);<br> fflush(stdin);<br> mpz_clear(array[i]);<br> mpz_clear(array1[i]);<br> i++;<br> <br>}<br><br>This code executes for 2 iterations and then give segmentation fault at <b>mpz_powm( )</b><div>
<div></div><div class="h5"><br>
<br><br><div class="gmail_quote">On Fri, May 8, 2009 at 1:40 PM, Paul Zimmermann <span dir="ltr"><<a href="mailto:Paul.Zimmermann@loria.fr" target="_blank">Paul.Zimmermann@loria.fr</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div>> I am getting segmentation fault in the program below.<br>
> I have initialised all the GMP variables properly...<br>
> But still i am getting segmentation fault at *mpz_powm( );<br>
> *The loop runs only once and second time it gives segmentation fault at<br>
> mpz_powm...<br>
> *<br>
</div>> The code is as follows: [...]<br>
<br>
without a complete code we cannot reproduce your problem. I suggest you try<br>
to print the values of your variables before the mpz_powm call, with say<br>
gmp_printf. If you still get a segmentation fault *inside* the mpz_powm call,<br>
please send your complete program to the list.<br>
<font color="#888888"><br>
Paul Zimmermann<br>
</font></blockquote></div><br>
</div></div></div><br>