crypt_and_hash: check MAC earlier
diff --git a/programs/aes/crypt_and_hash.c b/programs/aes/crypt_and_hash.c
index 37d9d30..0448440 100644
--- a/programs/aes/crypt_and_hash.c
+++ b/programs/aes/crypt_and_hash.c
@@ -454,17 +454,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 );
@@ -486,6 +475,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;