GNUnet  0.10.x
Functions
ABE Crypto library: Attribute-Based Encryption operations

Functions

struct GNUNET_ABE_AbeMasterKeyGNUNET_ABE_cpabe_create_master_key (void)
 Create a new CP-ABE master key. More...
 
void GNUNET_ABE_cpabe_delete_master_key (struct GNUNET_ABE_AbeMasterKey *key)
 Delete a CP-ABE master key. More...
 
struct GNUNET_ABE_AbeKeyGNUNET_ABE_cpabe_create_key (struct GNUNET_ABE_AbeMasterKey *key, char **attrs)
 Create a new CP-ABE key. More...
 
void GNUNET_ABE_cpabe_delete_key (struct GNUNET_ABE_AbeKey *key, int delete_pub)
 Delete a CP-ABE key. More...
 
ssize_t GNUNET_ABE_cpabe_encrypt (const void *block, size_t size, const char *policy, const struct GNUNET_ABE_AbeMasterKey *key, void **result)
 Encrypt a block using sessionkey. More...
 
ssize_t GNUNET_ABE_cpabe_decrypt (const void *block, size_t size, const struct GNUNET_ABE_AbeKey *key, void **result)
 Decrypt a block using the ABE key. More...
 
ssize_t GNUNET_ABE_cpabe_serialize_key (const struct GNUNET_ABE_AbeKey *key, void **result)
 Serialize an ABE key. More...
 
struct GNUNET_ABE_AbeKeyGNUNET_ABE_cpabe_deserialize_key (const void *data, size_t len)
 Deserialize a serialized ABE key. More...
 
ssize_t GNUNET_ABE_cpabe_serialize_master_key (const struct GNUNET_ABE_AbeMasterKey *key, void **result)
 Serialize an ABE master key. More...
 
struct GNUNET_ABE_AbeMasterKeyGNUNET_ABE_cpabe_deserialize_master_key (const void *data, size_t len)
 Deserialize an ABE master key. More...
 

Detailed Description

Function Documentation

◆ GNUNET_ABE_cpabe_create_master_key()

struct GNUNET_ABE_AbeMasterKey * GNUNET_ABE_cpabe_create_master_key ( void  )

Create a new CP-ABE master key.

Caller must free return value.

Returns
fresh private key; free using GNUNET_ABE_cpabe_delete_master_key

Definition at line 155 of file abe.c.

References GNUNET_assert, GNUNET_new, key, GNUNET_ABE_AbeMasterKey::msk, and GNUNET_ABE_AbeMasterKey::pub.

156 {
158 
159  key = GNUNET_new(struct GNUNET_ABE_AbeMasterKey);
160  gabe_setup(&key->pub, &key->msk);
161  GNUNET_assert(NULL != key->pub);
162  GNUNET_assert(NULL != key->msk);
163  return key;
164 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
gabe_msk_t * msk
Definition: abe.c:38
#define GNUNET_new(type)
Allocate a struct or union of the given type.
struct GNUNET_HashCode key
The key used in the DHT.
gabe_pub_t * pub
Definition: abe.c:37

◆ GNUNET_ABE_cpabe_delete_master_key()

void GNUNET_ABE_cpabe_delete_master_key ( struct GNUNET_ABE_AbeMasterKey key)

Delete a CP-ABE master key.

Parameters
keythe master key
Returns
fresh private key; free using GNUNET_free

Definition at line 174 of file abe.c.

References GNUNET_free, GNUNET_ABE_AbeMasterKey::msk, and GNUNET_ABE_AbeMasterKey::pub.

175 {
176  gabe_msk_free(key->msk);
177  gabe_pub_free(key->pub);
178  //GNUNET_free (key->msk);
179  //gabe_msk_free (key->msk); //For some reason free of pub implicit?
180  GNUNET_free(key);
181 }
gabe_msk_t * msk
Definition: abe.c:38
gabe_pub_t * pub
Definition: abe.c:37
#define GNUNET_free(ptr)
Wrapper around free.

◆ GNUNET_ABE_cpabe_create_key()

struct GNUNET_ABE_AbeKey * GNUNET_ABE_cpabe_create_key ( struct GNUNET_ABE_AbeMasterKey key,
char **  attrs 
)

Create a new CP-ABE key.

Caller must free return value.

Parameters
keythe master key
attrsthe attributes to append to the key
Returns
fresh private key; free using GNUNET_ABE_cpabe_delete_key

Definition at line 192 of file abe.c.

References GNUNET_assert, GNUNET_free, GNUNET_new, GNUNET_ABE_AbeMasterKey::msk, GNUNET_ABE_AbeKey::prv, GNUNET_ABE_AbeMasterKey::pub, GNUNET_ABE_AbeKey::pub, and size.

194 {
195  struct GNUNET_ABE_AbeKey *prv_key;
196  int size;
197  char *tmp;
198 
199  prv_key = GNUNET_new(struct GNUNET_ABE_AbeKey);
200  prv_key->prv = gabe_keygen(key->pub, key->msk, attrs);
201  size = gabe_pub_serialize(key->pub, &tmp);
202  prv_key->pub = gabe_pub_unserialize(tmp, size);
203  GNUNET_free(tmp);
204  GNUNET_assert(NULL != prv_key->prv);
205  return prv_key;
206 }
gabe_pub_t * pub
Definition: abe.c:42
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
gabe_msk_t * msk
Definition: abe.c:38
#define GNUNET_new(type)
Allocate a struct or union of the given type.
gabe_prv_t * prv
Definition: abe.c:43
static unsigned int size
Size of the "table".
Definition: peer.c:66
gabe_pub_t * pub
Definition: abe.c:37
#define GNUNET_free(ptr)
Wrapper around free.

◆ GNUNET_ABE_cpabe_delete_key()

void GNUNET_ABE_cpabe_delete_key ( struct GNUNET_ABE_AbeKey key,
int  delete_pub 
)

Delete a CP-ABE key.

Parameters
keythe key to delete
delete_pubGNUNE_YES if the public key should also be freed (bug in gabe)
Returns
fresh private key; free using GNUNET_free
Parameters
keythe key to delete
delete_pubGNUNET_YES if the public key should also be freed (bug in gabe)
Returns
fresh private key; free using GNUNET_free

Definition at line 217 of file abe.c.

References GNUNET_free, GNUNET_YES, GNUNET_ABE_AbeKey::prv, and GNUNET_ABE_AbeKey::pub.

219 {
220  //Memory management in gabe is buggy
221  gabe_prv_free(key->prv);
222  if (GNUNET_YES == delete_pub)
223  gabe_pub_free(key->pub);
224  GNUNET_free(key);
225 }
gabe_pub_t * pub
Definition: abe.c:42
gabe_prv_t * prv
Definition: abe.c:43
#define GNUNET_YES
Definition: gnunet_common.h:77
#define GNUNET_free(ptr)
Wrapper around free.

◆ GNUNET_ABE_cpabe_encrypt()

ssize_t GNUNET_ABE_cpabe_encrypt ( const void *  block,
size_t  size,
const char *  policy,
const struct GNUNET_ABE_AbeMasterKey key,
void **  result 
)

Encrypt a block using sessionkey.

Parameters
blockthe block to encrypt
sizethe size of the block
policythe ABE policy
keythe key used to encrypt
resultthe result buffer. Will be allocated. Free using GNUNET_free
Returns
the size of the encrypted block, -1 for errors

Definition at line 297 of file abe.c.

References aes_128_cbc_encrypt(), GNUNET_free, GNUNET_memdup, GNUNET_SYSERR, m, GNUNET_ABE_AbeMasterKey::pub, and write_cpabe().

302 {
303  gabe_cph_t* cph;
304  char* plt;
305  char* cph_buf;
306  char* aes_buf;
307  element_t m;
308  int cph_buf_len;
309  int aes_buf_len;
310  ssize_t result_len;
311 
312  if (!(cph = gabe_enc(key->pub, m, (char*)policy)))
313  return GNUNET_SYSERR;
314  cph_buf_len = gabe_cph_serialize(cph,
315  &cph_buf);
316  gabe_cph_free(cph);
317  GNUNET_free(cph);
318  plt = GNUNET_memdup(block, size);
319  aes_buf_len = aes_128_cbc_encrypt(plt, size, m, &aes_buf);
320  GNUNET_free(plt);
321  element_clear(m);
322  result_len = write_cpabe(result, size, cph_buf, cph_buf_len, aes_buf, aes_buf_len);
323  GNUNET_free(cph_buf);
324  GNUNET_free(aes_buf);
325  return result_len;
326 }
#define GNUNET_memdup(buf, size)
Allocate and initialize a block of memory.
static struct GNUNET_ARM_MonitorHandle * m
Monitor connection with ARM.
Definition: gnunet-arm.c:99
static int result
Global testing status.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
static unsigned int size
Size of the "table".
Definition: peer.c:66
static ssize_t write_cpabe(void **result, uint32_t file_len, char *cph_buf, int cph_buf_len, char *aes_buf, int aes_buf_len)
Definition: abe.c:228
gabe_pub_t * pub
Definition: abe.c:37
static int aes_128_cbc_encrypt(char *pt, int size, element_t k, char **ct)
Definition: abe.c:79
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:

◆ GNUNET_ABE_cpabe_decrypt()

ssize_t GNUNET_ABE_cpabe_decrypt ( const void *  block,
size_t  size,
const struct GNUNET_ABE_AbeKey key,
void **  result 
)

Decrypt a block using the ABE key.

Parameters
blockthe block to encrypt
sizethe size of the block
keythe key used to decrypt
resultthe result buffer. Will be allocated. Free using GNUNET_free
Returns
the size of the encrypted block, -1 for errors

Definition at line 339 of file abe.c.

References aes_128_cbc_decrypt(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_log, GNUNET_SYSERR, m, GNUNET_ABE_AbeKey::prv, GNUNET_ABE_AbeKey::pub, and read_cpabe().

343 {
344  char* aes_buf;
345  char* cph_buf;
346  gabe_cph_t* cph;
347  element_t m;
348  int cph_buf_size;
349  int aes_buf_size;
350  int plt_len;
351 
352  read_cpabe(block, &cph_buf, &cph_buf_size, &aes_buf, &aes_buf_size);
353  cph = gabe_cph_unserialize(key->pub, cph_buf, cph_buf_size);
354  if (!gabe_dec(key->pub, key->prv, cph, m))
355  {
357  "%s\n", gabe_error());
358  GNUNET_free(aes_buf);
359  GNUNET_free(cph_buf);
360  gabe_cph_free(cph);
361  GNUNET_free(cph);
362  element_clear(m);
363  return GNUNET_SYSERR;
364  }
365  gabe_cph_free(cph);
366  GNUNET_free(cph);
367  plt_len = aes_128_cbc_decrypt(aes_buf, aes_buf_size, m, (char**)result);
368  GNUNET_free(cph_buf);
369  GNUNET_free(aes_buf);
370  element_clear(m);
371  //freeing is buggy in gabe
372  //gabe_prv_free (prv);
373  //gabe_pub_free (pub);
374  return plt_len;
375 }
gabe_pub_t * pub
Definition: abe.c:42
static int aes_128_cbc_decrypt(char *ct, int size, element_t k, char **pt)
Definition: abe.c:116
static struct GNUNET_ARM_MonitorHandle * m
Monitor connection with ARM.
Definition: gnunet-arm.c:99
static int result
Global testing status.
gabe_prv_t * prv
Definition: abe.c:43
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
#define GNUNET_log(kind,...)
static ssize_t read_cpabe(const void *data, char **cph_buf, int *cph_buf_len, char **aes_buf, int *aes_buf_len)
Definition: abe.c:256
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:

◆ GNUNET_ABE_cpabe_serialize_key()

ssize_t GNUNET_ABE_cpabe_serialize_key ( const struct GNUNET_ABE_AbeKey key,
void **  result 
)

Serialize an ABE key.

Parameters
keythe key to serialize
resultthe result buffer. Will be allocated. Free using GNUNET_free
Returns
the size of the encrypted block, -1 for errors

Definition at line 386 of file abe.c.

References GNUNET_free, len, GNUNET_ABE_AbeKey::prv, GNUNET_ABE_AbeMasterKey::pub, GNUNET_ABE_AbeKey::pub, and write_cpabe().

388 {
389  ssize_t len;
390  char *pub;
391  char *prv;
392  int pub_len;
393  int prv_len;
394 
395  pub_len = gabe_pub_serialize(key->pub, &pub);
396  prv_len = gabe_prv_serialize(key->prv, &prv);
397 
398  len = pub_len + prv_len + 12;
399  write_cpabe(result, len, pub, pub_len, prv, prv_len);
400 
401  GNUNET_free(pub);
402  GNUNET_free(prv);
403 
404  return len;
405 }
gabe_pub_t * pub
Definition: abe.c:42
static int result
Global testing status.
gabe_prv_t * prv
Definition: abe.c:43
static ssize_t write_cpabe(void **result, uint32_t file_len, char *cph_buf, int cph_buf_len, char *aes_buf, int aes_buf_len)
Definition: abe.c:228
static struct GNUNET_CRYPTO_EddsaPublicKey pub
Definition: gnunet-scrypt.c:39
#define GNUNET_free(ptr)
Wrapper around free.
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
Here is the call graph for this function:

◆ GNUNET_ABE_cpabe_deserialize_key()

struct GNUNET_ABE_AbeKey * GNUNET_ABE_cpabe_deserialize_key ( const void *  data,
size_t  len 
)

Deserialize a serialized ABE key.

Parameters
datathe data to deserialize
lenthe length of the data.
Returns
the ABE key. NULL of unsuccessful

Definition at line 416 of file abe.c.

References GNUNET_free, GNUNET_new, key, GNUNET_ABE_AbeKey::prv, GNUNET_ABE_AbeMasterKey::pub, GNUNET_ABE_AbeKey::pub, and read_cpabe().

418 {
419  struct GNUNET_ABE_AbeKey *key;
420  char *pub;
421  char *prv;
422  int prv_len;
423  int pub_len;
424 
425  key = GNUNET_new(struct GNUNET_ABE_AbeKey);
427  &pub,
428  &pub_len,
429  &prv,
430  &prv_len);
431  key->pub = gabe_pub_unserialize(pub, pub_len);
432  key->prv = gabe_prv_unserialize(key->pub, prv, prv_len);
433 
434  GNUNET_free(pub);
435  GNUNET_free(prv);
436  return key;
437 }
gabe_pub_t * pub
Definition: abe.c:42
#define GNUNET_new(type)
Allocate a struct or union of the given type.
gabe_prv_t * prv
Definition: abe.c:43
struct GNUNET_HashCode key
The key used in the DHT.
static struct GNUNET_CRYPTO_EddsaPublicKey pub
Definition: gnunet-scrypt.c:39
static ssize_t read_cpabe(const void *data, char **cph_buf, int *cph_buf_len, char **aes_buf, int *aes_buf_len)
Definition: abe.c:256
uint32_t data
The data value.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:

◆ GNUNET_ABE_cpabe_serialize_master_key()

ssize_t GNUNET_ABE_cpabe_serialize_master_key ( const struct GNUNET_ABE_AbeMasterKey key,
void **  result 
)

Serialize an ABE master key.

Parameters
keythe key to serialize
resultthe result buffer. Will be allocated. Free using GNUNET_free
Returns
the size of the encrypted block, -1 for errors

Definition at line 448 of file abe.c.

References GNUNET_free, len, GNUNET_ABE_AbeMasterKey::msk, GNUNET_ABE_AbeMasterKey::pub, and write_cpabe().

450 {
451  ssize_t len;
452  char *pub;
453  char *msk;
454  int pub_len;
455  int msk_len;
456 
457  pub_len = gabe_pub_serialize(key->pub, &pub);
458  msk_len = gabe_msk_serialize(key->msk, &msk);
459 
460  len = pub_len + msk_len + 12;
461  write_cpabe(result, len, pub, pub_len, msk, msk_len);
462 
463  GNUNET_free(pub);
464  GNUNET_free(msk);
465 
466  return len;
467 }
gabe_msk_t * msk
Definition: abe.c:38
static int result
Global testing status.
static ssize_t write_cpabe(void **result, uint32_t file_len, char *cph_buf, int cph_buf_len, char *aes_buf, int aes_buf_len)
Definition: abe.c:228
gabe_pub_t * pub
Definition: abe.c:37
static struct GNUNET_CRYPTO_EddsaPublicKey pub
Definition: gnunet-scrypt.c:39
#define GNUNET_free(ptr)
Wrapper around free.
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
Here is the call graph for this function:

◆ GNUNET_ABE_cpabe_deserialize_master_key()

struct GNUNET_ABE_AbeMasterKey * GNUNET_ABE_cpabe_deserialize_master_key ( const void *  data,
size_t  len 
)

Deserialize an ABE master key.

Parameters
datathe data to deserialize
lenthe length of the data.
Returns
the ABE key. NULL of unsuccessful

Definition at line 478 of file abe.c.

References GNUNET_free, GNUNET_new, key, GNUNET_ABE_AbeMasterKey::msk, GNUNET_ABE_AbeMasterKey::pub, and read_cpabe().

480 {
482  char *msk;
483  char *pub;
484  int msk_len;
485  int pub_len;
486 
487  key = GNUNET_new(struct GNUNET_ABE_AbeMasterKey);
489  &pub,
490  &pub_len,
491  &msk,
492  &msk_len);
493  key->pub = gabe_pub_unserialize(pub, pub_len);
494  key->msk = gabe_msk_unserialize(key->pub, msk, msk_len);
495 
496  GNUNET_free(pub);
497  GNUNET_free(msk);
498 
499  return key;
500 }
gabe_msk_t * msk
Definition: abe.c:38
#define GNUNET_new(type)
Allocate a struct or union of the given type.
struct GNUNET_HashCode key
The key used in the DHT.
gabe_pub_t * pub
Definition: abe.c:37
static struct GNUNET_CRYPTO_EddsaPublicKey pub
Definition: gnunet-scrypt.c:39
static ssize_t read_cpabe(const void *data, char **cph_buf, int *cph_buf_len, char **aes_buf, int *aes_buf_len)
Definition: abe.c:256
uint32_t data
The data value.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function: