crypt_and_hash: check MAC earlier
diff --git a/programs/aes/crypt_and_hash.c b/programs/aes/crypt_and_hash.c
index 50218e1..333f10e 100644
--- a/programs/aes/crypt_and_hash.c
+++ b/programs/aes/crypt_and_hash.c
@@ -456,17 +456,6 @@
}
/*
- * Write the final block of data
- */
- cipher_finish( &cipher_ctx, output, &olen );
-
- if( fwrite( output, 1, olen, fout ) != olen )
- {
- fprintf( stderr, "fwrite(%ld bytes) failed\n", (long) olen );
- goto exit;
- }
-
- /*
* Verify the message authentication code.
*/
md_hmac_finish( &md_ctx, digest );
@@ -488,6 +477,17 @@
"or file corrupted.\n" );
goto exit;
}
+
+ /*
+ * Write the final block of data
+ */
+ cipher_finish( &cipher_ctx, output, &olen );
+
+ if( fwrite( output, 1, olen, fout ) != olen )
+ {
+ fprintf( stderr, "fwrite(%ld bytes) failed\n", (long) olen );
+ goto exit;
+ }
}
ret = 0;