[OTR-dev] working with the libgcrypt mpi type and getting the actual integer value

Bjorn Kuiper bjorn at kuiper.nu
Tue Feb 26 18:04:23 EST 2013


Hi,

I'm trying to develop a C# implementation of the Off-the-record library, 
but I'm having some problems with the libgcrypt library.

Can somebody explain to me how you can print out the actual integer 
value of an hex'd MPI ?

Basically i want to know the integer value of this 'private' key

48BFDA215C31A9F0B226B3DB11F862450A0F30DA

I think it is

415325779662433871844955547383752003988573073626

but I'm unable to find a way to confirm this using libgcrypt

I tried the following code:

-- code snippit
gcry_mpi_t cript_prime;
char buffer[50] = {0};
char number[50] = {0};

cript_prime = gcry_mpi_new(50);

strcpy(number,"415325779662433871844955547383752003988573073626");
gcry_mpi_scan(&cript_prime,GCRYMPI_FMT_USG,number,sizeof(number),NULL);

gcry_mpi_print(GCRYMPI_FMT_USG,buffer,sizeof(buffer),NULL,cript_prime);

printf("The number tested is: %s\n",buffer);

printf("trying to convert to HEX\n");

/* get actual value */
gcry_mpi_print (GCRYMPI_FMT_HEX, buffer, sizeof(buffer), NULL, cript_prime);
/* print actual value */
printf("result: %s\n", buffer);
-- end of code snippit

which results in:

-- output
The number tested is: 415325779662433871844955547383752003988573073626
trying to convert to HEX
result: 415325779662433871844955547383752003988573073626
-- end of output

I expected the second gcry_mpi_print to convert it to HEX by using 
GCRYPT_FMT_HEX enum, but that doesn't seem to work.

I also devoted an stackoverflow question to it:
http://stackoverflow.com/questions/15080516/print-unsigned-int-value-of-mpi

Thank you for your help, this will help me advance my implementation 
efforts in creating a C# lib.

Greetings Bjorn



More information about the OTR-dev mailing list