As the title states, say you create a hypothetical completely random string like one used for a OTP. Would hashing the string (provided it is the same length and possible characters as the hash output) and using the hash make the OTP any less cryptographically secure then just using the string as a key?
2 Answers
Hashing never outputs random string.
A hash algorithm is an algorithm which manipulates the input data in very strictly defined steps and outputs the result.
You can't know how the output will looks like before calculating the hash, so according to your question: if you input a random data, the output will look like random (but only to you, and not to the original data).
As much the length of input matches length of hash output, both methods are safe enough.
-
Cryptographic hash functions actually work quite well as cryptographically secure pseudorandom number generators. [The Java SecureRandom class works by repeatedly hashing SHA1 hashes](https://security.stackexchange.com/questions/47871/how-securely-random-is-oracles-java-security-securerandom). – Philipp Sep 14 '17 at 14:38
-
@Philipp random and pseudorandom are not the same thing, which is an extremely important distinction when it comes to the one time pad – Richie Frame Nov 14 '17 at 06:44
In practice your randomness is not degraded.
(For input size == output size: Any reduction in entropy would be through unnecessary collisions. They exist, but are rare enough that you can publish a paper about it when you find one. So it will not happen often enough to affect you.)
Mot likely it will improve the security of your cipher.
(In the case that your random string is not completely random, and it´s possible to use previous outputs of your random generator to predict future outputs, hashing will save you. An attacker will most likely not be able to make any predictions from hash(randomstring1) ).
- 1,111
- 7
- 10