[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-anastasis] branch master updated: modified encryption method
From: |
gnunet |
Subject: |
[taler-anastasis] branch master updated: modified encryption method |
Date: |
Thu, 26 Mar 2020 17:48:58 +0100 |
This is an automated email from the git hooks/post-receive script.
dennis-neufeld pushed a commit to branch master
in repository anastasis.
The following commit(s) were added to refs/heads/master by this push:
new 7dc949a modified encryption method
7dc949a is described below
commit 7dc949a7beef5398699cee63e4db54efdb144f31
Author: Dennis Neufeld <address@hidden>
AuthorDate: Thu Mar 26 16:48:47 2020 +0000
modified encryption method
---
src/util/anastasis_crypto.c | 152 ++++++++++++++++++++-------------------
src/util/test_anastasis_crypto.c | 46 ++++++++++++
2 files changed, 125 insertions(+), 73 deletions(-)
diff --git a/src/util/anastasis_crypto.c b/src/util/anastasis_crypto.c
index b16c73d..fb17361 100644
--- a/src/util/anastasis_crypto.c
+++ b/src/util/anastasis_crypto.c
@@ -47,12 +47,13 @@
* Compute @a key and @a iv.
*
* @param msec master secret for calculation
- * @param serial number for the @a smac calculation
- * @param key[out] where to write the decrption key
+ * @param nonce nonce for calculation
+ * @param salt salt value for calculation
+ * @param key[out] where to write the en-/decription key
* @param iv[out] where to write the IV
*/
static void
-get_iv_key (const struct ANASTASIS_CRYPTO_UserIdentifier *kdf_id,
+get_iv_key (const void *msec,
const struct ANASTASIS_CRYPTO_Nonce *nonce,
const char *salt,
char key[AES_KEY_SIZE],
@@ -65,9 +66,8 @@ get_iv_key (const struct ANASTASIS_CRYPTO_UserIdentifier
*kdf_id,
sizeof (res),
GCRY_MD_SHA512,
GCRY_MD_SHA256,
- kdf_id,
- sizeof(struct
- ANASTASIS_CRYPTO_UserIdentifier),
+ msec,
+ sizeof(msec),
nonce,
sizeof(struct ANASTASIS_CRYPTO_Nonce),
salt,
@@ -78,6 +78,67 @@ get_iv_key (const struct ANASTASIS_CRYPTO_UserIdentifier
*kdf_id,
memcpy (iv, &res[AES_KEY_SIZE], AES_IV_SIZE);
}
+/**
+ * Encryption of data like recovery document etc.
+ *
+ * @param msec master secret which is used to derive a key/iv pair from
+ * @param data data to encrypt
+ * @param data_size size of the data
+ * @param salt salt value which is used for key derivation
+ * @param res ciphertext output
+ * @param res_size size of the ciphertext
+ */
+void
+encrypt (const void *msec,
+ const void *data,
+ size_t data_size,
+ const char *salt,
+ void **res,
+ size_t *res_size)
+{
+ struct ANASTASIS_CRYPTO_Nonce nonce;
+ gcry_cipher_hd_t cipher;
+ char sym_key[AES_KEY_SIZE];
+ char iv[AES_IV_SIZE];
+ int rc;
+
+ GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE,
+ &nonce,
+ sizeof (struct ANASTASIS_CRYPTO_Nonce));
+ memcpy (*res,
+ &nonce,
+ sizeof (struct ANASTASIS_CRYPTO_Nonce));
+ get_iv_key (msec, &nonce, salt, sym_key, iv);
+ GNUNET_assert (0 ==
+ gcry_cipher_open (&cipher,
+ GCRY_CIPHER_AES256,
+ GCRY_CIPHER_MODE_GCM,
+ 0));
+ rc = gcry_cipher_setkey (cipher,
+ sym_key,
+ sizeof (sym_key));
+ GNUNET_assert ((0 == rc) || ((char) rc == GPG_ERR_WEAK_KEY));
+ rc = gcry_cipher_setiv (cipher,
+ &iv,
+ sizeof (iv));
+ GNUNET_assert ((0 == rc) || ((char) rc == GPG_ERR_WEAK_KEY));
+
+ GNUNET_assert (0 == gcry_cipher_encrypt (cipher,
+ *res
+ + sizeof (struct
+ ANASTASIS_CRYPTO_Nonce)
+ + GCM_TAG_SIZE,
+ sizeof (data_size),
+ data,
+ data_size));
+ GNUNET_assert (0 == gcry_cipher_gettag (cipher,
+ *res
+ + sizeof (struct
+ ANASTASIS_CRYPTO_Nonce),
+ GCM_TAG_SIZE));
+ gcry_cipher_close (cipher);
+}
+
/**
* Creates the UserIdentifier, it is used as entropy source for the encryption
keys and
* for the public and private key for signing the data.
@@ -89,18 +150,16 @@ ANASTASIS_CRYPTO_user_identifier_derive (
const json_t *id_data,
struct ANASTASIS_CRYPTO_UserIdentifier *id)
{
-
- /*
- GNUNET_break (0 == gcry_kdf_derive (buf,
- buf_len,
- GCRY_KDF_SCRYPT,
- 1 ,
- salt,
- strlen (salt),
- 2 ,
- sizeof(twofish_key),
- &twofish_key));
- */
+ GNUNET_assert (0 == gcry_kdf_derive (id_data,
+ sizeof (*id_data),
+ GCRY_KDF_SCRYPT,
+ 1, // subalgo
+ "SERVER_SALT", // FIXME: Set real salt
value!!!
+ strlen ("SERVER_SALT"),
+ 1000, // iterations
+ sizeof (struct
+
ANASTASIS_CRYPTO_UserIdentifier),
+ id));
}
/**
@@ -114,19 +173,6 @@ ANASTASIS_CRYPTO_account_public_key_derive (
const struct ANASTASIS_CRYPTO_UserIdentifier *id)
{
- // FIXME Muss zuerst HKDF mit "ver" als salt gemacht werden !
- struct GNUNET_CRYPTO_EddsaPrivateKey priv_key;
- char *val;
- val = GNUNET_STRINGS_data_to_string_alloc (&id,
- sizeof (id));
- GNUNET_CRYPTO_eddsa_private_key_from_string (val,
- sizeof (val),
- &priv_key);
-
- GNUNET_CRYPTO_eddsa_key_get_public (&priv_key,
- &pub_key->pub);
-
- GNUNET_free (val);
}
/**
@@ -148,51 +194,11 @@ ANASTASIS_CRYPTO_recovery_document_encrypt (
void **res,
size_t *res_size)
{
- struct ANASTASIS_CRYPTO_Nonce nonce;
- gcry_cipher_hd_t cipher;
- char sym_key[AES_KEY_SIZE];
- char iv[AES_IV_SIZE];
- int rc;
-
+ char *salt = "erd";
*res_size = sizeof (data_size) + sizeof(struct ANASTASIS_CRYPTO_Nonce)
+ GCM_TAG_SIZE;
*res = GNUNET_malloc (*res_size);
-
- GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE,
- &nonce,
- sizeof (struct ANASTASIS_CRYPTO_Nonce));
- memcpy (*res,
- &nonce,
- sizeof (struct ANASTASIS_CRYPTO_Nonce));
- get_iv_key (id, &nonce, "erd", sym_key, iv);
- GNUNET_assert (0 ==
- gcry_cipher_open (&cipher,
- GCRY_CIPHER_AES256,
- GCRY_CIPHER_MODE_GCM,
- 0));
- rc = gcry_cipher_setkey (cipher,
- sym_key,
- sizeof (sym_key));
- GNUNET_assert ((0 == rc) || ((char) rc == GPG_ERR_WEAK_KEY));
- rc = gcry_cipher_setiv (cipher,
- &iv,
- sizeof (iv));
- GNUNET_assert ((0 == rc) || ((char) rc == GPG_ERR_WEAK_KEY));
-
- GNUNET_assert (0 == gcry_cipher_encrypt (cipher,
- *res
- + sizeof (struct
- ANASTASIS_CRYPTO_Nonce)
- + GCM_TAG_SIZE,
- sizeof (data_size),
- data,
- data_size));
- GNUNET_assert (0 == gcry_cipher_gettag (cipher,
- *res
- + sizeof (struct
- ANASTASIS_CRYPTO_Nonce),
- GCM_TAG_SIZE));
- gcry_cipher_close (cipher);
+ encrypt (id, data, data_size, salt, res, res_size);
}
/**
diff --git a/src/util/test_anastasis_crypto.c b/src/util/test_anastasis_crypto.c
index 8b1ce00..06922b0 100644
--- a/src/util/test_anastasis_crypto.c
+++ b/src/util/test_anastasis_crypto.c
@@ -29,6 +29,50 @@
#include <gnunet/gnunet_util_lib.h>
#include "anastasis_crypto_lib.h"
+/**
+ * Testing derivation of the user identifier
+ */
+static int
+test_user_identifier_derive ()
+{
+ json_t *id_data_1;
+ json_t *id_data_2;
+ json_t *id_data_3;
+ struct ANASTASIS_CRYPTO_UserIdentifier id_1;
+ struct ANASTASIS_CRYPTO_UserIdentifier id_2;
+ struct ANASTASIS_CRYPTO_UserIdentifier id_3;
+
+ // sample data 1
+ id_data_1 = json_array ();
+ json_array_append (id_data_1, json_string ("Hallo"));
+ // sample data 2, equal to sample data 1
+ id_data_2 = json_array ();
+ json_array_append (id_data_2, json_string ("Hallo"));
+ // sample data 3, differs
+ id_data_3 = json_array ();
+ json_array_append (id_data_3, json_string ("Hallo2"));
+
+ ANASTASIS_CRYPTO_user_identifier_derive (id_data_1, &id_1);
+ ANASTASIS_CRYPTO_user_identifier_derive (id_data_2, &id_2);
+ ANASTASIS_CRYPTO_user_identifier_derive (id_data_3, &id_3);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "UserIdentifier_1: %s\n",
+ TALER_B2S (&id_1));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "UserIdentifier_2: %s\n",
+ TALER_B2S (&id_2));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "UserIdentifier_3: %s\n",
+ TALER_B2S (&id_3));
+ GNUNET_assert (0 == GNUNET_memcmp (&id_1, &id_2));
+ GNUNET_assert (0 != GNUNET_memcmp (&id_1, &id_3));
+ return 0;
+}
+
+/**
+ * Testing the encryption of an recovery document and the
+ * decryption of the encrypted recovery document
+ */
static int
test_recovery_document ()
{
@@ -70,6 +114,8 @@ main (int argc,
GNUNET_log_setup (argv[0], "DEBUG", NULL);
if (0 != test_recovery_document ())
return 1;
+ if (0 != test_user_identifier_derive ())
+ return 1;
return 0;
--
To stop receiving notification emails like this one, please contact
address@hidden.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [taler-anastasis] branch master updated: modified encryption method,
gnunet <=