当前位置: 首页>>代码示例>>PHP>>正文


PHP BigInteger::random方法代码示例

本文整理汇总了PHP中phpseclib\Math\BigInteger::random方法的典型用法代码示例。如果您正苦于以下问题:PHP BigInteger::random方法的具体用法?PHP BigInteger::random怎么用?PHP BigInteger::random使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在phpseclib\Math\BigInteger的用法示例。


在下文中一共展示了BigInteger::random方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: count

 /**
  * 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 BigInteger $x        	
  * @return 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 BigInteger(1);
         $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;
 }
开发者ID:HerO-0110,项目名称:EmailAuth,代码行数:56,代码来源:RSA.php

示例2: array


//.........这里部分代码省略.........
                     break;
                     // see http://tools.ietf.org/html/rfc3526#section-3
                 // 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);
             $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($kexHash->getLength(), max($encryptKeyLength, $decryptKeyLength));
         $max = $one->bitwise_leftShift(16 * $keyLength);
         // 2 * 8 * $keyLength
         $max = $max->subtract($one);
         $x = BigInteger::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)) {
         throw new \RuntimeException('Connection closed by server');
     }
     $response = $this->_get_binary_packet();
     if ($response === false) {
         throw new \RuntimeException('Connection closed by server');
     }
     extract(unpack('Ctype', $this->_string_shift($response, 1)));
     if ($type != $serverKexReplyMessage) {
         throw new \UnexpectedValueException('Expected SSH_MSG_KEXDH_REPLY');
     }
     $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']);
     $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']);
     if ($kex_algorithm === 'curve25519-sha256@libssh.org') {
         if (strlen($fBytes) !== 32) {
             user_error('Received curve25519 public key of invalid length.');
             return false;
         }
         $key = new BigInteger(\Sodium\crypto_scalarmult($x, $fBytes), 256);
         \Sodium\memzero($x);
开发者ID:paragonie-scott,项目名称:phpseclib,代码行数:67,代码来源:SSH2.php


注:本文中的phpseclib\Math\BigInteger::random方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。