Skip to content
This repository has been archived by the owner on Sep 20, 2023. It is now read-only.

CFB mode for stream cipher? #86

Open
srayuws opened this issue Apr 30, 2016 · 3 comments
Open

CFB mode for stream cipher? #86

srayuws opened this issue Apr 30, 2016 · 3 comments

Comments

@srayuws
Copy link

srayuws commented Apr 30, 2016

Hi,

Here is question about if there is any plan adding CFB mode to stream cipher.

Unlike CBC or ECB, CFB is a self-synchronizing stream cipher, which can work perfect in both block and stream mode.

It would be great if we can have such code

cfbStreamInit :: (BlockCipher cipher, ByteArray key) =>  key -> IV cipher -> StreamCipher cipher
cfbStreamEncrypt ::  ByteArray ba => StreamCipher cipher -> ba -> (ba , StreamCipher cipher)

Or just like what AES dose, having some monad encasing everything, IV and IV offset, in the context.

@Lazersmoke
Copy link

This appears to be already implemented, but commented out.

https://github.com/haskell-crypto/cryptonite/blob/master/Crypto/Cipher/Types/Block.hs#L252

I'm not familiar enough with this library to advise how to make this into a StreamCipher instance, (since it only appears to have a single method, not a decrypt and encrpyt, but a "combine") but would appriciate if someone could do that copy paste.

@Lazersmoke
Copy link

Upon further inspection, the StreamCipher class doesn't make any sense to me, and probably isn't what is needed here. There's no substantive documentation, and no instances as far as I can tell. I don't know why it exists at all tbh.

The commented out function I linked above looks sketchy at best, and does some really weird stuff compared to my code, which is based directly on the Wikipedia page on block cipher modes (Specifically the part about CFB8, which is essentially shimming CFB to work with block sizes of 8 bits. There is also a bitwise CFB1)

Perhaps that function is more efficient, but I don't think it actually has CFB8 implemented properly because it is padding with 0s and ciphering with CFB instead of ECB which is not how CFB8 or CFB1 work at all. It also appears to throw out the final IV, which is super weird.

@Xandaros
Copy link

I was actually looking for something like this.
I ended up using the implementation found here

It would be really nice if I could get the same functionality from cryptonite, though.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants