nostril

A C cli tool for creating nostr events
git clone git://jb55.com/nostril
Log | Files | Refs | Submodules | README | LICENSE

proof.h (392B)


      1 static inline int zero_bits(unsigned char b)
      2 {
      3 	int n = 0;
      4 
      5 	if (b == 0)
      6 		return 8;
      7 
      8 	while (b >>= 1)
      9 		n++;
     10 
     11 	return 7-n;
     12 }
     13 
     14 /* find the number of leading zero bits in a hash */
     15 static int count_leading_zero_bits(unsigned char *hash)
     16 {
     17 	int bits, total, i;
     18 
     19 	for (i = 0, total = 0; i < 32; i++) {
     20 		bits = zero_bits(hash[i]);
     21 		total += bits;
     22 		if (bits != 8)
     23 			break;
     24 	}
     25 	return total;
     26 }