Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cffi #5

Closed
Sp0Q1 opened this issue Aug 5, 2020 · 1 comment
Closed

cffi #5

Sp0Q1 opened this issue Aug 5, 2020 · 1 comment

Comments

@Sp0Q1
Copy link

Sp0Q1 commented Aug 5, 2020

Almost got cffi working, just missing 1 little thing, I guess...

from cffi import FFI
ffi = FFI()
ffi.cdef("""
    struct CpAbeCiphertext;
    struct CpAbeContext;
    struct CpAbeSecretKey;

    struct CpAbeContext* rabe_bsw_context_create();
    void rabe_bsw_context_destroy(struct CpAbeContext* ctx);
    struct CpAbeSecretKey* rabe_bsw_keygen(const struct CpAbeContext* ctx, const char* attributes);
    void rabe_bsw_keygen_destroy(void* sk);
    int32_t rabe_bsw_encrypt(const void* pk, char* policy, char* pt, int32_t pt_len, char** ct, int32_t *ct_len);
    int32_t rabe_bsw_decrypt(const struct CpAbeSecretKey* sk, const char* ct, uint32_t ct_len, char** pt_buf, uint32_t *pt_len);
""")

C = ffi.dlopen("librabe.so")

ctx = C.rabe_bsw_context_create()
print(ctx)
sk = C.rabe_bsw_keygen(ctx, b"[ \"test1\", \"test2\", \"test3\" ]")
print(sk)
pt = b"testing123"
ct = ffi.new("char **")
ct_len = ???

output = C.rabe_bsw_encrypt(ctx, b"{\"OR\": [{\"ATT\": \"A\"}, {\"ATT\": \"B\"}]}", pt, len(pt), ct, ct_len)
print(output)

How should I define ct_len?

@schanzen
Copy link
Collaborator

schanzen commented Aug 7, 2020

You don't.
ct is allocated for you and ct_len will be set by the encrypt function https://github.com/Fraunhofer-AISEC/rabe/blob/master/src/ffi/bsw.rs#L117

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants