ikalchev / kpabe-yct14-cpp Goto Github PK
View Code? Open in Web Editor NEWA lightweight Key-Policy Attribute-Based Encryption scheme in C++
License: Apache License 2.0
A lightweight Key-Policy Attribute-Based Encryption scheme in C++
License: Apache License 2.0
Hello,
I am interested on testing the kp abe on an esp32 device. I would like to know how to load the dependencies (GMP and PBC are not part of the FreeRT-OS from espressif idf). Can you make a branch with the modifications for the kp abe to run on the esp32 please?
Thanks in advance
Hello,
I would like to implement the library on ESP32.
Kindly advise on the modifications that should be done in order to flash the library on ESP32.
Do you recommend a specific compilation method for the dependencies (gmp, pbc, mbedtls, and boost.test)?
Should the library be imported in an ESP32-template (https://github.com/espressif/esp-idf-template) and then flashed using the idf.py command instead of Scons?
Note: I have already recompiled the libraries PBC and GMP as was mentioned in your reply to the closed issue, however, not successfully flashed on ESP32.
I am using WSL with Ubuntu under Windows 10. I installed all the relevant libraries to compile the code. However, when attempting to compile using scons -f SConstruct.py
I get an error. The full output from the compiler is below.
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
g++ -o kpabe.o -c -std=gnu++14 -Os -I. -I/usr/local/include -I/usr/local/include/pbc kpabe.cpp
kpabe.cpp: In function 'void mbedtlsSymCrypt(const uint8_t*, size_t, uint8_t*, uint8_t*, size_t*, mbedtls_operation_t)':
kpabe.cpp:54:49: error: 'const struct mbedtls_cipher_info_t' has no member named 'key_bitlen'
54 | mbedtls_cipher_setkey(&ctx, key, cipherInfo->key_bitlen, mode);
| ^~~~~~~~~~
kpabe.cpp:57:54: error: 'const struct mbedtls_cipher_info_t' has no member named 'iv_size'
57 | mbedtls_cipher_crypt(&ctx, iv.data(), cipherInfo->iv_size, input, ilen, output, olen);
| ^~~~~~~
scons: *** [kpabe.o] Error 1
scons: building terminated because of errors.
Do you have any ideas of what the issue could be?
Hello,
I was trying to decrypt the secret with a "worst case" policy of all attributes in the universe in AND. See the code below:
#include <vector>
#include <iostream>
#include <pbc/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, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
setup(attributeUniverse, pub, priv);
// Create an access policy and derive a key for it.
// (1 OR 2) AND (3 OR 4)
Node node1(1);
Node node2(2);
Node node3(3);
Node node4(4);
Node node5(5);
Node node6(6);
Node node7(7);
Node node8(8);
Node node9(9);
Node node10(10);
Node node11(11);
Node node12(12);
Node node13(13);
Node node14(14);
Node node15(15);
Node root(Node::Type::AND, {node1, node2, node3, node4, node5, node6, node7, node8, node9, node10, node11, node12, node13, node14, node15});
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, attributeUniverse, secret);
// Recover secret
element_s recovered;
recoverSecret(key, Cw, attributeUniverse, 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;
}
The fact is that for more than 15 attributes in AND the library fails to decrypt the secret.
The line:
cout << element_cmp(&secret, &recovered) << endl; // should be ==0
gives 1.
Is this a library limitation or a bug?
@ikalchev
Hello.
I have found the 'encrypt' and 'decrypt' functions in the kpabe.cpp file, and tested them.
They are not working properly in my test. Have they been tested before?
Could you please give an example on how to use them properly?
Much appreciated.
I got the following error when trying to compile.
g++ -o kpabe_test kpabe_test.o -L. -L/usr/local/lib -lpbc -lgmp -lmbedcrypto -lm -lkpabe -lboost_unit_test_framework
./libkpabe.a(kpabe.o): In function `element_pow_zn':
kpabe.cpp:(.text+0x52): undefined reference to `__gmpz_init'
kpabe.cpp:(.text+0x7c): undefined reference to `__gmpz_clear'
./libkpabe.a(kpabe.o): In function `getPairing()':
kpabe.cpp:(.text+0x1f2): undefined reference to `pairing_init_set_str'
./libkpabe.a(kpabe.o): In function `hashElement(element_s*, unsigned char*)':
kpabe.cpp:(.text+0x250): undefined reference to `mbedtls_md_info_from_type'
kpabe.cpp:(.text+0x261): undefined reference to `mbedtls_md'
./libkpabe.a(kpabe.o): In function `mbedtlsSymCrypt(unsigned char const*, unsigned long, unsigned char*, unsigned char*, unsigned long*, mbedtls_operation_t)':
kpabe.cpp:(.text+0x2ac): undefined reference to `mbedtls_cipher_info_from_type'
kpabe.cpp:(.text+0x2bc): undefined reference to `mbedtls_cipher_setup'
kpabe.cpp:(.text+0x2d4): undefined reference to `mbedtls_cipher_setkey'
kpabe.cpp:(.text+0x303): undefined reference to `mbedtls_cipher_crypt'
collect2: error: ld returned 1 exit status
scons: *** [kpabe_test] Error 1
scons: building terminated because of errors.
I have the mbedtls headers in /usr/include/mbedtls/
and /usr/local/include/mbedtls/
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.