-
Notifications
You must be signed in to change notification settings - Fork 1
/
block.h
77 lines (60 loc) · 1.87 KB
/
block.h
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#ifndef BLOCK_H
#define BLOCK_H
#include "hash.h"
#include <openssl/rsa.h>
typedef struct block { //1448-bit
uint8_t difficulty;//block difficulty
char src[8]; //identifier for source
uint64_t ts; //timestamp
uint32_t nonce; //nonce
uint8_t pl[128]; // payload
uint8_t phash[32]; //previous hash
} block;
/**
Compares two hashes.
@param hash1 First hash
@param hash2 Second hash
@return true if distinct, false if identical
*/
bool hashcmp(uint8_t *hash1, uint8_t *hash2);
/**
Generate genesis block. Memory should be allocated to passed block pointer.
@param blk Pointer to a block
*/
void genesisblk(block* blk);
/**
Prints the block.
@param b Block to print
*/
void printblk(block blk);
/**
Computes hash of the block and stores in bhash.
@param bhash Array to store computed hash
@param hash2 Second hash
*/
void hashblk(uint8_t* bhash, block* blk);
/**
Generates block with given parameters. Memory should be allocated to passed newblk pointer.
@param newblk Pointer to newly generated block
@param prevblk Pointer to previous block in the chain
@param msg Pointer to message
@param len Length of message
@param rsa_pri RSA structure initialized with private key
*/
void genblk(block* newblk, block* prevblk, char* msg, uint8_t len, RSA *rsa_pri);
/**
Generates block with given parameters. Memory should be allocated to passed newblk pointer.
@param newblk Pointer to newly generated block
@param phash Pointer to hash of previous block in the chain
@param msg Pointer to message
@param len Length of message
@param rsa_pri RSA structure initialized with private key
*/
void genblk_hash(block* newblk, uint8_t* phash, char* msg, uint8_t len, RSA *rsa_pri);
/**
Verifies that difficulty is reflected in block hash.
@param blk Pointer to block that is to be verified
@return true if verified, false if block is faulty
*/
bool verifyHash(block *blk);
#endif