コード例 #1
0
function check_ElGRerand_correctness($pk, $sk)
{
    $group = $pk["group"];
    foreach ($group["G"] as $m) {
        if (_DEBUG >= 8) {
            echo "Checking ElGamal Enc/Dec for {$m}...";
        }
        $c = ElG_Enc($m, $pk);
        $c = ElG_Rerand($c, $pk);
        if ($m != ElG_Dec($c, $pk, $sk)) {
            if (_DEBUG >= 1) {
                echo "\nERROR : Re-randomization Error for m = {$m}\n";
            }
            return false;
        }
        if (_DEBUG >= 8) {
            echo "\n";
        }
    }
    return true;
}
コード例 #2
0
        $begin_time = microtime(true);
        ElG_Dec($ca, $pk, $sk);
        $end_time = microtime(true);
        $cumul["dec"] += 1000 * ($end_time - $begin_time);
        $cb = ElG_Enc($b, $pk);
        $begin_time = microtime(true);
        ElG_Mult($ca, $cb, $pk);
        $end_time = microtime(true);
        $cumul["mult"] += 1000 * ($end_time - $begin_time);
        $begin_time = microtime(true);
        ElG_PlainMult($ca, $b, $pk);
        $end_time = microtime(true);
        $cumul["plainmult"] += 1000 * ($end_time - $begin_time);
        $begin_time = microtime(true);
        ElG_ScalarExp($ca, $b, $pk);
        $end_time = microtime(true);
        $cumul["scexp"] += 1000 * ($end_time - $begin_time);
        $begin_time = microtime(true);
        ElG_Rerand($ca, $pk);
        $end_time = microtime(true);
        $cumul["rerand"] += 1000 * ($end_time - $begin_time);
    }
    echo "For {$limit} tests and a security of {$lambda} bits, mean ElGamal running times are:\n";
    echo "\tKeyGen: ", $cumul["keygen"] / $limit, "ms\n";
    echo "\tEnc: ", $cumul["enc"] / $limit, "ms\n";
    echo "\tDec: ", $cumul["dec"] / $limit, "ms\n";
    echo "\tMult: ", $cumul["mult"] / $limit, "ms\n";
    echo "\tPlainMult: ", $cumul["plainmult"] / $limit, "ms\n";
    echo "\tScalarExp: ", $cumul["scexp"] / $limit, "ms\n";
    echo "\tRerand: ", $cumul["rerand"] / $limit, "ms\n";
}