echo "hash of ", ivcs_transform_from(explode(" ", $result[0])), " = ", __cn_hash(sha1(ivcs_transform_from(explode(" ", $result[0])))), "<BR>";
echo "<BR>symmetry test<BR>";
echo "1st OTP from generator = ", $result[0], "<BR>";
$hex = ivcs_transform_from(explode(" ", $result[0]));
echo "Hex result from ivcs_transform_from = ", $hex, "<BR>";
$six = ivcs_transform_to($hex);
echo "Re-encoding result from ivcs_transform_to ", implode(" ", $six), "<BR>";
echo "<BR>";
echo "<BR>";
echo "Test of OTP table : <BR>";
$index = 1;
$lastHash = __cn_hash(sha1(ivcs_transform_from(explode(" ", $result[0]))));
$numfailed = 0;
$numpassed = 0;
foreach ($result as $sixword) {
    $currentHash = ivcs_transform_from(explode(" ", $sixword));
    $verifyHash = __cn_hash(sha1($currentHash));
    if (strcmp($verifyHash, $lastHash) == 0) {
        //echo "SUCCESS at ",$index, " : hash(", $sixword, ") = ",$verifyHash, ", expected ", $lastHash,"<BR>";
        $numpassed++;
    } else {
        echo "FAILURE at ", $index, " : hash(", $sixword, ") = ", $verifyHash, ", expected ", $lastHash, "<BR>";
        $numfailed++;
    }
    $lastHash = $currentHash;
    $index++;
}
echo $numfailed, " failed, ", $numpassed, " passed.";
echo "<BR><BR>";
echo "Test of valid_otp() : <BR>";
$index = 1;
Example #2
0
function ivcs_transform_array_to($otpList)
{
    if (!is_array($otpList)) {
        throw new Exception("passed list is not array!");
        return false;
    }
    $len = count($otpList);
    if ($len < 1) {
        throw new Exception("passed list is not array!");
        return false;
    }
    $sixWord = array();
    for ($i = 0; $i < $len; $i++) {
        if (null == $otpList[$i]) {
            $sixWord[$i] = null;
        } elseif (!is_string($otpList[$i])) {
            $sixWord[$i] = null;
        } elseif (strlen($otpList[$i]) < 1) {
            $sixWord[$i] = null;
        } else {
            $sixWord[$i] = implode(" ", ivcs_transform_to($otpList[$i]));
            //////////////////// invertibilty integrity check ////////////////////////////////////
            $testinverse = ivcs_transform_from(explode(" ", $sixWord[$i]));
            if (strcmp($otpList[$i], $testinverse) != 0) {
                error_log("ivcs_transform_array_to : ivcs_transform not invertible");
                error_log("ivcs_transform_array_to : original = " . $otpList[$i] . ", strlen = " . strlen($otpList[$i]));
                error_log("ivcs_transform_array_to : transform= " . $sixWord[$i]);
                error_log("ivcs_transform_array_to : inverted = " . $testinverse . ", strlen = " . strlen($testinverse));
            }
            ////////////////////////////////////////////////////////////////////////////////////
        }
    }
    return $sixWord;
}
        $failureCount++;
    }
    $ptr++;
}
echo $failureCount, "  failures, ", $successCount, " successes, out of ", $ptr, " total <BR>";
$iterations = 40;
//--TIMING ivcs_transform_from------------------------------------------------------
echo "<BR>";
echo "Timing ivcs_transform_from()<BR>";
////////////////////////////////////////////////////
$time1 = time();
$counter = 0;
for ($i = 0; $i < $iterations; $i++) {
    foreach ($converted as $codewords) {
        ///////////////////////////////////////////////////
        $result = ivcs_transform_from($codewords);
        ///////////////////////////////////////////////////
        $counter++;
    }
}
$time2 = time();
echo "elapsed time = ", $time2 - $time1, " seconds.<BR>";
echo "For {$counter} six-word code groups converted.<BR>";
//////////////////////////////////////////////////
//--TIMING ivcs_transform_to------------------------------------------------------
echo "<BR>";
echo "Timing ivcs_transform_to()<BR>";
////////////////////////////////////////////////////
$time1 = time();
$counter = 0;
for ($i = 0; $i < $iterations; $i++) {
require_once '../otp.php';
$uid = get_user_id();
$otp = $_POST['form_challenge_response'];
$login = $_POST['login'];
/* LICENSED UNDER THE GPL */
###############################################################################################
#
# if they have clicked the login button
#
###############################################################################################
if ($login) {
    // six word format test/convert
    if (!is_array($otp)) {
        $otp = explode(' ', $otp);
    }
    $cur = ivcs_transform_from($otp);
    $last = __otp_hash(sha1($cur));
    $sequence = get_otp_seq($uid);
    $match = demo_compare_last_otp($sequence, $last, $uid);
    if (!$match) {
        print "<h1>Invalid OTP</h1>";
    } else {
        // update session/auth state
        demo_set_last_otp($sequence + 1, $cur, $uid);
        //redirect to requested page
        header("Location: index.php");
        exit;
    }
} else {
}
###############################################################################################