From: Nikos Mavrogiannopoulos Date: Wed, 19 Dec 2012 09:06:11 +0000 (+0200) Subject: some simplifications X-Git-Tag: gnutls_3_1_7~141 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e1d6f7fd8a2350956d8a8356d3243c726d88906c;p=thirdparty%2Fgnutls.git some simplifications --- diff --git a/lib/gnutls_cipher.c b/lib/gnutls_cipher.c index 4953a34bbc..cc30eefb6b 100644 --- a/lib/gnutls_cipher.c +++ b/lib/gnutls_cipher.c @@ -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; } diff --git a/lib/gnutls_cipher.h b/lib/gnutls_cipher.h index 104a624fb6..9d0da641ac 100644 --- a/lib/gnutls_cipher.h +++ b/lib/gnutls_cipher.h @@ -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); diff --git a/lib/gnutls_record.c b/lib/gnutls_record.c index 44178abf99..005ffbefcd 100644 --- a/lib/gnutls_record.c +++ b/lib/gnutls_record.c @@ -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);