From 2270786a8a9bc3ac143b87c72b7f51fad856e488 Mon Sep 17 00:00:00 2001 From: Oleg Kovalov Date: Mon, 18 Apr 2022 18:55:00 +0200 Subject: [PATCH] Add jwt benchmarks --- .gitignore | 1 + jwt/Makefile | 3 + jwt/README.md | 37 +++++ jwt/bench.txt | 369 +++++++++++++++++++++++++++++++++++++++++ jwt/bench_test.go | 410 ++++++++++++++++++++++++++++++++++++++++++++++ jwt/go.mod | 16 ++ jwt/go.sum | 48 ++++++ jwt/keys_test.go | 188 +++++++++++++++++++++ 8 files changed, 1072 insertions(+) create mode 100644 .gitignore create mode 100644 jwt/Makefile create mode 100644 jwt/README.md create mode 100644 jwt/bench.txt create mode 100644 jwt/bench_test.go create mode 100644 jwt/go.mod create mode 100644 jwt/go.sum create mode 100644 jwt/keys_test.go diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c33ea5d --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*bench.exec \ No newline at end of file diff --git a/jwt/Makefile b/jwt/Makefile new file mode 100644 index 0000000..b2c56b7 --- /dev/null +++ b/jwt/Makefile @@ -0,0 +1,3 @@ +run: + go test -c -o jwt-bench.exec + time ./jwt-bench.exec -test.v -test.benchmem -test.bench ^Benchmark -test.count 5 -test.run ^$ > bench.txt diff --git a/jwt/README.md b/jwt/README.md new file mode 100644 index 0000000..e3cb2b4 --- /dev/null +++ b/jwt/README.md @@ -0,0 +1,37 @@ +# jwt + +## Who + +``` +github.com/cristalhq/jwt/v4 v4.0.0 +github.com/golang-jwt/jwt v3.2.2+incompatible +github.com/lestrrat-go/jwx v1.2.23 +github.com/pascaldekloe/jwt v1.10.0 +``` + +## Where + +``` +MacBook Pro (15-inch, 2017) +2,8 GHz Quad-Core Intel Core i7 +16 GB 2133 MHz LPDDR3 +``` + +## How + +```shell script +# build & run benchmark +$ make run + +# or in steps + +# build test executable +$ go test -c -o jwt-bench.exec + +# run executable +$ time ./jwt-bench.exec -v -benchmem -bench ^Benchmark -count 5 -run ^$ > bench.txt +``` + +## Well + +See [bench.txt](https://github.com/cristalhq/benchmarks/blob/main/jwt/bench.txt) diff --git a/jwt/bench.txt b/jwt/bench.txt new file mode 100644 index 0000000..ac3a06a --- /dev/null +++ b/jwt/bench.txt @@ -0,0 +1,369 @@ +goos: darwin +goarch: arm64 +pkg: github.com/cristaloleg/benches/jwt +Benchmark_cristalhq_jwt_EdDSA +Benchmark_cristalhq_jwt_EdDSA/sign-EdDSA +Benchmark_cristalhq_jwt_EdDSA/sign-EdDSA-10 48038 24601 ns/op 172.0 B/token 480 B/op 6 allocs/op +Benchmark_cristalhq_jwt_EdDSA/sign-EdDSA-10 48878 24576 ns/op 172.0 B/token 480 B/op 6 allocs/op +Benchmark_cristalhq_jwt_EdDSA/sign-EdDSA-10 48878 24644 ns/op 172.0 B/token 480 B/op 6 allocs/op +Benchmark_cristalhq_jwt_EdDSA/sign-EdDSA-10 48692 24599 ns/op 172.0 B/token 480 B/op 6 allocs/op +Benchmark_cristalhq_jwt_EdDSA/sign-EdDSA-10 48694 24541 ns/op 172.0 B/token 480 B/op 6 allocs/op +Benchmark_cristalhq_jwt_EdDSA/check-EdDSA +Benchmark_cristalhq_jwt_EdDSA/check-EdDSA-10 23143 51990 ns/op 0 B/op 0 allocs/op +Benchmark_cristalhq_jwt_EdDSA/check-EdDSA-10 23143 51840 ns/op 0 B/op 0 allocs/op +Benchmark_cristalhq_jwt_EdDSA/check-EdDSA-10 23125 51857 ns/op 0 B/op 0 allocs/op +Benchmark_cristalhq_jwt_EdDSA/check-EdDSA-10 23136 51951 ns/op 0 B/op 0 allocs/op +Benchmark_cristalhq_jwt_EdDSA/check-EdDSA-10 23149 51848 ns/op 0 B/op 0 allocs/op +Benchmark_cristalhq_jwt_HMAC +Benchmark_cristalhq_jwt_HMAC/sign-HS256 +Benchmark_cristalhq_jwt_HMAC/sign-HS256-10 1687972 711.4 ns/op 129.0 B/token 416 B/op 6 allocs/op +Benchmark_cristalhq_jwt_HMAC/sign-HS256-10 1685468 712.2 ns/op 129.0 B/token 416 B/op 6 allocs/op +Benchmark_cristalhq_jwt_HMAC/sign-HS256-10 1684227 714.1 ns/op 129.0 B/token 416 B/op 6 allocs/op +Benchmark_cristalhq_jwt_HMAC/sign-HS256-10 1688468 709.2 ns/op 129.0 B/token 416 B/op 6 allocs/op +Benchmark_cristalhq_jwt_HMAC/sign-HS256-10 1689355 711.6 ns/op 129.0 B/token 416 B/op 6 allocs/op +Benchmark_cristalhq_jwt_HMAC/sign-HS384 +Benchmark_cristalhq_jwt_HMAC/sign-HS384-10 725773 1620 ns/op 150.0 B/token 448 B/op 6 allocs/op +Benchmark_cristalhq_jwt_HMAC/sign-HS384-10 728716 1623 ns/op 150.0 B/token 448 B/op 6 allocs/op +Benchmark_cristalhq_jwt_HMAC/sign-HS384-10 730410 1621 ns/op 150.0 B/token 448 B/op 6 allocs/op +Benchmark_cristalhq_jwt_HMAC/sign-HS384-10 726630 1620 ns/op 150.0 B/token 448 B/op 6 allocs/op +Benchmark_cristalhq_jwt_HMAC/sign-HS384-10 725888 1621 ns/op 150.0 B/token 448 B/op 6 allocs/op +Benchmark_cristalhq_jwt_HMAC/sign-HS512 +Benchmark_cristalhq_jwt_HMAC/sign-HS512-10 724214 1637 ns/op 172.0 B/token 480 B/op 6 allocs/op +Benchmark_cristalhq_jwt_HMAC/sign-HS512-10 722506 1640 ns/op 172.0 B/token 480 B/op 6 allocs/op +Benchmark_cristalhq_jwt_HMAC/sign-HS512-10 693190 1639 ns/op 172.0 B/token 480 B/op 6 allocs/op +Benchmark_cristalhq_jwt_HMAC/sign-HS512-10 719536 1640 ns/op 172.0 B/token 480 B/op 6 allocs/op +Benchmark_cristalhq_jwt_HMAC/sign-HS512-10 728365 1638 ns/op 172.0 B/token 480 B/op 6 allocs/op +Benchmark_cristalhq_jwt_HMAC/check-HS256 +Benchmark_cristalhq_jwt_HMAC/check-HS256-10 3826406 313.9 ns/op 32 B/op 1 allocs/op +Benchmark_cristalhq_jwt_HMAC/check-HS256-10 3827530 313.5 ns/op 32 B/op 1 allocs/op +Benchmark_cristalhq_jwt_HMAC/check-HS256-10 3819402 313.7 ns/op 32 B/op 1 allocs/op +Benchmark_cristalhq_jwt_HMAC/check-HS256-10 3819306 313.8 ns/op 32 B/op 1 allocs/op +Benchmark_cristalhq_jwt_HMAC/check-HS256-10 3824636 314.0 ns/op 32 B/op 1 allocs/op +Benchmark_cristalhq_jwt_HMAC/check-HS384 +Benchmark_cristalhq_jwt_HMAC/check-HS384-10 983746 1206 ns/op 48 B/op 1 allocs/op +Benchmark_cristalhq_jwt_HMAC/check-HS384-10 988362 1207 ns/op 48 B/op 1 allocs/op +Benchmark_cristalhq_jwt_HMAC/check-HS384-10 992890 1205 ns/op 48 B/op 1 allocs/op +Benchmark_cristalhq_jwt_HMAC/check-HS384-10 988776 1205 ns/op 48 B/op 1 allocs/op +Benchmark_cristalhq_jwt_HMAC/check-HS384-10 985551 1206 ns/op 48 B/op 1 allocs/op +Benchmark_cristalhq_jwt_HMAC/check-HS512 +Benchmark_cristalhq_jwt_HMAC/check-HS512-10 980251 1218 ns/op 64 B/op 1 allocs/op +Benchmark_cristalhq_jwt_HMAC/check-HS512-10 981992 1220 ns/op 64 B/op 1 allocs/op +Benchmark_cristalhq_jwt_HMAC/check-HS512-10 981384 1217 ns/op 64 B/op 1 allocs/op +Benchmark_cristalhq_jwt_HMAC/check-HS512-10 982975 1215 ns/op 64 B/op 1 allocs/op +Benchmark_cristalhq_jwt_HMAC/check-HS512-10 978519 1217 ns/op 64 B/op 1 allocs/op +Benchmark_cristalhq_jwt_RSA +Benchmark_cristalhq_jwt_RSA/sign-1024-bit +Benchmark_cristalhq_jwt_RSA/sign-1024-bit-10 5666 209658 ns/op 257.0 B/token 16822 B/op 109 allocs/op +Benchmark_cristalhq_jwt_RSA/sign-1024-bit-10 5702 210189 ns/op 257.0 B/token 16820 B/op 109 allocs/op +Benchmark_cristalhq_jwt_RSA/sign-1024-bit-10 5674 209743 ns/op 257.0 B/token 16822 B/op 109 allocs/op +Benchmark_cristalhq_jwt_RSA/sign-1024-bit-10 5674 209811 ns/op 257.0 B/token 16820 B/op 109 allocs/op +Benchmark_cristalhq_jwt_RSA/sign-1024-bit-10 5695 209625 ns/op 257.0 B/token 16822 B/op 109 allocs/op +Benchmark_cristalhq_jwt_RSA/sign-2048-bit +Benchmark_cristalhq_jwt_RSA/sign-2048-bit-10 1168 1024342 ns/op 428.0 B/token 31383 B/op 115 allocs/op +Benchmark_cristalhq_jwt_RSA/sign-2048-bit-10 1171 1024324 ns/op 428.0 B/token 31382 B/op 115 allocs/op +Benchmark_cristalhq_jwt_RSA/sign-2048-bit-10 1124 1026749 ns/op 428.0 B/token 31383 B/op 115 allocs/op +Benchmark_cristalhq_jwt_RSA/sign-2048-bit-10 1165 1023851 ns/op 428.0 B/token 31379 B/op 115 allocs/op +Benchmark_cristalhq_jwt_RSA/sign-2048-bit-10 1168 1022296 ns/op 428.0 B/token 31382 B/op 115 allocs/op +Benchmark_cristalhq_jwt_RSA/sign-4096-bit +Benchmark_cristalhq_jwt_RSA/sign-4096-bit-10 212 5633548 ns/op 769.0 B/token 77461 B/op 129 allocs/op +Benchmark_cristalhq_jwt_RSA/sign-4096-bit-10 212 5614326 ns/op 769.0 B/token 77433 B/op 129 allocs/op +Benchmark_cristalhq_jwt_RSA/sign-4096-bit-10 213 5608067 ns/op 769.0 B/token 77479 B/op 129 allocs/op +Benchmark_cristalhq_jwt_RSA/sign-4096-bit-10 213 5599901 ns/op 769.0 B/token 77439 B/op 129 allocs/op +Benchmark_cristalhq_jwt_RSA/sign-4096-bit-10 213 5604916 ns/op 769.0 B/token 77460 B/op 129 allocs/op +Benchmark_cristalhq_jwt_RSA/check-1024-bit +Benchmark_cristalhq_jwt_RSA/check-1024-bit-10 102832 11653 ns/op 2777 B/op 12 allocs/op +Benchmark_cristalhq_jwt_RSA/check-1024-bit-10 102446 11652 ns/op 2777 B/op 12 allocs/op +Benchmark_cristalhq_jwt_RSA/check-1024-bit-10 102830 11655 ns/op 2777 B/op 12 allocs/op +Benchmark_cristalhq_jwt_RSA/check-1024-bit-10 103052 11643 ns/op 2777 B/op 12 allocs/op +Benchmark_cristalhq_jwt_RSA/check-1024-bit-10 102802 11656 ns/op 2777 B/op 12 allocs/op +Benchmark_cristalhq_jwt_RSA/check-2048-bit +Benchmark_cristalhq_jwt_RSA/check-2048-bit-10 42026 28543 ns/op 5210 B/op 12 allocs/op +Benchmark_cristalhq_jwt_RSA/check-2048-bit-10 42163 28530 ns/op 5211 B/op 12 allocs/op +Benchmark_cristalhq_jwt_RSA/check-2048-bit-10 42103 28474 ns/op 5210 B/op 12 allocs/op +Benchmark_cristalhq_jwt_RSA/check-2048-bit-10 42145 28535 ns/op 5210 B/op 12 allocs/op +Benchmark_cristalhq_jwt_RSA/check-2048-bit-10 42090 28484 ns/op 5211 B/op 12 allocs/op +Benchmark_cristalhq_jwt_RSA/check-4096-bit +Benchmark_cristalhq_jwt_RSA/check-4096-bit-10 14018 85609 ns/op 14754 B/op 13 allocs/op +Benchmark_cristalhq_jwt_RSA/check-4096-bit-10 13992 85693 ns/op 14755 B/op 13 allocs/op +Benchmark_cristalhq_jwt_RSA/check-4096-bit-10 14013 85690 ns/op 14753 B/op 13 allocs/op +Benchmark_cristalhq_jwt_RSA/check-4096-bit-10 13962 85893 ns/op 14754 B/op 13 allocs/op +Benchmark_cristalhq_jwt_RSA/check-4096-bit-10 14006 86031 ns/op 14753 B/op 13 allocs/op +Benchmark_cristalhq_jwt_ECDSA +Benchmark_cristalhq_jwt_ECDSA/sign-ES256 +Benchmark_cristalhq_jwt_ECDSA/sign-ES256-10 60254 19792 ns/op 172.0 B/token 3187 B/op 41 allocs/op +Benchmark_cristalhq_jwt_ECDSA/sign-ES256-10 60559 19794 ns/op 172.0 B/token 3188 B/op 41 allocs/op +Benchmark_cristalhq_jwt_ECDSA/sign-ES256-10 60518 19774 ns/op 172.0 B/token 3188 B/op 41 allocs/op +Benchmark_cristalhq_jwt_ECDSA/sign-ES256-10 60669 19758 ns/op 172.0 B/token 3188 B/op 41 allocs/op +Benchmark_cristalhq_jwt_ECDSA/sign-ES256-10 60580 19757 ns/op 172.0 B/token 3188 B/op 41 allocs/op +Benchmark_cristalhq_jwt_ECDSA/sign-ES384 +Benchmark_cristalhq_jwt_ECDSA/sign-ES384-10 2240 535568 ns/op 214.0 B/token 6591 B/op 69 allocs/op +Benchmark_cristalhq_jwt_ECDSA/sign-ES384-10 2230 535658 ns/op 214.0 B/token 6591 B/op 69 allocs/op +Benchmark_cristalhq_jwt_ECDSA/sign-ES384-10 2235 536763 ns/op 214.0 B/token 6591 B/op 69 allocs/op +Benchmark_cristalhq_jwt_ECDSA/sign-ES384-10 2235 535557 ns/op 214.0 B/token 6592 B/op 69 allocs/op +Benchmark_cristalhq_jwt_ECDSA/sign-ES384-10 2224 535862 ns/op 214.0 B/token 6592 B/op 69 allocs/op +Benchmark_cristalhq_jwt_ECDSA/sign-ES512 +Benchmark_cristalhq_jwt_ECDSA/sign-ES512-10 748 1600164 ns/op 262.0 B/token 8308 B/op 69 allocs/op +Benchmark_cristalhq_jwt_ECDSA/sign-ES512-10 748 1601715 ns/op 262.0 B/token 8307 B/op 69 allocs/op +Benchmark_cristalhq_jwt_ECDSA/sign-ES512-10 745 1600699 ns/op 262.0 B/token 8307 B/op 69 allocs/op +Benchmark_cristalhq_jwt_ECDSA/sign-ES512-10 746 1601790 ns/op 262.0 B/token 8308 B/op 69 allocs/op +Benchmark_cristalhq_jwt_ECDSA/sign-ES512-10 746 1601936 ns/op 262.0 B/token 8307 B/op 69 allocs/op +Benchmark_cristalhq_jwt_ECDSA/check-ES256 +Benchmark_cristalhq_jwt_ECDSA/check-ES256-10 21486 55832 ns/op 1248 B/op 21 allocs/op +Benchmark_cristalhq_jwt_ECDSA/check-ES256-10 21403 55940 ns/op 1248 B/op 21 allocs/op +Benchmark_cristalhq_jwt_ECDSA/check-ES256-10 21486 55880 ns/op 1248 B/op 21 allocs/op +Benchmark_cristalhq_jwt_ECDSA/check-ES256-10 21499 55820 ns/op 1248 B/op 21 allocs/op +Benchmark_cristalhq_jwt_ECDSA/check-ES256-10 21517 55799 ns/op 1248 B/op 21 allocs/op +Benchmark_cristalhq_jwt_ECDSA/check-ES384 +Benchmark_cristalhq_jwt_ECDSA/check-ES384-10 1192 1006077 ns/op 4434 B/op 72 allocs/op +Benchmark_cristalhq_jwt_ECDSA/check-ES384-10 1191 1005289 ns/op 4434 B/op 72 allocs/op +Benchmark_cristalhq_jwt_ECDSA/check-ES384-10 1192 1005020 ns/op 4434 B/op 72 allocs/op +Benchmark_cristalhq_jwt_ECDSA/check-ES384-10 1192 1005469 ns/op 4434 B/op 72 allocs/op +Benchmark_cristalhq_jwt_ECDSA/check-ES384-10 1190 1005587 ns/op 4434 B/op 72 allocs/op +Benchmark_cristalhq_jwt_ECDSA/check-ES512 +Benchmark_cristalhq_jwt_ECDSA/check-ES512-10 385 3152044 ns/op 5844 B/op 72 allocs/op +Benchmark_cristalhq_jwt_ECDSA/check-ES512-10 375 3125700 ns/op 5844 B/op 72 allocs/op +Benchmark_cristalhq_jwt_ECDSA/check-ES512-10 384 3117594 ns/op 5844 B/op 72 allocs/op +Benchmark_cristalhq_jwt_ECDSA/check-ES512-10 384 3117390 ns/op 5843 B/op 72 allocs/op +Benchmark_cristalhq_jwt_ECDSA/check-ES512-10 384 3123422 ns/op 5843 B/op 72 allocs/op +Benchmark_pascaldekloe_jwt_EdDSA +Benchmark_pascaldekloe_jwt_EdDSA/sign-EdDSA +Benchmark_pascaldekloe_jwt_EdDSA/sign-EdDSA-10 49888 23990 ns/op 166.0 B/token 224 B/op 2 allocs/op +Benchmark_pascaldekloe_jwt_EdDSA/sign-EdDSA-10 49944 23996 ns/op 166.0 B/token 224 B/op 2 allocs/op +Benchmark_pascaldekloe_jwt_EdDSA/sign-EdDSA-10 50013 24005 ns/op 166.0 B/token 224 B/op 2 allocs/op +Benchmark_pascaldekloe_jwt_EdDSA/sign-EdDSA-10 50034 24005 ns/op 166.0 B/token 224 B/op 2 allocs/op +Benchmark_pascaldekloe_jwt_EdDSA/sign-EdDSA-10 50043 24006 ns/op 166.0 B/token 224 B/op 2 allocs/op +Benchmark_pascaldekloe_jwt_EdDSA/check-EdDSA +Benchmark_pascaldekloe_jwt_EdDSA/check-EdDSA-10 22470 53382 ns/op 1320 B/op 26 allocs/op +Benchmark_pascaldekloe_jwt_EdDSA/check-EdDSA-10 22452 53394 ns/op 1320 B/op 26 allocs/op +Benchmark_pascaldekloe_jwt_EdDSA/check-EdDSA-10 22459 53411 ns/op 1320 B/op 26 allocs/op +Benchmark_pascaldekloe_jwt_EdDSA/check-EdDSA-10 22479 53422 ns/op 1320 B/op 26 allocs/op +Benchmark_pascaldekloe_jwt_EdDSA/check-EdDSA-10 22455 53391 ns/op 1320 B/op 26 allocs/op +Benchmark_pascaldekloe_jwt_HMAC +Benchmark_pascaldekloe_jwt_HMAC/sign-HS256 +Benchmark_pascaldekloe_jwt_HMAC/sign-HS256-10 1510303 799.2 ns/op 123.0 B/token 656 B/op 7 allocs/op +Benchmark_pascaldekloe_jwt_HMAC/sign-HS256-10 1493904 801.0 ns/op 123.0 B/token 656 B/op 7 allocs/op +Benchmark_pascaldekloe_jwt_HMAC/sign-HS256-10 1500766 800.3 ns/op 123.0 B/token 656 B/op 7 allocs/op +Benchmark_pascaldekloe_jwt_HMAC/sign-HS256-10 1496866 801.5 ns/op 123.0 B/token 656 B/op 7 allocs/op +Benchmark_pascaldekloe_jwt_HMAC/sign-HS256-10 1497058 799.6 ns/op 123.0 B/token 656 B/op 7 allocs/op +Benchmark_pascaldekloe_jwt_HMAC/sign-HS384 +Benchmark_pascaldekloe_jwt_HMAC/sign-HS384-10 447494 2683 ns/op 144.0 B/token 992 B/op 7 allocs/op +Benchmark_pascaldekloe_jwt_HMAC/sign-HS384-10 445864 2672 ns/op 144.0 B/token 992 B/op 7 allocs/op +Benchmark_pascaldekloe_jwt_HMAC/sign-HS384-10 439272 2677 ns/op 144.0 B/token 992 B/op 7 allocs/op +Benchmark_pascaldekloe_jwt_HMAC/sign-HS384-10 434118 2672 ns/op 144.0 B/token 992 B/op 7 allocs/op +Benchmark_pascaldekloe_jwt_HMAC/sign-HS384-10 443274 2679 ns/op 144.0 B/token 992 B/op 7 allocs/op +Benchmark_pascaldekloe_jwt_HMAC/sign-HS512 +Benchmark_pascaldekloe_jwt_HMAC/sign-HS512-10 444696 2688 ns/op 166.0 B/token 1024 B/op 7 allocs/op +Benchmark_pascaldekloe_jwt_HMAC/sign-HS512-10 444146 2686 ns/op 166.0 B/token 1024 B/op 7 allocs/op +Benchmark_pascaldekloe_jwt_HMAC/sign-HS512-10 440916 2689 ns/op 166.0 B/token 1024 B/op 7 allocs/op +Benchmark_pascaldekloe_jwt_HMAC/sign-HS512-10 444733 2690 ns/op 166.0 B/token 1024 B/op 7 allocs/op +Benchmark_pascaldekloe_jwt_HMAC/sign-HS512-10 446044 2693 ns/op 166.0 B/token 1024 B/op 7 allocs/op +Benchmark_pascaldekloe_jwt_HMAC/check-HS256 +Benchmark_pascaldekloe_jwt_HMAC/check-HS256-10 614578 1905 ns/op 1752 B/op 31 allocs/op +Benchmark_pascaldekloe_jwt_HMAC/check-HS256-10 621232 1903 ns/op 1752 B/op 31 allocs/op +Benchmark_pascaldekloe_jwt_HMAC/check-HS256-10 635602 1912 ns/op 1752 B/op 31 allocs/op +Benchmark_pascaldekloe_jwt_HMAC/check-HS256-10 619737 1901 ns/op 1752 B/op 31 allocs/op +Benchmark_pascaldekloe_jwt_HMAC/check-HS256-10 631855 1905 ns/op 1752 B/op 31 allocs/op +Benchmark_pascaldekloe_jwt_HMAC/check-HS384 +Benchmark_pascaldekloe_jwt_HMAC/check-HS384-10 316443 3780 ns/op 2168 B/op 32 allocs/op +Benchmark_pascaldekloe_jwt_HMAC/check-HS384-10 316234 3778 ns/op 2168 B/op 32 allocs/op +Benchmark_pascaldekloe_jwt_HMAC/check-HS384-10 315879 3778 ns/op 2168 B/op 32 allocs/op +Benchmark_pascaldekloe_jwt_HMAC/check-HS384-10 319636 3786 ns/op 2168 B/op 32 allocs/op +Benchmark_pascaldekloe_jwt_HMAC/check-HS384-10 314652 3780 ns/op 2168 B/op 32 allocs/op +Benchmark_pascaldekloe_jwt_HMAC/check-HS512 +Benchmark_pascaldekloe_jwt_HMAC/check-HS512-10 313888 3799 ns/op 2216 B/op 32 allocs/op +Benchmark_pascaldekloe_jwt_HMAC/check-HS512-10 312476 3799 ns/op 2216 B/op 32 allocs/op +Benchmark_pascaldekloe_jwt_HMAC/check-HS512-10 315922 3803 ns/op 2216 B/op 32 allocs/op +Benchmark_pascaldekloe_jwt_HMAC/check-HS512-10 308049 3808 ns/op 2216 B/op 32 allocs/op +Benchmark_pascaldekloe_jwt_HMAC/check-HS512-10 312576 3807 ns/op 2216 B/op 32 allocs/op +Benchmark_pascaldekloe_jwt_RSA +Benchmark_pascaldekloe_jwt_RSA/sign-1024-bit +Benchmark_pascaldekloe_jwt_RSA/sign-1024-bit-10 5692 210238 ns/op 251.0 B/token 16543 B/op 105 allocs/op +Benchmark_pascaldekloe_jwt_RSA/sign-1024-bit-10 5742 209625 ns/op 251.0 B/token 16545 B/op 105 allocs/op +Benchmark_pascaldekloe_jwt_RSA/sign-1024-bit-10 5713 209636 ns/op 251.0 B/token 16544 B/op 105 allocs/op +Benchmark_pascaldekloe_jwt_RSA/sign-1024-bit-10 5694 209486 ns/op 251.0 B/token 16544 B/op 105 allocs/op +Benchmark_pascaldekloe_jwt_RSA/sign-1024-bit-10 5677 209629 ns/op 251.0 B/token 16544 B/op 105 allocs/op +Benchmark_pascaldekloe_jwt_RSA/sign-2048-bit +Benchmark_pascaldekloe_jwt_RSA/sign-2048-bit-10 1167 1021585 ns/op 422.0 B/token 31131 B/op 111 allocs/op +Benchmark_pascaldekloe_jwt_RSA/sign-2048-bit-10 1176 1021849 ns/op 422.0 B/token 31130 B/op 111 allocs/op +Benchmark_pascaldekloe_jwt_RSA/sign-2048-bit-10 1174 1027102 ns/op 422.0 B/token 31133 B/op 111 allocs/op +Benchmark_pascaldekloe_jwt_RSA/sign-2048-bit-10 1167 1022249 ns/op 422.0 B/token 31132 B/op 111 allocs/op +Benchmark_pascaldekloe_jwt_RSA/sign-2048-bit-10 1174 1021065 ns/op 422.0 B/token 31132 B/op 111 allocs/op +Benchmark_pascaldekloe_jwt_RSA/sign-4096-bit +Benchmark_pascaldekloe_jwt_RSA/sign-4096-bit-10 213 5610722 ns/op 763.0 B/token 77066 B/op 125 allocs/op +Benchmark_pascaldekloe_jwt_RSA/sign-4096-bit-10 213 5609565 ns/op 763.0 B/token 77064 B/op 125 allocs/op +Benchmark_pascaldekloe_jwt_RSA/sign-4096-bit-10 213 5611519 ns/op 763.0 B/token 77086 B/op 125 allocs/op +Benchmark_pascaldekloe_jwt_RSA/sign-4096-bit-10 213 5608090 ns/op 763.0 B/token 77081 B/op 125 allocs/op +Benchmark_pascaldekloe_jwt_RSA/sign-4096-bit-10 213 5609843 ns/op 763.0 B/token 77064 B/op 125 allocs/op +Benchmark_pascaldekloe_jwt_RSA/check-1024-bit +Benchmark_pascaldekloe_jwt_RSA/check-1024-bit-10 90940 13158 ns/op 4138 B/op 37 allocs/op +Benchmark_pascaldekloe_jwt_RSA/check-1024-bit-10 91090 13146 ns/op 4138 B/op 37 allocs/op +Benchmark_pascaldekloe_jwt_RSA/check-1024-bit-10 90820 13161 ns/op 4138 B/op 37 allocs/op +Benchmark_pascaldekloe_jwt_RSA/check-1024-bit-10 91384 13154 ns/op 4138 B/op 37 allocs/op +Benchmark_pascaldekloe_jwt_RSA/check-1024-bit-10 91460 13138 ns/op 4138 B/op 37 allocs/op +Benchmark_pascaldekloe_jwt_RSA/check-2048-bit +Benchmark_pascaldekloe_jwt_RSA/check-2048-bit-10 40386 29648 ns/op 6763 B/op 37 allocs/op +Benchmark_pascaldekloe_jwt_RSA/check-2048-bit-10 40392 29723 ns/op 6764 B/op 37 allocs/op +Benchmark_pascaldekloe_jwt_RSA/check-2048-bit-10 40418 29667 ns/op 6764 B/op 37 allocs/op +Benchmark_pascaldekloe_jwt_RSA/check-2048-bit-10 40459 29658 ns/op 6764 B/op 37 allocs/op +Benchmark_pascaldekloe_jwt_RSA/check-2048-bit-10 40522 29623 ns/op 6764 B/op 37 allocs/op +Benchmark_pascaldekloe_jwt_RSA/check-4096-bit +Benchmark_pascaldekloe_jwt_RSA/check-4096-bit-10 13657 87844 ns/op 16629 B/op 38 allocs/op +Benchmark_pascaldekloe_jwt_RSA/check-4096-bit-10 13681 87948 ns/op 16631 B/op 38 allocs/op +Benchmark_pascaldekloe_jwt_RSA/check-4096-bit-10 13652 87778 ns/op 16629 B/op 38 allocs/op +Benchmark_pascaldekloe_jwt_RSA/check-4096-bit-10 13653 87939 ns/op 16630 B/op 38 allocs/op +Benchmark_pascaldekloe_jwt_RSA/check-4096-bit-10 13664 87823 ns/op 16628 B/op 38 allocs/op +Benchmark_pascaldekloe_jwt_ECDSA +Benchmark_pascaldekloe_jwt_ECDSA/sign-ES256 +Benchmark_pascaldekloe_jwt_ECDSA/sign-ES256-10 60277 19603 ns/op 166.0 B/token 2835 B/op 34 allocs/op +Benchmark_pascaldekloe_jwt_ECDSA/sign-ES256-10 60956 19623 ns/op 166.0 B/token 2835 B/op 34 allocs/op +Benchmark_pascaldekloe_jwt_ECDSA/sign-ES256-10 61306 19601 ns/op 166.0 B/token 2835 B/op 34 allocs/op +Benchmark_pascaldekloe_jwt_ECDSA/sign-ES256-10 61209 19603 ns/op 166.0 B/token 2835 B/op 34 allocs/op +Benchmark_pascaldekloe_jwt_ECDSA/sign-ES256-10 61102 19597 ns/op 166.0 B/token 2835 B/op 34 allocs/op +Benchmark_pascaldekloe_jwt_ECDSA/sign-ES384 +Benchmark_pascaldekloe_jwt_ECDSA/sign-ES384-10 2238 536110 ns/op 208.0 B/token 6145 B/op 62 allocs/op +Benchmark_pascaldekloe_jwt_ECDSA/sign-ES384-10 2236 536136 ns/op 208.0 B/token 6145 B/op 62 allocs/op +Benchmark_pascaldekloe_jwt_ECDSA/sign-ES384-10 2238 536494 ns/op 208.0 B/token 6145 B/op 62 allocs/op +Benchmark_pascaldekloe_jwt_ECDSA/sign-ES384-10 2236 535921 ns/op 208.0 B/token 6145 B/op 62 allocs/op +Benchmark_pascaldekloe_jwt_ECDSA/sign-ES384-10 2236 536471 ns/op 208.0 B/token 6145 B/op 62 allocs/op +Benchmark_pascaldekloe_jwt_ECDSA/sign-ES512 +Benchmark_pascaldekloe_jwt_ECDSA/sign-ES512-10 750 1602887 ns/op 256.0 B/token 7716 B/op 62 allocs/op +Benchmark_pascaldekloe_jwt_ECDSA/sign-ES512-10 748 1602064 ns/op 256.0 B/token 7716 B/op 62 allocs/op +Benchmark_pascaldekloe_jwt_ECDSA/sign-ES512-10 748 1600806 ns/op 256.0 B/token 7716 B/op 62 allocs/op +Benchmark_pascaldekloe_jwt_ECDSA/sign-ES512-10 750 1602336 ns/op 256.0 B/token 7715 B/op 62 allocs/op +Benchmark_pascaldekloe_jwt_ECDSA/sign-ES512-10 748 1601573 ns/op 256.0 B/token 7715 B/op 62 allocs/op +Benchmark_pascaldekloe_jwt_ECDSA/check-ES256 +Benchmark_pascaldekloe_jwt_ECDSA/check-ES256-10 20866 57413 ns/op 2537 B/op 46 allocs/op +Benchmark_pascaldekloe_jwt_ECDSA/check-ES256-10 20901 57395 ns/op 2537 B/op 46 allocs/op +Benchmark_pascaldekloe_jwt_ECDSA/check-ES256-10 20896 57373 ns/op 2537 B/op 46 allocs/op +Benchmark_pascaldekloe_jwt_ECDSA/check-ES256-10 20887 57442 ns/op 2537 B/op 46 allocs/op +Benchmark_pascaldekloe_jwt_ECDSA/check-ES256-10 20892 57363 ns/op 2537 B/op 46 allocs/op +Benchmark_pascaldekloe_jwt_ECDSA/check-ES384 +Benchmark_pascaldekloe_jwt_ECDSA/check-ES384-10 1190 1008136 ns/op 5642 B/op 96 allocs/op +Benchmark_pascaldekloe_jwt_ECDSA/check-ES384-10 1191 1008285 ns/op 5642 B/op 96 allocs/op +Benchmark_pascaldekloe_jwt_ECDSA/check-ES384-10 1183 1007909 ns/op 5642 B/op 96 allocs/op +Benchmark_pascaldekloe_jwt_ECDSA/check-ES384-10 1189 1008161 ns/op 5643 B/op 96 allocs/op +Benchmark_pascaldekloe_jwt_ECDSA/check-ES384-10 1190 1007879 ns/op 5642 B/op 96 allocs/op +Benchmark_pascaldekloe_jwt_ECDSA/check-ES512 +Benchmark_pascaldekloe_jwt_ECDSA/check-ES512-10 386 3097249 ns/op 7180 B/op 97 allocs/op +Benchmark_pascaldekloe_jwt_ECDSA/check-ES512-10 386 3097214 ns/op 7180 B/op 97 allocs/op +Benchmark_pascaldekloe_jwt_ECDSA/check-ES512-10 386 3098215 ns/op 7180 B/op 97 allocs/op +Benchmark_pascaldekloe_jwt_ECDSA/check-ES512-10 386 3097509 ns/op 7180 B/op 97 allocs/op +Benchmark_pascaldekloe_jwt_ECDSA/check-ES512-10 386 3096805 ns/op 7180 B/op 97 allocs/op +Benchmark_golang_jwt_jwt_EdDSA +Benchmark_golang_jwt_jwt_EdDSA-10 1000000000 0.0000001 ns/op 0 B/op 0 allocs/op +Benchmark_golang_jwt_jwt_EdDSA-10 1000000000 0.0000000 ns/op 0 B/op 0 allocs/op +Benchmark_golang_jwt_jwt_EdDSA-10 1000000000 0.0000000 ns/op 0 B/op 0 allocs/op +Benchmark_golang_jwt_jwt_EdDSA-10 1000000000 0.0000000 ns/op 0 B/op 0 allocs/op +Benchmark_golang_jwt_jwt_EdDSA-10 1000000000 0 B/op 0 allocs/op +Benchmark_golang_jwt_jwt_HMAC +Benchmark_golang_jwt_jwt_HMAC/sign-HS256 +Benchmark_golang_jwt_jwt_HMAC/sign-HS256-10 781130 1482 ns/op 129.0 B/token 1696 B/op 27 allocs/op +Benchmark_golang_jwt_jwt_HMAC/sign-HS256-10 798369 1476 ns/op 129.0 B/token 1696 B/op 27 allocs/op +Benchmark_golang_jwt_jwt_HMAC/sign-HS256-10 810096 1478 ns/op 129.0 B/token 1696 B/op 27 allocs/op +Benchmark_golang_jwt_jwt_HMAC/sign-HS256-10 802693 1476 ns/op 129.0 B/token 1696 B/op 27 allocs/op +Benchmark_golang_jwt_jwt_HMAC/sign-HS256-10 810577 1470 ns/op 129.0 B/token 1696 B/op 27 allocs/op +Benchmark_golang_jwt_jwt_HMAC/sign-HS384 +Benchmark_golang_jwt_jwt_HMAC/sign-HS384-10 362635 3333 ns/op 150.0 B/token 2080 B/op 27 allocs/op +Benchmark_golang_jwt_jwt_HMAC/sign-HS384-10 360958 3330 ns/op 150.0 B/token 2080 B/op 27 allocs/op +Benchmark_golang_jwt_jwt_HMAC/sign-HS384-10 358340 3336 ns/op 150.0 B/token 2080 B/op 27 allocs/op +Benchmark_golang_jwt_jwt_HMAC/sign-HS384-10 354702 3337 ns/op 150.0 B/token 2080 B/op 27 allocs/op +Benchmark_golang_jwt_jwt_HMAC/sign-HS384-10 358450 3347 ns/op 150.0 B/token 2080 B/op 27 allocs/op +Benchmark_golang_jwt_jwt_HMAC/sign-HS512 +Benchmark_golang_jwt_jwt_HMAC/sign-HS512-10 358262 3353 ns/op 172.0 B/token 2176 B/op 27 allocs/op +Benchmark_golang_jwt_jwt_HMAC/sign-HS512-10 355081 3364 ns/op 172.0 B/token 2176 B/op 27 allocs/op +Benchmark_golang_jwt_jwt_HMAC/sign-HS512-10 359236 3361 ns/op 172.0 B/token 2176 B/op 27 allocs/op +Benchmark_golang_jwt_jwt_HMAC/sign-HS512-10 357702 3368 ns/op 172.0 B/token 2176 B/op 27 allocs/op +Benchmark_golang_jwt_jwt_HMAC/sign-HS512-10 356360 3362 ns/op 172.0 B/token 2176 B/op 27 allocs/op +Benchmark_golang_jwt_jwt_HMAC/check-HS256 +Benchmark_golang_jwt_jwt_HMAC/check-HS256-10 464704 2555 ns/op 3248 B/op 54 allocs/op +Benchmark_golang_jwt_jwt_HMAC/check-HS256-10 445372 2548 ns/op 3248 B/op 54 allocs/op +Benchmark_golang_jwt_jwt_HMAC/check-HS256-10 465698 2551 ns/op 3248 B/op 54 allocs/op +Benchmark_golang_jwt_jwt_HMAC/check-HS256-10 466240 2552 ns/op 3248 B/op 54 allocs/op +Benchmark_golang_jwt_jwt_HMAC/check-HS256-10 472140 2547 ns/op 3248 B/op 54 allocs/op +Benchmark_golang_jwt_jwt_HMAC/check-HS384 +Benchmark_golang_jwt_jwt_HMAC/check-HS384-10 267934 4412 ns/op 3616 B/op 54 allocs/op +Benchmark_golang_jwt_jwt_HMAC/check-HS384-10 271386 4429 ns/op 3616 B/op 54 allocs/op +Benchmark_golang_jwt_jwt_HMAC/check-HS384-10 271707 4426 ns/op 3616 B/op 54 allocs/op +Benchmark_golang_jwt_jwt_HMAC/check-HS384-10 269170 4416 ns/op 3616 B/op 54 allocs/op +Benchmark_golang_jwt_jwt_HMAC/check-HS384-10 271563 4426 ns/op 3616 B/op 54 allocs/op +Benchmark_golang_jwt_jwt_HMAC/check-HS512 +Benchmark_golang_jwt_jwt_HMAC/check-HS512-10 269169 4454 ns/op 3680 B/op 54 allocs/op +Benchmark_golang_jwt_jwt_HMAC/check-HS512-10 270244 4450 ns/op 3680 B/op 54 allocs/op +Benchmark_golang_jwt_jwt_HMAC/check-HS512-10 269605 4451 ns/op 3680 B/op 54 allocs/op +Benchmark_golang_jwt_jwt_HMAC/check-HS512-10 268952 4443 ns/op 3680 B/op 54 allocs/op +Benchmark_golang_jwt_jwt_HMAC/check-HS512-10 267988 4434 ns/op 3680 B/op 54 allocs/op +Benchmark_golang_jwt_jwt_RSA +Benchmark_golang_jwt_jwt_RSA/sign-1024-bit +Benchmark_golang_jwt_jwt_RSA/sign-1024-bit-10 5660 210562 ns/op 257.0 B/token 17849 B/op 124 allocs/op +Benchmark_golang_jwt_jwt_RSA/sign-1024-bit-10 5709 210480 ns/op 257.0 B/token 17849 B/op 124 allocs/op +Benchmark_golang_jwt_jwt_RSA/sign-1024-bit-10 5682 210307 ns/op 257.0 B/token 17849 B/op 124 allocs/op +Benchmark_golang_jwt_jwt_RSA/sign-1024-bit-10 5704 210917 ns/op 257.0 B/token 17850 B/op 124 allocs/op +Benchmark_golang_jwt_jwt_RSA/sign-1024-bit-10 5719 210507 ns/op 257.0 B/token 17849 B/op 124 allocs/op +Benchmark_golang_jwt_jwt_RSA/sign-2048-bit +Benchmark_golang_jwt_jwt_RSA/sign-2048-bit-10 1174 1020157 ns/op 428.0 B/token 32761 B/op 130 allocs/op +Benchmark_golang_jwt_jwt_RSA/sign-2048-bit-10 1177 1019760 ns/op 428.0 B/token 32764 B/op 130 allocs/op +Benchmark_golang_jwt_jwt_RSA/sign-2048-bit-10 1168 1020055 ns/op 428.0 B/token 32760 B/op 130 allocs/op +Benchmark_golang_jwt_jwt_RSA/sign-2048-bit-10 1177 1020451 ns/op 428.0 B/token 32759 B/op 130 allocs/op +Benchmark_golang_jwt_jwt_RSA/sign-2048-bit-10 1174 1019583 ns/op 428.0 B/token 32761 B/op 130 allocs/op +Benchmark_golang_jwt_jwt_RSA/sign-4096-bit +Benchmark_golang_jwt_jwt_RSA/sign-4096-bit-10 213 5605568 ns/op 769.0 B/token 79502 B/op 144 allocs/op +Benchmark_golang_jwt_jwt_RSA/sign-4096-bit-10 213 5605539 ns/op 769.0 B/token 79522 B/op 144 allocs/op +Benchmark_golang_jwt_jwt_RSA/sign-4096-bit-10 213 5605496 ns/op 769.0 B/token 79560 B/op 144 allocs/op +Benchmark_golang_jwt_jwt_RSA/sign-4096-bit-10 213 5604844 ns/op 769.0 B/token 79540 B/op 144 allocs/op +Benchmark_golang_jwt_jwt_RSA/sign-4096-bit-10 213 5602424 ns/op 769.0 B/token 79487 B/op 144 allocs/op +Benchmark_golang_jwt_jwt_RSA/check-1024-bit +Benchmark_golang_jwt_jwt_RSA/check-1024-bit-10 85509 14024 ns/op 5723 B/op 59 allocs/op +Benchmark_golang_jwt_jwt_RSA/check-1024-bit-10 85266 13967 ns/op 5722 B/op 59 allocs/op +Benchmark_golang_jwt_jwt_RSA/check-1024-bit-10 85592 14012 ns/op 5722 B/op 59 allocs/op +Benchmark_golang_jwt_jwt_RSA/check-1024-bit-10 85672 14023 ns/op 5723 B/op 59 allocs/op +Benchmark_golang_jwt_jwt_RSA/check-1024-bit-10 85806 14000 ns/op 5723 B/op 59 allocs/op +Benchmark_golang_jwt_jwt_RSA/check-2048-bit +Benchmark_golang_jwt_jwt_RSA/check-2048-bit-10 38884 30938 ns/op 8461 B/op 59 allocs/op +Benchmark_golang_jwt_jwt_RSA/check-2048-bit-10 38496 30866 ns/op 8461 B/op 59 allocs/op +Benchmark_golang_jwt_jwt_RSA/check-2048-bit-10 38930 30792 ns/op 8461 B/op 59 allocs/op +Benchmark_golang_jwt_jwt_RSA/check-2048-bit-10 38858 30817 ns/op 8461 B/op 59 allocs/op +Benchmark_golang_jwt_jwt_RSA/check-2048-bit-10 38990 30793 ns/op 8461 B/op 59 allocs/op +Benchmark_golang_jwt_jwt_RSA/check-4096-bit +Benchmark_golang_jwt_jwt_RSA/check-4096-bit-10 13519 88761 ns/op 18614 B/op 60 allocs/op +Benchmark_golang_jwt_jwt_RSA/check-4096-bit-10 13521 88787 ns/op 18615 B/op 60 allocs/op +Benchmark_golang_jwt_jwt_RSA/check-4096-bit-10 13515 88781 ns/op 18616 B/op 60 allocs/op +Benchmark_golang_jwt_jwt_RSA/check-4096-bit-10 13510 88740 ns/op 18613 B/op 60 allocs/op +Benchmark_golang_jwt_jwt_RSA/check-4096-bit-10 13528 88630 ns/op 18615 B/op 60 allocs/op +Benchmark_golang_jwt_jwt_ECDSA +Benchmark_golang_jwt_jwt_ECDSA/sign-256-bit +Benchmark_golang_jwt_jwt_ECDSA/sign-256-bit-10 58587 20416 ns/op 172.0 B/token 3996 B/op 54 allocs/op +Benchmark_golang_jwt_jwt_ECDSA/sign-256-bit-10 58545 20413 ns/op 172.0 B/token 3996 B/op 54 allocs/op +Benchmark_golang_jwt_jwt_ECDSA/sign-256-bit-10 58958 20373 ns/op 172.0 B/token 3996 B/op 54 allocs/op +Benchmark_golang_jwt_jwt_ECDSA/sign-256-bit-10 58999 20471 ns/op 172.0 B/token 3996 B/op 54 allocs/op +Benchmark_golang_jwt_jwt_ECDSA/sign-256-bit-10 58796 20388 ns/op 172.0 B/token 3996 B/op 54 allocs/op +Benchmark_golang_jwt_jwt_ECDSA/sign-384-bit +Benchmark_golang_jwt_jwt_ECDSA/sign-384-bit-10 2222 536719 ns/op 214.0 B/token 7434 B/op 82 allocs/op +Benchmark_golang_jwt_jwt_ECDSA/sign-384-bit-10 2233 536769 ns/op 214.0 B/token 7434 B/op 82 allocs/op +Benchmark_golang_jwt_jwt_ECDSA/sign-384-bit-10 2212 536847 ns/op 214.0 B/token 7434 B/op 82 allocs/op +Benchmark_golang_jwt_jwt_ECDSA/sign-384-bit-10 2234 536737 ns/op 214.0 B/token 7434 B/op 82 allocs/op +Benchmark_golang_jwt_jwt_ECDSA/sign-384-bit-10 2216 536669 ns/op 214.0 B/token 7434 B/op 82 allocs/op +Benchmark_golang_jwt_jwt_ECDSA/sign-521-bit +Benchmark_golang_jwt_jwt_ECDSA/sign-521-bit-10 748 1602664 ns/op 262.0 B/token 9180 B/op 82 allocs/op +Benchmark_golang_jwt_jwt_ECDSA/sign-521-bit-10 748 1601860 ns/op 262.0 B/token 9180 B/op 82 allocs/op +Benchmark_golang_jwt_jwt_ECDSA/sign-521-bit-10 747 1601900 ns/op 262.0 B/token 9179 B/op 82 allocs/op +Benchmark_golang_jwt_jwt_ECDSA/sign-521-bit-10 750 1602989 ns/op 262.0 B/token 9180 B/op 82 allocs/op +Benchmark_golang_jwt_jwt_ECDSA/sign-521-bit-10 748 1603239 ns/op 262.0 B/token 9180 B/op 82 allocs/op +Benchmark_golang_jwt_jwt_ECDSA/check-256-bit +Benchmark_golang_jwt_jwt_ECDSA/check-256-bit-10 20563 58236 ns/op 4041 B/op 68 allocs/op +Benchmark_golang_jwt_jwt_ECDSA/check-256-bit-10 20600 58305 ns/op 4041 B/op 68 allocs/op +Benchmark_golang_jwt_jwt_ECDSA/check-256-bit-10 20587 58258 ns/op 4041 B/op 68 allocs/op +Benchmark_golang_jwt_jwt_ECDSA/check-256-bit-10 20572 58275 ns/op 4041 B/op 68 allocs/op +Benchmark_golang_jwt_jwt_ECDSA/check-256-bit-10 20587 58224 ns/op 4041 B/op 68 allocs/op +Benchmark_golang_jwt_jwt_ECDSA/check-384-bit +Benchmark_golang_jwt_jwt_ECDSA/check-384-bit-10 1180 1010285 ns/op 7292 B/op 119 allocs/op +Benchmark_golang_jwt_jwt_ECDSA/check-384-bit-10 1188 1010886 ns/op 7292 B/op 119 allocs/op +Benchmark_golang_jwt_jwt_ECDSA/check-384-bit-10 1188 1010517 ns/op 7292 B/op 119 allocs/op +Benchmark_golang_jwt_jwt_ECDSA/check-384-bit-10 1188 1010456 ns/op 7292 B/op 119 allocs/op +Benchmark_golang_jwt_jwt_ECDSA/check-384-bit-10 1188 1010825 ns/op 7291 B/op 119 allocs/op +Benchmark_golang_jwt_jwt_ECDSA/check-521-bit +Benchmark_golang_jwt_jwt_ECDSA/check-521-bit-10 386 3100910 ns/op 8796 B/op 119 allocs/op +Benchmark_golang_jwt_jwt_ECDSA/check-521-bit-10 386 3108435 ns/op 8796 B/op 119 allocs/op +Benchmark_golang_jwt_jwt_ECDSA/check-521-bit-10 386 3101219 ns/op 8795 B/op 119 allocs/op +Benchmark_golang_jwt_jwt_ECDSA/check-521-bit-10 386 3102096 ns/op 8796 B/op 119 allocs/op +Benchmark_golang_jwt_jwt_ECDSA/check-521-bit-10 386 3101261 ns/op 8796 B/op 119 allocs/op +PASS diff --git a/jwt/bench_test.go b/jwt/bench_test.go new file mode 100644 index 0000000..6c17fa8 --- /dev/null +++ b/jwt/bench_test.go @@ -0,0 +1,410 @@ +package jwt_test + +import ( + "crypto/ecdsa" + "crypto/rsa" + "fmt" + "testing" + "time" + + cristalhq_jwt "github.com/cristalhq/jwt/v4" + golang_jwt_jwt "github.com/golang-jwt/jwt" + lestrrat_go_jwx "github.com/lestrrat-go/jwx" + pascaldekloe_jwt "github.com/pascaldekloe/jwt" +) + +var cristalhq_jwt_benchClaims = &struct { + cristalhq_jwt.RegisteredClaims +}{ + RegisteredClaims: cristalhq_jwt.RegisteredClaims{ + Issuer: "benchmark", + IssuedAt: cristalhq_jwt.NewNumericDate(time.Now()), + }, +} + +func Benchmark_cristalhq_jwt_EdDSA(b *testing.B) { + signer, err := cristalhq_jwt.NewSignerEdDSA(testKeyEd25519Private) + failIfErr(b, err) + + bui := cristalhq_jwt.NewBuilder(signer) + b.Run("sign-"+cristalhq_jwt.EdDSA.String(), func(b *testing.B) { + var tokenLen int + for i := 0; i < b.N; i++ { + token, err := bui.Build(cristalhq_jwt_benchClaims) + failIfErr(b, err) + tokenLen += len(token.Bytes()) + } + b.ReportMetric(float64(tokenLen)/float64(b.N), "B/token") + }) + + token, err := cristalhq_jwt.NewBuilder(signer).Build(cristalhq_jwt_benchClaims) + failIfErr(b, err) + + verifier, err := cristalhq_jwt.NewVerifierEdDSA(testKeyEd25519Public) + failIfErr(b, err) + + b.Run("check-"+cristalhq_jwt.EdDSA.String(), func(b *testing.B) { + for i := 0; i < b.N; i++ { + err := verifier.Verify(token) + failIfErr(b, err) + } + }) +} + +func Benchmark_cristalhq_jwt_HMAC(b *testing.B) { + algs := []cristalhq_jwt.Algorithm{cristalhq_jwt.HS256, cristalhq_jwt.HS384, cristalhq_jwt.HS512} + + for _, alg := range algs { + signer, err := cristalhq_jwt.NewSignerHS(alg, keysHMAC) + failIfErr(b, err) + bui := cristalhq_jwt.NewBuilder(signer) + b.Run("sign-"+alg.String(), func(b *testing.B) { + var tokenLen int + for i := 0; i < b.N; i++ { + token, err := bui.Build(cristalhq_jwt_benchClaims) + failIfErr(b, err) + tokenLen += len(token.Bytes()) + } + b.ReportMetric(float64(tokenLen)/float64(b.N), "B/token") + }) + } + + for _, alg := range algs { + signer, err := cristalhq_jwt.NewSignerHS(alg, keysHMAC) + failIfErr(b, err) + token, err := cristalhq_jwt.NewBuilder(signer).Build(cristalhq_jwt_benchClaims) + failIfErr(b, err) + + verifier, err := cristalhq_jwt.NewVerifierHS(alg, keysHMAC) + failIfErr(b, err) + b.Run("check-"+alg.String(), func(b *testing.B) { + for i := 0; i < b.N; i++ { + err := verifier.Verify(token) + failIfErr(b, err) + } + }) + } +} + +func Benchmark_cristalhq_jwt_RSA(b *testing.B) { + keys := []*rsa.PrivateKey{testKeyRSA1024, testKeyRSA2048, testKeyRSA4096} + + for _, key := range keys { + signer, err := cristalhq_jwt.NewSignerRS(cristalhq_jwt.RS384, key) + failIfErr(b, err) + bui := cristalhq_jwt.NewBuilder(signer) + b.Run(fmt.Sprintf("sign-%d-bit", key.Size()*8), func(b *testing.B) { + var tokenLen int + for i := 0; i < b.N; i++ { + token, err := bui.Build(cristalhq_jwt_benchClaims) + failIfErr(b, err) + tokenLen += len(token.Bytes()) + } + b.ReportMetric(float64(tokenLen)/float64(b.N), "B/token") + }) + } + + for _, key := range keys { + signer, err := cristalhq_jwt.NewSignerRS(cristalhq_jwt.RS384, key) + failIfErr(b, err) + token, err := cristalhq_jwt.NewBuilder(signer).Build(cristalhq_jwt_benchClaims) + failIfErr(b, err) + + verifier, err := cristalhq_jwt.NewVerifierRS(cristalhq_jwt.RS384, &key.PublicKey) + failIfErr(b, err) + b.Run(fmt.Sprintf("check-%d-bit", key.Size()*8), func(b *testing.B) { + for i := 0; i < b.N; i++ { + err := verifier.Verify(token) + failIfErr(b, err) + } + }) + } +} + +func Benchmark_cristalhq_jwt_ECDSA(b *testing.B) { + tests := []struct { + key *ecdsa.PrivateKey + alg cristalhq_jwt.Algorithm + }{ + {keysECDSA[0], cristalhq_jwt.ES256}, + {keysECDSA[1], cristalhq_jwt.ES384}, + {keysECDSA[2], cristalhq_jwt.ES512}, + } + + for _, test := range tests { + signer, err := cristalhq_jwt.NewSignerES(test.alg, test.key) + failIfErr(b, err) + bui := cristalhq_jwt.NewBuilder(signer) + b.Run("sign-"+test.alg.String(), func(b *testing.B) { + var tokenLen int + for i := 0; i < b.N; i++ { + token, err := bui.Build(cristalhq_jwt_benchClaims) + failIfErr(b, err) + tokenLen += len(token.Bytes()) + } + b.ReportMetric(float64(tokenLen)/float64(b.N), "B/token") + }) + } + + for _, test := range tests { + signer, err := cristalhq_jwt.NewSignerES(test.alg, test.key) + failIfErr(b, err) + bui := cristalhq_jwt.NewBuilder(signer) + token, err := bui.Build(cristalhq_jwt_benchClaims) + failIfErr(b, err) + + verifier, err := cristalhq_jwt.NewVerifierES(test.alg, &test.key.PublicKey) + failIfErr(b, err) + b.Run("check-"+test.alg.String(), func(b *testing.B) { + for i := 0; i < b.N; i++ { + err := verifier.Verify(token) + failIfErr(b, err) + } + }) + } +} + +var pascaldekloe_jwt_benchClaims = &pascaldekloe_jwt.Claims{ + Registered: pascaldekloe_jwt.Registered{ + Issuer: "benchmark", + Issued: pascaldekloe_jwt.NewNumericTime(time.Now()), + }, +} + +func Benchmark_pascaldekloe_jwt_EdDSA(b *testing.B) { + b.Run("sign-"+pascaldekloe_jwt.EdDSA, func(b *testing.B) { + var tokenLen int + for i := 0; i < b.N; i++ { + token, err := pascaldekloe_jwt_benchClaims.EdDSASign(testKeyEd25519Private) + failIfErr(b, err) + tokenLen += len(token) + } + b.ReportMetric(float64(tokenLen)/float64(b.N), "B/token") + }) + + b.Run("check-"+pascaldekloe_jwt.EdDSA, func(b *testing.B) { + token, err := pascaldekloe_jwt_benchClaims.EdDSASign(testKeyEd25519Private) + failIfErr(b, err) + + for i := 0; i < b.N; i++ { + _, err := pascaldekloe_jwt.EdDSACheck(token, testKeyEd25519Public) + failIfErr(b, err) + } + }) +} + +func Benchmark_pascaldekloe_jwt_HMAC(b *testing.B) { + algs := []string{pascaldekloe_jwt.HS256, pascaldekloe_jwt.HS384, pascaldekloe_jwt.HS512} + + for _, alg := range algs { + b.Run("sign-"+alg, func(b *testing.B) { + var tokenLen int + for i := 0; i < b.N; i++ { + token, err := pascaldekloe_jwt_benchClaims.HMACSign(alg, keysHMAC) + failIfErr(b, err) + tokenLen += len(token) + } + b.ReportMetric(float64(tokenLen)/float64(b.N), "B/token") + }) + } + + for _, alg := range algs { + token, err := pascaldekloe_jwt_benchClaims.HMACSign(alg, keysHMAC) + failIfErr(b, err) + + b.Run("check-"+alg, func(b *testing.B) { + for i := 0; i < b.N; i++ { + _, err := pascaldekloe_jwt.HMACCheck(token, keysHMAC) + failIfErr(b, err) + } + }) + } +} + +func Benchmark_pascaldekloe_jwt_RSA(b *testing.B) { + keys := []*rsa.PrivateKey{testKeyRSA1024, testKeyRSA2048, testKeyRSA4096} + + for _, key := range keys { + b.Run(fmt.Sprintf("sign-%d-bit", key.Size()*8), func(b *testing.B) { + var tokenLen int + for i := 0; i < b.N; i++ { + token, err := pascaldekloe_jwt_benchClaims.RSASign(pascaldekloe_jwt.RS384, key) + failIfErr(b, err) + tokenLen += len(token) + } + b.ReportMetric(float64(tokenLen)/float64(b.N), "B/token") + }) + } + + for _, key := range keys { + token, err := pascaldekloe_jwt_benchClaims.RSASign(pascaldekloe_jwt.RS384, key) + failIfErr(b, err) + + b.Run(fmt.Sprintf("check-%d-bit", key.Size()*8), func(b *testing.B) { + for i := 0; i < b.N; i++ { + _, err := pascaldekloe_jwt.RSACheck(token, &key.PublicKey) + failIfErr(b, err) + } + }) + } +} + +func Benchmark_pascaldekloe_jwt_ECDSA(b *testing.B) { + tests := []struct { + key *ecdsa.PrivateKey + alg string + }{ + {testKeyEC256, pascaldekloe_jwt.ES256}, + {testKeyEC384, pascaldekloe_jwt.ES384}, + {testKeyEC521, pascaldekloe_jwt.ES512}, + } + + for _, test := range tests { + b.Run("sign-"+test.alg, func(b *testing.B) { + var tokenLen int + for i := 0; i < b.N; i++ { + token, err := pascaldekloe_jwt_benchClaims.ECDSASign(test.alg, test.key) + failIfErr(b, err) + tokenLen += len(token) + } + b.ReportMetric(float64(tokenLen)/float64(b.N), "B/token") + }) + } + + for _, test := range tests { + token, err := pascaldekloe_jwt_benchClaims.ECDSASign(test.alg, test.key) + failIfErr(b, err) + + b.Run("check-"+test.alg, func(b *testing.B) { + for i := 0; i < b.N; i++ { + _, err := pascaldekloe_jwt.ECDSACheck(token, &test.key.PublicKey) + failIfErr(b, err) + } + }) + } +} + +var golang_jwt_jwt_benchClaims = &golang_jwt_jwt.StandardClaims{ + Issuer: "benchmark", + IssuedAt: time.Now().Unix(), +} + +func Benchmark_golang_jwt_jwt_EdDSA(b *testing.B) {} + +func Benchmark_golang_jwt_jwt_HMAC(b *testing.B) { + algs := []golang_jwt_jwt.SigningMethod{ + golang_jwt_jwt.SigningMethodHS256, + golang_jwt_jwt.SigningMethodHS384, + golang_jwt_jwt.SigningMethodHS512, + } + + for _, alg := range algs { + token := golang_jwt_jwt.NewWithClaims(alg, golang_jwt_jwt_benchClaims) + + b.Run("sign-"+alg.Alg(), func(b *testing.B) { + var tokenLen int + for i := 0; i < b.N; i++ { + tokenStr, err := token.SignedString(keysHMAC) + failIfErr(b, err) + tokenLen += len(tokenStr) + } + b.ReportMetric(float64(tokenLen)/float64(b.N), "B/token") + }) + } + + for _, alg := range algs { + token := golang_jwt_jwt.NewWithClaims(alg, golang_jwt_jwt_benchClaims) + tokenStr, err := token.SignedString(keysHMAC) + failIfErr(b, err) + + b.Run("check-"+alg.Alg(), func(b *testing.B) { + for i := 0; i < b.N; i++ { + token, err := golang_jwt_jwt.Parse(tokenStr, func(token *golang_jwt_jwt.Token) (interface{}, error) { + return keysHMAC, nil + }) + if err != nil || !token.Valid { + b.Fatal(err) + } + } + }) + } +} + +func Benchmark_golang_jwt_jwt_RSA(b *testing.B) { + for _, key := range keysRSA { + token := golang_jwt_jwt.NewWithClaims(golang_jwt_jwt.SigningMethodRS384, golang_jwt_jwt_benchClaims) + + b.Run(fmt.Sprintf("sign-%d-bit", key.Size()*8), func(b *testing.B) { + var tokenLen int + for i := 0; i < b.N; i++ { + tokenStr, err := token.SignedString(key) + failIfErr(b, err) + tokenLen += len(tokenStr) + } + b.ReportMetric(float64(tokenLen)/float64(b.N), "B/token") + }) + } + + for _, key := range keysRSA { + token := golang_jwt_jwt.NewWithClaims(golang_jwt_jwt.SigningMethodRS384, golang_jwt_jwt_benchClaims) + tokenStr, err := token.SignedString(key) + failIfErr(b, err) + + b.Run(fmt.Sprintf("check-%d-bit", key.Size()*8), func(b *testing.B) { + for i := 0; i < b.N; i++ { + token, err := golang_jwt_jwt.Parse(tokenStr, func(token *golang_jwt_jwt.Token) (interface{}, error) { + return &key.PublicKey, nil + }) + failIfErr(b, err) + if !token.Valid { + b.Fatal("not valiad") + } + } + }) + } +} + +func Benchmark_golang_jwt_jwt_ECDSA(b *testing.B) { + tests := []struct { + key *ecdsa.PrivateKey + alg *golang_jwt_jwt.SigningMethodECDSA + }{ + {keysECDSA[0], golang_jwt_jwt.SigningMethodES256}, + {keysECDSA[1], golang_jwt_jwt.SigningMethodES384}, + {keysECDSA[2], golang_jwt_jwt.SigningMethodES512}, + } + + for _, test := range tests { + token := golang_jwt_jwt.NewWithClaims(test.alg, golang_jwt_jwt_benchClaims) + + b.Run(fmt.Sprintf("sign-%d-bit", test.key.Params().BitSize), func(b *testing.B) { + var tokenLen int + for i := 0; i < b.N; i++ { + tokenStr, err := token.SignedString(test.key) + failIfErr(b, err) + tokenLen += len(tokenStr) + } + b.ReportMetric(float64(tokenLen)/float64(b.N), "B/token") + }) + } + + for _, test := range tests { + token := golang_jwt_jwt.NewWithClaims(test.alg, golang_jwt_jwt_benchClaims) + tokenStr, err := token.SignedString(test.key) + failIfErr(b, err) + + b.Run(fmt.Sprintf("check-%d-bit", test.key.Params().BitSize), func(b *testing.B) { + for i := 0; i < b.N; i++ { + token, err := golang_jwt_jwt.Parse(tokenStr, func(token *golang_jwt_jwt.Token) (interface{}, error) { + return &test.key.PublicKey, nil + }) + failIfErr(b, err) + if !token.Valid { + b.Fatal("not valiad") + } + } + }) + } +} + +var lestrrat_go_jwx_benchClaims = lestrrat_go_jwx.DecoderSettings diff --git a/jwt/go.mod b/jwt/go.mod new file mode 100644 index 0000000..f63b018 --- /dev/null +++ b/jwt/go.mod @@ -0,0 +1,16 @@ +module github.com/cristaloleg/benches/jwt + +go 1.17 + +require ( + github.com/cristalhq/jwt/v4 v4.0.0 + github.com/golang-jwt/jwt v3.2.2+incompatible + github.com/lestrrat-go/jwx v1.2.23 + github.com/pascaldekloe/jwt v1.10.0 +) + +require ( + github.com/goccy/go-json v0.9.6 // indirect + github.com/lestrrat-go/option v1.0.0 // indirect + github.com/pkg/errors v0.9.1 // indirect +) diff --git a/jwt/go.sum b/jwt/go.sum new file mode 100644 index 0000000..ca63ce8 --- /dev/null +++ b/jwt/go.sum @@ -0,0 +1,48 @@ +github.com/cristalhq/jwt/v4 v4.0.0 h1:gy4qHXjr7U8aPn9G8onlLfnC2UpjTyOg9QvEK/sDqq4= +github.com/cristalhq/jwt/v4 v4.0.0/go.mod h1:HnYraSNKDRag1DZP92rYHyrjyQHnVEHPNqesmzs+miQ= +github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/decred/dcrd/crypto/blake256 v1.0.0/go.mod h1:sQl2p6Y26YV+ZOcSTP6thNdn47hh8kt6rqSlvmrXFAc= +github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.0-20210816181553-5444fa50b93d h1:1iy2qD6JEhHKKhUOA9IWs7mjco7lnw2qx8FsRI2wirE= +github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.0-20210816181553-5444fa50b93d/go.mod h1:tmAIfUFEirG/Y8jhZ9M+h36obRZAk/1fcSpXwAVlfqE= +github.com/goccy/go-json v0.9.6 h1:5/4CtRQdtsX0sal8fdVhTaiMN01Ri8BExZZ8iRmHQ6E= +github.com/goccy/go-json v0.9.6/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= +github.com/golang-jwt/jwt v3.2.2+incompatible h1:IfV12K8xAKAnZqdXVzCZ+TOjboZ2keLg81eXfW3O+oY= +github.com/golang-jwt/jwt v3.2.2+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I= +github.com/lestrrat-go/backoff/v2 v2.0.8 h1:oNb5E5isby2kiro9AgdHLv5N5tint1AnDVVf2E2un5A= +github.com/lestrrat-go/backoff/v2 v2.0.8/go.mod h1:rHP/q/r9aT27n24JQLa7JhSQZCKBBOiM/uP402WwN8Y= +github.com/lestrrat-go/blackmagic v1.0.0 h1:XzdxDbuQTz0RZZEmdU7cnQxUtFUzgCSPq8RCz4BxIi4= +github.com/lestrrat-go/blackmagic v1.0.0/go.mod h1:TNgH//0vYSs8VXDCfkZLgIrVTTXQELZffUV0tz3MtdQ= +github.com/lestrrat-go/httpcc v1.0.1 h1:ydWCStUeJLkpYyjLDHihupbn2tYmZ7m22BGkcvZZrIE= +github.com/lestrrat-go/httpcc v1.0.1/go.mod h1:qiltp3Mt56+55GPVCbTdM9MlqhvzyuL6W/NMDA8vA5E= +github.com/lestrrat-go/iter v1.0.1 h1:q8faalr2dY6o8bV45uwrxq12bRa1ezKrB6oM9FUgN4A= +github.com/lestrrat-go/iter v1.0.1/go.mod h1:zIdgO1mRKhn8l9vrZJZz9TUMMFbQbLeTsbqPDrJ/OJc= +github.com/lestrrat-go/jwx v1.2.23 h1:8oP5fY1yzCRraUNNyfAVdOkLCqY7xMZz11lVcvHqC1Y= +github.com/lestrrat-go/jwx v1.2.23/go.mod h1:sAXjRwzSvCN6soO4RLoWWm1bVPpb8iOuv0IYfH8OWd8= +github.com/lestrrat-go/option v1.0.0 h1:WqAWL8kh8VcSoD6xjSH34/1m8yxluXQbDeKNfvFeEO4= +github.com/lestrrat-go/option v1.0.0/go.mod h1:5ZHFbivi4xwXxhxY9XHDe2FHo6/Z7WWmtT7T5nBBp3I= +github.com/pascaldekloe/jwt v1.10.0 h1:ktcIUV4TPvh404R5dIBEnPCsSwj0sqi3/0+XafE5gJs= +github.com/pascaldekloe/jwt v1.10.0/go.mod h1:TKhllgThT7TOP5rGr2zMLKEDZRAgJfBbtKyVeRsNB9A= +github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= +github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +golang.org/x/crypto v0.0.0-20220214200702-86341886e292 h1:f+lwQ+GtmgoY+A2YaQxlSOnDjXcQ7ZRLWOHbC6HtRqE= +golang.org/x/crypto v0.0.0-20220214200702-86341886e292/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= +golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/jwt/keys_test.go b/jwt/keys_test.go new file mode 100644 index 0000000..307975e --- /dev/null +++ b/jwt/keys_test.go @@ -0,0 +1,188 @@ +package jwt_test + +import ( + "crypto/ecdsa" + "crypto/ed25519" + "crypto/rsa" + "crypto/x509" + "encoding/pem" + "strings" + "testing" +) + +var ( + keysHMAC = []byte(strings.Repeat("a", 64)) + keysRSA = []*rsa.PrivateKey{testKeyRSA1024, testKeyRSA2048, testKeyRSA4096} + keysECDSA = []*ecdsa.PrivateKey{testKeyEC256, testKeyEC384, testKeyEC521} +) + +func failIfErr(tb testing.TB, err error) { + tb.Helper() + if err != nil { + tb.Fatal(err) + } +} + +func mustParseECKey(s string) *ecdsa.PrivateKey { + block, _ := pem.Decode([]byte(s)) + if block == nil { + panic("invalid PEM") + } + + key, err := x509.ParseECPrivateKey(block.Bytes) + if err != nil { + panic(err) + } + return key +} + +func mustParseRSAKey(s string) *rsa.PrivateKey { + block, _ := pem.Decode([]byte(s)) + if block == nil { + panic("invalid PEM") + } + + key, err := x509.ParsePKCS1PrivateKey(block.Bytes) + if err != nil { + panic(err) + } + return key +} + +var testKeyEC256 = mustParseECKey(`-----BEGIN EC PRIVATE KEY----- +MHcCAQEEIBOm12aaXvqSzysOSGV2yL/xKY3kCtaOfAPY1KQN2sTJoAoGCCqGSM49 +AwEHoUQDQgAEX0iTLAcGqlWeGIRtIk0G2PRgpf/6gLxOTyMAdriP4NLRkuu+9Idt +y3qmEizRC0N81j84E213/LuqLqnsrgfyiw== +-----END EC PRIVATE KEY-----`) + +var testKeyEC384 = mustParseECKey(`-----BEGIN EC PRIVATE KEY----- +MIGkAgEBBDBluSyfK9BEPc9y944ZLahd4xHRVse64iCeEC5gBQ4UM1961bsEthUC +NKXyTGTBuW2gBwYFK4EEACKhZANiAAR3Il6V61OwAnb6oYm4hQ4TVVaGQ2QGzrSi +eYGoRewNhAaZ8wfemWX4fww7yNi6AmUzWV8Su5Qq3dtN3nLpKUEaJrTvfjtowrr/ +ZtU1fZxzI/agEpG2+uLFW6JNdYzp67w= +-----END EC PRIVATE KEY-----`) + +var testKeyEC521 = mustParseECKey(`-----BEGIN EC PRIVATE KEY----- +MIHcAgEBBEIBH31vhkSH+x+J8C/xf/PRj81u3MCqgiaGdW1S1jcjEuikczbbX689 +9ETHGCPtHEWw/Il1RAFaKMvndmfDVd/YapmgBwYFK4EEACOhgYkDgYYABAGNpBDA +Lx6rKQXWdWQR581uw9dTuV8zjmkSpLZ3k0qLHVlOqt00AfEL4NO+E7fxh4SuAZPb +RDMu2lx4lWOM2EyFvgFIyu8xlA9lEg5GKq+A7+y5r99RLughiDd52vGnudMspHEy +x6IpwXzTZR/T8TkluL3jDWtVNFxGBf/aEErnpeLfRQ== +-----END EC PRIVATE KEY-----`) + +var testKeyRSA1024 = mustParseRSAKey(`-----BEGIN RSA PRIVATE KEY----- +MIICXAIBAAKBgQDCzQ4MMppUkCXTi/BjPWO2gLnaVmPhyMdo7rnccfoBnH5lCTdY +x2aK2vNkVVLi4w8zITBXAXwKB7O5iQaaXImnUD2KPReRKbyGbvkGwQGpU1UsZjzZ +uPFfbDtdWr+d2CxQUdPjKu886Lad4BsJFWSJYt06K1byYCGAYyN5hosmOQIDAQAB +AoGAO5EIYqJ2nrUVXALGlxIGk5/5NNKF6FzE3UlifA4+LI/19l9DFVqj+IHLOzr8 +BXT5COF1LqW9kDOauXk1E66ISJ/vAFYvS+hIugKDqUhpBTpgPa2nyJGOjUHScvIP +sVdo1unpYU40bvhhy7HD4kwQvohYq9w5KW732jpqPJK5TKECQQD3XpZGlXAJ+O/5 +p97Xwt6Rz7peG1Aqx3TlzVUvOPCXT8rnycEub0j52sYZUwg3dtf763R385pJmBJs +TJc2oN9PAkEAyZjyDqGUM6IJy7O55Ylsy3dxply7NIym+BM4p8MiEwzHZb5dXgX3 +pxuPlLX3DojlGWNcLB5+gw1ZSq9Y5dz/9wJBAOQoQtUBemBIUhbj5d795sl4Xn30 +FUIPy9s1Qy+WBhqZxx148gxBKn8BcRvkgLyfieDasAb/Ebx1XfCzx/jj8nMCQBNr +WT3RkL4ciMcHjAuxXjqHSfpVim74cYkKCPYYFOsy2u5RFRtehcmiHQWdNaw/wZnd +eV6CnXswSP6pv219CWcCQBv3wKhme0RkuPuyG4MUFFeHxOcilasHx/nWiz8U90Tm +hP30X1iUlekEFj/2oneT6qWqtH4nVX18/WehPQoDoLg= +-----END RSA PRIVATE KEY-----`) + +var testKeyRSA2048 = mustParseRSAKey(`-----BEGIN RSA PRIVATE KEY----- +MIIEowIBAAKCAQEA8NBRypbuyT1o2p7Ze94kmZTrwu2TsqZ1u7BOcY97xn6cc7/e +c9aZI+S4Ure57XNvKQAZlULWjWhEfY8vhP1m2hDzVCV0DnNRCPmMJxx212b2iTmA +1IsMmRYFHOYgVVUdx5QzS1xIQMZgyLP++CBkYJXZZCC1MBqyW93BkBcNzt0+70ZT +mMpXOYKoq/pFcxVMllKY41JCcDqpKcJnSmWyS+DQX5X4CcNecXxCMoL7WGeMVrng +7NTFJmv4Iyh19/WRERqQUqlPPQoWd0Wrw/Ih+p38PlxvdxxcGIgG8gZC1eZ441MR +4KeHEnx7nQ08TtzdsTULYlx3kM173h1yI+HuBwIDAQABAoIBAQCyX5w2E9aL+ZDR +Xxh5R/KUUFrR6Giey+4pOE7ijwV/4gjBND3yT+LfU2u02aI+4GJWXFyW0wtZcwJI +fucT+x9UJ3oVuihdC83ad/34en0M0JeMzas/xD9wpX7kCRGqI4ILcxsLly9ty4Ol +Jq6V3Gh9ooGESTXsi9nRclEOCgWQU6F8BeDGbI19aqkFi67wZqvOYrlUXfznRwQQ +iaffaeh+wH5qp79dd+MoSPJLmhuhNH6Q/T70tVqTvlslufcro1/7YYuq9X2/IO+u +O1Nd1/nyT46xYQ16HqLdH2KPN2jsmbWFCMM4leTbyk18ldDnU3LG7BMwwoW7vemE +gU8KuX4BAoGBAP4zMVT+M1421fXUTyxK1ViQprdqT5zksFwK0cMdy1upE0EFqUrr +TtN5mao+7rGFp7R/0xuVSwYs+LX7jsrRPXn5JgB2JdPg9UakdKkULAfGVCLJouXm +/32C9YlFuqPjJWxr5Ndb1aqvPNfIvsfmys1O+GJ39x9R+iFezvuKN2BvAoGBAPKE +3E9fSWjXg9N+y2QazeU6wJjJYhIGtceuTwPPW1n3IfOzgB1QHXZhH7YM07OoI2jF +NFBM99ygjdfRbKCosEQoUQCF78avHYJJDhdPhjAWiaIZg7X4gfgWqEMJ0SWXyCAM +cxQ0XEC0AHocWNipWv8zVFEC62K3omMXS/9leefpAoGAB/eGxkkpRvyk/A1pZdP6 +l8oAz6LPV/V66YeVR245n2fPKKyKv8RcNhiLjmBmjr3HocqXzTeCoHDsYpe9w/GG +4bnDTSRmzxsv1MT2uw3cy2mV3XlAV8BDpaVjGKhMzzIhTCKdi3pfWfggCgtKn21G +UeT1t/BWmG6zTjRwfEW6spUCgYAUsXF69E53O6xr523DZOYcoR696rELiLcKCr2D +PbY1vviOqspLtgJNj4v9JKsLsVUUI3+LOoYLtUdlGuGB8+LWbfo7aTJEabzC2Sjy +pD526/Vid3rdlA7C9Gv3DGdkJcdVtLo9Bxq4CqPfx3ttQUYacG7JWs5q5fBdNCev +6yCzwQKBgHZRiC82Bzd10OgIL4WadlNphmMnGgROgNhwBu2bd5loPc+26omBAVtC +mQ9Ug7u6QOshlvxmqrgRFlWkLAwozqvS6RC4yru8FRqYnmtW7QgxO1pOj9VEzHSw +iugbqlkWvaTnn5JZoHZ+60PZc8Z4UJvzi0/h9ksnWhp5l6u1KBmc +-----END RSA PRIVATE KEY-----`) + +var testKeyRSA4096 = mustParseRSAKey(`-----BEGIN RSA PRIVATE KEY----- +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 +-----END RSA PRIVATE KEY-----`) + +// example from RFC 8037, appendix A.1 +var testKeyEd25519Private = ed25519.PrivateKey([]byte{ + 0x9d, 0x61, 0xb1, 0x9d, 0xef, 0xfd, 0x5a, 0x60, + 0xba, 0x84, 0x4a, 0xf4, 0x92, 0xec, 0x2c, 0xc4, + 0x44, 0x49, 0xc5, 0x69, 0x7b, 0x32, 0x69, 0x19, + 0x70, 0x3b, 0xac, 0x03, 0x1c, 0xae, 0x7f, 0x60, + // public key suffix + 0xd7, 0x5a, 0x98, 0x01, 0x82, 0xb1, 0x0a, 0xb7, + 0xd5, 0x4b, 0xfe, 0xd3, 0xc9, 0x64, 0x07, 0x3a, + 0x0e, 0xe1, 0x72, 0xf3, 0xda, 0xa6, 0x23, 0x25, + 0xaf, 0x02, 0x1a, 0x68, 0xf7, 0x07, 0x51, 0x1a, +}) + +// example from RFC 8037, appendix A.1 +var testKeyEd25519Public = ed25519.PublicKey([]byte{ + 0xd7, 0x5a, 0x98, 0x01, 0x82, 0xb1, 0x0a, 0xb7, + 0xd5, 0x4b, 0xfe, 0xd3, 0xc9, 0x64, 0x07, 0x3a, + 0x0e, 0xe1, 0x72, 0xf3, 0xda, 0xa6, 0x23, 0x25, + 0xaf, 0x02, 0x1a, 0x68, 0xf7, 0x07, 0x51, 0x1a, +})