Skip to content
This repository has been archived by the owner on Jan 29, 2024. It is now read-only.

Commit

Permalink
Replaced NSec with BouncyCastle to solve the vcruntime140.dll is not …
Browse files Browse the repository at this point in the history
…supported issues
  • Loading branch information
COM8 committed Apr 3, 2022
1 parent 21bc03d commit 3d72193
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 16 deletions.
6 changes: 4 additions & 2 deletions Component_Tests/Classes/Crypto/Omemo/Test_KeyHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
using System.Collections.Generic;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NSec.Cryptography;
using Omemo.Classes;
using Omemo.Classes.Keys;
using Org.BouncyCastle.Math.EC.Rfc8032;
using Shared.Classes;

namespace Component_Tests.Classes.Crypto.Omemo
Expand Down Expand Up @@ -56,7 +56,9 @@ public void Test_SignPreKey()
for (uint id = 1; id < 250; id++)
{
byte[] data = Encoding.ASCII.GetBytes("Message for Ed25519 signing");
byte[] signature = SignatureAlgorithm.Ed25519.Sign(Key.Import(SignatureAlgorithm.Ed25519, identityKeyPair.privKey.key, KeyBlobFormat.RawPrivateKey), data);

byte[] signature = new byte[Ed25519.SignatureSize];
Ed25519.Sign(identityKeyPair.privKey.key, 0, data, 0, data.Length, signature, 0);
byte[] sigRef = SharedUtils.HexStringToByteArray("6dd355667fae4eb43c6e0ab92e870edb2de0a88cae12dbd8591507f584fe4912babff497f1b8edf9567d2483d54ddc6459bea7855281b7a246a609e3001a4e08");
string sigRefBase64 = Convert.ToBase64String(sigRef);
string sigBase64 = Convert.ToBase64String(signature);
Expand Down
13 changes: 7 additions & 6 deletions Omemo/Classes/KeyHelper.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Collections.Generic;
using NSec.Cryptography;
using Omemo.Classes.Keys;
using Org.BouncyCastle.Math.EC.Rfc8032;
using X25519;

namespace Omemo.Classes
Expand All @@ -9,8 +9,8 @@ public static class KeyHelper
{
//--------------------------------------------------------Attributes:-----------------------------------------------------------------\\
#region --Attributes--
public static int PUB_KEY_SIZE = SignatureAlgorithm.Ed25519.PublicKeySize;
public static int PRIV_KEY_SIZE = SignatureAlgorithm.Ed25519.PrivateKeySize;
public static int PUB_KEY_SIZE = Ed25519.PublicKeySize;
public static int PRIV_KEY_SIZE = Ed25519.SecretKeySize;

#endregion
//--------------------------------------------------------Constructor:----------------------------------------------------------------\\
Expand Down Expand Up @@ -95,8 +95,9 @@ public static SignedPreKeyModel GenerateSignedPreKey(uint id, ECPrivKeyModel ide
public static byte[] SignPreKey(PreKeyModel preKey, ECPrivKeyModel identiyKey)
{
byte[] pubKey = preKey.pubKey.ToByteArrayWithPrefix();
Key key = Key.Import(SignatureAlgorithm.Ed25519, identiyKey.key, KeyBlobFormat.RawPrivateKey);
return SignatureAlgorithm.Ed25519.Sign(key, pubKey);
byte[] signature = new byte[Ed25519.SignatureSize];
Ed25519.Sign(identiyKey.key, 0, pubKey, 0, pubKey.Length, signature, 0);
return signature;
}

/// <summary>
Expand All @@ -108,7 +109,7 @@ public static byte[] SignPreKey(PreKeyModel preKey, ECPrivKeyModel identiyKey)
/// <returns>True in case the signature is valid.</returns>
public static bool VerifySignature(ECPubKeyModel identityKey, ECPubKeyModel preKey, byte[] signature)
{
return SignatureAlgorithm.Ed25519.Verify(PublicKey.Import(SignatureAlgorithm.Ed25519, identityKey.key, KeyBlobFormat.RawPublicKey), preKey.ToByteArrayWithPrefix(), signature);
return Ed25519.Verify(signature, 0, identityKey.key, 0, preKey.key, 0, preKey.key.Length);
}

/// <summary>
Expand Down
8 changes: 0 additions & 8 deletions Omemo/Omemo.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,6 @@
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform">
<Version>6.2.13</Version>
</PackageReference>
<PackageReference Include="NSec.Cryptography">
<Version>20.2.0</Version>
</PackageReference>
<PackageReference Include="Portable.BouncyCastle">
<Version>1.9.0</Version>
</PackageReference>
Expand All @@ -177,11 +174,6 @@
<Name>Shared</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<SDKReference Include="Microsoft.VCLibs.Desktop, Version=14.0">
<Name>Visual C++ 2015-2019 UWP Desktop Runtime for native apps</Name>
</SDKReference>
</ItemGroup>
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' &lt; '14.0' ">
<VisualStudioVersion>14.0</VisualStudioVersion>
</PropertyGroup>
Expand Down

0 comments on commit 3d72193

Please sign in to comment.