gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-anastasis] branch master updated: worked on crypto library


From: gnunet
Subject: [taler-anastasis] branch master updated: worked on crypto library
Date: Wed, 25 Mar 2020 00:20:21 +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 be89c9f  worked on crypto library
be89c9f is described below

commit be89c9fd103510b2e632ce263274ed85d4a922b9
Author: Dennis Neufeld <address@hidden>
AuthorDate: Tue Mar 24 23:20:15 2020 +0000

    worked on crypto library
---
 src/util/anastasis_crypto.c      | 44 ++++++++++++++++++++++++++++------------
 src/util/test_anastasis_crypto.c | 15 ++++++++++----
 2 files changed, 42 insertions(+), 17 deletions(-)

diff --git a/src/util/anastasis_crypto.c b/src/util/anastasis_crypto.c
index 64ff0fe..3ea784c 100644
--- a/src/util/anastasis_crypto.c
+++ b/src/util/anastasis_crypto.c
@@ -146,17 +146,21 @@ ANASTASIS_CRYPTO_recovery_document_encrypt (
   void **res,
   size_t *res_size)
 {
-  struct ANASTASIS_CRYPTO_Nonce nonce;
+  const struct ANASTASIS_CRYPTO_Nonce nonce;
   gcry_cipher_hd_t cipher;
   char ciphertext[data_size];
   char sym_key[AES_KEY_SIZE];
   char iv[AES_IV_SIZE];
   char gcm_tag[GCM_TAG_SIZE];
+  size_t erd_size;
   void *erd;
 
   GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE,
                               &nonce,
-                              sizeof (nonce));
+                              sizeof (struct ANASTASIS_CRYPTO_Nonce));
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "\n NONCE_1:  %s \n",
+              &nonce);
   get_iv_key (id, &nonce, "erd", sym_key, iv);
   gcry_cipher_open (&cipher,
                     GCRY_CIPHER_AES256,
@@ -165,6 +169,9 @@ ANASTASIS_CRYPTO_recovery_document_encrypt (
   gcry_cipher_setkey (cipher,
                       sym_key,
                       sizeof (sym_key));
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "\n SYMKEY_1:  %s \n",
+              sym_key);
   gcry_cipher_setiv (cipher,
                      &iv,
                      sizeof (iv));
@@ -178,18 +185,22 @@ ANASTASIS_CRYPTO_recovery_document_encrypt (
                       sizeof (gcm_tag));
   gcry_cipher_close (cipher);
 
-  *res_size = sizeof (ciphertext) + sizeof(nonce) + sizeof(gcm_tag);
-  erd = GNUNET_malloc (*res_size);
+  erd_size = sizeof (ciphertext) + sizeof(struct ANASTASIS_CRYPTO_Nonce)
+             + GCM_TAG_SIZE;
+  memcpy (res_size, &erd_size, sizeof (erd_size));
+  erd = GNUNET_malloc (erd_size);
   memcpy (erd,
           &nonce,
-          sizeof(nonce));
-  memcpy (erd + sizeof(nonce),
+          sizeof (struct ANASTASIS_CRYPTO_Nonce));
+  memcpy (erd + sizeof (struct ANASTASIS_CRYPTO_Nonce),
           &gcm_tag,
-          sizeof(gcm_tag));
-  memcpy (erd + sizeof(nonce) + sizeof(gcm_tag),
-          ciphertext,
+          GCM_TAG_SIZE);
+  memcpy (erd + sizeof (struct ANASTASIS_CRYPTO_Nonce) + GCM_TAG_SIZE,
+          &ciphertext,
           sizeof(ciphertext));
   *res = (void *) erd;
+
+  GNUNET_free (erd);
 }
 
 /**
@@ -214,20 +225,24 @@ ANASTASIS_CRYPTO_recovery_document_decrypt (
 {
   struct ANASTASIS_CRYPTO_Nonce nonce;
   gcry_cipher_hd_t cipher;
-  char ciphertext[data_size];
+  char ciphertext[data_size - sizeof (struct ANASTASIS_CRYPTO_Nonce)
+                  - GCM_TAG_SIZE];
   char sym_key[AES_KEY_SIZE];
   char iv[AES_IV_SIZE];
   char gcm_tag[GCM_TAG_SIZE];
 
-  memcpy (&nonce, data + 0, sizeof (struct ANASTASIS_CRYPTO_Nonce));
-  memcpy (&gcm_tag, data + sizeof (struct ANASTASIS_CRYPTO_Nonce),
+  memcpy (&nonce, data, sizeof (struct ANASTASIS_CRYPTO_Nonce));
+  memcpy (&gcm_tag,
+          data + sizeof (struct ANASTASIS_CRYPTO_Nonce),
           GCM_TAG_SIZE);
   memcpy (&ciphertext,
           data + sizeof (struct ANASTASIS_CRYPTO_Nonce) + GCM_TAG_SIZE,
           data_size - sizeof (struct ANASTASIS_CRYPTO_Nonce) - GCM_TAG_SIZE);
 
   get_iv_key (id, &nonce, "erd", sym_key, iv);
-
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "\n NONCE_2:  %s \n",
+              &nonce);
   gcry_cipher_open (&cipher,
                     GCRY_CIPHER_AES256,
                     GCRY_CIPHER_MODE_GCM,
@@ -235,6 +250,9 @@ ANASTASIS_CRYPTO_recovery_document_decrypt (
   gcry_cipher_setkey (cipher,
                       sym_key,
                       sizeof (sym_key));
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "\n SYMKEY_2:  %s \n",
+              sym_key);
   gcry_cipher_setiv (cipher,
                      &iv,
                      sizeof (iv));
diff --git a/src/util/test_anastasis_crypto.c b/src/util/test_anastasis_crypto.c
index e49e3cd..12bad2f 100644
--- a/src/util/test_anastasis_crypto.c
+++ b/src/util/test_anastasis_crypto.c
@@ -34,6 +34,7 @@ static int test_recovery_document ()
   void *ciphertext;
   size_t size_ciphertext;
   void *plaintext;
+  const char *dec_plaintext;
   size_t size_plaintext;
   const struct ANASTASIS_CRYPTO_UserIdentifier id;
 
@@ -43,8 +44,8 @@ static int test_recovery_document ()
 
 
   ANASTASIS_CRYPTO_recovery_document_encrypt (&id,
-                                              "Test",
-                                              strlen ("Test"),
+                                              "TestTest",
+                                              strlen ("TestTest"),
                                               &ciphertext,
                                               &size_ciphertext);
 
@@ -53,18 +54,24 @@ static int test_recovery_document ()
                                               size_ciphertext,
                                               &plaintext,
                                               &size_plaintext);
-
-  return 0;
+  dec_plaintext = (char*) plaintext;
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "\n\n Plaintext:   %s\n\n",
+              *dec_plaintext);
+  // return strncmp ("Text", dec_plaintext, sizeof (dec_plaintext));
+  return 1;
 }
 
 int
 main (int argc,
       const char *const argv[])
 {
+  GNUNET_log_setup (argv[0], "DEBUG", NULL);
   if (0 != test_recovery_document ())
     return 1;
 
   return 0;
+
 }
 
 /* end of test_anastasis_crypto.c */

-- 
To stop receiving notification emails like this one, please contact
address@hidden.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]