jedisct1 / libhydrogen

A lightweight, secure, easy-to-use crypto library suitable for constrained environments.
https://libhydrogen.org
Other
608 stars 92 forks source link

Maximum length of message ? #34

Closed arshidkv12 closed 5 years ago

arshidkv12 commented 5 years ago

What is the maximum length of message? Can I encrypt 100MB text file ?

jedisct1 commented 5 years ago

A message can be up to 2^64 bit long, so there is no practical limit.

The number of messages encrypted with the same key must remain below 2^64, which is rarely an issue either.

arshidkv12 commented 5 years ago

Thank you... Can use this library for closed source project ? Like I will distribute only binary file.

jedisct1 commented 5 years ago

Still, for very large files, chunking is recommended. If only to save memory, and avoid processing a 100 MB ciphertext, only to discover later that it is invalid/corrupted.

This is fairly easy to do with libhydrogen, using message identifiers. Set msg_id to 0 for the first chunk, 1 for the second, etc. You can take a look at encpipe for an example implementation.

And yes, you can totally use this in a closed source project, commercial or not, provided that a copy of the license is present somewhere.

arshidkv12 commented 5 years ago

Is there any way to reduce key size ? Like 32 characters length key.

jedisct1 commented 5 years ago

The key is 256 bits. That's 32 bytes.

This is supposed to be a high-entropy key, indistinguishable from random, not a password.

If you really need to use a password here, no matter what its length is, use a password hashing function first, to derive a suitable key from the password.

arshidkv12 commented 5 years ago

I want encrypt plain text file with short key. How it possible ?

arshidkv12 commented 5 years ago

Sorry for my basic questions.

jedisct1 commented 5 years ago

Exactly as explained above: derive a key from the short key/password using hydro_pwhash_deterministic() and use that key with hydro_secretbox_encrypt/decrypt().

Or look at encpipe.c; it does exactly that.

arshidkv12 commented 5 years ago

Thank you very much