Ejemplo n.º 1
0
 /**
 * Performs RSA Blinding
 *
 * Protects against timing attacks by employing RSA Blinding.
 * Returns $x->modPow($this->exponents[$i], $this->primes[$i])
 *
 * @access private
 * @param MathBigInteger $x
 * @param MathBigInteger $r
 * @param Integer $i
 * @return MathBigInteger
 */
 function _blind($x, $r, $i)
 {
     $x = $x->multiply($r->modPow($this->publicExponent, $this->primes[$i]));
     $x = $x->modPow($this->exponents[$i], $this->primes[$i]);
     $r = $r->modInverse($this->primes[$i]);
     $x = $x->multiply($r);
     list(, $x) = $x->divide($this->primes[$i]);
     return $x;
 }
Ejemplo n.º 2
0
 /**
  * DSA verify
  *
  * @param string $message message
  * @param string $hash_alg hash algorithm
  * @param MathBigInteger $r r
  * @param MathBigInteger $s s
  * @param MathBigInteger $p p
  * @param MathBigInteger $q q
  * @param MathBigInteger $g g
  * @param MathBigInteger $y public key
  * @return bool
  */
 public static function verify($message, $hash_alg, $r, $s, $p, $q, $g, $y)
 {
     $hash = new CryptHash($hash_alg);
     $hash_m = new MathBigInteger($hash->hash($message), 256);
     $w = $s->modInverse($q);
     $hash_m_mul = $hash_m->multiply($w);
     $u1_base = $hash_m_mul->divide($q);
     $u1 = $u1_base[1];
     $r_mul = $r->multiply($w);
     $u2_base = $r_mul->divide($q);
     $u2 = $u2_base[1];
     $g_pow = $g->modPow($u1, $p);
     $y_pow = $y->modPow($u2, $p);
     $g_pow_mul = $g_pow->multiply($y_pow);
     $g_pow_mul_mod_base = $g_pow_mul->divide($p);
     $g_pow_mul_mod = $g_pow_mul_mod_base[1];
     $v_base = $g_pow_mul_mod->divide($q);
     $v = $v_base[1];
     return $v->compare($r) == 0;
 }