* 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);
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;
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;
}
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;
}
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);
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;
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);