Ejemplo n.º 1
0
 function biRSAKeyPair($encryptionExponent, $decryptionExponent, $modulus)
 {
     global $biRadixBits;
     $this->e = biFromString($encryptionExponent, 16);
     $this->d = biFromString($decryptionExponent, 16);
     $this->m = biFromString($modulus, 16);
     // We can do two bytes per digit, so
     // chunkSize = 2 * (number of digits in modulus - 1).
     // Since biHighIndex returns the high index, not the number of digits, 1 has
     // already been subtracted.
     $this->chunkSize = biHighIndex($this->m);
     $this->radix = $biRadixBits;
     //12;
     $this->barrett = new biBarrettMu($this->m);
 }
Ejemplo n.º 2
0
function biPowMod($x, $y, $m)
{
    global $biRadixBase, $biRadixBits, $biBitsPerDigit, $biRadix, $biHalfRadix, $biRadixSquared, $biMaxDigitVal, $biMaxInteger, $biMaxDigits, $biZERO_ARRAY, $biBigZero, $biBigOne, $dpl10, $lr10;
    $result = $biBigOne;
    $a = $x;
    $k = $y;
    while (true) {
        if (($k->digits[0] & 1) != 0) {
            $result = biMultiplyMod($result, $a, $m);
        }
        $k = biShiftRight($k, 1);
        if ($k->digits[0] == 0 && biHighIndex($k) == 0) {
            break;
        }
        $a = biMultiplyMod($a, $a, $m);
    }
    return $result;
}
Ejemplo n.º 3
0
 function powMod($x, $y)
 {
     $result = new BigInt();
     $result->digits[0] = 1;
     $a = $x;
     $k = $y;
     while (true) {
         if (($k->digits[0] & 1) != 0) {
             $result = $this->multiplyMod($result, $a);
         }
         $k = biShiftRight($k, 1);
         if ($k->digits[0] == 0 && biHighIndex($k) == 0) {
             break;
         }
         $a = $this->multiplyMod($a, $a);
     }
     return $result;
 }