CFB模式加密多个数据包时IV需要改变吗?
在 Erlang crypto 库中,没有 aes_cfb_ivec
函数。这是否意味着同一个 IVec
应该用于多轮?或者应该使用最后一步的加密数据,如链接页面末尾的“CBC 模式中的 DES”示例所示?
In the Erlang crypto library, there is no aes_cfb_ivec
function. Does it mean that the same IVec
should be used for multiple rounds? Or should the encrypted data from the last step be used, as in the example of "DES in CBC mode" at the end of the linked page?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
IV不得重复使用。否则,以相同 n 字节开头的两个数据包最终也会被加密为具有相同 n 字节的流。这是一个很强的安全问题。
理想情况下,IV 应随机且均匀地选择(使用加密强度高的生成器)。但是,使用 CFB,您可以使用前一个数据包中的最后一个加密块作为 IV。如果您查看维基百科文章中的图表,您会注意到重用最后一个数据包块作为下一个数据包块的 IV 相当于将两个数据包视为一条大消息的两半,并在一次运行中加密(在这方面,这相当于 CBC 加密)。
(为了清楚起见,我正在谈论 CFB-m,其中 m 是算法块大小。在 CFB-x 中,您将块称为对于 128 位分组密码(例如 AES),每 x 位输入加密一次;CFB-128 是最有效的,因此是最常用的。)
The IV MUST NOT be reused. Otherwise, two packets beginning with the same n bytes would end up encrypted into streams with the same n bytes too. This is a strong security issue.
Ideally the IV shall be chosen randomly and uniformly (with a cryptographically strong generator). However, with CFB, you can use the last encrypted block from the previous packet as IV. If you look at the diagram in the Wikipedia article, you will notice that reusing the last packet block as IV for the next is equivalent to considering both packets to be two halves of a big message, encrypted in one run (in that respect, this is equivalent to CBC encryption).
(Just to be clear, I am talking about CFB-m where m is the algorithm block size. In CFB-x you call the block cipher once for every x bits of input; CFB-128 for a 128-bit block cipher such as the AES is the most efficient, hence the most commonly used.)