remove silly workaround for aes-ctr encrypt/decrypt

This commit is contained in:
Sorunome 2020-05-25 17:55:49 +02:00
parent adc5591e54
commit 80c7125d1d
No known key found for this signature in database
GPG key ID: B19471D07FC9BE9C
3 changed files with 5 additions and 34 deletions

View file

@ -24,7 +24,6 @@ const BASE58_ALPHABET =
const base58 = Base58Codec(BASE58_ALPHABET);
const OLM_RECOVERY_KEY_PREFIX = [0x8B, 0x01];
const OLM_PRIVATE_KEY_LENGTH = 32; // TODO: fetch from dart-olm
const AES_BLOCKSIZE = 16;
class SSSS {
final Client client;
@ -56,24 +55,10 @@ class SSSS {
final keys = deriveKeys(key, name);
// workaround for https://github.com/leocavalcante/encrypt/issues/136
var plain = Uint8List.fromList(utf8.encode(data));
final bytesMissing = AES_BLOCKSIZE - (plain.lengthInBytes % AES_BLOCKSIZE);
if (bytesMissing != AES_BLOCKSIZE) {
// we want to be able to modify it
final oldPlain = plain;
plain = Uint8List(plain.lengthInBytes + bytesMissing);
for (var i = 0; i < oldPlain.lengthInBytes; i++) {
plain[i] = oldPlain[i];
}
}
var ciphertext = AES(Key(keys.aesKey), mode: AESMode.ctr, padding: null)
final plain = Uint8List.fromList(utf8.encode(data));
final ciphertext = AES(Key(keys.aesKey), mode: AESMode.ctr, padding: null)
.encrypt(plain, iv: IV(iv))
.bytes;
if (bytesMissing != AES_BLOCKSIZE) {
// chop off those extra bytes again
ciphertext = ciphertext.sublist(0, plain.length - bytesMissing);
}
final hmac = Hmac(sha256, keys.hmacKey).convert(ciphertext);
@ -94,23 +79,9 @@ class SSSS {
throw 'Bad MAC';
}
// workaround for https://github.com/leocavalcante/encrypt/issues/136
var cipher = base64.decode(data.ciphertext);
final bytesMissing = AES_BLOCKSIZE - (cipher.lengthInBytes % AES_BLOCKSIZE);
if (bytesMissing != AES_BLOCKSIZE) {
// we want to be able to modify it
final oldCipher = cipher;
cipher = Uint8List(cipher.lengthInBytes + bytesMissing);
for (var i = 0; i < oldCipher.lengthInBytes; i++) {
cipher[i] = oldCipher[i];
}
}
final cipher = base64.decode(data.ciphertext);
final decipher = AES(Key(keys.aesKey), mode: AESMode.ctr, padding: null)
.decrypt(Encrypted(cipher), iv: IV(base64.decode(data.iv)));
if (bytesMissing != AES_BLOCKSIZE) {
// chop off those extra bytes again
return String.fromCharCodes(
decipher.sublist(0, decipher.length - bytesMissing));
}
return String.fromCharCodes(decipher);
}

View file

@ -210,7 +210,7 @@ packages:
name: encrypt
url: "https://pub.dartlang.org"
source: hosted
version: "4.0.1"
version: "4.0.2"
ffi:
dependency: transitive
description:

View file

@ -16,7 +16,7 @@ dependencies:
html_unescape: ^1.0.1+3
moor: ^3.0.2
random_string: ^2.0.1
encrypt: ^4.0.1
encrypt: ^4.0.2
crypto: ^2.1.4
base58check: ^1.0.1
password_hash: ^2.0.0