From 4bcc7c0d7196169f1815f0bcb4046fc1b22fa654 Mon Sep 17 00:00:00 2001 From: Dinis Vieira Date: Wed, 18 Oct 2023 12:20:41 +0100 Subject: [PATCH] Enabled argon2Id for iOS --- src/App/App.csproj | 2 ++ src/iOS.Autofill/iOS.Autofill.csproj | 2 ++ src/iOS.Core/Services/CryptoPrimitiveService.cs | 14 ++++++-------- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/App/App.csproj b/src/App/App.csproj index 3c51b2ea2..ee1c50347 100644 --- a/src/App/App.csproj +++ b/src/App/App.csproj @@ -58,9 +58,11 @@ Platforms\iOS\Entitlements.plist all None + -gcc_flags "-L$(ProjectDir)../../lib/ios -largon2 -force_load $(ProjectDir)../../lib/ios/libargon2.a" false + -gcc_flags "-L$(ProjectDir)../../lib/ios -largon2 -force_load $(ProjectDir)../../lib/ios/libargon2.a" diff --git a/src/iOS.Autofill/iOS.Autofill.csproj b/src/iOS.Autofill/iOS.Autofill.csproj index c15688df2..68e88b8bf 100644 --- a/src/iOS.Autofill/iOS.Autofill.csproj +++ b/src/iOS.Autofill/iOS.Autofill.csproj @@ -26,9 +26,11 @@ Entitlements.plist all None + -gcc_flags "-L$(ProjectDir)../../lib/ios -largon2 -force_load $(ProjectDir)../../lib/ios/libargon2.a" false + -gcc_flags "-L$(ProjectDir)../../lib/ios -largon2 -force_load $(ProjectDir)../../lib/ios/libargon2.a" diff --git a/src/iOS.Core/Services/CryptoPrimitiveService.cs b/src/iOS.Core/Services/CryptoPrimitiveService.cs index 71989985f..f1047f00a 100644 --- a/src/iOS.Core/Services/CryptoPrimitiveService.cs +++ b/src/iOS.Core/Services/CryptoPrimitiveService.cs @@ -48,9 +48,8 @@ namespace Bit.iOS.Core.Services var passwordData = NSData.FromArray(password); var saltData = NSData.FromArray(salt); - // TODO: [MAUI-Migration] [Critical] - //argon2id_hash_raw(iterations, memory, parallelism, passwordData.Bytes, passwordData.Length, - // saltData.Bytes, saltData.Length, keyData.MutableBytes, keyData.Length); + argon2id_hash_raw(iterations, memory, parallelism, passwordData.Bytes, passwordData.Length, + saltData.Bytes, saltData.Length, keyData.MutableBytes, keyData.Length); var keyBytes = new byte[keyData.Length]; Marshal.Copy(keyData.Bytes, keyBytes, 0, Convert.ToInt32(keyData.Length)); @@ -59,12 +58,11 @@ namespace Bit.iOS.Core.Services // ref: http://opensource.apple.com/source/CommonCrypto/CommonCrypto-55010/CommonCrypto/CommonKeyDerivation.h [DllImport(ObjCRuntime.Constants.libSystemLibrary, EntryPoint = "CCKeyDerivationPBKDF")] - private extern static int CCKeyCerivationPBKDF(uint algorithm, IntPtr password, nuint passwordLen, + private static extern int CCKeyCerivationPBKDF(uint algorithm, IntPtr password, nuint passwordLen, IntPtr salt, nuint saltLen, uint prf, nuint rounds, IntPtr derivedKey, nuint derivedKeyLength); - // TODO: [MAUI-Migration] [Critical] - //[DllImport("__Internal", EntryPoint = "argon2id_hash_raw")] - //private static extern int argon2id_hash_raw(int timeCost, int memoryCost, int parallelism, IntPtr pwd, - // nuint pwdlen, IntPtr salt, nuint saltlen, IntPtr hash, nuint hashlen); + [DllImport("__Internal", EntryPoint = "argon2id_hash_raw")] + private static extern int argon2id_hash_raw(int timeCost, int memoryCost, int parallelism, IntPtr pwd, + nuint pwdlen, IntPtr salt, nuint saltlen, IntPtr hash, nuint hashlen); } }