Bitcoin Forum
May 22, 2024, 12:16:41 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: RIPEMD-160 progressive hashing?  (Read 623 times)
Hyena (OP)
Legendary
*
Offline Offline

Activity: 2114
Merit: 1013



View Profile WWW
April 09, 2016, 10:43:33 AM
 #1

This may or may not be a suitable question for this subforum but since Bitcoin utilizes RIPEMD-160 then perhaps there are people here who know the technical essence of this hashing algorithm.

I would like to know whether it is possible to calculate a RIPEMD-160 hash of a byte string on the go. For example, I need to calculate the hash of some binary data with an unknown length. I am receiving that data chunk-by-chunk and every chunk could be the last one. However, I cannot keep all of the data in the memory at once.

How to calculate the RIPEMD-160 hash of a byte string in such conditions? Eventually I would have to do it in JavaScript. Perhaps it is really easy? For example the current hash would be the hash of the concatenation of the last hash and the current 20 chunk of 20 bytes of data (just guessing).

★★★ CryptoGraffiti.info ★★★ Hidden Messages Found from the Block Chain (Thread)
hhanh00
Sr. Member
****
Offline Offline

Activity: 467
Merit: 266


View Profile
April 09, 2016, 11:27:25 AM
 #2

You can use crypto-js.

Hyena (OP)
Legendary
*
Offline Offline

Activity: 2114
Merit: 1013



View Profile WWW
April 09, 2016, 11:59:37 AM
 #3

You can use crypto-js.

Yes, I am actually already using it. However, RIPEMD-160 and other hashing functions typically require the whole data to be hashed as an argument. In my case I can only provide 20 bytes of data at a time.

★★★ CryptoGraffiti.info ★★★ Hidden Messages Found from the Block Chain (Thread)
hhanh00
Sr. Member
****
Offline Offline

Activity: 467
Merit: 266


View Profile
April 09, 2016, 12:29:57 PM
 #4

Does it? Extract from their doc:

Code:
Progressive Hashing

var sha256 = CryptoJS.algo.SHA256.create();
sha256.update("Message Part 1");
sha256.update("Message Part 2");
sha256.update("Message Part 3");
var hash = sha256.finalize();


Hyena (OP)
Legendary
*
Offline Offline

Activity: 2114
Merit: 1013



View Profile WWW
April 09, 2016, 12:31:28 PM
Last edit: April 09, 2016, 01:06:21 PM by Hyena
 #5

Does it? Extract from their doc:

Code:
Progressive Hashing

var sha256 = CryptoJS.algo.SHA256.create();
sha256.update("Message Part 1");
sha256.update("Message Part 2");
sha256.update("Message Part 3");
var hash = sha256.finalize();



holy shit, it looks exactly what I have been looking for. I need to test this out now, thank you  very much!

edit:
hopefully finalize function is not computationally very expensive, so the hash is gradually calculated during the calls to the update function. I have yet to verify if it's really the case.
looking at their documentation I am pretty confident that it is the case

edit 2:
So I have included ripemd160.js from here in my project and the following code actually is exactly what I needed.
Code:
    var ripemd160 = CryptoJS.algo.RIPEMD160.create(); 
    ripemd160.update("Message Part 1");
    ripemd160.update("Message Part 2");
    ripemd160.update("Message Part 3");
    var hash = ripemd160.finalize();
    alert(hash);

★★★ CryptoGraffiti.info ★★★ Hidden Messages Found from the Block Chain (Thread)
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!