mirror of
https://github.com/bitwarden/mobile
synced 2025-12-10 13:23:39 +00:00
Argon2id KDF (#2309)
* add gcc_flags for libargon2.a * fix up ios proj * remove unused tag * add gcc_flags to ios projects * ios libargon2 binary * fix paths in ios project * update pathing on other projs * Argon2id primitive * fix typing issues * comment * remove ds store * [PS-2249] Implement Argon2 (#2293) * Implement Argon2 * Fix incorrect argon2 type on iOS * Switch argon2 implementation to native bindings * Change argon2 to save iterations instead of memory as 'kdfIterations' * Remove mistakenly added import * Remove unused library * cleanup * move android libs * move android libs * Revert "move android libs" This reverts commit0b91b22cd2. * Revert "move android libs" This reverts commit139839c469. * PR feedback Co-authored-by: Bernd Schoolmann <mail@quexten.com>
This commit is contained in:
@@ -5,6 +5,8 @@ using Org.BouncyCastle.Crypto.Digests;
|
||||
using Org.BouncyCastle.Crypto.Generators;
|
||||
using Org.BouncyCastle.Crypto.Parameters;
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using Java.Lang;
|
||||
|
||||
namespace Bit.Droid.Services
|
||||
{
|
||||
@@ -33,5 +35,19 @@ 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");
|
||||
int keySize = 32;
|
||||
var key = new byte[keySize];
|
||||
argon2id_hash_raw(iterations, memory, parallelism,
|
||||
password, password.Length, salt, salt.Length, key, key.Length);
|
||||
return key;
|
||||
}
|
||||
|
||||
[DllImport("argon2", EntryPoint = "argon2id_hash_raw")]
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user