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

[backport#19601] Add single sha256 call to CHashWriter #95

Merged
merged 1 commit into from
Mar 18, 2021

Conversation

EyeOfPython
Copy link
Collaborator

Part 2 of 3.

}

// invalidates the object
/** Compute the double-SHA256 hash of all data written to this object.
Copy link
Collaborator

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?

Copy link
Collaborator

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great idea.

@@ -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);
Copy link
Collaborator

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?

Copy link
Collaborator Author

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());
Copy link
Collaborator

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?

Copy link
Collaborator Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants