28 {
32 int cbSecret;
34 {
36 readOnlySpan = span2;
37 cbSecret = 0;
39 }
40 else if (password.
Length <= hashBlockSize)
41 {
42 readOnlySpan = password;
43 cbSecret = password.
Length;
45 }
46 else
47 {
49 int num = hashAlgorithmName switch
50 {
56 };
57 span = destination2.
Slice(0, num);
58 readOnlySpan = span;
59 cbSecret = num;
60 }
61 global::Interop.BCrypt.NTSTATUS nTSTATUS;
63 if (global::Interop.BCrypt.PseudoHandlesSupported)
64 {
65 fixed (byte* pbSecret = readOnlySpan)
66 {
67 nTSTATUS = global::Interop.BCrypt.BCryptGenerateSymmetricKey(817u, out phKey,
IntPtr.
Zero, 0, pbSecret, cbSecret, 0u);
68 }
69 }
70 else
71 {
73 {
75 global::Interop.BCrypt.NTSTATUS nTSTATUS2 = global::Interop.BCrypt.BCryptOpenAlgorithmProvider(out phAlgorithm, "PBKDF2", null, global::Interop.BCrypt.BCryptOpenAlgorithmProviderFlags.None);
76 if (nTSTATUS2 != 0)
77 {
80 throw global::Interop.BCrypt.CreateCryptographicException(nTSTATUS2);
81 }
83 }
84 fixed (byte* pbSecret2 = readOnlySpan)
85 {
87 }
88 }
90 if (nTSTATUS != 0)
91 {
93 throw global::Interop.BCrypt.CreateCryptographicException(nTSTATUS);
94 }
95 ulong num2 = (ulong)iterations;
96 using (phKey)
97 {
98 fixed (char* ptr2 = hashAlgorithmName)
99 {
100 fixed (byte* ptr = salt)
101 {
103 {
104 Span<global::Interop.BCrypt.BCryptBuffer> span3 = stackalloc global::Interop.BCrypt.BCryptBuffer[3];
105 span3[0].BufferType = global::Interop.BCrypt.CngBufferDescriptors.KDF_ITERATION_COUNT;
106 span3[0].pvBuffer = (
IntPtr)(&num2);
107 span3[0].cbBuffer = 8;
108 span3[1].BufferType = global::Interop.BCrypt.CngBufferDescriptors.KDF_SALT;
109 span3[1].pvBuffer = (
IntPtr)ptr;
110 span3[1].cbBuffer = salt.
Length;
111 span3[2].BufferType = global::Interop.BCrypt.CngBufferDescriptors.KDF_HASH_ALGORITHM;
112 span3[2].pvBuffer = (
IntPtr)ptr2;
113 span3[2].cbBuffer = checked((hashAlgorithmName.Length + 1) * 2);
114 fixed (global::Interop.BCrypt.BCryptBuffer* ptr3 = span3)
115 {
116 Unsafe.SkipInit(out global::Interop.BCrypt.BCryptBufferDesc bCryptBufferDesc);
117 bCryptBufferDesc.ulVersion = 0;
118 bCryptBufferDesc.cBuffers = span3.Length;
119 bCryptBufferDesc.pBuffers = (
IntPtr)ptr3;
120 uint pcbResult;
121 global::Interop.BCrypt.NTSTATUS nTSTATUS3 = global::Interop.BCrypt.BCryptKeyDerivation(phKey, &bCryptBufferDesc, pbDerivedKey,
destination.Length, out pcbResult, 0);
122 if (nTSTATUS3 != 0)
123 {
124 throw global::Interop.BCrypt.CreateCryptographicException(nTSTATUS3);
125 }
127 {
129 }
130 }
131 }
132 }
133 }
134 }
135 }
static SafeBCryptAlgorithmHandle s_pbkdf2AlgorithmHandle
static int GetHashBlockSize(string hashAlgorithmName)
static void ZeroMemory(Span< byte > buffer)
static byte[] HashData(byte[] source)
static byte[] HashData(byte[] source)
static byte[] HashData(byte[] source)
static byte[] HashData(byte[] source)
static int CompareExchange(ref int location1, int value, int comparand)
static readonly IntPtr Zero
Span< T > Slice(int start)