40 else if (password.
Length <= hashBlockSize)
42 readOnlySpan = password;
43 cbSecret = password.
Length;
49 int num = hashAlgorithmName
switch
57 span = destination2.
Slice(0, num);
61 global::Interop.BCrypt.NTSTATUS nTSTATUS;
63 if (global::Interop.BCrypt.PseudoHandlesSupported)
65 fixed (
byte* pbSecret = readOnlySpan)
67 nTSTATUS = global::Interop.BCrypt.BCryptGenerateSymmetricKey(817u, out phKey,
IntPtr.
Zero, 0, pbSecret, cbSecret, 0u);
75 global::Interop.BCrypt.NTSTATUS nTSTATUS2 = global::Interop.BCrypt.BCryptOpenAlgorithmProvider(out phAlgorithm,
"PBKDF2",
null, global::Interop.BCrypt.BCryptOpenAlgorithmProviderFlags.None);
80 throw global::Interop.BCrypt.CreateCryptographicException(nTSTATUS2);
84 fixed (
byte* pbSecret2 = readOnlySpan)
93 throw global::Interop.BCrypt.CreateCryptographicException(nTSTATUS);
95 ulong num2 = (ulong)iterations;
98 fixed (
char* ptr2 = hashAlgorithmName)
100 fixed (
byte* ptr = salt)
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)
116 Unsafe.SkipInit(out global::Interop.BCrypt.BCryptBufferDesc bCryptBufferDesc);
117 bCryptBufferDesc.ulVersion = 0;
118 bCryptBufferDesc.cBuffers = span3.Length;
119 bCryptBufferDesc.pBuffers = (
IntPtr)ptr3;
121 global::Interop.BCrypt.NTSTATUS nTSTATUS3 = global::Interop.BCrypt.BCryptKeyDerivation(phKey, &bCryptBufferDesc, pbDerivedKey,
destination.Length, out pcbResult, 0);
124 throw global::Interop.BCrypt.CreateCryptographicException(nTSTATUS3);
140 SafeBCryptAlgorithmHandle cachedBCryptAlgorithmHandle = global::Interop.BCrypt.BCryptAlgorithmCache.GetCachedBCryptAlgorithmHandle(hashAlgorithmName, global::Interop.BCrypt.BCryptOpenAlgorithmProviderFlags.BCRYPT_ALG_HANDLE_HMAC_FLAG, out hashSizeInBytes);
141 fixed (
byte* pbPassword = password)
143 fixed (
byte* pbSalt = salt)
147 global::Interop.BCrypt.NTSTATUS nTSTATUS = global::Interop.BCrypt.BCryptDeriveKeyPBKDF2(cachedBCryptAlgorithmHandle, pbPassword, password.
Length, pbSalt, salt.
Length, (ulong)iterations, pbDerivedKey,
destination.Length, 0u);
150 throw global::Interop.BCrypt.CreateCryptographicException(nTSTATUS);