# How easily could this be cracked?

I'm looking into encrypting files like this: First, I SHA-1 hash the password. Let's say the password is something normal like "hello123", and then hashed. Then I encrypt a file using this:

openssl aes-256-cbc -a -salt -in file -out file.enc


(using the hash for the password).

So it's basically just an AES-256-CBC encryption with a salt.

How easy would it be to crack this by brute force? (Assuming the attacker knows that we have aes-256-cbc with salt and that the original password is hashed.) For instance, how long time would it take these days, on "normal" hardware?

-
How is the password chosen and are there are requirements (length, special characters, etc)? –  mikeazo Oct 25 '12 at 14:35
@mikeazo There are no requirements, but let's for the sake of argument just say the password could be 4-10 characters long (a-z, 0-9). I suppose most brute force attacks start with the shorter passwords, and work their way towards the longer ones? –  Cryptography Oct 25 '12 at 14:38
Ok, now what is the attacker's goal? Say there are 100 encrypted files all encrypted with a different password. Does the attacker want to crack any one, all 100, or a specific one. –  mikeazo Oct 25 '12 at 14:51
@mikeazo Just a single file. (Or many files with the same password.) –  Cryptography Oct 25 '12 at 15:03

But who is attacking? What is their motivation? If it's a national security organization, their idea of a normal password cracker is different than yours. A criminal organization wanting to steal millions of dollars from a stock brokerage or a bank would certainly invest $100,000 in cracking it quicker. They would likely farm such a task out to a botherder, who might assign 1,000 internet zombie machines to crunch away at the task, cracking it in a day or two. - Another thing to consider is the randomness of the password. – mikeazo Oct 25 '12 at 14:30 @mikeazo, good point! A dictionary attack could yield a password based on a dictionary word in far less time. He did ask about brute forcing, but I completely forgot that he said the password is "something normal". Rules to apply to a dictionary, like the old Crack tool has, would give a huge potential advantage to the attacker. – John Deters Oct 25 '12 at 14:53 If the 100 byte password is hashed with SHA-1, only the 20 byte hash remains, so one would only need to brute force the hash, not the original password. – Paŭlo Ebermann Oct 26 '12 at 22:50 It depends. If your password requirements are weak, it's probably not too difficult to brute force given your weak key derivation (SHA-1). OpenSSL already does key derivation for you (the -salt parameter is a part of that), but if you wish to do it yourself, you should use something like PBKDF2 with 100,000+ rounds and a randomly-generated (for each file, if possible; otherwise, once) salt. If you do this and pass the key into the command line with -K, however, you will also need to take care of the IV requirements of CBC, which require generating a cryptographically random string of appropriate length, sending it along with the -iv flag, and storing it alongside the file. - So you could say that I was considering using first sha1 and then the "-salt". I suppose the former really is unnecessary. Whatever. But now, given that I use "-salt", does that make things secure? How many rounds does the built-in "-salt" do? – Cryptography Oct 25 '12 at 21:17 No idea. I couldn't find the key derivation function used by OpenSSL anywhere. If I were paranoid (I am), I would PBKDF2 it for 128,000 rounds using SHA-256 and a cryptographically-random salt of appropriate length to generate a key. Then I'd generate a unique, cryptographically random IV for every file I wanted to encrypt, and pass the key (not password and -salt), IV, and data in to the command line. – Stephen Touset Oct 25 '12 at 22:22 This doesn't add anything. OpenSSL already provides a proprietary method of key derivation / key stretching. So you have added a single hash to a whole iteration of hashes to derive the key. An attacker only has to perform a single hash to an attack of this scheme. Using a good password is going to help you much more than hashing a weak password. And a really insecure password will stay insecure forever. - I don't know how you're adapting the digest of SHA-1 to meet the key requirement of AES-256 (stretching the 160 bit digest into a 256 bit key), but if you somehow have a way of doing that without seriously compromising key entropy, then you have a theoretical key space of$2^{256}$. That window is limited by the limitations on your encryption passphrase however. In an ideal case for decryption where the person cracking your cipher has your program and knows the limits on your passphrases, they don't have to test all$2^{256}$, only your possibilities. Say you limit passphrases to$10$keys, alpha-numeric. That's$62$characters to work with. The practical key space for you is$62^{10}$. Arguably, it is currently impossible to decrypt even in the above worst-case scenario. This is largely due to another factor: verification of success. Say you only had$200$possibilities. Someone trying to decrypt the file needs a way to check if each of the$200\$ attempted keys yielded accurate results. Given that they may not know the nature of the file, that seriously complicates the process.