Hybrid Ciphertext Policy Attribute Based Encryption Library for C/C++ in Windows/Linux
- Clone the repository:
https://github.com/WanThinnn/Hybrid-CP-ABE-Library.git
- Navigate to the project directory:
Using x64 Native Tools Command Prompt for VS 2022
cd Hybrid-CP-ABE-Library/src/cpp code . #for open projects Visual Studio Code
- Configure
tasks.jsonto build the project usingcl.exe:- Create or open the
.vscodefolder in your project directory. - Create a
tasks.jsonfile inside the.vscodefolder with the following content:
- Create or open the
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "C/C++: cl.exe build executable",
"command": "cl.exe",
"args": [
"/MD",
"/GS",
"/O2",
"/Zi",
"/EHsc",
"/Fe:${fileDirname}\\${fileBasenameNoExtension}.exe",
"${file}",
"/I${workspaceFolder}\\include",
"/link",
"/LIBPATH:${workspaceFolder}\\lib\\static",
"librabe_ffi.lib",
"cryptlib.lib",
"bcrypt.lib",
"advapi32.lib",
"ntdll.lib",
"Ws2_32.lib",
"/MACHINE:X64"
],
"problemMatcher": [
"$msCompile"
],
"group": "build",
"detail": "Task to build executable."
},
{
"type": "shell",
"label": "C/C++: cl.exe build executable for hybrid CP-ABE",
"command": "cl.exe",
"args": [
"/MD",
"/GS",
"/O2",
"/Zi",
"/EHsc",
"/Fe:${fileDirname}\\${fileBasenameNoExtension}.exe",
"${file}",
"/I${workspaceFolder}\\include",
"/link",
"/LIBPATH:${workspaceFolder}\\lib\\static",
"libac17_gcm256.lib",
"/MACHINE:X64"
],
"problemMatcher": [
"$msCompile"
],
"group": "build",
"detail": "Task to build executable for hybrid CP-ABE."
},
{
"type": "shell",
"label": "C/C++: cl.exe build static library for hybrid CP-ABE",
"command": "cl.exe",
"args": [
"/MD",
"/GS",
"/O2",
"/Zi",
"/EHsc",
"/c",
"${file}",
"/I${workspaceFolder}\\include"
],
"problemMatcher": [
"$msCompile"
],
"group": {
"kind": "build",
"isDefault": false
},
"detail": "Task to build static library for hybrid CP-ABE."
},
{
"type": "shell",
"label": "C/C++: lib.exe create static library for hybrid CP-ABE",
"command": "lib.exe",
"args": [
"/OUT:${fileDirname}\\${fileBasenameNoExtension}.lib",
"${fileDirname}\\${fileBasenameNoExtension}.obj",
"/LIBPATH:${workspaceFolder}\\lib\\static",
"librabe_ffi.lib",
"cryptlib.lib",
"bcrypt.lib",
"advapi32.lib",
"ntdll.lib"
],
"problemMatcher": [
"$msCompile"
],
"group": {
"kind": "build",
"isDefault": false
},
"detail": "Task to create static library."
},
{
"type": "shell",
"label": "C/C++: cl.exe build dynamic linking library (DLL) for hybrid CP-ABE",
"command": "cl.exe",
"args": [
"/MD",
"/GS",
"/O2",
"/Zi",
"/EHsc",
"/LD",
"/DBUILD_DLL",
"/Fe:${fileDirname}\\${fileBasenameNoExtension}.dll",
"${file}",
"/I${workspaceFolder}\\include",
"/link",
"/LIBPATH:${workspaceFolder}\\lib\\static",
"librabe_ffi.lib",
"cryptlib.lib",
"bcrypt.lib",
"advapi32.lib",
"ntdll.lib",
"/MACHINE:X64"
],
"problemMatcher": [
"$msCompile"
],
"group": {
"kind": "build",
"isDefault": false
},
"detail": "C/C++: cl.exe build dynamic linking library (DLL) for hybrid CP-ABE"
},
]
}- Build the project:
- Open Visual Studio Code and open your project.
- Press
Ctrl+Shift+Bto run the configured build task. - If everything is configured correctly, your program will be compiled using
cl.exe.
- Clone the repository:
https://github.com/WanThinnn/Hybrid-CP-ABE-Library.git
- Navigate to the project directory:
cd Hybrid-CP-ABE-Library/src/cpp code . #for open projects Visual Studio Code
- Configure
tasks.jsonto build the project usingg++:- Create or open the
.vscodefolder in your project directory. - Create a
tasks.jsonfile inside the.vscodefolder with the following content:
- Create or open the
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "Build executable (cryptopp/rabe_ffi)",
"command": "g++",
"args": [
"-O3",
"-g2",
"-Wall",
"-I${workspaceFolder}/include",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}",
"-L${workspaceFolder}/lib/static",
"-lcryptopp",
"-lrabe_ffi"
],
"problemMatcher": ["$gcc"],
"group": "build",
"detail": "Build executable linking cryptopp and rabe_ffi."
},
{
"type": "shell",
"label": "Build executable (hybrid CP-ABE)",
"command": "g++",
"args": [
"-O2",
"-g",
"-Wall",
"-I${workspaceFolder}/include",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}",
"-L${workspaceFolder}/lib/static",
"-lhybrid-cp-abe"
],
"problemMatcher": ["$gcc"],
"group": "build",
"detail": "Build executable linking fat library libhybrid-cp-abe.a."
},
{
"type": "shell",
"label": "Compile source for hybrid CP-ABE (1/3)",
"command": "g++",
"args": [
"-O2",
"-g",
"-Wall",
"-c",
"${file}",
"-I${workspaceFolder}/include",
"-fPIC",
"-o",
"${fileDirname}/${fileBasenameNoExtension}.o"
],
"problemMatcher": ["$gcc"],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Compile source into object file."
},
{
"type": "shell",
"label": "Extract dependency objects (2/3)",
"command": "bash",
"args": [
"-c",
"rm -rf \"${workspaceFolder}/tmp_extracted\" && mkdir -p \"${workspaceFolder}/tmp_extracted\" && cd \"${workspaceFolder}/lib/static\" && ar x libcryptopp.a && ar x librabe_ffi.a && mv *.o \"${workspaceFolder}/tmp_extracted/\""
],
"problemMatcher": [],
"group": "build",
"detail": "Extract .o files from libcryptopp.a and librabe_ffi.a."
},
{
"type": "shell",
"label": "Create fat static library for hybrid CP-ABE (3/3)",
"command": "bash",
"args": [
"-c",
"ar rcs \"${workspaceFolder}/lib/static/libhybrid-cp-abe.a\" \"${fileDirname}/${fileBasenameNoExtension}.o\" \"${workspaceFolder}/tmp_extracted/\"*.o && rm -rf \"${workspaceFolder}/tmp_extracted\""
],
"problemMatcher": ["$gcc"],
"group": "build",
"detail": "Combine object files into libhybrid-cp-abe.a."
},
{
"type": "shell",
"label": "Build shared library for hybrid CP-ABE",
"command": "g++",
"args": [
"-O2",
"-g",
"-Wall",
"-fPIC",
"-DBUILD_DLL",
"-I${workspaceFolder}/include",
"${file}",
"-shared",
"-o",
"${fileDirname}/${fileBasenameNoExtension}.so",
"-L${workspaceFolder}/lib/static",
"-lhybrid-cp-abe",
"-lcryptopp",
"-lrabe_ffi"
],
"problemMatcher": ["$gcc"],
"group": "build",
"detail": "Build shared library (.so) for hybrid CP-ABE."
}
]
}
- Build the project:
- Open Visual Studio Code and open your project.
- Press
Ctrl+Shift+Bto run the configured build task. - If everything is configured correctly, your program will be compiled using
g++.
The usage of the executable is as follows:
Usage: hybrid-cp-abe.exe [setup|genkey|encrypt|decrypt]
Usage: hybrid-cp-abe.exe setup <path_to_save_file>
Usage: hybrid-cp-abe.exe genkey <master_key_file> <attributes> <private_key_file>
Usage: hybrid-cp-abe.exe encrypt <public_key_file> <plaintext_file> <policy> <ciphertext_file>
Usage: hybrid-cp-abe.exe decrypt <private_key_file> <ciphertext_file> <recovertext_file>Example commands:
hybrid-cp-abe.exe setup test_case
hybrid-cp-abe.exe genkey "test_case/cpabe_msk.key" "A B C" "test_case/cpabe_sk.key"
hybrid-cp-abe.exe encrypt "test_case/cpabe_pk.key" "test_case/plaintext.txt" "((A and C) or E)" "test_case/ciphertext.txt"
hybrid-cp-abe.exe decrypt "test_case/cpabe_sk.key" "test_case/ciphertext.txt" "test_case/recovertext.txt"After building the library, you can integrate it into any program on Windows/Linux. Here are the steps to include the library in your project. Please go to python-sources folder to see more.
Special thanks to Aya0wind for the Rabe-ffi project and the CryptoPP Library for helping me build this library.
This project is open-source and available for anyone to use, modify, and distribute. We encourage you to clone, fork, and contribute to this project to help improve and expand its capabilities. By contributing to this project, you agree that your contributions will be available under the same open terms.