PHP Classes

Argon2 Refiner: Benchmark Argon2id hashing to recommend parameters

Recommend this page to a friend!
  Info   View files Example   View files View files (9)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 37 This week: 1All time: 10,888 This week: 560Up
Version License PHP version Categories
argon2-refiner 1.0MIT/X Consortium ...5Cryptography, Performance and optimiz..., P...
Description 

Author

This package can be used to benchmark Argon2id hashing to recommend parameters.

It takes as arguments some parameters that the limits of time and memory used by Argon2id password hashing.

The package runs some benchmarks with the given parameters and generates new parameter values to optimize the hashing process on the current hosting environment.

Innovation Award
PHP Programming Innovation award nominee
August 2019
Number 9
Argon2 is a function for implementing a password hashing method. It provides means to change parameters that can tune its behavior.

This package can generate parameter values to optimize the execution of a password hashing function based on Argon2.

Manuel Lemos
Picture of Scott Arciszewski
  Performance   Level  
Name: Scott Arciszewski <contact>
Classes: 36 packages by
Country: United States United States
Age: ???
All time rank: 1180171 in United States United States
Week rank: 52 Up6 in United States United States Up
Innovation award
Innovation award
Nominee: 28x

Winner: 1x

Example

#!/usr/bin/php
<?php
use ParagonIE\Argon2Refiner\ParameterRecommender;

if (
file_exists(dirname(__DIR__) . '/vendor/autoload.php')) {
   
// We're a standalone package
   
require_once dirname(__DIR__) . '/vendor/autoload.php';
} elseif (
file_exists(dirname(__DIR__, 3) . '/autoload.php')) {
   
// We're installed as a library
   
require_once dirname(__DIR__, 3) . '/autoload.php';
} else {
   
// Trust the include path.
   
require_once 'vendor/autoload.php';
}

$ms = $argc > 1 ? $argv[1] : 500;
$recommender = (new ParameterRecommender($ms));
if (
$argc > 2) {
   
$tolerance = (int) $argv[2];
    if (
$tolerance > 0) {
       
$recommender->setTolerance($tolerance);
    }
}

$results = $recommender->runBenchmarks();
if (empty(
$results)) {
    echo
'No parameters meet your target time window.', PHP_EOL;
    exit(
255);
}

$min = [
   
'diff' => PHP_INT_MAX,
   
'data' => [
       
'time_cost' => null,
       
'mem_cost' => null,
       
'bench_time' => PHP_INT_MAX
   
]
];

foreach (
$results as $i => $res) {
   
$weightedDiff = $res['bench_time'] - $ms;
    if (
$weightedDiff > 0) {
       
// Apply a penalty to overshots
       
$weightedDiff *= 2;
    } else {
       
$weightedDiff *= -1;
    }
    if (
$weightedDiff < $min['diff']) {
       
$min = [
           
'diff' => $weightedDiff,
           
'data' => $res
       
];
    }
   
$results[$i]['diff'] = $weightedDiff;
}

$reduced = $min['data']['mem_cost'] >> 10;
echo
'Recommended Argon2id parameters:', PHP_EOL;
echo
"\t Memory cost (sodium): {$min['data']['mem_cost']}\n";
echo
"\tMemory cost (password_hash): {$reduced}\n";
echo
"\t Time cost: {$min['data']['time_cost']}\n\n";
echo
"Real time: {$min['data']['bench_time']}ms\n";


  Files folder image Files  
File Role Description
Files folder imagebin (1 file)
Files folder imagesrc (1 file)
Files folder imagetests (1 file)
Accessible without login Plain text file .travis.yml Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file phpunit.xml Data Auxiliary data
Accessible without login Plain text file psalm.xml Data Auxiliary data
Accessible without login Plain text file README.md Doc. Read me

  Files folder image Files  /  bin  
File Role Description
  Accessible without login Plain text file benchmark Example Example script

  Files folder image Files  /  src  
File Role Description
  Accessible without login Plain text file ParameterRecommender.php Class Class source

  Files folder image Files  /  tests  
File Role Description
  Accessible without login Plain text file ParameterRecommenderTest.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:37
This week:1
All time:10,888
This week:560Up