GNUnet  0.11.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 161 of file abe.c.

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

162 {
164 
165  key = GNUNET_new (struct GNUNET_ABE_AbeMasterKey);
166  gabe_setup (&key->pub, &key->msk);
167  GNUNET_assert (NULL != key->pub);
168  GNUNET_assert (NULL != key->msk);
169  return key;
170 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
gabe_msk_t * msk
Definition: abe.c:39
#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:38

◆ 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 181 of file abe.c.

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

182 {
183  gabe_msk_free (key->msk);
184  gabe_pub_free (key->pub);
185  // GNUNET_free (key->msk);
186  // gabe_msk_free (key->msk); //For some reason free of pub implicit?
187  GNUNET_free (key);
188 }
gabe_msk_t * msk
Definition: abe.c:39
gabe_pub_t * pub
Definition: abe.c:38
#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 200 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.

202 {
203  struct GNUNET_ABE_AbeKey *prv_key;
204  int size;
205  char *tmp;
206 
207  prv_key = GNUNET_new (struct GNUNET_ABE_AbeKey);
208  prv_key->prv = gabe_keygen (key->pub, key->msk, attrs);
209  size = gabe_pub_serialize (key->pub, &tmp);
210  prv_key->pub = gabe_pub_unserialize (tmp, size);
211  GNUNET_free (tmp);
212  GNUNET_assert (NULL != prv_key->prv);
213  return prv_key;
214 }
gabe_pub_t * pub
Definition: abe.c:44
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
gabe_msk_t * msk
Definition: abe.c:39
#define GNUNET_new(type)
Allocate a struct or union of the given type.
gabe_prv_t * prv
Definition: abe.c:45
static unsigned int size
Size of the "table".
Definition: peer.c:67
gabe_pub_t * pub
Definition: abe.c:38
#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 226 of file abe.c.

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

228 {
229  // Memory management in gabe is buggy
230  gabe_prv_free (key->prv);
231  if (GNUNET_YES == delete_pub)
232  gabe_pub_free (key->pub);
233  GNUNET_free (key);
234 }
gabe_pub_t * pub
Definition: abe.c:44
gabe_prv_t * prv
Definition: abe.c:45
#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 309 of file abe.c.

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

314 {
315  gabe_cph_t*cph;
316  char*plt;
317  char*cph_buf;
318  char*aes_buf;
319  element_t m;
320  int cph_buf_len;
321  int aes_buf_len;
322  ssize_t result_len;
323 
324  if (! (cph = gabe_enc (key->pub, m, (char*) policy)))
325  return GNUNET_SYSERR;
326  cph_buf_len = gabe_cph_serialize (cph,
327  &cph_buf);
328  gabe_cph_free (cph);
329  GNUNET_free (cph);
330  plt = GNUNET_memdup (block, size);
331  aes_buf_len = aes_128_cbc_encrypt (plt, size, m, &aes_buf);
332  GNUNET_free (plt);
333  element_clear (m);
334  result_len = write_cpabe (result, size, cph_buf, cph_buf_len, aes_buf,
335  aes_buf_len);
336  GNUNET_free (cph_buf);
337  GNUNET_free (aes_buf);
338  return result_len;
339 }
#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:104
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:67
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:238
gabe_pub_t * pub
Definition: abe.c:38
static int aes_128_cbc_encrypt(char *pt, int size, element_t k, char **ct)
Definition: abe.c:82
#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 353 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().

357 {
358  char*aes_buf;
359  char*cph_buf;
360  gabe_cph_t*cph;
361  element_t m;
362  int cph_buf_size;
363  int aes_buf_size;
364  int plt_len;
365 
366  read_cpabe (block, &cph_buf, &cph_buf_size, &aes_buf, &aes_buf_size);
367  cph = gabe_cph_unserialize (key->pub, cph_buf, cph_buf_size);
368  if (! gabe_dec (key->pub, key->prv, cph, m))
369  {
371  "%s\n", gabe_error ());
372  GNUNET_free (aes_buf);
373  GNUNET_free (cph_buf);
374  gabe_cph_free (cph);
375  GNUNET_free (cph);
376  element_clear (m);
377  return GNUNET_SYSERR;
378  }
379  gabe_cph_free (cph);
380  GNUNET_free (cph);
381  plt_len = aes_128_cbc_decrypt (aes_buf, aes_buf_size, m, (char**) result);
382  GNUNET_free (cph_buf);
383  GNUNET_free (aes_buf);
384  element_clear (m);
385  // freeing is buggy in gabe
386  // gabe_prv_free (prv);
387  // gabe_pub_free (pub);
388  return plt_len;
389 }
gabe_pub_t * pub
Definition: abe.c:44
static int aes_128_cbc_decrypt(char *ct, int size, element_t k, char **pt)
Definition: abe.c:121
static struct GNUNET_ARM_MonitorHandle * m
Monitor connection with ARM.
Definition: gnunet-arm.c:104
static int result
Global testing status.
gabe_prv_t * prv
Definition: abe.c:45
#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:267
#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 401 of file abe.c.

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

403 {
404  ssize_t len;
405  char *pub;
406  char *prv;
407  int pub_len;
408  int prv_len;
409 
410  pub_len = gabe_pub_serialize (key->pub, &pub);
411  prv_len = gabe_prv_serialize (key->prv, &prv);
412 
413  len = pub_len + prv_len + 12;
414  write_cpabe (result, len, pub, pub_len, prv, prv_len);
415 
416  GNUNET_free (pub);
417  GNUNET_free (prv);
418 
419  return len;
420 }
gabe_pub_t * pub
Definition: abe.c:44
static int result
Global testing status.
gabe_prv_t * prv
Definition: abe.c:45
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:238
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 432 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().

434 {
435  struct GNUNET_ABE_AbeKey *key;
436  char *pub;
437  char *prv;
438  int prv_len;
439  int pub_len;
440 
441  key = GNUNET_new (struct GNUNET_ABE_AbeKey);
442  read_cpabe (data,
443  &pub,
444  &pub_len,
445  &prv,
446  &prv_len);
447  key->pub = gabe_pub_unserialize (pub, pub_len);
448  key->prv = gabe_prv_unserialize (key->pub, prv, prv_len);
449 
450  GNUNET_free (pub);
451  GNUNET_free (prv);
452  return key;
453 }
gabe_pub_t * pub
Definition: abe.c:44
#define GNUNET_new(type)
Allocate a struct or union of the given type.
gabe_prv_t * prv
Definition: abe.c:45
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:267
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 465 of file abe.c.

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

468 {
469  ssize_t len;
470  char *pub;
471  char *msk;
472  int pub_len;
473  int msk_len;
474 
475  pub_len = gabe_pub_serialize (key->pub, &pub);
476  msk_len = gabe_msk_serialize (key->msk, &msk);
477 
478  len = pub_len + msk_len + 12;
479  write_cpabe (result, len, pub, pub_len, msk, msk_len);
480 
481  GNUNET_free (pub);
482  GNUNET_free (msk);
483 
484  return len;
485 }
gabe_msk_t * msk
Definition: abe.c:39
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:238
gabe_pub_t * pub
Definition: abe.c:38
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 497 of file abe.c.

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

499 {
501  char *msk;
502  char *pub;
503  int msk_len;
504  int pub_len;
505 
506  key = GNUNET_new (struct GNUNET_ABE_AbeMasterKey);
507  read_cpabe (data,
508  &pub,
509  &pub_len,
510  &msk,
511  &msk_len);
512  key->pub = gabe_pub_unserialize (pub, pub_len);
513  key->msk = gabe_msk_unserialize (key->pub, msk, msk_len);
514 
515  GNUNET_free (pub);
516  GNUNET_free (msk);
517 
518  return key;
519 }
gabe_msk_t * msk
Definition: abe.c:39
#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:38
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:267
uint32_t data
The data value.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function: