:: Re: [Libbitcoin] new ripemd generat…
Startseite
Nachricht löschen
Nachricht beantworten
Autor: Amir Taaki
Datum:  
To: libbitcoin
Betreff: Re: [Libbitcoin] new ripemd generates different hashes
the hash function is correct, I've verified it against Python.

~> g++ -std=c++11 foo.cpp libbitcoin/src/utility/external/ripemd160.c -I
libbitcoin/include/ libbitcoin/src/utility/external/zeroize.c
~> ./a.out
8eb208f7e05d987a9b044a8e98c6b087f15a0bfc
~> python
Python 2.7.3 (default, Jan 2 2013, 13:56:14)
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import hashlib
>>> h = hashlib.new('ripemd160')
>>> h.update("abc")
>>> h.hexdigest()

'8eb208f7e05d987a9b044a8e98c6b087f15a0bfc'
~> cat foo.cpp
#include "libbitcoin/include/bitcoin/utility/external/ripemd160.h"
#include <iostream>
#include <sstream>
#include <iomanip>

std::string encode_hex(uint8_t data[20])
{
    std::stringstream ss;
    ss << std::hex;
    for (size_t i = 0; i < 20; ++i)
    {
        int val = data[i];
        ss << std::setw(2) << std::setfill('0') << val;
    }
    return ss.str();
}


int main()
{
    uint8_t result[20];
    RMD160(reinterpret_cast<const uint8_t*>("abc"), 3, result);
    std::cout << encode_hex(result) << std::endl;
    return 0;
}



> A hash function is a function in the mathematical sense, same input = same
> output (i.e. deterministic). So assuming this was proper from the start,
> the integration is the issue. Also probabilistically comparative tests
> should fail if it's incorrect.
>
> e
>
> Sent from my iPhone
>
>> On Apr 17, 2014, at 2:17 PM, "Amir Taaki" <genjix@???> wrote:
>>
>> I think maybe the library just generates different hashes and is not
>> compatible? Or am I wrong?
>>
>>> Thanks for putting the tests together Amir. I'm tied up for the next
>>> few
>>> hours. The most likely issue is that my port changed something
>>> inadvertently. Possibly the endian issue - I replaced the endianess
>>> test
>>> with boost's.
>>>
>>> e
>>>
>>> Sent from my iPhone
>>>
>>>> On Apr 17, 2014, at 1:20 PM, "Amir Taaki" <genjix@???> wrote:
>>>>
>>>> $ cd libbitcoin/test/
>>>> $ ./make.sh
>>>> Linking...
>>>> Running 8 test cases...
>>>> hash.cpp(32): fatal error in "sha256_hash": critical check
>>>> encode_hex(ripemd_hash) == "17d040b739d639c729daaf627eaff88cfe4207f4"
>>>> failed
>>>>
>>>> *** 1 failure detected in test suite "libbitcoin tests"
>>>>
>>>>
>>>>> between computer 1 (working) and computer 2 (newest). I've added a
>>>>> unit
>>>>> test for ripemd in test/ which should pass.
>>>>>
>>>>> genjix@astra1609:~$ cat test.cpp
>>>>> #include <bitcoin/bitcoin.hpp>
>>>>> using namespace bc;
>>>>>
>>>>> int main()
>>>>> {
>>>>> std::cout << generate_ripemd_hash(data_chunk{{110}}) << std::endl;
>>>>> return 0;
>>>>> }
>>>>>
>>>>> genjix@astra1609:~$ ./a.out
>>>>> 17d040b739d639c729daaf627eaff88cfe4207f4
>>>>>
>>>>> --------------------------------------------
>>>>>
>>>>> /tmp> cat rh.cpp
>>>>> #include <bitcoin/bitcoin.hpp>
>>>>> using namespace bc;
>>>>>
>>>>> int main()
>>>>> {
>>>>>       std::cout << generate_short_hash(data_chunk{{110}}) <<
>>>>> std::endl;
>>>>>           return 0;
>>>>> }

>>>>>
>>>>> /tmp> ./a.out
>>>>> 2a392d9c021a12ab0b51d90e438a54b11bf27497
>>>>>
>>>>> --------------------
>>>>>
>>>>> and when I add output to the libbitcoin ripemd hash function in the
>>>>> source:
>>>>>
>>>>> sha hash:
>>>>> 1b16b1df538ba12dc3f97edbb85caa7050d46c148134290feba80f8236c83db9
>>>>> ripemd hash: 17d040b739d639c729daaf627eaff88cfe4207f4
>>>>> 17d040b739d639c729daaf627eaff88cfe4207f4
>>>>>
>>>>> ---------------
>>>>> (newest)
>>>>>
>>>>> sha256:
>>>>> 1b16b1df538ba12dc3f97edbb85caa7050d46c148134290feba80f8236c83db9
>>>>> ripemd: 2a392d9c021a12ab0b51d90e438a54b11bf27497
>>>>> 2a392d9c021a12ab0b51d90e438a54b11bf27497
>>>>
>>>>
>>>> _______________________________________________
>>>> Libbitcoin mailing list
>>>> Libbitcoin@???
>>>> https://mailinglists.dyne.org/cgi-bin/mailman/listinfo/libbitcoin
>>
>>
>> _______________________________________________
>> Libbitcoin mailing list
>> Libbitcoin@???
>> https://mailinglists.dyne.org/cgi-bin/mailman/listinfo/libbitcoin
>