From: Nikos Mavrogiannopoulos Date: Tue, 2 Dec 2003 21:39:31 +0000 (+0000) Subject: some cleanups in the record protocol processing. X-Git-Tag: gnutls_1_0_0~2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=eca782dae7b830a1b9eda63fb1ae4e429edf18a6;p=thirdparty%2Fgnutls.git some cleanups in the record protocol processing. --- diff --git a/lib/gnutls_cipher.c b/lib/gnutls_cipher.c index 3c7eabdd70..cca6a8fed4 100644 --- a/lib/gnutls_cipher.c +++ b/lib/gnutls_cipher.c @@ -332,7 +332,7 @@ int _gnutls_ciphertext2compressed(gnutls_session session, uint8 MAC[MAX_HASH_SIZE]; uint16 c_length; uint8 pad; - uint16 length; + int length; GNUTLS_MAC_HANDLE td; uint16 blocksize; int ret, i, pad_failed = 0; @@ -407,7 +407,8 @@ int _gnutls_ciphertext2compressed(gnutls_session session, */ if ( ver == GNUTLS_TLS1) for (i=2;i 0) + _gnutls_hmac(td, ciphertext.data, length); mac_deinit( td, MAC, ver); } + /* This one was introduced to avoid a timing attack against the TLS + * 1.0 protocol. + */ + if (pad_failed != 0) return pad_failed; + /* HMAC was not the same. */ if (memcmp @@ -455,11 +453,14 @@ int _gnutls_ciphertext2compressed(gnutls_session session, gnutls_assert(); return GNUTLS_E_DECRYPTION_FAILED; } - - /* This one was introduced to avoid a timing attack against the TLS - * 1.0 protocol. + + /* copy the decrypted stuff to compress_data. */ - if (pad_failed != 0) return pad_failed; + if (compress_size < length) { + gnutls_assert(); + return GNUTLS_E_INTERNAL_ERROR; + } + memcpy( compress_data, ciphertext.data, length); return length; } diff --git a/lib/gnutls_cipher_int.c b/lib/gnutls_cipher_int.c index caddcebcd6..05267fff1b 100644 --- a/lib/gnutls_cipher_int.c +++ b/lib/gnutls_cipher_int.c @@ -66,7 +66,9 @@ gcry_error_t err = GPG_ERR_GENERAL; /* doesn't matter */ return ret; } -int _gnutls_cipher_encrypt(GNUTLS_CIPHER_HANDLE handle, void* text, int textlen) { +int _gnutls_cipher_encrypt(GNUTLS_CIPHER_HANDLE handle, void* text, + int textlen) +{ if (handle!=GNUTLS_CIPHER_FAILED) { if (gcry_cipher_encrypt( handle, text, textlen, NULL, textlen)!=0) { gnutls_assert(); @@ -76,7 +78,9 @@ int _gnutls_cipher_encrypt(GNUTLS_CIPHER_HANDLE handle, void* text, int textlen) return 0; } -int _gnutls_cipher_decrypt(GNUTLS_CIPHER_HANDLE handle, void* ciphertext, int ciphertextlen) { +int _gnutls_cipher_decrypt(GNUTLS_CIPHER_HANDLE handle, void* ciphertext, + int ciphertextlen) +{ if (handle!=GNUTLS_CIPHER_FAILED) { if (gcry_cipher_decrypt( handle, ciphertext, ciphertextlen, NULL, ciphertextlen)!=0) { gnutls_assert(); @@ -86,7 +90,8 @@ int _gnutls_cipher_decrypt(GNUTLS_CIPHER_HANDLE handle, void* ciphertext, int ci return 0; } -void _gnutls_cipher_deinit(GNUTLS_CIPHER_HANDLE handle) { +void _gnutls_cipher_deinit(GNUTLS_CIPHER_HANDLE handle) +{ if (handle!=GNUTLS_CIPHER_FAILED) { gcry_cipher_close(handle); }