﻿id	summary	reporter	owner	description	type	status	priority	milestone	version	resolution	keywords	cc	launchpad_bug
65	alleged bug in SHA256 on win32 MSVC 2005 release build	zooko		"On 2010-12-18, !BlackEye <blackeye1@gmail.com> wrote:
{{{
I've been struggling with getting incorrect results from the SHA256 in CryptoPP 5.6.1.  I've only seen it happen in release builds with optimizations turned on.  If I build in debug mode, or turn off optimizations, I get the expected results.  I can also influence the output of correct or incorrect results in release mode by placing unrelated code around the calls to the hashing function.  For instance, the following piece of code produces the same hash in release mode, even though the data differs.  However, if I compile in debug mode or turn off optimizations I get two different hashes.  What can I do to remedy this?

#include <cryptopp/sha.h>
#include <iostream>

template <size_t nBytes, typename T>
T* alignup(T* p)
{
       union
       {
               T* ptr;
               size_t n;
       } u;
       u.ptr = p;
       u.n = (u.n + (nBytes-1)) & ~(nBytes-1);
       return u.ptr;
}

int main(int argc, char *argv)
{
       unsigned char digestbuff[32+16];
       unsigned char databuff[64+16];
       unsigned char *digest=alignup<16>(digestbuff);
       unsigned char *data=alignup<16>(databuff);

       for(int i=0; i<64; i++)
       {
               data[i]=0;
       }

       CryptoPP::SHA256::Transform((CryptoPP::word32 *)digest,(CryptoPP::word32 *)data);
       std::cout << digest[0] << "" "" << digest[1] << std::endl;

       data[0]=1;
       CryptoPP::SHA256::Transform((CryptoPP::word32 *)digest,(CryptoPP::word32 *)data);
       std::cout << digest[0] << "" "" << digest[1] << std::endl;

       return 0;
}
}}}"	defect	closed	major	0.6.0	0.5.19	invalid		dcoder	
