libbtc
bitcoinclibrary
Functions
ripemd160.h File Reference
#include <stdint.h>

Go to the source code of this file.

Functions

void ripemd160 (const uint8_t *msg, uint32_t msg_len, uint8_t *hash)
 

Function Documentation

void ripemd160 ( const uint8_t *  msg,
uint32_t  msg_len,
uint8_t *  hash 
)

Copyright (c) 2013-2014 Tomas Dzetkulic Copyright (c) 2013-2014 Pavol Rusnak

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Definition at line 292 of file ripemd160.c.

References compress().

Referenced by btc_hdnode_private_ckd(), btc_hdnode_public_ckd(), and btc_pubkey_get_hash160().

293 {
294  uint32_t i;
295  int j;
296  uint32_t digest[5] = {0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0UL};
297 
298  for (i = 0; i < (msg_len >> 6); ++i) {
299  uint32_t chunk[16];
300 
301  for (j = 0; j < 16; ++j) {
302  chunk[j] = (uint32_t)(*(msg++));
303  chunk[j] |= (uint32_t)(*(msg++)) << 8;
304  chunk[j] |= (uint32_t)(*(msg++)) << 16;
305  chunk[j] |= (uint32_t)(*(msg++)) << 24;
306  }
307 
308  compress(digest, chunk);
309  }
310 
311  // Last chunk
312  {
313  uint32_t chunk[16] = {0};
314 
315  for (i = 0; i < (msg_len & 63); ++i) {
316  chunk[i >> 2] ^= (uint32_t)*msg++ << ((i & 3) << 3);
317  }
318 
319  chunk[(msg_len >> 2) & 15] ^= (uint32_t)1 << (8 * (msg_len & 3) + 7);
320 
321  if ((msg_len & 63) > 55) {
322  compress(digest, chunk);
323  memset(chunk, 0, 64);
324  }
325 
326  chunk[14] = msg_len << 3;
327  chunk[15] = (msg_len >> 29);
328  compress(digest, chunk);
329  }
330 
331  for (i = 0; i < 5; ++i) {
332  *(hash++) = digest[i];
333  *(hash++) = digest[i] >> 8;
334  *(hash++) = digest[i] >> 16;
335  *(hash++) = digest[i] >> 24;
336  }
337 }
static void compress(uint32_t *MDbuf, uint32_t *X)
Definition: ripemd160.c:98