Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BCRYPT_HANDLE is missing and should be convertible #1011

Closed
kennykerr opened this issue Jul 26, 2022 · 1 comment
Closed

BCRYPT_HANDLE is missing and should be convertible #1011

kennykerr opened this issue Jul 26, 2022 · 1 comment
Assignees
Labels
enhancement New feature or request usability Touch-up to improve the user experience for a language projection

Comments

@kennykerr
Copy link
Contributor

Original declarations for BCRYPT handles:

typedef PVOID BCRYPT_HANDLE;
typedef PVOID BCRYPT_ALG_HANDLE;
typedef PVOID BCRYPT_KEY_HANDLE;
typedef PVOID BCRYPT_HASH_HANDLE;
typedef PVOID BCRYPT_SECRET_HANDLE;

The various handles are all convertible to BCRYPT_HANDLE so that they can all be used with functions like BCryptGetProperty and BCryptSetProperty.

Unfortunately, the AlsoUsableFor is not present on these handles and BCRYPT_HANDLE is not defined at all. BCryptGetProperty for examples is declared as follows:

_Must_inspect_result_
NTSTATUS
WINAPI
BCryptGetProperty(
    _In_                                        BCRYPT_HANDLE   hObject,
    _In_                                        LPCWSTR pszProperty,
    _Out_writes_bytes_to_opt_(cbOutput, *pcbResult) PUCHAR   pbOutput,
    _In_                                        ULONG   cbOutput,
    _Out_                                       ULONG   *pcbResult,
    _In_                                        ULONG   dwFlags);

But the metadata just uses void*:

[DllImport("bcrypt", ExactSpelling = true, PreserveSig = false)]
[SupportedOSPlatform("windows6.0.6000")]
public unsafe static extern NTSTATUS BCryptGetProperty([In] void* hObject, [In][Const] PWSTR pszProperty, [Optional][Out][MemorySize(BytesParamIndex = 3)] byte* pbOutput, [In] uint cbOutput, [Out] uint* pcbResult, [In] uint dwFlags);

This makes using these APIs very difficult as the handles don't even have the same underlying type (IntPtr vs void*).

@riverar riverar added enhancement New feature or request usability Touch-up to improve the user experience for a language projection labels Jul 28, 2022
@mikebattista mikebattista self-assigned this Aug 1, 2022
@mikebattista
Copy link
Contributor

Windows.Win32.Security.Cryptography.BCRYPT_ALG_HANDLE : [RAIIFree(BCryptCloseAlgorithmProvider),InvalidHandleValue(0),NativeTypedef] => [RAIIFree(BCryptCloseAlgorithmProvider),AlsoUsableFor(BCRYPT_HANDLE),InvalidHandleValue(0),NativeTypedef]
Windows.Win32.Security.Cryptography.BCRYPT_KEY_HANDLE : [RAIIFree(BCryptDestroyKey),InvalidHandleValue(0),NativeTypedef] => [RAIIFree(BCryptDestroyKey),AlsoUsableFor(BCRYPT_HANDLE),InvalidHandleValue(0),NativeTypedef]
Windows.Win32.Security.Cryptography.BCRYPT_HASH_HANDLE not found in 1st winmd
Windows.Win32.Security.Cryptography.BCRYPT_SECRET_HANDLE not found in 1st winmd
Windows.Win32.Security.Cryptography.BCRYPT_HANDLE not found in 1st winmd
Windows.Win32.Security.Cryptography.Apis.BCryptGetProperty : hObject...Void* => BCRYPT_HANDLE
Windows.Win32.Security.Cryptography.Apis.BCryptSetProperty : hObject...Void* => BCRYPT_HANDLE
Windows.Win32.Security.Cryptography.Apis.BCryptSetProperty : hObject : [In,Out] => [In]
Windows.Win32.Security.Cryptography.Apis.BCryptDestroySecret : hSecret...Void* => BCRYPT_SECRET_HANDLE
Windows.Win32.Security.Cryptography.Apis.BCryptDestroySecret : hSecret : [In,Out] => [In]
Windows.Win32.Security.Cryptography.Apis.BCryptSecretAgreement : phAgreedSecret...Void** => BCRYPT_SECRET_HANDLE*
Windows.Win32.Security.Cryptography.Apis.BCryptDeriveKey : hSharedSecret...Void* => BCRYPT_SECRET_HANDLE
Windows.Win32.Security.Cryptography.Apis.BCryptCreateHash : phHash...Void** => BCRYPT_HASH_HANDLE*
Windows.Win32.Security.Cryptography.Apis.BCryptHashData : hHash...Void* => BCRYPT_HASH_HANDLE
Windows.Win32.Security.Cryptography.Apis.BCryptHashData : hHash : [In,Out] => [In]
Windows.Win32.Security.Cryptography.Apis.BCryptFinishHash : hHash...Void* => BCRYPT_HASH_HANDLE
Windows.Win32.Security.Cryptography.Apis.BCryptFinishHash : hHash : [In,Out] => [In]
Windows.Win32.Security.Cryptography.Apis.BCryptCreateMultiHash : phHash...Void** => BCRYPT_HASH_HANDLE*
Windows.Win32.Security.Cryptography.Apis.BCryptProcessMultiOperations : hObject...Void* => BCRYPT_HANDLE
Windows.Win32.Security.Cryptography.Apis.BCryptProcessMultiOperations : hObject : [In,Out] => [In]
Windows.Win32.Security.Cryptography.Apis.BCryptDuplicateHash : hHash...Void* => BCRYPT_HASH_HANDLE
Windows.Win32.Security.Cryptography.Apis.BCryptDuplicateHash : phNewHash...Void** => BCRYPT_HASH_HANDLE*
Windows.Win32.Security.Cryptography.Apis.BCryptDestroyHash : hHash...Void* => BCRYPT_HASH_HANDLE
Windows.Win32.Security.Cryptography.Apis.BCryptDestroyHash : hHash : [In,Out] => [In]
Windows.Win32.Security.Cryptography.Apis.BCryptDeriveKeyCapi : hHash...Void* => BCRYPT_HASH_HANDLE

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request usability Touch-up to improve the user experience for a language projection
Projects
None yet
Development

No branches or pull requests

3 participants