Here are some more or less explicit warnings against using the same
key for both encryption and authentication:
"...computing the HMAC with a *completely separate* key; e.g., not the
same key you used to perform encryption"[8]
"...on a general basis, use a Key Derivation Function to extend your
encryption key into two keys, one for HMAC and one for the actual AES
encryption (make it three keys: one for the HMAC-for-IV, one for
encryption, and one for the MAC which you *of course* add to the
message to thwart active attackers)"[9]
"...even if (in the case of Encrypt-then-MAC) he can correctly forge
the MAC (say, if he stole the MAC key but doesn't have the Encrypt
key)."[10] (Note: This is from Colin Percival's (creator of Tarsnap)
blog. It's easily the best short piece on "encrypt-then-mac" I've
seen; highly recommended read.)
"Clearly, if you had been using AES-256-CBC for confidentiality and
AES-256-CBC-MAC for authentication, it would not be secure to use the
same key for both confidentiality and authentication. Hence, using the
same key for confidentiality and authentication cannot *generally* be
secure; you need additional premises to arrive at that conclusion. In
your case it would be that the algorithms are "too different" for any
related key attack to be feasible. This assumption is usually
considered to be a bit too shaky for safety, which is why the
established practice, in cases similar to yours when you start with a
single shared secret key, is to derive different keys for
confidentiality and authentication from that shared secret. If you do
that the security of your construct will rest on the assumption that
the KDF you use is a PRF and not on the assumed difference of the
confidentiality algorithm and MAC algorithm."[11]
"... With HMAC vs AES, no such interference is known. The general
feeling of cryptographers is that AES and SHA-1 (or SHA-256) are
"sufficiently different" that there should be no practical issue with
using the same key for AES and HMAC/SHA-1. However, simply defining
that "difference" with any kind of scientific rigor would be hard, and
it is not a much explored security feature. So that's one of these
constructions which can be qualified as "no urgency to fix it, but
don't do it if you can avoid it". A much "safer" way (in the sense of:
"we know what characteristics of the involved algorithms we are
exercising") is to take your master key K, and derive from it, with a
good one-way Key-Derivation Function, a sub-key for encryption and
another sub-key for the MAC...."[12]
And this seems to be another strong reason to start using a good key
derivation function:
"The OpenSSL apps need to be used carefully, they often have old and
possibly insecure defaults, at least by contemporary standards.
In this case openssl enc defaults to using a digest of MD5 (apps/enc.c)
...
The biggest problem here is not the potentially problematic use of
MD5, it's that the KDF that openssl enc uses is "cheap", specifically
it only uses one round, making brute force attacks on passwords the
best attack (apps/enc.c, line #569):
EVP_BytesToKey(cipher,dgst,sptr,
(unsigned char *)str,
strlen(str),1,key,iv);
The sixth parameter to EVP_BytesToKey (hard-coded to 1) is the count,
designed to slow down an attacker (or not, in this case). What
*should* be used instead is a robust, expensive key-stretching
function like bcrypt or scrypt."[13][14]
In other words, "openssl enc" uses a rather weak key derivation
function by default. We can get around the lesser problem of md5 [15]
by using the "-md" option (e.g., "openssl enc -md sha512 ..."). But if
we're going to do that, perhaps we might as well (also) use a proper
key derivation function to initially turn the user's passphrase into
two keys (one for enc, one for hmac). If it's important to stay within
openssl, perhaps PKCS5_PBKDF2_HMAC(_SHA1) is an option?[16] If it's
not important to stay within openssl, bcrypt is probably better, and
scrypt is probably best.[17]
[8]
http://crypto.stackexchange.com/a/5429
[9]
http://crypto.stackexchange.com/a/298
[10]
http://www.daemonology.net/blog/2009-06-24-encrypt-then-mac.html
[11]
http://crypto.stackexchange.com/a/8084
[12]
http://crypto.stackexchange.com/a/8086
[13]
http://security.stackexchange.com/a/79923
[14]
https://www.openssl.org/docs/crypto/EVP_BytesToKey.html
[15]
http://security.stackexchange.com/a/23141
[16]
https://www.openssl.org/docs/crypto/PKCS5_PBKDF2_HMAC.html
[17]
https://www.tarsnap.com/scrypt.html
-----BEGIN PGP SIGNATURE-----
iQIcBAEBCgAGBQJVAYNkAAoJEJh4Btx1RPV8eJIP/R9eSgxTZw3ZqbHlqf/87yDV
M8s6w7qMq0GdFH0Clo1hM9SdDjR/8doGNaEZ3p3Dm+V/A0TL+fbuS29TvvJSpjfW
AuVpOcvjrjdNMKaUQ22uHD9PPgb4MOMhz7YMW1/5fkfqlSzqWOpeJijLs+HELhlE
8HCUwF6YDLm2xCOgIVo3CUIsrwTtUvYVbMAn3oIQXT5tFPB7CqAxniWDwiAIjyyk
zTMTsJlixJYikMmX9EHFAyDa/xflcx/8dkHi89Bbn6lctsLICVwRkgyCX3/PT1RK
8lUZLJEH91PBVyS86GH30N2ABUOwo8IXPWeYHfYrKFx6ibZY8qIxOPIYMCQdDrFp
msZA67xsMXFksSp4g2RPCmKSbDcvgXrLozyrZIwccb6bRdlUt2f84eXYKv0mYPv9
ja3yH/LpVYG+X/2HbpQmEwoC+Wc+JHFRhaANd1aa+vH2g5VyrlmqegC4EQRzLKNZ
/7htGmHo15INeaiU6awteS9Mmxo8NtWuWX0Btb+PuGFsgmXs/0budce/FzL4lglh
DNJhtWF7xsAJIR7X1hHEcUFnHyI2VXWDlmpbtPxKs9klyBQU4f8EcFNA96aETABn
J4mhbhcUipNKy1O23ZJp0C3mZALlPiiBPgusQnargaFDXPTrYlkWOVDk/S1hZfQN
gx3Z21oWe0RNSxiqll0J
=fZWi
-----END PGP SIGNATURE-----