Fraunhofer-AISEC / rabe

rabe is an Attribute Based Encryption library, written in Rust
MIT License
76 stars 20 forks source link

How can I use this project in Python? #13

Open MrT3acher opened 1 year ago

MrT3acher commented 1 year ago

Hi I've built the project using cargo build --release. Now I see librabe.so file. It contains these symbols (using nm command):

0000000000004008 b completed.8061
                 w __cxa_finalize@@GLIBC_2.2.5
0000000000001040 t deregister_tm_clones
00000000000010b0 t __do_global_dtors_aux
0000000000003dd0 d __do_global_dtors_aux_fini_array_entry
0000000000004000 d __dso_handle
0000000000003dd8 d _DYNAMIC
0000000000001114 t _fini
00000000000010f0 t frame_dummy
0000000000003dc8 d __frame_dummy_init_array_entry
0000000000002094 r __FRAME_END__
0000000000003fc8 d _GLOBAL_OFFSET_TABLE_
                 w __gmon_start__
0000000000002000 r __GNU_EH_FRAME_HDR
0000000000001000 t _init
                 w _ITM_deregisterTMCloneTable
                 w _ITM_registerTMCloneTable
0000000000001070 t register_tm_clones
0000000000004008 d __TMC_END__
0000000000001100 t _ZN3std3sys4unix4args3imp15ARGV_INIT_ARRAY12init_wrapper17h9817c52b4f788959E
0000000000003dc0 d _ZN3std3sys4unix4args3imp15ARGV_INIT_ARRAY17hf93f535c4855ea1bE
0000000000004010 b _ZN3std3sys4unix4args3imp4ARGC17h4850cf38500183b7E.0
0000000000004018 b _ZN3std3sys4unix4args3imp4ARGV17hd52966b69df71d64E.0

I don't see any encrypt or decrypt function. Did I have a mistake in building the project? or is there another way to see the exports of this shared object (so) file.

finally I want to use this project in python language.

PekeDevil commented 1 year ago

Let's go one by one. In general, information to use Rabe can be found here.

There are many different schemes offered by Rabe: BSW07, KP-ABE FAME, FAME, LW11, YCT14, etc. If you have installed rabe correctly, whenever you use it in a rust script you may have a cargo.toml looking like this:

[package]
name = "NAME"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
rabe = "0.3.1"

[dev-dependencies]
criterion = "0.3"

[[bench]]
name = "SCRIPT_NAME"
harness = false

And below you have an example on how to use BSW, extracted from the documentation

use rabe::schemes::bsw::*;
use rabe::utils::policy::pest::PolicyLanguage;
let (pk, msk) = setup();
let plaintext = String::from("dance like no one's watching, encrypt like everyone is!").into_bytes();
let policy = String::from(r#""A" and "B""#);
let ct_cp: CpAbeCiphertext = encrypt(&pk, &policy, &plaintext, PolicyLanguage::HumanPolicy).unwrap();
let sk: CpAbeSecretKey = keygen(&pk, &msk, &vec!["A".to_string(), "B".to_string()]).unwrap();
assert_eq!(decrypt(&sk, &ct_cp).unwrap(), plaintext);

Regarding its use with python, I'm sorry but I do not know how to create a Python wrapper. However, you may find useful the Python ABE library, Charm.

Aya0wind commented 1 year ago

I had implemented the CFFI and a C# wrapper library for all algorithms in rabe. If you need it to create a wrapper in Python or other languages, please check my repositories (Rabe-ffi).

MrT3acher commented 1 year ago

Thanks! I finally used https://github.com/MrT3acher/mosaic.

wkwi2r commented 11 months ago

I'm using Maturin to call RABE from Python successfully.