[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] [gnunet] 99/171: -add free ABE functions
From: |
gnunet |
Subject: |
[GNUnet-SVN] [gnunet] 99/171: -add free ABE functions |
Date: |
Thu, 04 Jan 2018 16:10:07 +0100 |
This is an automated email from the git hooks/post-receive script.
martin-schanzenbach pushed a commit to branch master
in repository gnunet.
commit cfc492f5d6c7c5786bd5d033892238a6889b5d7d
Author: Schanzenbach, Martin <address@hidden>
AuthorDate: Sun Jul 9 19:23:26 2017 +0200
-add free ABE functions
---
src/include/gnunet_crypto_lib.h | 4 ++
src/util/crypto_abe.c | 87 +++++++++++++++++++++--------------------
2 files changed, 49 insertions(+), 42 deletions(-)
diff --git a/src/include/gnunet_crypto_lib.h b/src/include/gnunet_crypto_lib.h
index 4d00103ab..69f6ce5d4 100644
--- a/src/include/gnunet_crypto_lib.h
+++ b/src/include/gnunet_crypto_lib.h
@@ -2138,6 +2138,8 @@ GNUNET_CRYPTO_rsa_verify (const struct GNUNET_HashCode
*hash,
*/
struct GNUNET_CRYPTO_AbeMasterKey *
GNUNET_CRYPTO_cpabe_create_master_key (void);
+void
+GNUNET_CRYPTO_cpabe_delete_master_key (struct GNUNET_CRYPTO_AbeMasterKey *key);
/**
* @ingroup crypto
@@ -2148,6 +2150,8 @@ GNUNET_CRYPTO_cpabe_create_master_key (void);
struct GNUNET_CRYPTO_AbeKey *
GNUNET_CRYPTO_cpabe_create_key (struct GNUNET_CRYPTO_AbeMasterKey *msk,
char **attrs);
+void
+GNUNET_CRYPTO_cpabe_delete_key (struct GNUNET_CRYPTO_AbeKey *key);
/**
diff --git a/src/util/crypto_abe.c b/src/util/crypto_abe.c
index 38812b412..ddaec83eb 100644
--- a/src/util/crypto_abe.c
+++ b/src/util/crypto_abe.c
@@ -148,6 +148,14 @@ GNUNET_CRYPTO_cpabe_create_master_key (void)
return key;
}
+void
+GNUNET_CRYPTO_cpabe_delete_master_key (struct GNUNET_CRYPTO_AbeMasterKey *key)
+{
+ g_byte_array_unref (key->msk);
+ g_byte_array_unref (key->pub);
+ GNUNET_free (key);
+}
+
struct GNUNET_CRYPTO_AbeKey*
GNUNET_CRYPTO_cpabe_create_key (struct GNUNET_CRYPTO_AbeMasterKey *key,
char **attrs)
@@ -156,7 +164,6 @@ GNUNET_CRYPTO_cpabe_create_key (struct
GNUNET_CRYPTO_AbeMasterKey *key,
bswabe_pub_t* pub;
bswabe_msk_t* msk;
bswabe_prv_t* prv;
- gchar* pub_data;
gsize len;
pub = bswabe_pub_unserialize(key->pub, 0);
@@ -164,73 +171,69 @@ GNUNET_CRYPTO_cpabe_create_key (struct
GNUNET_CRYPTO_AbeMasterKey *key,
prv = bswabe_keygen(pub, msk, attrs);
prv_key = GNUNET_new (struct GNUNET_CRYPTO_AbeKey);
prv_key->prv = bswabe_prv_serialize(prv);
- pub_data = g_strndup ((gchar*)key->pub->data,
- key->pub->len);
+
len = key->pub->len;
- prv_key->pub = g_byte_array_new_take ((guint8*)pub_data, len);
+ printf ("Keylen %lu\n", len);
+ prv_key->pub = bswabe_pub_serialize (pub);
GNUNET_assert (NULL != prv_key->prv);
return prv_key;
}
+void
+GNUNET_CRYPTO_cpabe_delete_key (struct GNUNET_CRYPTO_AbeKey *key)
+{
+ g_byte_array_unref (key->prv);
+ g_byte_array_unref (key->pub);
+ GNUNET_free (key);
+}
+
ssize_t
write_cpabe (void **result, GByteArray* cph_buf,
- int file_len, GByteArray* aes_buf)
+ uint32_t file_len, GByteArray* aes_buf)
{
char *ptr;
- int i;
- ssize_t size;
- size = aes_buf->len + cph_buf->len + 12;
- *result = GNUNET_malloc (size);
+ uint32_t *len;
+
+ *result = GNUNET_malloc (12 + cph_buf->len + aes_buf->len);
ptr = *result;
- for(i=3; i >= 0; i--) {
- *ptr = (file_len & 0xff<<(i*8))>>(i*8);
- ptr++;
- }
- for(i=3; i >= 0; i--) {
- *ptr = (aes_buf->len & 0xff<<(i*8))>>(i*8);
- ptr++;
- }
+ len = (uint32_t*) ptr;
+ *len = htonl (file_len);
+ ptr += 4;
+ len = (uint32_t*) ptr;
+ *len = htonl (aes_buf->len);
+ ptr += 4;
memcpy (ptr, aes_buf->data, aes_buf->len);
ptr += aes_buf->len;
- for(i=3; i >= 0; i--) {
- *ptr = (cph_buf->len & 0xff<<(i*8))>>(i*8);
- ptr++;
- }
+ len = (uint32_t*) ptr;
+ *len = htonl (cph_buf->len);
+ ptr += 4;
memcpy (ptr, cph_buf->data, cph_buf->len);
- return size;
+ return 12 + cph_buf->len + aes_buf->len;
}
ssize_t
read_cpabe (const void *data, GByteArray** cph_buf, GByteArray** aes_buf)
{
- int i;
- ssize_t buf_len;
- ssize_t tmp_len;
+ int buf_len;
+ int tmp_len;
char *ptr;
+ uint32_t *len;
*cph_buf = g_byte_array_new();
*aes_buf = g_byte_array_new();
ptr = (char*)data;
-
- buf_len = 0;
- for(i=3; i >= 0; i--) {
- buf_len |= *ptr<<(i*8);
- ptr++;
- }
-
- tmp_len = 0;
- for(i=3; i >= 0; i--) {
- tmp_len |= *ptr<<(i*8);
- ptr++;
- }
+ len = (uint32_t*)ptr;
+ buf_len = ntohl (*len);
+ ptr += 4;
+ len = (uint32_t*)ptr;
+ tmp_len = ntohl (*len);
+ ptr += 4;
g_byte_array_set_size(*aes_buf, tmp_len);
memcpy((*aes_buf)->data, ptr, tmp_len);
ptr += tmp_len;
- tmp_len = 0;
- for(i=3; i >= 0; i--) {
- tmp_len |= *ptr<<(i*8);
- ptr++;
- }
+ len = (uint32_t*)ptr;
+ tmp_len = ntohl (*len);
+ ptr += 4;
g_byte_array_set_size(*cph_buf, tmp_len);
memcpy((*cph_buf)->data, ptr, tmp_len);
--
To stop receiving notification emails like this one, please contact
address@hidden
- [GNUnet-SVN] [gnunet] 104/171: -fix, (continued)
- [GNUnet-SVN] [gnunet] 104/171: -fix, gnunet, 2018/01/04
- [GNUnet-SVN] [gnunet] 94/171: -add CLI, gnunet, 2018/01/04
- [GNUnet-SVN] [gnunet] 87/171: -towards IdP2, gnunet, 2018/01/04
- [GNUnet-SVN] [gnunet] 62/171: -change api, gnunet, 2018/01/04
- [GNUnet-SVN] [gnunet] 70/171: - merge with master, gnunet, 2018/01/04
- [GNUnet-SVN] [gnunet] 101/171: -fix, gnunet, 2018/01/04
- [GNUnet-SVN] [gnunet] 107/171: -fix, gnunet, 2018/01/04
- [GNUnet-SVN] [gnunet] 100/171: -merge, gnunet, 2018/01/04
- [GNUnet-SVN] [gnunet] 103/171: Merge branch 'abe' into identity_abe, gnunet, 2018/01/04
- [GNUnet-SVN] [gnunet] 112/171: Merge remote-tracking branch 'origin/master' into identity_abe, gnunet, 2018/01/04
- [GNUnet-SVN] [gnunet] 99/171: -add free ABE functions,
gnunet <=
- [GNUnet-SVN] [gnunet] 90/171: -fix, gnunet, 2018/01/04
- [GNUnet-SVN] [gnunet] 125/171: -do not persist sensitive data, gnunet, 2018/01/04
- [GNUnet-SVN] [gnunet] 95/171: -fix, gnunet, 2018/01/04
- [GNUnet-SVN] [gnunet] 106/171: -fixes, gnunet, 2018/01/04
- [GNUnet-SVN] [gnunet] 114/171: -move idp gns record handling to identity-provider, gnunet, 2018/01/04
- [GNUnet-SVN] [gnunet] 75/171: -add policy record type, gnunet, 2018/01/04
- [GNUnet-SVN] [gnunet] 102/171: -fix leaks, gnunet, 2018/01/04
- [GNUnet-SVN] [gnunet] 108/171: -fixes, gnunet, 2018/01/04
- [GNUnet-SVN] [gnunet] 111/171: Merge remote-tracking branch 'origin/master' into identity_abe, gnunet, 2018/01/04
- [GNUnet-SVN] [gnunet] 97/171: -add attr list, gnunet, 2018/01/04