The 100 Basic Rules of Cryptography (and Secure Programming)

Kerckhoff’s principle defines that “a Cryptographic system should be designed to be secure, even if all its details, except for the key…

The 100 Basic Rules of Cryptography (and Secure Programming)

Apple [here] Spotify [here]

Kerckhoff’s principle defines that “a Cryptographic system should be designed to be secure, even if all its details, except for the key, are publicly known”, but there aren’t too many other rules defined. So here are my 100 Basic Rules of Cryptography (and Secure Programming). First, my Top 10:

  1. Cryptography is both an art and a science.
  2. Cryptography needs to be both theoretical and practical — one without the other leaves gaps.
  3. The maths is not actually that difficult — it is just the way that researchers talk about it that is a problem.
  4. Know your knowledge gaps — and plug them.
  5. Your university education is unlikely to have properly set you up for the serious world of cryptography.
  6. Crypto is cryptography and not cryptocurrency.
  7. Few methods are perfect — know the limits of any method you use.
  8. Don’t cook your own crypto! How many times do you have to say this to yourself?
  9. Security-by-obfuscation never works that well.
  10. Confidentiality, Integrity and Assurance are different things and require different methods. Don’t merge them all together into one thing.

And the rest:

  1. Digital certificates and PKI (Public Key Infrastructure) are two of the least understood areas of cybersecurity — don’t expect many people to understand them.
  2. For public key encryption, you encrypt with Alice’s public key, and she decrypts with her private key.
  3. For public key signatures, you sign a hash of the message with your private key, and Alice proves your public key.
  4. Your baseline hack is always brute force. Know how many dollars it would cost the NSA to crack something.
  5. Machine code can reveal your secrets.
  6. A hack of one key should not lead to the loss of all the previous keys.
  7. A key should only exist for the time it was meant to exist for.
  8. Use session keys wherever possible, and watch out for long-term keys.
  9. Your role is typically to protect the user and not reveal things to the NSA.
  10. Listen to experts, and be a teacher to others. Be open with your knowledge, and don’t pretend you know something that you don’t.
  11. Try and understand the basics of the maths involved — otherwise, you are trusting others.
  12. Understand entropy, and know how to calculate it and prove it with experiments.
  13. Run entropy calculations before pushing related code to production.
  14. Don’t use a method unless it has been peer-reviewed and published.
  15. Understand the strengths and weaknesses of your methods. No method is perfect —but at least know what problems it might cause and try and mitigate against these.
  16. Know why you have chosen X over Y, and be able to defend the reason to others.
  17. The maths may be sound, but human is typically the main weakness.
  18. Everything will work fine until it doesn’t.
  19. Test for out-of-band conditions as much for good conditions.
  20. Zero is not your friend in cryptography, so always know what it will do to your system.
  21. Don’t just catch exceptions; action them. Do not allow to progress unless everything checks out okay.
  22. Log good and bad. Catch good things, along with bad things.
  23. Monitor your security logs for exceptions and bad operations.
  24. Remove debugging code from your production version.
  25. Keep up to date with the latest research.
  26. Beware of backdoors in methods and code.
  27. Side channels are smart ways to reveal the 1s and 0s, and every bit discovered reduces the security level by two and makes it so much less expensive to crack. Every bit drops the price tag for a crack by a half.
  28. The core security of your system is likely to depend on the generation of random oracles (seed values). Make sure they are generated so they do not repeat within a given time and cannot be brute forced by the NSA.
  29. If you can use real randomisation and not pseudo-randomness.
  30. If you generate pseudo-randomness, take the randomness from several sources.
  31. Continually review your code, and get external experts to review it.
  32. Don’t push your code in production until you have tested it — fully!
  33. Check the code in the libraries you use, and perhaps, don’t use them if there are no open-source repositories.
  34. If you can, open source your libraries.
  35. Watch out for version updates on your code, and try and lock a given (known) version to your code.
  36. Encrypt anything that looks like PII (Personally Identifiable Information) at rest and over the air.
  37. Remember that running memory can reveal keys and cryptographic artefacts, so know the risk.
  38. Learn a new method every day, and don’t get stuck with the same old crypto!
  39. Quantum computers will happen one day and will disrupt our life, so start thinking about the impact they might have.
  40. Revealing your private keys is like giving someone the keys to your castle, so know where they are and restrict access to them.
  41. Only give access to private keys to those you most trust to use them properly.
  42. Air your development environment from your production environment, and don’t let private keys propagate.
  43. The best systems use zero trust. No rights to anything unless they can be proven.
  44. You will — at times — need to revoke your public keys. Be aware of the processes involved and of the embarrassment it will cause.
  45. Educate the board on the importance of good crypto!
  46. Encourage your team to undertake academic study, and get them to reserve a few hours a week for independent study of new methods.
  47. Read classic research papers, and don’t dismiss methods because they are not currently used.
  48. Collaborate with an academic team which has complementary skills to your own team.
  49. If you lack theoretical knowledge in your team, get external experts to come in for a chat.
  50. Once a private key is destroyed, any data encrypted with it is also likely to be destroyed.
  51. Limit the copies of a secret key.
  52. If you can, keep your keys in an HSM (Hardware Security Module).
  53. Cryptography in the Cloud pushes you to the limits and will often enhance the methods you use.
  54. Back up those secret keys, but make sure they are well-wrapped before putting them in a place that others can access.
  55. Learn about the garbage collector and how your program deals with data when running.
  56. Leave the coding of the maths in papers to experts.
  57. Don’t trust auditors to prove the security of your system.
  58. Generally, auditors are likely to have little understanding of the methods you will use — get experts to review your methods.
  59. Beware of Denial of Service (DoS) on your code — such as continual exception handling.
  60. Most systems boil down to one single thing that defines the overall security — know what this is.
  61. If you are interested in the X method, go and contact the person that created it — you will often be surprised how open many researchers are in sharing their ideas.
  62. Watch those CVE updates like a hawk — it can be a race between you and your adversary.
  63. On Cloud-based systems, log everything about your keys.
  64. In the Cloud, only allow keys to be used for the purpose they should be used for, and don’t use them generally.
  65. Limit access to keys for services and roles.
  66. Reduce the impact of a stolen or lost secret key.
  67. Never encrypt large-scale data infrastructures with the same secret key — try to use envelope encryption.
  68. Passwords are dead — replace with cryptographic signing methods.
  69. Your enemy can be within. Watch out for key stealing and deletion.
  70. Tell your incident response team about the difference between losing encrypted data and non-encrypted data.
  71. Scan your network for secret keys placed in locations where they should not be stored.
  72. Know what the acronyms mean and not just what they stand for.
  73. Know why we use message authentication codes (MACs).
  74. If you need to generate an encryption key from a password or secret, pick a good KDF (Key Derivation Function), and know the cost to crack it.
  75. Rainbow tables aren’t much of a threat anymore, so make use your use a good salt value.
  76. Everything below 72 bits of entropy is likely to be crackable by the NSA — unless a slow method is used for the processing with the key.
  77. Nonce/salt values should start at 96 bits. Never use anything less.
  78. RC4 has been cracked … get over it.
  79. Stream ciphers can often be broken — make sure you never reuse your salt value.
  80. DES and 3DES are mainly uncracked, but DES only uses a 56-bit key, so never use it
  81. Compared with ECC, RSA requires a good deal more processing and has larger key sizes, but it is still great.
  82. ECDSA suffers from nonce reuse attacks.
  83. For digital signatures, you should delete the nonce value after the signature has been created, but for symmetric key and hashing, you need to store it.
  84. In ECC, the public key is a point on the elliptic curve. For secp256k1, we have a 256-bit private key and a 512-bit (x,y) point for the public key. A “04” in the public key is an uncompressed public key, and “02” and “03” are compressed versions with only the x-co-ordinate and whether the y coordinate is odd or even.
  85. Consider writing papers — it is a great way to develop your writing and abstraction skills.
  86. Don’t sit back with the status quo — try to continually improve privacy and security.
  87. Have a risk register and maintain it. Don’t be shy, and don’t hide things.
  88. Have someone to check your code — on a regular basis.
  89. Remember Moore’s Law … computing power is increasing every year, so know that something that is safe now might not be in 10 years.
  90. Know how long something needs to be kept secure and secure for that age (and a lot more).

And there you go … 100 rules of cryptography!

Still interested? If you don’t have an MSc, they go and do one. We have a great one which can be done part-time and remotely:

Or come and study Applied Cryptography with us.