-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdraft-paragon-paseto-rfc-01.txt
2520 lines (1623 loc) · 84.8 KB
/
draft-paragon-paseto-rfc-01.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
Network Working Group R. Terjesen
Internet-Draft Paragon Initiative Enterprises
Intended status: Informational S. Haussmann
Expires: 25 November 2022 Rensselaer Polytechnic Institute
S. Arciszewski
Paragon Initiative Enterprises
24 May 2022
PASETO (Platform-Agnostic SEcurity TOkens)
draft-paragon-paseto-rfc-01
Abstract
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.
Status of This Memo
This Internet-Draft is submitted in full conformance with the
provisions of BCP 78 and BCP 79.
Internet-Drafts are working documents of the Internet Engineering
Task Force (IETF). Note that other groups may also distribute
working documents as Internet-Drafts. The list of current Internet-
Drafts is at https://datatracker.ietf.org/drafts/current/.
Internet-Drafts are draft documents valid for a maximum of six months
and may be updated, replaced, or obsoleted by other documents at any
time. It is inappropriate to use Internet-Drafts as reference
material or to cite them other than as "work in progress."
This Internet-Draft will expire on 25 November 2022.
Copyright Notice
Copyright (c) 2022 IETF Trust and the persons identified as the
document authors. All rights reserved.
This document is subject to BCP 78 and the IETF Trust's Legal
Provisions Relating to IETF Documents (https://trustee.ietf.org/
license-info) in effect on the date of publication of this document.
Please review these documents carefully, as they describe your rights
and restrictions with respect to this document. Code Components
Terjesen, et al. Expires 25 November 2022 [Page 1]
Internet-Draft PASETO May 2022
extracted from this document must include Revised BSD License text as
described in Section 4.e of the Trust Legal Provisions and are
provided without warranty as described in the Revised BSD License.
Table of Contents
1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . 3
1.1. Difference Between PASETO and JOSE . . . . . . . . . . . 3
1.2. Why Not Update JOSE to Be Secure? . . . . . . . . . . . . 3
1.3. Notation and Conventions . . . . . . . . . . . . . . . . 4
2. PASETO Message Format . . . . . . . . . . . . . . . . . . . . 4
2.1. PASETO Token Versions . . . . . . . . . . . . . . . . . . 4
2.2. PASETO Token Purposes . . . . . . . . . . . . . . . . . . 4
2.3. Base64 Encoding . . . . . . . . . . . . . . . . . . . . . 5
2.4. Multi-Part Authentication . . . . . . . . . . . . . . . . 5
2.4.1. PAE Definition . . . . . . . . . . . . . . . . . . . 5
3. Protocol Versions . . . . . . . . . . . . . . . . . . . . . . 7
3.1. PASETO Protocol Guidelines . . . . . . . . . . . . . . . 7
4. PASETO Protocol Version 3 . . . . . . . . . . . . . . . . . . 8
4.1. v3.local . . . . . . . . . . . . . . . . . . . . . . . . 8
4.2. v3.public . . . . . . . . . . . . . . . . . . . . . . . . 8
4.3. PASETO Version 3 Algorithms . . . . . . . . . . . . . . . 8
4.3.1. PASETO.v3.Encrypt . . . . . . . . . . . . . . . . . . 8
4.3.2. PASETO.v3.Decrypt . . . . . . . . . . . . . . . . . . 10
4.3.3. PASETO.v3.Sign . . . . . . . . . . . . . . . . . . . 11
4.3.4. PASETO.v3.Verify . . . . . . . . . . . . . . . . . . 12
4.3.5. PASETO.v3.CompressPublicKey . . . . . . . . . . . . . 13
5. PASETO Protocol Version v4 . . . . . . . . . . . . . . . . . 14
5.1. v4.local . . . . . . . . . . . . . . . . . . . . . . . . 14
5.2. v4.public . . . . . . . . . . . . . . . . . . . . . . . . 14
5.3. PASETO Version 4 Algorithms . . . . . . . . . . . . . . . 14
5.3.1. PASETO.v4.Encrypt . . . . . . . . . . . . . . . . . . 14
5.3.2. PASETO.v4.Decrypt . . . . . . . . . . . . . . . . . . 16
5.3.3. PASETO.v4.Sign . . . . . . . . . . . . . . . . . . . 18
5.3.4. PASETO.v4.Verify . . . . . . . . . . . . . . . . . . 18
6. Payload Processing . . . . . . . . . . . . . . . . . . . . . 19
6.1. Type Safety with Cryptographic Keys . . . . . . . . . . . 19
6.2. Registered Claims . . . . . . . . . . . . . . . . . . . . 20
6.2.1. Payload Claims . . . . . . . . . . . . . . . . . . . 20
6.2.2. Optional Footer Claims . . . . . . . . . . . . . . . 21
6.2.3. Key-ID Support . . . . . . . . . . . . . . . . . . . 21
6.3. Optional Footer . . . . . . . . . . . . . . . . . . . . . 22
6.3.1. Storing JSON in the Footer . . . . . . . . . . . . . 22
6.4. Implicit Assertions . . . . . . . . . . . . . . . . . . . 25
7. Intended Use-Cases for PASETO . . . . . . . . . . . . . . . . 25
8. Security Considerations . . . . . . . . . . . . . . . . . . . 26
9. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 27
10. Normative References . . . . . . . . . . . . . . . . . . . . 28
Terjesen, et al. Expires 25 November 2022 [Page 2]
Internet-Draft PASETO May 2022
Appendix A. PASETO Test Vectors . . . . . . . . . . . . . . . . 30
A.1. PASETO v3 Test Vectors . . . . . . . . . . . . . . . . . 30
A.1.1. v3.local (Shared-Key Encryption) Test Vectors . . . . 30
A.1.2. v3.public (Public-Key Authentication) Test Vectors . 34
A.2. PASETO v4 Test Vectors . . . . . . . . . . . . . . . . . 37
A.2.1. v4.local (Shared-Key Encryption) Test Vectors . . . . 37
A.2.2. v4.public (Public-Key Authentication) Test Vectors . 41
Authors' Addresses . . . . . . . . . . . . . . . . . . . . . . . 44
1. Introduction
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 [RFC8259] object by default), and
is either encrypted symmetrically or signed using public-key
cryptography.
1.1. Difference Between PASETO and JOSE
The key difference between PASETO and the JOSE family of standards
(JWS [RFC7516], JWE [RFC7517], JWK [RFC7518], JWA [RFC7518], and JWT
[RFC7519]) is that JOSE allows implementors and users to mix and
match their own choice of cryptographic algorithms (specified by the
"alg" header in JWT), while PASETO has clearly defined protocol
versions to prevent unsafe configurations from being selected.
PASETO is defined in two pieces:
1. The PASETO Message Format, defined in Section 2
2. The PASETO Protocol Version, defined in Section 3
1.2. Why Not Update JOSE to Be Secure?
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.
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.
Terjesen, et al. Expires 25 November 2022 [Page 3]
Internet-Draft PASETO May 2022
1.3. Notation and Conventions
The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT",
"SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this
document are to be interpreted as described in RFC 2119 [RFC2119].
2. PASETO Message Format
PASETOs consist of three or four segments, separated by a period (the
ASCII character whose number, represented in hexadecimal, is 2E).
Without the Optional Footer:
version.purpose.payload
With the Optional Footer:
version.purpose.payload.footer
If no footer is provided, implementations SHOULD NOT append a
trailing period to each payload.
2.1. PASETO Token Versions
The *version* is a string that represents the current version of the
protocol. Currently, two versions are specified, which each possess
their own ciphersuites. Accepted values: *v3*, *v4*.
(Earlier versions of the PASETO RFC specified *v1* and *v2*, but
these are not proposed for IETF standardization.)
Future standardization efforts MAY 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).
2.2. PASETO Token Purposes
The *purpose* is a short string describing the purpose of the token.
Accepted values: *local*, *public*.
* *local*: shared-key authenticated encryption
* *public*: public-key digital signatures; *not encrypted*
Terjesen, et al. Expires 25 November 2022 [Page 4]
Internet-Draft PASETO May 2022
The *payload* is a string that contains the token's data. In a local
token, this data is encrypted with a symmetric cipher. In a public
token, this data is _unencrypted_.
Any optional data can be appended to the *footer*. This data is
authenticated through inclusion in the calculation of the
authentication tag along with the header and payload. The *footer*
MUST NOT be encrypted.
2.3. Base64 Encoding
The payload and footer in a PASETO MUST be encoded using base64url as
defined in [RFC4648], without = padding.
In this document. b64() refers to this unpadded variant of base64url.
2.4. Multi-Part Authentication
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.
In local mode, this encoding is applied to the additional associated
data (AAD). In public mode, which is not encrypted, this encoding is
applied to the components of the token, with respect to the protocol
version being followed.
We will refer to this process as *PAE* in this document (short for
Pre-Authentication Encoding).
2.4.1. PAE Definition
PAE() accepts an array of strings.
LE64() encodes a 64-bit unsigned integer into a little-endian binary
string. The most significant bit MUST be set to 0 for
interoperability with programming languages that do not have unsigned
integer support.
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
LE64() to the size of the array.
Next, for each piece provided, the length of the piece is encoded via
LE64() and prefixed to each piece before concatenation.
Terjesen, et al. Expires 25 November 2022 [Page 5]
Internet-Draft PASETO May 2022
function LE64(n) {
var str = '';
for (var i = 0; i < 8; ++i) {
if (i === 7) {
n &= 127;
}
str += String.fromCharCode(n & 255);
n = n >>> 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 < count; i++) {
output += LE64(pieces[i].length);
output += pieces[i];
}
return output;
}
Figure 1: JavaScript implementation of Pre-Authentication
Encoding (PAE)
As a consequence:
* PAE([]) will always return \x00\x00\x00\x00\x00\x00\x00\x00
* PAE(['']) will always return
\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00
* PAE(['test']) will always return \x01\x00\x00\x00\x00\x00\x00\x00\
x04\x00\x00\x00\x00\x00\x00\x00test
* PAE('test') will throw a TypeError
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.
Due to the length being expressed as an unsigned 64-bit integer, it
is infeasible to encode enough data to create an integer overflow.
Terjesen, et al. Expires 25 November 2022 [Page 6]
Internet-Draft PASETO May 2022
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.
3. Protocol Versions
This document defines two protocol versions for the PASETO standard.
Protocol versions (*Version 3*, *Version 4*) correspond to a specific
message format version (*v3*, *v4*).
Each protocol version strictly defines the cryptographic primitives
used. Changes to the primitives requires new protocol versions.
Future RFCs MAY introduce new PASETO protocol versions by continuing
the convention (e.g. *Version 5*, *Version 6*, ...).
Both *Version 3* and *Version 4* provide authentication of the entire
PASETO message, including the *version*, *purpose*, *payload*,
*footer*, and (optional) *implicit assertions*.
The initial recommendation is to use *Version 4*, allowing for
upgrades to possible future versions *Version 5*, *Version 6*, etc.
when they are defined in the future.
3.1. PASETO Protocol Guidelines
When defining future protocol versions, the following rules SHOULD or
MUST be followed:
1. Everything in a token MUST be authenticated. Attackers should
never be allowed the opportunity to alter messages freely.
* If encryption is specified, unauthenticated modes (e.g. AES-
CBC without a MAC) are forbidden.
* The nonce or initialization vector must be covered by the
authentication tag, not just the ciphertext.
2. Some degree of nonce-misuse resistance SHOULD be provided:
* 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 */dev/urandom* on Linux.
* Key-splitting and including an additional HKDF salt as part of
the nonce is sufficient for this requirement.
Terjesen, et al. Expires 25 November 2022 [Page 7]
Internet-Draft PASETO May 2022
3. Public-key cryptography MUST be IND-CCA2 secure to be considered
for inclusion.
* This means that RSA with PKCS1v1.5 padding and unpadded RSA
MUST NOT ever be used in a PASETO protocol.
4. PASETO Protocol Version 3
*PASETO Version 3* is composed of NIST-approved algorithms, and will
operate on tokens with the *v3* version header.
*v3* messages MUST use a *purpose* value of either *local* or
*public*.
4.1. v3.local
*v3.local* messages SHALL be encrypted and authenticated with *AES-
256-CTR* (AES-CTR from [RFC3686] with a 256-bit key) and *HMAC-SHA-
384* ([RFC4231]), using an *Encrypt-then-MAC* construction.
Encryption and authentication keys are split from the original key
and 256-bit nonce, facilitated by HKDF [RFC5869] using SHA384.
Refer to the operations defined in *PASETO.v3.Encrypt* and
*PASETO.v3.Decrypt* for a formal definition.
4.2. v3.public
*v1.public* messages SHALL be signed using ECDSA with NIST curve
P-384 as defined in [RFC6687]. These messages provide authentication
but do not prevent the contents from being read, including by those
without either the *public key* or the *secret key*. Refer to the
operations defined in *PASETO.v3.Sign* and *PASETO.v3.Verify* for a
formal definition.
4.3. PASETO Version 3 Algorithms
4.3.1. PASETO.v3.Encrypt
Given a message m, key k, and optional footer f (which defaults to
empty string), and an optional implicit assertion i (which defaults
to empty string):
1. Before encrypting, first assert that the key being used is
intended for use with v3.local tokens. If this assertion fails,
abort encryption.
2. Set header h to v3.local.
Terjesen, et al. Expires 25 November 2022 [Page 8]
Internet-Draft PASETO May 2022
3. Generate 32 random bytes from the OS's CSPRNG to get the nonce,
n.
4. Split the key into an Encryption key (Ek) and Authentication key
(Ak), using HKDF-HMAC-SHA384, with n appended to the info rather
than the salt.
* The output length MUST be 48 for both key derivations.
* 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 Ek is derived) will be used as a
counter nonce (n2):
5. Encrypt the message using AES-256-CTR, using Ek as the key and n2
as the nonce. We'll call the encrypted output of this step c.
6. Pack h, n, c, and f together (in that order) using PAE (see
Section 2.4.1). We'll call this preAuth.
7. Calculate HMAC-SHA384 of the output of preAuth, using Ak as the
authentication key. We'll call this t.
8. If f is:
* Empty: return h || b64(n || c || t)
* Non-empty: return h || b64(n || c || t) || . || b64(f)
* ...where || means "concatenate"
Example code:
tmp = hkdf_sha384(
len = 48,
ikm = k,
info = "paseto-encryption-key" || n,
salt = NULL
);
Ek = tmp[0:32]
n2 = tmp[32:]
Ak = hkdf_sha384(
len = 48,
ikm = k,
info = "paseto-auth-key-for-aead" || n,
salt = NULL
);
Terjesen, et al. Expires 25 November 2022 [Page 9]
Internet-Draft PASETO May 2022
Figure 2: Step 4: Key splitting with HKDF-SHA384 as per [RFC5869].
c = aes256ctr_encrypt(
plaintext = m,
nonce = n2
key = Ek
);
Figure 3: Step 5: PASETO Version 3 encryption (calculating c)
4.3.2. PASETO.v3.Decrypt
Given a message m, key k, and optional footer f (which defaults to
empty string):
1. Before decrypting, first assert that the key being used is
intended for use with v3.local tokens. If this assertion fails,
abort decryption.
2. If f is not empty, implementations MAY verify that the value
appended to the token matches some expected string f, provided
they do so using a constant-time string compare function.
3. Verify that the message begins with v3.local., otherwise throw an
exception. This constant will be referred to as h.
4. Decode the payload (m sans h, f, and the optional trailing period
between m and f) from b64 to raw binary. Set:
* n to the leftmost 32 bytes
* t to the rightmost 48 bytes
* c to the middle remainder of the payload, excluding n and t
5. Split the key (k) into an Encryption key (Ek) and an
Authentication key (Ak), n appended to the HKDF info.
* For encryption keys, the *info* parameter for HKDF MUST be set
to *paseto-encryption-key*.
* For authentication keys, the *info* parameter for HKDF MUST be
set to *paseto-auth-key-for-aead*.
* The output length MUST be 48 for both key derivations. The
leftmost 32 bytes of the first key derivation will produce Ek,
while the remaining 16 bytes will be the AES nonce n2.
Terjesen, et al. Expires 25 November 2022 [Page 10]
Internet-Draft PASETO May 2022
6. Pack h, n, c, f, and i together (in that order) using PAE (see
Section 2.4.1). We'll call this preAuth.
7. Recalculate HMAC-SHA-384 of preAuth using Ak as the key. We'll
call this t2.
8. Compare t with t2 using a constant-time string compare function.
If they are not identical, throw an exception.
9. Decrypt c using AES-256-CTR, using Ek as the key and the
rightmost 16 bytes of n as the nonce, and return this value.
Example code:
tmp = hkdf_sha384(
len = 48,
ikm = k,
info = "paseto-encryption-key" || n,
salt = NULL
);
Ek = tmp[0:32]
n2 = tmp[32:]
Ak = hkdf_sha384(
len = 48,
ikm = k,
info = "paseto-auth-key-for-aead" || n,
salt = NULL
);
Figure 4: Step 4: Key splitting with HKDF-SHA384 as per [RFC5869].
return aes256ctr_decrypt(
cipherext = c,
nonce = n2
key = Ek
);
Figure 5: Step 8: PASETO Version 3 decryption
4.3.3. PASETO.v3.Sign
Given a message m, 384-bit ECDSA secret key sk, an optional footer f
(which defaults to empty string), and an optional implicit assertion
i (which defaults to empty string):
1. Before signing, first assert that the key being used is intended
for use with v3.public tokens, and is a secret key (not a public
key). If this assertion fails, abort signing.
Terjesen, et al. Expires 25 November 2022 [Page 11]
Internet-Draft PASETO May 2022
2. Set cpk to the compressed point representation of the ECDSA
public key (see point compression (https://www.secg.org/
sec1-v2.pdf)), using [#paseto-v3-compresspublickey].
3. Set h to v3.public.
4. Pack cpk, h, m, f, and i together (in that order) using PAE (see
Section 2.4.1). We'll call this m2.
5. Sign m2 using ECDSA over P-384 and SHA-384 with the private key
sk. We'll call this sig. The output of sig MUST be in the
format r || s (where ||means concatenate), for a total length of
96 bytes.
* Signatures SHOULD use deterministic k-values ([RFC6979]) if
possible, to mitigate the risk of k-value reuse
(https://blog.trailofbits.com/2020/06/11/ecdsa-handle-with-
care/).
* If possible, hedged signatures ([RFC6979] + additional
randomness when generating k-values to provide resilience to
fault attacks) are preferred over [RFC6979] alone.
* If [RFC6979] is not available in your programming language,
ECDSA MUST use a CSPRNG to generate the k-value.
6. If f is:
* Empty: return h || b64(m || sig)
* Non-empty: return h || b64(m || sig) || . || b64(f)
* ...where || means "concatenate"
cpk = PASETO.v3.CompressPublicKey(sk.getPublicKey());
m2 = PASETO.PAE(cpk, h, m, f, i);
sig = crypto_sign_ecdsa_p384(
message = m2,
private_key = sk
);
Figure 6: Pseudocode: ECDSA signature algorithm used in PASETO v3
4.3.4. PASETO.v3.Verify
Given a signed message sm, ECDSA public key pk, and optional footer f
(which defaults to empty string), and an optional implicit assertion
i (which defaults to empty string):
Terjesen, et al. Expires 25 November 2022 [Page 12]
Internet-Draft PASETO May 2022
1. Before verifying, first assert that the key being used is
intended for use with v3.public tokens, and is a public key (not
a secret key). If this assertion fails, abort verifying.
2. If f is not empty, implementations MAY verify that the value
appended to the token matches some expected string f, provided
they do so using a constant-time string compare function.
3. Set cpk to the compressed point representation of the ECDSA
public key (see point compression (https://www.secg.org/
sec1-v2.pdf)), using [#paseto-v3-compresspublickey].
4. Verify that the message begins with v3.public., otherwise throw
an exception. This constant will be referred to as h.
5. Decode the payload (sm sans h, f, and the optional trailing
period between m and f) from base64url to raw binary. Set:
* s to the rightmost 96 bytes
* m to the leftmost remainder of the payload, excluding s
6. Pack h, m, f, and i together (in that order) using PAE (see
Section 2.4.1). We'll call this m2.
7. Use RSA to verify that the signature is valid for the message.
The padding mode MUST be RSASSA-PSS [RFC8017]; PKCS1v1.5 is
explicitly forbidden. The public exponent e MUST be 65537. The
mask generating function MUST be MGF1+SHA384. The hash function
MUST be SHA384. (See below for pseudocode.)
8. If the signature is valid, return m. Otherwise, throw an
exception.
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
);
Figure 7: Pseudocode: ECDSA signature validation for PASETO Version 3
4.3.5. PASETO.v3.CompressPublicKey
Given a public key consisting of two coordinates (X, Y):
Terjesen, et al. Expires 25 November 2022 [Page 13]
Internet-Draft PASETO May 2022
1. Set the header to 0x02.
2. Take the least significant bit of Y and add it to the header.
3. Append the X coordinate (in big-endian byte order) to the header.
lsb(y):
return y[y.length - 1] & 1
pubKeyCompress(x, y):
header = [0x02 + lsb(y)]
return header.concat(x)
Figure 8: Pseudocode: Point compression as used in PASETO Version 3.
5. PASETO Protocol Version v4
*PASETO Version 4* is the recommended version of PASETO, and will
operate on tokens with the *v4* version header.
*v4* messages MUST use a *purpose* value of either *local* or
*public*.
5.1. v4.local
*v4.local* messages MUST be encrypted with XChaCha20, a variant of
ChaCha20 [RFC7539] defined in XChaCha20
(https://datatracker.ietf.org/doc/html/draft-irtf-cfrg-xchacha-03).
Refer to the operations defined in *PASETO.v4.Encrypt* and
*PASETO.v4.Decrypt* for a formal definition.
5.2. v4.public
*v4.public* messages MUST be signed using Ed25519 [RFC8032] public
key signatures. These messages provide authentication but do not
prevent the contents from being read, including by those without
either the *public key* or the *private key*. Refer to the operations
defined in *v4.Sign* and *v4.Verify* for a formal definition.
5.3. PASETO Version 4 Algorithms
5.3.1. PASETO.v4.Encrypt
Given a message m, key k, and optional footer f.
1. Before encrypting, first assert that the key being used is
intended for use with v4.local tokens. If this assertion fails,
abort encryption.
Terjesen, et al. Expires 25 November 2022 [Page 14]
Internet-Draft PASETO May 2022
2. Set header h to v4.local.
3. Generate 32 random bytes from the OS's CSPRNG, n.
4. Split the key into an Encryption key (Ek) and Authentication key
(Ak), using keyed BLAKE2b, using the domain separation constants
and n 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 (n2).
5. Encrypt the message using XChaCha20, using n2 from step 3 as the
nonce and Ek as the key.
6. Pack h, n, c, f, and i together (in that order) using PAE (see
Section 2.4.1). We'll call this preAuth.
7. Calculate BLAKE2b-MAC of the output of preAuth, using Ak as the
authentication key. We'll call this t.
8. If f is:
* Empty: return h || b64(n || c)
* Non-empty: return h || b64(n || c) || . || b64(f)
* ...where || means "concatenate"
tmp = crypto_generichash(
msg = "paseto-encryption-key" || n,
key = key,
length = 56
);
Ek = tmp[0:32]
n2 = tmp[32:]
Ak = crypto_generichash(
msg = "paseto-auth-key-for-aead" || n,
key = key,
length = 32
);
Figure 9: Step 4: Key splitting with BLAKE2b.
Terjesen, et al. Expires 25 November 2022 [Page 15]
Internet-Draft PASETO May 2022
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
);
Figure 10: Steps 5-7: PASETO Version 4 encryption
5.3.2. PASETO.v4.Decrypt
Given a message m, key k, and optional footer f.
1. Before decrypting, first assert that the key being used is
intended for use with v4.local tokens. If this assertion fails,
abort decryption.
2. If f is not empty, implementations MAY verify that the value
appended to the token matches some expected string f, provided
they do so using a constant-time string compare function.
3. Verify that the message begins with v4.local., otherwise throw
an exception. This constant will be referred to as h.
4. Decode the payload (m sans h, f, and the optional trailing
period between m and f) from base64url to raw binary. Set:
* n to the leftmost 32 bytes
* c to the middle remainder of the payload, excluding n.
5. Split the key into an Encryption key (Ek) and Authentication key
(Ak), using keyed BLAKE2b, using the domain separation constants
and n 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 (n2)
6. Pack h, n, c, f, and i together (in that order) using PAE (see
Section 2.4.1). We'll call this preAuth.
7. Re-calculate BLAKE2b-MAC of the output of preAuth, using Ak as
the authentication key. We'll call this t2.
Terjesen, et al. Expires 25 November 2022 [Page 16]
Internet-Draft PASETO May 2022
8. Compare t with t2 using a constant-time string compare function.
If they are not identical, throw an exception.
* You MUST 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 Double HMAC
(https://paragonie.com/blog/2015/11/preventing-timing-
attacks-on-string-comparison-with-double-hmac-strategy).
9. Decrypt c using XChaCha20, store the result in p.
10. If decryption failed, throw an exception. Otherwise, return p.
tmp = crypto_generichash(
msg = "paseto-encryption-key" || n,
key = key,
length = 56
);
Ek = tmp[0:32]
n2 = tmp[32:]
Ak = crypto_generichash(
msg = "paseto-auth-key-for-aead" || n,
key = key,
length = 32
);
Figure 11: Step 4: Key splitting with BLAKE2b.
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("Invalid auth tag");
}
p = crypto_stream_xchacha20_xor(
ciphertext = c
nonce = n2
key = Ek
);
Figure 12: Steps 5-8: PASETO v4 decryption
Terjesen, et al. Expires 25 November 2022 [Page 17]
Internet-Draft PASETO May 2022
5.3.3. PASETO.v4.Sign
Given a message m, Ed25519 secret key sk, and optional footer f
(which defaults to empty string):
1. Before signing, first assert that the key being used is intended
for use with v4.public tokens, and is a secret key (not a public
key). If this assertion fails, abort signing.
2. Set h to v4.public.
3. Pack h, m, f, and i together (in that order) using PAE (see
Section 2.4.1). We'll call this m2.
4. Sign m2 using Ed25519 sk. We'll call this sig. (See below for
pseudocode.)
5. If f is:
* Empty: return h || b64(m || sig)
* Non-empty: return h || b64(m || sig) || . || b64(f)
* ...where || means "concatenate"
m2 = PASETO.PAE(h, m, f, i);
sig = crypto_sign_detached(
message = m2,
private_key = sk
);
Figure 13: Step 4: Generating an Ed25519 with libsodium
5.3.4. PASETO.v4.Verify
Given a signed message sm, public key pk, and optional footer f
(which defaults to empty string), and an optional implicit assertion
i (which defaults to empty string):
1. Before verifying, first assert that the key being used is
intended for use with v4.public tokens, and is a public key (not
a secret key). If this assertion fails, abort verifying.
2. If f is not empty, implementations MAY verify that the value