Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
ECDH.cs
1using System;
2
4{
8 public static class ECDH
9 {
18 public static PointOnCurve GetSharedPoint(byte[] LocalPrivateKey, byte[] RemotePublicKey,
19 bool RemoteBigEndian, EllipticCurve Curve)
20 {
21 PointOnCurve PublicKey = Curve.Decode(RemotePublicKey, RemoteBigEndian);
22 return Curve.ScalarMultiplication(LocalPrivateKey, PublicKey, true);
23 }
24
36 public static byte[] GetSharedKey(byte[] LocalPrivateKey, byte[] RemotePublicKey,
37 bool RemoteBigEndian, HashFunctionArray HashFunction, EllipticCurve Curve)
38 {
39 PointOnCurve P = GetSharedPoint(LocalPrivateKey, RemotePublicKey, RemoteBigEndian, Curve);
40
41 byte[] B = P.X.ToByteArray(); // Little endian
42
43 if (B.Length != Curve.OrderBytes)
44 Array.Resize(ref B, Curve.OrderBytes);
45
46 Array.Reverse(B); // Most significant byte first.
47
48 return HashFunction(B);
49 }
50 }
51}
Implements the Elliptic Curve Diffie-Hellman (ECDH) algorithm.
Definition: ECDH.cs:9
static PointOnCurve GetSharedPoint(byte[] LocalPrivateKey, byte[] RemotePublicKey, bool RemoteBigEndian, EllipticCurve Curve)
Gets a shared key using the Elliptic Curve Diffie-Hellman (ECDH) algorithm.
Definition: ECDH.cs:18
static byte[] GetSharedKey(byte[] LocalPrivateKey, byte[] RemotePublicKey, bool RemoteBigEndian, HashFunctionArray HashFunction, EllipticCurve Curve)
Gets a shared key using the Elliptic Curve Diffie-Hellman (ECDH) algorithm.
Definition: ECDH.cs:36
Abstract base class for elliptic curves.
int OrderBytes
Number of bytes required to represent the order of the curve.
PointOnCurve Decode(byte[] Point)
Decodes an encoded point on the curve.
PointOnCurve ScalarMultiplication(BigInteger N, PointOnCurve P, bool Normalize)
Performs the scalar multiplication of N *P .
delegate byte[] HashFunctionArray(byte[] Data)
Delegate to hash function.
HashFunction
Hash method enumeration.
Definition: Hashes.cs:26
Represents a point on a curve.
Definition: PointOnCurve.cs:10