Ejemplo n.º 1
0
inline static int priv2hash160(unsigned char *priv) {
  unsigned char *pub_chr = mem;
  int pub_chr_sz;

  secp256k1_ec_pubkey_create_precomp(pub_chr, &pub_chr_sz, priv);

  /* compute hash160 for uncompressed public key */
  /* sha256(pub) */
  SHA256_Init(sha256_ctx);
  SHA256_Update(sha256_ctx, pub_chr, 65);
  SHA256_Final(hash256, sha256_ctx);
  /* ripemd160(sha256(pub)) */
  ripemd160_256(hash256, hash160_uncmp.uc);

  /* quick and dirty public key compression */
  pub_chr[0] = 0x02 | (pub_chr[64] & 0x01);

  /* compute hash160 for compressed public key */
  /* sha256(pub) */
  SHA256_Init(sha256_ctx);
  SHA256_Update(sha256_ctx, pub_chr, 33);
  SHA256_Final(hash256, sha256_ctx);
  /* ripemd160(sha256(pub)) */
  ripemd160_256(hash256, hash160_compr.uc);

  return 0;
}
Ejemplo n.º 2
0
inline static int pub2hash160(unsigned char *pub_chr) {
  /* compute hash160 for uncompressed public key */
  /* sha256(pub) */
  SHA256_Init(sha256_ctx);
  SHA256_Update(sha256_ctx, pub_chr, 65);
  SHA256_Final(hash256, sha256_ctx);
  /* ripemd160(sha256(pub)) */
  ripemd160_256(hash256, hash160_uncmp.uc);

  /* quick and dirty public key compression */
  pub_chr[0] = 0x02 | (pub_chr[64] & 0x01);

  /* compute hash160 for compressed public key */
  /* sha256(pub) */
  SHA256_Init(sha256_ctx);
  SHA256_Update(sha256_ctx, pub_chr, 33);
  SHA256_Final(hash256, sha256_ctx);
  /* ripemd160(sha256(pub)) */
  ripemd160_256(hash256, hash160_compr.uc);

  return 0;
}