gcry_mpi_scan( ) problem ....

kky mingyur at inventati.org
Fri Oct 13 16:06:23 CEST 2006


Hi all ! i'm using the libgcrypt and i've got an error i can't go
through, i don't know if you can help me and if it is the right place.
I'm using the same function in an other context without problems and if
i pass the same parameter of the other context i get the same error :

this is the output of the debug with gdb:
[...]

The salt buffer is :
3216252CB911C77A49E4F311F933C176ECC7BA4C0E05CB14960EB82C9645E0B1

The length of s + id + pwd is :  48

printing the buffer:
3216252CB911C77A49E4F311F933C176ECC7BA4C0E05CB14960EB82C9645E0B16D696E677975726B6F626C656E736B79

Printing the x_digest :
DDC4425FB32D87AAD3236FC7C9EC6C60842F11EDDCFA5D7C6E172D6F0457C7AF

Program received signal SIGSEGV, Segmentation fault.
0xb7d148d2 in _int_malloc () from /lib/tls/libc.so.6
(gdb) bt
#0  0xb7d148d2 in _int_malloc () from /lib/tls/libc.so.6
#1  0xb7d138f3 in malloc () from /lib/tls/libc.so.6
#2  0xb7f0b849 in _gcry_private_malloc (n=3084695584) at stdmem.c:78
#3  0xb7f08ba3 in _gcry_malloc (n=134915000, flags=0, mem=0x15fe0421) at
global.c:409
#4  0xb7f08bd9 in gcry_malloc (n=20) at global.c:429
#5  0xb7f08ed9 in gcry_xmalloc (n=20) at global.c:562
#6  0xb7f3e5ff in _gcry_mpi_alloc (nlimbs=1) at mpiutil.c:43
#7  0xb7f3cb32 in gcry_mpi_scan (ret_mpi=0xbff481d0,
format=GCRYMPI_FMT_USG, buffer_arg=0x80aaf90, buflen=32, nscanned=0x21)
at mpicoder.c:383

[...]


the code:
int build_x(gcry_mpi_t *x,uint8_t *id,uint8_t *password,uint8_t *s)
{
    uint8_t *buffer, *x_digest,*next;
    gcry_mpi_t prova;
    int md_size,length,len_s,len_id,len_passwd,buffer_byte,grplen,i;
    size_t *scanned;
    gcry_error_t err;

    len_s = 32;
    len_id = strlen(id);
    len_passwd = strlen(password);
    length = len_s+len_id+len_passwd;
   
   
    printf("\nThe salt buffer is : ");
    for(i=0;i<32;i++)
        printf("%02X",s[i] & 0xFF);
    printf("\n");
   
    buffer = (uint8_t *)gcry_calloc(length+100,1);
    if (buffer == NULL)  {
        printf("buffer: out of memory");
        return 0;
    }
   
    next = mempcpy (buffer, s, len_s);
    next = mempcpy (next, id, len_id);
    mempcpy (next, password, len_passwd);
   
    printf("\nThe length of s + id + pwd is :  %d\n",length);
    printf("\nprinting the buffer: ");
    for(i=0;i<length;i++)
    printf("%02X",buffer[i] & 0xFF);
    printf("\n");
   
    //get the size of the message digest
    md_size = gcry_md_get_algo_dlen(GCRY_MD_SHA256);
   
    x_digest = (uint8_t*) gcry_calloc(md_size,1); //era md_size+1
    if (x_digest == NULL)  {
        printf("k_digest: out of memory");
        return 0;
    }
   
    gcry_md_hash_buffer(GCRY_MD_SHA256, x_digest, buffer,length);
   
    printf("\nPrinting the x_digest : ");
    for(i=0;i<32;i++)
        printf("%02X",x_digest[i] & 0xFF);
    printf("\n");
   
    err = gcry_mpi_scan(x, GCRYMPI_FMT_USG, x_digest,32, scanned);    <-
THIS IS THE FUNCTION IN LINE #7 OF GDB
    if(err){
        printf("Failed to scan mpi from md buffer: %s\n",
gpg_strerror(err));
        return 0;
    }
   
    printf("\nThe value of x\n");
    gcry_mpi_dump (*x);
   
    //free memory
    gcry_free(buffer);
    gcry_free(x_digest);
   
    return 0;
}

Thank you !!
kky



More information about the Gcrypt-devel mailing list