Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong Type of Encryption Algorithm #1

Open
marcoonroad opened this issue Nov 18, 2018 · 7 comments
Open

Wrong Type of Encryption Algorithm #1

marcoonroad opened this issue Nov 18, 2018 · 7 comments
Labels
enhancement New feature or request invalid This doesn't seem right

Comments

@marcoonroad
Copy link
Owner

It's quite wrong to use ARC4 / Stream Cipher encryption algorithms here. I really don't remember why I had such idea in the first place. Stream ciphers are only good if the following conditions are meet:

  • The data has a variable size (imagine streams of video or telephone calls).
  • The keys to encrypt are never reused again.

In our current state of affairs, we're doing the opposite of that. Really. And it's really insecure by doing that, so. Really. Our private keys have a fixed-length, first and foremost. We're quite wrong here, and it's annoying for any expert information security engineer to see that. By second, the keys to encrypt and decrypt private keys can be used and reused again, indefinitely, 'cause it's the responsibility of the caller / client of our library to define that. Again, we're quite wrong and this can render the whole Post-Quantum security of this library as flawed even on Classical Machines.

Therefore, I should figure out Block Cipher algorithms to use here instead. By preference, strong ones.

@marcoonroad marcoonroad added enhancement New feature or request invalid This doesn't seem right labels Nov 18, 2018
@marcoonroad
Copy link
Owner Author

The most known good encryption algorithm is Blowfish, but neither the author recommends it anymore. Instead, he recommends Twofish and forward. Twofish is slower than AES, in which is slower than Blowfish, but I should not care about performance, 'cause the importing and exporting of private keys is not an often operation in the same sense of signing and verification. There's no Twofish implementation for OCaml, only Blowfish. Therefore, I must implement Twofish by hand in OCaml or link C bindings here.

@marcoonroad
Copy link
Owner Author

I've changed my mind a bit by now. I'm using the already provided AES encryption in the Nocrypto library. There's no problem in using ECB mode of operation, 'cause our data (the private keys) are quite random, and thus, no pattern is leaked by the deterministic encryption nature of the algorithm. If our encrypted data were sensible and non-random, for instance, this picture of me, the encrypted message (a.k.a cipher text) would leak some patterns, such as my face's traces, and therefore, privacy and confidentiality are broken. In such case, the CTR and CBC modes of operations are recommended.

@marcoonroad
Copy link
Owner Author

(It doesn't mean / imply that future plans for Twofish doesn't exist.)

@marcoonroad
Copy link
Owner Author

marcoonroad commented Nov 24, 2018

Update:
I must use a Password-based Key Derivation algorithm. Currently, the encryption uses a sole SHA256 hash (derived from password) as encryption key. It's unsafe. Quite unsafe. Nowadays, there are CPU instructions, GPUs, FPGAs and even ASICs dedicated to SHA256 hashing. It's not much hard to perform brute-force / dictionary attacks on that, and some analysis beforehand guessing good password candidates turns it even more easy.

The existing Password-based Key Derivation algorithms are (from the most weak to the most strong):

  • bcrypt
  • pbkdf2
  • scrypt
  • argon2

Such Password-based Key Derivation Algorithms perform intensive tasks to hardening and slow automated brute-force attacks.

Another possible solution is to use a deterministic Proof-of-Work (based on the given password) to derive an encryption and decryption key. The user/client could set the difficulty during the encryption/decryption process, so it would take a random but long amount of time to backup and restore private keys, thus rendering brute-force attacks infeasible.

@marcoonroad marcoonroad reopened this Nov 24, 2018
marcoonroad added a commit that referenced this issue Nov 24, 2018
proof-of-work is used for the hardening of the encryption process.
AES-256 bits (32 bytes) is quantum-safe (by now?), but the password
as defined by the user/client might be vulnerable to brute-force and
dictionary attacks. therefore, the proof-of-work ensures that the
derived encryption key from the password plain text takes a long time,
thus, slowing down such attacks. it turns the client encryption process
really slow, a good approach might be to store such encrypted private
keys with a less CPU-expensive difficulty, but whenever the user wants
to backup or restore her private keys outside her computer, she must
pass through this more CPU-expensive difficulty.

a planned / future command line interface may deal with that, for instance,
to load encrypted private keys from filesystem, the command-line may take
30-60 seconds by some certain PoW's difficulty, but whenever the user
wants to dump or load base-64 versions of the encrypted private keys,
5-6 minutes is a good/secure backup time (really? must re-check that --)

Signed-off-by: Marco Aurélio da Silva <[email protected]>
@marcoonroad
Copy link
Owner Author

marcoonroad commented Nov 25, 2018

Proofs-of-Work are often RAM-memory-friendly, so attacks made by ASICs decrease the hardening embedded as a Key Derivation Function here. I should drop such "hacking" / workaround and look forward the Argon2 password-based key derivation function anyways.

@marcoonroad
Copy link
Owner Author

BUMP:

There's some folks who don't trust AES. 🙃
(Perhaps neither me...) 🤔
Therefore I should look forward another Encryption algorithm.

@marcoonroad
Copy link
Owner Author

I've changed my mind a bit by now. I'm using the
already provided AES encryption in the Nocrypto
library. There's no problem in using ECB mode of
operation, 'cause our data (the private keys) are
quite random, and thus, no pattern is leaked by
the deterministic encryption nature of the
algorithm. If our encrypted data were sensible
and non-random, for instance, this picture of me,
the encrypted message (a.k.a cipher text) would
leak some patterns, such as my face's traces, and
therefore, privacy and confidentiality are broken.
In such case, the CTR and CBC modes of
operations are recommended.

Nevermind, using AES CBC nevertheless.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

1 participant