-
Notifications
You must be signed in to change notification settings - Fork 3
Advanced _Point*scalar multiplication
Chrono edited this page Dec 29, 2022
·
2 revisions
For detailed documentation, kindly refer to official libsodium.
Scalarmult in libsodium allows the developer to do 2 of the following functions..
- Allow the developer to compute an elliptic curve diffie hellman public key given an elliptic curve diffie hellman private key.
- Allow the developer to compute a shared secret by using different pair of public and private keys.
Initial Function
public static Byte[] Base(Byte[] CurrentUserSecretKey,Boolean ClearKey=false)
Example Code
RevampedKeyPair MyKeyPair = SodiumPublicKeyBox.GenerateRevampedKeyPair();
Byte[] PublicKey = SodiumScalarMult.Base(MyKeyPair.PrivateKey);
MessageBox.Show(PublicKey.SequenceEqual(MyKeyPair.PublicKey).ToString());
Initial Function
public static Byte[] Mult(Byte[] CurrentUserSecretKey,Byte[] OtherUserPublicKey,Boolean ClearKey=false)
public static IntPtr MultIntPtr(Byte[] CurrentUserSecretKey, Byte[] OtherUserPublicKey, Boolean ClearKey = false)
Example Code
RevampedKeyPair AliceKeyPair = SodiumPublicKeyBox.GenerateRevampedKeyPair();
RevampedKeyPair BobKeyPair = SodiumPublicKeyBox.GenerateRevampedKeyPair();
Byte[] SharedSecret1 = SodiumScalarMult.Mult(AliceKeyPair.PrivateKey, BobKeyPair.PublicKey);
IntPtr SharedSecret2IntPtr = SodiumScalarMult.MultIntPtr(BobKeyPair.PrivateKey, AliceKeyPair.PublicKey);
SodiumGuardedHeapAllocation.Sodium_MProtect_ReadWrite(SharedSecret2IntPtr);
Byte[] SharedSecret2 = new Byte[SharedSecret1.Length];
Marshal.Copy(SharedSecret2IntPtr, SharedSecret2, 0, SharedSecret1.Length);
SodiumGuardedHeapAllocation.Sodium_MProtect_NoAccess(SharedSecret2IntPtr);
MessageBox.Show(SharedSecret1.SequenceEqual(SharedSecret2).ToString());