-
Notifications
You must be signed in to change notification settings - Fork 4.6k
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
Incremental Hash, allowing to continue to hash #1968
Comments
I'd honestly go with a Clone or Duplicate approach. Usability is a little more clear with a dedicated method to clone the internal state than the AndContinue proposal IMO. |
I am fine with that. Have updated to reflect it |
This came up previously and my initial thought was If the "Partial" (or "Current") seems self-identifying enough then we could do both; but if we want to only do one then DuplicateHash is probably the one to do (because of generalization). And, as noted, DuplicateHash might get renamed to Clone in API review, even though that word has a certain amount of smell to it 😄. |
So my initial API was either of those, but actually I like you idea of both. I 100% agree that clone is very overloaded in meaning already and I wouldn't like it as much. How about I put back the (Try)GetCurrentHash as well (we can always negotiate down to only the duplicate). |
namespace System.Security.Cryptography
{
public partial class IncrementalHash
{
public bool TryGetCurrentHash(Span<byte> destination, out int bytesWritten);
public int GetCurrentHash(Span<byte> destination);
// public bool TryGetHashAndReset(Span<byte> destination, out int bytesWritten);
public int GetHashAndReset(Span<byte> destination);
public byte[] GetCurrentHash();
public int HashLengthInBytes { get; }
}
} |
@terrajobst It appears that some API changes are needed on the public type HashProvider. They are in the PR public virtual int GetCurrentHash(Span<byte> destination);
public virtual bool TryGetCurrentHash(Span<byte> destination, out int bytesWritten); |
|
In a number of protocols signing is based on a hash of all messages up to the signing point in the protocol. Incremental Hash is great for that because it means we don't need to hold all the current messages in the conversation in memory. However if we are required to sign at a specific point but then continue hashing for a future signing point we are stuck as we can only do a FinishAndReset
My proposal is to add a Clone or Duplicate method
I know for a fact that both OpenSsl and BCrypt support this operation, I am unsure on osx.
Such implementation on OpenSsl would look like
And in BCrypt something like
Obviously with differences due to using the .net core PAL etc
The text was updated successfully, but these errors were encountered: