/** * Exponentiate with or without Chinese Remainder Theorem * * See {@link http://tools.ietf.org/html/rfc3447#section-5.1.1 RFC3447#section-5.1.2}. * * @access private * @param Math_BigInteger $x * @return Math_BigInteger */ function _exponentiate($x) { if (empty($this->primes) || empty($this->coefficients) || empty($this->exponents)) { return $x->modPow($this->exponent, $this->modulus); } $num_primes = count($this->primes); if (defined('CRYPT_RSA_DISABLE_BLINDING')) { $m_i = array(1 => $x->modPow($this->exponents[1], $this->primes[1]), 2 => $x->modPow($this->exponents[2], $this->primes[2])); $h = $m_i[1]->subtract($m_i[2]); $h = $h->multiply($this->coefficients[2]); list(, $h) = $h->divide($this->primes[1]); $m = $m_i[2]->add($h->multiply($this->primes[2])); $r = $this->primes[1]; for ($i = 3; $i <= $num_primes; $i++) { $m_i = $x->modPow($this->exponents[$i], $this->primes[$i]); $r = $r->multiply($this->primes[$i - 1]); $h = $m_i->subtract($m); $h = $h->multiply($this->coefficients[$i]); list(, $h) = $h->divide($this->primes[$i]); $m = $m->add($r->multiply($h)); } } else { $smallest = $this->primes[1]; for ($i = 2; $i <= $num_primes; $i++) { if ($smallest->compare($this->primes[$i]) > 0) { $smallest = $this->primes[$i]; } } $one = new Math_BigInteger(1); $one->setRandomGenerator('crypt_random'); $r = $one->random($one, $smallest->subtract($one)); $m_i = array(1 => $this->_blind($x, $r, 1), 2 => $this->_blind($x, $r, 2)); $h = $m_i[1]->subtract($m_i[2]); $h = $h->multiply($this->coefficients[2]); list(, $h) = $h->divide($this->primes[1]); $m = $m_i[2]->add($h->multiply($this->primes[2])); $r = $this->primes[1]; for ($i = 3; $i <= $num_primes; $i++) { $m_i = $this->_blind($x, $r, $i); $r = $r->multiply($this->primes[$i - 1]); $h = $m_i->subtract($m); $h = $h->multiply($this->coefficients[$i]); list(, $h) = $h->divide($this->primes[$i]); $m = $m->add($r->multiply($h)); } } return $m; }
/** * generation of a position, logoot algorithm * @param <Object> $start is the previous logootPosition * @param <Object> $end is the next logootPosition * @param <Integer> $N number of positions generated (should be 1 in our case) * @param <Object> $sid session id * @return <Object> a logootPosition between $start and $end */ private function getLogootPosition($start, $end, $N, $sid) { $result = array(); $Id_Max = LogootId::IdMax(); $Id_Min = LogootId::IdMin(); $i = 0; $pos = array(); $currentPosition = new LogootPosition($pos); // voir constructeur $inf = new Math_BigInteger("0"); $sup = new Math_BigInteger("0"); $isInf = false; while (true) { $inf = new Math_BigInteger($start->get($i)->getInt()); if ($isInf == true) { $sup = new Math_BigInteger(INT_MAX); } else { $sup = new Math_BigInteger($end->get($i)->getInt()); } $tmpVal = $sup->subtract($inf); $tmpVal1 = $tmpVal->subtract(new Math_BigInteger("1")); if ($tmpVal1->compare($N) > 0) { // inf = start.get(i).getInteger(); // sup = end.get(i).getInteger(); break; } $currentPosition->add($start->get($i)); $i++; if ($i == $start->size()) { $start->add($Id_Min); } if ($i == $end->size()) { $end->add($Id_Max); } if ($inf->compare($sup) < 0) { $isInf = true; } } $binf = $inf->add(new Math_BigInteger("1")); $bsup = $sup->subtract(new Math_BigInteger("1")); $slot = $bsup->subtract($binf); $stepTmp = $slot->divide($N); $step = $stepTmp[0]; // quotient, [1] is the remainder $old = clone $currentPosition; if ($step->compare(new Math_BigInteger(INT_MAX)) > 0) { $lstep = new Math_BigInteger(INT_MAX); $r = clone $currentPosition; $tmpVal2 = $inf->random($inf, $sup); $r->set($i, $tmpVal2->toString(), $sid); $result[] = $r; // result est une arraylist<Position> return $result; } else { $lstep = $step; } if ($lstep->compare(new Math_BigInteger("0")) == 0) { $lstep = new Math_BigInteger("1"); } $p = clone $currentPosition; $p->set($i, $inf->toString(), $sid); $tmpVal3 = (int) $N->toString(); for ($j = 0; $j < $tmpVal3; $j++) { $r = clone $p; if (!($lstep->compare(new Math_BigInteger("1")) == 0)) { $tmpVal4 = new Math_BigInteger($p->get($i)->getInt()); $tmpVal5 = $tmpVal4->add($lstep); // max $tmpVal6 = new Math_BigInteger($p->get($i)->getInt()); // min $add = $tmpVal6->random($tmpVal6, $tmpVal5); $r->set($i, $add->toString(), $sid); } else { $r->add1($i, new Math_BigInteger("1"), $sid); } $result[] = clone $r; // voir $old = clone $r; $tmpVal7 = new Math_BigInteger($p->get($i)->getInt()); $tmpVal7 = $tmpVal7->add($lstep); $p->set($i, $tmpVal7->toString(), $sid); } return $result; }