gnutls-commit
[Top][All Lists]
Advanced

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

[SCM] GNU gnutls branch, master, updated. gnutls_2_9_10-284-gba349b1


From: Nikos Mavrogiannopoulos
Subject: [SCM] GNU gnutls branch, master, updated. gnutls_2_9_10-284-gba349b1
Date: Sat, 03 Jul 2010 08:38:27 +0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU gnutls".

http://git.savannah.gnu.org/cgit/gnutls.git/commit/?id=ba349b1a8751d6830fdeace466909d2cc6178cd1

The branch, master has been updated
       via  ba349b1a8751d6830fdeace466909d2cc6178cd1 (commit)
       via  82e5b85de5ee9ac86cfb4f90a2e77c72a685df86 (commit)
      from  e057e49b2d147cd4a911aa55c5f67fde310a1ecf (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit ba349b1a8751d6830fdeace466909d2cc6178cd1
Author: Nikos Mavrogiannopoulos <address@hidden>
Date:   Sat Jul 3 10:37:45 2010 +0200

    Allow encryption and decryption that are not in-place only.

commit 82e5b85de5ee9ac86cfb4f90a2e77c72a685df86
Author: Nikos Mavrogiannopoulos <address@hidden>
Date:   Sat Jul 3 10:29:23 2010 +0200

    Print values in a human-readable format and do the calculations in fixed
    time to prevent stalling in slow systems.

-----------------------------------------------------------------------

Summary of changes:
 lib/crypto-api.c             |   46 ++++++++++++++++++++++++++
 lib/gnutls_cipher_int.c      |   21 ++++++++++++
 lib/gnutls_cipher_int.h      |    4 ++
 lib/includes/gnutls/crypto.h |    5 +++
 lib/libgnutls.map            |    2 +
 src/benchmark.c              |   74 ++++++++++++++++++++++++++++++++++--------
 6 files changed, 138 insertions(+), 14 deletions(-)

diff --git a/lib/crypto-api.c b/lib/crypto-api.c
index cad9914..1e61e41 100644
--- a/lib/crypto-api.c
+++ b/lib/crypto-api.c
@@ -102,6 +102,52 @@ gnutls_cipher_decrypt (gnutls_cipher_hd_t handle, void 
*ciphertext,
 }
 
 /**
+ * gnutls_cipher_encrypt2:
+ * @handle: is a #gnutls_cipher_hd_t structure.
+ * @text: the data to encrypt
+ * @textlen: The length of data to encrypt
+ * @ciphertext: the encrypted data
+ * @ciphertextlen: The available length for encrypted data
+ *
+ * This function will encrypt the given data using the algorithm
+ * specified by the context.
+ *
+ * Returns: Zero or a negative value on error.
+ *
+ * Since: 2.10.0
+ **/
+int
+gnutls_cipher_encrypt2 (gnutls_cipher_hd_t handle, void *text, size_t textlen,
+  void* ciphertext, size_t ciphertextlen)
+{
+  return _gnutls_cipher_encrypt2 ((cipher_hd_st *) handle, text, textlen, 
+    ciphertext, ciphertextlen);
+}
+
+/**
+ * gnutls_cipher_decrypt2:
+ * @handle: is a #gnutls_cipher_hd_t structure.
+ * @ciphertext: the data to encrypt
+ * @ciphertextlen: The length of data to encrypt
+ * @text: the decrypted data
+ * @textlen: The available length for decrypted data
+ *
+ * This function will decrypt the given data using the algorithm
+ * specified by the context.
+ *
+ * Returns: Zero or a negative value on error.
+ *
+ * Since: 2.10.0
+ **/
+int
+gnutls_cipher_decrypt2 (gnutls_cipher_hd_t handle, const void *ciphertext,
+                      size_t ciphertextlen, void* text, size_t textlen)
+{
+  return _gnutls_cipher_decrypt2 ((cipher_hd_st *) handle, ciphertext,
+                                ciphertextlen, text, textlen);
+}
+
+/**
  * gnutls_cipher_deinit:
  * @handle: is a #gnutls_cipher_hd_t structure.
  *
diff --git a/lib/gnutls_cipher_int.c b/lib/gnutls_cipher_int.c
index 4a830b8..023e459 100644
--- a/lib/gnutls_cipher_int.c
+++ b/lib/gnutls_cipher_int.c
@@ -113,6 +113,27 @@ int _gnutls_cipher_decrypt (const cipher_hd_st * handle, 
void *ciphertext,
   return 0;
 }
 
+int _gnutls_cipher_encrypt2 (const cipher_hd_st * handle, const void *text, 
int textlen,
+  void* ciphertext, int ciphertextlen)
+{
+  if (handle != NULL && handle->handle != NULL)
+    {
+      return handle->encrypt(handle->handle, text, textlen, ciphertext, 
ciphertextlen);
+    }
+  return 0;
+}
+
+int _gnutls_cipher_decrypt2 (const cipher_hd_st * handle, const void 
*ciphertext,
+                       int ciphertextlen, void* text, int textlen)
+{
+  if (handle != NULL && handle->handle != NULL)
+    {
+      return handle->decrypt(handle->handle, ciphertext, ciphertextlen, 
+       text, textlen);
+    }
+  return 0;
+}
+
 void _gnutls_cipher_deinit (cipher_hd_st * handle)
 {
   if (handle != NULL && handle->handle != NULL)
diff --git a/lib/gnutls_cipher_int.h b/lib/gnutls_cipher_int.h
index 81950f1..3131746 100644
--- a/lib/gnutls_cipher_int.h
+++ b/lib/gnutls_cipher_int.h
@@ -50,6 +50,10 @@ int _gnutls_cipher_encrypt (const cipher_hd_st * handle, 
void *text,
                            int textlen);
 int _gnutls_cipher_decrypt (const cipher_hd_st * handle, void *ciphertext,
                            int ciphertextlen);
+int _gnutls_cipher_encrypt2 (const cipher_hd_st * handle, const void *text,
+                           int textlen, void* ciphertext, int ciphertextlen);
+int _gnutls_cipher_decrypt2 (const cipher_hd_st * handle, const void 
*ciphertext,
+                           int ciphertextlen, void* text, int textlen);
 void _gnutls_cipher_deinit (cipher_hd_st * handle);
 
 #endif /* GNUTLS_CIPHER_INT */
diff --git a/lib/includes/gnutls/crypto.h b/lib/includes/gnutls/crypto.h
index 31352dd..d121490 100644
--- a/lib/includes/gnutls/crypto.h
+++ b/lib/includes/gnutls/crypto.h
@@ -35,6 +35,11 @@ int gnutls_cipher_encrypt (const gnutls_cipher_hd_t handle,
                           void *text, size_t textlen);
 int gnutls_cipher_decrypt (const gnutls_cipher_hd_t handle,
                           void *ciphertext, size_t ciphertextlen);
+int gnutls_cipher_decrypt2 (gnutls_cipher_hd_t handle, const void *ciphertext,
+                      size_t ciphertextlen, void* text, size_t textlen);
+int gnutls_cipher_encrypt2 (gnutls_cipher_hd_t handle, void *text, size_t 
textlen,
+  void* ciphertext, size_t ciphertextlen);
+
 void gnutls_cipher_deinit (gnutls_cipher_hd_t handle);
 int gnutls_cipher_get_block_size (gnutls_cipher_algorithm_t algorithm);
 
diff --git a/lib/libgnutls.map b/lib/libgnutls.map
index 47eed0c..9b25b29 100644
--- a/lib/libgnutls.map
+++ b/lib/libgnutls.map
@@ -681,6 +681,8 @@ GNUTLS_2_11
        gnutls_pk_bits_to_sec_param;
        gnutls_rnd;
        gnutls_x509_crq_get_preferred_hash_algorithm;
+       gnutls_cipher_encrypt2;
+       gnutls_cipher_decrypt2;
 } GNUTLS_2_10;
 
 GNUTLS_PRIVATE {
diff --git a/src/benchmark.c b/src/benchmark.c
index e3be4c4..6c8fd6e 100644
--- a/src/benchmark.c
+++ b/src/benchmark.c
@@ -28,11 +28,17 @@
 #include <gnutls/gnutls.h>
 #include <gnutls/crypto.h>
 #include <time.h>
+#include <signal.h>
 #include "timespec.h"          /* gnulib gettime */
 
 static unsigned char data[64 * 1024];
 
-#define TOTAL_ITER 8*1024
+static int must_finish = 0;
+
+static void alarm_handler(int signo)
+{
+        must_finish = 1;
+}
 
 static void
 tls_log_func (int level, const char *str)
@@ -40,19 +46,45 @@ tls_log_func (int level, const char *str)
   fprintf (stderr, "|<%d>| %s", level, str);
 }
 
+static void value2human(int bytes, double time, double* data, double* 
speed,char* metric)
+{
+        if (bytes > 1000 && bytes < 1000*1000) {
+                *data = ((double)bytes)/1000;
+                *speed = *data/time;
+                strcpy(metric, "Kb");
+                return;
+        } else if (bytes >= 1000*1000 && bytes < 1000*1000*1000) {
+                *data = ((double)bytes)/(1000*1000);
+                *speed = *data/time;
+                strcpy(metric, "Mb");
+                return;
+        } else if (bytes >= 1000*1000*1000) {
+                *data = ((double)bytes)/(1000*1000*1000);
+                *speed = *data/time;
+                strcpy(metric, "Gb");
+                return;
+        } else {
+                *data = (double)bytes;
+                *speed = *data/time;
+                strcpy(metric, "bytes");
+                return;
+        }
+}
+
 static void
 cipher_bench (int algo, int size)
 {
-  int ret, i;
+  int ret;
   gnutls_cipher_hd_t ctx;
   void *_key, *_iv;
   gnutls_datum_t key, iv;
   struct timespec start, stop;
   double secs;
   long data_size = 0;
-  double dd;
+  double dspeed, ddata;
   int blocksize = gnutls_cipher_get_block_size (algo);
   int keysize = gnutls_cipher_get_key_size (algo);
+  char metric[16];
 
   _key = malloc (keysize);
   if (_key == NULL)
@@ -70,10 +102,13 @@ cipher_bench (int algo, int size)
   key.data = _key;
   key.size = keysize;
 
-
   printf ("Checking %s (%dkb payload)... ", gnutls_cipher_get_name (algo),
          size);
   fflush (stdout);
+  
+  must_finish = 0;
+  alarm(5);
+  
   gettime (&start);
 
   ret = gnutls_cipher_init (&ctx, algo, &key, &iv);
@@ -83,11 +118,12 @@ cipher_bench (int algo, int size)
       goto leave;
     }
 
-  for (i = 0; i < TOTAL_ITER; i++)
+  do
     {
       gnutls_cipher_encrypt (ctx, data, size * 1024);
       data_size += size * 1024;
     }
+  while(must_finish == 0);
 
   gnutls_cipher_deinit (ctx);
 
@@ -96,9 +132,10 @@ cipher_bench (int algo, int size)
   secs = (stop.tv_sec * 1000 + stop.tv_nsec / (1000 * 1000) -
          (start.tv_sec * 1000 + start.tv_nsec / (1000 * 1000)));
   secs /= 1000;
-  dd = (((double) data_size / (double) secs)) / 1000;
-  printf ("Encrypted %ld kb in %.2f secs: ", data_size / 1000, secs);
-  printf ("%.2f kbyte/sec\n", dd);
+  
+  value2human(data_size, secs, &ddata, &dspeed, metric);
+  printf ("Encrypted %.2f %s in %.2f secs: ", ddata, metric, secs);
+  printf ("%.2f %s/sec\n", dspeed, metric);
 
 leave:
   free (_key);
@@ -109,13 +146,13 @@ leave:
 static void
 mac_bench (int algo, int size)
 {
-  int i;
   void *_key;
   struct timespec start, stop;
   double secs;
   long data_size = 0;
-  double dd;
+  double ddata, dspeed;
   int blocksize = gnutls_hmac_get_len (algo);
+  char metric[16];
 
   _key = malloc (blocksize);
   if (_key == NULL)
@@ -124,13 +161,18 @@ mac_bench (int algo, int size)
 
   printf ("Checking %s (%dkb payload)... ", gnutls_mac_get_name (algo), size);
   fflush (stdout);
+
+  must_finish = 0;
+  alarm(5);
+
   gettime (&start);
 
-  for (i = 0; i < TOTAL_ITER; i++)
+  do
     {
       gnutls_hmac_fast (algo, _key, blocksize, data, size * 1024, _key);
       data_size += size * 1024;
     }
+  while(must_finish == 0);
 
   gettime (&stop);
 
@@ -138,9 +180,11 @@ mac_bench (int algo, int size)
     (stop.tv_sec * 1000 + stop.tv_nsec / (1000 * 1000) -
      (start.tv_sec * 1000 + start.tv_nsec / (1000 * 1000)));
   secs /= 1000;
-  dd = (((double) data_size / (double) secs)) / 1000;
-  printf ("Hashed %ld kb in %.2f secs: ", data_size / 1000, secs);
-  printf ("%.2f kbyte/sec\n", dd);
+
+  value2human(data_size, secs, &ddata, &dspeed, metric);
+
+  printf ("Hashed %.2f %s in %.2f secs: ", ddata, metric, secs);
+  printf ("%.2f %s/sec\n", dspeed, metric);
 
   free (_key);
 }
@@ -152,6 +196,8 @@ main (int argc, char** argv)
 
   if (argc > 1)
     debug_level = 2;
+    
+  signal(SIGALRM, alarm_handler);
 
   gnutls_global_set_log_function (tls_log_func);
   gnutls_global_set_log_level (debug_level);


hooks/post-receive
-- 
GNU gnutls



reply via email to

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