-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathTPORAM_main.cpp
88 lines (73 loc) · 2.52 KB
/
TPORAM_main.cpp
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
78
79
80
81
82
83
84
85
86
87
88
//
// Created by Dong Xie on 7/13/2016.
//
#include <mongo/client/dbclient.h>
#include <cryptopp/osrng.h>
#include "ORAM.h"
#include "TPPartitionORAMInstance.h"
#include "PartitionORAM.h"
#include "Config.h"
using namespace mongo;
using namespace CryptoPP;
int main() {
mongo::client::initialize();
srand((uint32_t)time(NULL));
uint32_t N = 1024;
ORAM *oram = new PartitionORAM<TPPartitionORAMInstance>(N, R);
for(uint32_t i = 0; i < N; i ++) {
char str[12];
sprintf(str, "%zu\n", (size_t)i);
std::string key(str);
std::string value;
const uint32_t tmp_len = B - AES::BLOCKSIZE - 2 * sizeof(uint32_t);
byte tmp_buffer[tmp_len];
AutoSeededRandomPool prng;
prng.GenerateBlock(tmp_buffer, tmp_len);
value = std::string((const char *)tmp_buffer, tmp_len);
int32_t blockID = i;
std::string bID = std::string((const char *)(& blockID), sizeof(uint32_t));
value = bID + value;
oram->put(key, value);
}
size_t roundNum = 5;
for(size_t r = 0; r < roundNum; r ++) {
for(size_t i = 0; i < N; i ++) {
char str[12];
sprintf(str, "%zu\n", i);
std::string key(str);
std::string block = oram->get(key);
uint32_t value;
memcpy((& value), block.c_str(), sizeof(uint32_t));
printf("%d ", value);
}
printf("\n=========================================================================\n");
}
for(uint32_t i = 0; i < N; i ++) {
char str[12];
sprintf(str, "%zu\n", (size_t)i);
std::string key(str);
std::string value;
const uint32_t tmp_len = B - AES::BLOCKSIZE - 2 * sizeof(uint32_t);
byte tmp_buffer[tmp_len];
AutoSeededRandomPool prng;
prng.GenerateBlock(tmp_buffer, tmp_len);
value = std::string((const char *)tmp_buffer, tmp_len);
int32_t blockID = N - 1 - i;
std::string bID = std::string((const char *)(& blockID), sizeof(uint32_t));
value = bID + value;
oram->put(key, value);
}
for(size_t i = 0; i < N; i ++) {
char str[12];
sprintf(str, "%zu\n", i);
std::string key(str);
std::string block = oram->get(key);
uint32_t value;
memcpy((& value), block.c_str(), sizeof(uint32_t));
printf("%d ", value);
}
printf("\n=========================================================================\n");
delete oram;
mongo::client::shutdown();
return 0;
}