deriveSharedSecretFactory function
Uint8List Function(Uint8List privateKeyBytes, PublicKey otherPublicKey)
deriveSharedSecretFactory(
Implementation
Uint8List Function(Uint8List privateKeyBytes, ct.PublicKey otherPublicKey)
deriveSharedSecretFactory(cryptoHash) {
return (privateKeyBytes, otherPublicKey) {
var tweetNacl = tweet_nacl.TweetNaCl();
var scalarmult = tweetNacl.scalarmult;
var Z = tweetNacl.Z;
var point = [gf(), gf(), gf(), gf()];
tweet_nacl.TweetNaCl.unpackneg(point, otherPublicKey.bytes);
if (!isCanonicalKey(otherPublicKey) ||
0 != tweet_nacl.TweetNaCl.unpackneg(point, otherPublicKey.bytes) ||
!isInMainSubgroup(point)) {
throw Exception('invalid point');
}
// negate point == negate X coordinate and 't'
Z(point[0], gf(), point[0]);
Z(point[3], gf(), point[3]);
var scalar = Uint8List(64);
cryptoHash(scalar, privateKeyBytes);
scalar[0] &= 248;
scalar[31] &= 127;
scalar[31] |= 64;
var result = [gf(), gf(), gf(), gf()];
scalarmult(result, point, scalar, 0);
var sharedSecret = Uint8List(32);
tweetNacl.pack(sharedSecret, result);
return sharedSecret;
};
}