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 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <openssl/dh.h>
#include <openssl/engine.h>
#define PRIME_LEN 64
#define GENERATOR 2
int main()
{
void printDH(char *name, DH *dh);
void test(DH *dh); // modifie les champs de dh
DH *dhAlice;
srand( (unsigned)time( NULL ) );
dhAlice = DH_new();
test(dhAlice);
printDH("Main", dhAlice); // MARCHE PAS :(
DH_free(dhAlice);
return EXIT_SUCCESS;
}
void test(DH *dh)
{
printf("Generating DH params ... this can take a while \n");
dh = DH_generate_parameters(PRIME_LEN, GENERATOR, NULL, NULL);
printf("Generating public & private keys ... \n");
DH_generate_key(dh);
printDH("Alice", dh); // MARCHE
}
void printDH(char *name, DH *dh)
{
//char *BN_bn2dec(const BIGNUM *a);
printf("--------------\n");
printf("%s :\n", name);
printf("%i bits\n", PRIME_LEN);
if(dh->p != NULL)
printf("p: %s\n", BN_bn2hex(dh->p));
else
printf("p: NULL\n");
printf("g: %s\n", BN_bn2hex(dh->g));
printf("priv_key: %s\n", BN_bn2hex(dh->priv_key));
printf("pub_key: %s\n", BN_bn2hex(dh->pub_key));
printf("\n");
} |
Partager