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

◆ Decrypt()

static unsafe void System.Security.Cryptography.AeadCommon.Decrypt ( SafeKeyHandle keyHandle,
ReadOnlySpan< byte > nonce,
ReadOnlySpan< byte > associatedData,
ReadOnlySpan< byte > ciphertext,
ReadOnlySpan< byte > tag,
Span< byte > plaintext,
bool clearPlaintextOnFailure )
inlinestatic

Definition at line 61 of file AeadCommon.cs.

62 {
63 fixed (byte* pbOutput = &GetNonNullPinnableReference(plaintext))
64 {
65 fixed (byte* pbNonce = &GetNonNullPinnableReference(nonce))
66 {
67 fixed (byte* pbInput = &GetNonNullPinnableReference(ciphertext))
68 {
69 fixed (byte* pbTag = &GetNonNullPinnableReference(tag))
70 {
71 fixed (byte* pbAuthData = &GetNonNullPinnableReference(associatedData))
72 {
73 global::Interop.BCrypt.BCRYPT_AUTHENTICATED_CIPHER_MODE_INFO bCRYPT_AUTHENTICATED_CIPHER_MODE_INFO = global::Interop.BCrypt.BCRYPT_AUTHENTICATED_CIPHER_MODE_INFO.Create();
74 bCRYPT_AUTHENTICATED_CIPHER_MODE_INFO.pbNonce = pbNonce;
75 bCRYPT_AUTHENTICATED_CIPHER_MODE_INFO.cbNonce = nonce.Length;
76 bCRYPT_AUTHENTICATED_CIPHER_MODE_INFO.pbTag = pbTag;
77 bCRYPT_AUTHENTICATED_CIPHER_MODE_INFO.cbTag = tag.Length;
78 bCRYPT_AUTHENTICATED_CIPHER_MODE_INFO.pbAuthData = pbAuthData;
79 bCRYPT_AUTHENTICATED_CIPHER_MODE_INFO.cbAuthData = associatedData.Length;
80 int cbResult;
81 global::Interop.BCrypt.NTSTATUS nTSTATUS = global::Interop.BCrypt.BCryptDecrypt(keyHandle, pbInput, ciphertext.Length, new IntPtr(&bCRYPT_AUTHENTICATED_CIPHER_MODE_INFO), null, 0, pbOutput, plaintext.Length, out cbResult, 0);
82 switch (nTSTATUS)
83 {
84 case global::Interop.BCrypt.NTSTATUS.STATUS_SUCCESS:
85 break;
86 case global::Interop.BCrypt.NTSTATUS.STATUS_AUTH_TAG_MISMATCH:
87 if (clearPlaintextOnFailure)
88 {
89 CryptographicOperations.ZeroMemory(plaintext);
90 }
91 throw new CryptographicException(System.SR.Cryptography_AuthTagMismatch);
92 default:
93 throw global::Interop.BCrypt.CreateCryptographicException(nTSTATUS);
94 }
95 }
96 }
97 }
98 }
99 }
100 }
static string Cryptography_AuthTagMismatch
Definition SR.cs:44
Definition SR.cs:7
static unsafe ref readonly byte GetNonNullPinnableReference(ReadOnlySpan< byte > buffer)
int Length
Definition Span.cs:70

References System.SR.Cryptography_AuthTagMismatch, System.Security.Cryptography.AeadCommon.GetNonNullPinnableReference(), System.ReadOnlySpan< T >.Length, System.Span< T >.Length, and System.Security.Cryptography.CryptographicOperations.ZeroMemory().

Referenced by System.Security.Cryptography.AesCcm.DecryptCore(), System.Security.Cryptography.AesGcm.DecryptCore(), and System.Security.Cryptography.ChaCha20Poly1305.DecryptCore().