-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.cpp
50 lines (39 loc) · 1.31 KB
/
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
#include <vector>
#include <iostream>
#include "pbc.h"
#include "kpabe.hpp"
using namespace std;
int main() {
// Setup the scheme
PrivateParams priv;
PublicParams pub;
vector <int> attributeUniverse {1, 2, 3, 4, 5};
setup(attributeUniverse, pub, priv);
// Create an access policy and derive a key for it.
// (1 OR 2) AND (3 OR 4)
Node orNodeLeft(Node::Type::OR, {1, 2});
Node orNodeRight(Node::Type::OR, {3, 4});
Node root(Node::Type::AND, {orNodeLeft, orNodeRight});
auto key = keyGeneration(priv, root);
// Create an attribute-based secret (attributes 1 and 3).
element_s secret;
vector<int> encryptionAttributes {1, 3};
auto Cw = createSecret(pub, encryptionAttributes, secret);
// Recover secret
element_s recovered;
recoverSecret(key, Cw, encryptionAttributes, recovered);
cout << element_cmp(&secret, &recovered) << endl; // should be ==0
for(auto& attrCiPair: Cw) {
element_clear(&attrCiPair.second);
}
Cw.clear();
// Secret cannto be recovered if the encryption attributes do not satisfy the policy.
encryptionAttributes = {1};
Cw = createSecret(pub, encryptionAttributes, secret);
try {
recoverSecret(key, Cw, encryptionAttributes, recovered);
} catch(const UnsatError& e) {
cout << "Unsatisfied" << endl;
}
return 0;
}