Skip to content

Commit fe971c2

Browse files
committed
MAGETWO-96459: Fix performance on MAGETWO-83832
1 parent 42a857a commit fe971c2

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

app/code/Magento/Config/App/Config/Type/System.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -267,12 +267,12 @@ private function loadScopeData($scopeType, $scopeId)
267267
private function cacheData(array $data)
268268
{
269269
$this->cache->save(
270-
$this->encriptFilter->encrypt($this->serializer->serialize($data)),
270+
$this->encriptFilter->encryptWithFastestAlgorithm($this->serializer->serialize($data)),
271271
$this->configType,
272272
[self::CACHE_TAG]
273273
);
274274
$this->cache->save(
275-
$this->encriptFilter->encrypt($this->serializer->serialize($data['default'])),
275+
$this->encriptFilter->encryptWithFastestAlgorithm($this->serializer->serialize($data['default'])),
276276
$this->configType . '_default',
277277
[self::CACHE_TAG]
278278
);
@@ -281,14 +281,14 @@ private function cacheData(array $data)
281281
foreach ($data[$curScopeType] ?? [] as $curScopeId => $curScopeData) {
282282
$scopes[$curScopeType][$curScopeId] = 1;
283283
$this->cache->save(
284-
$this->encriptFilter->encrypt($this->serializer->serialize($curScopeData)),
284+
$this->encriptFilter->encryptWithFastestAlgorithm($this->serializer->serialize($curScopeData)),
285285
$this->configType . '_' . $curScopeType . '_' . $curScopeId,
286286
[self::CACHE_TAG]
287287
);
288288
}
289289
}
290290
$this->cache->save(
291-
$this->encriptFilter->encrypt($this->serializer->serialize($scopes)),
291+
$this->encriptFilter->encryptWithFastestAlgorithm($this->serializer->serialize($scopes)),
292292
$this->configType . '_scopes',
293293
[self::CACHE_TAG]
294294
);

lib/internal/Magento/Framework/Encryption/Encryptor.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,21 @@ private function getPasswordVersion()
281281
* @return string
282282
*/
283283
public function encrypt($data)
284+
{
285+
$crypt = new SodiumChachaIetf($this->keys[$this->keyVersion]);
286+
287+
return $this->keyVersion .
288+
':' . self::CIPHER_AEAD_CHACHA20POLY1305 .
289+
':' . base64_encode($crypt->encrypt($data));
290+
}
291+
292+
/**
293+
* Encrypt data using the fastest available algorithm
294+
*
295+
* @param string $data
296+
* @return string
297+
*/
298+
public function encryptWithFastestAlgorithm($data)
284299
{
285300
$crypt = $this->getCrypt();
286301
if (null === $crypt) {
@@ -290,7 +305,6 @@ public function encrypt($data)
290305
':' . $this->getCipherVersion() .
291306
':' . base64_encode($crypt->encrypt($data));
292307
}
293-
294308
/**
295309
* Look for key and crypt versions in encrypted data before decrypting
296310
*
@@ -423,13 +437,16 @@ private function getCrypt(
423437

424438
if ($cipherVersion === self::CIPHER_RIJNDAEL_128) {
425439
$cipher = MCRYPT_RIJNDAEL_128;
440+
$mode = MCRYPT_MODE_ECB;
426441
} elseif ($cipherVersion === self::CIPHER_RIJNDAEL_256) {
427442
$cipher = MCRYPT_RIJNDAEL_256;
443+
$mode = MCRYPT_MODE_CBC;
428444
} else {
429445
$cipher = MCRYPT_BLOWFISH;
446+
$mode = MCRYPT_MODE_ECB;
430447
}
431448

432-
return new Mcrypt($key, $cipher, MCRYPT_MODE_ECB, $initVector);
449+
return new Mcrypt($key, $cipher, $mode, $initVector);
433450
}
434451

435452
/**

0 commit comments

Comments
 (0)