3

Wikipedia:

CBC mode has the self-healing property: if one block of the cipher is altered, the error propagates for at most two blocks.

Made up Example:

Let the block size be 64 bits. The original plaintext is:

3231343336353837  3231343336353837  3231343336353837  • • •

The correct cipher text is:

ef7c4bb2b4ce6f3b  f6266e3a97af0e2c  746ab9a6308f4256 • • •

If the ciphertext is corrupted, with the byte '0x4b' changed to '0x4c':

ef7c4cb2b4ce6f3b  f6266e3a97af0e2c  746ab9a6308f4256  • • •

Then it is decrypted to:

efca61e19f4836f1  3231333336353837  3231343336353837  • • •

Question:

I am having hard time understanding the self-healing property of CBC (Cipher Block Chaining), I thought that a made up example might help but I am now more confused. Any help would be great.

4

2 回答 2

15

就个人而言,我发现解密图形对此类问题非常有帮助。来自维基百科(公共领域图片)

原CBC解密

现在让我们添加一些损坏:

损坏的 CBC 解密

红点代表部分损坏的输入,而红色实线代表完全块损坏。

在我们开始之前的一些符号:我将原始明文块编号为p1through p3,损坏的块编号为p1'through p3',正确的密文块编号为c1through c3,损坏的块编号为c1'through c3'

3231343336353837  3231343336353837  3231343336353837  • • •
       p1                p2                 p3

ef7c4bb2b4ce6f3b  f6266e3a97af0e2c  746ab9a6308f4256  • • •
       c1                c2                 c3

ef7c4cb2b4ce6f3b  f6266e3a97af0e2c  746ab9a6308f4256  • • •
       c1'               c2'=c3             c3'=c3

efca61e19f4836f1  3231333336353837  3231343336353837  • • •
       p1'               p2'                p3'=p3

还有一些IV你没有在你的例子中给出。

让我们看一下第一个块:块密码的输入中的三个比特被改变了(0x4b ^ 0x4c = 0x07 = 4+2+1)。由于分组密码被设计为伪随机排列 - 这是一个与随机函数无法区分的双射函数(不知道密钥k) - 我们得到一个完全(伪)随机块作为解密函数的输出:

    dec(      c1        ,k) =         p1       XOR IV
<=> dec(ef7c4bb2b4ce6f3b,k) = 3231343336353837 XOR IV
    dec(      c1'       ,k) =         p1'      XOR IV
<=> dec(ef7c4cb2b4ce6f3b,k) = efca61e19f4836f1 XOR IV

作为下一步,IV 被异或,所以我们最终得到

    dec(      c1        ,k) XOR IV =         p1       
<=> dec(ef7c4bb2b4ce6f3b,k) XOR IV = 3231343336353837 
    dec(      c1'       ,k) XOR IV =         p1'      
<=> dec(ef7c4cb2b4ce6f3b,k) XOR IV = efca61e19f4836f1 

这表明整个块被破坏(底部完整的红色块)。

现在,进入第二个块:我们从解密密文块重新开始,它工作正常,因为块中没有发生损坏:

    dec(      c2        ,k) =         p2       XOR         c1
<=> dec(f6266e3a97af0e2c,k) = 3231343336353837 XOR ef7c4bb2b4ce6f3b
                                                    ^

请注意,此公式到处都使用未损坏的块。提醒一下,这个块是在加密期间生成的:

             c2      = enc(        p2       XOR         c1      ,k)
<=> f6266e3a97af0e2c = enc(3231343336353837 XOR ef7c4bb2b4ce6f3b,k)

下一步是再次对前一个块应用 XOR(这次不是 IV,而是 c1')。先前的块 c1' 已损坏:

    dec(      c2        ,k) XOR       c1'        =         p2       XOR         c1       XOR        c1'
<=> dec(f6266e3a97af0e2c,k) XOR ef7c4cb2b4ce6f3b = 3231343336353837 XOR ef7c4bb2b4ce6f3b XOR ef7c4cb2b4ce6f3b

现在我们实际上可以计算c1 XOR c1'(误差)c1 XOR c1' = 0000007000000000并在任何地方替换它:

    dec(      c2        ,k) XOR       c1'        =         p2       XOR 0000007000000000
<=> dec(f6266e3a97af0e2c,k) XOR ef7c4cb2b4ce6f3b = 3231343336353837 XOR 0000007000000000

最后简化p2 XOR 0000007000000000 = p2'

    dec(      c2        ,k) XOR       c1'        =         p2'      
<=> dec(f6266e3a97af0e2c,k) XOR ef7c4cb2b4ce6f3b = 3231333336353837

您会看到,第一个密文块的原始损坏 ( 0x07)c1'被逐字传输到第二个明文块p2',但在其他方面保持不变(如图中大部分为白色的块所示,单个正方形为红色)。CBC 的这种特殊属性可能导致对现实世界系统的攻击,例如填充预言攻击

第三个块非常无聊:解密和 XOR 的输入没有改变,因此p1=p1'那里一切都很好。

于 2014-10-11T22:26:02.443 回答
1

When decrypting in CBC mode a block is decrypted by first deciphering the block in question using the key, and then XOR it with the previous block in the ciphertext. Take a look at the CBC mode drawing on wiki

As you only need the current and previous block for decryptin in CBC mode, the effect of a changed byte in the ciphertext, would only affect the block it's in, and the following block (if that exists).

于 2014-10-11T21:35:16.910 回答