Skip to content

Commit bb5be4b

Browse files
committed
Optimize
1 parent b5bb887 commit bb5be4b

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/neo/Cryptography/Helper.cs

+6-4
Original file line numberDiff line numberDiff line change
@@ -154,23 +154,25 @@ public static byte[] AES256Decrypt(this byte[] encryptedData, byte[] key, byte[]
154154

155155
public static byte[] ECDHDeriveKey(KeyPair local, ECPoint remote)
156156
{
157+
ReadOnlySpan<byte> pubkey_local = local.PublicKey.EncodePoint(false);
158+
ReadOnlySpan<byte> pubkey_remote = remote.EncodePoint(false);
157159
using ECDiffieHellman ecdh1 = ECDiffieHellman.Create(new ECParameters
158160
{
159161
Curve = ECCurve.NamedCurves.nistP256,
160162
D = local.PrivateKey,
161163
Q = new System.Security.Cryptography.ECPoint
162164
{
163-
X = local.PublicKey.EncodePoint(false)[1..][..32],
164-
Y = local.PublicKey.EncodePoint(false)[1..][32..]
165+
X = pubkey_local[1..][..32].ToArray(),
166+
Y = pubkey_local[1..][32..].ToArray()
165167
}
166168
});
167169
using ECDiffieHellman ecdh2 = ECDiffieHellman.Create(new ECParameters
168170
{
169171
Curve = ECCurve.NamedCurves.nistP256,
170172
Q = new System.Security.Cryptography.ECPoint
171173
{
172-
X = remote.EncodePoint(false)[1..][..32],
173-
Y = remote.EncodePoint(false)[1..][32..]
174+
X = pubkey_remote[1..][..32].ToArray(),
175+
Y = pubkey_remote[1..][32..].ToArray()
174176
}
175177
});
176178
return ecdh1.DeriveKeyMaterial(ecdh2.PublicKey).Sha256();//z = r * P = r* k * G

0 commit comments

Comments
 (0)