Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor symmetric one-shots for improved performance #58270

Merged
merged 3 commits into from
Sep 17, 2021

Conversation

vcsjones
Copy link
Member

@vcsjones vcsjones commented Aug 27, 2021

This is a revival of #55090 which was unable to make it in the 6.0 time frame.

This reduces allocations and overhead in for the symmetric one shots.

  • The Reset is skipped in the case of one shots since we won't use the cipher after the finalize. It's finalized, then disposed.
  • Since we don't reset, we don't need to hang on to a copy of the original IV to reset with. CNG still requires a copy of the IV because each call to encrypt or decrypt accepts the IV as it is updated throughout each block.

Starting off a draft because I think I can fix up Windows a bit more, but benchmarks look good.

Allocations that are "overhead" are cut about half. ECB and CBC show small throughput improvements. CFB shows larger improvements on the Apple platform because the overhead of doing a Reset with CFB is much higher.

Work remaining:

  • See what we can do about the IV situation on Windows. Probably rent for the IV.
  • Benchmarks on other platforms
  • Benchmark TransformBlock and TransformFinalBlock to ensure we didn't regress the non-one-shots.

Contributes to #55601.

Benchmarks on Apple M1

CBC

Method Job Toolchain DataSize Mode Algorithm Mean Error StdDev Ratio Gen 0 Gen 1 Gen 2 Allocated
Encrypt_Cbc_ToSpan Job-SPRJJB branch 16 None Internal.Cryptography.AesImplementation 558.7 ns 1.83 ns 1.62 ns 0.86 0.0610 - - 128 B
Encrypt_Cbc_ToSpan Job-LCBJSG main 16 None Internal.Cryptography.AesImplementation 650.2 ns 2.76 ns 2.45 ns 1.00 0.1068 - - 224 B
Decrypt_Cbc_ToSpan Job-SPRJJB branch 16 None Internal.Cryptography.AesImplementation 558.5 ns 4.28 ns 4.00 ns 0.87 0.0610 - - 128 B
Decrypt_Cbc_ToSpan Job-LCBJSG main 16 None Internal.Cryptography.AesImplementation 642.1 ns 2.38 ns 1.99 ns 1.00 0.1106 - - 232 B
Encrypt_Cbc_ToSpan Job-SPRJJB branch 16 None Internal.Cryptography.DesImplementation 3,833.9 ns 2.59 ns 2.16 ns 0.95 0.0763 - - 168 B
Encrypt_Cbc_ToSpan Job-LCBJSG main 16 None Internal.Cryptography.DesImplementation 4,047.9 ns 4.40 ns 3.90 ns 1.00 0.1221 - - 256 B
Decrypt_Cbc_ToSpan Job-SPRJJB branch 16 None Internal.Cryptography.DesImplementation 3,922.1 ns 4.68 ns 4.15 ns 0.97 0.0763 - - 168 B
Decrypt_Cbc_ToSpan Job-LCBJSG main 16 None Internal.Cryptography.DesImplementation 4,063.5 ns 6.45 ns 5.72 ns 1.00 0.1221 - - 264 B
Encrypt_Cbc_ToSpan Job-SPRJJB branch 16 None Internal.Cryptography.RC2Implementation 1,825.4 ns 3.37 ns 2.98 ns 0.94 0.0877 - - 184 B
Encrypt_Cbc_ToSpan Job-LCBJSG main 16 None Internal.Cryptography.RC2Implementation 1,932.8 ns 2.85 ns 2.67 ns 1.00 0.1297 - - 272 B
Decrypt_Cbc_ToSpan Job-SPRJJB branch 16 None Internal.Cryptography.RC2Implementation 1,724.6 ns 3.16 ns 2.64 ns 0.94 0.0877 - - 184 B
Decrypt_Cbc_ToSpan Job-LCBJSG main 16 None Internal.Cryptography.RC2Implementation 1,833.5 ns 1.80 ns 1.59 ns 1.00 0.1335 - - 280 B
Encrypt_Cbc_ToSpan Job-SPRJJB branch 16 None Internal.Cryptography.TripleDesImplementation 10,919.6 ns 76.68 ns 71.73 ns 1.01 0.0763 - - 168 B
Encrypt_Cbc_ToSpan Job-LCBJSG main 16 None Internal.Cryptography.TripleDesImplementation 10,771.8 ns 18.05 ns 16.00 ns 1.00 0.1221 - - 256 B
Decrypt_Cbc_ToSpan Job-SPRJJB branch 16 None Internal.Cryptography.TripleDesImplementation 10,756.1 ns 31.83 ns 29.77 ns 0.97 0.0763 - - 168 B
Decrypt_Cbc_ToSpan Job-LCBJSG main 16 None Internal.Cryptography.TripleDesImplementation 11,048.4 ns 37.20 ns 31.06 ns 1.00 0.1221 - - 264 B
Encrypt_Cbc_ToSpan Job-SPRJJB branch 16 PKCS7 Internal.Cryptography.AesImplementation 579.8 ns 1.33 ns 1.24 ns 0.87 0.0610 - - 128 B
Encrypt_Cbc_ToSpan Job-LCBJSG main 16 PKCS7 Internal.Cryptography.AesImplementation 666.2 ns 1.19 ns 0.99 ns 1.00 0.1068 - - 224 B
Decrypt_Cbc_ToSpan Job-SPRJJB branch 16 PKCS7 Internal.Cryptography.AesImplementation 626.5 ns 4.94 ns 4.62 ns 0.87 0.0610 - - 128 B
Decrypt_Cbc_ToSpan Job-LCBJSG main 16 PKCS7 Internal.Cryptography.AesImplementation 717.5 ns 2.98 ns 2.64 ns 1.00 0.1106 - - 232 B
Encrypt_Cbc_ToSpan Job-SPRJJB branch 16 PKCS7 Internal.Cryptography.DesImplementation 3,819.3 ns 4.47 ns 3.96 ns 0.94 0.0763 - - 168 B
Encrypt_Cbc_ToSpan Job-LCBJSG main 16 PKCS7 Internal.Cryptography.DesImplementation 4,053.4 ns 4.84 ns 4.04 ns 1.00 0.1221 - - 256 B
Decrypt_Cbc_ToSpan Job-SPRJJB branch 16 PKCS7 Internal.Cryptography.DesImplementation 4,117.0 ns 4.56 ns 4.04 ns 0.98 0.0763 - - 168 B
Decrypt_Cbc_ToSpan Job-LCBJSG main 16 PKCS7 Internal.Cryptography.DesImplementation 4,219.6 ns 10.33 ns 8.63 ns 1.00 0.1221 - - 264 B
Encrypt_Cbc_ToSpan Job-SPRJJB branch 16 PKCS7 Internal.Cryptography.RC2Implementation 1,962.6 ns 5.17 ns 4.84 ns 0.95 0.0877 - - 184 B
Encrypt_Cbc_ToSpan Job-LCBJSG main 16 PKCS7 Internal.Cryptography.RC2Implementation 2,073.3 ns 6.05 ns 5.36 ns 1.00 0.1297 - - 272 B
Decrypt_Cbc_ToSpan Job-SPRJJB branch 16 PKCS7 Internal.Cryptography.RC2Implementation 1,868.5 ns 1.05 ns 0.93 ns 0.95 0.0877 - - 184 B
Decrypt_Cbc_ToSpan Job-LCBJSG main 16 PKCS7 Internal.Cryptography.RC2Implementation 1,959.2 ns 3.74 ns 3.31 ns 1.00 0.1335 - - 280 B
Encrypt_Cbc_ToSpan Job-SPRJJB branch 16 PKCS7 Internal.Cryptography.TripleDesImplementation 11,011.9 ns 15.59 ns 13.82 ns 0.99 0.0763 - - 168 B
Encrypt_Cbc_ToSpan Job-LCBJSG main 16 PKCS7 Internal.Cryptography.TripleDesImplementation 11,111.5 ns 9.77 ns 7.63 ns 1.00 0.1221 - - 256 B
Decrypt_Cbc_ToSpan Job-SPRJJB branch 16 PKCS7 Internal.Cryptography.TripleDesImplementation 10,933.5 ns 15.30 ns 14.31 ns 0.99 0.0763 - - 168 B
Decrypt_Cbc_ToSpan Job-LCBJSG main 16 PKCS7 Internal.Cryptography.TripleDesImplementation 11,010.9 ns 19.28 ns 17.10 ns 1.00 0.1221 - - 264 B

CFB

Method Job Toolchain DataSize FeebackSize Mode Algorithm Mean Error StdDev Ratio Gen 0 Gen 1 Gen 2 Allocated
Encrypt_Cfb_ToSpan Job-SPRJJB branch 16 8 None Internal.Cryptography.AesImplementation 700.2 ns 2.13 ns 1.99 ns 0.68 0.0610 - - 128 B
Encrypt_Cfb_ToSpan Job-LCBJSG main 16 8 None Internal.Cryptography.AesImplementation 1,026.9 ns 7.10 ns 6.64 ns 1.00 0.1221 - - 256 B
Decrypt_Cfb_ToSpan Job-SPRJJB branch 16 8 None Internal.Cryptography.AesImplementation 667.4 ns 6.13 ns 5.74 ns 0.67 0.0610 - - 128 B
Decrypt_Cfb_ToSpan Job-LCBJSG main 16 8 None Internal.Cryptography.AesImplementation 990.1 ns 7.68 ns 7.19 ns 1.00 0.1259 - - 264 B
Encrypt_Cfb_ToSpan Job-SPRJJB branch 16 8 None Internal.Cryptography.DesImplementation 3,740.5 ns 5.54 ns 5.18 ns 0.67 0.0801 - - 168 B
Encrypt_Cfb_ToSpan Job-LCBJSG main 16 8 None Internal.Cryptography.DesImplementation 5,578.8 ns 11.14 ns 10.42 ns 1.00 0.1373 - - 288 B
Decrypt_Cfb_ToSpan Job-SPRJJB branch 16 8 None Internal.Cryptography.DesImplementation 3,638.7 ns 3.00 ns 2.81 ns 0.65 0.0801 - - 168 B
Decrypt_Cfb_ToSpan Job-LCBJSG main 16 8 None Internal.Cryptography.DesImplementation 5,564.1 ns 6.48 ns 5.41 ns 1.00 0.1373 - - 296 B
Encrypt_Cfb_ToSpan Job-SPRJJB branch 16 8 None Internal.Cryptography.TripleDesImplementation 9,559.0 ns 13.73 ns 12.84 ns 0.65 0.0763 - - 168 B
Encrypt_Cfb_ToSpan Job-LCBJSG main 16 8 None Internal.Cryptography.TripleDesImplementation 14,785.0 ns 19.50 ns 18.24 ns 1.00 0.1373 - - 288 B
Decrypt_Cfb_ToSpan Job-SPRJJB branch 16 8 None Internal.Cryptography.TripleDesImplementation 9,459.0 ns 31.59 ns 28.00 ns 0.64 0.0763 - - 168 B
Decrypt_Cfb_ToSpan Job-LCBJSG main 16 8 None Internal.Cryptography.TripleDesImplementation 14,800.5 ns 27.65 ns 24.51 ns 1.00 0.1373 - - 296 B
Encrypt_Cfb_ToSpan Job-SPRJJB branch 16 8 PKCS7 Internal.Cryptography.AesImplementation 722.5 ns 4.40 ns 4.11 ns 0.68 0.0610 - - 128 B
Encrypt_Cfb_ToSpan Job-LCBJSG main 16 8 PKCS7 Internal.Cryptography.AesImplementation 1,068.5 ns 3.72 ns 3.48 ns 1.00 0.1221 - - 256 B
Decrypt_Cfb_ToSpan Job-SPRJJB branch 16 8 PKCS7 Internal.Cryptography.AesImplementation 679.4 ns 2.07 ns 1.84 ns 0.67 0.0610 - - 128 B
Decrypt_Cfb_ToSpan Job-LCBJSG main 16 8 PKCS7 Internal.Cryptography.AesImplementation 1,017.5 ns 6.10 ns 5.71 ns 1.00 0.1259 - - 264 B
Encrypt_Cfb_ToSpan Job-SPRJJB branch 16 8 PKCS7 Internal.Cryptography.DesImplementation 3,786.3 ns 2.91 ns 2.43 ns 0.65 0.0801 - - 168 B
Encrypt_Cfb_ToSpan Job-LCBJSG main 16 8 PKCS7 Internal.Cryptography.DesImplementation 5,789.9 ns 2.58 ns 2.02 ns 1.00 0.1373 - - 288 B
Decrypt_Cfb_ToSpan Job-SPRJJB branch 16 8 PKCS7 Internal.Cryptography.DesImplementation 3,765.6 ns 4.90 ns 4.58 ns 0.66 0.0801 - - 168 B
Decrypt_Cfb_ToSpan Job-LCBJSG main 16 8 PKCS7 Internal.Cryptography.DesImplementation 5,699.2 ns 6.43 ns 5.70 ns 1.00 0.1373 - - 296 B
Encrypt_Cfb_ToSpan Job-SPRJJB branch 16 8 PKCS7 Internal.Cryptography.TripleDesImplementation 9,685.0 ns 11.34 ns 10.61 ns 0.64 0.0763 - - 168 B
Encrypt_Cfb_ToSpan Job-LCBJSG main 16 8 PKCS7 Internal.Cryptography.TripleDesImplementation 15,248.0 ns 21.36 ns 19.98 ns 1.00 0.1373 - - 288 B
Decrypt_Cfb_ToSpan Job-SPRJJB branch 16 8 PKCS7 Internal.Cryptography.TripleDesImplementation 9,631.0 ns 17.41 ns 16.28 ns 0.64 0.0763 - - 168 B
Decrypt_Cfb_ToSpan Job-LCBJSG main 16 8 PKCS7 Internal.Cryptography.TripleDesImplementation 15,103.2 ns 35.81 ns 31.75 ns 1.00 0.1373 - - 296 B

ECB

Method Job Toolchain DataSize Mode Algorithm Mean Error StdDev Ratio Gen 0 Gen 1 Gen 2 Allocated
Encrypt_Ecb_ToSpan Job-SPRJJB branch 16 None Internal.Cryptography.AesImplementation 556.3 ns 3.20 ns 2.84 ns 0.91 0.0610 - - 128 B
Encrypt_Ecb_ToSpan Job-LCBJSG main 16 None Internal.Cryptography.AesImplementation 612.9 ns 4.45 ns 4.17 ns 1.00 0.0877 - - 184 B
DecryptEcb_ToSpan Job-SPRJJB branch 16 None Internal.Cryptography.AesImplementation 547.7 ns 3.33 ns 3.12 ns 0.91 0.0610 - - 128 B
DecryptEcb_ToSpan Job-LCBJSG main 16 None Internal.Cryptography.AesImplementation 601.8 ns 2.57 ns 2.27 ns 1.00 0.0916 - - 192 B
Encrypt_Ecb_ToSpan Job-SPRJJB branch 16 None Internal.Cryptography.DesImplementation 3,909.5 ns 3.71 ns 3.47 ns 0.98 0.0763 - - 168 B
Encrypt_Ecb_ToSpan Job-LCBJSG main 16 None Internal.Cryptography.DesImplementation 3,988.5 ns 5.14 ns 4.81 ns 1.00 0.1068 - - 224 B
DecryptEcb_ToSpan Job-SPRJJB branch 16 None Internal.Cryptography.DesImplementation 3,892.1 ns 7.83 ns 6.54 ns 0.97 0.0763 - - 168 B
DecryptEcb_ToSpan Job-LCBJSG main 16 None Internal.Cryptography.DesImplementation 4,023.6 ns 7.93 ns 7.42 ns 1.00 0.1068 - - 232 B
Encrypt_Ecb_ToSpan Job-SPRJJB branch 16 None Internal.Cryptography.RC2Implementation 1,789.2 ns 3.29 ns 3.08 ns 0.97 0.0877 - - 184 B
Encrypt_Ecb_ToSpan Job-LCBJSG main 16 None Internal.Cryptography.RC2Implementation 1,853.1 ns 2.17 ns 2.03 ns 1.00 0.1144 - - 240 B
DecryptEcb_ToSpan Job-SPRJJB branch 16 None Internal.Cryptography.RC2Implementation 1,715.4 ns 2.65 ns 2.48 ns 0.96 0.0877 - - 184 B
DecryptEcb_ToSpan Job-LCBJSG main 16 None Internal.Cryptography.RC2Implementation 1,779.2 ns 3.54 ns 3.31 ns 1.00 0.1183 - - 248 B
Encrypt_Ecb_ToSpan Job-SPRJJB branch 16 None Internal.Cryptography.TripleDesImplementation 10,705.0 ns 19.60 ns 17.38 ns 1.00 0.0763 - - 168 B
Encrypt_Ecb_ToSpan Job-LCBJSG main 16 None Internal.Cryptography.TripleDesImplementation 10,737.2 ns 26.27 ns 24.57 ns 1.00 0.1068 - - 224 B
DecryptEcb_ToSpan Job-SPRJJB branch 16 None Internal.Cryptography.TripleDesImplementation 10,779.4 ns 12.80 ns 11.35 ns 0.98 0.0763 - - 168 B
DecryptEcb_ToSpan Job-LCBJSG main 16 None Internal.Cryptography.TripleDesImplementation 11,012.6 ns 19.02 ns 17.79 ns 1.00 0.1068 - - 232 B
Encrypt_Ecb_ToSpan Job-SPRJJB branch 16 PKCS7 Internal.Cryptography.AesImplementation 555.3 ns 4.03 ns 3.77 ns 0.89 0.0610 - - 128 B
Encrypt_Ecb_ToSpan Job-LCBJSG main 16 PKCS7 Internal.Cryptography.AesImplementation 620.7 ns 0.85 ns 0.75 ns 1.00 0.0877 - - 184 B
DecryptEcb_ToSpan Job-SPRJJB branch 16 PKCS7 Internal.Cryptography.AesImplementation 607.1 ns 3.18 ns 2.98 ns 0.91 0.0610 - - 128 B
DecryptEcb_ToSpan Job-LCBJSG main 16 PKCS7 Internal.Cryptography.AesImplementation 664.2 ns 7.82 ns 7.32 ns 1.00 0.0916 - - 192 B
Encrypt_Ecb_ToSpan Job-SPRJJB branch 16 PKCS7 Internal.Cryptography.DesImplementation 3,922.0 ns 9.55 ns 7.97 ns 0.97 0.0763 - - 168 B
Encrypt_Ecb_ToSpan Job-LCBJSG main 16 PKCS7 Internal.Cryptography.DesImplementation 4,047.2 ns 10.18 ns 8.50 ns 1.00 0.1068 - - 224 B
DecryptEcb_ToSpan Job-SPRJJB branch 16 PKCS7 Internal.Cryptography.DesImplementation 3,986.7 ns 2.99 ns 2.65 ns 1.00 0.0763 - - 168 B
DecryptEcb_ToSpan Job-LCBJSG main 16 PKCS7 Internal.Cryptography.DesImplementation 3,985.0 ns 10.94 ns 10.24 ns 1.00 0.1068 - - 232 B
Encrypt_Ecb_ToSpan Job-SPRJJB branch 16 PKCS7 Internal.Cryptography.RC2Implementation 1,907.3 ns 3.47 ns 2.90 ns 0.96 0.0877 - - 184 B
Encrypt_Ecb_ToSpan Job-LCBJSG main 16 PKCS7 Internal.Cryptography.RC2Implementation 1,984.0 ns 2.22 ns 2.08 ns 1.00 0.1144 - - 240 B
DecryptEcb_ToSpan Job-SPRJJB branch 16 PKCS7 Internal.Cryptography.RC2Implementation 1,837.6 ns 3.17 ns 2.96 ns 0.96 0.0877 - - 184 B
DecryptEcb_ToSpan Job-LCBJSG main 16 PKCS7 Internal.Cryptography.RC2Implementation 1,905.8 ns 2.76 ns 2.45 ns 1.00 0.1183 - - 248 B
Encrypt_Ecb_ToSpan Job-SPRJJB branch 16 PKCS7 Internal.Cryptography.TripleDesImplementation 10,960.8 ns 8.04 ns 7.52 ns 1.01 0.0763 - - 168 B
Encrypt_Ecb_ToSpan Job-LCBJSG main 16 PKCS7 Internal.Cryptography.TripleDesImplementation 10,812.9 ns 22.44 ns 20.99 ns 1.00 0.1068 - - 224 B
DecryptEcb_ToSpan Job-SPRJJB branch 16 PKCS7 Internal.Cryptography.TripleDesImplementation 11,254.4 ns 15.72 ns 14.70 ns 1.00 0.0763 - - 168 B
DecryptEcb_ToSpan Job-LCBJSG main 16 PKCS7 Internal.Cryptography.TripleDesImplementation 11,291.4 ns 19.30 ns 16.12 ns 1.00 0.1068 - - 232 B
Benchmarks on Windows 10

CBC

Method Job Toolchain DataSize Mode Algorithm Mean Error StdDev Ratio RatioSD Gen 0 Gen 1 Gen 2 Allocated
Encrypt_Cbc_ToSpan Job-BAFYQM branch 16 None Internal.Cryptography.AesImplementation 699.1 ns 5.89 ns 5.51 ns 0.94 0.01 0.0610 - - 256 B
Encrypt_Cbc_ToSpan Job-IBXDLM main 16 None Internal.Cryptography.AesImplementation 739.9 ns 4.76 ns 4.22 ns 1.00 0.00 0.0801 - - 336 B
Decrypt_Cbc_ToSpan Job-BAFYQM branch 16 None Internal.Cryptography.AesImplementation 692.9 ns 8.56 ns 8.01 ns 0.97 0.01 0.0610 - - 256 B
Decrypt_Cbc_ToSpan Job-IBXDLM main 16 None Internal.Cryptography.AesImplementation 717.5 ns 5.23 ns 4.63 ns 1.00 0.00 0.0820 - - 344 B
Encrypt_Cbc_ToSpan Job-BAFYQM branch 16 None Internal.Cryptography.DesImplementation 1,371.2 ns 11.78 ns 10.45 ns 0.97 0.01 0.0629 - - 264 B
Encrypt_Cbc_ToSpan Job-IBXDLM main 16 None Internal.Cryptography.DesImplementation 1,420.2 ns 5.63 ns 5.27 ns 1.00 0.00 0.0801 - - 336 B
Decrypt_Cbc_ToSpan Job-BAFYQM branch 16 None Internal.Cryptography.DesImplementation 1,381.9 ns 7.13 ns 6.32 ns 0.98 0.00 0.0629 - - 264 B
Decrypt_Cbc_ToSpan Job-IBXDLM main 16 None Internal.Cryptography.DesImplementation 1,410.9 ns 3.92 ns 3.28 ns 1.00 0.00 0.0820 - - 344 B
Encrypt_Cbc_ToSpan Job-BAFYQM branch 16 None Internal.Cryptography.RC2Implementation 2,497.4 ns 12.60 ns 10.52 ns 0.97 0.01 0.0763 - - 320 B
Encrypt_Cbc_ToSpan Job-IBXDLM main 16 None Internal.Cryptography.RC2Implementation 2,582.6 ns 19.12 ns 16.95 ns 1.00 0.00 0.0916 - - 392 B
Decrypt_Cbc_ToSpan Job-BAFYQM branch 16 None Internal.Cryptography.RC2Implementation 2,399.7 ns 9.50 ns 8.88 ns 0.69 0.01 0.0763 - - 320 B
Decrypt_Cbc_ToSpan Job-IBXDLM main 16 None Internal.Cryptography.RC2Implementation 3,483.6 ns 47.72 ns 44.64 ns 1.00 0.00 0.0954 - - 400 B
Encrypt_Cbc_ToSpan Job-BAFYQM branch 16 None Internal.Cryptography.TripleDesImplementation 1,428.8 ns 20.30 ns 18.00 ns 0.95 0.02 0.0668 - - 280 B
Encrypt_Cbc_ToSpan Job-IBXDLM main 16 None Internal.Cryptography.TripleDesImplementation 1,504.7 ns 19.35 ns 15.10 ns 1.00 0.00 0.0839 - - 352 B
Decrypt_Cbc_ToSpan Job-BAFYQM branch 16 None Internal.Cryptography.TripleDesImplementation 1,425.4 ns 13.58 ns 12.04 ns 0.97 0.01 0.0668 - - 280 B
Decrypt_Cbc_ToSpan Job-IBXDLM main 16 None Internal.Cryptography.TripleDesImplementation 1,468.5 ns 15.49 ns 14.49 ns 1.00 0.00 0.0858 - - 360 B
Encrypt_Cbc_ToSpan Job-BAFYQM branch 16 PKCS7 Internal.Cryptography.AesImplementation 728.8 ns 9.54 ns 8.93 ns 0.92 0.02 0.0610 - - 256 B
Encrypt_Cbc_ToSpan Job-IBXDLM main 16 PKCS7 Internal.Cryptography.AesImplementation 797.2 ns 15.68 ns 18.06 ns 1.00 0.00 0.0801 - - 336 B
Decrypt_Cbc_ToSpan Job-BAFYQM branch 16 PKCS7 Internal.Cryptography.AesImplementation 811.0 ns 13.77 ns 12.88 ns 0.95 0.02 0.0610 - - 256 B
Decrypt_Cbc_ToSpan Job-IBXDLM main 16 PKCS7 Internal.Cryptography.AesImplementation 855.2 ns 15.87 ns 14.84 ns 1.00 0.00 0.0820 - - 344 B
Encrypt_Cbc_ToSpan Job-BAFYQM branch 16 PKCS7 Internal.Cryptography.DesImplementation 1,644.7 ns 14.21 ns 13.29 ns 0.99 0.01 0.0629 - - 264 B
Encrypt_Cbc_ToSpan Job-IBXDLM main 16 PKCS7 Internal.Cryptography.DesImplementation 1,659.2 ns 7.35 ns 5.74 ns 1.00 0.00 0.0801 - - 336 B
Decrypt_Cbc_ToSpan Job-BAFYQM branch 16 PKCS7 Internal.Cryptography.DesImplementation 1,697.8 ns 13.52 ns 11.29 ns 0.94 0.01 0.0629 - - 264 B
Decrypt_Cbc_ToSpan Job-IBXDLM main 16 PKCS7 Internal.Cryptography.DesImplementation 1,816.0 ns 7.31 ns 6.48 ns 1.00 0.00 0.0820 - - 344 B
Encrypt_Cbc_ToSpan Job-BAFYQM branch 16 PKCS7 Internal.Cryptography.RC2Implementation 2,847.0 ns 9.29 ns 8.69 ns 0.76 0.01 0.0763 - - 320 B
Encrypt_Cbc_ToSpan Job-IBXDLM main 16 PKCS7 Internal.Cryptography.RC2Implementation 3,747.0 ns 50.44 ns 47.18 ns 1.00 0.00 0.0916 - - 392 B
Decrypt_Cbc_ToSpan Job-BAFYQM branch 16 PKCS7 Internal.Cryptography.RC2Implementation 2,602.8 ns 19.01 ns 17.78 ns 0.72 0.01 0.0763 - - 320 B
Decrypt_Cbc_ToSpan Job-IBXDLM main 16 PKCS7 Internal.Cryptography.RC2Implementation 3,596.1 ns 21.01 ns 19.65 ns 1.00 0.00 0.0954 - - 400 B
Encrypt_Cbc_ToSpan Job-BAFYQM branch 16 PKCS7 Internal.Cryptography.TripleDesImplementation 1,650.0 ns 20.38 ns 19.06 ns 0.97 0.01 0.0668 - - 280 B
Encrypt_Cbc_ToSpan Job-IBXDLM main 16 PKCS7 Internal.Cryptography.TripleDesImplementation 1,692.9 ns 12.35 ns 10.31 ns 1.00 0.00 0.0839 - - 352 B
Decrypt_Cbc_ToSpan Job-BAFYQM branch 16 PKCS7 Internal.Cryptography.TripleDesImplementation 1,725.6 ns 33.48 ns 35.82 ns 0.98 0.02 0.0668 - - 280 B
Decrypt_Cbc_ToSpan Job-IBXDLM main 16 PKCS7 Internal.Cryptography.TripleDesImplementation 1,770.3 ns 18.15 ns 16.98 ns 1.00 0.00 0.0858 - - 360 B

CFB

Method Job Toolchain DataSize FeebackSize Mode Algorithm Mean Error StdDev Ratio RatioSD Gen 0 Gen 1 Gen 2 Allocated
Encrypt_Cfb_ToSpan Job-BAFYQM branch 16 8 None Internal.Cryptography.AesImplementation 1.084 μs 0.0043 μs 0.0033 μs 0.93 0.01 0.0610 - - 256 B
Encrypt_Cfb_ToSpan Job-IBXDLM main 16 8 None Internal.Cryptography.AesImplementation 1.169 μs 0.0134 μs 0.0118 μs 1.00 0.00 0.0801 - - 336 B
Decrypt_Cfb_ToSpan Job-BAFYQM branch 16 8 None Internal.Cryptography.AesImplementation 1.022 μs 0.0044 μs 0.0037 μs 0.94 0.01 0.0610 - - 256 B
Decrypt_Cfb_ToSpan Job-IBXDLM main 16 8 None Internal.Cryptography.AesImplementation 1.095 μs 0.0145 μs 0.0136 μs 1.00 0.00 0.0820 - - 344 B
Encrypt_Cfb_ToSpan Job-BAFYQM branch 16 8 None Internal.Cryptography.DesImplementation 4.495 μs 0.0373 μs 0.0349 μs 0.98 0.01 0.0610 - - 264 B
Encrypt_Cfb_ToSpan Job-IBXDLM main 16 8 None Internal.Cryptography.DesImplementation 4.570 μs 0.0317 μs 0.0281 μs 1.00 0.00 0.0763 - - 336 B
Decrypt_Cfb_ToSpan Job-BAFYQM branch 16 8 None Internal.Cryptography.DesImplementation 4.457 μs 0.0370 μs 0.0346 μs 0.99 0.01 0.0610 - - 264 B
Decrypt_Cfb_ToSpan Job-IBXDLM main 16 8 None Internal.Cryptography.DesImplementation 4.495 μs 0.0288 μs 0.0270 μs 1.00 0.00 0.0763 - - 344 B
Encrypt_Cfb_ToSpan Job-BAFYQM branch 16 8 None Internal.Cryptography.TripleDesImplementation 4.543 μs 0.0250 μs 0.0234 μs 0.99 0.01 0.0610 - - 280 B
Encrypt_Cfb_ToSpan Job-IBXDLM main 16 8 None Internal.Cryptography.TripleDesImplementation 4.603 μs 0.0335 μs 0.0313 μs 1.00 0.00 0.0839 - - 352 B
Decrypt_Cfb_ToSpan Job-BAFYQM branch 16 8 None Internal.Cryptography.TripleDesImplementation 4.502 μs 0.0368 μs 0.0326 μs 1.00 0.01 0.0610 - - 280 B
Decrypt_Cfb_ToSpan Job-IBXDLM main 16 8 None Internal.Cryptography.TripleDesImplementation 4.486 μs 0.0484 μs 0.0452 μs 1.00 0.00 0.0839 - - 360 B
Encrypt_Cfb_ToSpan Job-BAFYQM branch 16 8 PKCS7 Internal.Cryptography.AesImplementation 1.148 μs 0.0170 μs 0.0159 μs 0.95 0.02 0.0610 - - 256 B
Encrypt_Cfb_ToSpan Job-IBXDLM main 16 8 PKCS7 Internal.Cryptography.AesImplementation 1.210 μs 0.0170 μs 0.0159 μs 1.00 0.00 0.0801 - - 336 B
Decrypt_Cfb_ToSpan Job-BAFYQM branch 16 8 PKCS7 Internal.Cryptography.AesImplementation 1.136 μs 0.0089 μs 0.0074 μs 0.95 0.01 0.0610 - - 256 B
Decrypt_Cfb_ToSpan Job-IBXDLM main 16 8 PKCS7 Internal.Cryptography.AesImplementation 1.190 μs 0.0127 μs 0.0119 μs 1.00 0.00 0.0820 - - 344 B
Encrypt_Cfb_ToSpan Job-BAFYQM branch 16 8 PKCS7 Internal.Cryptography.DesImplementation 4.731 μs 0.0329 μs 0.0308 μs 0.99 0.01 0.0610 - - 264 B
Encrypt_Cfb_ToSpan Job-IBXDLM main 16 8 PKCS7 Internal.Cryptography.DesImplementation 4.797 μs 0.0256 μs 0.0227 μs 1.00 0.00 0.0763 - - 336 B
Decrypt_Cfb_ToSpan Job-BAFYQM branch 16 8 PKCS7 Internal.Cryptography.DesImplementation 4.739 μs 0.0323 μs 0.0270 μs 0.99 0.01 0.0610 - - 264 B
Decrypt_Cfb_ToSpan Job-IBXDLM main 16 8 PKCS7 Internal.Cryptography.DesImplementation 4.788 μs 0.0231 μs 0.0216 μs 1.00 0.00 0.0763 - - 344 B
Encrypt_Cfb_ToSpan Job-BAFYQM branch 16 8 PKCS7 Internal.Cryptography.TripleDesImplementation 4.764 μs 0.0264 μs 0.0234 μs 0.99 0.01 0.0610 - - 280 B
Encrypt_Cfb_ToSpan Job-IBXDLM main 16 8 PKCS7 Internal.Cryptography.TripleDesImplementation 4.813 μs 0.0616 μs 0.0577 μs 1.00 0.00 0.0839 - - 352 B
Decrypt_Cfb_ToSpan Job-BAFYQM branch 16 8 PKCS7 Internal.Cryptography.TripleDesImplementation 4.803 μs 0.0598 μs 0.0559 μs 0.99 0.02 0.0610 - - 280 B
Decrypt_Cfb_ToSpan Job-IBXDLM main 16 8 PKCS7 Internal.Cryptography.TripleDesImplementation 4.839 μs 0.0757 μs 0.0708 μs 1.00 0.00 0.0839 - - 360 B

ECB

Method Job Toolchain DataSize Mode Algorithm Mean Error StdDev Ratio RatioSD Gen 0 Gen 1 Gen 2 Allocated
Encrypt_Ecb_ToSpan Job-BAFYQM branch 16 None Internal.Cryptography.AesImplementation 681.2 ns 6.98 ns 6.19 ns 0.95 0.01 0.0515 - - 216 B
Encrypt_Ecb_ToSpan Job-IBXDLM main 16 None Internal.Cryptography.AesImplementation 716.7 ns 9.85 ns 9.21 ns 1.00 0.00 0.0610 - - 256 B
DecryptEcb_ToSpan Job-BAFYQM branch 16 None Internal.Cryptography.AesImplementation 656.3 ns 9.33 ns 8.27 ns 0.93 0.02 0.0515 - - 216 B
DecryptEcb_ToSpan Job-IBXDLM main 16 None Internal.Cryptography.AesImplementation 702.6 ns 11.26 ns 10.53 ns 1.00 0.00 0.0629 - - 264 B
Encrypt_Ecb_ToSpan Job-BAFYQM branch 16 None Internal.Cryptography.DesImplementation 1,356.4 ns 8.05 ns 7.13 ns 0.98 0.01 0.0553 - - 232 B
Encrypt_Ecb_ToSpan Job-IBXDLM main 16 None Internal.Cryptography.DesImplementation 1,380.4 ns 16.62 ns 15.55 ns 1.00 0.00 0.0648 - - 272 B
DecryptEcb_ToSpan Job-BAFYQM branch 16 None Internal.Cryptography.DesImplementation 1,332.6 ns 17.07 ns 15.97 ns 0.98 0.02 0.0553 - - 232 B
DecryptEcb_ToSpan Job-IBXDLM main 16 None Internal.Cryptography.DesImplementation 1,365.3 ns 18.49 ns 17.29 ns 1.00 0.00 0.0668 - - 280 B
Encrypt_Ecb_ToSpan Job-BAFYQM branch 16 None Internal.Cryptography.RC2Implementation 2,541.3 ns 23.39 ns 21.88 ns 0.72 0.01 0.0687 - - 288 B
Encrypt_Ecb_ToSpan Job-IBXDLM main 16 None Internal.Cryptography.RC2Implementation 3,528.6 ns 55.38 ns 51.80 ns 1.00 0.00 0.0763 - - 328 B
DecryptEcb_ToSpan Job-BAFYQM branch 16 None Internal.Cryptography.RC2Implementation 2,428.8 ns 15.21 ns 12.70 ns 0.73 0.01 0.0687 - - 288 B
DecryptEcb_ToSpan Job-IBXDLM main 16 None Internal.Cryptography.RC2Implementation 3,328.8 ns 32.68 ns 30.57 ns 1.00 0.00 0.0801 - - 336 B
Encrypt_Ecb_ToSpan Job-BAFYQM branch 16 None Internal.Cryptography.TripleDesImplementation 1,337.4 ns 14.44 ns 13.50 ns 0.97 0.01 0.0591 - - 248 B
Encrypt_Ecb_ToSpan Job-IBXDLM main 16 None Internal.Cryptography.TripleDesImplementation 1,374.2 ns 11.52 ns 10.77 ns 1.00 0.00 0.0687 - - 288 B
DecryptEcb_ToSpan Job-BAFYQM branch 16 None Internal.Cryptography.TripleDesImplementation 1,323.5 ns 16.94 ns 15.84 ns 0.98 0.01 0.0591 - - 248 B
DecryptEcb_ToSpan Job-IBXDLM main 16 None Internal.Cryptography.TripleDesImplementation 1,354.1 ns 11.26 ns 9.98 ns 1.00 0.00 0.0706 - - 296 B
Encrypt_Ecb_ToSpan Job-BAFYQM branch 16 PKCS7 Internal.Cryptography.AesImplementation 693.4 ns 12.94 ns 12.10 ns 0.94 0.03 0.0515 - - 216 B
Encrypt_Ecb_ToSpan Job-IBXDLM main 16 PKCS7 Internal.Cryptography.AesImplementation 741.7 ns 14.88 ns 13.92 ns 1.00 0.00 0.0610 - - 256 B
DecryptEcb_ToSpan Job-BAFYQM branch 16 PKCS7 Internal.Cryptography.AesImplementation 755.7 ns 11.47 ns 10.73 ns 0.94 0.03 0.0515 - - 216 B
DecryptEcb_ToSpan Job-IBXDLM main 16 PKCS7 Internal.Cryptography.AesImplementation 806.4 ns 15.99 ns 20.79 ns 1.00 0.00 0.0629 - - 264 B
Encrypt_Ecb_ToSpan Job-BAFYQM branch 16 PKCS7 Internal.Cryptography.DesImplementation 1,547.3 ns 20.50 ns 19.17 ns 0.99 0.01 0.0553 - - 232 B
Encrypt_Ecb_ToSpan Job-IBXDLM main 16 PKCS7 Internal.Cryptography.DesImplementation 1,561.5 ns 6.28 ns 5.87 ns 1.00 0.00 0.0648 - - 272 B
DecryptEcb_ToSpan Job-BAFYQM branch 16 PKCS7 Internal.Cryptography.DesImplementation 1,621.8 ns 25.89 ns 24.22 ns 1.00 0.01 0.0553 - - 232 B
DecryptEcb_ToSpan Job-IBXDLM main 16 PKCS7 Internal.Cryptography.DesImplementation 1,617.3 ns 4.95 ns 4.39 ns 1.00 0.00 0.0668 - - 280 B
Encrypt_Ecb_ToSpan Job-BAFYQM branch 16 PKCS7 Internal.Cryptography.RC2Implementation 2,604.4 ns 17.55 ns 15.56 ns 0.74 0.01 0.0687 - - 288 B
Encrypt_Ecb_ToSpan Job-IBXDLM main 16 PKCS7 Internal.Cryptography.RC2Implementation 3,522.1 ns 13.22 ns 11.04 ns 1.00 0.00 0.0763 - - 328 B
DecryptEcb_ToSpan Job-BAFYQM branch 16 PKCS7 Internal.Cryptography.RC2Implementation 2,487.5 ns 6.77 ns 6.00 ns 0.98 0.01 0.0687 - - 288 B
DecryptEcb_ToSpan Job-IBXDLM main 16 PKCS7 Internal.Cryptography.RC2Implementation 2,534.3 ns 16.95 ns 15.85 ns 1.00 0.00 0.0801 - - 336 B
Encrypt_Ecb_ToSpan Job-BAFYQM branch 16 PKCS7 Internal.Cryptography.TripleDesImplementation 1,535.3 ns 5.91 ns 5.53 ns 0.96 0.01 0.0591 - - 248 B
Encrypt_Ecb_ToSpan Job-IBXDLM main 16 PKCS7 Internal.Cryptography.TripleDesImplementation 1,602.1 ns 20.70 ns 19.36 ns 1.00 0.00 0.0687 - - 288 B
DecryptEcb_ToSpan Job-BAFYQM branch 16 PKCS7 Internal.Cryptography.TripleDesImplementation 1,590.7 ns 7.32 ns 6.48 ns 0.98 0.01 0.0591 - - 248 B
DecryptEcb_ToSpan Job-IBXDLM main 16 PKCS7 Internal.Cryptography.TripleDesImplementation 1,624.4 ns 6.20 ns 5.80 ns 1.00 0.00 0.0706 - - 296 B
Benchmarks on Linux

CBC

Method Job Toolchain DataSize Mode Algorithm Mean Error StdDev Median Ratio RatioSD Gen 0 Gen 1 Gen 2 Allocated
Encrypt_Cbc_ToSpan Job-XPHHLI branch 16 None Internal.Cryptography.AesImplementation 609.7 ns 5.81 ns 4.85 ns 609.9 ns 0.83 0.01 0.0010 - - 120 B
Encrypt_Cbc_ToSpan Job-LZVMLS main 16 None Internal.Cryptography.AesImplementation 735.0 ns 7.13 ns 5.95 ns 736.4 ns 1.00 0.00 0.0019 - - 208 B
Decrypt_Cbc_ToSpan Job-XPHHLI branch 16 None Internal.Cryptography.AesImplementation 628.7 ns 6.40 ns 5.98 ns 627.8 ns 0.86 0.01 0.0010 - - 120 B
Decrypt_Cbc_ToSpan Job-LZVMLS main 16 None Internal.Cryptography.AesImplementation 734.4 ns 4.17 ns 3.49 ns 734.8 ns 1.00 0.00 0.0019 - - 216 B
Encrypt_Cbc_ToSpan Job-XPHHLI branch 16 None Internal.Cryptography.DesImplementation 867.8 ns 5.23 ns 4.37 ns 865.7 ns 0.84 0.01 0.0019 - - 160 B
Encrypt_Cbc_ToSpan Job-LZVMLS main 16 None Internal.Cryptography.DesImplementation 1,028.4 ns 15.02 ns 13.31 ns 1,031.8 ns 1.00 0.00 0.0019 - - 240 B
Decrypt_Cbc_ToSpan Job-XPHHLI branch 16 None Internal.Cryptography.DesImplementation 863.8 ns 6.22 ns 5.20 ns 862.3 ns 0.88 0.01 0.0019 - - 160 B
Decrypt_Cbc_ToSpan Job-LZVMLS main 16 None Internal.Cryptography.DesImplementation 981.2 ns 5.09 ns 4.76 ns 980.2 ns 1.00 0.00 0.0019 - - 248 B
Encrypt_Cbc_ToSpan Job-XPHHLI branch 16 None Internal.Cryptography.RC2Implementation 1,390.5 ns 14.24 ns 11.11 ns 1,393.3 ns 0.92 0.01 0.0019 - - 176 B
Encrypt_Cbc_ToSpan Job-LZVMLS main 16 None Internal.Cryptography.RC2Implementation 1,516.3 ns 14.77 ns 12.34 ns 1,515.0 ns 1.00 0.00 0.0019 - - 256 B
Decrypt_Cbc_ToSpan Job-XPHHLI branch 16 None Internal.Cryptography.RC2Implementation 1,282.9 ns 6.58 ns 5.49 ns 1,283.1 ns 0.92 0.00 0.0019 - - 176 B
Decrypt_Cbc_ToSpan Job-LZVMLS main 16 None Internal.Cryptography.RC2Implementation 1,401.8 ns 3.10 ns 2.42 ns 1,402.2 ns 1.00 0.00 0.0019 - - 264 B
Encrypt_Cbc_ToSpan Job-XPHHLI branch 16 None Internal.Cryptography.TripleDesImplementation 1,315.9 ns 3.99 ns 3.12 ns 1,316.1 ns 0.92 0.00 0.0019 - - 160 B
Encrypt_Cbc_ToSpan Job-LZVMLS main 16 None Internal.Cryptography.TripleDesImplementation 1,432.0 ns 3.26 ns 2.72 ns 1,431.4 ns 1.00 0.00 0.0019 - - 240 B
Decrypt_Cbc_ToSpan Job-XPHHLI branch 16 None Internal.Cryptography.TripleDesImplementation 1,311.2 ns 9.81 ns 8.19 ns 1,308.1 ns 0.91 0.01 0.0019 - - 160 B
Decrypt_Cbc_ToSpan Job-LZVMLS main 16 None Internal.Cryptography.TripleDesImplementation 1,442.5 ns 2.73 ns 2.28 ns 1,441.8 ns 1.00 0.00 0.0019 - - 248 B
Encrypt_Cbc_ToSpan Job-XPHHLI branch 16 PKCS7 Internal.Cryptography.AesImplementation 598.2 ns 3.46 ns 2.70 ns 597.7 ns 0.81 0.02 0.0010 - - 120 B
Encrypt_Cbc_ToSpan Job-LZVMLS main 16 PKCS7 Internal.Cryptography.AesImplementation 747.2 ns 14.92 ns 18.32 ns 735.8 ns 1.00 0.00 0.0019 - - 208 B
Decrypt_Cbc_ToSpan Job-XPHHLI branch 16 PKCS7 Internal.Cryptography.AesImplementation 699.0 ns 8.29 ns 6.92 ns 699.9 ns 0.82 0.01 0.0010 - - 120 B
Decrypt_Cbc_ToSpan Job-LZVMLS main 16 PKCS7 Internal.Cryptography.AesImplementation 854.1 ns 10.82 ns 9.59 ns 855.5 ns 1.00 0.00 0.0019 - - 216 B
Encrypt_Cbc_ToSpan Job-XPHHLI branch 16 PKCS7 Internal.Cryptography.DesImplementation 942.3 ns 5.39 ns 4.78 ns 941.4 ns 0.87 0.01 0.0019 - - 160 B
Encrypt_Cbc_ToSpan Job-LZVMLS main 16 PKCS7 Internal.Cryptography.DesImplementation 1,083.8 ns 3.58 ns 2.99 ns 1,083.7 ns 1.00 0.00 0.0019 - - 240 B
Decrypt_Cbc_ToSpan Job-XPHHLI branch 16 PKCS7 Internal.Cryptography.DesImplementation 1,069.9 ns 11.24 ns 10.52 ns 1,072.2 ns 0.92 0.01 0.0019 - - 160 B
Decrypt_Cbc_ToSpan Job-LZVMLS main 16 PKCS7 Internal.Cryptography.DesImplementation 1,162.2 ns 9.94 ns 9.30 ns 1,157.6 ns 1.00 0.00 0.0019 - - 248 B
Encrypt_Cbc_ToSpan Job-XPHHLI branch 16 PKCS7 Internal.Cryptography.RC2Implementation 1,560.3 ns 16.61 ns 13.87 ns 1,560.9 ns 0.94 0.01 0.0019 - - 176 B
Encrypt_Cbc_ToSpan Job-LZVMLS main 16 PKCS7 Internal.Cryptography.RC2Implementation 1,653.5 ns 11.09 ns 10.37 ns 1,648.0 ns 1.00 0.00 0.0019 - - 256 B
Decrypt_Cbc_ToSpan Job-XPHHLI branch 16 PKCS7 Internal.Cryptography.RC2Implementation 1,438.2 ns 3.57 ns 3.16 ns 1,437.3 ns 0.93 0.01 0.0019 - - 176 B
Decrypt_Cbc_ToSpan Job-LZVMLS main 16 PKCS7 Internal.Cryptography.RC2Implementation 1,540.7 ns 10.87 ns 9.08 ns 1,536.1 ns 1.00 0.00 0.0019 - - 264 B
Encrypt_Cbc_ToSpan Job-XPHHLI branch 16 PKCS7 Internal.Cryptography.TripleDesImplementation 1,579.9 ns 15.73 ns 14.72 ns 1,573.5 ns 0.94 0.01 0.0019 - - 160 B
Encrypt_Cbc_ToSpan Job-LZVMLS main 16 PKCS7 Internal.Cryptography.TripleDesImplementation 1,684.7 ns 7.77 ns 7.26 ns 1,685.2 ns 1.00 0.00 0.0019 - - 240 B
Decrypt_Cbc_ToSpan Job-XPHHLI branch 16 PKCS7 Internal.Cryptography.TripleDesImplementation 1,641.3 ns 8.67 ns 8.11 ns 1,640.8 ns 0.94 0.00 0.0019 - - 160 B
Decrypt_Cbc_ToSpan Job-LZVMLS main 16 PKCS7 Internal.Cryptography.TripleDesImplementation 1,736.6 ns 3.02 ns 2.52 ns 1,736.0 ns 1.00 0.00 0.0019 - - 248 B

CFB

Method Job Toolchain DataSize FeebackSize Mode Algorithm Mean Error StdDev Ratio Gen 0 Gen 1 Gen 2 Allocated
Encrypt_Cfb_ToSpan Job-XPHHLI branch 16 8 None Internal.Cryptography.AesImplementation 925.0 ns 2.68 ns 2.38 ns 0.86 - - - 120 B
Encrypt_Cfb_ToSpan Job-LZVMLS main 16 8 None Internal.Cryptography.AesImplementation 1,069.7 ns 3.07 ns 2.56 ns 1.00 0.0019 - - 208 B
Decrypt_Cfb_ToSpan Job-XPHHLI branch 16 8 None Internal.Cryptography.AesImplementation 934.5 ns 2.27 ns 2.01 ns 0.86 0.0010 - - 120 B
Decrypt_Cfb_ToSpan Job-LZVMLS main 16 8 None Internal.Cryptography.AesImplementation 1,087.6 ns 12.12 ns 11.34 ns 1.00 0.0019 - - 216 B
Encrypt_Cfb_ToSpan Job-XPHHLI branch 16 8 None Internal.Cryptography.DesImplementation 2,096.3 ns 4.35 ns 3.85 ns 0.94 - - - 160 B
Encrypt_Cfb_ToSpan Job-LZVMLS main 16 8 None Internal.Cryptography.DesImplementation 2,235.8 ns 4.59 ns 4.07 ns 1.00 - - - 240 B
Decrypt_Cfb_ToSpan Job-XPHHLI branch 16 8 None Internal.Cryptography.DesImplementation 2,088.8 ns 5.13 ns 4.55 ns 0.94 - - - 160 B
Decrypt_Cfb_ToSpan Job-LZVMLS main 16 8 None Internal.Cryptography.DesImplementation 2,217.3 ns 2.69 ns 2.52 ns 1.00 - - - 248 B
Encrypt_Cfb_ToSpan Job-XPHHLI branch 16 8 None Internal.Cryptography.TripleDesImplementation 4,518.7 ns 10.37 ns 9.70 ns 0.97 - - - 160 B
Encrypt_Cfb_ToSpan Job-LZVMLS main 16 8 None Internal.Cryptography.TripleDesImplementation 4,648.8 ns 15.43 ns 14.43 ns 1.00 - - - 240 B
Decrypt_Cfb_ToSpan Job-XPHHLI branch 16 8 None Internal.Cryptography.TripleDesImplementation 4,517.1 ns 9.13 ns 7.62 ns 0.98 - - - 160 B
Decrypt_Cfb_ToSpan Job-LZVMLS main 16 8 None Internal.Cryptography.TripleDesImplementation 4,624.3 ns 17.82 ns 16.66 ns 1.00 - - - 248 B
Encrypt_Cfb_ToSpan Job-XPHHLI branch 16 8 PKCS7 Internal.Cryptography.AesImplementation 980.1 ns 4.84 ns 4.29 ns 0.88 - - - 120 B
Encrypt_Cfb_ToSpan Job-LZVMLS main 16 8 PKCS7 Internal.Cryptography.AesImplementation 1,111.4 ns 10.46 ns 9.79 ns 1.00 0.0019 - - 208 B
Decrypt_Cfb_ToSpan Job-XPHHLI branch 16 8 PKCS7 Internal.Cryptography.AesImplementation 1,037.5 ns 3.09 ns 2.74 ns 0.88 - - - 120 B
Decrypt_Cfb_ToSpan Job-LZVMLS main 16 8 PKCS7 Internal.Cryptography.AesImplementation 1,178.2 ns 12.65 ns 11.22 ns 1.00 0.0019 - - 216 B
Encrypt_Cfb_ToSpan Job-XPHHLI branch 16 8 PKCS7 Internal.Cryptography.DesImplementation 2,206.1 ns 7.66 ns 7.17 ns 0.94 - - - 160 B
Encrypt_Cfb_ToSpan Job-LZVMLS main 16 8 PKCS7 Internal.Cryptography.DesImplementation 2,334.9 ns 10.53 ns 9.85 ns 1.00 - - - 240 B
Decrypt_Cfb_ToSpan Job-XPHHLI branch 16 8 PKCS7 Internal.Cryptography.DesImplementation 2,256.5 ns 5.63 ns 5.27 ns 0.94 - - - 160 B
Decrypt_Cfb_ToSpan Job-LZVMLS main 16 8 PKCS7 Internal.Cryptography.DesImplementation 2,403.3 ns 3.35 ns 2.97 ns 1.00 - - - 248 B
Encrypt_Cfb_ToSpan Job-XPHHLI branch 16 8 PKCS7 Internal.Cryptography.TripleDesImplementation 4,759.7 ns 7.57 ns 6.32 ns 0.97 - - - 160 B
Encrypt_Cfb_ToSpan Job-LZVMLS main 16 8 PKCS7 Internal.Cryptography.TripleDesImplementation 4,901.1 ns 13.06 ns 12.21 ns 1.00 - - - 240 B
Decrypt_Cfb_ToSpan Job-XPHHLI branch 16 8 PKCS7 Internal.Cryptography.TripleDesImplementation 4,874.9 ns 10.95 ns 10.24 ns 0.98 - - - 160 B
Decrypt_Cfb_ToSpan Job-LZVMLS main 16 8 PKCS7 Internal.Cryptography.TripleDesImplementation 4,958.6 ns 21.79 ns 20.39 ns 1.00 - - - 248 B

ECB

Method Job Toolchain DataSize Mode Algorithm Mean Error StdDev Ratio Gen 0 Gen 1 Gen 2 Allocated
Encrypt_Ecb_ToSpan Job-XPHHLI branch 16 None Internal.Cryptography.AesImplementation 567.5 ns 4.88 ns 4.56 ns 0.86 0.0010 - - 120 B
Encrypt_Ecb_ToSpan Job-LZVMLS main 16 None Internal.Cryptography.AesImplementation 659.9 ns 1.69 ns 1.50 ns 1.00 0.0019 - - 168 B
DecryptEcb_ToSpan Job-XPHHLI branch 16 None Internal.Cryptography.AesImplementation 577.8 ns 1.81 ns 1.69 ns 0.86 0.0010 - - 120 B
DecryptEcb_ToSpan Job-LZVMLS main 16 None Internal.Cryptography.AesImplementation 675.6 ns 1.94 ns 1.82 ns 1.00 0.0019 - - 176 B
Encrypt_Ecb_ToSpan Job-XPHHLI branch 16 None Internal.Cryptography.DesImplementation 817.2 ns 5.06 ns 4.74 ns 0.91 0.0019 - - 160 B
Encrypt_Ecb_ToSpan Job-LZVMLS main 16 None Internal.Cryptography.DesImplementation 902.1 ns 1.83 ns 1.62 ns 1.00 0.0019 - - 208 B
DecryptEcb_ToSpan Job-XPHHLI branch 16 None Internal.Cryptography.DesImplementation 809.5 ns 7.18 ns 6.72 ns 0.90 0.0019 - - 160 B
DecryptEcb_ToSpan Job-LZVMLS main 16 None Internal.Cryptography.DesImplementation 896.4 ns 4.44 ns 3.94 ns 1.00 0.0019 - - 216 B
Encrypt_Ecb_ToSpan Job-XPHHLI branch 16 None Internal.Cryptography.RC2Implementation 1,343.1 ns 4.63 ns 4.10 ns 0.94 0.0019 - - 176 B
Encrypt_Ecb_ToSpan Job-LZVMLS main 16 None Internal.Cryptography.RC2Implementation 1,422.7 ns 3.05 ns 2.71 ns 1.00 0.0019 - - 224 B
DecryptEcb_ToSpan Job-XPHHLI branch 16 None Internal.Cryptography.RC2Implementation 1,232.1 ns 5.84 ns 5.46 ns 0.94 0.0019 - - 176 B
DecryptEcb_ToSpan Job-LZVMLS main 16 None Internal.Cryptography.RC2Implementation 1,311.1 ns 3.97 ns 3.71 ns 1.00 0.0019 - - 232 B
Encrypt_Ecb_ToSpan Job-XPHHLI branch 16 None Internal.Cryptography.TripleDesImplementation 1,303.2 ns 12.18 ns 11.40 ns 0.96 0.0019 - - 160 B
Encrypt_Ecb_ToSpan Job-LZVMLS main 16 None Internal.Cryptography.TripleDesImplementation 1,359.8 ns 3.65 ns 3.05 ns 1.00 0.0019 - - 208 B
DecryptEcb_ToSpan Job-XPHHLI branch 16 None Internal.Cryptography.TripleDesImplementation 1,300.0 ns 2.22 ns 1.97 ns 0.96 0.0019 - - 160 B
DecryptEcb_ToSpan Job-LZVMLS main 16 None Internal.Cryptography.TripleDesImplementation 1,352.3 ns 4.50 ns 4.21 ns 1.00 0.0019 - - 216 B
Encrypt_Ecb_ToSpan Job-XPHHLI branch 16 PKCS7 Internal.Cryptography.AesImplementation 556.3 ns 2.90 ns 2.72 ns 0.83 0.0010 - - 120 B
Encrypt_Ecb_ToSpan Job-LZVMLS main 16 PKCS7 Internal.Cryptography.AesImplementation 670.0 ns 1.76 ns 1.56 ns 1.00 0.0019 - - 168 B
DecryptEcb_ToSpan Job-XPHHLI branch 16 PKCS7 Internal.Cryptography.AesImplementation 655.8 ns 2.06 ns 1.93 ns 0.82 0.0010 - - 120 B
DecryptEcb_ToSpan Job-LZVMLS main 16 PKCS7 Internal.Cryptography.AesImplementation 797.0 ns 1.82 ns 1.62 ns 1.00 0.0019 - - 176 B
Encrypt_Ecb_ToSpan Job-XPHHLI branch 16 PKCS7 Internal.Cryptography.DesImplementation 900.0 ns 3.57 ns 3.16 ns 0.91 0.0019 - - 160 B
Encrypt_Ecb_ToSpan Job-LZVMLS main 16 PKCS7 Internal.Cryptography.DesImplementation 989.1 ns 1.53 ns 1.27 ns 1.00 0.0019 - - 208 B
DecryptEcb_ToSpan Job-XPHHLI branch 16 PKCS7 Internal.Cryptography.DesImplementation 956.5 ns 2.47 ns 2.31 ns 0.90 0.0019 - - 160 B
DecryptEcb_ToSpan Job-LZVMLS main 16 PKCS7 Internal.Cryptography.DesImplementation 1,065.9 ns 3.23 ns 3.02 ns 1.00 0.0019 - - 216 B
Encrypt_Ecb_ToSpan Job-XPHHLI branch 16 PKCS7 Internal.Cryptography.RC2Implementation 1,482.0 ns 3.82 ns 3.39 ns 0.95 0.0019 - - 176 B
Encrypt_Ecb_ToSpan Job-LZVMLS main 16 PKCS7 Internal.Cryptography.RC2Implementation 1,561.5 ns 1.91 ns 1.69 ns 1.00 0.0019 - - 224 B
DecryptEcb_ToSpan Job-XPHHLI branch 16 PKCS7 Internal.Cryptography.RC2Implementation 1,399.7 ns 5.72 ns 5.35 ns 0.94 0.0019 - - 176 B
DecryptEcb_ToSpan Job-LZVMLS main 16 PKCS7 Internal.Cryptography.RC2Implementation 1,487.6 ns 12.94 ns 12.11 ns 1.00 0.0019 - - 232 B
Encrypt_Ecb_ToSpan Job-XPHHLI branch 16 PKCS7 Internal.Cryptography.TripleDesImplementation 1,511.1 ns 1.81 ns 1.70 ns 0.95 0.0019 - - 160 B
Encrypt_Ecb_ToSpan Job-LZVMLS main 16 PKCS7 Internal.Cryptography.TripleDesImplementation 1,586.7 ns 2.88 ns 2.55 ns 1.00 0.0019 - - 208 B
DecryptEcb_ToSpan Job-XPHHLI branch 16 PKCS7 Internal.Cryptography.TripleDesImplementation 1,613.6 ns 7.70 ns 7.20 ns 0.96 0.0019 - - 160 B
DecryptEcb_ToSpan Job-LZVMLS main 16 PKCS7 Internal.Cryptography.TripleDesImplementation 1,689.4 ns 4.76 ns 4.22 ns 1.00 0.0019 - - 216 B

This refactors the symmetric one shots to do less work. This removes the
calls to Reset for the one shots since the cipher will not be reused,
and in the Unix cases, removes keeping a copy of the IV around.
@ghost ghost added the community-contribution Indicates that the PR has been added by a community member label Aug 27, 2021
@ghost
Copy link

ghost commented Aug 27, 2021

Tagging subscribers to this area: @bartonjs, @vcsjones, @krwq, @GrabYourPitchforks
See info in area-owners.md if you want to be subscribed.

Issue Details

This is a revival of #55090 which was unable to make it in the 6.0 time frame.

This reduces allocations and overhead in for the symmetric one shots.

  • The Reset is skipped in the case of one shots since we won't use the cipher after the finalize. It's finalized, then disposed.
  • Since we don't reset, we don't need to hang on to a copy of the original IV to reset with. CNG still requires a copy of the IV because each call to encrypt or decrypt accepts the IV as it is updated throughout each block.

Starting off a draft because I think I can fix up Windows a bit more, but benchmarks look good.

Allocations that are "overhead" are cut about half. ECB and CBC show small throughput improvements. CFB shows larger improvements on the Apple platform because the overhead of doing a Reset with CFB is much higher.

Work remaining:

  • See what we can do about the IV situation on Windows. Probably rent for the IV.
  • Benchmarks on other platforms

Closes #55601.

Benchmarks on Apple M1

CBC

Method Job Toolchain DataSize Mode Algorithm Mean Error StdDev Ratio Gen 0 Gen 1 Gen 2 Allocated
Encrypt_Cbc_ToSpan Job-SPRJJB branch 16 None Internal.Cryptography.AesImplementation 558.7 ns 1.83 ns 1.62 ns 0.86 0.0610 - - 128 B
Encrypt_Cbc_ToSpan Job-LCBJSG main 16 None Internal.Cryptography.AesImplementation 650.2 ns 2.76 ns 2.45 ns 1.00 0.1068 - - 224 B
Decrypt_Cbc_ToSpan Job-SPRJJB branch 16 None Internal.Cryptography.AesImplementation 558.5 ns 4.28 ns 4.00 ns 0.87 0.0610 - - 128 B
Decrypt_Cbc_ToSpan Job-LCBJSG main 16 None Internal.Cryptography.AesImplementation 642.1 ns 2.38 ns 1.99 ns 1.00 0.1106 - - 232 B
Encrypt_Cbc_ToSpan Job-SPRJJB branch 16 None Internal.Cryptography.DesImplementation 3,833.9 ns 2.59 ns 2.16 ns 0.95 0.0763 - - 168 B
Encrypt_Cbc_ToSpan Job-LCBJSG main 16 None Internal.Cryptography.DesImplementation 4,047.9 ns 4.40 ns 3.90 ns 1.00 0.1221 - - 256 B
Decrypt_Cbc_ToSpan Job-SPRJJB branch 16 None Internal.Cryptography.DesImplementation 3,922.1 ns 4.68 ns 4.15 ns 0.97 0.0763 - - 168 B
Decrypt_Cbc_ToSpan Job-LCBJSG main 16 None Internal.Cryptography.DesImplementation 4,063.5 ns 6.45 ns 5.72 ns 1.00 0.1221 - - 264 B
Encrypt_Cbc_ToSpan Job-SPRJJB branch 16 None Internal.Cryptography.RC2Implementation 1,825.4 ns 3.37 ns 2.98 ns 0.94 0.0877 - - 184 B
Encrypt_Cbc_ToSpan Job-LCBJSG main 16 None Internal.Cryptography.RC2Implementation 1,932.8 ns 2.85 ns 2.67 ns 1.00 0.1297 - - 272 B
Decrypt_Cbc_ToSpan Job-SPRJJB branch 16 None Internal.Cryptography.RC2Implementation 1,724.6 ns 3.16 ns 2.64 ns 0.94 0.0877 - - 184 B
Decrypt_Cbc_ToSpan Job-LCBJSG main 16 None Internal.Cryptography.RC2Implementation 1,833.5 ns 1.80 ns 1.59 ns 1.00 0.1335 - - 280 B
Encrypt_Cbc_ToSpan Job-SPRJJB branch 16 None Internal.Cryptography.TripleDesImplementation 10,919.6 ns 76.68 ns 71.73 ns 1.01 0.0763 - - 168 B
Encrypt_Cbc_ToSpan Job-LCBJSG main 16 None Internal.Cryptography.TripleDesImplementation 10,771.8 ns 18.05 ns 16.00 ns 1.00 0.1221 - - 256 B
Decrypt_Cbc_ToSpan Job-SPRJJB branch 16 None Internal.Cryptography.TripleDesImplementation 10,756.1 ns 31.83 ns 29.77 ns 0.97 0.0763 - - 168 B
Decrypt_Cbc_ToSpan Job-LCBJSG main 16 None Internal.Cryptography.TripleDesImplementation 11,048.4 ns 37.20 ns 31.06 ns 1.00 0.1221 - - 264 B
Encrypt_Cbc_ToSpan Job-SPRJJB branch 16 PKCS7 Internal.Cryptography.AesImplementation 579.8 ns 1.33 ns 1.24 ns 0.87 0.0610 - - 128 B
Encrypt_Cbc_ToSpan Job-LCBJSG main 16 PKCS7 Internal.Cryptography.AesImplementation 666.2 ns 1.19 ns 0.99 ns 1.00 0.1068 - - 224 B
Decrypt_Cbc_ToSpan Job-SPRJJB branch 16 PKCS7 Internal.Cryptography.AesImplementation 626.5 ns 4.94 ns 4.62 ns 0.87 0.0610 - - 128 B
Decrypt_Cbc_ToSpan Job-LCBJSG main 16 PKCS7 Internal.Cryptography.AesImplementation 717.5 ns 2.98 ns 2.64 ns 1.00 0.1106 - - 232 B
Encrypt_Cbc_ToSpan Job-SPRJJB branch 16 PKCS7 Internal.Cryptography.DesImplementation 3,819.3 ns 4.47 ns 3.96 ns 0.94 0.0763 - - 168 B
Encrypt_Cbc_ToSpan Job-LCBJSG main 16 PKCS7 Internal.Cryptography.DesImplementation 4,053.4 ns 4.84 ns 4.04 ns 1.00 0.1221 - - 256 B
Decrypt_Cbc_ToSpan Job-SPRJJB branch 16 PKCS7 Internal.Cryptography.DesImplementation 4,117.0 ns 4.56 ns 4.04 ns 0.98 0.0763 - - 168 B
Decrypt_Cbc_ToSpan Job-LCBJSG main 16 PKCS7 Internal.Cryptography.DesImplementation 4,219.6 ns 10.33 ns 8.63 ns 1.00 0.1221 - - 264 B
Encrypt_Cbc_ToSpan Job-SPRJJB branch 16 PKCS7 Internal.Cryptography.RC2Implementation 1,962.6 ns 5.17 ns 4.84 ns 0.95 0.0877 - - 184 B
Encrypt_Cbc_ToSpan Job-LCBJSG main 16 PKCS7 Internal.Cryptography.RC2Implementation 2,073.3 ns 6.05 ns 5.36 ns 1.00 0.1297 - - 272 B
Decrypt_Cbc_ToSpan Job-SPRJJB branch 16 PKCS7 Internal.Cryptography.RC2Implementation 1,868.5 ns 1.05 ns 0.93 ns 0.95 0.0877 - - 184 B
Decrypt_Cbc_ToSpan Job-LCBJSG main 16 PKCS7 Internal.Cryptography.RC2Implementation 1,959.2 ns 3.74 ns 3.31 ns 1.00 0.1335 - - 280 B
Encrypt_Cbc_ToSpan Job-SPRJJB branch 16 PKCS7 Internal.Cryptography.TripleDesImplementation 11,011.9 ns 15.59 ns 13.82 ns 0.99 0.0763 - - 168 B
Encrypt_Cbc_ToSpan Job-LCBJSG main 16 PKCS7 Internal.Cryptography.TripleDesImplementation 11,111.5 ns 9.77 ns 7.63 ns 1.00 0.1221 - - 256 B
Decrypt_Cbc_ToSpan Job-SPRJJB branch 16 PKCS7 Internal.Cryptography.TripleDesImplementation 10,933.5 ns 15.30 ns 14.31 ns 0.99 0.0763 - - 168 B
Decrypt_Cbc_ToSpan Job-LCBJSG main 16 PKCS7 Internal.Cryptography.TripleDesImplementation 11,010.9 ns 19.28 ns 17.10 ns 1.00 0.1221 - - 264 B

CFB

Method Job Toolchain DataSize FeebackSize Mode Algorithm Mean Error StdDev Ratio Gen 0 Gen 1 Gen 2 Allocated
Encrypt_Cfb_ToSpan Job-SPRJJB branch 16 8 None Internal.Cryptography.AesImplementation 700.2 ns 2.13 ns 1.99 ns 0.68 0.0610 - - 128 B
Encrypt_Cfb_ToSpan Job-LCBJSG main 16 8 None Internal.Cryptography.AesImplementation 1,026.9 ns 7.10 ns 6.64 ns 1.00 0.1221 - - 256 B
Decrypt_Cfb_ToSpan Job-SPRJJB branch 16 8 None Internal.Cryptography.AesImplementation 667.4 ns 6.13 ns 5.74 ns 0.67 0.0610 - - 128 B
Decrypt_Cfb_ToSpan Job-LCBJSG main 16 8 None Internal.Cryptography.AesImplementation 990.1 ns 7.68 ns 7.19 ns 1.00 0.1259 - - 264 B
Encrypt_Cfb_ToSpan Job-SPRJJB branch 16 8 None Internal.Cryptography.DesImplementation 3,740.5 ns 5.54 ns 5.18 ns 0.67 0.0801 - - 168 B
Encrypt_Cfb_ToSpan Job-LCBJSG main 16 8 None Internal.Cryptography.DesImplementation 5,578.8 ns 11.14 ns 10.42 ns 1.00 0.1373 - - 288 B
Decrypt_Cfb_ToSpan Job-SPRJJB branch 16 8 None Internal.Cryptography.DesImplementation 3,638.7 ns 3.00 ns 2.81 ns 0.65 0.0801 - - 168 B
Decrypt_Cfb_ToSpan Job-LCBJSG main 16 8 None Internal.Cryptography.DesImplementation 5,564.1 ns 6.48 ns 5.41 ns 1.00 0.1373 - - 296 B
Encrypt_Cfb_ToSpan Job-SPRJJB branch 16 8 None Internal.Cryptography.TripleDesImplementation 9,559.0 ns 13.73 ns 12.84 ns 0.65 0.0763 - - 168 B
Encrypt_Cfb_ToSpan Job-LCBJSG main 16 8 None Internal.Cryptography.TripleDesImplementation 14,785.0 ns 19.50 ns 18.24 ns 1.00 0.1373 - - 288 B
Decrypt_Cfb_ToSpan Job-SPRJJB branch 16 8 None Internal.Cryptography.TripleDesImplementation 9,459.0 ns 31.59 ns 28.00 ns 0.64 0.0763 - - 168 B
Decrypt_Cfb_ToSpan Job-LCBJSG main 16 8 None Internal.Cryptography.TripleDesImplementation 14,800.5 ns 27.65 ns 24.51 ns 1.00 0.1373 - - 296 B
Encrypt_Cfb_ToSpan Job-SPRJJB branch 16 8 PKCS7 Internal.Cryptography.AesImplementation 722.5 ns 4.40 ns 4.11 ns 0.68 0.0610 - - 128 B
Encrypt_Cfb_ToSpan Job-LCBJSG main 16 8 PKCS7 Internal.Cryptography.AesImplementation 1,068.5 ns 3.72 ns 3.48 ns 1.00 0.1221 - - 256 B
Decrypt_Cfb_ToSpan Job-SPRJJB branch 16 8 PKCS7 Internal.Cryptography.AesImplementation 679.4 ns 2.07 ns 1.84 ns 0.67 0.0610 - - 128 B
Decrypt_Cfb_ToSpan Job-LCBJSG main 16 8 PKCS7 Internal.Cryptography.AesImplementation 1,017.5 ns 6.10 ns 5.71 ns 1.00 0.1259 - - 264 B
Encrypt_Cfb_ToSpan Job-SPRJJB branch 16 8 PKCS7 Internal.Cryptography.DesImplementation 3,786.3 ns 2.91 ns 2.43 ns 0.65 0.0801 - - 168 B
Encrypt_Cfb_ToSpan Job-LCBJSG main 16 8 PKCS7 Internal.Cryptography.DesImplementation 5,789.9 ns 2.58 ns 2.02 ns 1.00 0.1373 - - 288 B
Decrypt_Cfb_ToSpan Job-SPRJJB branch 16 8 PKCS7 Internal.Cryptography.DesImplementation 3,765.6 ns 4.90 ns 4.58 ns 0.66 0.0801 - - 168 B
Decrypt_Cfb_ToSpan Job-LCBJSG main 16 8 PKCS7 Internal.Cryptography.DesImplementation 5,699.2 ns 6.43 ns 5.70 ns 1.00 0.1373 - - 296 B
Encrypt_Cfb_ToSpan Job-SPRJJB branch 16 8 PKCS7 Internal.Cryptography.TripleDesImplementation 9,685.0 ns 11.34 ns 10.61 ns 0.64 0.0763 - - 168 B
Encrypt_Cfb_ToSpan Job-LCBJSG main 16 8 PKCS7 Internal.Cryptography.TripleDesImplementation 15,248.0 ns 21.36 ns 19.98 ns 1.00 0.1373 - - 288 B
Decrypt_Cfb_ToSpan Job-SPRJJB branch 16 8 PKCS7 Internal.Cryptography.TripleDesImplementation 9,631.0 ns 17.41 ns 16.28 ns 0.64 0.0763 - - 168 B
Decrypt_Cfb_ToSpan Job-LCBJSG main 16 8 PKCS7 Internal.Cryptography.TripleDesImplementation 15,103.2 ns 35.81 ns 31.75 ns 1.00 0.1373 - - 296 B

ECB

Method Job Toolchain DataSize Mode Algorithm Mean Error StdDev Ratio Gen 0 Gen 1 Gen 2 Allocated
Encrypt_Ecb_ToSpan Job-SPRJJB branch 16 None Internal.Cryptography.AesImplementation 556.3 ns 3.20 ns 2.84 ns 0.91 0.0610 - - 128 B
Encrypt_Ecb_ToSpan Job-LCBJSG main 16 None Internal.Cryptography.AesImplementation 612.9 ns 4.45 ns 4.17 ns 1.00 0.0877 - - 184 B
DecryptEcb_ToSpan Job-SPRJJB branch 16 None Internal.Cryptography.AesImplementation 547.7 ns 3.33 ns 3.12 ns 0.91 0.0610 - - 128 B
DecryptEcb_ToSpan Job-LCBJSG main 16 None Internal.Cryptography.AesImplementation 601.8 ns 2.57 ns 2.27 ns 1.00 0.0916 - - 192 B
Encrypt_Ecb_ToSpan Job-SPRJJB branch 16 None Internal.Cryptography.DesImplementation 3,909.5 ns 3.71 ns 3.47 ns 0.98 0.0763 - - 168 B
Encrypt_Ecb_ToSpan Job-LCBJSG main 16 None Internal.Cryptography.DesImplementation 3,988.5 ns 5.14 ns 4.81 ns 1.00 0.1068 - - 224 B
DecryptEcb_ToSpan Job-SPRJJB branch 16 None Internal.Cryptography.DesImplementation 3,892.1 ns 7.83 ns 6.54 ns 0.97 0.0763 - - 168 B
DecryptEcb_ToSpan Job-LCBJSG main 16 None Internal.Cryptography.DesImplementation 4,023.6 ns 7.93 ns 7.42 ns 1.00 0.1068 - - 232 B
Encrypt_Ecb_ToSpan Job-SPRJJB branch 16 None Internal.Cryptography.RC2Implementation 1,789.2 ns 3.29 ns 3.08 ns 0.97 0.0877 - - 184 B
Encrypt_Ecb_ToSpan Job-LCBJSG main 16 None Internal.Cryptography.RC2Implementation 1,853.1 ns 2.17 ns 2.03 ns 1.00 0.1144 - - 240 B
DecryptEcb_ToSpan Job-SPRJJB branch 16 None Internal.Cryptography.RC2Implementation 1,715.4 ns 2.65 ns 2.48 ns 0.96 0.0877 - - 184 B
DecryptEcb_ToSpan Job-LCBJSG main 16 None Internal.Cryptography.RC2Implementation 1,779.2 ns 3.54 ns 3.31 ns 1.00 0.1183 - - 248 B
Encrypt_Ecb_ToSpan Job-SPRJJB branch 16 None Internal.Cryptography.TripleDesImplementation 10,705.0 ns 19.60 ns 17.38 ns 1.00 0.0763 - - 168 B
Encrypt_Ecb_ToSpan Job-LCBJSG main 16 None Internal.Cryptography.TripleDesImplementation 10,737.2 ns 26.27 ns 24.57 ns 1.00 0.1068 - - 224 B
DecryptEcb_ToSpan Job-SPRJJB branch 16 None Internal.Cryptography.TripleDesImplementation 10,779.4 ns 12.80 ns 11.35 ns 0.98 0.0763 - - 168 B
DecryptEcb_ToSpan Job-LCBJSG main 16 None Internal.Cryptography.TripleDesImplementation 11,012.6 ns 19.02 ns 17.79 ns 1.00 0.1068 - - 232 B
Encrypt_Ecb_ToSpan Job-SPRJJB branch 16 PKCS7 Internal.Cryptography.AesImplementation 555.3 ns 4.03 ns 3.77 ns 0.89 0.0610 - - 128 B
Encrypt_Ecb_ToSpan Job-LCBJSG main 16 PKCS7 Internal.Cryptography.AesImplementation 620.7 ns 0.85 ns 0.75 ns 1.00 0.0877 - - 184 B
DecryptEcb_ToSpan Job-SPRJJB branch 16 PKCS7 Internal.Cryptography.AesImplementation 607.1 ns 3.18 ns 2.98 ns 0.91 0.0610 - - 128 B
DecryptEcb_ToSpan Job-LCBJSG main 16 PKCS7 Internal.Cryptography.AesImplementation 664.2 ns 7.82 ns 7.32 ns 1.00 0.0916 - - 192 B
Encrypt_Ecb_ToSpan Job-SPRJJB branch 16 PKCS7 Internal.Cryptography.DesImplementation 3,922.0 ns 9.55 ns 7.97 ns 0.97 0.0763 - - 168 B
Encrypt_Ecb_ToSpan Job-LCBJSG main 16 PKCS7 Internal.Cryptography.DesImplementation 4,047.2 ns 10.18 ns 8.50 ns 1.00 0.1068 - - 224 B
DecryptEcb_ToSpan Job-SPRJJB branch 16 PKCS7 Internal.Cryptography.DesImplementation 3,986.7 ns 2.99 ns 2.65 ns 1.00 0.0763 - - 168 B
DecryptEcb_ToSpan Job-LCBJSG main 16 PKCS7 Internal.Cryptography.DesImplementation 3,985.0 ns 10.94 ns 10.24 ns 1.00 0.1068 - - 232 B
Encrypt_Ecb_ToSpan Job-SPRJJB branch 16 PKCS7 Internal.Cryptography.RC2Implementation 1,907.3 ns 3.47 ns 2.90 ns 0.96 0.0877 - - 184 B
Encrypt_Ecb_ToSpan Job-LCBJSG main 16 PKCS7 Internal.Cryptography.RC2Implementation 1,984.0 ns 2.22 ns 2.08 ns 1.00 0.1144 - - 240 B
DecryptEcb_ToSpan Job-SPRJJB branch 16 PKCS7 Internal.Cryptography.RC2Implementation 1,837.6 ns 3.17 ns 2.96 ns 0.96 0.0877 - - 184 B
DecryptEcb_ToSpan Job-LCBJSG main 16 PKCS7 Internal.Cryptography.RC2Implementation 1,905.8 ns 2.76 ns 2.45 ns 1.00 0.1183 - - 248 B
Encrypt_Ecb_ToSpan Job-SPRJJB branch 16 PKCS7 Internal.Cryptography.TripleDesImplementation 10,960.8 ns 8.04 ns 7.52 ns 1.01 0.0763 - - 168 B
Encrypt_Ecb_ToSpan Job-LCBJSG main 16 PKCS7 Internal.Cryptography.TripleDesImplementation 10,812.9 ns 22.44 ns 20.99 ns 1.00 0.1068 - - 224 B
DecryptEcb_ToSpan Job-SPRJJB branch 16 PKCS7 Internal.Cryptography.TripleDesImplementation 11,254.4 ns 15.72 ns 14.70 ns 1.00 0.0763 - - 168 B
DecryptEcb_ToSpan Job-LCBJSG main 16 PKCS7 Internal.Cryptography.TripleDesImplementation 11,291.4 ns 19.30 ns 16.12 ns 1.00 0.1068 - - 232 B
Author: vcsjones
Assignees: -
Labels:

area-System.Security, community-contribution

Milestone: -

@vcsjones
Copy link
Member Author

Note: this PR omits some one-shot improvements for the *Cng one-shot implementations. I'll do that in a follow up PR, as this one has gotten a bit big (though most of the changes are just shuffling / decoupling existing code).

@vcsjones
Copy link
Member Author

vcsjones commented Sep 1, 2021

Linux, macOS, and Windows benchmarks look positive to me, so I'll mark it ready for review.

@vcsjones vcsjones marked this pull request as ready for review September 1, 2021 22:30
@vcsjones
Copy link
Member Author

vcsjones commented Sep 2, 2021

Performance of TransformFinalBlock remains on par.

Benchmarks
Method Job Toolchain DataSize Mode Mean Error StdDev Median Ratio RatioSD Gen 0 Gen 1 Gen 2 Allocated
Encrypt_TransformFinalBlock Job-SVGZYX branch 16 None 145.95 ns 0.134 ns 0.125 ns 145.96 ns 1.02 0.00 0.0191 - - 40 B
Encrypt_TransformFinalBlock Job-YNERGC main 16 None 143.39 ns 0.078 ns 0.073 ns 143.37 ns 1.00 0.00 0.0191 - - 40 B
Decrypt_TransformFinalBlock Job-SVGZYX branch 16 None 179.26 ns 0.044 ns 0.035 ns 179.27 ns 0.99 0.00 0.0191 - - 40 B
Decrypt_TransformFinalBlock Job-YNERGC main 16 None 180.40 ns 0.128 ns 0.113 ns 180.42 ns 1.00 0.00 0.0191 - - 40 B

@danmoseley
Copy link
Member

Are these scenarios that ought to be added to dotnet/performance to protect this change? I don't think I see them there.

@vcsjones
Copy link
Member Author

vcsjones commented Sep 8, 2021

Are these scenarios that ought to be added to dotnet/performance to protect this change? I don't think I see them there.

I don't know, and I don't know how volatile it would be. Crypto is largely dependent on platform implementations, and the majority of the time spent is in native calls. Benchmarks could be added but they would largely be timing these native APIs that we have no control over.

@vcsjones
Copy link
Member Author

@bartonjs just a ping to see if this one flew under your radar (I think you were out when I opened this PR). No worries if you cannot get to this one any time soon.

The diff looks scary but it's mostly just moving code around, not re-writes.

}
}

public static int PadBlock(ReadOnlySpan<byte> block, Span<byte> destination, int paddingSizeInBytes, PaddingMode paddingMode)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, I (personally) strongly prefer that methods inside internal classes are marked internal, unless they are conforming to an interface.

Every time I see "public" I have an API Review reaction (e.g. something like "is this the right shape for the rest of time?", "did we review this?", or "I don't remember seeing the ref.cs update").

I wouldn't spin the change at this point just for this... but if it has to be spun.... 😄.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. I suspect in two years you will have changed my mind on this, much like with var when I set out to start contributing here a few years ago 😄.

@bartonjs
Copy link
Member

if this one flew under your radar

Well... I knew it was here. But that it was long. And I was "so close" to finishing up a thing I was working on. Now it's two weeks later and I'm still "so close", so it was obviously time to bump this higher 😄. Sorry.

@bartonjs bartonjs merged commit e9869c3 into dotnet:main Sep 17, 2021
@vcsjones vcsjones deleted the refactor-one-shot branch September 17, 2021 17:11
@ghost ghost locked as resolved and limited conversation to collaborators Nov 3, 2021
@bartonjs bartonjs added the needs-further-triage Issue has been initially triaged, but needs deeper consideration or reconsideration label Aug 19, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Security community-contribution Indicates that the PR has been added by a community member needs-further-triage Issue has been initially triaged, but needs deeper consideration or reconsideration
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants