Merge pull request #660 from matrix-org/rav/megolm_export_fixes
Two megolm export fixes:
This commit is contained in:
@@ -50,7 +50,7 @@ export function decryptMegolmKeyFile(data, password) {
|
||||
}
|
||||
|
||||
const ciphertextLength = body.length-(1+16+16+4+32);
|
||||
if (body.length < 0) {
|
||||
if (ciphertextLength < 0) {
|
||||
throw new Error('Invalid file: too short');
|
||||
}
|
||||
|
||||
@@ -107,14 +107,14 @@ export function encryptMegolmKeyFile(data, password, options) {
|
||||
const salt = new Uint8Array(16);
|
||||
window.crypto.getRandomValues(salt);
|
||||
|
||||
// clear bit 63 of the salt to stop us hitting the 64-bit counter boundary
|
||||
// (which would mean we wouldn't be able to decrypt on Android). The loss
|
||||
// of a single bit of salt is a price we have to pay.
|
||||
salt[9] &= 0x7f;
|
||||
|
||||
const iv = new Uint8Array(16);
|
||||
window.crypto.getRandomValues(iv);
|
||||
|
||||
// clear bit 63 of the IV to stop us hitting the 64-bit counter boundary
|
||||
// (which would mean we wouldn't be able to decrypt on Android). The loss
|
||||
// of a single bit of iv is a price we have to pay.
|
||||
iv[9] &= 0x7f;
|
||||
|
||||
return deriveKeys(salt, kdf_rounds, password).then((keys) => {
|
||||
const [aes_key, hmac_key] = keys;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user