1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
|
unsigned char *keyAlice = NULL;
unsigned char *final = NULL;
...
// Computing secret shared keys with other peers's public key
//Alice
keyAlice = (unsigned char *)malloc(DH_size(dhAlice));
if(keyAlice == NULL) { perror("malloc"); exit(2); }
final = (unsigned char *)malloc(DH_size(dhAlice));
if(final == NULL) { perror("malloc"); exit(2); }
ret = DH_compute_key(keyAlice, dhBob->pub_key, dhAlice);
if( ret == -1 ) { perror("Dh Compute"); exit(2); }
printf("Alice calculated : ");
for (j=0; j<ret; j++)
{
// decallage du pointeur
sprintf(final+(2*j), "%02X",keyAlice[j]);
}
printf("%s\n", final);
if(final != NULL) free(final);
if(keyAlice != NULL) free(keyAlice); |
Partager