Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
BCryptAeadHandleCache.cs
Go to the documentation of this file.
1using System;
4
6
7internal static class BCryptAeadHandleCache
8{
10
12
14
15 internal static SafeAlgorithmHandle AesCcm => GetCachedAlgorithmHandle(ref s_aesCcm, "AES", "ChainingModeCCM");
16
17 internal static SafeAlgorithmHandle AesGcm => GetCachedAlgorithmHandle(ref s_aesGcm, "AES", "ChainingModeGCM");
18
19 internal static bool IsChaCha20Poly1305Supported { get; } = OperatingSystem.IsWindowsVersionAtLeast(10, 0, 20142);
20
21
23
24 private static SafeAlgorithmHandle GetCachedAlgorithmHandle(ref SafeAlgorithmHandle handle, string algId, string chainingMode = null)
25 {
26 SafeAlgorithmHandle safeAlgorithmHandle = Volatile.Read(ref handle);
27 if (safeAlgorithmHandle != null)
28 {
29 return safeAlgorithmHandle;
30 }
32 if (chainingMode != null)
33 {
34 safeAlgorithmHandle2.SetCipherMode(chainingMode);
35 }
36 safeAlgorithmHandle = Interlocked.CompareExchange(ref handle, safeAlgorithmHandle2, null);
37 if (safeAlgorithmHandle != null)
38 {
39 safeAlgorithmHandle2.Dispose();
40 return safeAlgorithmHandle;
41 }
42 return safeAlgorithmHandle2;
43 }
44}
static SafeAlgorithmHandle GetCachedAlgorithmHandle(ref SafeAlgorithmHandle handle, string algId, string chainingMode=null)
static SafeAlgorithmHandle BCryptOpenAlgorithmProvider(string pszAlgId, string pszImplementation, OpenAlgorithmProviderFlags dwFlags)
Definition Cng.cs:34
static bool IsWindowsVersionAtLeast(int major, int minor=0, int build=0, int revision=0)
static int CompareExchange(ref int location1, int value, int comparand)
static bool Read(ref bool location)
Definition Volatile.cs:67