Repository navigation
Tutorial PKE and Signatures
Besides ABE, OpenABE provides classic public-key primitives through the same crypto box style:
| Class | Primitive | Default curve |
|---|---|---|
OpenPKEContext |
One-pass Diffie-Hellman encryption (NIST SP 800-56A §6.2.2.2), authenticated | NIST_P256 |
OpenPKSIGContext |
ECDSA signatures | NIST_P256 |
Both constructors accept another curve ID as the first argument and base64encode (default true) as the second.
Adapted from examples/test_pk.cpp:
#include <cassert>
#include <iostream>
#include <string>
#include <openabe/openabe.h>
#include <openabe/zsymcrypto.h>
using namespace std;
using namespace oabe;
using namespace oabe::crypto;
int main() {
InitializeOpenABE();
OpenPKEContext pke; // NIST P-256
pke.keygen("user0"); // key pair stored under "user0"
string pt1 = "hello world!", pt2, ct;
pke.encrypt("user0", pt1, ct); // encrypt to user0's public key
bool ok = pke.decrypt("user0", ct, pt2);
assert(ok && pt1 == pt2);
ShutdownOpenABE();
return 0;
}Each party only ever holds its own private key and the other party's public key:
// Bob
OpenPKEContext bob;
bob.keygen("bob");
string bobPub;
bob.exportPublicKey("bob", bobPub); // send to Alice
// Alice
OpenPKEContext alice;
alice.importPublicKey("bob", bobPub);
alice.encrypt("bob", "for Bob only", ct); // send ct to Bob
// Bob
bob.decrypt("bob", ct, pt);exportPrivateKey / importPrivateKey exist for backup and migration. Treat their output like any other secret key.
OpenPKSIGContext pksig;
pksig.keygen("user1");
string msg = "hello world!", sig;
pksig.sign("user1", msg, sig);
bool valid = pksig.verify("user1", msg, sig); // true
bool forged = pksig.verify("user1", msg + "!", sig); // falseTo let others verify, export the public key with exportPublicKey("user1", blob). The verifier imports it with importPublicKey("user1", blob) and calls verify.
./oabe_keygen -s PK -i alice
./oabe_keygen -s PK -i bob
./oabe_enc -s PK -e alice -r bob -i input.txt -o input.pkenc # -e sender, -r recipient
./oabe_dec -s PK -e alice -r bob -i input.pkenc -o ok.txt # exit 0
./oabe_dec -s PK -e alice -r eve -i input.pkenc -o fail.txt # exit 32 (eve is not the recipient)The CLI has no signing tool: use the C++ API or the Python Bindings.
PK-ENC and ECDSA run on the NIST P-256 curve, while the ABE schemes run on the BN-254 pairing curve. The two curves come from two separate RELIC builds linked into the same binary; RELIC Dual Build explains why this matters.
OpenABE · AGPL-3.0 · Found a mistake in this wiki? Open an issue.
Using OpenABE
Reference
Contributing
Design notes
Help