You are viewing a single comment's thread from:
RE: Introduction to Cryptography I: Encryption (Pt. 3 - Salsa20 Stream Cipher)
I wonder what the strengths and weaknesses of salsa20 are with respect to SHA256?
I looked up salsa20 and python, the sample code sure looks involved, maybe I will try to give that code a run one day.
Well, you might be quite figuratively comparing apples to oranges, but maybe not!
SHA256 is a hashing algorithm, and Salsa20 is a stream cipher. They are purpose-built for separate things. However, a stream cipher scheme could be constructed using SHA256; a quick Google search yielded this example.
So, what would the strengths and weaknesses of such a scheme be? Well, as one of the answers points out, only one keystream is generated by that algorithm. This is a weakness since it is actually really dangerous to re-use the same keystream to encrypt two different plaintexts.
This is easily remedied, though; just add a nonce. Instead of computing the keystream directly by hashing the shared secret, decide upon a random constant (doesn't matter what), concatenate it to the shared secret, and hash that to kick off your keystream. The nonce can be broadcasted in plaintext; it does not need to be private. After all of that is done, you should have a secure stream cipher.
So why use a purpose-built stream cipher like Salsa20 instead? Two reasons.
I think you got more of an answer than you were looking for, @procrastilearner, but I had fun writing it. Please don't hesitate to stick around for the rest of the series!
Also, nobody has done this post's activity yet; a 100% upvote awaits you if you do!
Wow. Great answer. Thanks.