Last active
September 20, 2017 23:49
-
-
Save KarelWintersky/fe29dcad75de515e5a468894e7c070e6 to your computer and use it in GitHub Desktop.
openssl_encrypt() cyphers testing comparsion
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* User: Arris | |
* Date: 21.09.2017, time: 0:35 | |
*/ | |
const TEST_COUNT = 100000; | |
const SOURCE = 'Тестируем обратимое шифрование на php'; | |
const KEY = "password"; | |
function TESTER( $testing_function, $argument ) | |
{ | |
$t = microtime(true); | |
for ($test_iterator = 0; $test_iterator < TEST_COUNT; $test_iterator++) { | |
$testing_function( $argument ); | |
} | |
return round(microtime(true) - $t, 4); | |
} | |
$crypt = function($cipher) { | |
$ivlen = openssl_cipher_iv_length($cipher); | |
$iv = openssl_random_pseudo_bytes($ivlen); | |
openssl_encrypt(SOURCE, $cipher, KEY, $options=0, $iv); | |
}; | |
$methods = openssl_get_cipher_methods(false); | |
array_splice( $methods, 0, count($methods) / 2); | |
$timings = array(); | |
foreach ($methods as $cypher) { | |
$time = TESTER( $crypt, $cypher ); | |
$timings[ $cypher ] = $time; | |
echo str_pad($cypher, 40, ' ', STR_PAD_LEFT), " have time ", str_pad($time, 8, STR_PAD_LEFT), ' seconds. ', PHP_EOL; | |
} | |
uasort($timings, function($a, $b){ | |
return $a <=> $b; | |
}); | |
$min_time = round(reset($timings) / TEST_COUNT, 7); | |
$min_cypher = key($timings); | |
$max_time = round(end($timings) / TEST_COUNT, 7); | |
$max_cypher = key($timings); | |
echo '-------------', PHP_EOL; | |
echo "Total tests: ", count($timings), PHP_EOL; | |
echo "Max timing : {$max_time} seconds for `{$max_cypher}` algorithm.", PHP_EOL; | |
echo "Min timing : {$min_time} seconds for `{$min_cypher}` algorithm.", PHP_EOL; | |
echo 'Details: ', PHP_EOL; | |
foreach ($timings as $m => $t) { | |
echo '- ', str_pad($t, 8, STR_PAD_LEFT), " seconds for `{$m}`", PHP_EOL; | |
} | |
echo PHP_EOL; |
for ($i = 0; $i < 10; $i++) {
echo "[$i] ", openssl_random_pseudo_bytes( openssl_cipher_iv_length('seed-ofb') ), PHP_EOL;
}
// returns KiTTYKiTTYKiTTY at last iteration
O.O
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hardware: GA-N3150N-D3V, Celeron™ N3150 (1.6 GHz) quad-core processor, 4Gb RAM
Software: Gentoo 4.2.15, PHP version 7.0.2
Results:
Total tests: 99
Max timing : 0.000218 seconds for
camellia-192-cfb1
algorithm.Min timing : 4.2E-6 seconds for
aes-128-ecb
algorithm.Details (time for 100000 operations)
aes-128-ecb
aes-192-ecb
aes-256-ecb
camellia-128-ecb
rc4-40
rc5-ecb
rc4
camellia-256-ecb
camellia-192-ecb
idea-ecb
cast5-ecb
des-ecb
seed-ecb
rc4-hmac-md5
rc2-ecb
des-ede
id-aes128-wrap
id-aes256-wrap
des-ede3
id-aes192-wrap
aes-128-ofb
aes-192-cbc
aes-192-ofb
aes-256-cbc
aes-256-cfb
aes-256-ofb
aes-128-xts
aes-256-ctr
aes-192-ctr
aes-192-cfb
aes-256-xts
id-aes128-CCM
rc5-cbc
aes-256-ccm
id-aes192-CCM
rc5-ofb
rc5-cfb
aes-192-ccm
id-aes256-CCM
aes-256-cbc-hmac-sha1
idea-cbc
idea-cfb
camellia-128-cfb
idea-ofb
camellia-128-ofb
cast5-cbc
cast5-cfb
cast5-ofb
camellia-256-cfb
camellia-192-ofb
camellia-256-ofb
camellia-192-cfb
camellia-128-cbc
aes-128-gcm
des-ofb
aes-256-gcm
camellia-256-cbc
camellia-192-cbc
id-aes256-GCM
id-aes128-GCM
des-cbc
des-cfb
aes-192-gcm
id-aes192-GCM
desx-cbc
id-smime-alg-CMS3DESwrap
seed-ofb
aes-256-cbc-hmac-sha256
rc2-64-cbc
rc2-40-cbc
seed-cbc
seed-cfb
rc2-cbc
rc2-cfb
rc2-ofb
aes-192-cfb8
aes-256-cfb8
des-ede-ofb
des-ede-cfb
des-ede-cbc
des-ede3-cfb
des-ede3-cbc
des-ede3-ofb
camellia-128-cfb8
des-cfb8
camellia-192-cfb8
camellia-256-cfb8
des-ede3-cfb8
des-ede3-cfb1
bf-ecb
bf-cbc
bf-ofb
bf-cfb
aes-192-cfb1
aes-256-cfb1
des-cfb1
camellia-128-cfb1
camellia-256-cfb1
camellia-192-cfb1