I'm trying to confirm/get the unsigned int (base 10 / decimal) value of an hex'd mpi value. I'm using the following code:
#include <gcrypt.h>
#include <stdio.h>
static gcry_mpi_t privkey = NULL;
int main(){
char *parmstr = "48BFDA215C31A9F0B226B3DB11F862450A0F30DA";
printf("starting program\n");
gcry_mpi_scan(&privkey, GCRYMPI_FMT_HEX, (char *)parmstr, 0, NULL);
printf("printing hashed (?) mpi\n");
gcry_mpi_dump(privkey);
printf("\n");
size_t gablen;
unsigned char *result;
/* get length */
gcry_mpi_print (GCRYMPI_FMT_USG, NULL, 0, &gablen, privkey);
result = gcry_malloc_secure(gablen);
/* get actual value */
gcry_mpi_print (GCRYMPI_FMT_USG, result, gablen, NULL, privkey);
/* print actual value */
printf("result: %s\n", result);
printf("finished\n");
}
and i'm getting the following result:
$ ./foo
starting program
printing hashed (?) mpi
48BFDA215C31A9F0B226B3DB11F862450A0F30DA
result: H¿Ú!\1©ð²&³ÛøbE
0Ú
finished
I would the 'result: ' line to print the actual unsigned int (base 10 / decimal) value.
The private key is taking from the Off-The-Record Pidgin plug-in that i'm trying to work with.
EDIT:
can anybody confirm that the actual unsigned int (base 10 / decimal) value should be
415325779662433871844955547383752003988573073626
I could probably update the program to create a new mpi in gcrypt with this value and see if the HEX value is the same as what i already have. I will do this later today.
EDIT 2:
So i'm trying to do the following to print the HEX value of the int value mentioned above. Something is going wrong:
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);
The output is:
result: 48BFDA215C31A9F0B226B3DB11F862450A0F30DA
The number tested is: 415325779662433871844955547383752003988573073626
trying to convert to HEX
result: 415325779662433871844955547383752003988573073626
EDIT 3:
I updated the post a bit, basically i'm trying to print the base10 decimal value of an hex value that is generated by the gcrypt library. I'm looking for this value to confirm an implementation that i made to read these values. I was looking for a gcrypt function to achieve this. It seems that gcrypt doesn't supports this?