clightning-dumpkeys

dump clightning output descriptors
git clone git://jb55.com/clightning-dumpkeys
Log | Files | Refs | README | LICENSE

hash.c (682B)


      1 
      2 #include "ripemd160.h"
      3 #include "sha256.h"
      4 #include "compiler.h"
      5 #include "hash.h"
      6 
      7 int hash160(const unsigned char *bytes, size_t bytes_len,
      8                   unsigned char *bytes_out, size_t len)
      9 {
     10 	struct sha256 sha;
     11 	struct ripemd160 ripemd;
     12 	bool aligned = alignment_ok(bytes_out, sizeof(ripemd.u.u32));
     13 
     14 	if (!bytes || !bytes_out || len != HASH160_LEN)
     15 		return 0;
     16 
     17 	BUILD_ASSERT(sizeof(ripemd) == HASH160_LEN);
     18 
     19 	sha256(&sha, bytes, bytes_len);
     20 	ripemd160(aligned ? (struct ripemd160 *)bytes_out : &ripemd, &sha, sizeof(sha));
     21 	if (!aligned) {
     22 		memcpy(bytes_out, &ripemd, sizeof(ripemd));
     23 		memclear(&ripemd, sizeof(ripemd));
     24 	}
     25 	memclear(&sha, sizeof(sha));
     26 	return 1;
     27 }
     28