Post by Iain HibbertPost by Szabolcs Nagyso my guess is that sha512.c gets miscompiled
and it corrupts the evp ctx structure
the SHA512_Final() function from sha512.c corrupts the stack
in digest.c line 94, we have
ret=ctx->digest->final(ctx,md);
but if I add printf("ctx %p\n", ctx) before and after that, the value
changes..
EVP_DigestFinal_ex: A 0xbfbfe4a8
EVP_DigestFinal_ex: B 0xa54ca49f
this call is equivalent to SHA512_Final(md, ctx->md_data)
..will look more closely after some food :)
Ok, so.. the ctx value is being held in %esi during the function call, and
SHA512_Final() does save and restore it in the normal way, keeping it at
-8(%ebp)
..BUT on line 206 we have
case SHA512_DIGEST_LENGTH:
for (n=0;n<SHA512_DIGEST_LENGTH/8;n++)
{
SHA_LONG64 t = c->h[n];
*(md++) = (unsigned char)(t>>56);
*(md++) = (unsigned char)(t>>48);
*(md++) = (unsigned char)(t>>40);
*(md++) = (unsigned char)(t>>32);
*(md++) = (unsigned char)(t>>24);
*(md++) = (unsigned char)(t>>16);
*(md++) = (unsigned char)(t>>8);
/* line 206 ----> */ *(md++) = (unsigned char)(t);
}
break;
and the assembler for this line is as follows
.stabn 68,0,206,.LL430-SHA512_Final
.LL430:
movl %esi,-8(%ebp)
movb -8(%ebp),%dl
movl 8(%ebp),%eax
incl %eax
movl %eax,8(%ebp)
movb %dl,-1(%eax)
which I don't think is right.. for some reason, ccom has written a
register out over the stored value, in order to get a byte portion?
regards,
iain