Boost C++ Libraries: Ticket #5325: boost::uuids::detail::sha1 computes incorrect result on vs2010sp1.iso https://svn.boost.org/trac10/ticket/5325 <p> I wrote a program to compute the CRC32 and sha1 checksum, I found it can generate correct sha1 result only if the size of the checked file is not too big(e.g.,the size of virtualbox or linux kernel source), but when I checked vs2010sp1.iso which is around 1.6GB, the crc32 is correct, the sha1 is not the same as the output of sha1sum. The version of boost that I tested are 1.45.0,1.46.0 and 1.46.1, both on windows 7 and linux 2.6.36. I attach my source code here. </p> <p> #include &lt;stdio.h&gt; #ifdef WIN32 #include &lt;io.h&gt; #else #include &lt;sys/types.h&gt; #endif #include &lt;fcntl.h&gt; #include &lt;string.h&gt; #include &lt;errno.h&gt; #include &lt;exception&gt; #include &lt;boost/crc.hpp&gt; #include &lt;boost/uuid/sha1.hpp&gt; </p> <p> const int bufSize = 4096; int main(int argc, char<strong>argv) { </strong></p> <blockquote> <p> if(argc &lt; 2) { </p> <blockquote> <p> printf("Useage:\t%s FileName1 FileName2 ...\n",argv<a class="missing changeset" title="No changeset 0 in the repository">[0]</a>); return 1; </p> </blockquote> <p> } </p> <blockquote> <p> char buf[bufSize]; </p> </blockquote> <p> try { </p> <blockquote> <p> for(int i = 1; i &lt; argc; ++i) { </p> <blockquote> <p> boost::crc_32_type crc; boost::uuids::detail::sha1 sha; </p> </blockquote> </blockquote> </blockquote> <blockquote> <blockquote> <blockquote> <p> int fd=::open(argv[i], O_RDONLY); if(fd&lt;0) { </p> <blockquote> <p> printf("Failed to open file %s, error:%s\n", argv[i], strerror(errno)); continue; </p> </blockquote> <p> } while(1) { </p> <blockquote> <p> int n=::read(fd, buf, bufSize); if(n&lt;=0) </p> <blockquote> <p> break; </p> </blockquote> <p> crc.process_bytes(buf, n); sha.process_bytes(buf, n); </p> </blockquote> <p> }; ::close(fd); unsigned int dig<a class="changeset" href="https://svn.boost.org/trac10/changeset/5" title="Boost customization">[5]</a>; </p> </blockquote> <p> sha.get_digest(dig); </p> <blockquote> <p> printf("%s :\nCRC32 = %08x\nSHA1 = ",argv[i], crc.checksum()); for(i=0; i&lt;5; ++i) </p> </blockquote> <p> printf("%04x",dig[i]); </p> </blockquote> <p> printf("\n"); </p> </blockquote> <blockquote> <p> } return 0; </p> </blockquote> <blockquote> <p> } catch(std::exception &amp;e) { </p> <blockquote> <p> printf("Found an exception with '%s'\n",e.what()); return 2; </p> </blockquote> <p> } catch(...) { </p> <blockquote> <p> printf("Found an unknown exception.\n"); return 3; </p> </blockquote> <p> } </p> </blockquote> <p> } </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/5325 Trac 1.4.3 Andy Tompkins Wed, 11 Jan 2012 04:20:57 GMT <link>https://svn.boost.org/trac10/ticket/5325#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5325#comment:1</guid> <description> <p> Fixed with release commit 76405 and 76406 </p> <p> The digest was incorrect for messages longer than 536,870,911 bytes (and vs2010sp1.iso is). </p> <p> The sha1 implementation now handles messages as long as the sha1 specification, 2<sup>64 bits. </sup></p> </description> <category>Ticket</category> </item> <item> <dc:creator>Andy Tompkins</dc:creator> <pubDate>Wed, 18 Jan 2012 14:16:58 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/5325#comment:2 https://svn.boost.org/trac10/ticket/5325#comment:2 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> Note also that the given program has a bug. The ::open also needs the flag _O_BINARY. </p> <p> I added a test to hash 1 million 'a's, but I do need to add tests for even longer messages. </p> Ticket