Question: I need help getting stated on this assignment.I don't understand how to use SHA256 .h file to hash values for the tree and how to
I need help getting stated on this assignment.I don't understand how to use SHA256 .h file to hash values for the tree and how to build the tree and print it. If you could do the following below to get me stated that would be appreciated. (I know this is a lot for one question to ask I really just need help getting started any help would be very helpful)
testhashtree.c (test file)
struct TreeNode
struct HashNode
char* hash(char* data);
struct TreeNode* createLeafNode(char* data);
struct TreeNode* createBranchNode(struct TreeNode* child1, struct TreeNode* child2);
void printTree(struct TreeNode* root);
In a file named hashtree.c, implement all the functions declared in hashtree.h. Create your own testing file testhashtree.c that tests your code.
You will need to use the SHA 256 hash function provided here: https://github.com/ryancdotorg/lonesha256-ansi/blob/master/lonesha256.h. This was chosen since it is ANSI C compliant and does not rely on external dependencies. You do not have to comment this code or understand it.
SHA256 https://github.com/ryancdotorg/lonesha256-ansi/blob/master/lonesha256.h #ifndef HASHTREE_H #define HASHTREE_H /* This is the node storing each node in the hash tree*/ struct TreeNode { char* data; int isLeaf; struct TreeNode* left; struct TreeNode* right; }; /* This is the node storing each node in the list for the proof.*/ struct HashNode { char* hash; struct HashNode* next; }; /* Hashes the data by using a SHA256 hash in the lonesha C library. * Saves this as a character array, saved * on the heap. Returns a pointer to this character array. */ char* hash(char* data); /* Alloc a new leaf node with given data and returns a pointer to it. * Assume data does not lives on the heap. */ struct TreeNode* createLeafNode(char* data); /* Alloc a new inner node where the data is the hash of the data of child1 * plus the data of child2 */ struct TreeNode* createBranchNode(struct TreeNode* child1, struct TreeNode* child2); /* Verify if the given data is in a leaf node of the tree. * Returns a 0 if not, positive number if yes. */ int verifyDataInTree(struct TreeNode* hashtree, char* data); /* Print data for inorder tree traversal on single line, * separated with spaces, ending with newline. */ void printTree(struct TreeNode* root); /* Free memory used by the tree. */ void freeTree(struct TreeNode* root); /* Return all the hash values required for the merkle proof * They need to be in order from root on down * If the data isn't in the tree, returns NULL */ struct HashNode* giveProof(struct TreeNode* hashtree, char* data); #endif Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
