IPsec ESP AES-GCM

IPsec ESP AES-GCM

概述

第一次做IPsec还是在2009年,那个时候主要研究的都是23xx系列的RFC,这么多年过去了,IPsec又推出了一系列的算法,最近要分析IPsec-AES-GCM的封装问题,主要是其Padding大小是多少,于是又研究了一下。

参考

  1. https://www.rfc-editor.org/rfc/inline-errata/rfc4303.html
  2. https://www.rfc-editor.org/rfc/inline-errata/rfc4106.html

分析

首先在RFC4303中有一段说明:

For the purposes of ensuring that the ICV is aligned on a
4-byte boundary (second bullet above), the padding
computation applies to the Payload Data inclusive of the IV,
the Pad Length, and Next Header fields. If a combined mode
algorithm is used, any replicated data and ICV-equivalent
data are included in the Payload Data covered by the padding
computation.

也就是说,原始的明文+Padding至少是要4字节对齐。
其次在RFC4106中说了这么一段:

The IV adds an additional eight octets to the packet, and the ICV
adds an additional 8, 12, or 16 octets. These are the only sources
of packet expansion, other than the 10-13 octets taken up by the ESP
SPI, Sequence Number, Padding, Pad Length, and Next Header fields (if
the minimal amount of padding is used).

这里结合上面的4字节对齐,来看10-13字节这一句。也就是除去SPI(4字节)、Sequence Number(4字节),Pad Length(1字节),Next Header(1字节),还剩下0-3字节。

  • 如果明文正好4字节对齐,那么实际需要添加2个Pad;
  • 如果明文长度对4取模后是3字节,那么需要添加3个Pad,加上Pad Len、Next Header,凑成4字节对齐
  • 如果明文长度对4取模后是2字节,那么添加0个Pad。

因此,该算法最小添加字节数为:SPI(4)+Seq(4)+IV(8)+Pad(0)+Pad Len(1)+Next Header(1)+ICV(8)=26;
最大添加字节数为:SPI(4)+Seq(4)+IV(8)+Pad(3)+Pad Len(1)+Next Header(1)+ICV(16)=37;

注:以上不考虑TFC

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值