[vte] build: Wire up the gnutls switch



commit d03fa439b26ca876a05cea6bf5d57ca03f7131e1
Author: Egmont Koblinger <egmont gmail com>
Date:   Tue Jan 20 17:00:07 2015 +0100

    build: Wire up the gnutls switch
    
    https://bugzilla.gnome.org/show_bug.cgi?id=743231

 src/vtestream-file.h |   29 +++++++++++++++++++++--------
 1 files changed, 21 insertions(+), 8 deletions(-)
---
diff --git a/src/vtestream-file.h b/src/vtestream-file.h
index 55d0685..bcd68df 100644
--- a/src/vtestream-file.h
+++ b/src/vtestream-file.h
@@ -81,17 +81,24 @@
 #include <string.h>
 #include <unistd.h>
 #include <zlib.h>
-#include <gnutls/gnutls.h>
-#include <gnutls/crypto.h>
+
+#ifdef WITH_GNUTLS
+# include <gnutls/gnutls.h>
+# include <gnutls/crypto.h>
+#endif
 
 #include "vteutils.h"
 
+#ifdef WITH_GNUTLS
 /* Currently the code requires that a stream cipher (e.g. GCM) is used
  * which can encrypt any amount of data without need for padding. */
-#define VTE_CIPHER_ALGORITHM    GNUTLS_CIPHER_AES_256_GCM
-#define VTE_CIPHER_KEY_SIZE     32
-#define VTE_CIPHER_IV_SIZE      12
-#define VTE_CIPHER_TAG_SIZE     16
+# define VTE_CIPHER_ALGORITHM    GNUTLS_CIPHER_AES_256_GCM
+# define VTE_CIPHER_KEY_SIZE     32
+# define VTE_CIPHER_IV_SIZE      12
+# define VTE_CIPHER_TAG_SIZE     16
+#else
+# define VTE_CIPHER_TAG_SIZE     0
+#endif
 
 #ifndef VTESTREAM_MAIN
 # define VTE_SNAKE_BLOCKSIZE 65536
@@ -610,6 +617,7 @@ typedef struct _VteBoa {
         VteSnake parent;
         gsize tail, head;
 
+#if !defined VTESTREAM_MAIN && defined WITH_GNUTLS
         gnutls_cipher_hd_t cipher_hd;
         /* The IV (nonce) consists of the offset within the stream, and an overwrite counter so that
          * we don't reuse the same IVs when a block at a certain logical offset is overwritten.
@@ -621,6 +629,7 @@ typedef struct _VteBoa {
                 guint32 overwrite_counter;
                 unsigned char padding[VTE_CIPHER_IV_SIZE];
         } iv;
+#endif
         int compressBound;
 } VteBoa;
 
@@ -650,11 +659,13 @@ static void
 _vte_boa_encrypt (VteBoa *boa, gsize offset, guint32 overwrite_counter, char *data, unsigned int len)
 {
 #ifndef VTESTREAM_MAIN
+# ifdef WITH_GNUTLS
         boa->iv.offset = offset;
         boa->iv.overwrite_counter = overwrite_counter;
         gnutls_cipher_set_iv (boa->cipher_hd, &boa->iv, VTE_CIPHER_IV_SIZE);
         gnutls_cipher_encrypt (boa->cipher_hd, data, len);
         gnutls_cipher_tag (boa->cipher_hd, data + len, VTE_CIPHER_TAG_SIZE);
+# endif
 #else
         /* Fake encryption for unit testing: uppercase <-> lowercase, followed by verification tag which is
          * 5 bits: block sequence number (offset divided by blocksize)
@@ -679,11 +690,13 @@ _vte_boa_decrypt (VteBoa *boa, gsize offset, guint32 overwrite_counter, char *da
         guint8 faulty = 0;
 
 #ifndef VTESTREAM_MAIN
+# ifdef WITH_GNUTLS
         boa->iv.offset = offset;
         boa->iv.overwrite_counter = overwrite_counter;
         gnutls_cipher_set_iv (boa->cipher_hd, &boa->iv, VTE_CIPHER_IV_SIZE);
         gnutls_cipher_decrypt (boa->cipher_hd, data, len);
         gnutls_cipher_tag (boa->cipher_hd, tag, VTE_CIPHER_TAG_SIZE);
+# endif
 #else
         /* Fake decryption for unit testing; see above. */
         for (i = 0; i < len; i++) {
@@ -782,7 +795,7 @@ _vte_boa_uncompress (char *dst, unsigned int dstlen, const char *src, unsigned i
 static void
 _vte_boa_init (VteBoa *boa)
 {
-#ifndef VTESTREAM_MAIN
+#if !defined VTESTREAM_MAIN && defined WITH_GNUTLS
         unsigned char key[VTE_CIPHER_KEY_SIZE];
         gnutls_datum_t datum_key;
 
@@ -815,11 +828,11 @@ _vte_boa_init (VteBoa *boa)
 static void
 _vte_boa_finalize (GObject *object)
 {
+#if !defined VTESTREAM_MAIN && defined WITH_GNUTLS
         VteBoa *boa = (VteBoa *) object;
 
         memset(&boa->iv, 0, sizeof(boa->iv));
 
-#ifndef VTESTREAM_MAIN
         gnutls_cipher_deinit (boa->cipher_hd);
         gnutls_global_deinit ();
 #endif


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