:: Re: [Libbitcoin] new ripemd generat…
Página Principal
Delete this message
Reply to this message
Autor: Eric Voskuil
Data:  
Para: libbitcoin
Assunto: Re: [Libbitcoin] new ripemd generates different hashes
Just to put a bow on this one... the new RIPEMD160 hash was operating
correctly but the thin invocation wrapper was parameterized. The output
buffer size was passed as the input buffer size.

https://github.com/libbitcoin/libbitcoin/commit/afcb074111d4a25f1220b9b191c4
00a3c0ac22e8

Thanks for tracking this down @genjix!

The develop branch how has integrated hash implementations (sha1, sha256,
ripemd160). I am presently working on ecdsa integration (secp256k1) and
@swansontec is working on integrating his bignum library. This will free us
from OpenSSL altogether.

Someone asked today on IRC what is wrong with OpenSSL. There is a
problematic license and it's a fairly heavy dependency. But you may be
surprised to learn that it is written by monkeys:

www.peereboom.us/assl/assl/html/openssl.html

e

-----Original Message-----
From: Libbitcoin [mailto:libbitcoin-bounces@lists.dyne.org] On Behalf Of
Amir Taaki
Sent: Thursday, April 17, 2014 8:08 PM
To: libbitcoin@???
Subject: 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
>



_______________________________________________
Libbitcoin mailing list
Libbitcoin@???
https://mailinglists.dyne.org/cgi-bin/mailman/listinfo/libbitcoin