0
$\begingroup$

I've found an algorithm taht performs the following: expand the two keys using cryptographic hashing functions so the final keys will look like nonsense ASCII, then XOR them together to create a single key.

Is this algorithm secure?

Is there any benefit to xor together two keys rather than one with the message?

$\endgroup$
2
$\begingroup$

Well, yes.

The output of the cryptographic hash functions is indistinguishable from random - although not perfectly secure. So if you have $c = \operatorname{H}(K_1) \oplus \operatorname{H}(K_2) \oplus p$ then the result should be dependent on both keys, and you would almost have doubled the key size. This is similar to use two iterations of a block cipher and XOR them together. The XOR function itself should not leak any information about the hash values themselves.

There are however (quite) a few practicalities:

  • hash algorithms are sometimes not designed to be resistant to side channel attacks, and hashing keys may leak information about the keys themselves;
  • if the keys themselves are not very secure - e.g. relatively short or non-random - then having a hash could be used to distinguish the valid key values;
  • key reuse, as in a one time pad, is obviously catastrophical to security.

Using a key derivation function KDF such as HKDF over the concatenation of both key a values and then a trusted cipher would of be a much better way of accomplishing the same level of security, although I would imagine that the scheme in the question is more efficient on restricted platforms. Obviously a cipher has the advantage to be able to encrypt almost any amount of data instead of being restricted to the output size of the hash.

Finally, if the keys are already fully secure, they could be directly used in a one time pad. If the keys are passwords then a password based KDF should be used instead to strengthen the key material before it is used.

$\endgroup$
  • $\begingroup$ As OP didn't describe how the encryption actually works, one can only hope it doesn't go keyshashresult ^ plaintextblock1, keyshashresult ^ plaintextblock2, …. But I guess that's what you mean with "key reuse, as in one time pad…"? $\endgroup$ – e-sushi Feb 27 '18 at 23:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.