-
Notifications
You must be signed in to change notification settings - Fork 6
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
[backport#19601] Add single sha256 call to CHashWriter #95
[backport#19601] Add single sha256 call to CHashWriter #95
Conversation
9672024
to
2b18a56
Compare
} | ||
|
||
// invalidates the object | ||
/** Compute the double-SHA256 hash of all data written to this object. |
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.
How is OP_CDS doing the single round of SHA256 right now?
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.
if (vchSig.size()) {
valtype vchHash(32);
CSHA256()
.Write(vchMessage.data(), vchMessage.size())
.Finalize(vchHash.data());
fSuccess = checker.VerifySignature(
vchSig, CPubKey(vchPubKey), uint256(vchHash));
metrics.nSigChecks += 1;
May want to refactor this as you're doing this. IDK.
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.
Great idea.
2b18a56
to
3c63b12
Compare
@@ -112,23 +112,38 @@ class CHashWriter { | |||
int GetVersion() const { return nVersion; } | |||
|
|||
void write(const char *pch, size_t size) { | |||
ctx.Write({(const uint8_t *)pch, size}); | |||
ctx.Write((const uint8_t *)pch, size); |
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.
Why does this need to change? Seems like an optimization of some sort?
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.
No, they just have different signatures:
CHash256 &Write(Span<const uint8_t> input);
vs
CSHA256 &Write(const uint8_t *data, size_t len);
🤷♂️
uint256 GetHash() { | ||
uint256 result; | ||
ctx.Finalize(result); | ||
ctx.Finalize(result.begin()); |
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.
Why does this need to change? Is it just to reset it?
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.
Again, different signatures:
void CHash256::Finalize(Span<uint8_t> output);
vs.
void CSHA256::Finalize(uint8_t hash[32]);
Should probably be refactored at some point, but not yet.
Part 2 of 3.