-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathpp_secrets.cpp
More file actions
69 lines (67 loc) · 2.2 KB
/
pp_secrets.cpp
File metadata and controls
69 lines (67 loc) · 2.2 KB
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
#include <fstream>
#include <boost/filesystem.hpp>
#include <boost/lexical_cast.hpp>
#include <bitcoin/bitcoin.hpp>
#include <wallet/wallet.hpp>
#include "aes256.h"
using namespace bc;
namespace fs = boost::filesystem;
int main(int argc, char** argv)
{
if (argc != 3)
{
std::cerr << "Usage: pp_secrets DOCUMENT CHUNKS" << std::endl;
std::cerr << "Good default for CHUNKS is 100" << std::endl;
return -1;
}
const fs::path document_full_path = argv[1];
const fs::path doc_path = document_full_path.parent_path();
const fs::path doc_filename = document_full_path.filename();
const std::string chunks_str = argv[2];
size_t chunks = 0;
try
{
chunks = boost::lexical_cast<size_t>(chunks_str);
}
catch (const boost::bad_lexical_cast&)
{
std::cerr << "pp_secrets: bad CHUNKS provided." << std::endl;
return -1;
}
const fs::path public_chunks_path =
doc_path / (doc_filename.native() + "_public_chunks");
#if 0
if (!fs::create_directory(public_chunks_path))
{
std::cerr << "pp_secrets: error creating path '"
<< public_chunks_path.native() << "'" << std::endl;
return -1;
}
#endif
std::ifstream infile(document_full_path.native(), std::ifstream::binary);
infile.seekg(0, std::ifstream::end);
size_t file_size = infile.tellg();
infile.seekg(0, std::ifstream::beg);
size_t chunk_size = file_size / chunks;
// AES works on blocks of 16 bytes. Round up to nearest multiple.
chunk_size += 16 - (chunk_size % 16);
BITCOIN_ASSERT(chunk_size % 16 == 0);
//std::cout << "Creating chunks of "
// << chunk_size << " bytes each." << std::endl;
// Write the bidding address and chunks
size_t i = 0;
hash_digest_list hashes;
while (infile)
{
data_chunk buffer(chunk_size);
// Copy chunk to public chunk file.
char* data = reinterpret_cast<char*>(buffer.data());
infile.read(data, chunk_size);
++i;
// Create a seed.
BITCOIN_ASSERT(ec_secret_size == hash_size);
ec_secret secret = bitcoin_hash(buffer);
std::cout << libwallet::secret_to_wif(secret) << std::endl;
}
return 0;
}