ssl/*: remove SSL3_RECORD->orig_len to restore binary compatibility.
[openssl.git] / ssl / t1_enc.c
index 6d6046b3376b7858f27f0b9cd73b44638e356834..3dd36b81429dd271160d76ba5c12ab1aef0e2f1a 100644 (file)
@@ -528,6 +528,15 @@ err:
        return(0);
        }
 
+/* tls1_enc encrypts/decrypts the record in |s->wrec| / |s->rrec|, respectively.
+ *
+ * Returns:
+ *   0: (in non-constant time) if the record is publically invalid (i.e. too
+ *       short etc).
+ *   1: if the record's padding is valid / the encryption was successful.
+ *   -1: if the record's padding/AEAD-authenticator is invalid or, if sending,
+ *       an internal error occured.
+ */
 int tls1_enc(SSL *s, int send)
        {
        SSL3_RECORD *rec;
@@ -610,11 +619,7 @@ int tls1_enc(SSL *s, int send)
                if (!send)
                        {
                        if (l == 0 || l%bs != 0)
-                               {
-                               SSLerr(SSL_F_TLS1_ENC,SSL_R_BLOCK_CIPHER_PAD_IS_WRONG);
-                               ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_DECRYPTION_FAILED);
                                return 0;
-                               }
                        }
                
                EVP_Cipher(ds,rec->data,rec->input,l);
@@ -628,8 +633,6 @@ int tls1_enc(SSL *s, int send)
                 }
 #endif /* KSSL_DEBUG */
 
-               rec->orig_len = rec->length;
-
                ret = 1;
                if (s->read_hash != NULL)
                        mac_size = EVP_MD_size(s->read_hash);
@@ -686,7 +689,7 @@ int tls1_mac(SSL *ssl, unsigned char *md, int send)
        SSL3_RECORD *rec;
        unsigned char *mac_sec,*seq;
        const EVP_MD *hash;
-       size_t md_size;
+       size_t md_size, orig_len;
        int i;
        HMAC_CTX hmac;
        unsigned char header[13];
@@ -724,6 +727,10 @@ int tls1_mac(SSL *ssl, unsigned char *md, int send)
        else
                memcpy(header, seq, 8);
 
+       /* kludge: tls1_cbc_remove_padding passes padding length in rec->type */
+       orig_len = rec->length+md_size+((unsigned int)rec->type>>8);
+       rec->type &= 0xff;
+
        header[8]=rec->type;
        header[9]=(unsigned char)(ssl->version>>8);
        header[10]=(unsigned char)(ssl->version);
@@ -742,7 +749,7 @@ int tls1_mac(SSL *ssl, unsigned char *md, int send)
                        hash,
                        md, &md_size,
                        header, rec->input,
-                       rec->length + md_size, rec->orig_len,
+                       rec->length + md_size, orig_len,
                        ssl->s3->read_mac_secret,
                        EVP_MD_size(ssl->read_hash),
                        0 /* not SSLv3 */);
@@ -755,6 +762,14 @@ int tls1_mac(SSL *ssl, unsigned char *md, int send)
                HMAC_Update(&hmac,rec->input,rec->length);
                HMAC_Final(&hmac,md,&mds);
                md_size = mds;
+#ifdef OPENSSL_FIPS
+               if (!send && FIPS_mode())
+                       tls_fips_digest_extra(
+                                       ssl->enc_read_ctx,
+                                       hash,
+                                       &hmac, rec->input,
+                                       rec->length, rec->orig_len);
+#endif
                }
                
        HMAC_CTX_cleanup(&hmac);