-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Improve allocations in NegotiateStreamPal #71280
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
Conversation
|
Tagging subscribers to this area: @dotnet/ncl, @vcsjones Issue DetailsThis reduces allocations during NTLM/Negotiate authentication by reusing an existing buffer. It saves about 3Kb of allocated memory for a typical NTLM authentication exchange. It also converts a couple of the internals to use Span/Memory. This would be a prerequisite for offering public API for encryption/decryption on
|
|
While refactoring the code I found a couple of bugs that I plan to fix in subsequent PRs:
|
52b3db7 to
1a2892e
Compare
src/libraries/System.Net.Security/src/System/Net/Security/ReadWriteAdapter.cs
Outdated
Show resolved
Hide resolved
…ead of explicit offset/count
Remove indirect Encrypt/Decrypt layer from SSPIWrapper, it is unnecessarily cumbersome to use and SslStreamPal already migrated away from it.
1a2892e to
3b4aff6
Compare
| out Status minorStatus, | ||
| SafeGssContextHandle? contextHandle, | ||
| byte[] inputBytes, | ||
| byte* inputBytes, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need offset any more? It feels like if we pass pointer we can just do count.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't. Unfortunately, dotnet/sqlclient uses the native APIs, so I didn't feel confident in changing it. I am quite sure they don't use this particular API though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't the pointer change by itself be breaking for them?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't change the native code side, the prototype remains unchanged there. They basically copied the managed side of the interop. (We cannot change the signature, add parameters, remove parameters, or change their types. We can change how they are marshalled on the C# side though.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc: @JRahnama just in case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I cross-checked with the SqlClient source and this particular native method is not referenced so we can remove the offset parameter. I will do that in a follow-up PR (#71373) since I need to update the native interop there anyway.
wfurt
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice. Thanks @filipnavara
Co-authored-by: Stephen Toub <[email protected]>
This reduces allocations during NTLM/Negotiate authentication by reusing an existing buffer. It saves about 3Kb of allocated memory for a typical NTLM authentication exchange on Windows.
It also converts a couple of the internals to use Span/Memory. This would be a prerequisite for offering public API for encryption/decryption on
NegotiateAuthenticationclass. As a side effect, it removes a big chunk of cumbersome interop marshaling on Windows.