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;