function check_ElGPlainMult_correctness($pk, $sk)
{
    $group = $pk["group"];
    foreach ($group["G"] as $m) {
        foreach ($group["G"] as $plain) {
            if (_DEBUG >= 8) {
                echo "Checking ElGamal plain mult for {$m} and {$plain}...";
            }
            $c = ElG_Enc($m, $pk);
            $cmult = ElG_PlainMult($c, $plain, $pk);
            if (modular_mult($m, $plain, $group["modulo"]) != ElG_Dec($cmult, $pk, $sk)) {
                if (_DEBUG >= 1) {
                    echo "\nERROR : ElGamal homomorphic plain multiplication error for m = {$m} and plain = {$plain}\n";
                }
                return false;
            }
            if (_DEBUG >= 8) {
                echo "\n";
            }
        }
    }
    return true;
}
Пример #2
0
 //Note: now P takes the place of V, so V = P in the following
 $src_V = $src_P;
 //Simulation of the threshold homomorphic part of the protocol
 do {
     $r_tmp = $group["G"][array_rand($group["G"])];
 } while (gcd($r_tmp, $group["modulo"] - 1) != 1);
 $trap = $r_tmp * $dst_D;
 //Done by V (key generation is considered as done offline, prior to network setup)
 $keys_V = ElG_KeyGen_alt($r, $q);
 if ($keys_V == false) {
     echo "Error: Key Generation failed for V with lambda = {$lambda} and r = {$r}...\n";
     exit;
 }
 list($pk_V, $sk_V) = array_values($keys_V);
 $time_aux = microtime(true);
 $gpowdstDrtmpsrcV = modular_exp($group["gen"], modular_mult($trap, $src_V, $group["modulo"] - 1), $group["modulo"]);
 $cgpowdstDrtmpsrcV = ElG_Enc($gpowdstDrtmpsrcV, $pk_V);
 //Done by S
 $inv_rtmp_pmin1 = modular_inverse($r_tmp, $group["modulo"] - 1);
 $cgpowdstDsrcV = ElG_ScalarExp($cgpowdstDrtmpsrcV, $inv_rtmp_pmin1, $pk_V);
 $cLocalID_DV = ElG_PlainMult($cgpowdstDsrcV, $ID_D, $pk_V);
 $cLocalID_DV = ElG_Rerand($cLocalID_DV, $pk_V);
 //Done by V
 $LocalID_DV = ElG_Dec($cLocalID_DV, $pk_V, $sk_V);
 $total_time_init_route += microtime(true) - $time_aux;
 //Because V = P, we should have that the LocalID_DV found be equal to LocalID_DP_theoretic from above
 if ($LocalID_DV != $LocalID_DP_theoretic) {
     echo "Error in route initialization: for q = {$q}, p = ", $group["modulo"], ", ID_D = {$ID_D}, s_D = {$dst_D}, k_V = {$src_V}, r_tmp = {$r_tmp}, we have {$LocalID_DV} != {$LocalID_DP_theoretic}\n";
     exit;
 } elseif ($echo_when_OK) {
     echo "Route initialization test #{$i} OK: for q = {$q}, p = ", $group["modulo"], ", ID_D = {$ID_D}, s_D = {$dst_D}, k_V = {$src_V}, r_tmp = {$r_tmp},we have {$LocalID_DV} = {$LocalID_DP_theoretic}\n";