• caglararli@hotmail.com
  • 05386281520

Security of simple XOR cipher

Çağlar Arlı      -    1 Views

Security of simple XOR cipher

A while ago I was toying around with XOR ciphers and stumbled on the following construction. I want to understand the security properties/implications of this idea, and thusly under what circumstances (if any) I might viably use it.


Encoding:

  1. Let's say we want to encode a small integer like 1234567890. This encodes to four bytes of data, so all cipher operations will operate on 4 bytes.

  2. Securely store a symmetric 4-byte key key.

  3. Retrieve 4 random bytes, aka random, from /dev/urandom.

  4. XOR random with data to get enc_data.

  5. XOR random with key to get enc_key.

  6. Concatenate enc_data and enc_key together to form the 8 byte encoded.

Decoding:

  1. The encoder understands the input format. It splits encoded into enc_data and enc_key.

  2. It derives random by XORing key with enc_key.

  3. It derives data by XORing random with enc_data.


When I came up with this I was trying to non-authoritatively gate access to resources by an intermediary HTTP gateway - an environment looking for a lightweight, "best effort" solution that wasn't the of the world if it was broken.

So I came up with the above, and for a moment was really proud that the intermediary could generate tiny little 8 byte opaque tokens when it allowed access.

But then I started to contemplate the 32-bit search space imposed by a merely 4-byte random nonce... and how the use of a CRNG would prove meaningful in practice... and got the eye-twitches :)

I primarily have two questions:

  1. What wheel have I reinvented?

  2. What are the security properties of this idea? How trivially compromisable is it?

Thanks!