My own opinion on the principles of cryptography
In the modern era, cryptography has become one of the most important part of our digital life. We all know, cryptography is used to encrypt, sign, authenticate. Above all, the most important is of course, the security. We would never want anyone except ourselves (or the recipients, if applicable). So here are some advices based on my own experience.
1. Use proper algorithm.
It depends on your needs. For example, would you like to use symmetric or asymmetric? If you are going to use symmetric, do you want to use Advanced Encryption Standard (AES, approved by the U.S. government, standardized in FIPS 197) or other algorithms like DES, Twofish, RC4, ChaCha20 etc.?
Don’t choose any symmetric algorithm except AES unless it’s absolutely needed.
As for asymmetric, there are RSA, ECC, DH (Diffie-Hellman) and DSA. RSA is one of the most widely used one. It has been used for nearly half a century. DSA was used by the U.S. government (FIPS 186, in 1994), but since DSA only has 64-bit long key size, it’s unsafe for today’s computation.
As for Elliptic Curve (ECC), things become more interesting. There are many kinds of ECCs, and each of them does different things. For example, ECDSA is only used for signature and authentication (common algorithms are NIST P-256/384/521), the specification is defined in FIPS 186-4, and it’s now used by the U.S. government. But this algorithm wouldn’t be your choice since there is controversy on backdoors (more on that later). EdDSA is also used for signature and authentication, but it uses Ed25519, which is now widely used. You may have noticed, none of above has the ability to encrypt files. This is where ECDH comes in. It uses Diffie-Hellman key exchange magnesium. And common algorithms are Curve 25519 (cv25519), and some NIST curves.
Bottom line then, use RSA if you need to ensure compatibility (for devices which is older than a decade), and it’s generally A LOT slower than ECC because of their theory. And I would strongly recommend you to use Curve 25519 aka. ECC for your daily life. (But for TLS, you may have no choice but to use ECDSA, published by NIST)
2. Use long enough keys.
Private keys are the critical part of the cryptography world. It acts the role of, well, a key. If anyone else gets it or cracks it, something terrible would happen. We would never want this to happen. So we should use key which is long enough. Here are my setup, which you can take a look.
RSA: use at least 2048 bits, and use 4096 bits when possible.
ECC: For Curve 25519, you wouldn’t have any choices but to use 256 bits. For NIST P-series curves, you will be comfortable with 256 bits. If you want more security, consider using 384 bits or 521 bits (yes this is not a mistake, it is indeed 521, not 512).
3. Avoid made in some countries.
In my opinion, you should avoid cryptography devices which are made in China (I’m not sure if there are others, but in my case, it’s made in China).
A lot of research indicates that cryptography devices which are made in China have backdoors which they can used to exploit your system if they wanted.
The Chinese government has forced all the manufacturers to integrate the government backdoor, and if they don’t follow it, they can’t sell it.
Thank God the Chinese customs doesn’t put limitations on the imported ones.
The most obvious example is TPMs (Trusted Platform Modules). The Chinese has their own indoor password standard, SM2/3/4. And they forced manufacturers to use them, instead of the regular ones. Because of some reasons, I can’t say much about it. Search it and you will understand.
Next time when purchasing an HSM, TPM, or security key, take a look at where the manufacturers are and where the factories are.
4. Don’t trust anyone.
You should never trust anyone except yourself. You should remember that anyone can pretend to be you and do malicious operations. That would bring a lot of serious trouble. You would never want this kind of things happen to you. And this is the reason why 3 exists above.
You should never give your private keys away. Instead, store it in an offline USB key and encrypt it use VeraCrypt, LUKS etc. Take it with you, or put it in a safe. Never let anyone touch it.
5. Be offline.
When possible, perform the critical cryptographical operations offline, and on a operating system (e.g. Tails) which is totally safe.
This is especially important for GnuPG, when you can certify others’ keys. You shouldn’t let anyone else pretend to be you and use your key to certify others’ keys.
6. Lost is better than leak.
When you have no choice but to hand out your private key, destroy it.
Normally we won’t want to do it because all the files you have encrypted are long gone, never coming back. But if you are some evil people, you would rather destroy the key than let other people know that.
Remember, do this only when you have no choices.
Outro
Above are my opinions on the principles of cryptography, references will be placed down below a short time later. I hope all of you can enjoy a happy digital life.