gnunet-svn
[Top][All Lists]
Advanced

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

[taler-anastasis] branch master updated: created new data structures, e


From: gnunet
Subject: [taler-anastasis] branch master updated: created new data structures, eliminated memcpy usage
Date: Wed, 01 Apr 2020 12:10:53 +0200

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 83cff6a  created new data structures, eliminated memcpy usage
83cff6a is described below

commit 83cff6aa5432b0b87daf21ba7e999966320317a0
Author: Dennis Neufeld <address@hidden>
AuthorDate: Wed Apr 1 10:10:32 2020 +0000

    created new data structures, eliminated memcpy usage
---
 src/include/anastasis_crypto_lib.h | 10 +++++++-
 src/util/anastasis_crypto.c        | 50 ++++++++++++++------------------------
 2 files changed, 27 insertions(+), 33 deletions(-)

diff --git a/src/include/anastasis_crypto_lib.h 
b/src/include/anastasis_crypto_lib.h
index 2eb545c..728fcaf 100644
--- a/src/include/anastasis_crypto_lib.h
+++ b/src/include/anastasis_crypto_lib.h
@@ -95,7 +95,15 @@ struct ANASTASIS_CRYPTO_Nonce
 */
 struct ANASTASIS_CRYPTO_Iv
 {
-  char iv[96 / 8];
+  uint32_t iv[3];
+};
+
+/**
+ * Specifies an symmetric key used for the AES encryption, here defined as 
32Byte large.
+*/
+struct ANASTASIS_CRYPTO_SymKey
+{
+  uint32_t key[8];
 };
 
 /**
diff --git a/src/util/anastasis_crypto.c b/src/util/anastasis_crypto.c
index b2d3e2a..0b2128e 100644
--- a/src/util/anastasis_crypto.c
+++ b/src/util/anastasis_crypto.c
@@ -28,21 +28,6 @@
 #include <gnunet/gnunet_util_lib.h>
 #include <string.h>
 
-/**
- * AES key size.
- */
-#define AES_KEY_SIZE (256 / 8)
-
-/**
- * AES (GCM) IV size.
- */
-#define AES_IV_SIZE (96 / 8)
-
-/**
- * Size of the GCM tag.
- */
-#define GCM_TAG_SIZE (128 / 8)
-
 /**
  * Compute @a key and @a iv.
  *
@@ -58,10 +43,13 @@ get_iv_key (const void *key_material,
             size_t key_m_len,
             const struct ANASTASIS_CRYPTO_Nonce *nonce,
             const char *salt,
-            char key[AES_KEY_SIZE],
-            char iv[AES_IV_SIZE])
+            struct ANASTASIS_CRYPTO_SymKey *key,
+            struct ANASTASIS_CRYPTO_Iv *iv)
 {
-  char res[AES_KEY_SIZE + AES_IV_SIZE];
+  char res[sizeof (struct ANASTASIS_CRYPTO_SymKey)
+           + sizeof (struct ANASTASIS_CRYPTO_Iv)];
+  key = (struct ANASTASIS_CRYPTO_SymKey *) &res;
+  iv = (struct ANASTASIS_CRYPTO_Iv *) &key[1];
 
   GNUNET_assert (GNUNET_YES ==
                  GNUNET_CRYPTO_hkdf (res,
@@ -77,8 +65,6 @@ get_iv_key (const void *key_material,
                                      strlen (salt),
                                      NULL,
                                      0));
-  memcpy (key, res, AES_KEY_SIZE);
-  memcpy (iv, &res[AES_KEY_SIZE], AES_IV_SIZE);
 }
 
 
@@ -104,8 +90,8 @@ anastasis_encrypt (const void *key,
 {
   struct ANASTASIS_CRYPTO_Nonce *nonce;
   gcry_cipher_hd_t cipher;
-  char sym_key[AES_KEY_SIZE];
-  char iv[AES_IV_SIZE];
+  struct ANASTASIS_CRYPTO_SymKey sym_key;
+  struct ANASTASIS_CRYPTO_Iv iv;
   int rc;
   struct ANASTASIS_CRYPTO_AesTag *tag;
   char *ciphertext;
@@ -127,19 +113,19 @@ anastasis_encrypt (const void *key,
               key_len,
               nonce,
               salt,
-              sym_key,
-              iv);
+              &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,
+                           &sym_key,
                            sizeof (sym_key));
   GNUNET_assert ((0 == rc) || ((char) rc == GPG_ERR_WEAK_KEY));
   rc = gcry_cipher_setiv (cipher,
-                          iv,
+                          &iv,
                           sizeof (iv));
   GNUNET_assert ((0 == rc) || ((char) rc == GPG_ERR_WEAK_KEY));
 
@@ -179,8 +165,8 @@ anastasis_decrypt (const void *key,
 {
   struct ANASTASIS_CRYPTO_Nonce *nonce;
   gcry_cipher_hd_t cipher;
-  char sym_key[AES_KEY_SIZE];
-  char iv[AES_IV_SIZE];
+  struct ANASTASIS_CRYPTO_SymKey sym_key;
+  struct ANASTASIS_CRYPTO_Iv iv;
   int rc;
   struct ANASTASIS_CRYPTO_AesTag *tag;
   char *ciphertext;
@@ -199,19 +185,19 @@ anastasis_decrypt (const void *key,
               key_len,
               nonce,
               salt,
-              sym_key,
-              iv);
+              &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,
+                           &sym_key,
                            sizeof (sym_key));
   GNUNET_assert ((0 == rc) || ((char) rc == GPG_ERR_WEAK_KEY));
 
   rc = gcry_cipher_setiv (cipher,
-                          iv,
+                          &iv,
                           sizeof (iv));
   GNUNET_assert ((0 == rc) || ((char) rc == GPG_ERR_WEAK_KEY));
 

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



reply via email to

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