fix issue with argon2 kdf (regression from .net8 migration) by

* including armeabi-v7 and arm64-v8 .so files
* switching to [LibraryImport] instead of [DllImport]
This commit is contained in:
Philipp Crocoll
2025-01-14 13:55:21 +01:00
parent 81b48a3ac2
commit 73fc93ed96
3 changed files with 14 additions and 6 deletions

View File

@@ -17,6 +17,7 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
using Java.Lang;
using System;
using System.Collections.Generic;
using System.Diagnostics;
@@ -179,6 +180,7 @@ namespace KeePassLib.Cryptography.KeyDerivation
Marshal.Copy(pbSalt, 0, saltPtr, pbSalt.Length);
const UInt32 Argon2_d = 0;
JavaSystem.LoadLibrary("argon2");
int ret = argon2_hash(
(UInt32)uIt, (UInt32)(uMem / 1024), uPar,
@@ -189,7 +191,7 @@ namespace KeePassLib.Cryptography.KeyDerivation
if (ret != 0)
{
throw new Exception("argon2_hash failed with " + ret);
throw new System.Exception("argon2_hash failed with " + ret);
}
pbRet = new byte[32];
@@ -214,8 +216,9 @@ namespace KeePassLib.Cryptography.KeyDerivation
return p;
}
[DllImport("argon2")]
static extern int argon2_hash(
[LibraryImport("argon2")]
[return: MarshalAs(UnmanagedType.I4)]
public static partial int argon2_hash(
UInt32 t_cost, UInt32 m_cost, UInt32 parallelism,
IntPtr pwd, IntPtr pwdlen,
IntPtr salt, IntPtr saltlen,

View File

@@ -4,6 +4,7 @@
<SupportedOSPlatformVersion>21</SupportedOSPlatformVersion>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<None Remove="Resources\values\Strings.xml" />

View File

@@ -9,6 +9,7 @@
<ApplicationId>keepass2android.keepass2android</ApplicationId>
<ApplicationVersion>1</ApplicationVersion>
<ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<None Remove="Assets\fontawesome-webfont.ttf" />
@@ -712,9 +713,6 @@
<None Remove="Resources\xml\searchable_mattest.xml" />
<None Remove="Resources\xml\searchable_offline.xml" />
</ItemGroup>
<ItemGroup>
<AndroidNativeLibrary Include="..\java\argon2\libs\armeabi-v7a\libargon2.so" Link="libargon2.so" />
</ItemGroup>
<ItemGroup>
<AndroidResource Include="Resources\drawable-mdpi\ic_storage_kp2a">
<SubType>Designer</SubType>
@@ -728,6 +726,12 @@
<Folder Include="Resources\drawable-xxhdpi\" />
<Folder Include="Resources\drawable-xxxhdpi\" />
</ItemGroup>
<ItemGroup>
<AndroidNativeLibrary Include="..\java\argon2\libs\arm64-v8a\libargon2.so" Link="arm64-v8a\libargon2.so" />
</ItemGroup>
<ItemGroup>
<AndroidNativeLibrary Include="..\java\argon2\libs\armeabi-v7a\libargon2.so" Link="armeabi-v7a\libargon2.so" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Xamarin.AndroidX.AppCompat" Version="1.7.0.3" />
<PackageReference Include="Xamarin.AndroidX.AppCompat.AppCompatResources" Version="1.7.0.3" />