Skip to content

Commit f1618a9

Browse files
committed
refactor: rename Aes
1 parent be9182d commit f1618a9

File tree

12 files changed

+130
-128
lines changed

12 files changed

+130
-128
lines changed

src/CryptoBase/SymmetricCryptos/AEADCryptos/AEADCryptoCreate.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ public static IAEADCrypto AesGcm(ReadOnlySpan<byte> key)
2121
[MethodImpl(MethodImplOptions.AggressiveInlining)]
2222
public static IAEADCrypto Sm4Gcm(ReadOnlySpan<byte> key)
2323
{
24-
if (Aes.IsSupported && Avx2.IsSupported)
24+
if (AesX86.IsSupported && Avx2.IsSupported)
2525
{
2626
return new GcmCryptoModeBlock16X86(new SM4Crypto(key), new SM4CryptoBlock16X86(key));
2727
}
2828

29-
if (Aes.IsSupported && Sse2.IsSupported && Ssse3.IsSupported && Sse41.IsSupported)
29+
if (AesX86.IsSupported && Sse2.IsSupported && Ssse3.IsSupported && Sse41.IsSupported)
3030
{
3131
return new GcmCryptoModeBlock8X86(new SM4Crypto(key), new SM4CryptoBlock8X86(key));
3232
}

src/CryptoBase/SymmetricCryptos/BlockCryptos/AES/AESUtils.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ static AESUtils()
2424
[MethodImpl(MethodImplOptions.AggressiveInlining)]
2525
public static AESCrypto CreateECB(ReadOnlySpan<byte> key)
2626
{
27-
if (System.Runtime.Intrinsics.X86.Aes.IsSupported && Sse2.IsSupported)
27+
if (AesX86.IsSupported && Sse2.IsSupported)
2828
{
2929
return key.Length switch
3030
{
@@ -41,7 +41,7 @@ public static AESCrypto CreateECB(ReadOnlySpan<byte> key)
4141
[MethodImpl(MethodImplOptions.AggressiveInlining)]
4242
public static IBlockCrypto CreateCBC(ReadOnlySpan<byte> key, ReadOnlySpan<byte> iv)
4343
{
44-
if (System.Runtime.Intrinsics.X86.Aes.IsSupported && Sse2.IsSupported)
44+
if (AesX86.IsSupported && Sse2.IsSupported)
4545
{
4646
return new CBCBlockMode(CreateECB(key), iv);
4747
}

src/CryptoBase/SymmetricCryptos/BlockCryptos/AES/Aes128CryptoX86.cs

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public Aes128CryptoX86(ReadOnlySpan<byte> key) : base(key)
1313
[MethodImpl(MethodImplOptions.AggressiveInlining)]
1414
private static Vector128<byte> KeyRound(Vector128<byte> key, [ConstantExpected] byte rcon)
1515
{
16-
Vector128<byte> t = Aes.KeygenAssist(key, rcon);
16+
Vector128<byte> t = AesX86.KeygenAssist(key, rcon);
1717
t = Sse2.Shuffle(t.AsUInt32(), 0b11_11_11_11).AsByte();
1818

1919
key ^= Sse2.ShiftLeftLogical128BitLane(key, 4);
@@ -37,15 +37,15 @@ private void Init(ReadOnlySpan<byte> key)
3737
_k9 = KeyRound(_k8, Rcon9);
3838
_k10 = KeyRound(_k9, Rcon10);
3939

40-
_k11 = Aes.InverseMixColumns(_k9);
41-
_k12 = Aes.InverseMixColumns(_k8);
42-
_k13 = Aes.InverseMixColumns(_k7);
43-
_k14 = Aes.InverseMixColumns(_k6);
44-
_k15 = Aes.InverseMixColumns(_k5);
45-
_k16 = Aes.InverseMixColumns(_k4);
46-
_k17 = Aes.InverseMixColumns(_k3);
47-
_k18 = Aes.InverseMixColumns(_k2);
48-
_k19 = Aes.InverseMixColumns(_k1);
40+
_k11 = AesX86.InverseMixColumns(_k9);
41+
_k12 = AesX86.InverseMixColumns(_k8);
42+
_k13 = AesX86.InverseMixColumns(_k7);
43+
_k14 = AesX86.InverseMixColumns(_k6);
44+
_k15 = AesX86.InverseMixColumns(_k5);
45+
_k16 = AesX86.InverseMixColumns(_k4);
46+
_k17 = AesX86.InverseMixColumns(_k3);
47+
_k18 = AesX86.InverseMixColumns(_k2);
48+
_k19 = AesX86.InverseMixColumns(_k1);
4949
}
5050

5151
public override void Encrypt(ReadOnlySpan<byte> source, Span<byte> destination)
@@ -55,16 +55,16 @@ public override void Encrypt(ReadOnlySpan<byte> source, Span<byte> destination)
5555
Vector128<byte> t = Vector128.Create(source);
5656

5757
t ^= _k0;
58-
t = Aes.Encrypt(t, _k1);
59-
t = Aes.Encrypt(t, _k2);
60-
t = Aes.Encrypt(t, _k3);
61-
t = Aes.Encrypt(t, _k4);
62-
t = Aes.Encrypt(t, _k5);
63-
t = Aes.Encrypt(t, _k6);
64-
t = Aes.Encrypt(t, _k7);
65-
t = Aes.Encrypt(t, _k8);
66-
t = Aes.Encrypt(t, _k9);
67-
t = Aes.EncryptLast(t, _k10);
58+
t = AesX86.Encrypt(t, _k1);
59+
t = AesX86.Encrypt(t, _k2);
60+
t = AesX86.Encrypt(t, _k3);
61+
t = AesX86.Encrypt(t, _k4);
62+
t = AesX86.Encrypt(t, _k5);
63+
t = AesX86.Encrypt(t, _k6);
64+
t = AesX86.Encrypt(t, _k7);
65+
t = AesX86.Encrypt(t, _k8);
66+
t = AesX86.Encrypt(t, _k9);
67+
t = AesX86.EncryptLast(t, _k10);
6868

6969
t.CopyTo(destination);
7070
}
@@ -76,16 +76,16 @@ public override void Decrypt(ReadOnlySpan<byte> source, Span<byte> destination)
7676
Vector128<byte> t = Vector128.Create(source);
7777

7878
t ^= _k10;
79-
t = Aes.Decrypt(t, _k11);
80-
t = Aes.Decrypt(t, _k12);
81-
t = Aes.Decrypt(t, _k13);
82-
t = Aes.Decrypt(t, _k14);
83-
t = Aes.Decrypt(t, _k15);
84-
t = Aes.Decrypt(t, _k16);
85-
t = Aes.Decrypt(t, _k17);
86-
t = Aes.Decrypt(t, _k18);
87-
t = Aes.Decrypt(t, _k19);
88-
t = Aes.DecryptLast(t, _k0);
79+
t = AesX86.Decrypt(t, _k11);
80+
t = AesX86.Decrypt(t, _k12);
81+
t = AesX86.Decrypt(t, _k13);
82+
t = AesX86.Decrypt(t, _k14);
83+
t = AesX86.Decrypt(t, _k15);
84+
t = AesX86.Decrypt(t, _k16);
85+
t = AesX86.Decrypt(t, _k17);
86+
t = AesX86.Decrypt(t, _k18);
87+
t = AesX86.Decrypt(t, _k19);
88+
t = AesX86.DecryptLast(t, _k0);
8989

9090
t.CopyTo(destination);
9191
}

src/CryptoBase/SymmetricCryptos/BlockCryptos/AES/Aes192CryptoX86.cs

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ private static void KeyRound(
3636
{
3737
a = t0;
3838
b = t1;
39-
Vector128<byte> t2 = Aes.KeygenAssist(t1, rcon0);
39+
Vector128<byte> t2 = AesX86.KeygenAssist(t1, rcon0);
4040
KeyRound(ref t0, ref t2, ref t1);
4141

4242
b = Sse2.Shuffle(b.AsDouble(), t0.AsDouble(), 0).AsByte();
4343
c = Sse2.Shuffle(t0.AsDouble(), t1.AsDouble(), 1).AsByte();
44-
t2 = Aes.KeygenAssist(t1, rcon1);
44+
t2 = AesX86.KeygenAssist(t1, rcon1);
4545
KeyRound(ref t0, ref t2, ref t1);
4646
}
4747

@@ -57,17 +57,17 @@ private void Init(ReadOnlySpan<byte> key)
5757
KeyRound(out _k9, out _k10, out _k11, ref t0, ref t1, Rcon7, Rcon8);
5858
_k12 = t0;
5959

60-
_k13 = Aes.InverseMixColumns(_k11);
61-
_k14 = Aes.InverseMixColumns(_k10);
62-
_k15 = Aes.InverseMixColumns(_k9);
63-
_k16 = Aes.InverseMixColumns(_k8);
64-
_k17 = Aes.InverseMixColumns(_k7);
65-
_k18 = Aes.InverseMixColumns(_k6);
66-
_k19 = Aes.InverseMixColumns(_k5);
67-
_k20 = Aes.InverseMixColumns(_k4);
68-
_k21 = Aes.InverseMixColumns(_k3);
69-
_k22 = Aes.InverseMixColumns(_k2);
70-
_k23 = Aes.InverseMixColumns(_k1);
60+
_k13 = AesX86.InverseMixColumns(_k11);
61+
_k14 = AesX86.InverseMixColumns(_k10);
62+
_k15 = AesX86.InverseMixColumns(_k9);
63+
_k16 = AesX86.InverseMixColumns(_k8);
64+
_k17 = AesX86.InverseMixColumns(_k7);
65+
_k18 = AesX86.InverseMixColumns(_k6);
66+
_k19 = AesX86.InverseMixColumns(_k5);
67+
_k20 = AesX86.InverseMixColumns(_k4);
68+
_k21 = AesX86.InverseMixColumns(_k3);
69+
_k22 = AesX86.InverseMixColumns(_k2);
70+
_k23 = AesX86.InverseMixColumns(_k1);
7171
}
7272

7373
public override void Encrypt(ReadOnlySpan<byte> source, Span<byte> destination)
@@ -77,18 +77,18 @@ public override void Encrypt(ReadOnlySpan<byte> source, Span<byte> destination)
7777
Vector128<byte> t = Vector128.Create(source);
7878

7979
t ^= _k0;
80-
t = Aes.Encrypt(t, _k1);
81-
t = Aes.Encrypt(t, _k2);
82-
t = Aes.Encrypt(t, _k3);
83-
t = Aes.Encrypt(t, _k4);
84-
t = Aes.Encrypt(t, _k5);
85-
t = Aes.Encrypt(t, _k6);
86-
t = Aes.Encrypt(t, _k7);
87-
t = Aes.Encrypt(t, _k8);
88-
t = Aes.Encrypt(t, _k9);
89-
t = Aes.Encrypt(t, _k10);
90-
t = Aes.Encrypt(t, _k11);
91-
t = Aes.EncryptLast(t, _k12);
80+
t = AesX86.Encrypt(t, _k1);
81+
t = AesX86.Encrypt(t, _k2);
82+
t = AesX86.Encrypt(t, _k3);
83+
t = AesX86.Encrypt(t, _k4);
84+
t = AesX86.Encrypt(t, _k5);
85+
t = AesX86.Encrypt(t, _k6);
86+
t = AesX86.Encrypt(t, _k7);
87+
t = AesX86.Encrypt(t, _k8);
88+
t = AesX86.Encrypt(t, _k9);
89+
t = AesX86.Encrypt(t, _k10);
90+
t = AesX86.Encrypt(t, _k11);
91+
t = AesX86.EncryptLast(t, _k12);
9292

9393
t.CopyTo(destination);
9494
}
@@ -100,18 +100,18 @@ public override void Decrypt(ReadOnlySpan<byte> source, Span<byte> destination)
100100
Vector128<byte> t = Vector128.Create(source);
101101

102102
t ^= _k12;
103-
t = Aes.Decrypt(t, _k13);
104-
t = Aes.Decrypt(t, _k14);
105-
t = Aes.Decrypt(t, _k15);
106-
t = Aes.Decrypt(t, _k16);
107-
t = Aes.Decrypt(t, _k17);
108-
t = Aes.Decrypt(t, _k18);
109-
t = Aes.Decrypt(t, _k19);
110-
t = Aes.Decrypt(t, _k20);
111-
t = Aes.Decrypt(t, _k21);
112-
t = Aes.Decrypt(t, _k22);
113-
t = Aes.Decrypt(t, _k23);
114-
t = Aes.DecryptLast(t, _k0);
103+
t = AesX86.Decrypt(t, _k13);
104+
t = AesX86.Decrypt(t, _k14);
105+
t = AesX86.Decrypt(t, _k15);
106+
t = AesX86.Decrypt(t, _k16);
107+
t = AesX86.Decrypt(t, _k17);
108+
t = AesX86.Decrypt(t, _k18);
109+
t = AesX86.Decrypt(t, _k19);
110+
t = AesX86.Decrypt(t, _k20);
111+
t = AesX86.Decrypt(t, _k21);
112+
t = AesX86.Decrypt(t, _k22);
113+
t = AesX86.Decrypt(t, _k23);
114+
t = AesX86.DecryptLast(t, _k0);
115115

116116
t.CopyTo(destination);
117117
}

src/CryptoBase/SymmetricCryptos/BlockCryptos/AES/Aes256CryptoX86.cs

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ private static void KeyRound1(ref Vector128<byte> a, ref Vector128<byte> b)
2828
[MethodImpl(MethodImplOptions.AggressiveInlining)]
2929
private static void KeyRound2(ref Vector128<byte> a, ref Vector128<byte> b)
3030
{
31-
Vector128<byte> t0 = Aes.KeygenAssist(a, Rcon0);
31+
Vector128<byte> t0 = AesX86.KeygenAssist(a, Rcon0);
3232
Vector128<byte> t1 = Sse2.Shuffle(t0.AsUInt32(), 0b10_10_10_10).AsByte();
3333

3434
t0 = Sse2.ShiftLeftLogical128BitLane(b, 4);
@@ -45,7 +45,7 @@ private static void KeyRound(out Vector128<byte> a, out Vector128<byte> b,
4545
ref Vector128<byte> t0, ref Vector128<byte> t1, [ConstantExpected] byte rcon)
4646
{
4747
a = t1;
48-
Vector128<byte> t2 = Aes.KeygenAssist(t1, rcon);
48+
Vector128<byte> t2 = AesX86.KeygenAssist(t1, rcon);
4949
KeyRound1(ref t0, ref t2);
5050
b = t0;
5151
KeyRound2(ref t0, ref t1);
@@ -67,23 +67,23 @@ private void Init(ReadOnlySpan<byte> key)
6767
KeyRound(out _k11, out _k12, ref t0, ref t1, Rcon6);
6868

6969
_k13 = t1;
70-
Vector128<byte> t2 = Aes.KeygenAssist(t1, Rcon7);
70+
Vector128<byte> t2 = AesX86.KeygenAssist(t1, Rcon7);
7171
KeyRound1(ref t0, ref t2);
7272
_k14 = t0;
7373

74-
_k15 = Aes.InverseMixColumns(_k13);
75-
_k16 = Aes.InverseMixColumns(_k12);
76-
_k17 = Aes.InverseMixColumns(_k11);
77-
_k18 = Aes.InverseMixColumns(_k10);
78-
_k19 = Aes.InverseMixColumns(_k9);
79-
_k20 = Aes.InverseMixColumns(_k8);
80-
_k21 = Aes.InverseMixColumns(_k7);
81-
_k22 = Aes.InverseMixColumns(_k6);
82-
_k23 = Aes.InverseMixColumns(_k5);
83-
_k24 = Aes.InverseMixColumns(_k4);
84-
_k25 = Aes.InverseMixColumns(_k3);
85-
_k26 = Aes.InverseMixColumns(_k2);
86-
_k27 = Aes.InverseMixColumns(_k1);
74+
_k15 = AesX86.InverseMixColumns(_k13);
75+
_k16 = AesX86.InverseMixColumns(_k12);
76+
_k17 = AesX86.InverseMixColumns(_k11);
77+
_k18 = AesX86.InverseMixColumns(_k10);
78+
_k19 = AesX86.InverseMixColumns(_k9);
79+
_k20 = AesX86.InverseMixColumns(_k8);
80+
_k21 = AesX86.InverseMixColumns(_k7);
81+
_k22 = AesX86.InverseMixColumns(_k6);
82+
_k23 = AesX86.InverseMixColumns(_k5);
83+
_k24 = AesX86.InverseMixColumns(_k4);
84+
_k25 = AesX86.InverseMixColumns(_k3);
85+
_k26 = AesX86.InverseMixColumns(_k2);
86+
_k27 = AesX86.InverseMixColumns(_k1);
8787
}
8888

8989
public override void Encrypt(ReadOnlySpan<byte> source, Span<byte> destination)
@@ -93,20 +93,20 @@ public override void Encrypt(ReadOnlySpan<byte> source, Span<byte> destination)
9393
Vector128<byte> t = Vector128.Create(source);
9494

9595
t ^= _k0;
96-
t = Aes.Encrypt(t, _k1);
97-
t = Aes.Encrypt(t, _k2);
98-
t = Aes.Encrypt(t, _k3);
99-
t = Aes.Encrypt(t, _k4);
100-
t = Aes.Encrypt(t, _k5);
101-
t = Aes.Encrypt(t, _k6);
102-
t = Aes.Encrypt(t, _k7);
103-
t = Aes.Encrypt(t, _k8);
104-
t = Aes.Encrypt(t, _k9);
105-
t = Aes.Encrypt(t, _k10);
106-
t = Aes.Encrypt(t, _k11);
107-
t = Aes.Encrypt(t, _k12);
108-
t = Aes.Encrypt(t, _k13);
109-
t = Aes.EncryptLast(t, _k14);
96+
t = AesX86.Encrypt(t, _k1);
97+
t = AesX86.Encrypt(t, _k2);
98+
t = AesX86.Encrypt(t, _k3);
99+
t = AesX86.Encrypt(t, _k4);
100+
t = AesX86.Encrypt(t, _k5);
101+
t = AesX86.Encrypt(t, _k6);
102+
t = AesX86.Encrypt(t, _k7);
103+
t = AesX86.Encrypt(t, _k8);
104+
t = AesX86.Encrypt(t, _k9);
105+
t = AesX86.Encrypt(t, _k10);
106+
t = AesX86.Encrypt(t, _k11);
107+
t = AesX86.Encrypt(t, _k12);
108+
t = AesX86.Encrypt(t, _k13);
109+
t = AesX86.EncryptLast(t, _k14);
110110

111111
t.CopyTo(destination);
112112
}
@@ -118,20 +118,20 @@ public override void Decrypt(ReadOnlySpan<byte> source, Span<byte> destination)
118118
Vector128<byte> t = Vector128.Create(source);
119119

120120
t ^= _k14;
121-
t = Aes.Decrypt(t, _k15);
122-
t = Aes.Decrypt(t, _k16);
123-
t = Aes.Decrypt(t, _k17);
124-
t = Aes.Decrypt(t, _k18);
125-
t = Aes.Decrypt(t, _k19);
126-
t = Aes.Decrypt(t, _k20);
127-
t = Aes.Decrypt(t, _k21);
128-
t = Aes.Decrypt(t, _k22);
129-
t = Aes.Decrypt(t, _k23);
130-
t = Aes.Decrypt(t, _k24);
131-
t = Aes.Decrypt(t, _k25);
132-
t = Aes.Decrypt(t, _k26);
133-
t = Aes.Decrypt(t, _k27);
134-
t = Aes.DecryptLast(t, _k0);
121+
t = AesX86.Decrypt(t, _k15);
122+
t = AesX86.Decrypt(t, _k16);
123+
t = AesX86.Decrypt(t, _k17);
124+
t = AesX86.Decrypt(t, _k18);
125+
t = AesX86.Decrypt(t, _k19);
126+
t = AesX86.Decrypt(t, _k20);
127+
t = AesX86.Decrypt(t, _k21);
128+
t = AesX86.Decrypt(t, _k22);
129+
t = AesX86.Decrypt(t, _k23);
130+
t = AesX86.Decrypt(t, _k24);
131+
t = AesX86.Decrypt(t, _k25);
132+
t = AesX86.Decrypt(t, _k26);
133+
t = AesX86.Decrypt(t, _k27);
134+
t = AesX86.DecryptLast(t, _k0);
135135

136136
t.CopyTo(destination);
137137
}

src/CryptoBase/SymmetricCryptos/BlockCryptos/SM4/SM4CryptoBlock16X86.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ namespace CryptoBase.SymmetricCryptos.BlockCryptos.SM4;
22

33
public class SM4CryptoBlock16X86(ReadOnlySpan<byte> key) : SM4Crypto(key)
44
{
5-
public static bool IsSupported => Aes.IsSupported && Avx2.IsSupported;
5+
public static bool IsSupported => AesX86.IsSupported && Avx2.IsSupported;
66

77
public override int BlockSize => 256;
88

src/CryptoBase/SymmetricCryptos/BlockCryptos/SM4/SM4CryptoBlock8X86.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ namespace CryptoBase.SymmetricCryptos.BlockCryptos.SM4;
22

33
public class SM4CryptoBlock8X86(ReadOnlySpan<byte> key) : SM4Crypto(key)
44
{
5-
public static bool IsSupported => Aes.IsSupported && Sse2.IsSupported && Ssse3.IsSupported;
5+
public static bool IsSupported => AesX86.IsSupported && Sse2.IsSupported && Ssse3.IsSupported;
66

77
public override int BlockSize => 128;
88

src/CryptoBase/SymmetricCryptos/BlockCryptos/SM4/SM4CryptoX86.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ namespace CryptoBase.SymmetricCryptos.BlockCryptos.SM4;
22

33
public class SM4CryptoX86(ReadOnlySpan<byte> key) : SM4Crypto(key)
44
{
5-
public static bool IsSupported => Aes.IsSupported && Sse2.IsSupported && Ssse3.IsSupported;
5+
public static bool IsSupported => AesX86.IsSupported && Sse2.IsSupported && Ssse3.IsSupported;
66

77
public override int BlockSize => 64;
88

0 commit comments

Comments
 (0)