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

Add sha256_buffer to PoolByteArray #31187

Closed
wants to merge 1 commit into from

Conversation

chiguireitor
Copy link

This PR includes sha256_buffer to PoolByteArray (sha256_string should be refactored to sha256_text to keep consistency with string methods)

@chiguireitor
Copy link
Author

We're using this in our GDScript crypto library, and would like to mainline it so advanced uses can be done with Godot's native script.

@akien-mga
Copy link
Member

CC @Faless - does it make sense to add this or does #30239 provide the sha256 sum as a PoolByteArray too?

@chiguireitor
Copy link
Author

That's for files from what i gather (and tested on latest compiled godot), and it returns the sha256 as an hex string.

For cryptocurrency manipulation stuff you need unmangled bytes to be processed by sha256, so a string isn't fit as it trims at any 0x00 char.

Also, code is much cleaner using just PBAs for handling this and finally converting everything to your needed format when finalized.

@chiguireitor
Copy link
Author

Just to be clear, i'm porting a BigNumber (arbitrary precision arithmethic) library to GDScript, Elliptic Curve cryptography, RipeMD160, base58 and several Bitcoin functions (message signing, tx building, etc). Without proper sha256 manipulation on unmangled PBAs the Bitcoin stuff is almost impossible (doublesha256 + ripemd160 for address building, etc) due to "String" mangling the characters with 0x00 as value. Using a clean PBA with sha256 solves all this.

@Faless
Copy link
Collaborator

Faless commented Aug 19, 2019

This will be addressed soon via #29871 which allows to perform different hashes (MD5, SHA1, SHA256) PoolBytesArray via a single API (HashingContext class).

@chiguireitor
Copy link
Author

chiguireitor commented Aug 19, 2019

This will be addressed soon via #29871 which allows to perform different hashes (MD5, SHA1, SHA256) PoolBytesArray via a single API (HashingContext class).

Ok, that works too, and to boot has the random bytes call, which we had to solve via "random mouse movement of the user".

However, if the sha256_text call is making the cut to the PBA code on 3.2 (as it's already on master), it wouldn't hurt anyone to include this PR too, as it completes the functionality and causes less confusion to the uninitiated.

@Faless
Copy link
Collaborator

Faless commented Aug 19, 2019

I would honestly prefer deprecating the functions on strings/poolbytesarray regarding hashing and move everything to the new HashContext class removing most of the code from variantcall.
But this is probably a matter for discussion. Maybe do it in 4.0 instead?

@chiguireitor
Copy link
Author

As this is a minor revision, feature completeness is more important than correctness imho (also, users would expect little to no breaking changed from 3.1 to 3.2).

I'm not a main dev here, but i would feel more comfortable with breaking changes making the cut on 4.0 than 3.2. Maybe add a deprecation notice in the documentation

@Faless
Copy link
Collaborator

Faless commented Aug 19, 2019

I'm not a main dev here, but i would feel more comfortable with breaking changes making the cut on 4.0 than 3.2. Maybe add a deprecation notice in the documentation

Yes, ofc, deprecation will maintain the current funcitons, show warnings in editor/docs, and then in 4.0 deprecated functions will be dropped.
This is why adding a function that is already deprecated seems confusing.

@chiguireitor
Copy link
Author

chiguireitor commented Aug 19, 2019

Indeed, it's weird, but i gather that some people will get confused if they happen to need it and just see the string version but not the pba version.

And i gather 4.0 could be a while off, so again it's just my opinion, but you want users seeing a more complete feature set (although with deprecation notices) than something that looks kinda half done because there's a coming update (and this updates addresses that issue with almost 0 fluff).

Btw, i would rather prefer using your PR, it's more like what one does in nodejs and python, would be nice if it exposed the native ripemd hash in the same way (although afaik, that's not provided by mbedtls).

@akien-mga
Copy link
Member

The plan is to include #29871 in 3.2, so it's maybe better that we don't add new APIs next to it that would be meant to be removed in 4.0.

If we decide not to merge this PR (#31187) and we do merge #29871 soon, maybe we should also revert #24269 which was merged during 3.2 development too (so reverting it now doesn't really break compat, only for users of the master branch)?

@chiguireitor
Copy link
Author

Makes sense. I'm ok with consistency here, so if there's a better alternative that has the same end result, much better for everyone.

However, leaving PBA with half of the functionality out would be very confusing at best, so the approach of reverting in favor of the new functionality is much cleaner imho.

akien-mga added a commit to akien-mga/godot that referenced this pull request Aug 22, 2019
This reverts commit e2c3bba.

This was superseded by godotengine#29871 which adds more crypto features with a
dedicated interface.

Since this commit was never in a stable release (merged during 3.2 dev),
we revert it to avoid having to deprecate it in favor of the Crypto API.
See godotengine#31187 (comment)
@akien-mga
Copy link
Member

I opened #31560 to revert sha256_string. I guess we can also close this PR now, but thanks for the proposal and the discussion :)

@akien-mga akien-mga closed this Aug 22, 2019
pchasco pushed a commit to pchasco/godot that referenced this pull request Oct 23, 2019
This reverts commit e2c3bba.

This was superseded by godotengine#29871 which adds more crypto features with a
dedicated interface.

Since this commit was never in a stable release (merged during 3.2 dev),
we revert it to avoid having to deprecate it in favor of the Crypto API.
See godotengine#31187 (comment)
@Henry-E
Copy link

Henry-E commented Nov 2, 2020

So, Is it possible to use base58 encoding in godot? And how can I call it. Thanks!

@chiguireitor
Copy link
Author

Afaik, it's not in. However, adding a C++ library for that is kinda easy if you're fluent in C++ ofc.

@Henry-E
Copy link

Henry-E commented Nov 2, 2020

ah ok, so I could just make a custom module. I will look into that!

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

Successfully merging this pull request may close these issues.

None yet

5 participants