From cce2c58fc3e2f59e76ae75c83f80170d932f294d Mon Sep 17 00:00:00 2001 From: Robert Date: Sun, 25 Dec 2022 18:25:23 -0500 Subject: [PATCH] encryption bechmarks. --- src/configs/mockup/loadall.php | 4 +- src/configs/mockup/on_security.php | 4 +- src/mockup/controllers/app/enc_ctrl.php | 94 +++++++++++++++++++++++++ 3 files changed, 98 insertions(+), 4 deletions(-) create mode 100644 src/mockup/controllers/app/enc_ctrl.php diff --git a/src/configs/mockup/loadall.php b/src/configs/mockup/loadall.php index d2da7ba..679d067 100644 --- a/src/configs/mockup/loadall.php +++ b/src/configs/mockup/loadall.php @@ -40,8 +40,8 @@ 'csrf_security_level' => 'high', // Stop Attacks at what cost?? 'retries_allowed_before_throttling' => 3, // Reties attempts allowed for login, before it throttles it... 'throttling_login_seconds' => 20, // Seconds to deny more login attempts - 'password_hash' => PASSWORD_BCRYPT, - 'password_hash_options' => ['cost' => 10], // Default=10. This is a good baseline cost, but you may want to consider increasing it depending on your hardware. + 'pepper_pwd' => 'SZFJXX]7HcwJjS]av3q8cUR', + 'salt_pwd' => 'fVN(P8nBNK3;tM88Kkku', )); /* Contents of : on_sessions.php */ diff --git a/src/configs/mockup/on_security.php b/src/configs/mockup/on_security.php index e44cb02..140130a 100644 --- a/src/configs/mockup/on_security.php +++ b/src/configs/mockup/on_security.php @@ -7,6 +7,6 @@ 'csrf_security_level' => 'high', // Stop Attacks at what cost?? 'retries_allowed_before_throttling' => 3, // Reties attempts allowed for login, before it throttles it... 'throttling_login_seconds' => 20, // Seconds to deny more login attempts - 'password_hash' => PASSWORD_BCRYPT, - 'password_hash_options' => ['cost' => 10], // Default=10. This is a good baseline cost, but you may want to consider increasing it depending on your hardware. + 'pepper_pwd' => 'SZFJXX]7HcwJjS]av3q8cUR', + 'salt_pwd' => 'fVN(P8nBNK3;tM88Kkku', )); diff --git a/src/mockup/controllers/app/enc_ctrl.php b/src/mockup/controllers/app/enc_ctrl.php new file mode 100644 index 0000000..cae8c78 --- /dev/null +++ b/src/mockup/controllers/app/enc_ctrl.php @@ -0,0 +1,94 @@ + + * @copyright Copyright (c) 2022, Robert Strutts. + * @license https://mit-license.org/ + */ + +namespace prj\mockup\controllers\app; + +class enc_ctrl { + public $page_output; + + private function time_enc(array $levels): void { + $enc = new \tts\services\encryption(); + foreach($levels as $level) { + echo "ENC: Level = $level
" . PHP_EOL; + $enc->change_security_level($level); + +// $key = $enc->generate_valid_key(); + $key = "51623a064210f9d3d5162d0885621f53"; + echo "KEY Used: $key
" . PHP_EOL; + + $startTime = microtime(true); + $data = $enc->encrypt($key, "Hello, World!"); + echo "
$data
" . PHP_EOL; + echo "Encrypt Time: " . number_format(( microtime(true) - $startTime), 4) . " Seconds\n"; + + $startTime = microtime(true); + $decoded = $enc->decrypt($key, $data); + echo "
$decoded
" . PHP_EOL; + echo "Decrypt Time: " . number_format(( microtime(true) - $startTime), 4) . " Seconds\n"; + echo "

".PHP_EOL; + } + } + + /* + * Let's test the in-secure, Quicker encryption methods + * These methods are good engough to make sure + * data was not tampered with and hide it's contents + * from spying eyes. + */ + public function index() { + $levels = ['lighting','blaze','quick','good']; + $this->time_enc($levels); + } + + // Let's test the secure encryption methods. + public function slow() { + $levels = ['good','normal','paranoid']; + $this->time_enc($levels); + } + + public function sodium() { // 0.0041 Seconds + $crypto = new \tts\services\paragon_crypto\crypto(); +// echo $crypto->a_single_key_maker(); + $key = "oH5LUubQXkUgC2sXkxahLnzgcZokVFANyxAew+kOvuk="; + + $startTime = microtime(true); + $data = $crypto->safe_encrypt("Hello, World!", $key, $crypto::single_key); + echo "
$data
" . PHP_EOL; + echo "Encrypt Time: " . number_format(( microtime(true) - $startTime), 4) . " Seconds\n"; + +// $data = "sJWIPEasG1W8ModZJKU8jOR78/i1qUZDl6nX5ew21ceOdEZHNDGwqCA1lD70GuIHP4DJEMQ="; + + $startTime = microtime(true); + $decoded = $crypto->safe_decrypt($data, $key, $crypto::single_key); + echo "
$decoded
" . PHP_EOL; + echo "Decrypt Time: " . number_format(( microtime(true) - $startTime), 4) . " Seconds\n"; + echo "

".PHP_EOL; + } + + public function sodium_pwd_test() { // 0.1233 Seconds + $startTime = microtime(true); + $c = new \tts\services\paragon_crypto\password_storage(); +// $key = $c->generate_a_key(); + $key = "9054695cc0f4080c15865de470f63ee993478b14c357eb910c815a4e0a1d4401"; + + $h = $c->hash("HelpMe", $key); + var_dump( $c->verify("HelpMe", $h, $key) ); + echo "Hashed PWD and Verified it: " . number_format(( microtime(true) - $startTime), 4) . " Seconds\n"; + } + + public function pwd_test() { // 0.9281 Seconds + $startTime = microtime(true); + $db_hash = \tts\security::do_password_hash("HelpMe"); + var_dump( \tts\security::do_password_verify("HelpMe", $db_hash) ); + echo "Hashed PWD and Verified it: " . number_format(( microtime(true) - $startTime), 4) . " Seconds\n"; + } + + +} \ No newline at end of file