Skip to content

Instantly share code, notes, and snippets.

@ZenithalHourlyRate
Last active May 17, 2022 08:12
Show Gist options
  • Save ZenithalHourlyRate/12b60891cfc70f97b5fb357f458d6a41 to your computer and use it in GitHub Desktop.
Save ZenithalHourlyRate/12b60891cfc70f97b5fb357f458d6a41 to your computer and use it in GitHub Desktop.
Benchmark of OpenSSL SM4 on RISC-V

Benchmark of OpenSSL SM4 on RISC-V

Same setup as https://gist.github.com/ZenithalHourlyRate/7b5175734f87acb73d0bbc53391d7140 (aligned from openssl/openssl#18267 and Zbb/Zbc from openssl/openssl#17640)

I've made a PR openssl/openssl#18285

It turned out that both RV32/RV64 can use the same function (I removed RV64 specific asm) and here is the new benchmark

New Benchmark

Start cbc for 2 sec
./openssl-c-long
SM4-CBC           1064.71k     1289.18k     1368.45k     1384.96k     1372.16k     1368.06k
./openssl-zksed-rvi-aligned
SM4-CBC           2549.08k     4217.95k     5020.29k     5270.53k     5234.69k     5096.33k

Start ecb for 2 sec
./openssl-c-long
SM4-ECB           1169.30k     1340.26k     1396.99k     1404.78k     1388.54k     1384.45k
./openssl-zksed-rvi-aligned
SM4-ECB           3131.71k     4545.34k     5240.45k     5459.62k     5373.95k     5219.83k

Start cfb for 2 sec
./openssl-c-long
SM4-CFB           1134.87k     1319.68k     1385.10k     1384.45k     1372.16k     1368.06k
./openssl-zksed-rvi-aligned
SM4-CFB           2909.79k     4367.14k     5067.65k     5280.26k     5218.30k     5062.66k

Start ctr for 2 sec
./openssl-c-long
SM4-CTR           1072.59k     1254.24k     1303.81k     1314.30k     1298.43k     1294.34k
./openssl-zksed-rvi-aligned
SM4-CTR           2575.82k     3699.07k     4203.14k     4361.31k     4278.97k     4186.11k

Start ofb for 2 sec
./openssl-c-long
SM4-OFB           1121.12k     1328.74k     1383.30k     1400.15k     1369.41k     1368.06k
./openssl-zksed-rvi-aligned
SM4-OFB           2810.17k     4380.69k     5111.68k     5305.34k     5259.26k     5103.62k

Start ccm for 2 sec
./openssl-c-long
SM4-CCM            294.40k      507.33k      623.02k      655.36k      667.65k      668.40k
./openssl-zksed-rvi-aligned
SM4-CCM            294.86k      508.72k      623.41k      655.36k      667.65k      668.40k

Start ocb for 2 sec
./openssl-c-long
./openssl-zksed-rvi-aligned

Start gcm for 2 sec
./openssl-c-long
SM4-GCM            674.22k      805.44k      839.27k      853.16k      843.65k      847.73k
./openssl-zksed-rvi-aligned
SM4-GCM           1320.50k     1603.57k     1708.29k     1733.12k     1716.22k     1703.61k

Start xts for 2 sec
./openssl-c-long
./openssl-zksed-rvi-aligned

Start gcm for 2 sec
./openssl-c-long
SM4-GCM            680.04k      812.51k      842.88k      849.92k      848.02k      847.73k
./openssl-zksed-rvi-aligned
SM4-GCM           2365.86k     3436.58k     3958.02k     4104.70k     4067.33k     3973.12k

New ccm

Start ccm for 2 sec
./openssl-c-long
SM4-CCM            293.49k      505.73k      619.96k      653.82k      667.65k      665.09k
./openssl-xts
SM4-CCM            820.49k     1625.54k     2136.58k     2327.04k     2358.80k     2331.26k

Old Benchmark

Start cbc for 2 sec         
./openssl-c-long       
SM4-CBC           1062.26k     1298.14k     1368.19k     1393.46k     1372.16k     1368.06k
./openssl-zksed-zbkb-aligned
SM4-CBC           2722.61k     4180.42k     4785.54k     4971.01k     4927.49k     4784.13k
./openssl-zksed-aligned                                                                                                                                                            
SM4-CBC           2661.43k     4103.14k     4701.22k     4892.44k     4841.10k     4694.02k
                                                                                                                                                                                   
Start ecb for 2 sec    
./openssl-c-long                                                                                                                                                                   
SM4-ECB           1175.97k     1340.45k     1398.02k     1406.46k     1395.52k     1377.56k
./openssl-zksed-zbkb-aligned
SM4-ECB           3348.52k     4547.78k     5068.80k     5205.93k     5103.62k     4939.90k
./openssl-zksed-aligned     
SM4-ECB           3310.79k     4498.33k     4961.15k     5090.30k     5013.50k     4874.24k

Start cfb for 2 sec
./openssl-c-long
SM4-CFB           1121.37k     1320.81k     1383.30k     1393.78k     1372.16k     1368.06k
./openssl-zksed-zbkb-aligned
SM4-CFB           2960.60k     4341.68k     4849.72k     4998.05k     4911.10k     4767.74k
./openssl-zksed-aligned
SM4-CFB           2974.54k     4288.58k     4749.57k     4894.41k     4812.80k     4685.82k

Start ctr for 2 sec
./openssl-c-long
SM4-CTR           1064.59k     1252.53k     1308.17k     1313.28k     1296.72k     1294.34k
./openssl-zksed-zbkb-aligned
SM4-CTR           2775.49k     3671.20k     4049.54k     4147.20k     4096.00k     3989.50k
./openssl-zksed-aligned
SM4-CTR           2736.47k     3601.05k     3985.79k     4084.74k     4014.08k     3923.97k

Start ofb for 2 sec
./openssl-c-long
SM4-OFB           1123.45k     1323.38k     1383.04k     1388.83k     1376.26k     1368.06k
./openssl-zksed-zbkb-aligned
SM4-OFB           3185.52k     4266.29k     4908.25k     5044.87k     4952.06k     4808.70k
./openssl-zksed-aligned
SM4-OFB           2866.47k     4217.15k     4776.27k     4911.10k     4857.28k     4718.59k

Start ccm for 2 sec
./openssl-c-long
SM4-CCM            296.84k      509.47k      621.06k      656.90k      668.40k      671.74k
./openssl-zksed-zbkb-aligned
SM4-CCM            294.22k      507.87k      624.18k      656.90k      667.65k      671.74k
./openssl-zksed-aligned
SM4-CCM            292.93k      509.94k      621.22k      656.38k      671.74k      671.74k

Start ocb for 2 sec
./openssl-c-long
./openssl-zksed-zbkb-aligned
./openssl-zksed-aligned

Start gcm for 2 sec
./openssl-c-long
SM4-GCM            675.45k      808.10k      842.24k      853.68k      847.73k      851.97k
./openssl-zksed-zbkb-aligned
SM4-GCM           1232.71k     1488.74k     1579.05k     1598.46k     1584.34k     1581.06k
./openssl-zksed-aligned
SM4-GCM           1236.62k     1496.57k     1580.29k     1601.54k     1585.15k     1581.06k

Start xts for 2 sec
./openssl-c-long
./openssl-zksed-zbkb-aligned
./openssl-zksed-aligned

Start gcm for 2 sec (with Zbb/Zbc)
./openssl-c-long
SM4-GCM            676.48k      808.00k      842.62k      849.92k      848.02k      848.02k
./openssl-zksed-zbkb-aligned
SM4-GCM           2175.66k     3159.01k     3579.26k     3702.27k     3661.82k     3588.10k
./openssl-zksed-aligned
SM4-GCM           2196.04k     3221.12k     3586.82k     3727.57k     3665.92k     3614.36k

Benchmark of OpenSSL SM4 for RISC-V 32

This is evaluated against FPGA based on RTL from chipsalliance/rocket-chip#2950.

The openssl32-asm-all binary is the result of merging openssl/openssl#17640, openssl/openssl#18197, openssl/openssl#18308 and openssl/openssl#18285

Start cbc for 2 sec
./openssl32-c
SM4-CBC           1033.51k     1297.50k     1393.59k     1413.12k     1400.83k     1392.64k
./openssl32-asm-all
SM4-CBC           2333.68k     3897.95k     4711.68k     4979.71k     4964.35k     4800.51k

Start ecb for 2 sec
./openssl32-c
SM4-ECB           1174.14k     1378.62k     1440.77k     1466.53k     1430.54k     1425.41k
./openssl32-asm-all
SM4-ECB           3208.92k     4661.87k     5267.26k     5448.70k     5382.14k     5177.34k

Start cfb for 2 sec
./openssl32-c
SM4-CFB           1168.14k     1348.41k     1416.49k     1432.06k     1400.83k     1392.64k
./openssl32-asm-all
SM4-CFB           2974.76k     4273.02k     4846.46k     4996.10k     4968.72k     4767.74k

Start ctr for 2 sec
./openssl32-c
SM4-CTR           1112.15k     1272.38k     1336.09k     1342.98k     1323.01k     1312.35k
./openssl32-asm-all
SM4-CTR           2748.49k     3665.17k     4057.09k     4159.49k     4108.29k     4001.32k

Start ofb for 2 sec
./openssl32-c
SM4-OFB           1175.41k     1358.82k     1417.70k     1428.99k     1409.02k     1392.64k
./openssl32-asm-all
SM4-OFB           3153.23k     4355.10k     4904.70k     5068.29k     5046.93k     4841.47k

Start ccm for 2 sec
./openssl32-c
SM4-CCM            309.30k      528.19k      642.18k      679.94k      692.22k      691.59k
./openssl32-asm-all
SM4-CCM            309.10k      525.87k      640.90k      682.32k      692.22k      691.59k

Start ocb for 2 sec
./openssl32-c
./openssl32-asm-all

Start gcm for 2 sec
./openssl32-c
SM4-GCM            613.11k      696.35k      720.14k      726.58k      717.31k      717.31k
./openssl32-asm-all
SM4-GCM            916.36k     1077.43k     1127.17k     1145.95k     1138.69k     1133.02k

Start xts for 2 sec
./openssl32-c
./openssl32-asm-all

New ccm

It turned out that sm4-ccm is not accelerated, here is the fixed benchmark

Start ccm for 2 sec                                   
./openssl32-c                                         
SM4-CCM            309.11k      528.83k      640.39k      680.45k      691.59k      689.43k 
./openssl32-asm-xts                                   
SM4-CCM            852.48k     1617.91k     2088.58k     2274.93k     2292.94k     2260.99k 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment