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

How can I use asmcrypto to implement aes-cfb stream? #68

Closed
hackwaly opened this issue Feb 1, 2015 · 7 comments
Closed

How can I use asmcrypto to implement aes-cfb stream? #68

hackwaly opened this issue Feb 1, 2015 · 7 comments

Comments

@hackwaly
Copy link

hackwaly commented Feb 1, 2015

AES_CFB.encrypt doesn't return the iv for next encrypt. Maybe it will preserve iv internally for next encrypt, but it looks like all aes encrypt or decrypt operation share one asm module. It will conflict when more than one cfb stream encrypt process with out of order.
So, how can I use asmcrypto to implement aes-cfb stream?

@hackwaly hackwaly changed the title How can I use asmcrypto to implement aes-cfb stream. How can I use asmcrypto to implement aes-cfb stream? Feb 1, 2015
@vibornoff
Copy link
Member

Hi, starting from 4e64ff1 you can use progressive cipher interface.

var encryptor = new asmCrypto.AES_CFB.Encrypt( { key: ..., iv: ... } );

var ciphertext1 = encryptor.process(cleartext1).result;
var ciphertext2 = encryptor.process(cleartext2).result;
...
var ciphertextN = encryptor.finish().result;

This is quite new feature and it hasn't been release yet, so you have to build asmcrypto.js from the source.

@hackwaly
Copy link
Author

hackwaly commented Feb 2, 2015

It's pretty good! I've tried it yesterday. But it doesn't cover my needs.
CFB mode do not need padding, and it can encrypt any length plaintext. Somehow I need this feature:
The process method in CFB mode should returns ciphertext as same length as plaintext. So I can use it for socket encryption with no delay and no wrappings.

I'm trying to adapt this library to gopherjs to get huge performance improvement. In gopherjs, AES encryption takes nearly 1 second when encrypt 1MB text.

Thanks for your awesome works!

@vibornoff
Copy link
Member

CFB mode do not need padding

Yup, it doesn't. Just a doc error.

The process method in CFB mode should returns ciphertext as same length as plaintext.

Unfortunely it's not possible for now. I'm working on this. That relates to CTR, CCM, GCM and OBF modes too.

@hackwaly
Copy link
Author

hackwaly commented Feb 2, 2015

Thanks. That's will be excited!

@alippai
Copy link
Member

alippai commented Feb 2, 2015

You can check pako.js' inflate/deflate stream interface, I think we could apply it here.

@vibornoff
Copy link
Member

You can check pako.js' inflate/deflate stream interface, I think we could apply it here.

Bad idea, take a look to pako.js README:

var inflator = new pako.Inflate();

inflator.push(chunk1, false);
inflator.push(chunk2, false);
...
inflator.push(chunkN, true); // true -> last chunk
...
var output = inflator.result;

Great, we end up with a gigabyte of inflator.result held in memory.

@alippai
Copy link
Member

alippai commented Feb 2, 2015

Sorry, I didn't mean the default API: http://nodeca.github.io/pako/#Deflate.prototype.onData

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

No branches or pull requests

3 participants