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

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

157 {
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: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 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: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 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: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 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:44
gabe_prv_t * prv
Definition: abe.c:45
#define GNUNET_YES
Definition: gnunet_common.h:80
#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:79
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:228
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:81
#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) ) {
356  "%s\n", gabe_error());
357  GNUNET_free (aes_buf);
358  GNUNET_free (cph_buf);
359  gabe_cph_free(cph);
360  GNUNET_free (cph);
361  element_clear (m);
362  return GNUNET_SYSERR;
363  }
364  gabe_cph_free(cph);
365  GNUNET_free (cph);
366  plt_len = aes_128_cbc_decrypt(aes_buf, aes_buf_size, m, (char**)result);
367  GNUNET_free (cph_buf);
368  GNUNET_free (aes_buf);
369  element_clear (m);
370  //freeing is buggy in gabe
371  //gabe_prv_free (prv);
372  //gabe_pub_free (pub);
373  return plt_len;
374 }
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:117
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:45
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
#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 385 of file abe.c.

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

387 {
388  ssize_t len;
389  char *pub;
390  char *prv;
391  int pub_len;
392  int prv_len;
393 
394  pub_len = gabe_pub_serialize (key->pub, &pub);
395  prv_len = gabe_prv_serialize (key->prv, &prv);
396 
397  len = pub_len + prv_len + 12;
398  write_cpabe (result, len, pub, pub_len, prv, prv_len);
399 
400  GNUNET_free (pub);
401  GNUNET_free (prv);
402 
403  return len;
404 }
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: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 415 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().

417 {
418  struct GNUNET_ABE_AbeKey *key;
419  char *pub;
420  char *prv;
421  int prv_len;
422  int pub_len;
423 
424  key = GNUNET_new (struct GNUNET_ABE_AbeKey);
425  read_cpabe (data,
426  &pub,
427  &pub_len,
428  &prv,
429  &prv_len);
430  key->pub = gabe_pub_unserialize (pub, pub_len);
431  key->prv = gabe_prv_unserialize (key->pub, prv, prv_len);
432 
433  GNUNET_free (pub);
434  GNUNET_free (prv);
435  return key;
436 }
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: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 447 of file abe.c.

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

449 {
450  ssize_t len;
451  char *pub;
452  char *msk;
453  int pub_len;
454  int msk_len;
455 
456  pub_len = gabe_pub_serialize (key->pub, &pub);
457  msk_len = gabe_msk_serialize (key->msk, &msk);
458 
459  len = pub_len + msk_len + 12;
460  write_cpabe (result, len, pub, pub_len, msk, msk_len);
461 
462  GNUNET_free (pub);
463  GNUNET_free (msk);
464 
465  return len;
466 }
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:228
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 477 of file abe.c.

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

479 {
481  char *msk;
482  char *pub;
483  int msk_len;
484  int pub_len;
485 
486  key = GNUNET_new (struct GNUNET_ABE_AbeMasterKey);
487  read_cpabe (data,
488  &pub,
489  &pub_len,
490  &msk,
491  &msk_len);
492  key->pub = gabe_pub_unserialize (pub, pub_len);
493  key->msk = gabe_msk_unserialize (key->pub, msk, msk_len);
494 
495  GNUNET_free (pub);
496  GNUNET_free (msk);
497 
498  return key;
499 }
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:256
uint32_t data
The data value.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function: