<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/book.mcrypt.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'zh',
  ),
  'this' => 
  array (
    0 => 'mcrypt.constants.php',
    1 => '预定义常量',
    2 => '预定义常量',
  ),
  'up' => 
  array (
    0 => 'book.mcrypt.php',
    1 => 'Mcrypt',
  ),
  'prev' => 
  array (
    0 => 'mcrypt.resources.php',
    1 => '资源类型',
  ),
  'next' => 
  array (
    0 => 'mcrypt.ciphers.php',
    1 => 'Mcrypt 密码',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'zh',
    'path' => 'reference/mcrypt/constants.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="mcrypt.constants" class="appendix">
 <h1 class="title">预定义常量</h1>

 <p class="simpara">下列常量由此扩展定义，且仅在此扩展编译入 PHP 或在运行时动态载入时可用。</p>
 <p class="para">
  Mcrypt 支持以下四种分组密码模式：<code class="literal">CBC</code>，
  <code class="literal">OFB</code>，<code class="literal">CFB</code> 和
  <code class="literal">ECB</code>。
  如果使用 libmcrypt-2.4.x 或更高版本链接，
  还可以支持 <code class="literal">nOFB</code> 分组模式
  和 <code class="literal">STREAM</code> 模式。
  下列是所支持的加密模式以及其对应的预定义常量。
  完整的参考见：Applied Cryptography by Schneier (ISBN 0-471-11709-9)。
  <ul class="itemizedlist">
   <li class="listitem">
    <span class="simpara">
     <strong><code>MCRYPT_MODE_ECB</code></strong> (<code class="literal">electronic
     codebook</code>) 是一种分组加密模式，但是它无法适用于大部分场景，
     所以不建议使用这种模式进行分组加密。
    </span>
   </li>
   <li class="listitem">
    <span class="simpara">
     <strong><code>MCRYPT_MODE_CBC</code></strong> (<code class="literal">cipher block
     chaining</code>) 也是一种分组加密方式，
     相对 <code class="literal">ECB</code> 模式，它更加安全。
    </span>
   </li>
   <li class="listitem">
    <span class="simpara">
     <strong><code>MCRYPT_MODE_CFB</code></strong> (<code class="literal">8 比特模式的 cipher
     feedback</code>) 是一种流式加密模式。
     相对于 <code class="literal">CFB</code> 而言，
     推荐使用 <code class="literal">NCFB</code> 模式。
    </span>
   </li>
   <li class="listitem">
    <span class="simpara">
     <strong><code>MCRYPT_MODE_OFB</code></strong> (<code class="literal">output feedback, in
     8bit</code>) 和 <code class="literal">CFB</code> 类似，
     也是一种流式加密模式，它可以用在无法容忍加密错误传播的应用中。
     推荐使用 <code class="literal">NOFB</code> 模式，而不是 <code class="literal">OFB</code> 模式。
    </span>
   </li>
   <li class="listitem">
    <span class="simpara">
     <strong><code>MCRYPT_MODE_NOFB</code></strong> (<code class="literal">output feedback,
     in nbit</code>) 和 <code class="literal">OFB</code> 类似，但是更加安全，
     因为它可以按照算法指定的分组大小来对数据进行加密。
    </span>
   </li> 
   <li class="listitem">
    <span class="simpara">
     <strong><code>MCRYPT_MODE_STREAM</code></strong> 是一种扩展模式，
     它包含了诸如 <code class="literal">&quot;WAKE&quot;</code> 或 <code class="literal">&quot;RC4&quot;</code> 的流加密算法。
    </span>
   </li> 
  </ul>
 </p>

 <p class="para">
  Mcrypt 还支持一些尚未预定义常量的加密模式。
  可以通过传入一个字符串来使用使用未预定义常量的加密模式。
  <ul class="itemizedlist">
   <li class="listitem">
    <span class="simpara">
     <code class="literal">&quot;ctr&quot;</code> (<code class="literal">counter mode</code>) 是一种流式加密模式。
    </span>
   </li>
   <li class="listitem">
    <span class="simpara">
     <code class="literal">&quot;ncfb&quot;</code> (<code class="literal">cipher feedback,
     in n-bit mode</code>)，类似于 <code class="literal">CFB</code> 模式，
     但是它会对于算法设定的整块数据进行操作。
    </span>
   </li>
  </ul>
 </p>
 
 <p class="para">
  其他模式以及随机设备常量：
  <dl>
   
    <dt id="constant.mcrypt-encrypt">
     <strong><code><a href="mcrypt.constants.php#constant.mcrypt-encrypt">MCRYPT_ENCRYPT</a></code></strong> 
     (<span class="type"><a href="language.types.integer.php" class="type int">int</a></span>)
    </dt>
    <dd>
     <span class="simpara">
      
     </span>
    </dd>
   
   
    <dt id="constant.mcrypt-decrypt">
     <strong><code><a href="mcrypt.constants.php#constant.mcrypt-decrypt">MCRYPT_DECRYPT</a></code></strong> 
     (<span class="type"><a href="language.types.integer.php" class="type int">int</a></span>)
    </dt>
    <dd>
     <span class="simpara">
      
     </span>
    </dd>
   
   
    <dt id="constant.mcrypt-dev-random">
     <strong><code><a href="mcrypt.constants.php#constant.mcrypt-dev-random">MCRYPT_DEV_RANDOM</a></code></strong> 
     (<span class="type"><a href="language.types.integer.php" class="type int">int</a></span>)
    </dt>
    <dd>
     <span class="simpara">
      
     </span>
    </dd>
   
   
    <dt id="constant.mcrypt-dev-urandom">
     <strong><code><a href="mcrypt.constants.php#constant.mcrypt-dev-urandom">MCRYPT_DEV_URANDOM</a></code></strong> 
     (<span class="type"><a href="language.types.integer.php" class="type int">int</a></span>)
    </dt>
    <dd>
     <span class="simpara">
      
     </span>
    </dd>
   
   
    <dt id="constant.mcrypt-rand">
     <strong><code><a href="mcrypt.constants.php#constant.mcrypt-rand">MCRYPT_RAND</a></code></strong> 
     (<span class="type"><a href="language.types.integer.php" class="type int">int</a></span>)
    </dt>
    <dd>
     <span class="simpara">
      
     </span>
    </dd>
   
  </dl>
 </p>
</div>
<?php manual_footer($setup); ?>