by api · 4y ago · 0 comments
The only people who will listen to “don’t roll your own crypto” are people who maybe should be learning crypto since they can approach it with the needed level of humility.
The people who should not be writing crypto are precisely the ones who will ignore this advice.
It’s also sort of elitist sounding and that puts people off and further reduces the odds that they will listen.
Everyone knows that someone “rolls their own” crypto or none of it would exist. How does one get into this mysterious club? As near as I can tell you… roll your own crypto… and manage not to fuck it up. So the way you get to become someone who gives this sage advice is by disobeying it.
(Of course there are degrees and Ph.Ds and publications but that’s the realm of real cryptographers of the sort that design ciphers. I’m talking about programmers using crypto.)
> The people who should not be writing crypto are precisely the ones who will ignore this advice.
Why would they pay attention to "good examples and good explanations" if they disregard the simplest and most basic advice?
> It’s also sort of elitist sounding and that puts people off and further reduces the odds that they will listen.
Modern cryptography is intrinsically elite. It requires math and computer knowledge far beyond the ken of mere mortals, eh?
> Everyone knows that someone “rolls their own” crypto or none of it would exist. How does one get into this mysterious club? As near as I can tell you… roll your own crypto… and manage not to fuck it up. So the way you get to become someone who gives this sage advice is by disobeying it.
That sounds like, "Medical students dissect corpses to learn anatomy, so non-doctors should be allowed to perform their own surgery."
If you ask a crypto developer how to become one, they tell you to go away. "Don't roll your own crypto." Not "here's where you go to learn how to do crypto correctly, and here's a test you can take to determine if you're ready to do it." There's no generally accepted path to learn or to test your knowledge. There's just this informal guild of people we think know what they're doing.
So no, it's nothing like medicine except in the most superficial sense of them both being hard things.
"You can't roll your own crypto without becoming a crypto developer first" is just as valid as "You can't do your own surgery without becoming a surgeon first".
Those crypto developers didn't become crypto developers the first time they fucked up rolling their own crypto; it took lots of failures and probably quite a bit of formal study. Exactly like surgeons do lots of formal studying (and do their first fuck-ups on people who are already dead).
So yes, it's pretty much exactly like medicine, down to the most fundamental sense of them both being hard things that one needs to learn by formal studying and lots of preferably harmless fuck-ups.
The solution is to provide better learning materials.
BTW some people often say "just use libraries." The problem is that even the best designed cryptographic libraries are easy to misuse if you don't at least understand the basics of what those building blocks are doing. Imagine using a networking library without knowing what a TCP connection is or how it behaves. You don't need to understand the deep internals of TCP but you need to at least know the semantics and what the protocol does.
I 100% agree with this statement, in isolation.
But in context, I have to wonder if something in the post sounded like I was telling people not to roll their own? Because that wasn't the take-away.
Either way, https://gotchas.salusa.dev/GettingStarted.html
> So the way you get to become someone who gives this sage advice is by disobeying it.
Lawyers have a similar thing, from what I've been told.
"Don't go to law school", "Don't become a lawyer", etc. are what many lawyer parents have told their children (some of whom went on to become lawyers themselves).
It is like authoring compilers, most engineers have some knowledge of what's needed. But the few who are lucky enough to get paid to do it full time professionally are not very common. One thing I am thankful for with the hype about cryptocurrencies is that people with understanding of cryptography at the algorithmic are now much more common since the markets are aligned to reward technologies like symbolic execution and probably correct algorithms.
> 2) Strong knowledge of computer architecture
Is it so we can do performant things? Avoid side-channel attacks? Computer architecture isn't focal in my thinking when I'm working on cryptography. Very rarely it becomes important (I could leak information because of ... or boy, that is branch heavy and isn't going to be fast ...)
*algorithmic level
I should have proof read it
Someone did or none of the crypto I use would exist.
If you're going to roll your own crypto maybe make sure you're professionally trained.
After all, the whole infosec feild moves fast and what was 100% professinal at the time of being trained with the then known aspects does not mean that they would hold true today.
Heck I'm certified to recogise drugs and bombs, yet I'd not have any idea upon many modern drugs or explosives, so in some eye's I qualify as a professional and in my eye's I'm far from it and garantee many who have no such acreditation would be far better than I.
But nobody does that. Nobody says "don't roll your own crypto until you learn these things and pass these tests." They just say don't, and the people saying don't are often the ones who are.
So it's ignored, and with no good guidance people write crappy crypto.
I posted a link to a Getting Started guide in my comment above.
Once you've exhausted those resources, your best bet is to join a cryptography team at a tech company to round off your education with some real-world experience.
For example, https://www.amazon.jobs/en/search?business_category[]=amazon...
Or teaching it by silently noting and exploiting the flaw, rather than put out a public blog post.
Once people know you are elite, all such things do is draw attention to yourself.
We live in terrible times, it's not a good idea to engage in cyber dick waving that only serves to draw attention to oneself.
Are you suggesting that writing explanatory blog posts about technical topics is dangerous because someone will eventually come after you for being elite?
Yes, based on my personal experience and that of others. But I wouldn't call myself elite... I just know a little bit ;-)
I am saying giving them any sort of heads up is not good praxis, since the police have so thoroughly abused the access they already have.
See: https://www.vice.com/en/article/k7bqew/us-marshal-securus-ph...
There are great books out there that will tell you everything you need to know to understand and write safe crypto code. It's not some kind of closely guarded secret kept by an exclusive elite, it just requires reading. Pirate the books if you want to stop information hoarding among the rich, it's trivially easy to do with libgen.
You can roll your own crypto if you're capable of doing so, and have someone as competent as you check your work.
In this case, this tweet has listed the flaws that the custom crypto implementation has: https://mobile.twitter.com/gsuberland/status/153811763597137...
Some of these flaws aren't that bad (== vs === shouldn't matter too much in this case, though it's a sign of bad PHP code when the types are supposed to be well known). Others are either bad code practice (allowing a variable to be uninitialized) or well-known cryptographic mistakes that you'll learn to catch after reading a book or two (timing attack, shared keys). I won't pretend I would've spotted all of those at a glance, but I can admit that my crypto course has been too long ago for me to write or review such code.
I've got a basic grasp of electrical cirtuits but that doesn't mean I should be allowed to design highly secure electronic security circuits. I will miss important problems and dangerous flaws because I lack in-depth knowledge and experience. It's not because there's not an easy 1-2-3 guide on how to design safe circuits or because a cabal of academic elites are keeping this knowledge to themselves and pretending to do so just shifts the blame for my lack of effort to others.
Feel free to do your own crypto. Tons of companies do. You'd better put in the work to make sure you're doing it right, though! If you're working on some kind of new cryptographic structure and an academic writes up a theoretical attack in a paper somewhere, you're doing it right, assuming that you extend your scheme to solve the problems discovered. If you make textbook mistakes in important code, you're clearly doing it wrong.
If you're interested in learning cryptography so you can try to roll your own, I recommend starting with books like these:
- Cryptography Made Simple by Nigel Smart
- Applied Cryptography by Bruce Schneier
- Cryptography Engineering: design principles and practical applications by Neil Ferguson, Bruce Schneier, and Tadayoshi Kohno
These books require some prerequisite mathematical knowledge (like all crypto does) which you can probably pick up on Khan Academy. They go in depth into how common cryptography works, why these schemes are secure and how they can be broken (in theory and in practice). Some of them are getting old, though, so you may need to find some newer material if you're doing stuff like modern elliptic curve or post-quantum cryptography.
I would like to suggest that the problem is that the skilled people that understand how to write crypto systems are providing libraries that are easy to misuse. Instead of providing a library that is likely to be used incorrectly without a lot of specialized knowledge, provide infrastructure that manages the crypto so the average developer doesn't need to become an expert on crypto systems.
HTTPS is a useful example. Instead of providing webapp authors a library of cypher/hash functions and warning that they shouldn't roll their own transport layer security and then acting shocked when those authors try to use that library and make a lot of mistakes, we instead separate the crypto step into a separate layer of infrastructure so the average webapp author can easily use crypto without having to learn a lot of specialized knowledge. Someone writing a Ruby on Rails app shouldn't have to write functions like pervade_encrypt($data)/pervade_decrypt($data) to move out of the plaintext world of HTTP and utilize encrypted transport. They only need to buy/LetsEncrypt a cert they can install in their webserver. They can even delegate that to their hosting provider.
"If it's possible for a human to hit the wrong button and [cause a catastrophic failure] by accident [or inexperience], then maybe the problem isn't with the human - it's with that button. [...] People make mistakes, and all of our systems need to be designed to be ready for that."
>> Tom Scott, https://www.youtube.com/watch?v=dabnx8VSdkE
I agree, but for the encryption basics, those libraries are available. Higher level languages like Python/Ruby/etc. all have libraries that do TLS transparently. Lower level languages have libraries like BoringSSL/GnuTLS/OpenSSL/(Windows|macOS) APIs available which are relatively straight forward; you need to do error handling yourself so there's a whole bunch of API calls, but that's because an application needs to deal with errors and thrown exceptions aren't always available/desirable.
In the example, the code authors wanted to encrypt a file and then sign it using their own algorithm. There are open source utilities for this, of course, but they chose to implement it their own way. They didn't build a bad implementation of AES, they didn't write a bad hashing algorithm, they didn't mess up RSA.
They could've done this perfectly safely by switching the order around, adding a second key, and picking a better file format, they were very close! They could've prevented all these problems by just using GCM instead of CBC+HMAC inside their own format.
Personally, I would've used GPG and skip the custom implementation all together. This is a software product that exposes an endpoint that will execute the command in a GET query, so why not use a bit of exec() to do all the weird crypto for you.
> HTTPS is a useful example. Instead of providing webapp authors a library of cypher/hash functions and warning that they shouldn't roll their own transport layer security and then acting shocked when those authors try to use that library and make a lot of mistakes, we instead separate the crypto step into a separate layer of infrastructure so the average webapp author can easily use crypto without having to learn a lot of specialized knowledge. Someone writing a Ruby on Rails app shouldn't have to write functions like pervade_encrypt($data)/pervade_decrypt($data) to move out of the plaintext world of HTTP and utilize encrypted transport. They only need to buy/LetsEncrypt a cert they can install in their webserver. They can even delegate that to their hosting provider.
For TLS you still need to configure a proxy. You need to make sure not to paste the private key in the cert field or every browser will receive your private key; you need to have _some_ crypto knowledge and this is the easiest process you can probably think of. You also need to check your auth/blacklisting/security code to accept the proxy and make sure you use the right headers for checking the remote user IP against blacklists etc. Enabling TLS is easy, but it's still not a transparent process, simply because it's not an easy task.