<?xml version="1.0" encoding="utf-8"?>
<!-- name="GENERATOR" content="github.com/mmarkdown/mmark Mmark Markdown Processor - mmark.miek.nl" -->
<rfc version="3" ipr="trust200902" docName="draft-paragon-paseto-rfc-01" submissionType="IETF" category="info" xml:lang="en" xmlns:xi="http://www.w3.org/2001/XInclude" indexInclude="false" consensus="true">

<front>
<title abbrev="PASETO">PASETO (Platform-Agnostic SEcurity TOkens)</title><seriesInfo value="draft-paragon-paseto-rfc-01" stream="IETF" status="informational" name="Internet-Draft"></seriesInfo>
<author initials="R." surname="Terjesen" fullname="Robyn Terjesen"><organization>Paragon Initiative Enterprises</organization><address><postal><street></street>
<country>United States</country>
</postal><email>robyn@paragonie.com</email>
</address></author><author initials="S." surname="Haussmann" fullname="Steven Haussmann"><organization>Rensselaer Polytechnic Institute</organization><address><postal><street></street>
<country>United States</country>
</postal><email>hausss@rpi.edu</email>
</address></author><author initials="S." surname="Arciszewski" fullname="Scott Arciszewski"><organization>Paragon Initiative Enterprises</organization><address><postal><street></street>
<country>United States</country>
</postal><email>security@paragonie.com</email>
</address></author><date year="2022" month="May" day="24"></date>
<area>Internet</area>
<workgroup></workgroup>
<keyword>security</keyword>
<keyword>token</keyword>

<abstract>
<t>Platform-Agnostic SEcurity TOkens (PASETOs) provide a cryptographically secure,
compact, and URL-safe representation of claims that may be transferred between
two parties. The claims are encoded in JavaScript Object Notation (JSON),
version-tagged, and either encrypted using shared-key cryptography or signed
using public-key cryptography.</t>
</abstract>

</front>

<middle>

<section anchor="introduction"><name>Introduction</name>
<t>A Platform-Agnostic SEcurity TOken (PASETO) is a cryptographically secure,
compact, and URL-safe representation of claims intended for space-constrained
environments such as HTTP Cookies, HTTP Authorization headers, and URI query
parameters. A PASETO encodes claims to be transmitted (in a JSON <xref target="RFC8259"></xref>
object by default), and is either encrypted symmetrically or signed using
public-key cryptography.</t>

<section anchor="difference-between-paseto-and-jose"><name>Difference Between PASETO and JOSE</name>
<t>The key difference between PASETO and the JOSE family of standards
(JWS <xref target="RFC7516"></xref>, JWE <xref target="RFC7517"></xref>, JWK <xref target="RFC7518"></xref>, JWA <xref target="RFC7518"></xref>, and
JWT <xref target="RFC7519"></xref>) is that JOSE allows implementors and users to mix and match
their own choice of cryptographic algorithms (specified by the &quot;alg&quot; header in
JWT), while PASETO has clearly defined protocol versions to prevent unsafe
configurations from being selected.</t>
<t>PASETO is defined in two pieces:</t>

<ol>
<li>The PASETO Message Format, defined in <xref target="paseto-message-format"></xref></li>
<li>The PASETO Protocol Version, defined in <xref target="protocol-versions"></xref></li>
</ol>
</section>

<section anchor="why-not-update-jose-to-be-secure"><name>Why Not Update JOSE to Be Secure?</name>
<t>Backwards compatibility introduces the risk of downgrade attacks. Conversely, a totally
separate standard can be designed from the ground up to be secure and misuse-resistant.</t>
<t>For that reason, PASETO does not aspire to update the JOSE family of standards. To do
so would undermine the security benefits of a non-interoperable alternative.</t>
</section>

<section anchor="notation-and-conventions"><name>Notation and Conventions</name>
<t>The key words &quot;<bcp14>MUST</bcp14>&quot;, &quot;<bcp14>MUST NOT</bcp14>&quot;, &quot;<bcp14>REQUIRED</bcp14>&quot;, &quot;<bcp14>SHALL</bcp14>&quot;,
&quot;<bcp14>SHALL NOT</bcp14>&quot;, &quot;<bcp14>SHOULD</bcp14>&quot;, &quot;<bcp14>SHOULD NOT</bcp14>&quot;, &quot;<bcp14>RECOMMENDED</bcp14>&quot;, &quot;<bcp14>MAY</bcp14>&quot;,
and &quot;<bcp14>OPTIONAL</bcp14>&quot; in this document are to be interpreted as described in
RFC 2119 <xref target="RFC2119"></xref>.</t>
</section>
</section>

<section anchor="paseto-message-format"><name>PASETO Message Format</name>
<t>PASETOs consist of three or four segments, separated by a period (the ASCII
character whose number, represented in hexadecimal, is 2E).</t>
<t>Without the Optional Footer:</t>

<sourcecode type="text">version.purpose.payload
</sourcecode>
<t>With the Optional Footer:</t>

<sourcecode type="text">version.purpose.payload.footer
</sourcecode>
<t>If no footer is provided, implementations <bcp14>SHOULD NOT</bcp14> append a trailing
period to each payload.</t>

<section anchor="paseto-token-versions"><name>PASETO Token Versions</name>
<t>The <strong>version</strong> is a string that represents the current version of the protocol.
Currently, two versions are specified, which each possess their own
ciphersuites. Accepted values: <strong>v3</strong>, <strong>v4</strong>.</t>
<t>(Earlier versions of the PASETO RFC specified <strong>v1</strong> and <strong>v2</strong>, but these are
not proposed for IETF standardization.)</t>
<t>Future standardization efforts <bcp14>MAY</bcp14> optionally suffix an additional piece of
information to the version to specify a non-JSON encoding for claims. The default
encoding, when no suffix is applied, is JSON. This suffix does not change the
cryptography protocol being used (except that the suffix is also authenticated).</t>
</section>

<section anchor="paseto-token-purposes"><name>PASETO Token Purposes</name>
<t>The <strong>purpose</strong> is a short string describing the purpose of the token. Accepted
values: <strong>local</strong>, <strong>public</strong>.</t>

<ul>
<li><strong>local</strong>: shared-key authenticated encryption</li>
<li><strong>public</strong>: public-key digital signatures; <strong>not encrypted</strong></li>
</ul>
<t>The <strong>payload</strong> is a string that contains the token's data. In a <tt>local</tt> token,
this data is encrypted with a symmetric cipher. In a <tt>public</tt> token, this data
is <em>unencrypted</em>.</t>
<t>Any optional data can be appended to the <strong>footer</strong>. This data is authenticated
through inclusion in the calculation of the authentication tag along with the
header and payload. The <strong>footer</strong> <bcp14>MUST NOT</bcp14> be encrypted.</t>
</section>

<section anchor="base64-encoding"><name>Base64 Encoding</name>
<t>The payload and footer in a PASETO <bcp14>MUST</bcp14> be encoded using base64url as
defined in <xref target="RFC4648"></xref>, without <tt>=</tt> padding.</t>
<t>In this document. <tt>b64()</tt> refers to this unpadded variant of base64url.</t>
</section>

<section anchor="multi-part-authentication"><name>Multi-Part Authentication</name>
<t>Multi-part messages (e.g. header, content, footer, implicit) are encoded in
a specific manner before being passed to the appropriate cryptographic
function, to prevent canonicalization attacks.</t>
<t>In <tt>local</tt> mode, this encoding is applied to the additional associated data
(AAD). In <tt>public</tt> mode, which is not encrypted, this encoding is applied to the
components of the token, with respect to the protocol version being followed.</t>
<t>We will refer to this process as <strong>PAE</strong> in this document (short for
Pre-Authentication Encoding).</t>

<section anchor="pae-definition"><name>PAE Definition</name>
<t><tt>PAE()</tt> accepts an array of strings.</t>
<t><tt>LE64()</tt> encodes a 64-bit unsigned integer into a little-endian binary string.
The most significant bit <bcp14>MUST</bcp14> be set to 0 for interoperability with
programming languages that do not have unsigned integer support.</t>
<t>The first 8 bytes of the output will be the number of pieces. Currently, this
will be 3 or 4. This is calculated by applying <tt>LE64()</tt> to the size of the
array.</t>
<t>Next, for each piece provided, the length of the piece is encoded via <tt>LE64()</tt>
and prefixed to each piece before concatenation.</t>
<figure><name>JavaScript implementation of Pre-Authentication Encoding (PAE)
</name>
<sourcecode type="javascript">function LE64(n) {
    var str = '';
    for (var i = 0; i &lt; 8; ++i) {
        if (i === 7) {
            n &amp;= 127;
        }
        str += String.fromCharCode(n &amp; 255);
        n = n &gt;&gt;&gt; 8;
    }
    return str;
}
function PAE(pieces) {
    if (!Array.isArray(pieces)) {
        throw TypeError('Expected an array.');
    }
    var count = pieces.length;
    var output = LE64(count);
    for (var i = 0; i &lt; count; i++) {
        output += LE64(pieces[i].length);
        output += pieces[i];
    }
    return output;
}
</sourcecode>
</figure>
<t>As a consequence:</t>

<ul>
<li><tt>PAE([])</tt> will always return <tt>\x00\x00\x00\x00\x00\x00\x00\x00</tt></li>
<li><tt>PAE([''])</tt> will always return
<tt>\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00</tt></li>
<li><tt>PAE(['test'])</tt> will always return
<tt>\x01\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00test</tt></li>
<li><tt>PAE('test')</tt> will throw a <tt>TypeError</tt></li>
</ul>
<t>As a result, partially controlled plaintext cannot be used to create a
collision. Either the number of pieces will differ, or the length of one of the
fields (which is prefixed to user-controlled input) will differ, or both.</t>
<t>Due to the length being expressed as an unsigned 64-bit integer, it is
infeasible to encode enough data to create an integer overflow.</t>
<t>This is not used to encode data prior to decryption, and no decoding function
is provided or specified. This merely exists to prevent canonicalization
attacks.</t>
</section>
</section>
</section>

<section anchor="protocol-versions"><name>Protocol Versions</name>
<t>This document defines two protocol versions for the PASETO standard.</t>
<t>Protocol versions (<strong>Version 3</strong>, <strong>Version 4</strong>) correspond to a specific message
format version (<strong>v3</strong>, <strong>v4</strong>).</t>
<t>Each protocol version strictly defines the cryptographic primitives used.
Changes to the primitives requires new protocol versions. Future RFCs <bcp14>MAY</bcp14>
introduce new PASETO protocol versions by continuing the convention
(e.g. <strong>Version 5</strong>, <strong>Version 6</strong>, ...).</t>
<t>Both <strong>Version 3</strong> and <strong>Version 4</strong> provide authentication of the entire PASETO
message, including the <strong>version</strong>, <strong>purpose</strong>, <strong>payload</strong>, <strong>footer</strong>, and
(optional) <strong>implicit assertions</strong>.</t>
<t>The initial recommendation is to use <strong>Version 4</strong>, allowing for upgrades to
possible future versions <strong>Version 5</strong>, <strong>Version 6</strong>, etc. when they are defined
in the future.</t>

<section anchor="paseto-protocol-guidelines"><name>PASETO Protocol Guidelines</name>
<t>When defining future protocol versions, the following rules <bcp14>SHOULD</bcp14>
or <bcp14>MUST</bcp14> be followed:</t>

<ol>
<li><t>Everything in a token <bcp14>MUST</bcp14> be authenticated. Attackers should never be
allowed the opportunity to alter messages freely.</t>

<ul>
<li>If encryption is specified, unauthenticated modes (e.g. AES-CBC without
a MAC) are forbidden.</li>
<li>The nonce or initialization vector must be covered by the authentication
tag, not just the ciphertext.</li>
</ul></li>
<li><t>Some degree of nonce-misuse resistance <bcp14>SHOULD</bcp14> be provided:</t>

<ul>
<li>Supporting larger nonces (longer than 128-bit) is sufficient for satisfying
this requirement, provided the nonce is generated by a cryptographically
secure random number generator, such as <strong>/dev/urandom</strong> on Linux.</li>
<li>Key-splitting and including an additional HKDF salt as part of the nonce is
sufficient for this requirement.</li>
</ul></li>
<li><t>Public-key cryptography <bcp14>MUST</bcp14> be IND-CCA2 secure to be considered for
inclusion.</t>

<ul>
<li>This means that RSA with PKCS1v1.5 padding and unpadded RSA <bcp14>MUST NOT</bcp14>
ever be used in a PASETO protocol.</li>
</ul></li>
</ol>
</section>
</section>

<section anchor="paseto-protocol-version-3"><name>PASETO Protocol Version 3</name>
<t><strong>PASETO Version 3</strong> is composed of NIST-approved algorithms, and will operate
on tokens with the <strong>v3</strong> version header.</t>
<t><strong>v3</strong> messages <bcp14>MUST</bcp14> use a <strong>purpose</strong> value of either <strong>local</strong> or
<strong>public</strong>.</t>

<section anchor="v3-local"><name>v3.local</name>
<t><strong>v3.local</strong> messages <bcp14>SHALL</bcp14> be encrypted and authenticated with
<strong>AES-256-CTR</strong> (AES-CTR from <xref target="RFC3686"></xref> with a 256-bit key) and
<strong>HMAC-SHA-384</strong> (<xref target="RFC4231"></xref>), using an <strong>Encrypt-then-MAC</strong> construction.</t>
<t>Encryption and authentication keys are split from the original key and 256-bit
nonce, facilitated by HKDF <xref target="RFC5869"></xref> using SHA384.</t>
<t>Refer to the operations defined in <strong>PASETO.v3.Encrypt</strong> and
<strong>PASETO.v3.Decrypt</strong> for a formal definition.</t>
</section>

<section anchor="v3-public"><name>v3.public</name>
<t><strong>v1.public</strong> messages <bcp14>SHALL</bcp14> be signed using ECDSA with NIST curve P-384
as defined in <xref target="RFC6687"></xref>. These messages provide authentication but do not
prevent the contents from being read, including by those without either the
<strong>public key</strong> or the <strong>secret key</strong>. Refer to the operations defined in
<strong>PASETO.v3.Sign</strong> and <strong>PASETO.v3.Verify</strong> for a formal definition.</t>
</section>

<section anchor="paseto-version-3-algorithms"><name>PASETO Version 3 Algorithms</name>

<section anchor="paseto-v3-encrypt"><name>PASETO.v3.Encrypt</name>
<t>Given a message <tt>m</tt>, key <tt>k</tt>, and optional footer <tt>f</tt> (which defaults to empty
string), and an optional implicit assertion <tt>i</tt> (which defaults to empty string):</t>

<ol>
<li>Before encrypting, first assert that the key being used is intended for use
with <tt>v3.local</tt> tokens. If this assertion fails, abort encryption.</li>
<li>Set header <tt>h</tt> to <tt>v3.local.</tt></li>
<li>Generate 32 random bytes from the OS's CSPRNG to get the nonce, <tt>n</tt>.</li>
<li><t>Split the key into an Encryption key (<tt>Ek</tt>) and Authentication key (<tt>Ak</tt>),
using HKDF-HMAC-SHA384, with <tt>n</tt> appended to the info rather than the salt.</t>

<ul>
<li>The output length <bcp14>MUST</bcp14> be 48 for both key derivations.</li>
<li>The derived key will be the leftmost 32 bytes of the first HKDF derivation.
The remaining 16 bytes of the first key derivation (from which <tt>Ek</tt> is derived)
will be used as a counter nonce (<tt>n2</tt>):</li>
</ul></li>
<li>Encrypt the message using <tt>AES-256-CTR</tt>, using <tt>Ek</tt> as the key and <tt>n2</tt> as the nonce.
We'll call the encrypted output of this step <tt>c</tt>.</li>
<li>Pack <tt>h</tt>, <tt>n</tt>, <tt>c</tt>, and <tt>f</tt> together (in that order) using PAE (see
<xref target="pae-definition"></xref>). We'll call this <tt>preAuth</tt>.</li>
<li>Calculate HMAC-SHA384 of the output of <tt>preAuth</tt>, using <tt>Ak</tt> as the
authentication key. We'll call this <tt>t</tt>.</li>
<li><t>If <tt>f</tt> is:</t>

<ul>
<li>Empty: return h || b64(n || c || t)</li>
<li>Non-empty: return h || b64(n || c || t) || <tt>.</tt> || b64(f)</li>
<li>...where || means &quot;concatenate&quot;</li>
</ul></li>
</ol>
<t>Example code:</t>
<figure><name>Step 4: Key splitting with HKDF-SHA384 as per <xref target="RFC5869"></xref>.
</name>
<artwork>tmp = hkdf_sha384(
    len = 48,
    ikm = k,
    info = &quot;paseto-encryption-key&quot; || n,
    salt = NULL
);
Ek = tmp[0:32]
n2 = tmp[32:]
Ak = hkdf_sha384(
    len = 48,
    ikm = k,
    info = &quot;paseto-auth-key-for-aead&quot; || n,
    salt = NULL
);
</artwork>
</figure>
<figure><name>Step 5: PASETO Version 3 encryption (calculating <tt>c</tt>)
</name>
<artwork>c = aes256ctr_encrypt(
    plaintext = m,
    nonce = n2
    key = Ek
);
</artwork>
</figure>
</section>

<section anchor="paseto-v3-decrypt"><name>PASETO.v3.Decrypt</name>
<t>Given a message <tt>m</tt>, key <tt>k</tt>, and optional footer <tt>f</tt>
(which defaults to empty string):</t>

<ol>
<li>Before decrypting, first assert that the key being used is intended for use
with <tt>v3.local</tt> tokens. If this assertion fails, abort decryption.</li>
<li>If <tt>f</tt> is not empty, implementations <bcp14>MAY</bcp14> verify that the value appended
to the token matches some expected string <tt>f</tt>, provided they do so using a
constant-time string compare function.</li>
<li>Verify that the message begins with <tt>v3.local.</tt>, otherwise throw an
exception. This constant will be referred to as <tt>h</tt>.</li>
<li><t>Decode the payload (<tt>m</tt> sans <tt>h</tt>, <tt>f</tt>, and the optional trailing period
between <tt>m</tt> and <tt>f</tt>) from b64 to raw binary. Set:</t>

<ul>
<li><tt>n</tt> to the leftmost 32 bytes</li>
<li><tt>t</tt> to the rightmost 48 bytes</li>
<li><tt>c</tt> to the middle remainder of the payload, excluding <tt>n</tt> and <tt>t</tt></li>
</ul></li>
<li><t>Split the key (<tt>k</tt>) into an Encryption key (<tt>Ek</tt>) and an Authentication key
(<tt>Ak</tt>), <tt>n</tt> appended to the HKDF info.</t>

<ul>
<li>For encryption keys, the <strong>info</strong> parameter for HKDF <bcp14>MUST</bcp14> be set to
<strong>paseto-encryption-key</strong>.</li>
<li>For authentication keys, the <strong>info</strong> parameter for HKDF <bcp14>MUST</bcp14> be set to
<strong>paseto-auth-key-for-aead</strong>.</li>
<li>The output length <bcp14>MUST</bcp14> be 48 for both key derivations.
The leftmost 32 bytes of the first key derivation will produce <tt>Ek</tt>, while
the remaining 16 bytes will be the AES nonce <tt>n2</tt>.</li>
</ul></li>
<li>Pack <tt>h</tt>, <tt>n</tt>, <tt>c</tt>, <tt>f</tt>, and <tt>i</tt> together (in that order) using PAE (see
<xref target="pae-definition"></xref>). We'll call this <tt>preAuth</tt>.</li>
<li>Recalculate HMAC-SHA-384 of <tt>preAuth</tt> using <tt>Ak</tt> as the key. We'll call this
<tt>t2</tt>.</li>
<li>Compare <tt>t</tt> with <tt>t2</tt> using a constant-time string compare function. If they
are not identical, throw an exception.</li>
<li>Decrypt <tt>c</tt> using <tt>AES-256-CTR</tt>, using <tt>Ek</tt> as the key and the rightmost 16
bytes of <tt>n</tt> as the nonce, and return this value.</li>
</ol>
<t>Example code:</t>
<figure><name>Step 4: Key splitting with HKDF-SHA384 as per <xref target="RFC5869"></xref>.
</name>
<artwork>tmp = hkdf_sha384(
    len = 48,
    ikm = k,
    info = &quot;paseto-encryption-key&quot; || n,
    salt = NULL
);
Ek = tmp[0:32]
n2 = tmp[32:]
Ak = hkdf_sha384(
    len = 48,
    ikm = k,
    info = &quot;paseto-auth-key-for-aead&quot; || n,
    salt = NULL
);
</artwork>
</figure>
<figure><name>Step 8: PASETO Version 3 decryption
</name>
<artwork>return aes256ctr_decrypt(
   cipherext = c,
   nonce = n2
   key = Ek
);
</artwork>
</figure>
</section>

<section anchor="paseto-v3-sign"><name>PASETO.v3.Sign</name>
<t>Given a message <tt>m</tt>, 384-bit ECDSA secret key <tt>sk</tt>, an optional footer <tt>f</tt>
(which defaults to empty string), and an optional implicit assertion <tt>i</tt>
(which defaults to empty string):</t>

<ol>
<li>Before signing, first assert that the key being used is intended for use
with <tt>v3.public</tt> tokens, and is a secret key (not a public key). If this
assertion fails, abort signing.</li>
<li>Set <tt>cpk</tt> to the compressed point representation of the ECDSA public key (see
<eref target="https://www.secg.org/sec1-v2.pdf">point compression</eref>), using [#paseto-v3-compresspublickey].</li>
<li>Set <tt>h</tt> to <tt>v3.public.</tt></li>
<li>Pack <tt>cpk</tt>, <tt>h</tt>, <tt>m</tt>, <tt>f</tt>, and <tt>i</tt> together (in that order) using PAE (see
<xref target="pae-definition"></xref>). We'll call this <tt>m2</tt>.</li>
<li><t>Sign <tt>m2</tt> using ECDSA over P-384 and SHA-384 with the private key <tt>sk</tt>.
We'll call this <tt>sig</tt>. The output of <tt>sig</tt> MUST be in the format <tt>r || s</tt>
(where <tt>||</tt>means concatenate), for a total length of 96 bytes.</t>

<ul>
<li>Signatures <bcp14>SHOULD</bcp14> use deterministic k-values (<xref target="RFC6979"></xref>) if possible,
to mitigate the risk of <eref target="https://blog.trailofbits.com/2020/06/11/ecdsa-handle-with-care/">k-value reuse</eref>.</li>
<li>If possible, hedged signatures (<xref target="RFC6979"></xref> + additional randomness when generating
k-values to provide resilience to fault attacks) are preferred over <xref target="RFC6979"></xref> alone.</li>
<li>If <xref target="RFC6979"></xref> is not available in your programming language, ECDSA <bcp14>MUST</bcp14> use a CSPRNG
to generate the k-value.</li>
</ul></li>
<li><t>If <tt>f</tt> is:</t>

<ul>
<li>Empty: return h || b64(m || sig)</li>
<li>Non-empty: return h || b64(m || sig) || <tt>.</tt> || b64(f)</li>
<li>...where || means &quot;concatenate&quot;</li>
</ul></li>
</ol>
<figure><name>Pseudocode: ECDSA signature algorithm used in PASETO v3
</name>
<artwork>cpk = PASETO.v3.CompressPublicKey(sk.getPublicKey());
m2 = PASETO.PAE(cpk, h, m, f, i);
sig = crypto_sign_ecdsa_p384(
    message = m2,
    private_key = sk
);
</artwork>
</figure>
</section>

<section anchor="paseto-v3-verify"><name>PASETO.v3.Verify</name>
<t>Given a signed message <tt>sm</tt>, ECDSA public key <tt>pk</tt>,
and optional footer <tt>f</tt> (which defaults to empty string), and an optional
implicit assertion <tt>i</tt> (which defaults to empty string):</t>

<ol>
<li>Before verifying, first assert that the key being used is intended for use
with <tt>v3.public</tt> tokens, and is a public key (not a secret key). If this
assertion fails, abort verifying.</li>
<li>If <tt>f</tt> is not empty, implementations <bcp14>MAY</bcp14> verify that the value appended
to the token matches some expected string <tt>f</tt>, provided they do so using a
constant-time string compare function.</li>
<li>Set <tt>cpk</tt> to the compressed point representation of the ECDSA public key (see
<eref target="https://www.secg.org/sec1-v2.pdf">point compression</eref>), using [#paseto-v3-compresspublickey].</li>
<li>Verify that the message begins with <tt>v3.public.</tt>, otherwise throw an
exception. This constant will be referred to as <tt>h</tt>.</li>
<li><t>Decode the payload (<tt>sm</tt> sans <tt>h</tt>, <tt>f</tt>, and the optional trailing period
between <tt>m</tt> and <tt>f</tt>) from base64url to raw binary. Set:</t>

<ul>
<li><tt>s</tt> to the rightmost 96 bytes</li>
<li><tt>m</tt> to the leftmost remainder of the payload, excluding <tt>s</tt></li>
</ul></li>
<li>Pack <tt>h</tt>, <tt>m</tt>, <tt>f</tt>, and <tt>i</tt> together (in that order) using PAE (see
<xref target="pae-definition"></xref>). We'll call this <tt>m2</tt>.</li>
<li>Use RSA to verify that the signature is valid for the message.
The padding mode <bcp14>MUST</bcp14> be RSASSA-PSS <xref target="RFC8017"></xref>; PKCS1v1.5 is
explicitly forbidden. The public exponent <tt>e</tt> <bcp14>MUST</bcp14> be 65537.
The mask generating function <bcp14>MUST</bcp14> be MGF1+SHA384. The hash function
<bcp14>MUST</bcp14> be SHA384. (See below for pseudocode.)</li>
<li>If the signature is valid, return <tt>m</tt>. Otherwise, throw an exception.</li>
</ol>
<figure><name>Pseudocode: ECDSA signature validation for PASETO Version 3
</name>
<artwork>cpk = PASETO.v3.CompressPublicKey(pk);
m2 = PASETO.PAE(cpk, h, m, f, i);
valid = crypto_sign_ecdsa_p384_verify(
    signature = s,
    message = m2,
    public_key = pk
);
</artwork>
</figure>
</section>

<section anchor="paseto-v3-compresspublickey"><name>PASETO.v3.CompressPublicKey</name>
<t>Given a public key consisting of two coordinates (X, Y):</t>

<ol>
<li>Set the header to <tt>0x02</tt>.</li>
<li>Take the least significant bit of <tt>Y</tt> and add it to the header.</li>
<li>Append the X coordinate (in big-endian byte order) to the header.</li>
</ol>
<figure><name>Pseudocode: Point compression as used in PASETO Version 3.
</name>
<artwork>lsb(y):
   return y[y.length - 1] &amp; 1

pubKeyCompress(x, y):
   header = [0x02 + lsb(y)]
   return header.concat(x)
</artwork>
</figure>
</section>
</section>
</section>

<section anchor="paseto-protocol-version-v4"><name>PASETO Protocol Version v4</name>
<t><strong>PASETO Version 4</strong> is the recommended version of PASETO, and will
operate on tokens with the <strong>v4</strong> version header.</t>
<t><strong>v4</strong> messages <bcp14>MUST</bcp14> use a <strong>purpose</strong> value of either <strong>local</strong> or
<strong>public</strong>.</t>

<section anchor="v4-local"><name>v4.local</name>
<t><strong>v4.local</strong> messages <bcp14>MUST</bcp14> be encrypted with XChaCha20, a variant
of ChaCha20 <xref target="RFC7539"></xref> defined in <eref target="https://datatracker.ietf.org/doc/html/draft-irtf-cfrg-xchacha-03">XChaCha20</eref>.
Refer to the operations defined in <strong>PASETO.v4.Encrypt</strong> and
<strong>PASETO.v4.Decrypt</strong> for a formal definition.</t>
</section>

<section anchor="v4-public"><name>v4.public</name>
<t><strong>v4.public</strong> messages <bcp14>MUST</bcp14> be signed using Ed25519 <xref target="RFC8032"></xref> public key
signatures. These messages provide authentication but do not prevent the
contents from being read, including by those without either the <strong>public key</strong>
or the <strong>private key</strong>. Refer to the operations defined in <strong>v4.Sign</strong> and
<strong>v4.Verify</strong> for a formal definition.</t>
</section>

<section anchor="paseto-version-4-algorithms"><name>PASETO Version 4 Algorithms</name>

<section anchor="paseto-v4-encrypt"><name>PASETO.v4.Encrypt</name>
<t>Given a message <tt>m</tt>, key <tt>k</tt>, and optional footer <tt>f</tt>.</t>

<ol>
<li>Before encrypting, first assert that the key being used is intended for use
with <tt>v4.local</tt> tokens. If this assertion fails, abort encryption.</li>
<li>Set header <tt>h</tt> to <tt>v4.local.</tt></li>
<li>Generate 32 random bytes from the OS's CSPRNG, <tt>n</tt>.</li>
<li>Split the key into an Encryption key (<tt>Ek</tt>) and Authentication key (<tt>Ak</tt>),
using keyed BLAKE2b, using the domain separation constants and <tt>n</tt> as the
message, and the input key as the key. The first value will be 56 bytes,
the second will be 32 bytes.
The derived key will be the leftmost 32 bytes of the hash output.
The remaining 24 bytes will be used as a counter nonce (<tt>n2</tt>).</li>
<li>Encrypt the message using XChaCha20, using <tt>n2</tt> from step 3 as the nonce and <tt>Ek</tt> as the key.</li>
<li>Pack <tt>h</tt>, <tt>n</tt>, <tt>c</tt>, <tt>f</tt>, and <tt>i</tt> together (in that order) using
PAE (see <xref target="pae-definition"></xref>). We'll call this <tt>preAuth</tt>.</li>
<li>Calculate BLAKE2b-MAC of the output of <tt>preAuth</tt>, using <tt>Ak</tt> as the
authentication key. We'll call this <tt>t</tt>.</li>
<li><t>If <tt>f</tt> is:</t>

<ul>
<li>Empty: return h || b64(n || c)</li>
<li>Non-empty: return h || b64(n || c) || <tt>.</tt> || b64(f)</li>
<li>...where || means &quot;concatenate&quot;</li>
</ul></li>
</ol>
<figure><name>Step 4: Key splitting with BLAKE2b.
</name>
<artwork>tmp = crypto_generichash(
    msg = &quot;paseto-encryption-key&quot; || n,
    key = key,
    length = 56
);
Ek = tmp[0:32]
n2 = tmp[32:]
Ak = crypto_generichash(
    msg = &quot;paseto-auth-key-for-aead&quot; || n,
    key = key,
    length = 32
);
</artwork>
</figure>
<figure><name>Steps 5-7: PASETO Version 4 encryption
</name>
<artwork>c = crypto_stream_xchacha20_xor(
    message = m
    nonce = n2
    key = Ek
);
preAuth = PASETO.PAE(h, n, c, f, i)
t = crypto_generichash(
    message = preAuth
    key = Ak,
    length = 32
);
</artwork>
</figure>
</section>

<section anchor="paseto-v4-decrypt"><name>PASETO.v4.Decrypt</name>
<t>Given a message <tt>m</tt>, key <tt>k</tt>, and optional footer <tt>f</tt>.</t>

<ol>
<li>Before decrypting, first assert that the key being used is intended for use
with <tt>v4.local</tt> tokens. If this assertion fails, abort decryption.</li>
<li>If <tt>f</tt> is not empty, implementations <bcp14>MAY</bcp14> verify that the value appended
to the token matches some expected string <tt>f</tt>, provided they do so using a
constant-time string compare function.</li>
<li>Verify that the message begins with <tt>v4.local.</tt>, otherwise throw an
exception. This constant will be referred to as <tt>h</tt>.</li>
<li><t>Decode the payload (<tt>m</tt> sans <tt>h</tt>, <tt>f</tt>, and the optional trailing period
between <tt>m</tt> and <tt>f</tt>) from base64url to raw binary. Set:</t>

<ul>
<li><tt>n</tt> to the leftmost 32 bytes</li>
<li><tt>c</tt> to the middle remainder of the payload, excluding <tt>n</tt>.</li>
</ul></li>
<li>Split the key into an Encryption key (<tt>Ek</tt>) and Authentication key (<tt>Ak</tt>),
using keyed BLAKE2b, using the domain separation constants and <tt>n</tt> as the
message, and the input key as the key. The first value will be 56 bytes,
the second will be 32 bytes.
The derived key will be the leftmost 32 bytes of the hash output.
The remaining 24 bytes will be used as a counter nonce (<tt>n2</tt>)</li>
<li>Pack <tt>h</tt>, <tt>n</tt>, <tt>c</tt>, <tt>f</tt>, and <tt>i</tt> together (in that order) using
PAE (see <xref target="pae-definition"></xref>). We'll call this <tt>preAuth</tt>.</li>
<li>Re-calculate BLAKE2b-MAC of the output of <tt>preAuth</tt>, using <tt>Ak</tt> as the
authentication key. We'll call this <tt>t2</tt>.</li>
<li><t>Compare <tt>t</tt> with <tt>t2</tt> using a constant-time string compare function. If they
are not identical, throw an exception.</t>

<ul>
<li>You <bcp14>MUST</bcp14> use a constant-time string compare function to be compliant.
If you do not have one available to you in your programming language/framework,
you MUST use <eref target="https://paragonie.com/blog/2015/11/preventing-timing-attacks-on-string-comparison-with-double-hmac-strategy">Double HMAC</eref>.</li>
</ul></li>
<li>Decrypt <tt>c</tt> using <tt>XChaCha20</tt>, store the result in <tt>p</tt>.</li>
<li>If decryption failed, throw an exception. Otherwise, return <tt>p</tt>.</li>
</ol>
<figure><name>Step 4: Key splitting with BLAKE2b.
</name>
<artwork>tmp = crypto_generichash(
    msg = &quot;paseto-encryption-key&quot; || n,
    key = key,
    length = 56
);
Ek = tmp[0:32]
n2 = tmp[32:]
Ak = crypto_generichash(
    msg = &quot;paseto-auth-key-for-aead&quot; || n,
    key = key,
    length = 32
);
</artwork>
</figure>
<figure><name>Steps 5-8: PASETO v4 decryption
</name>
<artwork>preAuth = PASETO.PAE(h, n, c, f, i)
t2 = crypto_generichash(
    message = preAuth
    key = Ak,
    length = 32
);
if (not constant_time_compare(t2, t)) {
    throw new Exception(&quot;Invalid auth tag&quot;);
}
p = crypto_stream_xchacha20_xor(
   ciphertext = c
   nonce = n2
   key = Ek
);
</artwork>
</figure>
</section>

<section anchor="paseto-v4-sign"><name>PASETO.v4.Sign</name>
<t>Given a message <tt>m</tt>, Ed25519 secret key <tt>sk</tt>, and
optional footer <tt>f</tt> (which defaults to empty string):</t>

<ol>
<li>Before signing, first assert that the key being used is intended for use
with <tt>v4.public</tt> tokens, and is a secret key (not a public key). If this
assertion fails, abort signing.</li>
<li>Set <tt>h</tt> to <tt>v4.public.</tt></li>
<li>Pack <tt>h</tt>, <tt>m</tt>, <tt>f</tt>, and <tt>i</tt> together (in that order) using PAE (see
<xref target="pae-definition"></xref>).
We'll call this <tt>m2</tt>.</li>
<li>Sign <tt>m2</tt> using Ed25519 <tt>sk</tt>. We'll call this <tt>sig</tt>.
(See below for pseudocode.)</li>
<li><t>If <tt>f</tt> is:</t>

<ul>
<li>Empty: return h || b64(m || sig)</li>
<li>Non-empty: return h || b64(m || sig) || <tt>.</tt> || b64(f)</li>
<li>...where || means &quot;concatenate&quot;</li>
</ul></li>
</ol>
<figure><name>Step 4: Generating an Ed25519 with libsodium
</name>
<artwork>m2 = PASETO.PAE(h, m, f, i);
sig = crypto_sign_detached(
    message = m2,
    private_key = sk
);
</artwork>
</figure>
</section>

<section anchor="paseto-v4-verify"><name>PASETO.v4.Verify</name>
<t>Given a signed message <tt>sm</tt>, public key <tt>pk</tt>, and optional footer <tt>f</tt>
(which defaults to empty string), and an optional
implicit assertion <tt>i</tt> (which defaults to empty string):</t>

<ol>
<li>Before verifying, first assert that the key being used is intended for use
with <tt>v4.public</tt> tokens, and is a public key (not a secret key). If this
assertion fails, abort verifying.</li>
<li>If <tt>f</tt> is not empty, implementations <bcp14>MAY</bcp14> verify that the value appended
to the token matches some expected string <tt>f</tt>, provided they do so using a
constant-time string compare function.</li>
<li>Verify that the message begins with <tt>v4.public.</tt>, otherwise throw an
exception. This constant will be referred to as <tt>h</tt>.</li>
<li><t>Decode the payload (<tt>sm</tt> sans <tt>h</tt>, <tt>f</tt>, and the optional trailing period
between <tt>m</tt> and <tt>f</tt>) from base64url to raw binary. Set:</t>

<ul>
<li><tt>s</tt> to the rightmost 64 bytes</li>
<li><tt>m</tt> to the leftmost remainder of the payload, excluding <tt>s</tt></li>
</ul></li>
<li>Pack <tt>h</tt>, <tt>m</tt>, <tt>f</tt>, and <tt>i</tt> together (in that order) using PAE (see
<xref target="pae-definition"></xref>).
We'll call this <tt>m2</tt>.</li>
<li>Use Ed25519 to verify that the signature is valid for the message:
(See below for pseudocode.)</li>
<li>If the signature is valid, return <tt>m</tt>. Otherwise, throw an exception.</li>
</ol>
<figure><name>Steps 5-6: Validating the Ed25519 signature using libsodium.
</name>
<artwork>m2 = PASETO.PAE(h, m, f, i);
valid = crypto_sign_verify_detached(
    signature = s,
    message = m2,
    public_key = pk
);
</artwork>
</figure>
</section>
</section>
</section>

<section anchor="payload-processing"><name>Payload Processing</name>
<t>All PASETO payloads <bcp14>MUST</bcp14> be a JSON object <xref target="RFC8259"></xref>.</t>
<t>If non-UTF-8 character sets are desired for some fields, implementors are
encouraged to use <eref target="https://tools.ietf.org/html/rfc4648#page-7">Base64url</eref>
encoding to preserve the original intended binary data, but still use UTF-8 for
the actual payloads.</t>

<section anchor="type-safety-with-cryptographic-keys"><name>Type Safety with Cryptographic Keys</name>
<t>PASETO library implementations <bcp14>MUST</bcp14> implement some means of preventing type
confusion bugs between different cryptography keys. For example:</t>

<ul>
<li>Prepending each key in memory with a magic byte to serve as a type indicator
(distinct for every combination of version and purpose).</li>
<li>In object-oriented programming languages, using separate classes for each
cryptography key object that may share an interface or common base class.</li>
</ul>
<t>Cryptographic keys <bcp14>MUST</bcp14> require the user to state a version and a purpose
for which they will be used. Furthermore, given a cryptographic key, it
<bcp14>MUST NOT</bcp14> be possible for a user to use this key for any version and purpose
combination other than that which was specified during the creation of this key.</t>
</section>

<section anchor="registered-claims"><name>Registered Claims</name>

<section anchor="payload-claims"><name>Payload Claims</name>
<t>The following keys are reserved for use within PASETO payloads. Users <bcp14>MUST NOT</bcp14>
write arbitrary/invalid data to any keys in a top-level PASETO in the list
below:</t>
<table>
<thead>
<tr>
<th>Key</th>
<th>Name</th>
<th>Type</th>
<th>Example</th>
</tr>
</thead>

<tbody>
<tr>
<td>iss</td>
<td>Issuer</td>
<td>string</td>
<td>{&quot;iss&quot;:&quot;paragonie.com&quot;}</td>
</tr>

<tr>
<td>sub</td>
<td>Subject</td>
<td>string</td>
<td>{&quot;sub&quot;:&quot;test&quot;}</td>
</tr>

<tr>
<td>aud</td>
<td>Audience</td>
<td>string</td>
<td>{&quot;aud&quot;:&quot;pie-hosted.com&quot;}</td>
</tr>

<tr>
<td>exp</td>
<td>Expiration</td>
<td>DtTime</td>
<td>{&quot;exp&quot;:&quot;2039-01-01T00:00:00+00:00&quot;}</td>
</tr>

<tr>
<td>nbf</td>
<td>Not Before</td>
<td>DtTime</td>
<td>{&quot;nbf&quot;:&quot;2038-04-01T00:00:00+00:00&quot;}</td>
</tr>

<tr>
<td>iat</td>
<td>Issued At</td>
<td>DtTime</td>
<td>{&quot;iat&quot;:&quot;2038-03-17T00:00:00+00:00&quot;}</td>
</tr>

<tr>
<td>jti</td>
<td>Token ID</td>
<td>string</td>
<td>{&quot;jti&quot;:&quot;87IFSGFgPNtQNNuw0AtuLttP&quot;}</td>
</tr>
</tbody>
</table><t>In the table above, DtTime means an ISO 8601 compliant DateTime string.</t>
<t>Any other claims can be freely used. These keys are only reserved in the
top-level JSON object.</t>
<t>The keys in the above table are case-sensitive.</t>
<t>Implementors (i.e. library designers) <bcp14>SHOULD</bcp14> provide some means to
discourage setting invalid/arbitrary data to these reserved claims.</t>
<t>For example: Storing any string that isn't a valid ISO 8601 DateTime in the
<tt>exp</tt> claim should result in an exception or error state (depending on the
programming language in question).</t>
</section>

<section anchor="optional-footer-claims"><name>Optional Footer Claims</name>
<t>The optional footer <bcp14>MAY</bcp14> contain an optional JSON object <xref target="RFC8259"></xref>.
It does not have to be JSON, but if it is, implementations <bcp14>MUST</bcp14> implement
the safety controls in [#json-handling]. If the optional footer does contain JSON,
the following claims may be stored in the footer.</t>
<t>Users SHOULD NOT write arbitrary/invalid data to any keys in a top-level
PASETO footer in the list below:</t>
<table>
<thead>
<tr>
<th>Key</th>
<th>Name</th>
<th>Type</th>
<th>Example</th>
</tr>
</thead>

<tbody>
<tr>
<td>kid</td>
<td>Key ID</td>
<td>string</td>
<td>{&quot;kid&quot;:&quot;k4.lid.iVtYQDjr5gEijCSjJC3fQaJm7nCeQSeaty0Jixy8dbsk&quot;}</td>
</tr>

<tr>
<td>wpk</td>
<td>Wrapped PASERK</td>
<td>string</td>
<td>{&quot;wpk&quot;:&quot;k4.local-wrap.pie.pu-fBxw... (truncated) ...0eo8iCS&quot;}</td>
</tr>
</tbody>
</table><t>Any other claims can be freely used. These keys are only reserved in the top-level
JSON object (if the footer contains a JSON object).</t>
<t>The keys in the above table are case-sensitive.</t>
<t>Implementors SHOULD provide some means to discourage setting invalid/arbitrary data
to these reserved claims.</t>
</section>

<section anchor="key-id-support"><name>Key-ID Support</name>
<t>Some systems need to support key rotation, but since the payloads of a <em>local</em>
token are always encrypted, it is impractical to store the key id in the
payload.</t>
<t>Instead, users should store Key-ID claims (<em>kid</em>) in the unencrypted footer.</t>
<t>For example, a footer of {&quot;kid&quot;:&quot;gandalf0&quot;} can be read without needing to first
decrypt the token (which would in turn allow the user to know which key to use
to decrypt the token).</t>
<t>Implementations <bcp14>SHOULD</bcp14> provide a means to extract the footer from a PASETO
before authentication and decryption. This is possible for <em>local</em> tokens
because the contents of the footer are <em>not</em> encrypted. However, the
authenticity of the footer is only assured after the authentication tag is
verified.</t>
<t>While a key identifier can generally be safely used for selecting the
cryptographic key used to decrypt and/or verify payloads before verification,
provided that the <em>kid</em> is a public number that is associated with a particular
key which is not supplied by attackers, any other fields stored in the footer
<bcp14>MUST</bcp14> be distrusted until the payload has been verified.</t>
<t>IMPORTANT: Key identifiers <bcp14>MUST</bcp14> be independent of the actual keys used by
PASETO.</t>
<t>A fingerprint of the key is allowed as long as it is impractical for an attacker
to recover the key from said fingerprint.</t>
<t>For example, the user <bcp14>MUST NOT</bcp14> store the public key in the footer for a
<strong>public</strong> token and have the recipient use the provided public key. Doing so
would allow an attacker to replace the public key with one of their own
choosing, which will cause the recipient to accept any signature for any message
as valid, therefore defeating the security goals of public-key cryptography.</t>
<t>Instead, it's recommended that implementors and users use a unique identifier
for each key (independent of the cryptographic key's contents) that is used in a
database or other key-value store to select the appropriate cryptographic key.
These search operations <bcp14>MUST</bcp14> fail closed if no valid key is found for the
given key identifier.</t>
</section>
</section>

<section anchor="optional-footer"><name>Optional Footer</name>
<t>PASETO places no restrictions on the contents of the authenticated footer.
The footer's contents <bcp14>MAY</bcp14> be JSON-encoded (as is the payload), but it
doesn't have to be.</t>
<t>The footer contents is intended to be free-form and application-specific.</t>

<section anchor="storing-json-in-the-footer"><name>Storing JSON in the Footer</name>
<t>Implementations that allow users to store JSON-encoded objects in the footer
<bcp14>MUST</bcp14> give users some mechanism to validate the footer before decoding.</t>
<t>Some example parser rules include:</t>

<ol>
<li>Enforcing a maximum length of the JSON-encoded string.</li>
<li>Enforcing a maximum depth of the decoded JSON object.
(Recommended default: Only 1-dimensional objects.)</li>
<li>Enforcing the maximum number of named keys within an object.</li>
</ol>
<t>The motivation for these additional rules is to mitigate the following
security risks:</t>

<ol>
<li>Stack overflows in JSON parsers caused by too much recursion.</li>
<li>Denial-of-Service attacks enabled by hash-table collisions.</li>
</ol>

<section anchor="enforcing-maximum-depth-without-parsing-the-json-string"><name>Enforcing Maximum Depth Without Parsing the JSON String</name>
<t>Arbitrary-depth JSON strings can be a risk for stack overflows in some JSON
parsing libraries. One mitigation to this is to enforce an upper limit on the
maximum stack depth. Some JSON libraries do not allow you to configure this
upper limit, so you're forced to take matters into your own hands.</t>
<t>A simple way of enforcing the maximum depth of a JSON string without having
to parse it with your JSON library is to employ the following algorithm:</t>

<ol>
<li>Create a copy of the JSON string with all <tt>\&quot;</tt> sequences and whitespace
characters removed.
This will prevent weird edge cases in step 2.</li>
<li>Use a regular expression to remove all quoted strings and their contents.
For example, replacing <tt>/&quot;[^&quot;]+?&quot;([:,\}\]])/</tt> with the first match will
strip the contents of any quoted strings.</li>
<li>Remove all characters except <tt>[</tt>, <tt>{</tt>, <tt>}</tt>, and <tt>]</tt>.</li>
<li>If you're left with an empty string, return <tt>1</tt>.</li>
<li>Initialize a variable called <tt>depth</tt> to <tt>1</tt>.</li>
<li>While the stripped variable is not empty <strong>and</strong> not equal to the output
of the previous iteration, remove all <tt>{}</tt> and <tt>[]</tt> pairs, then increment
<tt>depth</tt>.</li>
<li>If you end up with a non-empty string, you know you have invalid JSON:
Either you have a <tt>[</tt> that isn't paired with a <tt>]</tt>, or a <tt>{</tt> that isn't
paired with a <tt>}</tt>. Throw an exception.</li>
<li>Return <tt>depth</tt>.</li>
</ol>
<t>An example of this logic implemented below:</t>
<figure><name>JSON Depth Calculation
</name>
<artwork>function getJsonDepth(data: string): number {
    // Step 1
    let stripped = data.replace(/\\&quot;/g, '').replace(/\s+/g, '');
    
    // Step 2
    stripped = stripped.replace(/&quot;[^&quot;]+&quot;([:,\}\]])/g, '$1');
    
    // Step 3
    stripped = stripped.replace(/[^\[\{\}\]]/g, '');
    
    // Step 4
    if (stripped.length === 0) {
        return 1;
    }
    // Step 5
    let previous = '';
    let depth = 1;
    
    // Step 6
    while (stripped.length &gt; 0 &amp;&amp; stripped !== previous) {
        previous = stripped;
        stripped = stripped.replace(/({}|\[\])/g, '');
        depth++;
    }
    
    // Step 7
    if (stripped.length &gt; 0) {
        throw new Error(`Invalid JSON string`);
    }
    
    // Step 8
    return depth;
}
</artwork>
</figure>
</section>

<section anchor="enforcing-maximum-key-count-without-parsing-the-json-string"><name>Enforcing Maximum Key Count Without Parsing the JSON String</name>
<t>Hash-collision Denial of Service attacks (Hash-DoS) is made possible by
creating a very large number of keys that will hash to the same value,
with a given hash function (e.g., djb33).</t>
<t>One mitigation strategy is to limit the number of keys contained within
an object (at any arbitrary depth).</t>
<t>The easiest way is to count the number of times you encounter a <tt>&quot;:</tt>
token that isn't followed by a backslash (to side-step corner-cases where
JSON is encoded as a string inside a JSON value).</t>
<figure><name>Counting the number of keys in a JSON object
</name>
<artwork>/**
 * Split the string based on the number of `&quot;:` pairs without a preceding
 * backslash, then return the number of pieces it was broken into.
 */
function countKeys(json: string): number {
    return json.split(/[^\\]&quot;:/).length;
}
</artwork>
</figure>
</section>
</section>
</section>

<section anchor="implicit-assertions"><name>Implicit Assertions</name>
<t>The Optional Footer <xref target="optional-footer"></xref> provides a mechanism for Key IDs
(and therefore key rotation), and thus qualifies as additional authenticated
data when using encryption (local tokens).</t>
<t>Implicit Assertions are an additional layer of additional authenticated data
for a PASETO token. Unlike the optional footer, Implicit Assertions are never
stored in the token payload. They are, however, passed as an input to <tt>PAE()</tt>
<xref target="pae-definition"></xref> when minting or consuming a PASETO token.</t>
<t>Implicit Assertions are useful for cryptographically binding a PASETO token
to a specific domain or context without increasing the size of the payload.</t>
<t>Additionally, Implicit Assertions can be used to bind a token to data too
sensitive to disclose in the payload.</t>
</section>
</section>

<section anchor="intended-use-cases-for-paseto"><name>Intended Use-Cases for PASETO</name>
<t>Like JWTs, PASETOs are intended to be single-use tokens, as there is no built-in
mechanism to prevent replay attacks within the token lifetime.</t>

<ul>
<li><strong>local</strong> tokens are intended for tamper-resistant encrypted cookies or HTTP
request parameters. A resonable example would be long-term authentication
cookies which re-establish a new session cookie if a user checked the
&quot;remember me on this computer&quot; box when authenticating. To accomplish this,
the server would look use the <tt>jti</tt> claim in a database lookup to find the
appropriate user to associate this session with. After each new browsing
session, the <tt>jti</tt> would be rotated in the database and a fresh cookie would
be stored in tbe browser.</li>
<li><strong>public</strong> tokens are intended for one-time authentication claims from a third
party. For example, <strong>public</strong> PASETO would be suitable for a protocol like
OpenID Connect.</li>
</ul>
</section>

<section anchor="security-considerations"><name>Security Considerations</name>
<t>PASETO was designed in part to address known deficits of the JOSE standards
that directly caused insecure implementations.</t>
<t>PASETO uses versioned protocols, rather than in-band negotiation, to prevent
insecure algorithms from being selected. Mix-and-match is not a robust
strategy for usable security engineering, especially when implementations
have insecure default settings.</t>
<t>Cryptography keys in PASETO are defined as a tuple of (version, purpose,
bytes) rather than merely (bytes). This implies that cryptography keys
<bcp14>MUST NOT</bcp14> be used for a different version of PASETO, or for a different
purpose (local, public).</t>
<t>If a severe security vulnerability is ever discovered in one of the specified
versions, a new version of the protocol that is not affected should be decided
by a team of cryptography engineers familiar with the vulnerability in question.
This prevents users from having to rewrite and/or reconfigure their
implementations to side-step the vulnerability.</t>
<t>PASETO implementors should only support the two most recent protocol versions
(currently <strong>PASETO Version 3</strong> and <strong>PASETO Version 4</strong>) at any given time.</t>
<t>PASETO users should beware that, although footers are authenticated, they are
never encrypted. Therefore, sensitive information <bcp14>MUST NOT</bcp14> be stored in a
footer.</t>
<t>Furthermore, PASETO users should beware that, if footers are employed to
implement Key Identification (<strong>kid</strong>), the values stored in the footer
<bcp14>MUST</bcp14> be unrelated to the actual cryptographic key used in verifying the
token as discussed in <xref target="key-id-support"></xref>.</t>
<t>PASETO has no built-in mechanism to resist replay attacks within the token's
lifetime. Users <bcp14>SHOULD NOT</bcp14> attempt to use PASETO to obviate the need for
server-side data storage when designing web applications.</t>
<t>PASETO's cryptography features requires the availability of a secure random
number generator, such as the getrandom(2) syscall on newer Linux distributions,
/dev/urandom on most Unix-like systems, and CryptGenRandom on Windows computers.</t>
<t>The use of userspace pseudo-random number generators, even if seeded by the
operating system's cryptographically secure pseudo-random number generator, is
discouraged.</t>
<t>Implementors <bcp14>MUST NOT</bcp14> skip steps, although they <bcp14>MAY</bcp14> implement multiple
steps in a single code statement.</t>
<t>The &quot;Implicit Assertions&quot; feature <xref target="implicit-assertions"></xref> is intended to provide
a mechanism for additional authenticated data (AAD) that isn't stored in the
token payload.</t>
<t>Applications may leverage this feature to bind tokens to a specific domain or
context, but as it is not stored in the PASETO token, the application is
solely responsible for managing this data. Failure to manage this state will
result in authentication failures and could become a Denial of Service risk.</t>
</section>

<section anchor="iana-considerations"><name>IANA Considerations</name>
<t>The IANA should reserve a new &quot;PASETO Headers&quot; registry for the purpose of this
document and superseding RFCs.</t>
<t>This document defines a suite of string prefixes for PASETO tokens, called
&quot;PASETO Headers&quot; (see <xref target="paseto-message-format"></xref>), which consists of two parts:</t>

<ul>
<li><strong>version</strong>, with values <strong>v3</strong>, <strong>v4</strong> defined above</li>
<li><strong>purpose</strong>, with the values of <strong>local</strong> or <strong>public</strong></li>
</ul>
<t>These two values are concatenated with a single character separator, the ASCII
period character <strong>.</strong>.</t>
<t>Initial values for the &quot;PASETO Headers&quot; registry are given below; future
assignments are to be made through Expert Review <xref target="RFC8126"></xref>, such as the
<eref target="https://irtf.org/cfrg">CFRG</eref>.</t>
<table><name>PASETO Headers and their respective meanings
</name>
<thead>
<tr>
<th>Value</th>
<th>PASETO Header Meaning</th>
<th>Definition</th>
</tr>
</thead>

<tbody>
<tr>
<td>v3.local</td>
<td>Version 3, local</td>
<td><xref target="v3-local"></xref></td>
</tr>

<tr>
<td>v3.public</td>
<td>Version 3, public</td>
<td><xref target="v3-public"></xref></td>
</tr>

<tr>
<td>v4.local</td>
<td>Version 4, local</td>
<td><xref target="v4-local"></xref></td>
</tr>

<tr>
<td>v4.public</td>
<td>Version 4, public</td>
<td><xref target="v4-public"></xref></td>
</tr>
</tbody>
</table><t>Additionally, the IANA should reserve a new &quot;PASETO Claims&quot; registry.</t>
<table>
<thead>
<tr>
<th>Value</th>
<th>PASETO Claim Meaning</th>
</tr>
</thead>

<tbody>
<tr>
<td>iss</td>
<td>Issuer</td>
</tr>

<tr>
<td>sub</td>
<td>Subject</td>
</tr>

<tr>
<td>aud</td>
<td>Audience</td>
</tr>

<tr>
<td>exp</td>
<td>Expiration</td>
</tr>

<tr>
<td>nbf</td>
<td>Not Before</td>
</tr>

<tr>
<td>iat</td>
<td>Issued At</td>
</tr>

<tr>
<td>jti</td>
<td>Token ID</td>
</tr>

<tr>
<td>kid</td>
<td>Key ID</td>
</tr>

<tr>
<td>wpk</td>
<td>Wrapped PASERK</td>
</tr>
</tbody>
</table></section>

</middle>

<back>
<references><name>Normative References</name>
<xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.2119.xml"/>
<xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.3686.xml"/>
<xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.4231.xml"/>
<xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.4648.xml"/>
<xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.5869.xml"/>
<xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.6687.xml"/>
<xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.6979.xml"/>
<xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.7516.xml"/>
<xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.7517.xml"/>
<xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.7518.xml"/>
<xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.7519.xml"/>
<xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.7539.xml"/>
<xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.8017.xml"/>
<xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.8032.xml"/>
<xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.8126.xml"/>
<xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.8259.xml"/>
</references>

<section anchor="paseto-test-vectors"><name>PASETO Test Vectors</name>

<section anchor="paseto-v3-test-vectors"><name>PASETO v3 Test Vectors</name>

<section anchor="v3-local-shared-key-encryption-test-vectors"><name>v3.local (Shared-Key Encryption) Test Vectors</name>

<section anchor="test-vector-v3-e-1"><name>Test Vector v3-E-1</name>

<artwork>Token:      v3.local.AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADbfcIUR
            X_0pVZVU1mAESUzrKZAsRm2EsD6yBoZYn6cpVZNzSJOhSDN-sRaWjfLU-y
            n9OJH1J_B8GKtOQ9gSQlb8yk9Iza7teRdkiR89ZFyvPPsVjjFiepFUVcMa
            -LP18zV77f_crJrVXWa5PDNRkCSeHfBBeg
Key:        70717273 74757677 78797a7b 7c7d7e7f
            80818283 84858687 88898a8b 8c8d8e8f
Nonce:      00000000 00000000 00000000 00000000
            00000000 00000000 00000000 00000000
Payload:    {&quot;data&quot;:&quot;this is a secret message&quot;,
            &quot;exp&quot;:&quot;2022-01-01T00:00:00+00:00&quot;}
Footer:     
Implicit:   
ExpectFail: no
</artwork>
</section>

<section anchor="test-vector-v3-e-2"><name>Test Vector v3-E-2</name>
<t>Same as v3-E-1, but with a slightly different message.</t>

<artwork>Token:      v3.local.AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADbfcIUR
            X_0pVZVU1mAESUzrKZAqhWxBMDgyBoZYn6cpVZNzSJOhSDN-sRaWjfLU-y
            n9OJH1J_B8GKtOQ9gSQlb8yk9IzZfaZpReVpHlDSwfuygx1riVXYVs-Ujc
            rG_apl9oz3jCVmmJbRuKn5ZfD8mHz2db0A
Key:        70717273 74757677 78797a7b 7c7d7e7f
            80818283 84858687 88898a8b 8c8d8e8f
Nonce:      00000000 00000000 00000000 00000000
            00000000 00000000 00000000 00000000
Payload:    {&quot;data&quot;:&quot;this is a hidden message&quot;,
            &quot;exp&quot;:&quot;2022-01-01T00:00:00+00:00&quot;}
Footer:     
Implicit:   
ExpectFail: no
</artwork>
</section>

<section anchor="test-vector-v3-e-3"><name>Test Vector v3-E-3</name>

<artwork>Token:      v3.local.JvdVM1RIKh2R1HhGJ4VLjaa4BCp5ZlI8K0BOjbvn9_LwY78vQ
            nDait-Q-sjhF88dG2B0ROIIykcrGHn8wzPbTrqObHhyoKpjy3cwZQzLdiw
            RsdEK5SDvl02_HjWKJW2oqGMOQJlxnt5xyhQjFJomwnt7WW_7r2VT0G704
            ifult011-TgLCyQ2X8imQhniG_hAQ4BydM
Key:        70717273 74757677 78797a7b 7c7d7e7f
            80818283 84858687 88898a8b 8c8d8e8f
Nonce:      26f75533 54482a1d 91d47846 27854b8d
            a6b8042a 7966523c 2b404e8d bbe7f7f2
Payload:    {&quot;data&quot;:&quot;this is a secret message&quot;,
            &quot;exp&quot;:&quot;2022-01-01T00:00:00+00:00&quot;}
Footer:     
Implicit:   
ExpectFail: no
</artwork>
</section>

<section anchor="test-vector-v3-e-4"><name>Test Vector v3-E-4</name>
<t>Same as v3-E-3, but with a slightly different message.</t>

<artwork>Token:      v3.local.JvdVM1RIKh2R1HhGJ4VLjaa4BCp5ZlI8K0BOjbvn9_LwY78vQ
            nDait-Q-sjhF88dG2B0X-4P3EcxGHn8wzPbTrqObHhyoKpjy3cwZQzLdiw
            RsdEK5SDvl02_HjWKJW2oqGMOQJlBZa_gOpVj4gv0M9lV6Pwjp8JS_MmaZ
            aTA1LLTULXybOBZ2S4xMbYqYmDRhh3IgEk
Key:        70717273 74757677 78797a7b 7c7d7e7f
            80818283 84858687 88898a8b 8c8d8e8f
Nonce:      26f75533 54482a1d 91d47846 27854b8d
            a6b8042a 7966523c 2b404e8d bbe7f7f2
Payload:    {&quot;data&quot;:&quot;this is a hidden message&quot;,
            &quot;exp&quot;:&quot;2022-01-01T00:00:00+00:00&quot;}
Footer:     
Implicit:   
ExpectFail: no
</artwork>
</section>

<section anchor="test-vector-v3-e-5"><name>Test Vector v3-E-5</name>

<artwork>Token:      v3.local.JvdVM1RIKh2R1HhGJ4VLjaa4BCp5ZlI8K0BOjbvn9_LwY78vQ
            nDait-Q-sjhF88dG2B0ROIIykcrGHn8wzPbTrqObHhyoKpjy3cwZQzLdiw
            RsdEK5SDvl02_HjWKJW2oqGMOQJlkYSIbXOgVuIQL65UMdW9WcjOpmqvjq
            D40NNzed-XPqn1T3w-bJvitYpUJL_rmihc.eyJraWQiOiJVYmtLOFk2aXY
            0R1poRnA2VHgzSVdMV0xmTlhTRXZKY2RUM3pkUjY1WVp4byJ9
Key:        70717273 74757677 78797a7b 7c7d7e7f
            80818283 84858687 88898a8b 8c8d8e8f
Nonce:      26f75533 54482a1d 91d47846 27854b8d
            a6b8042a 7966523c 2b404e8d bbe7f7f2
Payload:    {&quot;data&quot;:&quot;this is a secret message&quot;,
            &quot;exp&quot;:&quot;2022-01-01T00:00:00+00:00&quot;}
Footer:     {&quot;kid&quot;:&quot;UbkK8Y6iv4GZhFp6Tx3IWLWLfNXSEvJcdT3zdR65YZxo&quot;}
Implicit:   
ExpectFail: no
</artwork>
</section>

<section anchor="test-vector-v3-e-6"><name>Test Vector v3-E-6</name>
<t>Same as v3-E-5, but with a slightly different message.</t>

<artwork>Token:      v3.local.JvdVM1RIKh2R1HhGJ4VLjaa4BCp5ZlI8K0BOjbvn9_LwY78vQ
            nDait-Q-sjhF88dG2B0X-4P3EcxGHn8wzPbTrqObHhyoKpjy3cwZQzLdiw
            RsdEK5SDvl02_HjWKJW2oqGMOQJmSeEMphEWHiwtDKJftg41O1F8Hat-8k
            Q82ZIAMFqkx9q5VkWlxZke9ZzMBbb3Znfo.eyJraWQiOiJVYmtLOFk2aXY
            0R1poRnA2VHgzSVdMV0xmTlhTRXZKY2RUM3pkUjY1WVp4byJ9
Key:        70717273 74757677 78797a7b 7c7d7e7f
            80818283 84858687 88898a8b 8c8d8e8f
Nonce:      26f75533 54482a1d 91d47846 27854b8d
            a6b8042a 7966523c 2b404e8d bbe7f7f2
Payload:    {&quot;data&quot;:&quot;this is a hidden message&quot;,
            &quot;exp&quot;:&quot;2022-01-01T00:00:00+00:00&quot;}
Footer:     {&quot;kid&quot;:&quot;UbkK8Y6iv4GZhFp6Tx3IWLWLfNXSEvJcdT3zdR65YZxo&quot;}
Implicit:   
ExpectFail: no
</artwork>
</section>

<section anchor="test-vector-v3-e-7"><name>Test Vector v3-E-7</name>

<artwork>Token:      v3.local.JvdVM1RIKh2R1HhGJ4VLjaa4BCp5ZlI8K0BOjbvn9_LwY78vQ
            nDait-Q-sjhF88dG2B0ROIIykcrGHn8wzPbTrqObHhyoKpjy3cwZQzLdiw
            RsdEK5SDvl02_HjWKJW2oqGMOQJkzWACWAIoVa0bz7EWSBoTEnS8MvGBYH
            Ho6t6mJunPrFR9JKXFCc0obwz5N-pxFLOc.eyJraWQiOiJVYmtLOFk2aXY
            0R1poRnA2VHgzSVdMV0xmTlhTRXZKY2RUM3pkUjY1WVp4byJ9
Key:        70717273 74757677 78797a7b 7c7d7e7f
            80818283 84858687 88898a8b 8c8d8e8f
Nonce:      26f75533 54482a1d 91d47846 27854b8d
            a6b8042a 7966523c 2b404e8d bbe7f7f2
Payload:    {&quot;data&quot;:&quot;this is a secret message&quot;,
            &quot;exp&quot;:&quot;2022-01-01T00:00:00+00:00&quot;}
Footer:     {&quot;kid&quot;:&quot;UbkK8Y6iv4GZhFp6Tx3IWLWLfNXSEvJcdT3zdR65YZxo&quot;}
Implicit:   {&quot;test-vector&quot;:&quot;3-E-7&quot;}
ExpectFail: no
</artwork>
</section>

<section anchor="test-vector-v3-e-8"><name>Test Vector v3-E-8</name>
<t>Same as v3-E-7, but with a slightly different message and implicit assertion.</t>

<artwork>Token:      v3.local.JvdVM1RIKh2R1HhGJ4VLjaa4BCp5ZlI8K0BOjbvn9_LwY78vQ
            nDait-Q-sjhF88dG2B0X-4P3EcxGHn8wzPbTrqObHhyoKpjy3cwZQzLdiw
            RsdEK5SDvl02_HjWKJW2oqGMOQJmZHSSKYR6AnPYJV6gpHtx6dLakIG_AO
            Phu8vKexNyrv5_1qoom6_NaPGecoiz6fR8.eyJraWQiOiJVYmtLOFk2aXY
            0R1poRnA2VHgzSVdMV0xmTlhTRXZKY2RUM3pkUjY1WVp4byJ9
Key:        70717273 74757677 78797a7b 7c7d7e7f
            80818283 84858687 88898a8b 8c8d8e8f
Nonce:      26f75533 54482a1d 91d47846 27854b8d
            a6b8042a 7966523c 2b404e8d bbe7f7f2
Payload:    {&quot;data&quot;:&quot;this is a hidden message&quot;,
            &quot;exp&quot;:&quot;2022-01-01T00:00:00+00:00&quot;}
Footer:     {&quot;kid&quot;:&quot;UbkK8Y6iv4GZhFp6Tx3IWLWLfNXSEvJcdT3zdR65YZxo&quot;}
Implicit:   {&quot;test-vector&quot;:&quot;3-E-8&quot;}
ExpectFail: no
</artwork>
</section>

<section anchor="test-vector-v3-e-9"><name>Test Vector v3-E-9</name>

<artwork>Token:      v3.local.JvdVM1RIKh2R1HhGJ4VLjaa4BCp5ZlI8K0BOjbvn9_LwY78vQ
            nDait-Q-sjhF88dG2B0X-4P3EcxGHn8wzPbTrqObHhyoKpjy3cwZQzLdiw
            RsdEK5SDvl02_HjWKJW2oqGMOQJlk1nli0_wijTH_vCuRwckEDc82QWK8-
            lG2fT9wQF271sgbVRVPjm0LwMQZkvvamqU.YXJiaXRyYXJ5LXN0cmluZy1
            0aGF0LWlzbid0LWpzb24
Key:        70717273 74757677 78797a7b 7c7d7e7f
            80818283 84858687 88898a8b 8c8d8e8f
Nonce:      26f75533 54482a1d 91d47846 27854b8d
            a6b8042a 7966523c 2b404e8d bbe7f7f2
Payload:    {&quot;data&quot;:&quot;this is a hidden message&quot;,
            &quot;exp&quot;:&quot;2022-01-01T00:00:00+00:00&quot;}
Footer:     arbitrary-string-that-isn't-json
Implicit:   {&quot;test-vector&quot;:&quot;3-E-9&quot;}
ExpectFail: no
</artwork>
</section>
</section>

<section anchor="v3-public-public-key-authentication-test-vectors"><name>v3.public (Public-Key Authentication) Test Vectors</name>

<section anchor="test-vector-v3-s-1"><name>Test Vector v3-S-1</name>

<artwork>Token:       v3.public.eyJkYXRhIjoidGhpcyBpcyBhIHNpZ25lZCBtZXNzYWdlIiwi
             ZXhwIjoiMjAyMi0wMS0wMVQwMDowMDowMCswMDowMCJ9qqEwwrKHKi5lJ7
             b9MBKc0G4MGZy0ptUiMv3lAUAaz-JY_zjoqBSIxMxhfAoeNYiSyvfUErj7
             6KOPWm1OeNnBPkTSespeSXDGaDfxeIrl3bRrPEIy7tLwLAIsRzsXkfph
Secret key:  -----BEGIN EC PRIVATE KEY-----
             MIGkAgEBBDAgNHYJYHR3rKj7+8XmIYRV8xmWaXku+LRm+qh73Gd5gUTISN
             0DZh7tWsYkYTQM6pagBwYFK4EEACKhZANiAAT7y3xp7hxgV5vnozQTSHjZ
             xcW/NdVS2rY8AUA5ftFM72N9dyCSXERpnqMOcodMcvt8kgcrB8KcKee0HU
             23E79/s4CvEs8hBfnjSUd/gcAm08EjSIz06iWjrNy4NakxR3I=
             -----END EC PRIVATE KEY-----
Public Key:  -----BEGIN PUBLIC KEY-----
             MHYwEAYHKoZIzj0CAQYFK4EEACIDYgAE+8t8ae4cYFeb56M0E0h42cXFvz
             XVUtq2PAFAOX7RTO9jfXcgklxEaZ6jDnKHTHL7fJIHKwfCnCnntB1NtxO/
             f7OArxLPIQX540lHf4HAJtPBI0iM9Oolo6zcuDWpMUdy
             -----END PUBLIC KEY-----
Payload:     {&quot;data&quot;:&quot;this is a signed message&quot;,
             &quot;exp&quot;:&quot;2022-01-01T00:00:00+00:00&quot;}
Footer:      
Implicit:    
ExpectFail:  no
</artwork>
</section>

<section anchor="test-vector-v3-s-2"><name>Test Vector v3-S-2</name>

<artwork>Token:       v3.public.eyJkYXRhIjoidGhpcyBpcyBhIHNpZ25lZCBtZXNzYWdlIiwi
             ZXhwIjoiMjAyMi0wMS0wMVQwMDowMDowMCswMDowMCJ9ZWrbGZ6L0MDK72
             skosUaS0Dz7wJ_2bMcM6tOxFuCasO9GhwHrvvchqgXQNLQQyWzGC2wkr-V
             KII71AvkLpC8tJOrzJV1cap9NRwoFzbcXjzMZyxQ0wkshxZxx8ImmNWP.e
             yJraWQiOiJkWWtJU3lseFFlZWNFY0hFTGZ6Rjg4VVpyd2JMb2xOaUNkcHp
             VSEd3OVVxbiJ9
Secret key:  -----BEGIN EC PRIVATE KEY-----
             MIGkAgEBBDAgNHYJYHR3rKj7+8XmIYRV8xmWaXku+LRm+qh73Gd5gUTISN
             0DZh7tWsYkYTQM6pagBwYFK4EEACKhZANiAAT7y3xp7hxgV5vnozQTSHjZ
             xcW/NdVS2rY8AUA5ftFM72N9dyCSXERpnqMOcodMcvt8kgcrB8KcKee0HU
             23E79/s4CvEs8hBfnjSUd/gcAm08EjSIz06iWjrNy4NakxR3I=
             -----END EC PRIVATE KEY-----
Public Key:  -----BEGIN PUBLIC KEY-----
             MHYwEAYHKoZIzj0CAQYFK4EEACIDYgAE+8t8ae4cYFeb56M0E0h42cXFvz
             XVUtq2PAFAOX7RTO9jfXcgklxEaZ6jDnKHTHL7fJIHKwfCnCnntB1NtxO/
             f7OArxLPIQX540lHf4HAJtPBI0iM9Oolo6zcuDWpMUdy
             -----END PUBLIC KEY-----
Payload:     {&quot;data&quot;:&quot;this is a signed message&quot;,
             &quot;exp&quot;:&quot;2022-01-01T00:00:00+00:00&quot;}
Footer:      {&quot;kid&quot;:&quot;dYkISylxQeecEcHELfzF88UZrwbLolNiCdpzUHGw9Uqn&quot;}
Implicit:    
ExpectFail:  no
</artwork>
</section>

<section anchor="test-vector-v3-s-3"><name>Test Vector v3-S-3</name>

<artwork>Token:       v3.public.eyJkYXRhIjoidGhpcyBpcyBhIHNpZ25lZCBtZXNzYWdlIiwi
             ZXhwIjoiMjAyMi0wMS0wMVQwMDowMDowMCswMDowMCJ94SjWIbjmS7715G
             jLSnHnpJrC9Z-cnwK45dmvnVvCRQDCCKAXaKEopTajX0DKYx1Xqr6gcTdf
             qscLCAbiB4eOW9jlt-oNqdG8TjsYEi6aloBfTzF1DXff_45tFlnBukEX.e
             yJraWQiOiJkWWtJU3lseFFlZWNFY0hFTGZ6Rjg4VVpyd2JMb2xOaUNkcHp
             VSEd3OVVxbiJ9
Secret key:  -----BEGIN EC PRIVATE KEY-----
             MIGkAgEBBDAgNHYJYHR3rKj7+8XmIYRV8xmWaXku+LRm+qh73Gd5gUTISN
             0DZh7tWsYkYTQM6pagBwYFK4EEACKhZANiAAT7y3xp7hxgV5vnozQTSHjZ
             xcW/NdVS2rY8AUA5ftFM72N9dyCSXERpnqMOcodMcvt8kgcrB8KcKee0HU
             23E79/s4CvEs8hBfnjSUd/gcAm08EjSIz06iWjrNy4NakxR3I=
             -----END EC PRIVATE KEY-----
Public Key:  -----BEGIN PUBLIC KEY-----
             MHYwEAYHKoZIzj0CAQYFK4EEACIDYgAE+8t8ae4cYFeb56M0E0h42cXFvz
             XVUtq2PAFAOX7RTO9jfXcgklxEaZ6jDnKHTHL7fJIHKwfCnCnntB1NtxO/
             f7OArxLPIQX540lHf4HAJtPBI0iM9Oolo6zcuDWpMUdy
             -----END PUBLIC KEY-----
Payload:     {&quot;data&quot;:&quot;this is a signed message&quot;,
             &quot;exp&quot;:&quot;2022-01-01T00:00:00+00:00&quot;}
Footer:      {&quot;kid&quot;:&quot;dYkISylxQeecEcHELfzF88UZrwbLolNiCdpzUHGw9Uqn&quot;}
Implicit:    {&quot;test-vector&quot;:&quot;3-S-3&quot;}
ExpectFail:  no
</artwork>
</section>

<section anchor="test-vector-v3-f-1"><name>Test Vector v3-F-1</name>
<t>This test vector <bcp14>MUST</bcp14> fail, because the keys are not meant for local
tokens.</t>

<artwork>Token:       v3.local.tthw-G1Da_BzYeMu_GEDp-IyQ7jzUCQHxCHRdDY6hQjKg6Cux
             ECXfjOzlmNgNJ-WELjN61gMDnldG9OLkr3wpxuqdZksCzH9Ul16t3pXCLG
             PoHQ9_l51NOqVmMLbFVZOPhsmdhef9RxJwmqvzQ_Mo_JkYRlrNA.YXJiaX
             RyYXJ5LXN0cmluZy10aGF0LWlzbid0LWpzb24
Secret key:  -----BEGIN EC PRIVATE KEY-----
             MIGkAgEBBDAgNHYJYHR3rKj7+8XmIYRV8xmWaXku+LRm+qh73Gd5gUTISN
             0DZh7tWsYkYTQM6pagBwYFK4EEACKhZANiAAT7y3xp7hxgV5vnozQTSHjZ
             xcW/NdVS2rY8AUA5ftFM72N9dyCSXERpnqMOcodMcvt8kgcrB8KcKee0HU
             23E79/s4CvEs8hBfnjSUd/gcAm08EjSIz06iWjrNy4NakxR3I=
             -----END EC PRIVATE KEY-----
Public Key:  -----BEGIN PUBLIC KEY-----
             MHYwEAYHKoZIzj0CAQYFK4EEACIDYgAE+8t8ae4cYFeb56M0E0h42cXFvz
             XVUtq2PAFAOX7RTO9jfXcgklxEaZ6jDnKHTHL7fJIHKwfCnCnntB1NtxO/
             f7OArxLPIQX540lHf4HAJtPBI0iM9Oolo6zcuDWpMUdy
             -----END PUBLIC KEY-----
Payload:     
Footer:      arbitrary-string-that-isn't-json
Implicit:    {&quot;test-vector&quot;:&quot;3-F-1&quot;}
ExpectFail:  YES
</artwork>
</section>

<section anchor="test-vector-v3-f-2"><name>Test Vector v3-F-2</name>
<t>This test vector <bcp14>MUST</bcp14> fail, because the key is not meant for public
tokens.</t>

<artwork>Token:       v3.public.eyJpbnZhbGlkIjoidGhpcyBzaG91bGQgbmV2ZXIgZGVjb2Rl
             In1hbzIBD_EU54TYDTvsN9bbCU1QPo7FDeIhijkkcB9BrVH73XyM3Wwvu1
             pJaGCOEc0R5DVe9hb1ka1cYBd0goqVHt0NQ2NhPtILz4W36eCCqyU4uV6x
             DMeLI8ni6r3GnaY.eyJraWQiOiJ6VmhNaVBCUDlmUmYyc25FY1Q3Z0ZUaW
             9lQTlDT2NOeTlEZmdMMVc2MGhhTiJ9
Key:         70717273 74757677 78797a7b 7c7d7e7f
             80818283 84858687 88898a8b 8c8d8e8f
Nonce:       df654812 bac49266 3825520b a2f6e67c
             f5ca5bdc 13d4e750 7a98cc4c 2fcc3ad8
Payload:     
Footer:      {&quot;kid&quot;:&quot;zVhMiPBP9fRf2snEcT7gFTioeA9COcNy9DfgL1W60haN&quot;}
Implicit:    {&quot;test-vector&quot;:&quot;3-F-2&quot;}
ExpectFail:  YES
</artwork>
</section>

<section anchor="test-vector-v3-f-3"><name>Test Vector v3-F-3</name>
<t>This test vector <bcp14>MUST</bcp14> fail, because token is Version 4 while we're
operating in Version 3.</t>

<artwork>Token:      v4.local.1JgN1UG8TFAYS49qsx8rxlwh-9E4ONUm3slJXYi5EibmzxpF0
            Q-du6gakjuyKCBX8TvnSLOKqCPu8Yh3WSa5yJWigPy33z9XZTJF2HQ9wlL
            DPtVn_Mu1pPxkTU50ZaBKblJBufRA.YXJiaXRyYXJ5LXN0cmluZy10aGF0
            LWlzbid0LWpzb24
Key:        70717273 74757677 78797a7b 7c7d7e7f
            80818283 84858687 88898a8b 8c8d8e8f
Nonce:      26f75533 54482a1d 91d47846 27854b8d
            a6b8042a 7966523c 2b404e8d bbe7f7f2
Payload:    
Footer:     arbitrary-string-that-isn't-json
Implicit:   {&quot;test-vector&quot;:&quot;3-F-3&quot;}
ExpectFail: YES
</artwork>
</section>
</section>
</section>

<section anchor="paseto-v4-test-vectors"><name>PASETO v4 Test Vectors</name>

<section anchor="v4-local-shared-key-encryption-test-vectors"><name>v4.local (Shared-Key Encryption) Test Vectors</name>

<section anchor="test-vector-v4-e-1"><name>Test Vector v4-E-1</name>

<artwork>Token:      v4.local.AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAr68P
            S4AXe7If_ZgesdkUMvSwscFlAl1pk5HC0e8kApeaqMfGo_7OpBnwJOAbY9
            V7WU6abu74MmcUE8YWAiaArVI8XJ5hOb_4v9RmDkneN0S92dx0OW4pgy7o
            mxgf3S8c3LlQg
Key:        70717273 74757677 78797a7b 7c7d7e7f
            80818283 84858687 88898a8b 8c8d8e8f
Nonce:      00000000 00000000 00000000 00000000
            00000000 00000000 00000000 00000000
Payload:    {&quot;data&quot;:&quot;this is a secret message&quot;,
            &quot;exp&quot;:&quot;2022-01-01T00:00:00+00:00&quot;}
Footer:     
Implicit:   
ExpectFail: no
</artwork>
</section>

<section anchor="test-vector-v4-e-2"><name>Test Vector v4-E-2</name>
<t>Same as v4-E-1, but with a slightly different message.</t>

<artwork>Token:      v4.local.AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAr68P
            S4AXe7If_ZgesdkUMvS2csCgglvpk5HC0e8kApeaqMfGo_7OpBnwJOAbY9
            V7WU6abu74MmcUE8YWAiaArVI8XIemu9chy3WVKvRBfg6t8wwYHK0ArLxx
            fZP73W_vfwt5A
Key:        70717273 74757677 78797a7b 7c7d7e7f
            80818283 84858687 88898a8b 8c8d8e8f
Nonce:      00000000 00000000 00000000 00000000
            00000000 00000000 00000000 00000000
Payload:    {&quot;data&quot;:&quot;this is a hidden message&quot;,
            &quot;exp&quot;:&quot;2022-01-01T00:00:00+00:00&quot;}
Footer:     
Implicit:   
ExpectFail: no
</artwork>
</section>

<section anchor="test-vector-v4-e-3"><name>Test Vector v4-E-3</name>

<artwork>Token:      v4.local.32VIErrEkmY4JVILovbmfPXKW9wT1OdQepjMTC_MOtjA4kiqw
            7_tcaOM5GNEcnTxl60WkwMsYXw6FSNb_UdJPXjpzm0KW9ojM5f4O2mRvE2
            IcweP-PRdoHjd5-RHCiExR1IK6t6-tyebyWG6Ov7kKvBdkrrAJ837lKP3i
            Dag2hzUPHuMKA
Key:        70717273 74757677 78797a7b 7c7d7e7f
            80818283 84858687 88898a8b 8c8d8e8f
Nonce:      df654812 bac49266 3825520b a2f6e67c
            f5ca5bdc 13d4e750 7a98cc4c 2fcc3ad8
Payload:    {&quot;data&quot;:&quot;this is a secret message&quot;,
            &quot;exp&quot;:&quot;2022-01-01T00:00:00+00:00&quot;}
Footer:     
Implicit:   
ExpectFail: no
</artwork>
</section>

<section anchor="test-vector-v4-e-4"><name>Test Vector v4-E-4</name>
<t>Same as v4-E-3, but with a slightly different message.</t>

<artwork>Token:      v4.local.32VIErrEkmY4JVILovbmfPXKW9wT1OdQepjMTC_MOtjA4kiqw
            7_tcaOM5GNEcnTxl60WiA8rd3wgFSNb_UdJPXjpzm0KW9ojM5f4O2mRvE2
            IcweP-PRdoHjd5-RHCiExR1IK6t4gt6TiLm55vIH8c_lGxxZpE3AWlH4WT
            R0v45nsWoU3gQ
Key:        70717273 74757677 78797a7b 7c7d7e7f
            80818283 84858687 88898a8b 8c8d8e8f
Nonce:      df654812 bac49266 3825520b a2f6e67c
            f5ca5bdc 13d4e750 7a98cc4c 2fcc3ad8
Payload:    {&quot;data&quot;:&quot;this is a hidden message&quot;,
            &quot;exp&quot;:&quot;2022-01-01T00:00:00+00:00&quot;}
Footer:     
Implicit:   
ExpectFail: no
</artwork>
</section>

<section anchor="test-vector-v4-e-5"><name>Test Vector v4-E-5</name>

<artwork>Token:      v4.local.32VIErrEkmY4JVILovbmfPXKW9wT1OdQepjMTC_MOtjA4kiqw
            7_tcaOM5GNEcnTxl60WkwMsYXw6FSNb_UdJPXjpzm0KW9ojM5f4O2mRvE2
            IcweP-PRdoHjd5-RHCiExR1IK6t4x-RMNXtQNbz7FvFZ_G-lFpk5RG3EOr
            wDL6CgDqcerSQ.eyJraWQiOiJ6VmhNaVBCUDlmUmYyc25FY1Q3Z0ZUaW9l
            QTlDT2NOeTlEZmdMMVc2MGhhTiJ9
Key:        70717273 74757677 78797a7b 7c7d7e7f
            80818283 84858687 88898a8b 8c8d8e8f
Nonce:      df654812 bac49266 3825520b a2f6e67c
            f5ca5bdc 13d4e750 7a98cc4c 2fcc3ad8
Payload:    {&quot;data&quot;:&quot;this is a secret message&quot;,
            &quot;exp&quot;:&quot;2022-01-01T00:00:00+00:00&quot;}
Footer:     {&quot;kid&quot;:&quot;zVhMiPBP9fRf2snEcT7gFTioeA9COcNy9DfgL1W60haN&quot;}
Implicit:   
ExpectFail: no
</artwork>
</section>

<section anchor="test-vector-v4-e-6"><name>Test Vector v4-E-6</name>
<t>Same as v4-E-5, but with a slightly different message.</t>

<artwork>Token:      v4.local.32VIErrEkmY4JVILovbmfPXKW9wT1OdQepjMTC_MOtjA4kiqw
            7_tcaOM5GNEcnTxl60WiA8rd3wgFSNb_UdJPXjpzm0KW9ojM5f4O2mRvE2
            IcweP-PRdoHjd5-RHCiExR1IK6t6pWSA5HX2wjb3P-xLQg5K5feUCX4P2f
            pVK3ZLWFbMSxQ.eyJraWQiOiJ6VmhNaVBCUDlmUmYyc25FY1Q3Z0ZUaW9l
            QTlDT2NOeTlEZmdMMVc2MGhhTiJ9
Key:        70717273 74757677 78797a7b 7c7d7e7f
            80818283 84858687 88898a8b 8c8d8e8f
Nonce:      df654812 bac49266 3825520b a2f6e67c
            f5ca5bdc 13d4e750 7a98cc4c 2fcc3ad8
Payload:    {&quot;data&quot;:&quot;this is a hidden message&quot;,
            &quot;exp&quot;:&quot;2022-01-01T00:00:00+00:00&quot;}
Footer:     {&quot;kid&quot;:&quot;zVhMiPBP9fRf2snEcT7gFTioeA9COcNy9DfgL1W60haN&quot;}
Implicit:   
ExpectFail: no
</artwork>
</section>

<section anchor="test-vector-v4-e-7"><name>Test Vector v4-E-7</name>

<artwork>Token:      v4.local.32VIErrEkmY4JVILovbmfPXKW9wT1OdQepjMTC_MOtjA4kiqw
            7_tcaOM5GNEcnTxl60WkwMsYXw6FSNb_UdJPXjpzm0KW9ojM5f4O2mRvE2
            IcweP-PRdoHjd5-RHCiExR1IK6t40KCCWLA7GYL9KFHzKlwY9_RnIfRrMQ
            pueydLEAZGGcA.eyJraWQiOiJ6VmhNaVBCUDlmUmYyc25FY1Q3Z0ZUaW9l
            QTlDT2NOeTlEZmdMMVc2MGhhTiJ9
Key:        70717273 74757677 78797a7b 7c7d7e7f
            80818283 84858687 88898a8b 8c8d8e8f
Nonce:      df654812 bac49266 3825520b a2f6e67c
            f5ca5bdc 13d4e750 7a98cc4c 2fcc3ad8
Payload:    {&quot;data&quot;:&quot;this is a secret message&quot;,
            &quot;exp&quot;:&quot;2022-01-01T00:00:00+00:00&quot;}
Footer:     {&quot;kid&quot;:&quot;zVhMiPBP9fRf2snEcT7gFTioeA9COcNy9DfgL1W60haN&quot;}
Implicit:   {&quot;test-vector&quot;:&quot;4-E-7&quot;}
ExpectFail: no
</artwork>
</section>

<section anchor="test-vector-v4-e-8"><name>Test Vector v4-E-8</name>
<t>Same as v4-E-7, but with a slightly different message and implicit assertion.</t>

<artwork>Token:      v4.local.32VIErrEkmY4JVILovbmfPXKW9wT1OdQepjMTC_MOtjA4kiqw
            7_tcaOM5GNEcnTxl60WiA8rd3wgFSNb_UdJPXjpzm0KW9ojM5f4O2mRvE2
            IcweP-PRdoHjd5-RHCiExR1IK6t5uvqQbMGlLLNYBc7A6_x7oqnpUK5WLv
            j24eE4DVPDZjw.eyJraWQiOiJ6VmhNaVBCUDlmUmYyc25FY1Q3Z0ZUaW9l
            QTlDT2NOeTlEZmdMMVc2MGhhTiJ9
Key:        70717273 74757677 78797a7b 7c7d7e7f
            80818283 84858687 88898a8b 8c8d8e8f
Nonce:      df654812 bac49266 3825520b a2f6e67c
            f5ca5bdc 13d4e750 7a98cc4c 2fcc3ad8
Payload:    {&quot;data&quot;:&quot;this is a hidden message&quot;,
            &quot;exp&quot;:&quot;2022-01-01T00:00:00+00:00&quot;}
Footer:     {&quot;kid&quot;:&quot;zVhMiPBP9fRf2snEcT7gFTioeA9COcNy9DfgL1W60haN&quot;}
Implicit:   {&quot;test-vector&quot;:&quot;4-E-8&quot;}
ExpectFail: no
</artwork>
</section>

<section anchor="test-vector-v4-e-9"><name>Test Vector v4-E-9</name>

<artwork>Token:      v4.local.32VIErrEkmY4JVILovbmfPXKW9wT1OdQepjMTC_MOtjA4kiqw
            7_tcaOM5GNEcnTxl60WiA8rd3wgFSNb_UdJPXjpzm0KW9ojM5f4O2mRvE2
            IcweP-PRdoHjd5-RHCiExR1IK6t6tybdlmnMwcDMw0YxA_gFSE_IUWl78a
            MtOepFYSWYfQA.YXJiaXRyYXJ5LXN0cmluZy10aGF0LWlzbid0LWpzb24
Key:        70717273 74757677 78797a7b 7c7d7e7f
            80818283 84858687 88898a8b 8c8d8e8f
Nonce:      df654812 bac49266 3825520b a2f6e67c
            f5ca5bdc 13d4e750 7a98cc4c 2fcc3ad8
Payload:    {&quot;data&quot;:&quot;this is a hidden message&quot;,
            &quot;exp&quot;:&quot;2022-01-01T00:00:00+00:00&quot;}
Footer:     arbitrary-string-that-isn't-json
Implicit:   {&quot;test-vector&quot;:&quot;4-E-9&quot;}
ExpectFail: no
</artwork>
</section>
</section>

<section anchor="v4-public-public-key-authentication-test-vectors"><name>v4.public (Public-Key Authentication) Test Vectors</name>

<section anchor="test-vector-v4-s-1"><name>Test Vector v4-S-1</name>

<artwork>Token:      v4.public.eyJkYXRhIjoidGhpcyBpcyBhIHNpZ25lZCBtZXNzYWdlIiwi
            ZXhwIjoiMjAyMi0wMS0wMVQwMDowMDowMCswMDowMCJ9bg_XBBzds8lTZS
            hVlwwKSgeKpLT3yukTw6JUz3W4h_ExsQV-P0V54zemZDcAxFaSeef1QlXE
            FtkqxT1ciiQEDA
Secret Key: b4cbfb43 df4ce210 727d953e 4a713307
            fa19bb7d 9f850414 38d9e11b 942a3774
            1eb9dbbb bc047c03 fd70604e 0071f098
            7e16b28b 757225c1 1f00415d 0e20b1a2
Public Key: 1eb9dbbb bc047c03 fd70604e 0071f098
            7e16b28b 757225c1 1f00415d 0e20b1a2
Payload:    {&quot;data&quot;:&quot;this is a signed message&quot;,
            &quot;exp&quot;:&quot;2022-01-01T00:00:00+00:00&quot;}
Footer:     
Implicit:   
ExpectFail: no
</artwork>
</section>

<section anchor="test-vector-v4-s-2"><name>Test Vector v4-S-2</name>

<artwork>Token:      v4.public.eyJkYXRhIjoidGhpcyBpcyBhIHNpZ25lZCBtZXNzYWdlIiwi
            ZXhwIjoiMjAyMi0wMS0wMVQwMDowMDowMCswMDowMCJ9v3Jt8mx_TdM2ce
            TGoqwrh4yDFn0XsHvvV_D0DtwQxVrJEBMl0F2caAdgnpKlt4p7xBnx1HcO
            -SPo8FPp214HDw.eyJraWQiOiJ6VmhNaVBCUDlmUmYyc25FY1Q3Z0ZUaW9
            lQTlDT2NOeTlEZmdMMVc2MGhhTiJ9
Secret Key: b4cbfb43 df4ce210 727d953e 4a713307
            fa19bb7d 9f850414 38d9e11b 942a3774
            1eb9dbbb bc047c03 fd70604e 0071f098
            7e16b28b 757225c1 1f00415d 0e20b1a2
Public Key: 1eb9dbbb bc047c03 fd70604e 0071f098
            7e16b28b 757225c1 1f00415d 0e20b1a2
Payload:    {&quot;data&quot;:&quot;this is a signed message&quot;,
            &quot;exp&quot;:&quot;2022-01-01T00:00:00+00:00&quot;}
Footer:     {&quot;kid&quot;:&quot;zVhMiPBP9fRf2snEcT7gFTioeA9COcNy9DfgL1W60haN&quot;}
Implicit:   
ExpectFail: no
</artwork>
</section>

<section anchor="test-vector-v4-s-3"><name>Test Vector v4-S-3</name>

<artwork>Token:      v4.public.eyJkYXRhIjoidGhpcyBpcyBhIHNpZ25lZCBtZXNzYWdlIiwi
            ZXhwIjoiMjAyMi0wMS0wMVQwMDowMDowMCswMDowMCJ9NPWciuD3d0o5eX
            JXG5pJy-DiVEoyPYWs1YSTwWHNJq6DZD3je5gf-0M4JR9ipdUSJbIovzmB
            ECeaWmaqcaP0DQ.eyJraWQiOiJ6VmhNaVBCUDlmUmYyc25FY1Q3Z0ZUaW9
            lQTlDT2NOeTlEZmdMMVc2MGhhTiJ9
Secret Key: b4cbfb43 df4ce210 727d953e 4a713307
            fa19bb7d 9f850414 38d9e11b 942a3774
            1eb9dbbb bc047c03 fd70604e 0071f098
            7e16b28b 757225c1 1f00415d 0e20b1a2
Public Key: 1eb9dbbb bc047c03 fd70604e 0071f098
            7e16b28b 757225c1 1f00415d 0e20b1a2
Payload:    {&quot;data&quot;:&quot;this is a signed message&quot;,
            &quot;exp&quot;:&quot;2022-01-01T00:00:00+00:00&quot;}
Footer:     {&quot;kid&quot;:&quot;zVhMiPBP9fRf2snEcT7gFTioeA9COcNy9DfgL1W60haN&quot;}
Implicit:   {&quot;test-vector&quot;:&quot;4-S-3&quot;}
ExpectFail: no
</artwork>
</section>

<section anchor="test-vector-4-f-1"><name>Test Vector 4-F-1</name>
<t>This test vector <bcp14>MUST</bcp14> fail, because the keys are not meant for local
tokens.</t>

<artwork>Token:      v4.local.vngXfCISbnKgiP6VWGuOSlYrFYU300fy9ijW33rznDYgxHNPw
            WluAY2Bgb0z54CUs6aYYkIJ-bOOOmJHPuX_34Agt_IPlNdGDpRdGNnBz2M
            pWJvB3cttheEc1uyCEYltj7wBQQYX.YXJiaXRyYXJ5LXN0cmluZy10aGF0
            LWlzbid0LWpzb24
Secret Key: b4cbfb43 df4ce210 727d953e 4a713307
            fa19bb7d 9f850414 38d9e11b 942a3774
            1eb9dbbb bc047c03 fd70604e 0071f098
            7e16b28b 757225c1 1f00415d 0e20b1a2
Public Key: 1eb9dbbb bc047c03 fd70604e 0071f098
            7e16b28b 757225c1 1f00415d 0e20b1a2
Payload:    
Footer:     arbitrary-string-that-isn't-json
Implicit:   {&quot;test-vector&quot;:&quot;4-F-1&quot;}
ExpectFail: YES
</artwork>
</section>

<section anchor="test-vector-4-f-2"><name>Test Vector 4-F-2</name>
<t>This test vector <bcp14>MUST</bcp14> fail, because the key is not meant for public
tokens.</t>

<artwork>Token:      v4.public.eyJpbnZhbGlkIjoidGhpcyBzaG91bGQgbmV2ZXIgZGVjb2Rl
            In22Sp4gjCaUw0c7EH84ZSm_jN_Qr41MrgLNu5LIBCzUr1pn3Z-Wukg9h3
            ceplWigpoHaTLcwxj0NsI1vjTh67YB.eyJraWQiOiJ6VmhNaVBCUDlmUmY
            yc25FY1Q3Z0ZUaW9lQTlDT2NOeTlEZmdMMVc2MGhhTiJ9
Key:        70717273 74757677 78797a7b 7c7d7e7f
            80818283 84858687 88898a8b 8c8d8e8f
Nonce:      df654812 bac49266 3825520b a2f6e67c
            f5ca5bdc 13d4e750 7a98cc4c 2fcc3ad8
Payload:    
Footer:     {&quot;kid&quot;:&quot;zVhMiPBP9fRf2snEcT7gFTioeA9COcNy9DfgL1W60haN&quot;}
Implicit:   {&quot;test-vector&quot;:&quot;4-F-2&quot;}
ExpectFail: YES
</artwork>
</section>

<section anchor="test-vector-4-f-3"><name>Test Vector 4-F-3</name>
<t>This test vector <bcp14>MUST</bcp14> fail, because token is Version 3 while we're
operating in Version 4.</t>

<artwork>Token:      v3.local.23e_2PiqpQBPvRFKzB0zHhjmxK3sKo2grFZRRLM-U7L0a8uHx
            uF9RlVz3Ic6WmdUUWTxCaYycwWV1yM8gKbZB2JhygDMKvHQ7eBf8GtF0r3
            K0Q_gF1PXOxcOgztak1eD1dPe9rLVMSgR0nHJXeIGYVuVrVoLWQ.YXJiaX
            RyYXJ5LXN0cmluZy10aGF0LWlzbid0LWpzb24
Key:        70717273 74757677 78797a7b 7c7d7e7f
            80818283 84858687 88898a8b 8c8d8e8f
Nonce:      26f75533 54482a1d 91d47846 27854b8d
            a6b8042a 7966523c 2b404e8d bbe7f7f2
Payload:    
Footer:     arbitrary-string-that-isn't-json
Implicit:   {&quot;test-vector&quot;:&quot;4-F-3&quot;}
ExpectFail: YES
</artwork>
</section>
</section>
</section>
</section>

</back>

</rfc>
