Topic: [SOLVED] Diffie-Helman Key agreement "wc_DhAgree" returns error (-243)
Hi everyone
I appreciate any hint in advanced.
Diffie-Helman Key agreement "wc_DhAgree" returns error (-243): "DH Check Public Key failure".
I tried to have both sides 'A' and 'B' in a same program and then establish a key using both private and public keys. I used 'p' and 'g' in cert_test.h to generate public and private keys on side A. and also used 'dh_key_der_1024' in cert_test.h to decode public and private keys for side B.
Side A:
DhKey keyA;
int ret;
const byte* pA= dh_p; // initialize with prime };
const byte* gA= dh_g; // initialize with base };
byte privA[256];
byte pubA[256];
byte agree[256];
word32 agreeSz;
word32 privSzA, pubSzA;
wc_InitDhKey(&keyA); // initialize key
WC_RNG rng;
wc_InitRng(&rng); // initialize rng
ret = wc_DhSetKey(&keyA, pA, sizeof(pA), gA, sizeof(gA));
ret = wc_DhGenerateKeyPair(&keyA, &rng, privA, &privSzA, pubA, &pubSzA);
Side B:
DhKey keyB;
byte privB[256];
byte pubB[256];
word32 privSzB, pubSzB;
const unsigned char* tmpB = dh_key_der_1024;
word32 idxB = 0;
wc_InitDhKey(&keyB); // initialize key
ret = wc_DhKeyDecode(tmpB, &idxB, &keyB, sizeof_client_keypub_der_1024);
ret = wc_DhGenerateKeyPair(&keyB, &rng, privB, &privSzB, pubB, &pubSzB);
and finally
ret = wc_DhAgree(&keyA,agree, &agreeSz, privA, sizeof(privA), pubB, pubSzB);
wc_ErrorString(ret,errorString);
printf("\r\nwc_DhAgree Error: (%d): %s",ret,errorString);
:
This will return error (-243): "DH Check Public Key failure".
Any clue?!