椭圆曲线公钥转换为比特币地址原理
2016-10-21 20:21
330 查看
Assuming what you're doing is based on this conversion: I'll describe what you can do in pseudo-code: First extract x, y from public key. // get x and y from Public key "point" EC_POINT_get_affine_coordinates_GFp(group, pub_key, x, y, ctx); // convert BIGNUMs x, y into binary form BN_bn2bin(x,x_char); BN_bn2bin(y,y_char); Next you need to do message digest several times, including 3 sha256 and 1 ripemd160. In the following pseudo-code I'll show you how to do ripemd160. To do sha256 with EVP_MD, just replace EVP_ripemd160()with EVP_sha256(), and update (input to EVP_MD) your input message with single or several EVP_DigestUpdate(). EVP_MD_CTX ctx; EVP_MD_CTX_init(&md_ctx); EVP_DigestInit(&md_ctx, EVP_ripemd160()); // hdr = 0x04 EVP_DigestUpdate(&md_ctx,hdr,1); EVP_DigestUpdate(&md_ctx,x_char,32); EVP_DigestUpdate(&md_ctx,y_char,32); // put message degest into dgst and set length to dgstlen EVP_DigestFinal(&md_ctx,dgst,&dgstlen); EVP_MD_CTX_cleanup(&md_ctx); Or the easier way, call sha256()and ripemd160()directly. But you need to prepare your input message before calling hash functions sha256()or ripemd160(). The 25-byte binary address is the result of ripemd160, together with the first 4 bytes of 32-byte checksum. You need to find a way to convert it from Base 256 to Base 58. I don't think OpenSSL support that.
| ||
Assuming what you're doing is based on this conversion: I'll describe what you can do in pseudo-code: First extract x, y from public key. // get x and y from Public key "point" EC_POINT_get_affine_coordinates_GFp(group, pub_key, x, y, ctx); // convert BIGNUMs x, y into binary form BN_bn2bin(x,x_char); BN_bn2bin(y,y_char); Next you need to do message digest several times, including 3 sha256 and 1 ripemd160. In the following pseudo-code I'll show you how to do ripemd160. To do sha256 with EVP_MD, just replace EVP_ripemd160()with EVP_sha256(), and update (input to EVP_MD) your input message with single or several EVP_DigestUpdate(). EVP_MD_CTX ctx; EVP_MD_CTX_init(&md_ctx); EVP_DigestInit(&md_ctx, EVP_ripemd160()); // hdr = 0x04 EVP_DigestUpdate(&md_ctx,hdr,1); EVP_DigestUpdate(&md_ctx,x_char,32); EVP_DigestUpdate(&md_ctx,y_char,32); // put message degest into dgst and set length to dgstlen EVP_DigestFinal(&md_ctx,dgst,&dgstlen); EVP_MD_CTX_cleanup(&md_ctx); Or the easier way, call sha256()and ripemd160()directly. But you need to prepare your input message before calling hash functions sha256()or ripemd160(). The 25-byte binary address is the result of ripemd160, together with the first 4 bytes of 32-byte checksum. You need to find a way to convert it from Base 256 to Base 58. I don't think OpenSSL support that.
| ||
相关文章推荐
- 迅雷/旋风地址转换原理分析(转)
- 迅雷,快车,旋风,飞速地址转换原理分析
- 洞悉linux下的Netfilter&iptables:网络地址转换原理之DNAT
- (十)洞悉linux下的Netfilter&iptables:网络地址转换原理之SNAT
- (九)洞悉linux下的Netfilter&iptables:网络地址转换原理之DNAT
- 趣味讲解网络地址转换NAT的原理的教程
- (九)洞悉linux下的Netfilter&iptables:网络地址转换原理之DNAT
- 网络地址转换NAT原理及应用
- NAT地址转换原理全攻略
- (十)洞悉linux下的Netfilter&iptables:网络地址转换原理之SNAT
- 普通下载url与迅雷快车旋风下载地址转换原理分析
- (九)洞悉linux下的Netfilter&iptables:网络地址转换原理之DNAT
- 新浪微博地址url字符与mid的相互转换算法及原理
- 网络地址转换NAT原理及应用
- NAT地址转换原理全攻略
- 网络地址转换NAT原理及应用
- 迅雷/旋风地址转换原理分析(转)
- 迅雷/旋风地址转换原理分析(转)
- 【比特币】椭圆曲线数字签名算法-ECDSA
- (九)洞悉linux下的Netfilter&iptables:网络地址转换原理之DNAT