]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
some simplifications
authorNikos Mavrogiannopoulos <nmav@gnutls.org>
Wed, 19 Dec 2012 09:06:11 +0000 (11:06 +0200)
committerNikos Mavrogiannopoulos <nmav@gnutls.org>
Wed, 2 Jan 2013 21:01:11 +0000 (22:01 +0100)
lib/gnutls_cipher.c
lib/gnutls_cipher.h
lib/gnutls_record.c

index 4953a34bbcf3d8db4515e3fcf031c87840e44b0e..cc30eefb6b3579543ad119f1c17a59f7c50270c7 100644 (file)
@@ -159,29 +159,26 @@ _gnutls_encrypt (gnutls_session_t session, const uint8_t * headers,
  * The output is preallocated with the maximum allowed data size.
  */
 int
-_gnutls_decrypt (gnutls_session_t session, uint8_t * ciphertext,
-                 size_t ciphertext_size, gnutls_datum_t *output, 
+_gnutls_decrypt (gnutls_session_t session, 
+                 gnutls_datum_t *ciphertext,
+                 gnutls_datum_t *output, 
                  content_type_t type,
                  record_parameters_st * params, uint64 *sequence)
 {
-  gnutls_datum_t gcipher;
   int ret;
 
-  if (ciphertext_size == 0)
+  if (ciphertext->size == 0)
     return 0;
 
-  gcipher.size = ciphertext_size;
-  gcipher.data = ciphertext;
-
   if (is_read_comp_null (params) == 0)
     {
       if (session->security_parameters.new_record_padding != 0)
         ret =
-          ciphertext_to_compressed_new (session, &gcipher, output, 
+          ciphertext_to_compressed_new (session, ciphertext, output, 
                                         type, params, sequence);
       else
         ret =
-          ciphertext_to_compressed (session, &gcipher, output,
+          ciphertext_to_compressed (session, ciphertext, output,
                                     type, params, sequence);
       if (ret < 0)
         return gnutls_assert_val(ret);
@@ -198,11 +195,11 @@ _gnutls_decrypt (gnutls_session_t session, uint8_t * ciphertext,
 
       if (session->security_parameters.new_record_padding != 0)
         ret =
-          ciphertext_to_compressed_new (session, &gcipher, &tmp,
+          ciphertext_to_compressed_new (session, ciphertext, &tmp,
                                         type, params, sequence);
       else
         ret =
-          ciphertext_to_compressed (session, &gcipher, &tmp, 
+          ciphertext_to_compressed (session, ciphertext, &tmp, 
                                     type, params, sequence);
       if (ret < 0)
         goto leave;
@@ -799,8 +796,7 @@ ciphertext_to_compressed (gnutls_session_t session,
   if (compressed->size < (unsigned)length)
     return gnutls_assert_val(GNUTLS_E_DECOMPRESSION_FAILED);
 
-  if (compressed->data != ciphertext->data)
-    memcpy (compressed->data, ciphertext->data, length);
+  memcpy (compressed->data, ciphertext->data, length);
 
   return length;
 }
@@ -922,10 +918,7 @@ ciphertext_to_compressed_new (gnutls_session_t session,
   if (compressed->size < (unsigned)length)
     return gnutls_assert_val(GNUTLS_E_DECOMPRESSION_FAILED);
 
-  if (compressed->data != ciphertext->data)
-    memcpy (compressed->data, &ciphertext->data[2+pad], length);
-  else
-    memmove (compressed->data, &ciphertext->data[2+pad], length);
+  memcpy (compressed->data, &ciphertext->data[2+pad], length);
 
   return length;
 }
index 104a624fb659f2e9c893fce88c64bdb276692593..9d0da641acae3d8215052acecca6c3ce8d1ac5e5 100644 (file)
@@ -26,7 +26,7 @@ int _gnutls_encrypt (gnutls_session_t session, const uint8_t * headers,
                      size_t ciphertext_size, content_type_t type,
                      record_parameters_st * params);
 
-int _gnutls_decrypt (gnutls_session_t session, uint8_t * ciphertext,
-                     size_t ciphertext_size, gnutls_datum_t *output,
+int _gnutls_decrypt (gnutls_session_t session,
+                     gnutls_datum_t *ciphertext, gnutls_datum_t *output,
                      content_type_t type, record_parameters_st * params,
                      uint64* sequence);
index 44178abf99b78d2712a2017d7d61df5e0950d4d0..005ffbefcd80811808d1f1edc1ff51b000d5f98f 100644 (file)
@@ -964,7 +964,7 @@ _gnutls_recv_in_buffers (gnutls_session_t session, content_type_t type,
                          gnutls_handshake_description_t htype, unsigned int ms)
 {
   uint64 *packet_sequence;
-  uint8_t *ciphertext;
+  gnutls_datum_t ciphertext;
   mbuffer_st* bufel = NULL, *decrypted = NULL;
   gnutls_datum_t t;
   int ret;
@@ -1047,14 +1047,15 @@ begin:
   if (decrypted == NULL)
     return gnutls_assert_val(GNUTLS_E_MEMORY_ERROR);
 
-  ciphertext = (uint8_t*)_mbuffer_get_udata_ptr(bufel) + record.header_size;
+  ciphertext.data = (uint8_t*)_mbuffer_get_udata_ptr(bufel) + record.header_size;
+  ciphertext.size = record.length;
 
   /* decrypt the data we got. 
    */
   t.data = _mbuffer_get_udata_ptr(decrypted);
   t.size = _mbuffer_get_udata_size(decrypted);
   ret =
-    _gnutls_decrypt (session, ciphertext, record.length, &t,
+    _gnutls_decrypt (session, &ciphertext, &t,
                     record.type, record_params, packet_sequence);
   if (ret >= 0) _mbuffer_set_udata_size(decrypted, ret);