-
Notifications
You must be signed in to change notification settings - Fork 122
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
Update BCryptSetProperty to optionally take pbinput #2034
Comments
From the header: // - Finally the key (or secret) is finalized via the
// BCRYPT_HKDF_PRK_AND_FINALIZE property. In this case the input property
// must be NULL since the PRK was already passed in. Yes, I think we should be able to make this work - I'll see what I can do. |
That's a bug, albeit not in the The bcrypt.h SDK header file declares _Must_inspect_result_
NTSTATUS
WINAPI
BCryptSetProperty(
_Inout_ BCRYPT_HANDLE hObject,
_In_z_ LPCWSTR pszProperty,
_In_reads_bytes_(cbInput) PUCHAR pbInput,
_In_ ULONG cbInput,
_In_ ULONG dwFlags); The win32metadata tooling faithfully transforms this into public static extern NTSTATUS BCryptSetProperty(
[In, Out] BCRYPT_HANDLE hObject,
[Const, In] PWSTR pszProperty,
[MemorySize(BytesParamIndex = 3), In] byte* pbInput,
[In] uint cbInput,
[In] uint dwFlags); This gets picked up by the The interesting bit here is the The bug could be either one of:
Properly fixing this would necessitate a change to the header file (and possibly the implementation) of the BCrypt library. That'll take a hot minute to trickle down. What you can do in the meantime is taking advantage of the link!("bcrypt.dll" "system" fn BCryptSetProperty(hobject : BCRYPT_HANDLE, pszproperty : windows_core::PCWSTR, pbinput : *const u8, cbinput : u32, dwflags : u32) -> super::super::Foundation:: NTSTATUS); |
Agree, looks like a bcrypt bug; makes you wonder how they satisfied the SAL tests. We can take this to win32metadata and get the |
Checking an |
Please, don't. This establishes a secondary API surface with unverified assumptions. Do have the BCrypt owners fix their published API contract, whatever time/effort this takes. Under the assumption that the implementation is attributed as There's a place and time to be pragmatic. Crypto isn't that. |
Does it? The above The counterpart |
The contract is "documented" in a source code comment. Source code comments are (generally) ignored by static code analysis tools. This is in stark contrast to SAL annotations that are tool-verified at the call site and the implementation. I'd very much appreciate if the |
@mikebattista can you chase down the API owner and see if they'd like to update the SAL annotation? |
Suggestion
Regarding https://microsoft.github.io/windows-docs-rs/doc/windows/Win32/Security/Cryptography/fn.BCryptSetProperty.html, for a HKDF operation I needed to set a property to a null pointer (I tried setting an empty array but it caused a CNG error).
I ended up just not using windows-rs for the one call in my crate that needed to set a null pointer: https://github.com/tofay/rustls-cng-crypto/blob/2f1de485a6856a8db4ccadb073e5ec3cf872d04f/src/hkdf.rs#L97.
The text was updated successfully, but these errors were encountered: