Provided that I have some data I want to cipher and a password to do it:
- I generate a random IV
- I define
c = sha256(password)
- I generate an infinite stream where
x0 = sha256(IV xor c) and xi = sha256(xi-1 xor c)
. This produces blocks of 32 bytes and I yield them byte by byte output = data xor stream
Would this be secure? In case it's not, how insecure is it?
Note: The NSA isn't going to crack it, I just need it to be secure for a user with average-high cryptographic knowledge.
I know it may look similar to Is it feasible to build a stream cipher from a cryptographic hash function? but it has some differences:
- I use a random IV instead of starting with hash(data)
- Im xoring c in each phase of the stream generator, so even knowing xi you can't guess xi+1
sha256(password)
as that’s the first part (of many) where your idea goes downhill. SHA-256 is not a Password-Based Key Derivation Function. Using a weak password would end in disaster, no matter if you wrap it in SHA-256 or not. I‘ll leave the rest up to others to explain in actual answers. Btw. there are some related Q&As you might want to check: Building a stream-cipher out of a hash function? and Can I construct a feasible stream cipher out of HMAC and a secure hash algorithm? $\endgroup$