generateKeyPair method
Generate a new Public/Private Key pair based on the curve
Implementation
EcdhKeyPair generateKeyPair(
EcdhCurve curve,
) {
final _curve = curve.getNative(_ecc);
final privateSize = _ecc.uECC_curve_private_key_size(_curve);
final publicSize = _ecc.uECC_curve_public_key_size(_curve);
final privateKey = calloc.allocate(privateSize).cast<Uint8>();
final publicKey = calloc.allocate(publicSize).cast<Uint8>();
bool err = _ecc.uECC_make_key(publicKey, privateKey, _curve) == 0;
final Uint8List private = Uint8List(privateSize);
final Uint8List public = Uint8List(publicSize);
private.setAll(0, privateKey.asTypedList(privateSize));
public.setAll(0, publicKey.asTypedList(publicSize));
calloc.free(privateKey);
calloc.free(publicKey);
if (err) {
throw Exception("Failed to generate key pair");
}
return EcdhKeyPair(private, public, curve);
}