I am testing out some Dart cryptography libraries for deriving Argon2id keys with large parameter values, such as the maximum allowed settings in the Bitwarden password manager, which as of today are 10 iterations, 16 parallelism, and 1024 MiB memory.
The following leads to a segmentation fault. Running the script with --old_gen_heap_size=2g sometimes gives a segmentation fault, but sometimes it works.
import 'dart:convert';
import 'dart:typed_data';
import 'package:cryptography/cryptography.dart';
Future<void> main() async {
final Uint8List password = utf8.encode("passphrase");
final List<int> salt =
(await Sha256().hash(base64.decode("rNYWSe/wFO1k+Qxia0A96A=="))).bytes;
// Bitwarden maximum settings
final int kdfIterations = 10;
final int kdfParallelism = 16;
final int kdfMemory = 1024; // 1024 MiB
final Argon2id algorithm = Argon2id(
parallelism: kdfParallelism,
memory: kdfMemory * 1024,
iterations: kdfIterations,
hashLength: 32,
);
final SecretKey newSecretKey =
await algorithm.deriveKey(secretKey: SecretKey(password), nonce: salt);
final List<int> newSecretKeyBytes = await newSecretKey.extractBytes();
print('hashed password: $newSecretKeyBytes');
}
An alternative solution would be to use the hashlib package, which is able to handle the aforementioned KDF settings (10 iterations, 16 parallelism, and 1024 MiB memory).
I am testing out some Dart cryptography libraries for deriving Argon2id keys with large parameter values, such as the maximum allowed settings in the Bitwarden password manager, which as of today are
10
iterations,16
parallelism, and1024 MiB
memory.The following leads to a segmentation fault. Running the script with
--old_gen_heap_size=2g
sometimes gives a segmentation fault, but sometimes it works.Equivalent working program using pointycastle.
Expected output for both programs:
I am aware that it is not advisable to set Argon2id KDF settings to such extreme values in either case, however, this may be worth some investigation.