Megolm export: Increase to 500000 PBKDF rounds

This takes 370ms on my machine (100000 only took 100ms).
This commit is contained in:
Richard van der Hoff 2017-02-02 16:38:19 +00:00
parent a0e4afc231
commit eebc7539f9

View file

@ -102,7 +102,7 @@ export function decryptMegolmKeyFile(data, password) {
*/
export function encryptMegolmKeyFile(data, password, options) {
options = options || {};
const kdf_rounds = options.kdf_rounds || 100000;
const kdf_rounds = options.kdf_rounds || 500000;
const salt = new Uint8Array(16);
window.crypto.getRandomValues(salt);
@ -164,6 +164,7 @@ export function encryptMegolmKeyFile(data, password, options) {
* @return {Promise<[CryptoKey, CryptoKey]>} promise for [aes key, hmac key]
*/
function deriveKeys(salt, iterations, password) {
const start = new Date();
return subtleCrypto.importKey(
'raw',
new TextEncoder().encode(password),
@ -182,6 +183,9 @@ function deriveKeys(salt, iterations, password) {
512
);
}).then((keybits) => {
const now = new Date();
console.log("E2e import/export: deriveKeys took " + (now - start) + "ms");
const aes_key = keybits.slice(0, 32);
const hmac_key = keybits.slice(32);