-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Fix #22140 - Add bech32 encoding/decoding #23466
Conversation
Maybe makes more sense to be in rahash2 |
Fix indentation rules
|
Its probably better to have it as a crypto plugin for encoding. Also chk the linting issues to follow the indentation rules (space before tab) and having some tests would be great too. good work! |
Will be good to have the plugin , take a look at the crypto_base64.c . if you dont expose this api and use it directly in the plugin it wont need to be new-abi specific |
I'm implementing tests, next pushed commits will be:
|
The crypto plugins implementation isn't valid at all. Sorry for having pushed too soon. |
sounds good. there's no hurry. ill cut the release before merging this |
github decided to broke all ubuntu-latest images, i fixed that on master, can you rebase your patches on top of master? |
The encoding code as been tested and works but I don't know how to integrate it into r2. Each time I try to build it fails. (The implem in crypto_bech32.c isn't totally finished but I tried to understand how to compile it first) |
The header file is not there. Maybe you forgot to commit it? |
libr/include/r_crypto.h
Outdated
@@ -9,6 +9,7 @@ | |||
#include <r_hash.h> | |||
#include <r_lib.h> | |||
#include <r_crypto/r_sm4.h> | |||
#include <r_crypto/r_bech32.h> |
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.
this file doesnt exist
BECH32_ENCODING_BECH32M | ||
} bech32_encoding; | ||
|
||
R_API int bech32_encode(char *output, const char *hrp, const uint8_t *data, size_t data_len, bech32_encoding enc); |
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 dont want to expose new APIs that will break the abi contract. Can you make this static for now? actually its only purpose is to be used by the plugin so it shouldnt be an issue
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.
also public apis must start with r_
and if you really want to expose them you can wrap them under R2_USE_NEW_ABI
test/unit/test_bech32.c
Outdated
return 0; | ||
} | ||
|
||
void test_crypto_bech32_encode (void) { |
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.
static
size_t data_len; | ||
int i; | ||
for (i = 0; i < sizeof (valid_checksum_bech32) / sizeof (valid_checksum_bech32[0]); i++) { | ||
bech32_decode (hrp, data, &data_len, valid_checksum_bech32[i]); |
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.
these tests use an api that shouldnt be made public to protect the abi contract. so you can:
- use RCrypto api to test bech32 with its plugin instead
- expose this API via R2_USE_NEW_ABI, and prefix it with r_crypto_bech32_...
char hrp[84]; | ||
size_t data_len; | ||
int i; | ||
for (i = 0; i < sizeof (valid_checksum_bech32) / sizeof (valid_checksum_bech32[0]); i++) { |
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.
better move this sizeof() to a const int size = .. one line above
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 you need more help better use the chat
please commit the missing file, i can take over the pr and do the needed fixes if you want, but the error in the build log complains about a file which i guess you didnt' commited |
Missing file coming. |
just fixing it on a branch, but this code have quite many errors and warnings. ill fix them up in my pr.
|
here you have: #23528 cherry pick the last commit, as its the only one that is different from your branch, but even if it compiles this code wont work because it have lots of inconsistent issues and im not sure how to use the bech32 algorithm, what's hrp, adn so on. please update your pr with my commit and fix the code |
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 can't build without r_bech32.h (that's why I left it last commit). |
if you cant build withhout the r_bech32.h is because its included or referenced from a .d somewhere. |
Apparently I can build without r_bech32.h ... |
There are conflicts with master now, also this function can be removed because its unused |
I tried to resolve the conflicts i hope it worked. |
Loooks like building now! Good job! |
Description
Add bech32 encoding/decoding but I don't know if I should integrate that to rax2 or not...