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

◆ DeriveKeyMaterial() [2/4]

static unsafe byte[] Interop.NCrypt.DeriveKeyMaterial ( SafeNCryptSecretHandle secretAgreement,
string kdf,
ReadOnlySpan< NCryptBuffer > parameters,
SecretAgreementFlags flags )
inlinestaticprivate

Definition at line 755 of file Interop.cs.

756 {
757 fixed (NCryptBuffer* value = &MemoryMarshal.GetReference(parameters))
758 {
759 NCryptBufferDesc pParameterList = default(NCryptBufferDesc);
760 pParameterList.ulVersion = 0;
761 pParameterList.cBuffers = parameters.Length;
762 pParameterList.pBuffers = new IntPtr(value);
763 ErrorCode errorCode = NCryptDeriveKey(secretAgreement, kdf, ref pParameterList, null, 0, out var pcbResult, flags);
764 if (errorCode != 0 && errorCode != ErrorCode.NTE_BUFFER_TOO_SMALL)
765 {
766 throw errorCode.ToCryptographicException();
767 }
768 byte[] array = new byte[pcbResult];
769 errorCode = NCryptDeriveKey(secretAgreement, kdf, ref pParameterList, array, array.Length, out pcbResult, flags);
770 if (errorCode != 0)
771 {
772 throw errorCode.ToCryptographicException();
773 }
774 Array.Resize(ref array, Math.Min(pcbResult, array.Length));
775 return array;
776 }
777 }
static ErrorCode NCryptDeriveKey(SafeNCryptSecretHandle hSharedSecret, string pwszKDF, [In] ref NCryptBufferDesc pParameterList, [Out][MarshalAs(UnmanagedType.LPArray)] byte[] pbDerivedKey, int cbDerivedKey, out int pcbResult, SecretAgreementFlags dwFlags)
static byte Min(byte val1, byte val2)
Definition Math.cs:912

References System.array, System.ReadOnlySpan< T >.Length, System.Math.Min(), Interop.NCrypt.NCryptDeriveKey(), and System.value.