Fully managed .NET AES implementation (based on AES-NI)
Do not use this in production! This is a toy project to explore System.Runtime.Intrinsics
and AES-NI
Currently with support for ECB, CBC and GCM encrypt/decrypt (all NIST KATs passing).
Adding all sorts of paddings is also supported, removing & verifying it is on my todo list...
Other modes of use may follow as well.
AES key expansion performance
Method
Mean
Error
StdDev
Aes128BitKeyExpansion
35.91 ns
0.6520 ns
0.6099 ns
Aes192BitKeyExpansion
47.13 ns
0.7675 ns
0.6804 ns
Aes256BitKeyExpansion
42.32 ns
0.9240 ns
0.9887 ns
AES GCM encrypt performance
Method
KeySize
DataSize
AadDataSize
Mean
Error
Ratio
AesNi
128
16
0
116.9 ns
0.9230 ns
0.59
Framework
128
16
0
196.7 ns
0.2843 ns
1.00
AesNi
128
16
16
125.9 ns
0.7349 ns
0.60
Framework
128
16
16
209.8 ns
1.3427 ns
1.00
AesNi
128
16
1024
363.3 ns
1.4387 ns
1.02
Framework
128
16
1024
357.8 ns
1.2221 ns
1.00
AesNi
128
16
1048576
251,047.3 ns
635.6994 ns
1.69
Framework
128
16
1048576
148,721.9 ns
328.4326 ns
1.00
AesNi
128
1024
0
513.7 ns
1.6526 ns
1.08
Framework
128
1024
0
475.1 ns
1.6877 ns
1.00
AesNi
128
1024
16
515.3 ns
1.3066 ns
1.09
Framework
128
1024
16
472.2 ns
2.3596 ns
1.00
AesNi
128
1024
1024
766.6 ns
1.5603 ns
1.21
Framework
128
1024
1024
635.7 ns
2.5873 ns
1.00
AesNi
128
1024
1048576
259,308.8 ns
1,252.8282 ns
1.70
Framework
128
1024
1048576
152,773.2 ns
851.4720 ns
1.00
AesNi
128
1048576
0
422,961.0 ns
2,256.4577 ns
1.59
Framework
128
1048576
0
266,618.2 ns
422.4311 ns
1.00
AesNi
128
1048576
16
424,680.1 ns
3,185.9390 ns
1.59
Framework
128
1048576
16
267,013.1 ns
1,777.2603 ns
1.00
AesNi
128
1048576
1024
434,743.8 ns
4,371.0678 ns
1.59
Framework
128
1048576
1024
273,610.6 ns
450.4404 ns
1.00
AesNi
128
1048576
1048576
689,697.7 ns
868.5420 ns
1.64
Framework
128
1048576
1048576
421,531.7 ns
3,582.6085 ns
1.00
AesNi
192
16
0
143.6 ns
0.5633 ns
0.74
Framework
192
16
0
192.9 ns
0.6242 ns
1.00
AesNi
192
16
16
153.1 ns
0.7294 ns
0.73
Framework
192
16
16
210.9 ns
0.4006 ns
1.00
AesNi
192
16
1024
400.2 ns
0.8833 ns
1.12
Framework
192
16
1024
356.8 ns
0.6916 ns
1.00
AesNi
192
16
1048576
250,448.8 ns
394.2873 ns
1.69
Framework
192
16
1048576
148,382.0 ns
290.7987 ns
1.00
AesNi
192
1024
0
568.1 ns
1.1216 ns
1.16
Framework
192
1024
0
487.6 ns
6.0360 ns
1.00
AesNi
192
1024
16
578.4 ns
1.1946 ns
1.16
Framework
192
1024
16
499.8 ns
1.7812 ns
1.00
AesNi
192
1024
1024
807.0 ns
1.3291 ns
1.25
Framework
192
1024
1024
643.6 ns
1.8400 ns
1.00
AesNi
192
1024
1048576
262,869.2 ns
943.2716 ns
1.73
Framework
192
1024
1048576
152,335.9 ns
935.3822 ns
1.00
AesNi
192
1048576
0
438,345.8 ns
1,060.3746 ns
1.57
Framework
192
1048576
0
278,631.5 ns
486.4308 ns
1.00
AesNi
192
1048576
16
442,616.3 ns
547.3178 ns
1.55
Framework
192
1048576
16
286,545.5 ns
1,512.6367 ns
1.00
AesNi
192
1048576
1024
450,771.3 ns
676.5289 ns
1.55
Framework
192
1048576
1024
290,664.8 ns
391.3501 ns
1.00
AesNi
192
1048576
1048576
686,396.4 ns
14,703.2507 ns
1.56
Framework
192
1048576
1048576
441,713.9 ns
494.7152 ns
1.00
AesNi
256
16
0
141.9 ns
0.3664 ns
0.71
Framework
256
16
0
198.5 ns
0.2866 ns
1.00
AesNi
256
16
16
156.5 ns
0.5802 ns
0.74
Framework
256
16
16
210.5 ns
0.9646 ns
1.00
AesNi
256
16
1024
400.8 ns
7.5786 ns
1.13
Framework
256
16
1024
355.9 ns
1.5194 ns
1.00
AesNi
256
16
1048576
247,994.4 ns
1,455.3164 ns
1.69
Framework
256
16
1048576
146,328.1 ns
1,307.2082 ns
1.00
AesNi
256
1024
0
544.0 ns
2.3217 ns
1.08
Framework
256
1024
0
502.1 ns
5.9181 ns
1.00
AesNi
256
1024
16
583.3 ns
6.9148 ns
1.13
Framework
256
1024
16
517.3 ns
4.6781 ns
1.00
AesNi
256
1024
1024
835.2 ns
12.4978 ns
1.32
Framework
256
1024
1024
634.3 ns
4.9952 ns
1.00
AesNi
256
1024
1048576
249,924.6 ns
1,841.8605 ns
1.68
Framework
256
1024
1048576
148,455.3 ns
458.4788 ns
1.00
AesNi
256
1048576
0
442,180.1 ns
4,221.1879 ns
1.52
Framework
256
1048576
0
291,458.2 ns
3,763.9204 ns
1.00
AesNi
256
1048576
16
438,106.3 ns
5,505.4349 ns
1.48
Framework
256
1048576
16
295,714.9 ns
2,600.2403 ns
1.00
AesNi
256
1048576
1024
456,180.5 ns
4,805.1506 ns
1.63
Framework
256
1048576
1024
280,266.8 ns
3,468.0828 ns
1.00
AesNi
256
1048576
1048576
689,585.6 ns
5,874.2785 ns
1.63
Framework
256
1048576
1048576
424,188.0 ns
2,975.6839 ns
1.00
Method
CipherMode
KeySize
DataSize
Mean
Error
Ratio
AesNi
CBC
128
16
51.48 ns
0.1573 ns
0.67
Framework
CBC
128
16
77.08 ns
0.5826 ns
1.00
AesNi
CBC
128
1024
693.96 ns
1.4697 ns
0.92
Framework
CBC
128
1024
752.54 ns
4.9276 ns
1.00
AesNi
CBC
128
1048576
698,223.91 ns
1,881.7810 ns
0.98
Framework
CBC
128
1048576
711,672.78 ns
4,434.7702 ns
1.00
AesNi
CBC
192
16
58.98 ns
0.4968 ns
0.71
Framework
CBC
192
16
82.70 ns
0.6663 ns
1.00
AesNi
CBC
192
1024
862.64 ns
1.0201 ns
0.93
Framework
CBC
192
1024
926.99 ns
2.3510 ns
1.00
AesNi
CBC
192
1048576
842,651.03 ns
4,075.8823 ns
0.99
Framework
CBC
192
1048576
853,973.89 ns
917.3084 ns
1.00
AesNi
CBC
256
16
58.53 ns
0.1174 ns
0.70
Framework
CBC
256
16
83.33 ns
0.4332 ns
1.00
AesNi
CBC
256
1024
859.57 ns
7.9029 ns
0.85
Framework
CBC
256
1024
1,016.35 ns
2.2197 ns
1.00
AesNi
CBC
256
1048576
835,345.80 ns
8,567.1241 ns
0.82
Framework
CBC
256
1048576
1,020,803.67 ns
2,502.8008 ns
1.00
AesNi
ECB
128
16
45.14 ns
0.1515 ns
0.58
Framework
ECB
128
16
77.69 ns
0.1875 ns
1.00
AesNi
ECB
128
1024
132.40 ns
0.4511 ns
0.79
Framework
ECB
128
1024
166.86 ns
1.3364 ns
1.00
AesNi
ECB
128
1048576
141,626.77 ns
198.7224 ns
1.48
Framework
ECB
128
1048576
95,954.07 ns
171.3752 ns
1.00
AesNi
ECB
192
16
51.69 ns
0.0787 ns
0.67
Framework
ECB
192
16
76.63 ns
0.4839 ns
1.00
AesNi
ECB
192
1024
153.73 ns
0.3768 ns
0.83
Framework
ECB
192
1024
185.51 ns
0.3866 ns
1.00
AesNi
ECB
192
1048576
121,029.49 ns
123.5305 ns
1.03
Framework
ECB
192
1048576
117,916.41 ns
511.1359 ns
1.00
AesNi
ECB
256
16
53.39 ns
0.1102 ns
0.67
Framework
ECB
256
16
79.32 ns
1.0731 ns
1.00
AesNi
ECB
256
1024
150.18 ns
0.4052 ns
0.71
Framework
ECB
256
1024
212.85 ns
2.3061 ns
1.00
AesNi
ECB
256
1048576
121,857.20 ns
605.2357 ns
0.89
Framework
ECB
256
1048576
136,291.12 ns
660.5039 ns
1.00
Method
CipherMode
KeySize
DataSize
Mean
Error
Ratio
AesNi
CBC
128
16
40.56 ns
0.3099 ns
0.48
Framework
CBC
128
16
85.17 ns
0.7217 ns
1.00
AesNi
CBC
128
1024
150.37 ns
6.1546 ns
0.82
Framework
CBC
128
1024
189.60 ns
1.9181 ns
1.00
AesNi
CBC
128
1048576
105,309.20 ns
536.4942 ns
0.97
Framework
CBC
128
1048576
108,803.69 ns
670.8807 ns
1.00
AesNi
CBC
192
16
45.69 ns
0.9025 ns
0.54
Framework
CBC
192
16
84.60 ns
0.4631 ns
1.00
AesNi
CBC
192
1024
155.21 ns
1.7375 ns
0.77
Framework
CBC
192
1024
202.52 ns
0.8997 ns
1.00
AesNi
CBC
192
1048576
124,210.60 ns
459.2670 ns
0.99
Framework
CBC
192
1048576
125,101.53 ns
198.4721 ns
1.00
AesNi
CBC
256
16
45.23 ns
0.2512 ns
0.51
Framework
CBC
256
16
89.06 ns
0.7113 ns
1.00
AesNi
CBC
256
1024
155.90 ns
1.9114 ns
0.70
Framework
CBC
256
1024
224.04 ns
2.2041 ns
1.00
AesNi
CBC
256
1048576
127,773.17 ns
3,084.0620 ns
0.90
Framework
CBC
256
1048576
144,033.44 ns
359.6341 ns
1.00
AesNi
ECB
128
16
31.46 ns
0.1889 ns
0.41
Framework
ECB
128
16
76.86 ns
0.3054 ns
1.00
AesNi
ECB
128
1024
111.58 ns
1.0203 ns
0.33
Framework
ECB
128
1024
339.31 ns
3.0097 ns
1.00
AesNi
ECB
128
1048576
139,299.30 ns
476.1600 ns
0.56
Framework
ECB
128
1048576
250,596.04 ns
2,637.1993 ns
1.00
AesNi
ECB
192
16
36.16 ns
0.1581 ns
0.48
Framework
ECB
192
16
75.77 ns
0.5718 ns
1.00
AesNi
ECB
192
1024
134.45 ns
0.7831 ns
0.40
Framework
ECB
192
1024
333.48 ns
5.6652 ns
1.00
AesNi
ECB
192
1048576
162,322.50 ns
954.9279 ns
0.63
Framework
ECB
192
1048576
259,364.61 ns
1,087.2464 ns
1.00
AesNi
ECB
256
16
36.13 ns
0.0700 ns
0.47
Framework
ECB
256
16
76.63 ns
0.7104 ns
1.00
AesNi
ECB
256
1024
133.11 ns
0.4417 ns
0.35
Framework
ECB
256
1024
375.75 ns
0.9654 ns
1.00
AesNi
ECB
256
1048576
161,534.95 ns
905.5891 ns
0.55
Framework
ECB
256
1048576
294,344.69 ns
1,807.6672 ns
1.00