<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>GCM - tag - 沐木</title><link>https://oldletter.cn/tags/gcm/</link><description>GCM - tag - 沐木</description><generator>Hugo -- gohugo.io</generator><language>zh-cn</language><lastBuildDate>Wed, 15 Mar 2023 00:00:00 +0000</lastBuildDate><atom:link href="https://oldletter.cn/tags/gcm/" rel="self" type="application/rss+xml"/><item><title>对称加密：AES 与 SM4 模式选择指南</title><link>https://oldletter.cn/posts/crypto-03-symmetric/</link><pubDate>Wed, 15 Mar 2023 00:00:00 +0000</pubDate><author>mumu</author><guid>https://oldletter.cn/posts/crypto-03-symmetric/</guid><description><![CDATA[<blockquote>
<p>作者：林 | 系列：密码学 | 适合读者：后端开发 / 安全工程师</p></blockquote>
<hr>
<h2 id="一对称加密基础">一、对称加密基础</h2>
<p>对称加密使用同一把密钥进行加密和解密。当前主流的两个分组密码算法：</p>
<table>
  <thead>
      <tr>
          <th>属性</th>
          <th>AES</th>
          <th>SM4</th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td>全称</td>
          <td>Advanced Encryption Standard</td>
          <td>国密分组密码算法</td>
      </tr>
      <tr>
          <td>标准</td>
          <td>NIST FIPS 197 (2001)</td>
          <td>GM/T 0002 (2012)</td>
      </tr>
      <tr>
          <td>分组长度</td>
          <td>128 bit</td>
          <td>128 bit</td>
      </tr>
      <tr>
          <td>密钥长度</td>
          <td>128 / 192 / 256 bit</td>
          <td>128 bit</td>
      </tr>
      <tr>
          <td>轮数</td>
          <td>10 / 12 / 14</td>
          <td>32</td>
      </tr>
      <tr>
          <td>结构</td>
          <td>SPN (代换-置换网络)</td>
          <td>非平衡 Feistel</td>
      </tr>
      <tr>
          <td>安全性</td>
          <td>无已知实际攻击</td>
          <td>无已知实际攻击</td>
      </tr>
  </tbody>
</table>
<p>两者安全性等价（AES-128 ≈ SM4），区别在于合规要求：信创项目用 SM4，其他场景用 AES。</p>
<hr>
<h2 id="二加密模式比算法本身更重要">二、加密模式：比算法本身更重要</h2>
<p>分组密码一次只能处理一个固定长度的数据块（16 字节）。当明文超过 16 字节时，<strong>加密模式</strong>决定了如何处理多个分组。</p>
<p>模式选错，算法再强也白搭。</p>
<h3 id="21-ecb千万别用">2.1 ECB：千万别用</h3>
<p>ECB（Electronic Codebook）每个分组独立加密：</p>]]></description></item></channel></rss>