Skip to content

Commit

Permalink
Merge pull request #2745 from PhilippC/argon2-fix
Browse files Browse the repository at this point in the history
fix issue with argon2 kdf
  • Loading branch information
PhilippC authored Jan 14, 2025
2 parents 1094b43 + 73fc93e commit 146f181
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ You should have received a copy of the GNU General Public License
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

using Java.Lang;
using System;
using System.Collections.Generic;
using System.Diagnostics;
Expand Down Expand Up @@ -179,6 +180,7 @@ public override byte[] Transform(byte[] pbMsg, KdfParameters p)
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,
Expand All @@ -189,7 +191,7 @@ public override byte[] Transform(byte[] pbMsg, KdfParameters p)

if (ret != 0)
{
throw new Exception("argon2_hash failed with " + ret);
throw new System.Exception("argon2_hash failed with " + ret);
}

pbRet = new byte[32];
Expand All @@ -214,8 +216,9 @@ public override KdfParameters GetBestParameters(uint uMilliseconds)
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,
Expand Down
1 change: 1 addition & 0 deletions src/KeePassLib2Android/KeePassLib2Android.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<SupportedOSPlatformVersion>21</SupportedOSPlatformVersion>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<None Remove="Resources\values\Strings.xml" />
Expand Down
10 changes: 7 additions & 3 deletions src/keepass2android-app/keepass2android-app.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand Down Expand Up @@ -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>
Expand All @@ -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" />
Expand Down

0 comments on commit 146f181

Please sign in to comment.