GNUnet  0.11.x
Data Structures | Functions
crypto_abe.c File Reference
#include "platform.h"
#include <pbc/pbc.h>
#include <gabe.h>
#include "gnunet_crypto_lib.h"
Include dependency graph for crypto_abe.c:

Go to the source code of this file.

Data Structures

struct  GNUNET_CRYPTO_AbeMasterKey
 
struct  GNUNET_CRYPTO_AbeKey
 

Functions

static int init_aes (element_t k, int enc, gcry_cipher_hd_t *handle, struct GNUNET_CRYPTO_SymmetricSessionKey *key, unsigned char *iv)
 
static int aes_128_cbc_encrypt (char *pt, int size, element_t k, char **ct)
 
static int aes_128_cbc_decrypt (char *ct, int size, element_t k, char **pt)
 
struct GNUNET_CRYPTO_AbeMasterKeyGNUNET_CRYPTO_cpabe_create_master_key (void)
 
void GNUNET_CRYPTO_cpabe_delete_master_key (struct GNUNET_CRYPTO_AbeMasterKey *key)
 
struct GNUNET_CRYPTO_AbeKeyGNUNET_CRYPTO_cpabe_create_key (struct GNUNET_CRYPTO_AbeMasterKey *key, char **attrs)
 
void GNUNET_CRYPTO_cpabe_delete_key (struct GNUNET_CRYPTO_AbeKey *key, int delete_pub)
 
ssize_t write_cpabe (void **result, uint32_t file_len, char *cph_buf, int cph_buf_len, char *aes_buf, int aes_buf_len)
 
ssize_t read_cpabe (const void *data, char **cph_buf, int *cph_buf_len, char **aes_buf, int *aes_buf_len)
 
ssize_t GNUNET_CRYPTO_cpabe_encrypt (const void *block, size_t size, const char *policy, const struct GNUNET_CRYPTO_AbeMasterKey *key, void **result)
 
ssize_t GNUNET_CRYPTO_cpabe_decrypt (const void *block, size_t size, const struct GNUNET_CRYPTO_AbeKey *key, void **result)
 
ssize_t GNUNET_CRYPTO_cpabe_serialize_key (const struct GNUNET_CRYPTO_AbeKey *key, void **result)
 
struct GNUNET_CRYPTO_AbeKeyGNUNET_CRYPTO_cpabe_deserialize_key (const void *data, size_t len)
 
ssize_t GNUNET_CRYPTO_cpabe_serialize_master_key (const struct GNUNET_CRYPTO_AbeMasterKey *key, void **result)
 
struct GNUNET_CRYPTO_AbeMasterKeyGNUNET_CRYPTO_cpabe_deserialize_master_key (const void *data, size_t len)
 

Function Documentation

◆ init_aes()

static int init_aes ( element_t  k,
int  enc,
gcry_cipher_hd_t *  handle,
struct GNUNET_CRYPTO_SymmetricSessionKey key,
unsigned char *  iv 
)
static

Definition at line 48 of file crypto_abe.c.

References GNUNET_CRYPTO_SymmetricSessionKey::aes_key, GNUNET_assert, GNUNET_CRYPTO_AES_KEY_LENGTH, and GNUNET_memcpy.

Referenced by aes_128_cbc_decrypt(), and aes_128_cbc_encrypt().

52 {
53  int rc;
54  int key_len;
55  unsigned char*key_buf;
56 
57  key_len = element_length_in_bytes (k) < 33 ? 3 : element_length_in_bytes (k);
58  key_buf = (unsigned char*) malloc (key_len);
59  element_to_bytes (key_buf, k);
60 
61  GNUNET_memcpy (key->aes_key,
62  key_buf,
64  GNUNET_assert (0 ==
65  gcry_cipher_open (handle, GCRY_CIPHER_AES256,
66  GCRY_CIPHER_MODE_CFB, 0));
67  rc = gcry_cipher_setkey (*handle,
68  key->aes_key,
69  sizeof(key->aes_key));
70  GNUNET_assert ((0 == rc) || ((char) rc == GPG_ERR_WEAK_KEY));
71  memset (iv, 0, 16); // TODO make reasonable
72  rc = gcry_cipher_setiv (*handle,
73  iv,
74  16);
75  GNUNET_assert ((0 == rc) || ((char) rc == GPG_ERR_WEAK_KEY));
76 
77  free (key_buf);
78  return rc;
79 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
unsigned char aes_key[(256/8)]
Actual key for AES.
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
#define GNUNET_CRYPTO_AES_KEY_LENGTH
length of the sessionkey in bytes (256 BIT sessionkey)
Here is the caller graph for this function:

◆ aes_128_cbc_encrypt()

static int aes_128_cbc_encrypt ( char *  pt,
int  size,
element_t  k,
char **  ct 
)
static

Definition at line 83 of file crypto_abe.c.

References buf, GNUNET_assert, GNUNET_free, GNUNET_malloc, GNUNET_memcpy, handle, init_aes(), len, and size.

Referenced by GNUNET_CRYPTO_cpabe_encrypt().

87 {
88  gcry_cipher_hd_t handle;
90  unsigned char iv[16];
91  char*buf;
92  int padding;
93  int buf_size;
94  uint8_t len[4];
95 
96  init_aes (k, 1, &handle, &skey, iv);
97 
98  /* TODO make less crufty */
99 
100  /* stuff in real length (big endian) before padding */
101  len[0] = (size & 0xff000000) >> 24;
102  len[1] = (size & 0xff0000) >> 16;
103  len[2] = (size & 0xff00) >> 8;
104  len[3] = (size & 0xff) >> 0;
105  padding = 16 - ((4 + size) % 16);
106  buf_size = 4 + size + padding;
107  buf = GNUNET_malloc (buf_size);
108  GNUNET_memcpy (buf, len, 4);
109  GNUNET_memcpy (buf + 4, pt, size);
110  *ct = GNUNET_malloc (buf_size);
111 
112  GNUNET_assert (0 == gcry_cipher_encrypt (handle, *ct, buf_size, buf,
113  buf_size));
114  gcry_cipher_close (handle);
115  // AES_cbc_encrypt(pt->data, ct->data, pt->len, &key, iv, AES_ENCRYPT);
116  GNUNET_free (buf);
117  return buf_size;
118 }
static int init_aes(element_t k, int enc, gcry_cipher_hd_t *handle, struct GNUNET_CRYPTO_SymmetricSessionKey *key, unsigned char *iv)
Definition: crypto_abe.c:48
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
static char buf[2048]
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
static unsigned int size
Size of the "table".
Definition: peer.c:67
#define GNUNET_malloc(size)
Wrapper around malloc.
#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:
Here is the caller graph for this function:

◆ aes_128_cbc_decrypt()

static int aes_128_cbc_decrypt ( char *  ct,
int  size,
element_t  k,
char **  pt 
)
static

Definition at line 122 of file crypto_abe.c.

References GNUNET_assert, GNUNET_free, GNUNET_malloc, GNUNET_memcpy, handle, init_aes(), and len.

Referenced by GNUNET_CRYPTO_cpabe_decrypt().

126 {
128  gcry_cipher_hd_t handle;
129  unsigned char iv[16];
130  char*tmp;
131  uint32_t len;
132 
133  init_aes (k, 1, &handle, &skey, iv);
134 
135  tmp = GNUNET_malloc (size);
136 
137  // AES_cbc_encrypt(ct->data, pt->data, ct->len, &key, iv, AES_DECRYPT);
138  GNUNET_assert (0 == gcry_cipher_decrypt (handle, tmp, size, ct, size));
139  gcry_cipher_close (handle);
140  /* TODO make less crufty */
141 
142  /* get real length */
143  len = 0;
144  len = len
145  | ((tmp[0]) << 24) | ((tmp[1]) << 16)
146  | ((tmp[2]) << 8) | ((tmp[3]) << 0);
147  /* truncate any garbage from the padding */
148  *pt = GNUNET_malloc (len);
149  GNUNET_memcpy (*pt, tmp + 4, len);
150  GNUNET_free (tmp);
151  return len;
152 }
static int init_aes(element_t k, int enc, gcry_cipher_hd_t *handle, struct GNUNET_CRYPTO_SymmetricSessionKey *key, unsigned char *iv)
Definition: crypto_abe.c:48
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
static unsigned int size
Size of the "table".
Definition: peer.c:67
#define GNUNET_malloc(size)
Wrapper around malloc.
#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:
Here is the caller graph for this function:

◆ GNUNET_CRYPTO_cpabe_create_master_key()

struct GNUNET_CRYPTO_AbeMasterKey* GNUNET_CRYPTO_cpabe_create_master_key ( void  )

Definition at line 156 of file crypto_abe.c.

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

157 {
159 
160  key = GNUNET_new (struct GNUNET_CRYPTO_AbeMasterKey);
161  gabe_setup (&key->pub, &key->msk);
162  GNUNET_assert (NULL != key->pub);
163  GNUNET_assert (NULL != key->msk);
164  return key;
165 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
struct GNUNET_HashCode key
The key used in the DHT.

◆ GNUNET_CRYPTO_cpabe_delete_master_key()

void GNUNET_CRYPTO_cpabe_delete_master_key ( struct GNUNET_CRYPTO_AbeMasterKey key)

Definition at line 169 of file crypto_abe.c.

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

170 {
171  gabe_msk_free (key->msk);
172  gabe_pub_free (key->pub);
173  // GNUNET_free (key->msk);
174  // gabe_msk_free (key->msk); //For some reason free of pub implicit?
175  GNUNET_free (key);
176 }
#define GNUNET_free(ptr)
Wrapper around free.

◆ GNUNET_CRYPTO_cpabe_create_key()

struct GNUNET_CRYPTO_AbeKey* GNUNET_CRYPTO_cpabe_create_key ( struct GNUNET_CRYPTO_AbeMasterKey key,
char **  attrs 
)

Definition at line 180 of file crypto_abe.c.

References GNUNET_assert, GNUNET_free, GNUNET_new, GNUNET_CRYPTO_AbeMasterKey::msk, GNUNET_CRYPTO_AbeKey::prv, GNUNET_CRYPTO_AbeMasterKey::pub, GNUNET_CRYPTO_AbeKey::pub, and size.

182 {
183  struct GNUNET_CRYPTO_AbeKey *prv_key;
184  int size;
185  char *tmp;
186 
187  prv_key = GNUNET_new (struct GNUNET_CRYPTO_AbeKey);
188  prv_key->prv = gabe_keygen (key->pub, key->msk, attrs);
189  size = gabe_pub_serialize (key->pub, &tmp);
190  prv_key->pub = gabe_pub_unserialize (tmp, size);
191  GNUNET_free (tmp);
192  GNUNET_assert (NULL != prv_key->prv);
193  return prv_key;
194 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
gabe_pub_t * pub
Definition: crypto_abe.c:43
static unsigned int size
Size of the "table".
Definition: peer.c:67
gabe_prv_t * prv
Definition: crypto_abe.c:44
#define GNUNET_free(ptr)
Wrapper around free.

◆ GNUNET_CRYPTO_cpabe_delete_key()

void GNUNET_CRYPTO_cpabe_delete_key ( struct GNUNET_CRYPTO_AbeKey key,
int  delete_pub 
)

Definition at line 198 of file crypto_abe.c.

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

200 {
201  // Memory management in gabe is buggy
202  gabe_prv_free (key->prv);
203  if (GNUNET_YES == delete_pub)
204  gabe_pub_free (key->pub);
205  GNUNET_free (key);
206 }
gabe_pub_t * pub
Definition: crypto_abe.c:43
gabe_prv_t * prv
Definition: crypto_abe.c:44
#define GNUNET_YES
Definition: gnunet_common.h:77
#define GNUNET_free(ptr)
Wrapper around free.

◆ write_cpabe()

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 at line 210 of file crypto_abe.c.

References GNUNET_malloc, GNUNET_memcpy, len, and result.

Referenced by GNUNET_CRYPTO_cpabe_encrypt(), GNUNET_CRYPTO_cpabe_serialize_key(), and GNUNET_CRYPTO_cpabe_serialize_master_key().

216 {
217  char *ptr;
218  uint32_t *len;
219 
220  *result = GNUNET_malloc (12 + cph_buf_len + aes_buf_len);
221  ptr = *result;
222  len = (uint32_t*) ptr;
223  *len = htonl (file_len);
224  ptr += 4;
225  len = (uint32_t*) ptr;
226  *len = htonl (aes_buf_len);
227  ptr += 4;
228  GNUNET_memcpy (ptr, aes_buf, aes_buf_len);
229  ptr += aes_buf_len;
230  len = (uint32_t*) ptr;
231  *len = htonl (cph_buf_len);
232  ptr += 4;
233  GNUNET_memcpy (ptr, cph_buf, cph_buf_len);
234  return 12 + cph_buf_len + aes_buf_len;
235 }
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
static int result
Global testing status.
#define GNUNET_malloc(size)
Wrapper around malloc.
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 caller graph for this function:

◆ read_cpabe()

ssize_t read_cpabe ( const void *  data,
char **  cph_buf,
int *  cph_buf_len,
char **  aes_buf,
int *  aes_buf_len 
)

Definition at line 239 of file crypto_abe.c.

References GNUNET_malloc, GNUNET_memcpy, and len.

Referenced by GNUNET_CRYPTO_cpabe_decrypt(), GNUNET_CRYPTO_cpabe_deserialize_key(), and GNUNET_CRYPTO_cpabe_deserialize_master_key().

244 {
245  int buf_len;
246  char *ptr;
247  uint32_t *len;
248 
249  ptr = (char*) data;
250  len = (uint32_t*) ptr;
251  buf_len = ntohl (*len);
252  ptr += 4;
253  len = (uint32_t*) ptr;
254  *aes_buf_len = ntohl (*len);
255  ptr += 4;
256  *aes_buf = GNUNET_malloc (*aes_buf_len);
257  GNUNET_memcpy (*aes_buf, ptr, *aes_buf_len);
258  ptr += *aes_buf_len;
259  len = (uint32_t*) ptr;
260  *cph_buf_len = ntohl (*len);
261  ptr += 4;
262  *cph_buf = GNUNET_malloc (*cph_buf_len);
263  GNUNET_memcpy (*cph_buf, ptr, *cph_buf_len);
264 
265  return buf_len;
266 }
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
uint32_t data
The data value.
#define GNUNET_malloc(size)
Wrapper around malloc.
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 caller graph for this function:

◆ GNUNET_CRYPTO_cpabe_encrypt()

ssize_t GNUNET_CRYPTO_cpabe_encrypt ( const void *  block,
size_t  size,
const char *  policy,
const struct GNUNET_CRYPTO_AbeMasterKey key,
void **  result 
)

Definition at line 270 of file crypto_abe.c.

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

275 {
276  gabe_cph_t*cph;
277  char*plt;
278  char*cph_buf;
279  char*aes_buf;
280  element_t m;
281  int cph_buf_len;
282  int aes_buf_len;
283  ssize_t result_len;
284 
285  if (! (cph = gabe_enc (key->pub, m, (char*) policy)))
286  return GNUNET_SYSERR;
287  cph_buf_len = gabe_cph_serialize (cph,
288  &cph_buf);
289  gabe_cph_free (cph);
290  GNUNET_free (cph);
291  plt = GNUNET_memdup (block, size);
292  aes_buf_len = aes_128_cbc_encrypt (plt, size, m, &aes_buf);
293  GNUNET_free (plt);
294  element_clear (m);
295  result_len = write_cpabe (result, size, cph_buf, cph_buf_len, aes_buf,
296  aes_buf_len);
297  GNUNET_free (cph_buf);
298  GNUNET_free (aes_buf);
299  return result_len;
300 }
static int aes_128_cbc_encrypt(char *pt, int size, element_t k, char **ct)
Definition: crypto_abe.c:83
#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
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: crypto_abe.c:210
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
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:

◆ GNUNET_CRYPTO_cpabe_decrypt()

ssize_t GNUNET_CRYPTO_cpabe_decrypt ( const void *  block,
size_t  size,
const struct GNUNET_CRYPTO_AbeKey key,
void **  result 
)

Definition at line 304 of file crypto_abe.c.

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

308 {
309  char*aes_buf;
310  char*cph_buf;
311  gabe_cph_t*cph;
312  element_t m;
313  int cph_buf_size;
314  int aes_buf_size;
315  int plt_len;
316 
317  read_cpabe (block, &cph_buf, &cph_buf_size, &aes_buf, &aes_buf_size);
318  cph = gabe_cph_unserialize (key->pub, cph_buf, cph_buf_size);
319  if (! gabe_dec (key->pub, key->prv, cph, m))
320  {
322  "%s\n", gabe_error ());
323  GNUNET_free (aes_buf);
324  GNUNET_free (cph_buf);
325  gabe_cph_free (cph);
326  GNUNET_free (cph);
327  element_clear (m);
328  return GNUNET_SYSERR;
329  }
330  gabe_cph_free (cph);
331  GNUNET_free (cph);
332  plt_len = aes_128_cbc_decrypt (aes_buf, aes_buf_size, m, (char**) result);
333  GNUNET_free (cph_buf);
334  GNUNET_free (aes_buf);
335  element_clear (m);
336  // freeing is buggy in gabe
337  // gabe_prv_free (prv);
338  // gabe_pub_free (pub);
339  return plt_len;
340 }
ssize_t read_cpabe(const void *data, char **cph_buf, int *cph_buf_len, char **aes_buf, int *aes_buf_len)
Definition: crypto_abe.c:239
static struct GNUNET_ARM_MonitorHandle * m
Monitor connection with ARM.
Definition: gnunet-arm.c:104
static int aes_128_cbc_decrypt(char *ct, int size, element_t k, char **pt)
Definition: crypto_abe.c:122
gabe_pub_t * pub
Definition: crypto_abe.c:43
static int result
Global testing status.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
#define GNUNET_log(kind,...)
gabe_prv_t * prv
Definition: crypto_abe.c:44
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:

◆ GNUNET_CRYPTO_cpabe_serialize_key()

ssize_t GNUNET_CRYPTO_cpabe_serialize_key ( const struct GNUNET_CRYPTO_AbeKey key,
void **  result 
)

Definition at line 344 of file crypto_abe.c.

References GNUNET_free, len, GNUNET_CRYPTO_AbeKey::prv, GNUNET_CRYPTO_AbeMasterKey::pub, GNUNET_CRYPTO_AbeKey::pub, and write_cpabe().

346 {
347  ssize_t len;
348  char *pub;
349  char *prv;
350  int pub_len;
351  int prv_len;
352 
353  pub_len = gabe_pub_serialize (key->pub, &pub);
354  prv_len = gabe_prv_serialize (key->prv, &prv);
355 
356  len = pub_len + prv_len + 12;
357  write_cpabe (result, len, pub, pub_len, prv, prv_len);
358 
359  GNUNET_free (pub);
360  GNUNET_free (prv);
361 
362  return len;
363 }
gabe_pub_t * pub
Definition: crypto_abe.c:43
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: crypto_abe.c:210
static int result
Global testing status.
static struct GNUNET_CRYPTO_EddsaPublicKey pub
Definition: gnunet-scrypt.c:39
gabe_prv_t * prv
Definition: crypto_abe.c:44
#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_CRYPTO_cpabe_deserialize_key()

struct GNUNET_CRYPTO_AbeKey* GNUNET_CRYPTO_cpabe_deserialize_key ( const void *  data,
size_t  len 
)

Definition at line 367 of file crypto_abe.c.

References GNUNET_free, GNUNET_new, key, GNUNET_CRYPTO_AbeKey::prv, GNUNET_CRYPTO_AbeMasterKey::pub, GNUNET_CRYPTO_AbeKey::pub, and read_cpabe().

369 {
370  struct GNUNET_CRYPTO_AbeKey *key;
371  char *pub;
372  char *prv;
373  int prv_len;
374  int pub_len;
375 
376  key = GNUNET_new (struct GNUNET_CRYPTO_AbeKey);
377  read_cpabe (data,
378  &pub,
379  &pub_len,
380  &prv,
381  &prv_len);
382  key->pub = gabe_pub_unserialize (pub, pub_len);
383  key->prv = gabe_prv_unserialize (key->pub, prv, prv_len);
384 
385  GNUNET_free (pub);
386  GNUNET_free (prv);
387  return key;
388 }
ssize_t read_cpabe(const void *data, char **cph_buf, int *cph_buf_len, char **aes_buf, int *aes_buf_len)
Definition: crypto_abe.c:239
#define GNUNET_new(type)
Allocate a struct or union of the given type.
gabe_pub_t * pub
Definition: crypto_abe.c:43
struct GNUNET_HashCode key
The key used in the DHT.
static struct GNUNET_CRYPTO_EddsaPublicKey pub
Definition: gnunet-scrypt.c:39
gabe_prv_t * prv
Definition: crypto_abe.c:44
uint32_t data
The data value.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:

◆ GNUNET_CRYPTO_cpabe_serialize_master_key()

ssize_t GNUNET_CRYPTO_cpabe_serialize_master_key ( const struct GNUNET_CRYPTO_AbeMasterKey key,
void **  result 
)

Definition at line 392 of file crypto_abe.c.

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

395 {
396  ssize_t len;
397  char *pub;
398  char *msk;
399  int pub_len;
400  int msk_len;
401 
402  pub_len = gabe_pub_serialize (key->pub, &pub);
403  msk_len = gabe_msk_serialize (key->msk, &msk);
404 
405  len = pub_len + msk_len + 12;
406  write_cpabe (result, len, pub, pub_len, msk, msk_len);
407 
408  GNUNET_free (pub);
409  GNUNET_free (msk);
410 
411  return len;
412 }
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: crypto_abe.c:210
static int result
Global testing status.
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_CRYPTO_cpabe_deserialize_master_key()

struct GNUNET_CRYPTO_AbeMasterKey* GNUNET_CRYPTO_cpabe_deserialize_master_key ( const void *  data,
size_t  len 
)

Definition at line 416 of file crypto_abe.c.

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

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