Boost C++ Libraries: Ticket #7128: boost::uuids::detail::sha1 computes incorrect result https://svn.boost.org/trac10/ticket/7128 <p> I found a problem when hash a large file in linux. my file size is: 1,545,746,148bytes boost :: uuids :: detail :: sha1 very serious problem, hope can fix this problem. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/7128 Trac 1.4.3 Andy Tompkins Wed, 12 Sep 2012 02:02:25 GMT <link>https://svn.boost.org/trac10/ticket/7128#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7128#comment:1</guid> <description> <p> Release commit 76405 updated the sh1 algorithm to handle messages as long as the specification (2<sup>64 bits). See ticket <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/7128#5325" title="#7128: Bugs: boost::uuids::detail::sha1 computes incorrect result (closed: fixed)">#5325</a><a class="ext-link" href="https://svn.boost.org/trac/boost/ticket/5325"><span class="icon">​</span>https://svn.boost.org/trac/boost/ticket/5325</a>. It should handle your file. </sup></p> <p> Can you show your program? </p> </description> <category>Ticket</category> </item> <item> <author>jack.wgm@…</author> <pubDate>Wed, 12 Sep 2012 07:23:23 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/7128#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7128#comment:2</guid> <description> <pre class="wiki">#include &lt;iostream&gt; #include &lt;string&gt; #include &lt;boost/shared_array.hpp&gt; #include &lt;boost/uuid/sha1.hpp&gt; #include &lt;boost/smart_ptr/scoped_ptr.hpp&gt; #include &lt;boost/iostreams/device/file.hpp&gt; std::string sha1_to_string(const char *hash) { char str[128] = { 0 }; char *ptr = str; std::string ret; for (int i = 0; i &lt; 20; i++) { sprintf(ptr, "%02X", (unsigned char)*hash); ptr += 2; hash++; } ret = str; return ret; } int main(int argc, char **argv) { if (argc != 2) { return -1; } boost::uuids::detail::sha1 hasher; boost::shared_array&lt;unsigned int&gt; digest; boost::shared_array&lt;char&gt; temp_buf(new char[5242880]); boost::scoped_ptr&lt;boost::iostreams::file&gt; file_ptr( new boost::iostreams::file(argv[1], BOOST_IOS::out|BOOST_IOS::in|BOOST_IOS::binary)); if (!file_ptr-&gt;is_open()) return -1; while (true) { std::streamsize readbytes = file_ptr-&gt;read(temp_buf.get(), 5242880); if (readbytes &lt;= 0) break; hasher.process_bytes(temp_buf.get(), readbytes); } file_ptr.reset(); digest.reset(new unsigned int [5]); char bin[20]; hasher.get_digest(reinterpret_cast&lt;boost::uuids::detail::sha1::digest_type&gt;(*digest.get())); for(int i = 0; i &lt; 5; ++i) { const char* tmp = reinterpret_cast&lt;char*&gt;(digest.get()); bin[i * 4 ] = tmp[i * 4 + 3]; bin[i * 4 + 1] = tmp[i * 4 + 2]; bin[i * 4 + 2] = tmp[i * 4 + 1]; bin[i * 4 + 3] = tmp[i * 4 ]; } std::string hash_hex = sha1_to_string(bin); // output hex digest std::cout &lt;&lt; hash_hex.c_str() &lt;&lt; std::endl; return 0; } </pre><p> run program: </p> <pre class="wiki">[root@media-coder test]# g++ test.cpp [root@coder test]# ./a.out dump.rmvb 3A383A31E5B447A0614361D7E6931FE29BA9519E [root@coder test]# sha1sum dump.rmvb ad74ded3e3cbea7f02997d51e79e887e596ed787 dump.rmvb </pre> </description> <category>Ticket</category> </item> <item> <dc:creator>Andy Tompkins</dc:creator> <pubDate>Thu, 04 Oct 2012 18:37:30 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/7128#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7128#comment:3</guid> <description> <p> fixed in trunk - changeset <a class="missing ticket">#80850</a> </p> </description> <category>Ticket</category> </item> <item> <author>jack.wgm@…</author> <pubDate>Tue, 09 Oct 2012 07:31:19 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/7128#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7128#comment:4</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/7128#comment:3" title="Comment 3">atompkins</a>: </p> <blockquote class="citation"> <p> fixed in trunk - changeset <a class="missing ticket">#80850</a> </p> </blockquote> <p> Passed the test, thank! </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Andy Tompkins</dc:creator> <pubDate>Thu, 11 Oct 2012 15:31:23 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/7128#comment:5 https://svn.boost.org/trac10/ticket/7128#comment:5 <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> fixed in release - changeset <a class="missing ticket">#80954</a> </p> Ticket