Subversion Repositories php_clientchallenge

Compare Revisions

No changes between revisions

Regard whitespace Rev 6 → Rev 7

/trunk/.gitignore
1,5 → 1,7
vendor/
cache/
composer.lock
composer.phar
Sha3.php
.phpstan.tmp
 
/trunk/ClientChallenge.class.php
23,20 → 23,24
 
const OPEN_TRANS_DIR = __DIR__.'/cache';
 
private static function sha3_512($message, $raw_output=false) {
if (version_compare(PHP_VERSION, '7.1.0') >= 0) {
return hash('sha3-512', $message, $raw_output);
} else {
private static function tryDownloadPhpSha3() {
// Download file if required (usually composer should do it)
if (file_exists(__DIR__.'/Sha3.php')) include_once __DIR__.'/Sha3.php';
if (!class_exists('\bb\Sha3\Sha3')) {
$sha3_lib = file_get_contents('https://raw.githubusercontent.com/danielmarschall/php-sha3/master/src/Sha3.php');
if (file_put_contents(__DIR__.'/Sha3.php', $sha3_lib)) {
if (@file_put_contents(__DIR__.'/Sha3.php', $sha3_lib)) {
include_once __DIR__.'/Sha3.php';
} else {
eval('?>'.$sha3_lib);
}
}
}
 
private static function sha3_512($message, $raw_output=false) {
if (version_compare(PHP_VERSION, '7.1.0') >= 0) {
return hash('sha3-512', $message, $raw_output);
} else {
self::tryDownloadPhpSha3();
return \bb\Sha3\Sha3::hash($message, 512, $raw_output);
}
}
46,25 → 50,11
if (version_compare(PHP_VERSION, '7.1.0') >= 0) {
return hash_hmac('sha3-512', $message, $key, $raw_output);
} else {
$blocksize = 576; // block size of sha-512!
 
if (strlen($key) > ($blocksize/8)) {
$k_ = self::sha3_512($key,true);
} else {
$k_ = $key;
self::tryDownloadPhpSha3();
return \bb\Sha3\Sha3::hash_hmac($message, $key, 512, $raw_output);
}
 
$k_opad = str_repeat(chr(0x5C),($blocksize/8));
$k_ipad = str_repeat(chr(0x36),($blocksize/8));
for ($i=0; $i<strlen($k_); $i++) {
$k_opad[$i] = $k_opad[$i] ^ $k_[$i];
$k_ipad[$i] = $k_ipad[$i] ^ $k_[$i];
}
 
return self::sha3_512($k_opad . self::sha3_512($k_ipad . $message, true));
}
}
 
private static function getOpenTransFileName($ip_target, $random) {
// Delete challenges which were never completed
$files = glob(self::OPEN_TRANS_DIR.'/*.tmp');
/trunk/cache
Property changes:
Added: svn:ignore
+*.tmp
+
/trunk/composer.json
17,6 → 17,6
"prefer-dist": true,
"require": {
"php": ">=7.0",
"n-other/php-sha3": "*@dev"
"danielmarschall/php-sha3": "*@dev"
}
}
/trunk/phpstan.neon.dist
2,7 → 2,6
level: 5
fileExtensions:
- php
- phps
paths:
- .
excludePaths: