<?xml version="1.0" encoding="utf-8"?>
<rfc ipr="trust200902"
     submissionType="independent"
     category="exp"
     docName="draft-maurette-hmtftp-03">

  <front>

    <title abbrev="HMTFTP v0.3">HMTFTP: HMAC-Derived TFTP with Optional AEAD Protection (v0.3)</title>

    <author fullname="A. Maurette" initials="A." surname="Maurette">
      <organization>IUT R&amp;T Béthune</organization>
      <address>
        <postal>
          <country>France</country>
        </postal>
        <email>contact@c4tz.fr</email>
      </address>
    </author>

    <date year="2026" month="February" day="3"/>

    <area>Applications</area>

    <keyword>hmtftp</keyword>
    <keyword>tftp</keyword>
    <keyword>aead</keyword>
    <keyword>hkdf</keyword>

    <abstract>
      <t>HMTFTP is a lightweight UDP file transfer protocol derived from TFTP that adds a compact TLV mechanism and an optional AEAD protection mode for DATA payloads. Version v0.3 clarifies interoperability and extension governance rules so that independent implementations can evolve safely over time. The default UDP port is TBD1 and implementations MUST allow it to be configured.</t>
    </abstract>

    <note title="Status of This Memo">
      <t>
        This Internet-Draft is submitted in full conformance with the
        provisions of BCP 78 and BCP 79.
      </t>
      <t>
        Internet-Drafts are working documents of the Internet Engineering Task
        Force (IETF). Note that other groups may also distribute working
        documents as Internet-Drafts. The list of current Internet-Drafts is
        at https://datatracker.ietf.org/drafts/current/.
      </t>
      <t>
        Internet-Drafts are draft documents valid for a maximum of six months
        and may be updated, replaced, or obsoleted by other documents at any
        time. It is inappropriate to use Internet-Drafts as reference material
        or to cite them other than as &quot;work in progress.&quot;
      </t>
    </note>

  </front>

  <middle>

    <section title="Introduction">

      <t>
        The Trivial File Transfer Protocol (TFTP)
        <xref target="RFC1350"/>
        is
        extremely simple but provides no built-in security properties.
        HMTFTP retains the TFTP operational model (UDP, numbered blocks, ACKs)
        while introducing (1) a compact TLV extension mechanism and (2) an
        optional AEAD protection mode for DATA payloads.
      </t>

      <t>
        The name &quot;HMTFTP&quot; reflects that cryptographic keys are derived using
        HKDF, a HMAC-based key derivation function <xref target="RFC5869"/>.
        Version v0.3 introduces an explicit compatibility profile and TLV
        governance rules intended to make extensions safe and deterministic.
      </t>

    </section>

    <section title="Conventions and Terminology">

      <t>
        The key words &quot;MUST&quot;, &quot;MUST NOT&quot;, &quot;REQUIRED&quot;, &quot;SHALL&quot;, &quot;SHALL NOT&quot;,
        &quot;SHOULD&quot;, &quot;SHOULD NOT&quot;, &quot;RECOMMENDED&quot;, &quot;MAY&quot;, and &quot;OPTIONAL&quot; in this
        document are to be interpreted as described in BCP 14
        (
        <xref target="RFC2119"/>
        and
        <xref target="RFC8174"/>
        ) when, and only
        when, they appear in all capitals.
      </t>

      <t>
        This document uses the following terms:
      </t>

      <list style="symbols">
        <t><strong>PSK</strong>: pre-shared key</t>
        <t><strong>AEAD</strong>: authenticated encryption with associated data</t>
        <t><strong>AAD</strong>: additional authenticated data</t>
      </list>

    </section>

    <section title="Relationship to TFTP">

      <t>
        HMTFTP is derived from TFTP
        <xref target="RFC1350"/>
        and reuses the
        core message types and semantics (RRQ, WRQ, DATA, ACK, ERROR). It also
        reuses the concept of an explicit option acknowledgment, OACK, as
        introduced by TFTP option extension
        <xref target="RFC2347"/>.
        HMTFTP
        replaces the key/value option encoding of RFC 2347 with a TLV encoding
        defined in this document.
      </t>

      <t>
        Similar option semantics exist in TFTP, notably the blocksize option
        <xref target="RFC2348"/> and the timeout and transfer size options
        <xref target="RFC2349"/>; HMTFTP provides analogous parameters using TLVs.
      </t>

      <t>
        HMTFTP differs from baseline TFTP primarily by:
      </t>

      <list style="symbols">
        <t>using UDP port TBD1 by default (configurable), rather than 69;</t>
        <t>allowing TLV extensions in RRQ, WRQ, and OACK;</t>
        <t>supporting an optional AEAD security mode for DATA payloads.</t>
      </list>

    </section>

    <section title="Transport">

      <t>
        HMTFTP runs over UDP. The default server port is TBD1, but
        implementations MUST allow the port to be configured.
      </t>

      <t>
        Any future assignment of the default UDP port follows IANA procedures for
        service name and transport protocol port numbers
        <xref target="RFC6335"/>.
      </t>

      <t>
        As in TFTP, a transfer is conducted between a client and a server
        transfer address (IP, UDP port). The server MAY respond from a
        different UDP port than TBD1 for the remainder of the transfer, as
        described in
        <xref target="RFC1350"/>.
      </t>

    </section>

    <section title="Message Formats">

      <t>
        All multi-octet fields are encoded in network byte order (big-endian).
        HMTFTP reuses the TFTP base message formats, with TLVs appended to RRQ,
        WRQ, and OACK. TLVs are not used in DATA, ACK, or ERROR in this version.
      </t>

      <section title="RRQ and WRQ">

        <t>
          RRQ and WRQ are defined as in
          <xref target="RFC1350"/>
          :
        </t>

        <t>
          <strong>RRQ/WRQ</strong>
          = OpCode (2) || Filename (N) || 0 || Mode (M) || 0 || [TLVs]
        </t>

        <t>
          The optional TLV sequence, when present, begins immediately after the
          terminating zero octet of the Mode field and continues to the end of
          the UDP datagram. The Mode is a NUL-terminated ASCII string (e.g.,
          &quot;octet&quot;).
        </t>

      </section>

      <section title="OACK">

        <t>
          OACK is used by the server to acknowledge and/or modify the TLVs
          offered in RRQ/WRQ. OACK is defined by
          <xref target="RFC2347"/>
          as
          OpCode value 6. In HMTFTP, OACK contains only a TLV sequence:
        </t>

        <t>
          <strong>OACK</strong>
          = OpCode (2) || TLVs
        </t>

        <t>
          An OACK with an empty TLV sequence indicates acceptance with no
          negotiated parameters.
        </t>

      </section>

      <section title="DATA and ACK">

        <t>
          DATA and ACK are as defined in
          <xref target="RFC1350"/>
          :
        </t>

        <t>
          <strong>DATA</strong>
          = OpCode (2) || Block (2) || Payload (0..n)
        </t>

        <t>
          <strong>ACK</strong>
          = OpCode (2) || Block (2)
        </t>

        <t>
          When AEAD protection is negotiated (
          <xref target="security-mode"/>
          ),
          the DATA Payload is structured as: Ciphertext || Tag, where Tag is a
          16-octet AES-GCM authentication tag. The ciphertext length is the
          datagram length minus 4 octets of header and minus 16 octets of tag.
        </t>

      </section>

      <section title="ERROR">

        <t>
          ERROR is as defined in
          <xref target="RFC1350"/>
          :
        </t>

        <t>
          <strong>ERROR</strong>
          = OpCode (2) || ErrorCode (2) || ErrMsg (string) || 0
        </t>

        <t>
          HMTFTP endpoints SHOULD use an ERROR with ErrorCode 0 (&quot;Not defined&quot;)
          for extension processing failures (e.g., unsupported critical TLV).
        </t>

      </section>

    </section>

    <section title="TLV Encoding and Processing">

      <t>
        HMTFTP TLVs extend RRQ, WRQ, and OACK. TLVs use a compact binary
        encoding:
      </t>

      <texttable anchor="tlv-format-table" title="TLV Format">
        <ttcol align="left">Field</ttcol>
        <ttcol align="left">Size</ttcol>
        <ttcol align="left">Description</ttcol>

        <c>Type</c>
        <c>16 bits</c>
        <c>Type code with Critical bit in MSB</c>

        <c>Length</c>
        <c>16 bits</c>
        <c>Length of Value in octets</c>

        <c>Value</c>
        <c>variable</c>
        <c>Type-specific data</c>
      </texttable>

      <t>
        The most significant bit (MSB) of the Type field is the
        <em>Critical</em>
        bit. Bits 0-14 form the 15-bit TLV code. The Critical bit is not part
        of the code space recorded by IANA.
      </t>

      <t>
        Processing rules:
      </t>

      <list style="symbols">
        <t>A receiver MUST ignore unknown TLVs with Critical=0.</t>
        <t>
          A receiver that encounters an unknown TLV with Critical=1 MUST
          reject the message by sending an ERROR (and MUST NOT proceed with
          the transfer).
        </t>
        <t>
          A receiver MAY accept known TLVs in any order. If a TLV appears
          multiple times, a receiver SHOULD treat this as an error unless the
          TLV definition explicitly allows repetition.
        </t>
      </list>

    </section>

    <section anchor="defined-tlvs" title="Defined TLVs">
      <t>
        This specification defines the following TLVs. All multi-octet values
        are encoded in network byte order (big-endian).
      </t>

      <texttable anchor="defined-tlvs-table" title="Defined TLVs">
        <ttcol align="left">Code</ttcol>
        <ttcol align="left">Name</ttcol>
        <ttcol align="left">Length</ttcol>
        <ttcol align="left">Description</ttcol>

        <c>0x0001</c>
        <c>BLKSIZE</c>
        <c>2</c>
        <c>Requested maximum DATA payload size in octets (uint16). If offered by a client, the server MUST respond with BLKSIZE in OACK with the selected value, which MUST be less than or equal to the requested value.</c>

        <c>0x0002</c>
        <c>TIMEOUT</c>
        <c>2</c>
        <c>Requested retransmission timeout in seconds (uint16). If offered by a client, the server MUST respond with TIMEOUT in OACK with the selected value or reject the request.</c>

        <c>0x0003</c>
        <c>TSIZE</c>
        <c>8</c>
        <c>Transfer size in octets (uint64). In RRQ, a client MAY send TSIZE=0 to request that the server return the size. In WRQ, a client SHOULD send TSIZE with the size if known.</c>

        <c>0x0010</c>
        <c>ENC_REQ</c>
        <c>0</c>
        <c>Request to enable AEAD protection for DATA payloads (empty value). Clients that require security mode MUST set the Critical bit on ENC_REQ. Servers that accept security mode MUST echo ENC_REQ in OACK.</c>

        <c>0x0011</c>
        <c>CIPHER</c>
        <c>2</c>
        <c>Select ciphersuite (uint16). If omitted, the default ciphersuite is 0x0001 (AES-256-GCM).</c>

        <c>0x0012</c>
        <c>CNONCE</c>
        <c>16</c>
        <c>Client nonce (16 octets) generated by a CSPRNG. CNONCE MUST be present in RRQ/WRQ when ENC_REQ is present.</c>

        <c>0x0013</c>
        <c>SNONCE</c>
        <c>16</c>
        <c>Server nonce (16 octets) generated by a CSPRNG. SNONCE MUST be present in OACK when ENC_REQ is accepted.</c>
      </texttable>

      <t>
        The ciphersuite value 0x0001 corresponds to AEAD AES-256-GCM.
      </t>
    </section>

    <section anchor="procedure" title="Transfer Procedure">

      <t>
        HMTFTP uses the following procedure, aligned with TFTP option
        negotiation
        <xref target="RFC2347"/>
        :
      </t>

      <list style="numbers">
        <t>The client sends RRQ or WRQ, optionally with TLVs.</t>
        <t>
          If the server accepts the request and any offered parameters, it
          replies with OACK containing the negotiated TLVs (which MAY be empty).
          If the server does not support a critical TLV or rejects parameters,
          it replies with ERROR.
        </t>
        <t>
          For RRQ: the client sends ACK(0) after receiving OACK, then the server
          starts with DATA(1).
        </t>
        <t>
          For WRQ: the client starts with DATA(1) after receiving OACK, and the
          server acknowledges each block with ACK(n).
        </t>
      </list>

      <t>
        Apart from the OACK exchange, block numbering, retransmissions, and EOF
        signaling follow
        <xref target="RFC1350"/>.
      </t>

    </section>

    <section anchor="security-mode" title="Optional AEAD Security Mode">

      <t>
        Security mode is negotiated using TLVs in RRQ/WRQ and OACK. When enabled,
        each DATA payload is protected with AEAD AES-256-GCM
        <xref target="RFC5116"/>.
        The AEAD key and IV base are derived using HKDF-SHA-256
        <xref target="RFC5869"/>.
      </t>

      <section title="Negotiation TLVs">

        <t>
          The client requests security mode by including TLV ENC_REQ in RRQ/WRQ.
          When ENC_REQ is present, the client MUST include CNONCE and MAY include
          CIPHER. If the server accepts, it includes ENC_REQ and SNONCE in OACK
          and MAY include (or echo) CIPHER. If the server does not support
          security mode, it MUST reject a Critical ENC_REQ with ERROR.
        </t>

      </section>

      <section title="Key Derivation">

        <t>
          This document assumes an externally provisioned PSK (32 octets RECOMMENDED).
          During negotiation, the client and server exchange nonces:
          CNONCE and SNONCE, each 16 octets from a CSPRNG.
        </t>

        <t>
          The AEAD key material is derived as follows:
        </t>

        <list style="symbols">
          <t>IKM = PSK</t>
          <t>salt = CNONCE || SNONCE (32 octets)</t>
          <t>info = &quot;hmtftp keys v1&quot;</t>
          <t>OKM = HKDF-SHA-256(IKM, salt, info, 44)</t>
          <t>key = OKM[0..31] (32 octets)</t>
          <t>iv_base = OKM[32..43] (12 octets)</t>
        </list>

        <t>
          The HKDF &quot;info&quot; string is a protocol constant. Implementations
          MUST use the exact value &quot;hmtftp keys v1&quot; to ensure interoperability
          across document revisions.
        </t>

      </section>

      <section title="Nonce Construction and AAD">

        <t>
          The AES-GCM nonce (12 octets) for DATA block number
          <em>n</em>
          is:
        </t>

        <t>
          nonce = iv_base[0..7] || uint32(n)
        </t>

        <t>
          where uint32(n) is the 32-bit big-endian encoding of the DATA block
          number (n is the 16-bit Block field widened to 32 bits).
        </t>

        <t>
          The AEAD AAD is the 4-octet DATA header (OpCode || Block). RRQ/WRQ/OACK
          metadata and TLVs are not encrypted and are not included in the DATA
          AAD in v0.3.
        </t>

        <t>
          Retransmissions MUST retransmit the exact same ciphertext and tag for
          a given block number (key, nonce).
        </t>

      </section>

      <section title="Limits">

        <t>
          To avoid nonce reuse, endpoints MUST NOT allow the 16-bit block number
          to wrap within a security context. Implementations SHOULD terminate a
          transfer with ERROR well before wrap if it would be reached.
        </t>

      </section>

    </section>

    <section anchor="compat-governance" title="Compatibility and TLV Governance">

      <t>
        This section clarifies how HMTFTP remains interoperable with the operational
        model of TFTP while enabling extensions through TLVs.  It also specifies
        governance rules intended to keep extensions safe, deterministic, and
        implementable on constrained devices.
      </t>

      <section anchor="compat-profile" title="Compatibility Profile">

        <t>
          HMTFTP reuses the TFTP message types (RRQ, WRQ, DATA, ACK, ERROR) and the
          OACK concept from the TFTP option extension.  Implementations MUST follow
          the state machine of TFTP for block numbering, retransmissions, and EOF
          detection, except where explicitly modified by this document.
        </t>

        <t>
          When a peer does not send or accept TLVs, endpoints MUST fall back to
          baseline TFTP behavior as described in
          <xref target="RFC1350"/>
          and MUST NOT
          assume that security mode is available.  A client that requires security
          mode MUST mark ENC_REQ as Critical so that servers that do not support it
          reject the request rather than silently downgrading.
        </t>

      </section>

      <section anchor="tlv-governance" title="TLV Code Point Governance">

        <t>
          The TLV Type field is 16 bits on the wire.  The most significant bit is the
          Critical bit; the remaining 15 bits are the TLV Code.  New TLVs MUST be
          specified with clear semantics, encoding, processing rules, and
          interoperability expectations.
        </t>

        <t>
          To reduce collision risks, this document reserves the TLV Code range
          0x7F00-0x7FFF for Private Use.  Implementations MAY use Private Use TLVs
          in controlled environments, but such TLVs MUST NOT be used as inputs to
          cryptographic processing and MUST be ignored by receivers unless
          explicitly configured.
        </t>

        <t>
          Unknown TLVs with Critical=0 MUST be ignored.  Unknown TLVs with
          Critical=1 MUST cause the request to be rejected with ERROR.  This rule
          is the primary downgrade and interoperability safety mechanism for this specification.
        </t>

      </section>

    </section>

    <section title="IANA Considerations">
      <t>
        This document requests IANA actions as described in
        <xref target="RFC8126"/>.
      </t>
      <t>
        The default UDP port is indicated as TBD1; any future assignment follows
        the IANA procedures for service name and transport protocol port numbers
        <xref target="RFC6335"/>.
      </t>
      <t>
        This document also defines a TLV code point space and includes guidance
        for private use ranges; future allocation of TLV code points may require
        IANA registry actions.
      </t>
    </section>

    <section title="Security Considerations">

      <t>
        Without security mode, HMTFTP provides no confidentiality or integrity
        beyond UDP checksums and is vulnerable to on-path modification and
        spoofing, as with TFTP
        <xref target="RFC1350"/>.
      </t>

      <t>
        With security mode enabled, only DATA payloads are encrypted and
        authenticated. RRQ/WRQ/OACK metadata and TLVs remain in cleartext. This
        means filenames, modes, and negotiated parameters are observable on the
        wire. Deployments that require metadata confidentiality MUST avoid
        placing sensitive data in RRQ/WRQ/OACK and SHOULD use an external secure
        channel or a future extension that encrypts metadata.
      </t>

      <t>
        Nonce reuse with AES-GCM is catastrophic. Implementations MUST enforce
        nonce uniqueness and MUST follow the nonce construction and wrap limits
        described in
        <xref target="security-mode"/>.
      </t>

      <t>
        Implementations should also consider UDP robustness guidelines
        (
        <xref target="RFC8085"/>
        ) and rate-limiting to mitigate amplification
        and resource-exhaustion attacks.
      </t>

    </section>

    <section title="Implementation Status">

      <t>
        This section is provided for RFC 7942 compliance (
        <xref target="RFC7942"/>
        ).
        Implementations, interop notes, and known limitations will be added in
        subsequent versions.
      </t>

    </section>

  </middle>

  <back>

    <references title="Normative References">

      <reference anchor="RFC1350">
        <front>
          <title>The TFTP Protocol (Revision 2)</title>
          <author fullname="K. Sollins"/>
          <date year="1992" month="07"/>
        </front>
        <seriesInfo name="RFC" value="1350"/>
      </reference>

      <reference anchor="RFC2119">
        <front>
          <title>Key words for use in RFCs to Indicate Requirement Levels</title>
          <author fullname="S. Bradner"/>
          <date year="1997" month="03"/>
        </front>
        <seriesInfo name="BCP" value="14"/>
        <seriesInfo name="RFC" value="2119"/>
      </reference>

      <reference anchor="RFC8174">
        <front>
          <title>Ambiguity of Uppercase vs Lowercase in RFC 2119 Key Words</title>
          <author fullname="B. Leiba"/>
          <date year="2017" month="05"/>
        </front>
        <seriesInfo name="BCP" value="14"/>
        <seriesInfo name="RFC" value="8174"/>
      </reference>

      <reference anchor="RFC2347">
        <front>
          <title>TFTP Option Extension</title>
          <author fullname="G. Malkin"/>
          <date year="1998" month="05"/>
        </front>
        <seriesInfo name="RFC" value="2347"/>
      </reference>

      <reference anchor="RFC2348">
        <front>
          <title>TFTP Blocksize Option</title>
          <author fullname="G. Malkin"/>
          <date year="1998" month="05"/>
        </front>
        <seriesInfo name="RFC" value="2348"/>
      </reference>

      <reference anchor="RFC2349">
        <front>
          <title>TFTP Timeout Interval and Transfer Size Options</title>
          <author fullname="G. Malkin"/>
          <date year="1998" month="05"/>
        </front>
        <seriesInfo name="RFC" value="2349"/>
      </reference>

      <reference anchor="RFC5116">
        <front>
          <title>An Interface and Algorithms for Authenticated Encryption</title>
          <author fullname="D. McGrew"/>
          <date year="2008" month="01"/>
        </front>
        <seriesInfo name="RFC" value="5116"/>
      </reference>

      <reference anchor="RFC5869">
        <front>
          <title>HMAC-based Extract-and-Expand Key Derivation Function (HKDF)</title>
          <author fullname="H. Krawczyk"/>
          <author fullname="P. Eronen"/>
          <date year="2010" month="05"/>
        </front>
        <seriesInfo name="RFC" value="5869"/>
      </reference>

      <reference anchor="RFC6335">
        <front>
          <title>Internet Assigned Numbers Authority (IANA) Procedures for the Management of the Service Name and Transport Protocol Port Number Registry</title>
          <author fullname="M. Cotton"/>
          <author fullname="B. Leiba"/>
          <author fullname="T. Narten"/>
          <date year="2011" month="08"/>
        </front>
        <seriesInfo name="RFC" value="6335"/>
      </reference>

      <reference anchor="RFC8085">
        <front>
          <title>UDP Usage Guidelines</title>
          <author fullname="L. Eggert"/>
          <author fullname="G. Fairhurst"/>
          <author fullname="G. Shepherd"/>
          <date year="2017" month="03"/>
        </front>
        <seriesInfo name="RFC" value="8085"/>
      </reference>

      <reference anchor="RFC8126">
        <front>
          <title>Guidelines for Writing an IANA Considerations Section in RFCs</title>
          <author fullname="M. Cotton"/>
          <author fullname="B. Leiba"/>
          <author fullname="T. Narten"/>
          <date year="2017" month="06"/>
        </front>
        <seriesInfo name="BCP" value="26"/>
        <seriesInfo name="RFC" value="8126"/>
      </reference>

    </references>

    <references title="Informative References">

      <reference anchor="RFC7942">
        <front>
          <title>Improving Awareness of Running Code: The Implementation Status Section</title>
          <author fullname="C. Bormann"/>
          <date year="2016" month="07"/>
        </front>
        <seriesInfo name="RFC" value="7942"/>
      </reference>

    </references>

  </back>

</rfc>
