diff --git a/src/Android/Services/CryptoPrimitiveService.cs b/src/Android/Services/CryptoPrimitiveService.cs index 6ea22224a..69a62f78f 100644 --- a/src/Android/Services/CryptoPrimitiveService.cs +++ b/src/Android/Services/CryptoPrimitiveService.cs @@ -35,15 +35,20 @@ namespace Bit.Droid.Services generator.Init(password, salt, iterations); return ((KeyParameter)generator.GenerateDerivedMacParameters(keySize)).GetKey(); } + public byte[] Argon2id(byte[] password, byte[] salt, int iterations, int memory, int parallelism) { JavaSystem.LoadLibrary("argon2"); - var hash = new byte[32]; - argon2id_hash_raw(iterations, memory, parallelism, password, password.Length, password, salt.Length, hash, 32); - return hash.ToArray(); + // TODO: Do we need to pass this in somehow like PBKDF2, based on an algorithm? + int keySize = 32; + var key = new byte[keySize]; + argon2id_hash_raw(iterations, memory, parallelism, + password, password.Length, password, salt.Length, key, key.Length); + return key; } [DllImport("argon2", EntryPoint = "argon2id_hash_raw")] - internal static extern int argon2id_hash_raw(int timeCost, int memoryCost, int parallelism, byte[] pwd, int pwdlen, byte[] salt, int saltlen, ref byte hash, int hashlen); + private static extern int argon2id_hash_raw(int timeCost, int memoryCost, int parallelism, + byte[] pwd, int pwdlen, byte[] salt, int saltlen, byte[] hash, int hashlen); } } diff --git a/src/iOS.Core/Services/CryptoPrimitiveService.cs b/src/iOS.Core/Services/CryptoPrimitiveService.cs index 5357e8f30..9c0bd87bc 100644 --- a/src/iOS.Core/Services/CryptoPrimitiveService.cs +++ b/src/iOS.Core/Services/CryptoPrimitiveService.cs @@ -63,7 +63,7 @@ namespace Bit.iOS.Core.Services IntPtr salt, nuint saltLen, uint prf, nuint rounds, IntPtr derivedKey, nuint derivedKeyLength); [DllImport("__Internal", EntryPoint = "argon2id_hash_raw")] - internal static extern int argon2id_hash_raw(int timeCost, int memoryCost, int parallelism, IntPtr pwd, + 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); } }