# Is my method symmetric encryption?

To obfuscate data I made up this method on the spot without planning since the goal wasn't real encryption.

At first I though this cannot be real encryption but after revisiting the code and reading on block symmetric encryption, and including R in the method, it seems that it is( looks like a stream cypher, OFB specifically ).

The method is the following( pseudo code ):

-Hash function parameters, secret key, hash and array elements all have the same size in bits.
-Size is at least 128 bits for this example.
-Using a cryptographic random generator.

H - cryptographic hash function
K - secret key, randomly generated
A - array of plaintext
L - array length
R - randomly generated, is not encrypted and is stored with the resulting encrypted data

keyhash = H(K)
hash = R
for( i , i < L , i++ )
{
hash = H( hash ^ keyhash )
A[i] ^= hash
}


Could this be called encryption or it has some fundamental flaws that would break it immediately?

-
Don't you mean $C_i = A_i \oplus h$? Otherwise you don't have ciphertext ;) –  Maarten Bodewes Jan 7 at 0:10
@MaartenBodewes-owlstead ^= is identical to x = x ^ h , where ^ is the xor operator, and x is the plaintext. Plaintext is xor-ed with h. Java doesn't have the ^ operator? ;-) –  this Jan 8 at 16:49
Of course, ^ is XOR in Java as well, but above you've only defined the plaintext. Now it's also the ciphertext after the operation. –  Maarten Bodewes Jan 8 at 16:56
@MaartenBodewes-owlstead Yes. I reduced the number of variables to a minimum for the example. –  this Jan 8 at 17:00

Your scheme is indeed an instance of output feedback mode (OFB), using $$(\mathit{key},\mathit{pad}) \mapsto H(\mathit{key}\oplus\mathit{pad})\text,$$ where $\mathit{key}$ corresponds to keyhash and $\mathit{pad}$ to hash, as the "block cipher". (It is very likely not really a block cipher due to lack of bijectivity, but that's not needed for output feedback mode.) When $H$ is a cryptographically secure hash function, the construction should have the same security properties as OFB using a "real" block cipher; however, since hash functions are usually slower than block ciphers, one generally prefers to use the latter.

-
How can you have a block cipher without calling a hash function every iteration? –  this Jan 4 at 17:22
Sorry, I do not understand your comment. Could you elaborate a bit? –  yyyyyyy Jan 4 at 17:44
since hash functions are usually slower than block ciphers, Isn't a hash function a part of the block cipher, in the block cipher encryption part: upload.wikimedia.org/wikipedia/commons/thumb/b/b0/… –  this Jan 4 at 17:54
Well, "block cipher encryption" denotes a block cipher. Most block ciphers (all that I know of) do not internally use hash functions since there is no reason to do so. –  yyyyyyy Jan 4 at 18:16
Really, what do they use then? Do you have any educational link(s)? –  this Jan 4 at 18:17

You are creating a bitstream and XORing it with your plaintext so yes, it is. More precisely, it's a block cipher. Have a look at a previous discussion.

-
That method seems different, specifically mine has: hash = H( hash ^ keyhash ). I don't think just hash = H( hash ) would do, since if attacker guesses plaintext in the middle then he/she can decrypt everything from that point on. –  this Jan 4 at 16:53