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

Micropython 1.24.1 compatibility fixes #2

Open
wants to merge 10 commits into
base: micropython_1.24.1
Choose a base branch
from
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,4 @@ Module.symvers
Mkfile.old
dkms.conf
.DS_Store
.vscode/settings.json
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
# Hash functions for Bitcoin

Originally from https://github.com/diybitcoinhardware/f469-disco/tree/master/usermods/uhashlib

---

extends `hashlib` micropython module with `ripemd160` and `sha512` functions.

Also adds a single-line function for pbkdf2_hmac_sha512:
Also adds a single-line function for pbkdf2_hmac (supports sha256 or sha512):

`pbkdf2_hmac_sha512(password, salt, iterations, bytes_to_read)`
`pbkdf2_hmac(hash_name, password, salt, iterations, bytes_to_read)`

in Bitcoin to generate a seed:

`pbkdf2_hmac_sha512(mnemonic, 'mnemonic'+password, 2048, 64)`
`pbkdf2_hmac('sha512', mnemonic, 'mnemonic'+password, 2048, 64)`

## TODO:

Expand Down
12 changes: 6 additions & 6 deletions crypto/sha2.c
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ void sha1_Update(SHA1_CTX* context, const sha2_byte *data, size_t len) {
usedspace = freespace = 0;
}

void sha1_Final(SHA1_CTX* context, sha2_byte digest[]) {
void sha1_Final(SHA1_CTX* context, sha2_byte digest[SHA1_DIGEST_LENGTH]) {
unsigned int usedspace;

/* If no digest buffer is passed, we don't bother doing this: */
Expand Down Expand Up @@ -631,7 +631,7 @@ void sha1_Final(SHA1_CTX* context, sha2_byte digest[]) {
usedspace = 0;
}

char *sha1_End(SHA1_CTX* context, char buffer[]) {
char *sha1_End(SHA1_CTX* context, char buffer[SHA1_DIGEST_STRING_LENGTH]) {
sha2_byte digest[SHA1_DIGEST_LENGTH], *d = digest;
int i;

Expand Down Expand Up @@ -884,7 +884,7 @@ void sha256_Update(SHA256_CTX* context, const sha2_byte *data, size_t len) {
usedspace = freespace = 0;
}

void sha256_Final(SHA256_CTX* context, sha2_byte digest[]) {
void sha256_Final(SHA256_CTX* context, sha2_byte digest[SHA256_DIGEST_LENGTH]) {
unsigned int usedspace;

/* If no digest buffer is passed, we don't bother doing this: */
Expand Down Expand Up @@ -938,7 +938,7 @@ void sha256_Final(SHA256_CTX* context, sha2_byte digest[]) {
usedspace = 0;
}

char *sha256_End(SHA256_CTX* context, char buffer[]) {
char *sha256_End(SHA256_CTX* context, char buffer[SHA256_DIGEST_STRING_LENGTH]) {
sha2_byte digest[SHA256_DIGEST_LENGTH], *d = digest;
int i;

Expand Down Expand Up @@ -1228,7 +1228,7 @@ static void sha512_Last(SHA512_CTX* context) {
sha512_Transform(context->state, context->buffer, context->state);
}

void sha512_Final(SHA512_CTX* context, sha2_byte digest[]) {
void sha512_Final(SHA512_CTX* context, sha2_byte digest[SHA512_DIGEST_LENGTH]) {
/* If no digest buffer is passed, we don't bother doing this: */
if (digest != (sha2_byte*)0) {
sha512_Last(context);
Expand All @@ -1247,7 +1247,7 @@ void sha512_Final(SHA512_CTX* context, sha2_byte digest[]) {
memzero(context, sizeof(SHA512_CTX));
}

char *sha512_End(SHA512_CTX* context, char buffer[]) {
char *sha512_End(SHA512_CTX* context, char buffer[SHA512_DIGEST_STRING_LENGTH]) {
sha2_byte digest[SHA512_DIGEST_LENGTH], *d = digest;
int i;

Expand Down
Loading