From: Schanzenbach, Martin Date: Sat, 8 Jul 2017 18:14:49 +0000 (+0200) Subject: -add serialization X-Git-Tag: gnunet-0.11.0rc0~24^2~66^2~4 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=f3a84ebcd657b369792667bb1c1bd5ca2e53ee35;p=oweals%2Fgnunet.git -add serialization --- diff --git a/src/include/gnunet_crypto_lib.h b/src/include/gnunet_crypto_lib.h index 6f2870c37..8a2763894 100644 --- a/src/include/gnunet_crypto_lib.h +++ b/src/include/gnunet_crypto_lib.h @@ -2185,7 +2185,21 @@ GNUNET_CRYPTO_cpabe_decrypt (const void *block, const struct GNUNET_CRYPTO_AbeKey *key, void **result); +ssize_t +GNUNET_CRYPTO_cpabe_serialize_key (struct GNUNET_CRYPTO_AbeKey *key, + void **result); + +struct GNUNET_CRYPTO_AbeKey* +GNUNET_CRYPTO_cpabe_deserialize_key (void *data, + size_t len); + +ssize_t +GNUNET_CRYPTO_cpabe_serialize_master_key (struct GNUNET_CRYPTO_AbeMasterKey *key, + void **result); +struct GNUNET_CRYPTO_AbeMasterKey* +GNUNET_CRYPTO_cpabe_deserialize_master_key (void *data, + size_t len); #if 0 /* keep Emacsens' auto-indent happy */ diff --git a/src/util/crypto_abe.c b/src/util/crypto_abe.c index d004220d1..62b9b7108 100644 --- a/src/util/crypto_abe.c +++ b/src/util/crypto_abe.c @@ -303,3 +303,51 @@ GNUNET_CRYPTO_cpabe_decrypt (const void *block, return pt_size; } + +ssize_t +GNUNET_CRYPTO_cpabe_serialize_key (struct GNUNET_CRYPTO_AbeKey *key, + void **result) +{ + ssize_t len; + + len = key->pub->len + key->prv->len + 12; + write_cpabe (result, key->pub, len, key->prv); + + return len; +} + +struct GNUNET_CRYPTO_AbeKey* +GNUNET_CRYPTO_cpabe_deserialize_key (void *data, + size_t len) +{ + struct GNUNET_CRYPTO_AbeKey *key; + + key = GNUNET_new (struct GNUNET_CRYPTO_AbeKey); + read_cpabe (data, &key->pub, &key->prv); + + return key; +} + +ssize_t +GNUNET_CRYPTO_cpabe_serialize_master_key (struct GNUNET_CRYPTO_AbeMasterKey *key, + void **result) +{ + ssize_t len; + + len = key->pub->len + key->msk->len + 12; + write_cpabe (result, key->pub, len, key->msk); + + return len; +} + +struct GNUNET_CRYPTO_AbeMasterKey* +GNUNET_CRYPTO_cpabe_deserialize_master_key (void *data, + size_t len) +{ + struct GNUNET_CRYPTO_AbeMasterKey *key; + + key = GNUNET_new (struct GNUNET_CRYPTO_AbeMasterKey); + read_cpabe (data, &key->pub, &key->msk); + + return key; +}