Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ PadOaep() [2/2]

void System.Security.Cryptography.RsaPaddingProcessor.PadOaep ( ReadOnlySpan< byte > source,
Span< byte > destination )
inlinepackage

Definition at line 115 of file RsaPaddingProcessor.cs.

116 {
117 byte[] array = null;
118 Span<byte> span = Span<byte>.Empty;
119 try
120 {
121 int num = checked(destination.Length - _hLen - _hLen - 2);
122 if (source.Length > num)
123 {
124 throw new CryptographicException(System.SR.Format(System.SR.Cryptography_Encryption_MessageTooLong, num));
125 }
126 Span<byte> span2 = destination.Slice(1, _hLen);
127 Span<byte> span3 = destination.Slice(1 + _hLen);
128 using IncrementalHash incrementalHash = IncrementalHash.CreateHash(_hashAlgorithmName);
129 Span<byte> destination2 = span3.Slice(0, _hLen);
130 Span<byte> destination3 = span3.Slice(span3.Length - source.Length);
131 Span<byte> span4 = span3.Slice(_hLen, span3.Length - _hLen - 1 - destination3.Length);
132 Span<byte> span5 = span3.Slice(_hLen + span4.Length, 1);
133 if (!incrementalHash.TryGetHashAndReset(destination2, out var bytesWritten) || bytesWritten != _hLen)
134 {
135 throw new CryptographicException();
136 }
137 span4.Clear();
138 span5[0] = 1;
139 source.CopyTo(destination3);
140 RandomNumberGenerator.Fill(span2);
142 span = new Span<byte>(array, 0, span3.Length);
143 Mgf1(incrementalHash, span2, span);
144 Xor(span3, span);
145 Span<byte> span6 = stackalloc byte[_hLen];
146 Mgf1(incrementalHash, span3, span6);
147 Xor(span2, span6);
148 destination[0] = 0;
149 }
150 catch (Exception ex) when (!(ex is CryptographicException))
151 {
152 throw new CryptographicException();
153 }
154 finally
155 {
156 if (array != null)
157 {
158 CryptographicOperations.ZeroMemory(span);
160 }
161 }
162 }
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string Cryptography_Encryption_MessageTooLong
Definition SR.cs:52
Definition SR.cs:7
static void Return(byte[] array, int clearSize=-1)
Definition CryptoPool.cs:12
static byte[] Rent(int minimumLength)
Definition CryptoPool.cs:7
void Mgf1(IncrementalHash hasher, ReadOnlySpan< byte > mgfSeed, Span< byte > mask)
static void Xor(Span< byte > a, ReadOnlySpan< byte > b)

References System.array, System.Span< T >.Clear(), System.Span< T >.CopyTo(), System.Security.Cryptography.IncrementalHash.CreateHash(), System.SR.Cryptography_Encryption_MessageTooLong, System.destination, System.Span< T >.Empty, System.Security.Cryptography.RandomNumberGenerator.Fill(), System.SR.Format(), System.Span< T >.Length, System.Security.Cryptography.CryptoPool.Rent(), System.Security.Cryptography.CryptoPool.Return(), System.Span< T >.Slice(), System.source, and System.Security.Cryptography.CryptographicOperations.ZeroMemory().