<?xml version="1.0" encoding="US-ASCII"?>
<!DOCTYPE rfc SYSTEM "rfc2629.dtd">
<?rfc symrefs="yes"?>
<?rfc sortrefs="yes"?>
<?rfc comments="yes"?>
<?rfc inline="yes"?>
<?rfc compact="yes"?>
<?rfc text-list-sybols="o-*+"?>
<rfc category="std" docName="draft-song-ipsecme-seq-icv-00" ipr="trust200902">
  <front>
    <title abbrev="IPsec SEQ-ICV">
      IPsec sequence number integrity check value
    </title>

    <author fullname="Jifei Song" initials="J." surname="Song">
      <organization>Huawei Technologies</organization>
      <address>
        <email>jifei.song@huawei.com</email>
      </address>
    </author>
    <author fullname="Tina Tsou" initials="T." surname="Tsou">
      <organization>Huawei Technologies</organization>
      <address>
        <postal>
          <street>2330 Central Expressway</street>
          <city>Santa Clara</city>
          <country>USA</country>
        </postal>
        <phone>+1-408-330-4424</phone>
        <email>tina.tsou.zouting@huawei.com</email>
      </address>
    </author>
    <author fullname="Vishwas Manral" initials="V." surname="Manral">
      <organization>Hewlett-Packard Company</organization>
      <address>
        <postal>
          <street>3000 Hanover St.</street>
          <city>Palo Alto</city>
          <country>USA</country>
        </postal>
        <email>vishwas.manral@hp.com</email>
      </address>
    </author>

    <date day="29" month="April" year="2013" />

    <workgroup>IPSECME Working Group</workgroup>

    <keyword>IPsec, sequence number, ICV</keyword>

    <abstract>
      <t>This document specifies an IPsec AH and ESP sequence number validation scheme, which is complementary to the existing ICV mechanism and anti-replay mechanism of AH and ESP in defense against DOS attack. It is an optional feature negotiable through IKE, for this feature to be negotiated, both sender and receiver must implement it. If any party doesn't support it, then this feature should be excluded from negotiation. The rationale for such a scheme is discussed first; then requirements and guidelines for design of the scheme are laid out. There can be various ways to implement the scheme, 
some reference designs are discussed to set the base for effort of identifying best practice and eventually establishing a standard on the subject.</t>
    </abstract>
  </front>

  <middle>
    <section title="Introduction">
      <t>As defense against replay attack, IPsec, both AH and ESP, uses anti-replay window to keep track of the sequence numbers of received packets, and reject packets with sequence number that is either too old (below anti-replay window) or duplicate (within anti-replay window, but marked as received).
Anti-replay window is not effective against DOS attack by packets with sequence number that are above anti-replay window, in which case the sequence number is neither considered too old, nor duplicate. Attack packets with sequence number above anti-replay window would penetrate anti-replay check and only be rejected after failing ICV check. The issue is that ICV check, which involves hashing operation, is rather expensive in terms of resource and time consumption. In case of ESP, when hardware crypto acceleration engine is used, ICV check and decryption often need to be performed together to optimize bandwidth efficiency, which makes the operation even more expensive. Large number of such packets would cause recevier's service degradation or interruption because significant amount of receiver's resource and time would be consumed by performing expensive ICV check on these packets.</t>

      <t>An inexpensive mechanism to check sequence number would allow rejecting such packets without causing service degradation or interruption. This check can be performed either before or after anti-replay check depending on policy and situation, but must be performed before ICV check. Such check doesn't have to be 100% accurate as long as it doesn't yield false positive result, i.e. mistaking correct sequence number as incorrect sequence number, since the packet with false negative result, i.e. incorrect sequence number passing the check, will be caught by ICV check eventually. But it must be significantly more resource and time efficient than ICV check to be beneficial.</t>

      <t>This check will increase packet length slightly, and incur slight computation overhead per packet, but greatly improve IPsec's capability to withstand DOS attack. This check would not be effective if attacker can prevent original packets from reaching destination, since in such case the attacker doesn't need to change sequence number, instead he or she can change payload, then the packet would pass both anti-replay check and this proposed sequence number check. But in order to shoot down original packets, attacker must compromise intermediate router. The proposed sequence number check is not designed to defend against attacks that involves compromised intermediate router, instead it is designed against attacks where attacker does not control intermediate router, but is able to obtain copy of original packets and launch attack by changing sequence number of the original packets to values that are greater so that anti-replay check would pass and ICV check is required. The latter is simpler attack and easier to carry out therefore is a more serious threat.</t>

      <t>This check is not designed for systems that are capable of line rate ICV check; instead it is designed for systems that are not capable of line rate ICV check. This check makes it possible for systems that are not capable of line rate ICV check to continue with normal function when under attacks, as long as the original packets are still being delivered, or in another words, as long as the network in between is not compromised. Systems that are capable of line rate ICV check should decline SEQ-ICV in negotiation.
      </t>

      <t>The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL
      NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and
      "OPTIONAL" in this document are to be interpreted as described
      in <xref target="RFC2119">RFC 2119</xref>.</t>
    </section>

    <section title="SEQ-ICV">
      <t>A value generated by sender for each IPsec packet based on packet sequence number and some secret known and only known to sender and receiver. The value is transmitted together with the packet to receiver, which generates its own value locally 
the same way as sender, then compares with the transmitted value. If the value is the same, then the sequence number is considered to be good, otherwise the sequence number is considered to be bad.</t>

      <t></t>

      <t>
      <list style="numbers">
	<t></t>
        <t></t>
      </list>
      </t>
    </section>
    <section title="SEQ-ICV type">
      <t>SEQ-ICV type is defined by its length and how it is transmitted. SEQ-ICV can be arbitrary number of bytes long and transmitted in band or out of band. Ease of generation and transmission should be the major factors in choosing SEQ-ICV type. Following are some recommended SEQ-ICV types, a solution can pick and choose to support one or more of them. For each type, different algorithms can be used to generate SEQ-ICV. SEQ-ICV type and generation algorithm should be negotiated through IKE. An algorithm to generate SEQ-ICV-4 is defined in Appendix A.</t>
       <t>
      <list style="numbers">
	<t>SEQ-ICV-1 : 1 byte is generated and embedded anywhere after AH/ESP header</t>
        <t>SEQ-ICV-2 : 2 bytes are generated and embedded anywhere after AH/ESP header</t>
<t>SEQ-ICV-3 : 3 bytes are generated and embedded anywhere after AH/ESP header</t>
        <t>SEQ-ICV-4 : 4 bytes are generated and embedded anywhere after AH/ESP header</t>
<t>SEQ-ICV-1-1 : 2 bytes are generated and embedded as two 1 byte separately anywhere after AH/ESP header</t>
        <t>SEQ-ICV-1-2 : 3 bytes are generated and embedded as an 1 byte and a 2 byte separately anywhere after AH/ESP header</t>
<t>SEQ-ICV-1-1-1 : 3 bytes are generated and embedded as three 1 byte separately anywhere after AH/ESP header</t>
        <t>SEQ-ICV-1-3 : 4 bytes are generated and embedded as an 1 byte and a three byte separately anywhere after AH/ESP header</t>
<t>SEQ-ICV-2-2 : 4 bytes are generated and embedded as two 2 byte separately anywhere after AH/ESP header</t>
<t>SEQ-ICV-1-1-2 : 4 bytes are generated and embedded as two 1 byte and one 2 byte separately anywhere after AH/ESP header</t>
<t>SEQ-ICV-1-1-1-1 : 4 bytes are generated and embedded as four 1 byte separately anywhere after AH/ESP header</t>
      </list>
      </t>
    </section>

    <section title="SEQ generation rules">
      <t></t>

      <t></t>

      <t>
      <list style="numbers">
	<t>part or whole of sequence number must be used</t>
        <t>must be significantly more memory and time efficient than whole packet ICV check</t>
      </list>
      </t>
    </section>
    <section title="SEQ SEQ-ICV transmission rules">
      <t></t>

      <t></t>

      <t>
      <list style="numbers">
	<t>can be embedded anywhere after AH/ESP header</t>
        <t>can be embedded as whole, or pieces</t>
      </list>
      </t>
    </section>
    <section title="SEQ-ICV retrieval and check rules">
      <t></t>

      <t></t>

      <t>
      <list style="numbers">
	<t>must be checked before ICV check</t>
        <t>can be checked either before or after anti-replay check if enabled</t>
      </list>
      </t>
    </section>
    <section title="Relation to IKE">
      <t>Like authentication and encryption, type of SEQ-ICV and algorithm used to generate/transmit SEQ-ICV should all be negotiable through IKE. Following information should be negotiated as part of SA,</t>
     <t>
      <list style="numbers">
	<t>whether SEQ-ICV is supported</t>
        <t>operation mode of SEQ-ICV : static - SEQ-ICV is always enabled; dynamic - SEQ-ICV is enabled and disabled dynamically by receiver based on whether it is under attack
</t>
	<t>type of SEQ-ICV chosen</t>
	<t>algorithm for SEQ-ICV generation and transmission</t>
	<t>key, if needed, for SEQ-ICV generation</t>
      </list>
      </t>
    </section>
    <section title="Outbound processing">
      <t>AH transport/tunnel mode</t>
        <t>
     <list style="numbers">
	<t>generate ICV</t>
        <t>generate SEQ-ICV</t>
	<t>embed SEQ-ICV</t>
	<t>adjust packet length in IP header</t>
      </list>
	</t>
<t>Packet length field can only be adjusted after generating ICV, which must be based on the packet length without SEQ-ICV</t>

      <t>ESP transport/tunnel mode</t>
        <t>
     <list style="numbers">
	<t>encrypt packet payload</t>
        <t>generate ICV</t>
	<t>generate SEQ-ICV</t>
	<t>embed SEQ-ICV</t>
      </list>
	</t>

      <t></t>
    </section>
    <section title="Inbound processing">
      <t>AH transport/tunnel mode</t>
         <t>
     <list style="numbers">
	<t>reject if failed anti-replay check</t>
        <t>generate SEQ-ICV</t>
	<t>retrieve, in reverse order if consists of multiple parts, transmitted SEQ-ICV</t>
	<t>Compare locally generated SEQ-ICV with transmitted SEQ-ICV</t>
	<t>Reject packet if not same, otherwise adjust packet length field of IP header proceed to AH processing</t>
      </list>
	</t>
<t>Packet length field must be adjusted before AH processing</t>     <t>ESP transport/tunnel mode</t>
        <t>
     <list style="numbers">
	<t>reject if failed anti-replay check</t>
        <t>generate SEQ-ICV</t>
	<t>retrieve, in reverse order if consists of multiple parts, transmitted SEQ-ICV</t>
	<t>Compare locally generated SEQ-ICV with transmitted SEQ-ICV</t>
	<t>Reject packet if not same, otherwise proceed to ESP processing</t>
      </list>
	</t>
 <t>In calculating ESP payload length, SEQ-ICV must be excluded.</t>          
<t>Enable SEQ-ICV dynamically</t>
<t>If too many packets passed anti-replay but failed ICV check, then notify sender to enable SEQ-ICV, and receiver begins SEQ-ICV check but would not reject packets that failed SEQ-ICV check, 
once receiver no longer observes packets passing ICV check but failing SEQ-ICV check, then receiver considers SEQ-ICV has been enabled, and begins to reject packet that failed SEQ-ICV check.</t>
<t>Disable SEQ-ICV dynamically</t>
<t>If no packets passed anti-replay but failed SEQ-ICV, then notify sender to disable SEQ-ICV, and receiver stops rejecting packets that failed SEQ-ICV check,
once receiver no longer observes packets passing both SEQ-ICV and ICV check, but only packets passing ICV check, then receiver considers SEQ-ICV has been disabled, and stops checking SEQ-ICV </t>
<t>Following is summary of conditions that could occur throughout the whole process of dynamically enabling and disabling SEQ-ICV with assumption that original packets are delivered,</t>
<figure><artwork>
--------------------------------------------------------------
| id |condition | packet |anti-replay|seq-icv| icv  | action |
|----|----------|--------|-----------|-------|------|--------|
|    | normal,  |original| pass      | skip  | pass | accept |
| 1  | seq-icv  |        |           |       |      |        |
|    | disabled |        |           |       |      |        |
|----|----------|--------|-----------|-------|------|--------|
|    | under    |original| pass      | skip  | pass | accept |
|    | attack,  |        |           |       |      |        |
|    | seq-icv  |        |           |       |      |        |
|    | disabled |        |           |       |      |        |
| 2  |----------|--------|-----------|-------|------|--------|
|    |under     | with   | pass	     | skip  | fail | reject |
|    |attack,   | fake   |           |       |      |        |
|    |seq-icv   | seq    |           |       |      |        |
|    |disabled  |        |           |       |      |        |
|----|----------|--------|-----------|-------|------|--------|
|    | under    |original| pass	     |  fail | pass | accept |
|    | attack,  |        |           |	     |      |        |
|    | enabling |        |           |       |      |        |
|    | seq-icv  |        |           |       |      |        |
| 3  |----------|--------|-----------|-------|------|--------|
|    | under    | with   | pass      |  fail | fail | reject |
|    | attack,  | fake   |           |	     |      |        |
|    | enabling | seq    |           |       |      |        |
|    | seq-icv  |        |           |       |      |        |
|----|----------|--------|-----------|-------|------|--------|
|    | under    |original| pass      |  pass | pass | accept |
|    | attack,  |        |           |	     |	    |        |
|    | enabling |        |           |       |      |        |
|    | seq-icv  |        |           |       |      |        |
|    | ready    |        |           |       |      |        |
| 4  |----------|--------|-----------|-------|------|--------|
|    | under    | with   | pass      | fail  | fail | reject |
|    | attack,  | fake   |           |       |      |        |
|    | enabling | seq    |           |       |      |        |
|    | seq-icv  |        |           |       |      |        |
|    | ready    |        |           |       |      |        |
|----|----------|--------|-----------|-------|------|--------|
|    | under    |original| pass      |  pass | pass | accept |
|    | attack,  |        |           |       |      |        |
|    | seq-icv  |        |           |       |      |        |
|    | enabled  |        |           |       |      |        |
| 5  |----------|--------|-----------|-------|------|--------|
|    | under    | with   | pass      |  fail | skip | reject |
|    | attack,  | fake   |           |       |      |        |
|    | seq-icv  | seq    |           |       |      |        |
|    | enabled  |        |           |       |      |        |
|----|----------|--------|-----------|-------|------|--------|
|    | normal,  |original| pass      |  pass | pass | accept |
| 6  | seq-icv  |        |           |       |      |        |
|    | enabled  |        |           |       |      |        |
|----|----------|--------|-----------|-------|------|--------|
|    | normal,  |original| pass      |  fail | pass | accept |
| 7  | disabling|        |           |       |      |        |
|    | seq-icv  |        |           |       |      |        |
--------------------------------------------------------------
</artwork></figure>
<t> </t>
<t> </t>
<t>1 - normal, seq-icv disabled</t>
<t>2 - under attack, seq-icv disabled</t>
<t>3 - under attack, enabling seq-icv</t>
<t>4 - under attack, enabling seq-icv ready</t>
<t>5 - under attack, seq-icv enabled</t>
<t>6 - normal, seq-icv enabled</t>
<t>7 - normal, disabling seq-icv</t>
<t> </t>
<t> </t>
<t> </t>
<t>SEQ-ICV enabling process is 1 through 5</t>
<t>SEQ-ICV disabling process is 6 -> 7 -> 1</t>
    </section>
    <section title="Appendix A : An Algorithm for SEQ-ICV-4 generation and transmission">
        <t>
     <list style="numbers">
	<t>SEQ is sequence number</t>
	<t>AK is authentication key</t>
	<t>CIPHER is the encrypted payload</t>
        <t>SEQ-ICV-4 is generated as follows : 
	SEQ-ICV-4[n]  =  (AK[n] + CIPHER[n])  ^  (AK[n+4] + SEQ[n]),    0 &lt;= n &lt;= 3
	   </t>
        <t>Location of SEQ-ICV-4 is derived as follows :
	offset-in-encrypted-payload  =  max(SEQ-ICV-4  %  payload-length , 4)	   </t>
	<t>Increase Packet length of IP header by 4 to account for SEQ-ICV-4</t>
      </list>
</t>
    </section>

    <section anchor="IANA" title="IANA Considerations">
      <t>This document makes no request of IANA.</t>

      <t>Note to RFC Editor: this section may be removed on
      publication as an RFC.</t>
    </section>

    <section anchor="Security" title="Security Considerations">
      <t>
      </t>
      <t>
      </t>
      <t>
      </t>
      
      <t>
      <list style="symbols">
        <t></t>
        <t></t>
      </list>
      </t>

      <t>
      </t>
    </section>

    <section title="Acknowledgments">
      <t>Robert Moskowitz reminded us of importance of grammatical integrity.</t>
      <t>Tero Kivinen pointed out issue with original sample SEQ-ICV-4 generation algorithm and provided insightful feedback on issues like compatibility with existing standard and usage scenario of SEQ-ICV.</t>
    </section>
  </middle>

  <back>
    <references title="Normative References">
      <?rfc include="reference.RFC.2119"?>
      <?rfc include="reference.RFC.4301"?>
      <?rfc include="reference.RFC.4302"?>
      <?rfc include="reference.RFC.4303"?>
    </references>

    <references title="Informative References">
      <?rfc include="reference.RFC.5996"?>
    </references>

    <section anchor="encap" title="Encapsulation Mode">
      <t>
      </t>

      <t></t>
    </section>

    <section title="Justification">
      <t>
      <list style="symbols">
        <t>
        </t>
        <t></t>
      </list>
     </t>

     <t></t>
    </section>
   </back>
</rfc>
