leslie-wung
leslie-wung

Reputation: 1

Crypto++ library x5519 shared key generation error

I am using Crypto++ library to sign and verify with ed25519 signature scheme by underlying Donna functions. I generated two key pair and then I try to generate shared key for both side by function curve25519_mult .But the key generated twice is not the same.

What is the problem with the code below?

#include <donna.h>
#include <osrng.h>
#include <cassert>
int main()
{
static CryptoPP::AutoSeededRandomPool prng;

//Generate random private keys
unsigned char private_key1[32],private_key2[32];
prng.GenerateBlock(private_key1, 32);
prng.GenerateBlock(private_key2, 32);

//Generate public keys
unsigned char public_key1[32],public_key2[32];
CryptoPP::Donna::ed25519_publickey(public_key1, private_key1);
CryptoPP::Donna::ed25519_publickey(public_key2, private_key2);

//Generate shared key
unsigned char shared_secret1[32],shared_secret2[32];
CryptoPP::Donna::curve25519_mult(shared_secret1, private_key1, publicKey2);
CryptoPP::Donna::curve25519_mult(shared_secret2, private_key2, publicKey1);

//Assertion failed!
assert(::memcmp(shared_secret1,shared_secret2,32) == 0);
}

What I done:

I just need to generate a shared key for the two key pair holders.

Upvotes: 0

Views: 45

Answers (0)

Related Questions