<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE rfc [
<!ENTITY RFC2119 PUBLIC '' "http://xml.resource.org/public/rfc/bibxml/reference.RFC.2119.xml">
<!ENTITY RFC3629 PUBLIC '' "http://xml.resource.org/public/rfc/bibxml/reference.RFC.3629.xml">
<!ENTITY RFC7049 PUBLIC '' "http://xml.resource.org/public/rfc/bibxml/reference.RFC.7049.xml">
<!ENTITY RFC8174 PUBLIC '' "http://xml.resource.org/public/rfc/bibxml/reference.RFC.8174.xml">
<!ENTITY RFC8610 PUBLIC '' "http://xml.resource.org/public/rfc/bibxml/reference.RFC.8610.xml">
<!ENTITY RFC8742 PUBLIC '' "http://xml.resource.org/public/rfc/bibxml/reference.RFC.8742.xml">
<!ENTITY RFC8949 PUBLIC '' "http://xml.resource.org/public/rfc/bibxml/reference.RFC.8949.xml">
<!ENTITY RFC9498 PUBLIC '' "http://xml.resource.org/public/rfc/bibxml/reference.RFC.9498.xml">
]>
<?xml-stylesheet type='text/xsl' href='rfc2629.xslt' ?>
<?rfc strict="yes" ?>
<?rfc toc="yes" ?>
<?rfc symrefs="yes"?>
<?rfc sortrefs="yes" ?>
<?rfc compact="yes" ?>
<?rfc subcompact="no" ?>
<rfc xmlns:xi="http://www.w3.org/2001/XInclude"
     category="info"
     docName="draft-gnunet-cbor-00"
     ipr="trust200902"
     obsoletes="" updates=""
     submissionType="independent"
     xml:lang="en"
     version="3">
  <front>
    <title abbrev="GNUnet CBOR Profile">
      The GNUnet CBOR Profile
    </title>
    <seriesInfo name="Internet-Draft" value="draft-gnunet-cbor-00"/>
    <author fullname="Christian Grothoff" initials="C." surname="Grothoff">
      <organization>Berner Fachhochschule</organization>
      <address>
       <postal>
        <street>Hoeheweg 80</street>
        <city>Biel/Bienne</city>
        <code>2501</code>
        <country>CH</country>
       </postal>
       <email>grothoff@gnunet.org</email>
      </address>
     </author>
    <!-- Meta-data Declarations -->
    <area>General</area>
    <workgroup>Independent Stream</workgroup>
    <keyword>peer-to-peer</keyword>
    <keyword>CBOR</keyword>
    <keyword>deterministic encoding</keyword>
    <abstract>
      <t>
        This document specifies the profile of CBOR in which GNUnet encodes
        the bodies of its peer-to-peer messages and the objects they carry,
        such as the HELLO.  The profile is a strict subset of the
        deterministic encoding of RFC 8949: receivers reject every other
        encoding, so that every value has exactly one valid encoding and
        independent implementations accept and reject the same messages.
        It also fixes conventions that the specifications of GNUnet
        messages share: positional arrays and extensible maps whose keys
        say whether a receiver may ignore them, fixed-size byte strings,
        typed keys, times, and the relation between the encoding and the
        data that GNUnet signs and hashes.
      </t>
      <t>
        This specification was developed outside the IETF and does not have
        IETF consensus.  It is published here to inform readers about the
        encoding of GNUnet messages, guide future implementations, and
        ensure interoperability among implementations.
      </t>
    </abstract>
  </front>
  <middle>
    <section anchor="introduction" numbered="true" toc="default">
      <name>Introduction</name>
      <t>
        A GNUnet message is a short header, which gives the size and the
        type of the message, followed by a body.  The bodies of GNUnet's
        peer-to-peer messages used to be packed C structures, with
        hand-written code for every variable-length part.  GNUnet moves
        the bodies of its peer-to-peer control messages to CBOR
        <xref target="RFC8949"/> in one clean break, starting with the
        HELLO <xref target="LSD0018"/>, so that each protocol breaks only
        once.
      </t>
      <t>
        CBOR permits several encodings of one value: integers and lengths
        in longer forms than necessary, items of indefinite length, and map
        keys in any order.  Most CBOR libraries accept all of them by
        default.  In a peer-to-peer network with more than one
        implementation, an encoding that one implementation accepts and
        another rejects splits the network: in a distributed hash table,
        some peers store and forward such an item and others drop it.
        Where a hash of an item serves as its identity, a second encoding
        of the same value is a second identity.  Each specification could
        state its own rules against this, but rules restated in every
        document drift apart.  This document states them once.
      </t>
      <t>
        The profile is a strict subset of the core deterministic encoding of
        <xref target="RFC8949" section="4.2.1"/>, which encoders produce and
        receivers enforce (<xref target="rules"/>).  It adds conventions
        for the structures that GNUnet messages share
        (<xref target="conventions"/>), places the encoded items in
        GNUnet's message framing (<xref target="framing"/>), and states how
        they relate to the data that GNUnet signs and hashes
        (<xref target="signatures"/>).  <xref target="using"/> lists what a
        specification that uses the profile must state.
      </t>
      <t>
        The profile does not apply to formats that another specification
        fixes, such as the record sets and blocks of the GNU Name System
        <xref target="RFC9498"/> and the content blocks of file-sharing, to
        the headers of data-plane messages, to the obfuscated outer layer
        of the communicators (<xref target="obfuscation"/>), or to the data
        that GNUnet signs, which remains a packed structure
        (<xref target="signatures"/>).
      </t>
      <t>
        This specification was developed outside the IETF and does not have
        IETF consensus.  It is published here to guide implementers of
        GNUnet and to ensure interoperability among implementations.
      </t>
      <section numbered="true" toc="default">
        <name>Requirements Notation</name>
        <t>
          The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT",
          "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and
          "OPTIONAL" in this document are to be interpreted as described in
          BCP 14 <xref target="RFC2119"/> <xref target="RFC8174"/> when, and only
          when, they appear in all capitals, as shown here.
        </t>
      </section>
    </section>
    <section anchor="terminology" numbered="true" toc="default">
      <name>Terminology</name>
      <dl>
        <dt>CBOR, item, well-formed, valid:</dt>
        <dd>
          As in <xref target="RFC8949"/>.  "The encoding of X" is the byte
          string that represents the item X under the rules of
          <xref target="rules"/>.
        </dd>
        <dt>CDDL:</dt>
        <dd>
          The Concise Data Definition Language <xref target="RFC8610"/>.
        </dd>
        <dt>Specification:</dt>
        <dd>
          A document that defines items encoded under this profile, such as
          <xref target="LSD0018"/>.
        </dd>
        <dt>Container:</dt>
        <dd>
          The byte string from which an item is decoded: a message body, a
          DHT block, a byte string inside another item, or a decoded URL
          parameter.
        </dd>
        <dt>Depth:</dt>
        <dd>
          The nesting depth of an item.  An item that is not inside an
          array or a map has depth 1; an item inside an array or a map has
          the depth of that array or map plus 1.
        </dd>
        <dt>Critical, optional:</dt>
        <dd>
          Properties of the keys of an extensible map
          (<xref target="maps"/>): a receiver that does not know a critical
          key rejects the item, and one that does not know an optional key
          ignores its entry.
        </dd>
        <dt>Absolute time:</dt>
        <dd>
          An unsigned integer counting microseconds since midnight (0 hour),
          January 1, 1970 UTC.
        </dd>
        <dt>NBO:</dt>
        <dd>Network byte order (big endian).</dd>
      </dl>
    </section>
    <section anchor="rules" numbered="true" toc="default">
      <name>Encoding Rules</name>
      <t>
        An item encoded under this profile <bcp14>MUST</bcp14> satisfy the
        following rules, and a receiver <bcp14>MUST</bcp14> reject an item
        that violates any of them.  Specifications refer to them by number.
      </t>
      <ol>
        <li>
          <strong>Deterministic encoding.</strong>  The core deterministic
          encoding requirements of <xref target="RFC8949" section="4.2.1"/>
          apply: integers, lengths and counts use the shortest form, all
          items have definite length, the keys of a map are sorted in the
          bytewise lexicographic order of their encodings, and no map has
          duplicate keys.
        </li>
        <li>
          <strong>Restricted data model.</strong>  Only unsigned and
          negative integers, byte strings, text strings, arrays, maps,
          false, true and null are allowed.  Tags (among them bignums and
          the self-described CBOR tag), floating-point values, undefined and
          all other simple values are not.
        </li>
        <li>
          <strong>Map keys</strong> are unsigned integers.
        </li>
        <li>
          <strong>Text strings</strong> are valid UTF-8
          <xref target="RFC3629"/> and do not contain U+0000.
        </li>
        <li>
          <strong>Nesting depth.</strong>  Every specification states the
          maximum depth of the items it defines, at most 16.  A receiver
          rejects an item that exceeds it, before it decodes the deeper
          item.
        </li>
        <li>
          <strong>Nothing follows the item.</strong>  An item is the whole
          content of its container.  Bytes after it are an error, except the
          padding of <xref target="padding"/>.
        </li>
      </ol>
      <t>
        These rules leave exactly one valid encoding for every value.  An
        item decoded from a byte string inside another item, such as a
        nested message (<xref target="nesting"/>), is an item of its own:
        its depth is counted from 1, and the rules apply to it again.
      </t>
      <t>
        Rule 3 also settles an ambiguity.  The "canonical" order of map
        keys of <xref target="RFC7049" section="3.9"/>, which
        <xref target="RFC8949" section="4.2.3"/> keeps as "length-first"
        ordering, sorts shorter encodings first, whereas rule 1 sorts
        bytewise.  The two orders differ for some keys, for example for a
        negative integer and an unsigned integer of more than 23.  For
        unsigned integers in their shortest form, both orders are the
        numeric order of the keys, so an implementation that uses the older
        definition sorts them correctly as well.
      </t>
      <t>
        The profile is a subset of the core deterministic encoding of
        <xref target="RFC8949" section="4.2.1"/>.  Since it excludes
        floating-point values and tags, the further rules that
        <xref target="RFC8949" section="4.2.2"/> and other deterministic
        profiles of CBOR make for them do not arise.  This document states
        its rules in full rather than referring to such a profile, so that
        they do not change with it.
      </t>
      <section anchor="enforcement" numbered="true" toc="default">
        <name>Enforcement</name>
        <t>
          A receiver enforces the rules while it decodes, or it decodes the
          item with a more permissive decoder, checks rules 2 to 5 on the
          result, encodes it again deterministically and compares the result
          with its input byte for byte.  Either way, it accepts an encoding
          only if it is the one encoding of its value.
        </t>
        <t>
          A decoder <bcp14>MUST NOT</bcp14> allocate memory based on a
          declared length or count before checking it against the remaining
          input: a byte or text string of n bytes needs n more bytes, an
          array of n elements at least n, and a map of n entries at least
          2n.  The work and memory that decoding takes are then bounded by
          the size of the container and the maximum depth.  A decoder
          <bcp14>MUST NOT</bcp14> recurse deeper than the maximum depth.
        </t>
        <t>
          Implementations <bcp14>SHOULD</bcp14> test their decoder against
          an independent CBOR implementation by differential fuzzing, and
          against the test vectors of <xref target="test_vectors"/>.
        </t>
      </section>
    </section>
    <section anchor="conventions" numbered="true" toc="default">
      <name>Conventions</name>
      <t>
        The following conventions apply to every specification that uses
        this profile, unless the specification states otherwise and gives
        its reason.
      </t>
      <section anchor="arrays" numbered="true" toc="default">
        <name>Positional Arrays</name>
        <t>
          A structure whose fields are fixed by its specification is an
          array whose elements are the fields, in the order the
          specification gives.  The number of elements is fixed as well.
          Arrays are not an extension mechanism: a specification that needs
          another field defines a new message type, or uses an extensible
          map (<xref target="maps"/>) for the fields that can grow.  An
          optional element that is absent is null, if the specification
          permits it.
        </t>
      </section>
      <section anchor="maps" numbered="true" toc="default">
        <name>Extensible Maps</name>
        <t>
          A structure that later revisions or other parties extend is a map
          with unsigned integer keys.  Whether a key is critical or optional
          is a property of the key, fixed when it is assigned, and given by
          its number:
        </t>
        <dl>
          <dt>Critical keys (odd numbers):</dt>
          <dd>
            A receiver that does not know the key <bcp14>MUST</bcp14> reject
            the item.
          </dd>
          <dt>Optional keys (even numbers):</dt>
          <dd>
            A receiver that does not know the key <bcp14>MUST</bcp14> ignore
            its entry for processing.
          </dd>
        </dl>
        <t>
          A receiver can therefore apply the rule to keys it does not know.
          Key 0 is reserved and <bcp14>MUST NOT</bcp14> occur.  A key occurs
          at most once (rule 1); a key whose value can occur several times
          has an array as its value.  An absent entry is omitted, not null.
          Keys from 1 to 23 encode in one byte, and specifications assign
          them to the entries that occur most often.  Where the keys of a
          map are allocated by a registry, as the record types of a HELLO
          are <xref target="LSD0018"/>, the registry assigns each number
          with the parity that matches the treatment it requires.
        </t>
        <t>
          An entry that a receiver ignores is still part of the item.  A
          peer that stores or forwards an item it has received
          <bcp14>SHOULD</bcp14> keep the bytes it received.  If it encodes
          the item again, it <bcp14>MUST</bcp14> preserve every entry,
          including those it does not know, so that the result is byte for
          byte the same.  How unknown entries relate to signatures is stated
          in <xref target="signatures"/>.
        </t>
      </section>
      <section anchor="integers" numbered="true" toc="default">
        <name>Integers</name>
        <t>
          The specification gives the range of every integer, in its CDDL.
          A receiver <bcp14>MUST</bcp14> reject an item with an integer
          outside its range, and <bcp14>MUST NOT</bcp14> truncate it to a
          narrower type: 70000 in a field whose range is that of a 16-bit
          integer makes the item invalid.  Negative integers occur only where
          the specification allows them.  Integers are not used as
          booleans.
        </t>
      </section>
      <section anchor="bytes" numbered="true" toc="default">
        <name>Fixed-Size Values and Lists</name>
        <t>
          Hashes, signatures, raw public keys, nonces and peer identities
          are byte strings of exactly the size that the specification fixes
          (<tt>bstr .size N</tt> in CDDL), and a receiver
          <bcp14>MUST</bcp14> check the size.
        </t>
        <t>
          A list whose elements all have the same fixed size, such as a list
          of peer identities, is one byte string that holds the elements one
          after another.  A receiver <bcp14>MUST</bcp14> reject it unless its
          length is a multiple of the element size.  This saves the head of
          every element and lets a receiver use the elements in place.  A
          list whose elements differ in size, such as a list of signers
          (<xref target="keys"/>), is an array.
        </t>
        <t>
          If an array represents a set, the specification
          <bcp14>SHOULD</bcp14> require its elements in strictly ascending
          order of their encodings, compared bytewise lexicographically.
          This excludes duplicates and leaves one encoding for every set,
          as for the addresses of a HELLO <xref target="LSD0018"/>.
        </t>
      </section>
      <section anchor="keys" numbered="true" toc="default">
        <name>Typed Keys</name>
        <t>
          A public key whose algorithm can vary is an array of its type and
          the key, <tt>[type: uint, key: bstr]</tt>, with the type from a
          GANA registry that fixes the encoding and the length of the key.
          <xref target="LSD0018"/> defines the identity key types and the
          KEM types of GNUnet peers, and the items that carry them: a
          <tt>signer</tt>, which is a typed identity key with a signature,
          an <tt>identity</tt>, and a <tt>kem-ct</tt>.  Specifications
          <bcp14>SHOULD</bcp14> use these items rather than define their
          own.
        </t>
        <t>
          A key whose encoding another specification fixes is carried in
          that encoding, as one byte string.  For example, a zone key of the
          GNU Name System is the 4-byte type followed by the key, as
          <xref target="RFC9498"/> defines it, so that it is the same in
          every GNUnet format.
        </t>
      </section>
      <section anchor="times" numbered="true" toc="default">
        <name>Times</name>
        <t>
          An absolute time is an unsigned integer that counts microseconds
          since the epoch, and a relative time is an unsigned integer that
          counts microseconds.  The largest value, 2^64 - 1, means "forever"
          in both.  The specification states for every time whether
          "forever" is allowed.  These are the semantics of the absolute and
          relative times of the GNUnet implementation.
        </t>
        <sourcecode type="cddl"><![CDATA[
abs-time = uint                    ; microseconds since the epoch
rel-time = uint                    ; microseconds
forever  = 18446744073709551615    ; 2^64 - 1
        ]]></sourcecode>
      </section>
      <section anchor="text" numbered="true" toc="default">
        <name>Text</name>
        <t>
          Text strings hold text that people read, and addresses and URIs.
          Every other string of bytes is a byte string.  Text strings are
          compared byte for byte, without Unicode normalization.  The ban on
          U+0000 (rule 4) lets an implementation pass a decoded text string
          to code that expects a NUL-terminated string without truncating
          it.
        </t>
      </section>
    </section>
    <section anchor="framing" numbered="true" toc="default">
      <name>Framing</name>
      <section anchor="bodies" numbered="true" toc="default">
        <name>Message Bodies</name>
        <t>
          A GNUnet message is a header, which gives the size of the message
          and its type, followed by the body.  The header is defined by
          GNUnet's message framing, not by this profile, and is not CBOR.
          The GNUnet implementation uses a 4-byte header of a 16-bit size and
          a 16-bit type in NBO; nothing in this profile depends on that
          layout.
        </t>
        <t>
          The body of a message whose specification uses this profile is
          exactly one item, whose CDDL rule the message type determines.
          There is no other indication of the encoding: one message type has
          one encoding of its body, and a version or flag in the header
          <bcp14>MUST NOT</bcp14> select another.  A receiver
          <bcp14>MUST NOT</bcp14> read beyond the size that the header
          gives.  Specifications <bcp14>SHOULD</bcp14> state the maximum
          size of the body of each message type, so that a receiver can
          reject a larger message before it reads the body.
        </t>
        <t>
          CBOR sequences <xref target="RFC8742"/> are not used for framing.
          Finding the end of a message in a byte stream then needs only the
          header, not a CBOR decoder.
        </t>
      </section>
      <section anchor="nesting" numbered="true" toc="default">
        <name>Nested Messages</name>
        <t>
          A message that another message carries is a byte string that holds
          the complete inner message, header and body.  Its body is decoded
          from that byte string as an item of its own
          (<xref target="rules"/>).
        </t>
      </section>
      <section anchor="padding" numbered="true" toc="default">
        <name>Padding</name>
        <t>
          A specification <bcp14>MAY</bcp14> declare that the body of a
          message type is padded, for example to hide its length.  The
          padding is a run of zero bytes after the item, inside the
          container; a receiver <bcp14>MUST</bcp14> reject padding that
          contains a byte other than zero.  Padding is useful only inside
          encryption, and the specification states how much is allowed.  A
          container whose specification declares no padding has none.
        </t>
      </section>
      <section anchor="obfuscation" numbered="true" toc="default">
        <name>Obfuscated Layers</name>
        <t>
          Some communicators make the bytes they send look random to an
          observer of the underlay.  The initial byte of a CBOR array or map
          at a fixed offset would identify them.  Specifications therefore
          <bcp14>MUST NOT</bcp14> place items of this profile where the
          bytes must look random.  Items of this profile travel inside
          encryption, where only their length is visible, or out of band,
          as a HELLO URL does.
        </t>
      </section>
    </section>
    <section anchor="signatures" numbered="true" toc="default">
      <name>Signatures and Hashes</name>
      <t>
        The data that GNUnet signs is not CBOR.  It is a packed structure:
        a 32-bit size and a 32-bit signature purpose from the GANA "GNUnet
        Signature Purposes" registry, in NBO, followed by the fields that
        the purpose defines.  Signer and verifier build it; it is not
        transmitted.  The purpose registry is shared with GNU Taler and the
        GNU Name System <xref target="RFC9498"/>, a structure of fixed-size
        fields in NBO is a deterministic encoding by construction, and the
        purpose at a fixed offset lets the service that holds the signing
        key check what it signs.  The one exception is the CAKE key
        exchange <xref target="LSD0012"/>, which signs, as TLS 1.3 does,
        64 zero bytes, a context string, a zero byte and a hash of the
        handshake transcript.  The kinds of data
        that a peer's identity key signs, and how they are kept apart, are
        stated in <xref target="LSD0018"/>.
      </t>
      <t>
        A structure that is signed, or hashed for another purpose, relates
        to the encoding as follows:
      </t>
      <ul>
        <li>
          <strong>Variable content is hashed into a fixed field.</strong>
          Where the signed data covers an item of variable size, a field of
          the signed structure holds the hash of the encoding of that item,
          as the HELLO does with its records map <xref target="LSD0018"/>.
        </li>
        <li>
          <strong>Hash the bytes received.</strong>  A receiver computes
          such a hash over the encoding of the item as it received it.
          Under <xref target="rules"/> that is the one encoding of the
          value, so sender and receiver hash the same bytes.  A receiver
          <bcp14>MUST NOT</bcp14> hash its own encoding of a value instead,
          since it may differ if the receiver did not preserve every entry.
        </li>
        <li>
          <strong>Unknown entries.</strong>  If the signature covers the
          encoding of an extensible map as received, directly or through its
          hash, it covers the entries that a receiver does not know, and the
          rule of <xref target="maps"/> applies.  If the signed structure is
          instead built from fields that the receiver decoded, an entry that
          the receiver does not know is covered by no signature, and the
          receiver <bcp14>MUST</bcp14> reject an item that contains one,
          whether its key is critical or optional.
        </li>
        <li>
          <strong>Values known from context.</strong>  A signed structure
          can contain values that are not transmitted because the verifier
          knows them, such as the neighbours of a peer on a DHT path
          <xref target="LSD0004"/>.  The verifier builds the structure from
          what it knows and what it received.
        </li>
        <li>
          <strong>Identity by hash.</strong>  Where a hash of an item serves
          as its identity, for example in the result filters of the DHT,
          the rules of <xref target="rules"/> make that identity unique.
        </li>
      </ul>
      <t>
        The profile does not use COSE.  <xref target="LSD0018"/> explains why
        the HELLO signature is not a COSE object; the same reasons apply to
        other signatures by a peer.
      </t>
    </section>
    <section anchor="using" numbered="true" toc="default">
      <name>Using this Profile</name>
      <t>
        A specification that uses this profile refers to this document and
        states:
      </t>
      <ul>
        <li>
          the CDDL <xref target="RFC8610"/> of every item it defines, as the
          normative definition, with diagrams for illustration only;
        </li>
        <li>
          the maximum depth of its items (rule 5), and the containers in
          which they appear with their maximum sizes;
        </li>
        <li>
          the range of every integer and the size of every fixed-size byte
          string;
        </li>
        <li>
          for every extensible map, its keys and whether they come from a
          registry;
        </li>
        <li>
          for every time, whether "forever" is allowed;
        </li>
        <li>
          which items are signed or hashed, and how
          (<xref target="signatures"/>);
        </li>
        <li>
          whether a message body is padded (<xref target="padding"/>);
        </li>
        <li>
          test vectors, in CBOR diagnostic notation
          (<xref target="RFC8949" section="8"/>) together with the encoding
          in hexadecimal.
        </li>
      </ul>
    </section>
    <section anchor="security" numbered="true" toc="default">
      <name>Security Considerations</name>
      <section anchor="sec_differentials" numbered="true" toc="default">
        <name>Parser Differentials</name>
        <t>
          An item that one implementation accepts and another rejects is
          handled differently by different peers: in the DHT, some store and
          forward it and others drop it.  Such differences are the usual way
          that networks with several implementations split, and they can be
          used to partition the network or to fingerprint implementations.
          The rules of <xref target="rules"/> leave nothing for a receiver to
          decide: every encoding is either the one encoding of its value or
          invalid.  The same holds for the semantic checks that
          specifications add, such as integer ranges, which is why
          <xref target="using"/> asks for them to be stated.
        </t>
      </section>
      <section anchor="sec_resources" numbered="true" toc="default">
        <name>Resource Exhaustion</name>
        <t>
          A declared length or count can be as large as 2^64 - 1, while the
          container holds a few bytes.  A decoder that allocates according to
          the declared value can be made to exhaust its memory by a single
          small message.  The checks of <xref target="enforcement"/> bound
          memory and work by the size of the container, and the maximum
          depth bounds the recursion of the decoder.  The size of the
          container is bounded by the message framing
          (<xref target="bodies"/>).
        </t>
      </section>
      <section anchor="sec_unsigned" numbered="true" toc="default">
        <name>Content Not Covered by a Signature</name>
        <t>
          When a signed structure is built from decoded fields, every field
          that the receiver uses has to be part of it.  A field that is
          transmitted but left out of the signed structure is accepted
          without a signature, and so is an unknown map entry.
          <xref target="signatures"/> requires receivers to reject unknown
          entries in that case.  Specifications <bcp14>SHOULD</bcp14> have
          tests that change each field of a signed message in turn and
          expect the verification to fail.
        </t>
      </section>
      <section anchor="sec_narrowing" numbered="true" toc="default">
        <name>Narrowing and Strings</name>
        <t>
          Decoders written in C copy decoded values into fixed-width
          integers and pass text to functions that expect NUL-terminated
          strings.  An integer that is silently truncated, or a string that
          is cut at an embedded U+0000, means something else to the decoder
          than to the sender.  The range checks of
          <xref target="integers"/> and rule 4 exclude both.
        </t>
      </section>
      <section anchor="sec_traffic" numbered="true" toc="default">
        <name>Traffic Analysis</name>
        <t>
          The structure of CBOR is visible to anyone who sees the bytes.
          Items of this profile travel inside encryption
          (<xref target="obfuscation"/>), where their length is visible as
          the length of a packed structure was.  Where the length itself
          reveals too much, the specification declares padding
          (<xref target="padding"/>).
        </t>
      </section>
    </section>
    <section anchor="gana" numbered="true" toc="default">
      <name>GANA Considerations</name>
      <t>
        This document requests no registry and no allocation.  GANA
        continues to allocate GNUnet message types and signature purposes.
        The keys of a map are defined by the specification of the map, in
        its CDDL, unless that specification creates a registry for them.
      </t>
    </section>
    <section anchor="implementation" numbered="true" toc="default">
      <name>Implementation Status</name>
      <t>
        A patch series for the GNUnet implementation contains a strict CBOR
        codec in the GNUnet utility library, which enforces the encoding
        rules of the HELLO <xref target="LSD0018"/>.  Those rules are the
        rules of <xref target="rules"/> with a maximum depth of 8.  The same
        series encodes the bodies of the peer-to-peer messages of several
        subsystems with it, as listed in <xref target="LSD0018"/>.  It
        predates this document, and its conventions have yet to be checked
        against <xref target="conventions"/>.
      </t>
      <t>
        The test vectors of <xref target="test_vectors"/> were checked with
        a validator written for this document in Python and, for
        well-formedness, with the CBOR decoder of Qt 6.8
        (QCborStreamReader).
      </t>
    </section>
    <section anchor="open" numbered="true" toc="default">
      <name>Open Issues</name>
      <ul>
        <li>
          <strong>Maximum depth.</strong>  Rule 5 caps the depth at 16, so
          that a decoder can use a fixed stack.  No specification needs more
          than 8 so far.
        </li>
        <li>
          <strong>IPC.</strong>  Messages between the components of one
          GNUnet installation could use this profile as well.  They need no
          extensibility, since both ends are released together, but the
          strictness protects the services from malformed requests.
        </li>
        <li>
          <strong>Message header.</strong>  A message header of 8 bytes with
          a size field of at least 24 bits is planned for GNUnet.  It does
          not change this profile, but the maximum sizes that specifications
          state (<xref target="bodies"/>) have to be set again with it.
        </li>
      </ul>
    </section>
  </middle>
  <back>
    <references>
      <name>Normative References</name>
      &RFC2119;
      &RFC3629;
      &RFC8174;
      &RFC8610;
      &RFC8949;
    </references>
    <references>
      <name>Informative References</name>
      &RFC7049;
      &RFC8742;
      &RFC9498;
      <reference anchor="LSD0004" target="https://lsd.gnunet.org/lsd0004">
        <front>
          <title>The R5N Distributed Hash Table</title>
          <author initials="M." surname="Schanzenbach" fullname="Martin Schanzenbach">
            <organization>Fraunhofer AISEC</organization>
          </author>
          <author initials="C." surname="Grothoff" fullname="Christian Grothoff">
            <organization>Berner Fachhochschule</organization>
          </author>
          <author initials="B." surname="Fix" fullname="Bernd Fix">
            <organization>GNUnet e.V.</organization>
          </author>
          <date year="2025"/>
        </front>
        <seriesInfo name="Internet-Draft" value="draft-schanzen-r5n-07"/>
      </reference>
      <reference anchor="LSD0012" target="https://lsd.gnunet.org/lsd0012">
        <front>
          <title>CORE Authenticated Key Exchange (CAKE)</title>
          <author initials="M." surname="Schanzenbach" fullname="Martin Schanzenbach">
            <organization>Fraunhofer AISEC</organization>
          </author>
          <author initials="" surname="ch3" fullname="ch3">
            <organization>GNUnet e.V.</organization>
          </author>
          <date year="2025"/>
        </front>
        <seriesInfo name="Internet-Draft" value="draft-schanzen-cake-00"/>
      </reference>
      <reference anchor="LSD0018" target="https://lsd.gnunet.org/lsd0018">
        <front>
          <title>The GNUnet HELLO Format, Version 2</title>
          <author initials="M." surname="Schanzenbach" fullname="Martin Schanzenbach">
            <organization>Fraunhofer AISEC</organization>
          </author>
          <date year="2026"/>
        </front>
        <seriesInfo name="Internet-Draft" value="draft-gnunet-hello-00"/>
      </reference>
    </references>
    <section anchor="test_vectors" numbered="true" toc="default">
      <name>Test Vectors</name>
      <t>
        Each line gives an encoding in hexadecimal, the item in diagnostic
        notation, and whether a receiver accepts it under this profile with
        a maximum depth of 8.  For a rejected encoding, the rule of
        <xref target="rules"/> that it violates is given.  The encodings
        rejected under rules 1 to 6 are well-formed CBOR, and a permissive
        decoder accepts them, except that some decoders check UTF-8
        themselves (<xref target="RFC8949" section="5.3.1"/> calls such a
        string well-formed but not valid).  The last three are not
        well-formed at all.
      </t>
      <table anchor="table_vectors">
        <name>Encodings and Their Treatment.</name>
        <thead>
          <tr><th>Encoding</th><th>Item</th><th>Result</th></tr>
        </thead>
        <tbody>
          <tr><td>830141006161</td><td>[1, h'00', "a"]</td><td>valid</td></tr>
          <tr><td>a201f51818f6</td><td>{1: true, 24: null}</td><td>valid</td></tr>
          <tr><td>82201bffffffffffffffff</td><td>[-1, 18446744073709551615]</td><td>valid</td></tr>
          <tr><td>8480a04060</td><td>[[], {}, h'', ""]</td><td>valid</td></tr>
          <tr><td>8181818181818180</td><td>[[[[[[[[]]]]]]]], depth 8</td><td>valid</td></tr>
          <tr><td>1801</td><td>1, in two bytes</td><td>rule 1</td></tr>
          <tr><td>580100</td><td>h'00', length in two bytes</td><td>rule 1</td></tr>
          <tr><td>9f01ff</td><td>[_ 1], indefinite length</td><td>rule 1</td></tr>
          <tr><td>a21818f601f5</td><td>{24: null, 1: true}, keys out of order</td><td>rule 1</td></tr>
          <tr><td>a201f501f4</td><td>{1: true, 1: false}, duplicate key</td><td>rule 1</td></tr>
          <tr><td>f93c00</td><td>1.0, a half-precision float</td><td>rule 2</td></tr>
          <tr><td>c24101</td><td>2(h'01'), a bignum</td><td>rule 2</td></tr>
          <tr><td>f7</td><td>undefined</td><td>rule 2</td></tr>
          <tr><td>f0</td><td>simple(16)</td><td>rule 2</td></tr>
          <tr><td>a1616101</td><td>{"a": 1}, a text key</td><td>rule 3</td></tr>
          <tr><td>a12001</td><td>{-1: 1}, a negative key</td><td>rule 3</td></tr>
          <tr><td>62c328</td><td>a text string that is not UTF-8</td><td>rule 4</td></tr>
          <tr><td>6100</td><td>"\u0000"</td><td>rule 4</td></tr>
          <tr><td>818181818181818180</td><td>[[[[[[[[[]]]]]]]]], depth 9</td><td>rule 5</td></tr>
          <tr><td>0100</td><td>1, followed by a zero byte</td><td>rule 6</td></tr>
          <tr><td>5affffffff00</td><td>a byte string of 2^32 - 1 bytes, of which 1 is present</td><td>not well-formed</td></tr>
          <tr><td>1c</td><td>reserved additional information 28</td><td>not well-formed</td></tr>
          <tr><td>ff</td><td>a "break" outside an item of indefinite length</td><td>not well-formed</td></tr>
        </tbody>
      </table>
      <t>
        A decoder must reject the byte string of 2^32 - 1 bytes without
        allocating memory for it (<xref target="enforcement"/>).  The
        second valid encoding shows the order of map keys: the encoding of
        1 (<tt>01</tt>) sorts before that of 24 (<tt>18 18</tt>).
      </t>
    </section>
  </back>
</rfc>
