forked from matja/bitcoin-tool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhash.c
30 lines (26 loc) · 766 Bytes
/
hash.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include "hash.h"
void Bitcoin_SHA256(struct BitcoinSHA256 *output, const void *input, size_t size)
{
SHA256_CTX ctx;
SHA256_Init(&ctx);
SHA256_Update(&ctx, input, size);
SHA256_Final(output->data, &ctx);
}
void Bitcoin_DoubleSHA256(struct BitcoinSHA256 *output, const void *input, size_t size)
{
struct BitcoinSHA256 round1;
SHA256_CTX ctx;
SHA256_Init(&ctx);
SHA256_Update(&ctx, input, size);
SHA256_Final(round1.data, &ctx);
SHA256_Init(&ctx);
SHA256_Update(&ctx, &round1.data, BITCOIN_SHA256_SIZE);
SHA256_Final(output->data, &ctx);
}
void Bitcoin_RIPEMD160(struct BitcoinRIPEMD160 *output, const void *input, size_t size)
{
RIPEMD160_CTX ctx;
RIPEMD160_Init(&ctx);
RIPEMD160_Update(&ctx, input, size);
RIPEMD160_Final(output->data, &ctx);
}