Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. Linux, Apache, MySQL, PHP
  4. segmentation error while using mpz_powm in a loop

segmentation error while using mpz_powm in a loop

Scheduled Pinned Locked Moved Linux, Apache, MySQL, PHP
data-structureshelp
1 Posts 1 Posters 5 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    shrims4u
    wrote on last edited by
    #1

    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 { 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( )

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups