简述
比特币的历史
比特币基本原理
md4 MD5 sha-1 sha-2 hash256 -512 sha-3
哈希算法
login as: shizizheng
shizizheng@47.94.19.190's password:
Last login: Sun Apr 15 11:06:22 2018 from 118.26.141.141
Welcome to Alibaba Cloud Elastic Compute Service !
$ nano abc.c
#includechar *get_file(char *path){
FILE *file;
int length;
char *contents;
file = fopen(path,"r+");
fseek(file, 0, SEEK_END);
length = ftell(file);
fseek(file, 0, SEEK_SET);
contents = malloc(length+1);
fread(contents, 1,length,file);
fclose(file);
return contents;
}
int main(int count,char **argument)
{
char *files;
files = get_file(argument[1]);
hash_state md;
unsigned char out[64];
sha256_init(&md);
sha256_process(&md,files,strlen(files));
sha256_done(&md,out);
for (int i = 0; i < 64; i++)
{
printf("%x",out[i]);
}
return 0;
}
$ nano abc.c
$ tcc abc.c -c -o abc.o
$ tcc abc.o -ltomcrypt -o abcd
$ ./abcd shsh.txt
fa8487d7a2e9e3f73a24ad91d384bb48a65ea997b6c6f3bdc443572618d00000000000000000000000000000000$ ^C
数字签名
ecdsa(椭圆曲线数字签名算法)
一、ECDSA是什么
1、DSA历史介绍
加密:RSA, Elgamal ,ECC
签名:RSA-DSA Elgamal-RSA EC-DSA
2、定义
密钥生成
K={p,q,E,B,mA,B=ma}
Secp256k1:y^2=x^3+7 mod p
y^2=x^3+ax+b mod p a.b属于Fp
二、为什么采用ECDSA
三、ECDSA在区块链中的应用
1、交易
四、编程实现ECDSA
login as: shizizheng
shizizheng@47.94.19.190's password:
Last login: Sun Apr 15 13:58:37 2018 from 118.26.141.141
Welcome to Alibaba Cloud Elastic Compute Service !
$ nano abc.c
$ nano abcde.c
$ cat abcde.c
int main (int argc, char ** arguement){
int hash_idx;
int prng_idx;
int res, err;
unsigned long L1, L2;
unsigned char hash_out[1024],
out[1024],
sign_out[1024];
memset(hash_out,0, 1024);
memset(out, 0, 1024);
memset(sign_out, 0,1024);
ecc_key key;
const ltc_ecc_set_type dp[]={32,
"ECC-256"
"FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFF",
"5AC635D8AA3A93E7B3EBBD55769886BC651D06B0CC53B0F63BCE3C3E27D2604B",
"FFFFFFFF00000000FFFFFFFFFFFFFFFFBCE6FAADA7179E84F3B9CAC2FC632551",
"6B17D1F2E12C4247F8BCE6E563A440F277037D812DEB33A0F4A13945D898C296",
"4FE342E2FE1A7F9B8EE7EB4A7C0F9E162BCE33576B315ECECBB6406837BF51F5"
}
}
命令
$ cp /usr/lib/libtfm.a ~/
$ ls
a a.out abc.c abc.c.save abc.o abcd abcde.c abcdef.c libtfm.a libtomcrypt.a sha256.o shsh.txt
$ nano abcdef.c
$
$
$ ls
a a.out aaaaa.c abc.c abc.c.save abc.o abcd abcde.c abcdef.c abcdef.o libtfm.a libtomcrypt.a sha256.o shsh.txt
$ nano bbb.c
$ cp /home/libtomcrypt.a ~/
$ tcc bbb.c -c -o bbb.o
$ tcc bbb.o libtomcrypt.a libtfm.a -o acc
$ ls
a a.out aaaaa.c abc.c abc.c.save abc.o abcd abcde.c abcdef.c abcdef.o acc bbb.c bbb.o libtfm.a libtomcrypt.a sha256.o shsh.txt
$ ./acc shsh.txt
fread: 100
signature value: 30452206efb193ff2ec8ffd93f7c732f8a799d139d23dcc97832cbf7ed548c4fdf1352210a5d911978a0fec37392ac126fcbde6e4ccd37eaa52651181c4e819380fe11
return non-value if the signature is valid: 1
$ ^C
$