From: Nikos Mavrogiannopoulos Date: Sun, 17 Mar 2013 11:22:11 +0000 (+0100) Subject: corrected bug in stream ciphers and added new cipher to the new padding format. X-Git-Tag: gnutls_3_2_0~111 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=be8fad6400c00ddfa61df2eabe4ddbadc7c43b24;p=thirdparty%2Fgnutls.git corrected bug in stream ciphers and added new cipher to the new padding format. --- diff --git a/lib/gnutls_cipher.c b/lib/gnutls_cipher.c index 8531a4c7b0..390a6b1ce8 100644 --- a/lib/gnutls_cipher.c +++ b/lib/gnutls_cipher.c @@ -417,7 +417,7 @@ compressed_to_ciphertext (gnutls_session_t session, */ if (auth_cipher) return gnutls_assert_val(GNUTLS_E_INTERNAL_ERROR); - else if (iv_size > 0) + else if (block_algo == CIPHER_STREAM && iv_size > 0) _gnutls_auth_cipher_setiv(¶ms->write.cipher_state, UINT64DATA(params->write.sequence_number), 8); } @@ -474,6 +474,9 @@ compressed_to_ciphertext_new (gnutls_session_t session, int explicit_iv = _gnutls_version_has_explicit_iv (session->security_parameters.version); int auth_cipher = _gnutls_auth_cipher_is_aead(¶ms->write.cipher_state); uint8_t nonce[MAX_CIPHER_BLOCK_SIZE]; + unsigned iv_size; + + iv_size = gnutls_cipher_get_iv_size(params->cipher_algorithm); _gnutls_hard_log("ENC[%p]: cipher: %s, MAC: %s, Epoch: %u\n", session, gnutls_cipher_get_name(params->cipher_algorithm), gnutls_mac_get_name(params->mac_algorithm), @@ -528,6 +531,8 @@ compressed_to_ciphertext_new (gnutls_session_t session, cipher_data += AEAD_EXPLICIT_DATA_SIZE; length += AEAD_EXPLICIT_DATA_SIZE; } + else if (iv_size > 0) + _gnutls_auth_cipher_setiv(¶ms->write.cipher_state, UINT64DATA(params->write.sequence_number), 8); } else { @@ -834,7 +839,9 @@ ciphertext_to_compressed_new (gnutls_session_t session, unsigned int ver = gnutls_protocol_get_version (session); unsigned int tag_size = _gnutls_auth_cipher_tag_len (¶ms->read.cipher_state); unsigned int explicit_iv = _gnutls_version_has_explicit_iv (session->security_parameters.version); - + unsigned iv_size; + + iv_size = gnutls_cipher_get_iv_size(params->cipher_algorithm); blocksize = gnutls_cipher_get_block_size (params->cipher_algorithm); /* actual decryption (inplace) @@ -866,6 +873,11 @@ ciphertext_to_compressed_new (gnutls_session_t session, length_to_decrypt = ciphertext->size - tag_size; } + else if (iv_size > 0) + { /* a stream cipher with explicit IV */ + _gnutls_auth_cipher_setiv(¶ms->read.cipher_state, UINT64DATA(*sequence), 8); + length_to_decrypt = ciphertext->size; + } else { if (ciphertext->size < tag_size)