當前位置: 首頁>>代碼示例>>PHP>>正文


PHP BigInteger::modPow方法代碼示例

本文整理匯總了PHP中phpseclib\Math\BigInteger::modPow方法的典型用法代碼示例。如果您正苦於以下問題:PHP BigInteger::modPow方法的具體用法?PHP BigInteger::modPow怎麽用?PHP BigInteger::modPow使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在phpseclib\Math\BigInteger的用法示例。


在下文中一共展示了BigInteger::modPow方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: array


//.........這裏部分代碼省略.........
             // see http://tools.ietf.org/html/rfc3526#section-3
             case 'diffie-hellman-group14-sha1':
                 $prime = 'FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74' . '020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F1437' . '4FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED' . 'EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3DC2007CB8A163BF05' . '98DA48361C55D39A69163FA8FD24CF5F83655D23DCA3AD961C62F356208552BB' . '9ED529077096966D670C354E4ABC9804F1746C08CA18217C32905E462E36CE3B' . 'E39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9DE2BCBF695581718' . '3995497CEA956AE515D2261898FA051015728E5A8AACAA68FFFFFFFFFFFFFFFF';
                 break;
         }
         // For both diffie-hellman-group1-sha1 and diffie-hellman-group14-sha1
         // the generator field element is 2 (decimal) and the hash function is sha1.
         $g = new BigInteger(2);
         $prime = new BigInteger($prime, 16);
         $exchange_hash_rfc4419 = '';
         $clientKexInitMessage = NET_SSH2_MSG_KEXDH_INIT;
         $serverKexReplyMessage = NET_SSH2_MSG_KEXDH_REPLY;
     }
     switch ($kex_algorithm) {
         case 'diffie-hellman-group-exchange-sha256':
             $kexHash = new Hash('sha256');
             break;
         default:
             $kexHash = new Hash('sha1');
     }
     /* To increase the speed of the key exchange, both client and server may
                reduce the size of their private exponents.  It should be at least
                twice as long as the key material that is generated from the shared
                secret.  For more details, see the paper by van Oorschot and Wiener
                [VAN-OORSCHOT].
     
                -- http://tools.ietf.org/html/rfc4419#section-6.2 */
     $one = new BigInteger(1);
     $keyLength = min($keyLength, $kexHash->getLength());
     $max = $one->bitwise_leftShift(16 * $keyLength);
     // 2 * 8 * $keyLength
     $max = $max->subtract($one);
     $x = $one->random($one, $max);
     $e = $g->modPow($x, $prime);
     $eBytes = $e->toBytes(true);
     $data = pack('CNa*', $clientKexInitMessage, strlen($eBytes), $eBytes);
     if (!$this->_send_binary_packet($data)) {
         user_error('Connection closed by server');
         return false;
     }
     $response = $this->_get_binary_packet();
     if ($response === false) {
         user_error('Connection closed by server');
         return false;
     }
     extract(unpack('Ctype', $this->_string_shift($response, 1)));
     if ($type != $serverKexReplyMessage) {
         user_error('Expected SSH_MSG_KEXDH_REPLY');
         return false;
     }
     $temp = unpack('Nlength', $this->_string_shift($response, 4));
     $this->server_public_host_key = $server_public_host_key = $this->_string_shift($response, $temp['length']);
     $temp = unpack('Nlength', $this->_string_shift($server_public_host_key, 4));
     $public_key_format = $this->_string_shift($server_public_host_key, $temp['length']);
     $temp = unpack('Nlength', $this->_string_shift($response, 4));
     $fBytes = $this->_string_shift($response, $temp['length']);
     $f = new BigInteger($fBytes, -256);
     $temp = unpack('Nlength', $this->_string_shift($response, 4));
     $this->signature = $this->_string_shift($response, $temp['length']);
     $temp = unpack('Nlength', $this->_string_shift($this->signature, 4));
     $this->signature_format = $this->_string_shift($this->signature, $temp['length']);
     $key = $f->modPow($x, $prime);
     $keyBytes = $key->toBytes(true);
     $this->exchange_hash = pack('Na*Na*Na*Na*Na*a*Na*Na*Na*', strlen($this->identifier), $this->identifier, strlen($this->server_identifier), $this->server_identifier, strlen($kexinit_payload_client), $kexinit_payload_client, strlen($kexinit_payload_server), $kexinit_payload_server, strlen($this->server_public_host_key), $this->server_public_host_key, $exchange_hash_rfc4419, strlen($eBytes), $eBytes, strlen($fBytes), $fBytes, strlen($keyBytes), $keyBytes);
     $this->exchange_hash = $kexHash->hash($this->exchange_hash);
     if ($this->session_id === false) {
開發者ID:edblighter,項目名稱:phpseclib,代碼行數:67,代碼來源:SSH2.php

示例2: verify

 /**
  * DSA verify.
  *
  * @param string $message            Message.
  * @param string $hash_alg           Hash algorithm.
  * @param \phpseclib\Math\BigInteger $r  r.
  * @param \phpseclib\Math\BigInteger $s  s.
  *
  * @return bool  True if verified.
  */
 public function verify($message, $hash_alg, $r, $s)
 {
     $hash = new Crypt\Hash($hash_alg);
     $hash_m = new BigInteger($hash->hash($message), 256);
     $g = new BigInteger($this->_key->key['g'], 256);
     $p = new BigInteger($this->_key->key['p'], 256);
     $q = new BigInteger($this->_key->key['q'], 256);
     $y = new BigInteger($this->_key->key['y'], 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;
 }
開發者ID:horde,項目名稱:horde,代碼行數:34,代碼來源:DSA.php

示例3: list

 /**
  * Performs RSA Blinding
  *
  * Protects against timing attacks by employing RSA Blinding.
  * Returns $x->modPow($this->exponents[$i], $this->primes[$i])
  *
  * @access private
  * @param BigInteger $x        	
  * @param BigInteger $r        	
  * @param Integer $i        	
  * @return BigInteger
  */
 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;
 }
開發者ID:HerO-0110,項目名稱:EmailAuth,代碼行數:21,代碼來源:RSA.php

示例4: decrypt

 /**
  * Decrypt data.
  *
  * @param string $text  PKCS1-v1_5 encoded text.
  *
  * @return string  Plaintext.
  */
 public function decrypt($text)
 {
     $out = '';
     $p_len = strlen($this->_key->key['p']);
     $text = str_split($text, $p_len);
     $text[count($text) - 1] = str_pad($text[count($text) - 1], $p_len, chr(0), STR_PAD_LEFT);
     $p = new BigInteger($this->_key->key['p'], 256);
     $x = new BigInteger($this->_key->key['x'], 256);
     for ($i = 0, $j = count($text); $i < $j; $i += 2) {
         $c1 = new BigInteger($text[$i], 256);
         $c2 = new BigInteger($text[$i + 1], 256);
         $s = $c1->modPow($x, $p);
         $m_prime = $s->modInverse($p)->multiply($c2)->divide($p);
         $em = str_pad($m_prime[1]->toBytes(), $p_len, chr(0), STR_PAD_LEFT);
         // EME-PKCS1-v1_5 decoding
         if (ord($em[0]) !== 0 || ord($em[1]) !== 2) {
             throw new RuntimeException();
         }
         $out .= substr($em, strpos($em, chr(0), 2) + 1);
     }
     return $out;
 }
開發者ID:horde,項目名稱:horde,代碼行數:29,代碼來源:Elgamal.php


注:本文中的phpseclib\Math\BigInteger::modPow方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。