Skip to content

Instantly share code, notes, and snippets.

View McSimp's full-sized avatar

Will Donohoe McSimp

View GitHub Profile
@McSimp
McSimp / Starbound SHA256 Bug.md
Last active August 29, 2015 13:56
Details of a bug in the SHA256 implementation in Starbound

Bug Details

The bug comes from the first if statment in sha256_final (or whatever you've called it in your code).

Yours looks like OpenSSL's, except the if statement on line 375 of md32_common.h in OpenSSL (https://github.com/openssl/openssl/blob/master/crypto/md32_common.h#L375) evaluates to if (n > 56), whereas yours evaluates to the equivalent of if (n > 55), producing erroneous hashes for data of length 55.

int HASH_FINAL (unsigned char *md, HASH_CTX *c)
{
 unsigned char *p = (unsigned char *)c->data;