This commit is contained in:
Kyle Spearrin 2023-01-20 16:12:41 -05:00
parent 9613019d4d
commit 392aa18497
2 changed files with 10 additions and 5 deletions

View file

@ -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);
}
}

View file

@ -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);
}
}