<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>唯密文攻击 &#8211; 寂静花园</title>
	<atom:link href="https://www.addesp.com/archives/tag/%E5%94%AF%E5%AF%86%E6%96%87%E6%94%BB%E5%87%BB/feed" rel="self" type="application/rss+xml" />
	<link>https://www.addesp.com</link>
	<description>寂静中交织着热情</description>
	<lastBuildDate>Sat, 05 Jun 2021 04:18:33 +0000</lastBuildDate>
	<language>zh-Hans</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.1.2</generator>
	<item>
		<title>从零设计通信协议（二）</title>
		<link>https://www.addesp.com/archives/4528</link>
					<comments>https://www.addesp.com/archives/4528#comments</comments>
		
		<dc:creator><![CDATA[ADD-SP]]></dc:creator>
		<pubDate>Mon, 24 May 2021 13:21:42 +0000</pubDate>
				<category><![CDATA[从零设计通信协议]]></category>
		<category><![CDATA[唯密文攻击]]></category>
		<category><![CDATA[网络安全]]></category>
		<category><![CDATA[通信协议]]></category>
		<guid isPermaLink="false">https://www.addesp.com/?p=4528</guid>

					<description><![CDATA[升级协议以抵御「唯密文攻击」。]]></description>
										<content:encoded><![CDATA[
<h2 class="wp-block-heading">写在前面</h2>



<ul class="wp-block-list"><li>本系列的介绍以及协议功能见「<a href="https://www.addesp.com/archives/4463">从零设计通信协议（一）</a>」。</li><li>本系列的全部文章见「<a href="https://www.addesp.com/archives/category/%e7%ac%94%e8%ae%b0/%e4%bb%8e%e9%9b%b6%e8%ae%be%e8%ae%a1%e9%80%9a%e4%bf%a1%e5%8d%8f%e8%ae%ae">从零设计通信协议系列</a>」。</li></ul>



<h2 class="wp-block-heading">上一版协议</h2>



<p class="wp-block-paragraph">首先回顾的以下上一版的协议。</p>



<figure class="wp-block-table aligncenter is-style-regular"><table class="has-fixed-layout"><thead><tr><th class="has-text-align-center" data-align="center">1 字节</th><th class="has-text-align-center" data-align="center">X 字节</th></tr></thead><tbody><tr><td class="has-text-align-center" data-align="center">数据长度</td><td class="has-text-align-center" data-align="center">数据</td></tr></tbody></table><figcaption>数据包格式</figcaption></figure>



<p class="wp-block-paragraph">整个数据包使用 AES-128-ECB 加密。</p>



<ul class="wp-block-list"><li>数据长度：表示「数据」的长度，单位为字节。</li><li>数据：表示具体的通信数据。</li></ul>



<p class="wp-block-paragraph">我们可以通过数据包的前一个字节获取数据长度，之后向后读取 X 字节即可获取全部的数据，整个数据包使用 AES-128-ECB 加密，看起来很安全。其实使用 AES-128-ECB 加密容易受到「唯密文攻击」。</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow"><p>唯密文攻击：指在仅知道密文的情况加进行攻击，攻击成功轻则获得部分或全部明文，重则获取密钥。</p><cite><a href="https://baike.baidu.com/item/%E5%94%AF%E5%AF%86%E6%96%87%E6%94%BB%E5%87%BB" target="_blank" rel="noreferrer noopener" title="https://baike.baidu.com/item/%E5%94%AF%E5%AF%86%E6%96%87%E6%94%BB%E5%87%BB">唯密文攻击_百度百科</a></cite></blockquote>



<h2 class="wp-block-heading">ECB 模式的缺陷</h2>



<p class="wp-block-paragraph">ECB 模式的缺陷就是相同的明文会产生相同的密文，这会让攻击者有机会猜出密文的含义，难以抵抗统计分析。</p>



<p class="wp-block-paragraph">例如我和 Alice 对话，每次我发送的第一个信息是「你好」，假设使用 ECB 模式加密后的密文为「#￥%#￥」，那么如果 Eve 中间截获我的数据包，发现我和 Alice 每次通信我都会先发一个「#￥%#￥」给 Alice。根据日常的对话习惯，Eve 猜测这可能是在打招呼，进而怀疑「#￥%#￥」解密后是「你好」、「有空么」之类的话，这已经十分接近我们的明文信息了。</p>



<p class="wp-block-paragraph">上面的例子可能并不特别可怕，但是如果进行统计分析的话就难说了。</p>



<h2 class="wp-block-heading">CBC 模式</h2>



<p class="wp-block-paragraph">CBC 即密码分组链接（<strong>C</strong>ipher-<strong>B</strong>lock <strong>C</strong>haining），我们无需关心原理，只需要知道该模式通过一个随机的初始化向量 <strong>IV</strong> 保证了每条消息的唯一性，即相同的明文可以对应许多个密文。</p>



<h2 class="wp-block-heading">第二版协议</h2>



<p class="wp-block-paragraph">下面我们使用 AES-128-CBC 算法来加密我们的通讯信息，使用 CBC 模式加密不仅需要密钥，也需要一个随机的初始化向量 <strong>IV</strong>，所以我们需要将 <strong>IV</strong> 传递给对方。</p>



<figure class="wp-block-table is-style-regular"><table class="has-fixed-layout"><thead><tr><th class="has-text-align-center" data-align="center">16 字节</th><th class="has-text-align-center" data-align="center">1 字节</th><th class="has-text-align-center" data-align="center">X 字节</th></tr></thead><tbody><tr><td class="has-text-align-center" data-align="center">IV</td><td class="has-text-align-center" data-align="center">数据长度</td><td class="has-text-align-center" data-align="center">数据</td></tr></tbody></table><figcaption>数据包格式</figcaption></figure>



<p class="wp-block-paragraph"><strong>数据包从第 17 个字节开始的所有数据要使用 AES-128-CBC 加密。</strong></p>



<ul class="wp-block-list"><li>IV：AES-128-CBC 加密时所用的初始化向量。</li><li>数据长度：表示「数据」的长度，单位为字节。</li><li>数据：表示具体的通信数据。</li></ul>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow"><p>初始化向量 <strong>IV</strong> 可以公开，但要保证不可预测。</p></blockquote>



<h2 class="wp-block-heading">写在最后</h2>



<p class="wp-block-paragraph">本次我们升级了协议，使得协议可以抵御「唯密文攻击」，本系列将会持续完善这一协议。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.addesp.com/archives/4528/feed</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
			</item>
	</channel>
</rss>
