34 lines
882 B
Plaintext
34 lines
882 B
Plaintext
|
#!/usr/bin/php
|
||
|
<?php
|
||
|
|
||
|
#define('SECRET_FILE', '/home/sats/satsd/conf/machine.secret');
|
||
|
define('SECRET_FILE', '/home/xdrm-brackets/Desktop/git.xdrm.io/logauth-sats/lib/cyclic-hash/secret');
|
||
|
define('SECRET_SIZE', 250);
|
||
|
|
||
|
|
||
|
/* [1] Fetch necessary data
|
||
|
=========================================================*/
|
||
|
/* (1) Fetch secret file */
|
||
|
$secret = @file_get_contents(SECRET_FILE);
|
||
|
|
||
|
/* (2) Check secret file format */
|
||
|
if( !is_string($secret) || !preg_match("/^(.{".SECRET_SIZE."}):(\d+)$/", $secret, $match) )
|
||
|
die(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);
|
||
|
|
||
|
echo $hash;
|
||
|
?>
|