SATS/lib/cyclic-hash/source/hash.php

43 lines
915 B
PHP
Raw Permalink Normal View History

#!/usr/bin/php
<?php
require_once __DIR__.'/../../include/php/const';
function cyclichash_hash(){
/* [1] Fetch necessary data
=========================================================*/
/* (1) Fetch secret file */
$secret = @file_get_contents(SECRET_CONF);
/* (2) Check secret file format */
if( !is_string($secret) || !preg_match("/^(.{".SECRET_SIZE."}):(\d+):.{".SECRET_SIZE."}$/", $secret, $match) )
return 127;
/* (3) Extract data for hashing from @secret */
$key = (string) $match[1];
$depth = (int) $match[2];
/* [2] Hash data
=========================================================*/
/* (1) Initialize with data */
$hash = $key;
/* (2) Hash @depth times */
for( $d = 0 ; $d < $depth ; $d++ )
$hash = hash('sha512', $hash);
2017-01-30 09:59:52 +00:00
slog("Returning hash with $depth depth", 'cyclic-hash:hash', 'update');
return $hash;
}
echo cyclichash_hash();
?>