forked from OlafvdSpek/xbt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
857f5e8
commit 11da9ef
Showing
3 changed files
with
174 additions
and
173 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,26 @@ | ||
/* | ||
XBT Make Merkle Tree | ||
Olaf van der Spek | ||
[email protected] | ||
[email protected] | ||
http://sourceforge.net/projects/xbtt/ | ||
http://open-content.net/specs/draft-jchapweske-thex-02.html | ||
This application creates a merkle tree with a 1024 byte segment size from an input file. | ||
The tree is created bottom up and written to stdout. | ||
*/ | ||
|
||
#include "stdafx.h" | ||
|
||
#include "bt_misc.h" | ||
#include "sha1.h" | ||
#include <cstdint> | ||
#include <cstring> | ||
#include <ctime> | ||
#include <fstream> | ||
#include <iostream> | ||
#include <list> | ||
#include <map> | ||
#include <sha1.h> | ||
#include <socket.h> | ||
#include <vector> | ||
#include <xbt/bt_misc.h> | ||
#include <xbt/virtual_binary.h> | ||
|
||
typedef std::map<int, std::string> t_map; | ||
|
||
|
@@ -36,7 +44,7 @@ int main(int argc, char* argv[]) | |
{ | ||
// calculate hash of next leaf node (one 0 byte and up to 1024 data bytes) | ||
*d = 0; | ||
std::string h = Csha1(const_memory_range(d, cb_d + 1)).read(); | ||
std::string h = Csha1(data_ref(d, cb_d + 1)).read(); | ||
std::cout << "0: " << hex_encode(h) << std::endl; | ||
// combine two hashes on the same tree level for one hash on the next level | ||
*d = 1; | ||
|
@@ -46,7 +54,7 @@ int main(int argc, char* argv[]) | |
// calculate hash of the next intermediate node (one 1 byte and two hashes) | ||
memcpy(d + 1, map.find(i)->second.c_str(), 20); | ||
memcpy(d + 21, h.c_str(), 20); | ||
h = Csha1(const_memory_range(d, 41)).read(); | ||
h = Csha1(data_ref(d, 41)).read(); | ||
std::cout << i + 1 << ": " << hex_encode(h) << std::endl; | ||
map.erase(i); | ||
} | ||
|
@@ -66,7 +74,7 @@ int main(int argc, char* argv[]) | |
std::cout << i + 1 << ": " << hex_encode(std::string(d + 21, 20)) << std::endl; | ||
memcpy(d + 1, map.begin()->second.c_str(), 20); | ||
map.erase(map.begin()); | ||
map[0] = Csha1(const_memory_range(d, 41)).read(); | ||
map[0] = Csha1(data_ref(d, 41)).read(); | ||
std::cout << i + 1 << ": " << hex_encode(map[0]) << std::endl; | ||
} | ||
return 0; | ||
|
Oops, something went wrong.