News for hackers. Stuff that matters.
Re:Rolling Your Own Crypto by slindsey on Tuesday December 20, 2016 @01:25PM (#13222468)
Forget about creating your own crypto. I have had endless troubles just using crypto. Obscure options that aren't explained. Examples that don't actually work.

C# had an option that I finally got to work but the documentation specifically said not to use it; but the other choices didn't work.

I had to encrypt something in PHP then decrypt it in ColdFusion. Despite being the same algorithm, key, etc, it didn't work. Strangely, the exact same data in the other direction (CF->PHP) worked just fine.

I'd just like the libraries I use to have a simple choice: Encrypt(data,key) and Decrypt(data,key) and be done.

Re:Rolling Your Own Crypto by wbond on Tuesday December 20, 2016 @02:27PM (#13223063)
I found the issue to be more insidious.

Don’t roll your own crypto. Ok, that makes sense.

Don’t implement existing crypto algorithms. Ok, arguments sound good.

This leaves the options of using existing libraries. Cool. So let’s go find an existing library to deal with validating an SSL certificate chain in Python.

PyCrypto (https://www.dlitz.net/software/pycrypto/api/current/) - hmm, so basically the OpenSSL API, probably a minefield unless you are really up on crypto.

M2Crypto (https://gitlab.com/m2crypto/m2crypto) - umm, so no real docs. The recommendation is to go read a book about network security with OpenSSL. So after reading a network security book, I should be good to wire together some OpenSSL, right?

cryptography (https://cryptography.io/en/latest/) - sweet, we have docs! Hmm, so for humans we have Fernet and the ability to look at X.509 certificates. But nothing about validating. Oh, but there is a stalled PR (https://github.com/pyca/cryptography/pull/2460) from 14 months ago, to verify a certificate signatures.

Which then leaves the typical programmer to – hack something together?

So it is (practically) 2017, and using one of the most popular programming languages, you can’t verify an SSL certificate in a sane way without becoming journeyman cryptographer.

I like crypto, but using cryptography to integrate with existing protocols/standards sucks. Can we really not have an end-user focused implementation of RFC 5280 with a few knobs to turn?

Perhaps people would stop "rolling their own" crypto if there were half-decent, maintained, documented solutions out there. Maybe some day!

Re:Rolling Your Own Crypto by guitarbill on Tuesday December 20, 2016 @05:24PM (#13224783)
> Perhaps people would stop "rolling their own" crypto if there were half-decent, maintained, documented solutions out there. Maybe some day!

For transport security, HTTPS or SSH. Why go lower level?

Cert based stuff sucks, and cert management sucks. All of these suck harder because of backwards compatibility. Slowly, people are coming round to the fact you need to just deprecate stuff and get on with our lives. But the most sucky thing is OpenSSL.

Sometimes, I think OpenSSL has actually done more damage than good. You accept a shitty library because everybody uses it so it must be secure, right? Wrong. And the API is so hostile, the docs are awful. Most things that use it or try to replace it are awful (M2Crypto, PyCrypto, PyOpenSSL, even urllib3 [0]), as if the awfulness of OpenSSL seeps into your thinking - I know it's happened to me once or twice, just interfacing with OpenSSL. Even cryptography suffers from being based on OpenSSL.

Every time I have to use OpenSSL on a new project, I can't wait to see it die.

[0] https://github.com/shazow/urllib3/blob/master/urllib3/util/s...

Re:Rolling Your Own Crypto by paulddraper on Tuesday December 20, 2016 @05:39PM (#13224930)
> For transport security, HTTPS or SSH. Why go lower level?

Because not everything on this green earth uses HTTPS and SSH.

Examples:

(1) I want to implement a SAML consumer, and per the spec, I need to verify signatures. Crypto.

(2) I want to use a client-side cookie so that users can remain authenticated in the current browser session. Crypto.

(3) I want to issue a URL with a signed assertion that the owner of the content has granted permission to access it. Crypto.

Asymmetric encryption is not the be-all end-all of cryptography.

Re:Rolling Your Own Crypto by wbond on Tuesday December 20, 2016 @05:40PM (#13224941)
I'm not going lower level – in fact, I'm not even dealing with a communication protocol. Certificates are also used for document and executable signing.
Re:Rolling Your Own Crypto by guitarbill on Wednesday December 21, 2016 @01:35AM (#13227229)
Yeah, fair enough - it was more of a general assertion that it's easy to forget that high-level solutions exist. It's NIH.

Does using certs still suck though? I get that it's a hard problem, but cert revocation and distribution, that's really hard even for OSes.

Re:Rolling Your Own Crypto by wolf550e on Tuesday December 20, 2016 @02:35PM (#13223170)
Look at this code from urllib3 (requests bundles this code): https://github.com/shazow/urllib3/blob/master/urllib3/contri...

If you install the dependencies, requests uses the package cryptography to use openssl to validate certificates, by running that code.

Note that openssl does not validate certificates the way Mozilla Firefox does, even if they use the exact same root CA bundle, because some of the validation logic is code in NSS instead of data (e.g. certificate transparency requirements). Ryan Sleevi wrote on tweeter that Red Hat are working on doing something to let applications using openssl use Firefox's full cert validation logic.

Re:Rolling Your Own Crypto by daenney on Tuesday December 20, 2016 @03:58PM (#13223894)
> Look at this code from urllib3 (requests bundles this code): https://github.com/shazow/urllib3/blob/master/urllib3/contri....

This only underscores/validates wbond's critique though. Apparently the advise on how to figure this stuff out isn't even through "RTFM", docs or an easy to use library, it's "go look at the dependency of this other library which uses that other dependency that you want to use on how it is done". And then copy-paste that and hopefully not get anything wrong along the way.

Re:Rolling Your Own Crypto by wbond on Tuesday December 20, 2016 @03:08PM (#13223473)
(Just to note, this wasn't me looking for help in how to accomplish that task.)

That said, does the proverbial "you" know all of the chain validation features that are NOT implemented by OpenSSL when using code such as in urllib3? What if you actually care more about revocation than utmost in connection performance? How does one trust a custom CA root? What if you want to verify a cert chain for something other than a TLS connection?

My main point is: here we are with people needing crypto, and (it seems) no one has taken it upon themselves to write good crypto libraries for (some of) the types of tasks that are fairly common. The obvious exception being NaCl. However, that has issues with pragmatic things like distribution due to CPU optimizations, hence libsodium.

Re:Rolling Your Own Crypto by problems on Tuesday December 20, 2016 @04:10PM (#13224028)
Well, this is a very particular case and it's only so bad because you're dealing with SSL and X509. X509 is a clusterfuck of its own. OpenSSL or OpenSSL-esque (like LibreSSL or BoringSSL), but in OpenSSL this essentially just boils down to X509_verify_cert, you really don't need to think much about the crypto.

You might need to care a whole lot about X509 when dealing with loading your certificates and the complete chain though. But overall if you have a nice python wrapper that shouldn't be too bad. Not pleasant, but not too bad.

We do have several quite pleasant cryptography libraries like libsodium, SJCL, etc, but none of these deal with x509.

Re:Rolling Your Own Crypto by wbond on Tuesday December 20, 2016 @04:27PM (#13224195)
Or PKCS#12, or PKCS#8, or ECDSA (OpenSSL has determinism now, but different than RFC 6979), or ASN.1. Basically anything where you are using crypto as part of another protocol, not simply for encrypt/decrypt, sign/verify.

So using crypto code will be good once we rid the world of contemporary code and move into the future where all protocols are implemented on top of poly1305, ed25519 and chacha20. Considering how long it took to get rid of SSLv2 and v3, I just think perhaps some effort should go into making good, usable solutions for crypto that needs to be used now.

Re:Rolling Your Own Crypto by TwoBit on Tuesday December 20, 2016 @10:54PM (#13226670)
"but none of these deal with x509"

Thus you have proven his point.

Re:Rolling Your Own Crypto by problems on Wednesday December 21, 2016 @05:12PM (#13233113)
His point was that crypto wasn't pleasant. In reality it's that x509 isn't pleasant.
Re:Rolling Your Own Crypto by pvg on Tuesday December 20, 2016 @03:14PM (#13223510)
Serious question: what are the common, practical situations you've run into or can think of where you need to be validating certificate chains yourself in your application code?
Re:Rolling Your Own Crypto by wbond on Tuesday December 20, 2016 @03:15PM (#13223520)
Document signing is what pushed me down that path. It uses the same ecosystem and technologies as TLS, but cares more about revocation.
Re:Rolling Your Own Crypto by pvg on Tuesday December 20, 2016 @03:22PM (#13223572)
Ah I see. Seems a bit off the beaten path already, though. Were they some sort of existing documents, generated by something not easily available server side?
Re:Rolling Your Own Crypto by wolf550e on Tuesday December 20, 2016 @03:58PM (#13223890)
Did you require online (not cached) revocation check? That would require buying more HSMs.
Re:Rolling Your Own Crypto by wbond on Tuesday December 20, 2016 @04:36PM (#13224278)
No, I'm just implementing code that signs and verifies PDF digital signatures for compliance with EU regulations. I'm not dealing with HSMs, or even the PKIX infrastructure other than verifying a certificate is valid according to Adobe/ETSI and generating/checking signatures. The certificate issuers need to provide the CRLs and OCSP responders/responses.
Re:Rolling Your Own Crypto by wolf550e on Tuesday December 20, 2016 @08:51PM (#13226184)
Why is this downvoted? Could the downvoter please comment?
Re:Rolling Your Own Crypto by viraptor on Wednesday December 21, 2016 @01:50AM (#13227293)
Online revocation check doesn't require buying HSMs. HSMs also usually operate on a much lower level / aren't really connected to the internet.
Re:Rolling Your Own Crypto by wolf550e on Wednesday December 21, 2016 @06:11AM (#13228262)
If you can't use a cached OCSP response and instead need a fresh one (or the cache is valid for a short period only), that means the CA must sign a new OCSP response much more often.

The key the CA uses to sign OCSP must be held safely because it is important, even if that key can't sign new certificates. I think it belongs in an HSM.

I've read Let's Encrypt spends ~98% of the time of its intermediate signing keys on OCSP, not on new certs. If the OCSP was good only for an hour instead of a week, they would need to perform many more signatures per unit of time which would require more hardware.

Re:Rolling Your Own Crypto by viraptor on Wednesday December 21, 2016 @06:23AM (#13228307)
But that's an implementation detail. Sure, some HSMs will make signing faster, some won't. You don't need to use HSMs which will have a considerable markup too. You can use more servers if you prefer.

And anyway, that's the server case. OP just wanted to check the revocation as a client as far as I can tell, which definitely doesn't require any extra hardware.

Re:Rolling Your Own Crypto by wbond on Wednesday December 21, 2016 @08:26AM (#13228866)
In some cases revocation info will be live, in others it will be stored inside of the document.

My use case involves embedding it, but also being able to verify it (Adobe distributes trusted CA certs through a signed PDF). Never would I need to run my own PKIX infrastructure.

Re:Rolling Your Own Crypto by paulddraper on Tuesday December 20, 2016 @05:41PM (#13224944)
I want to implement SAML (as a consumer).

(To be fair, it can be done without certificate chains, but it could also be done with chains.)

Re:Rolling Your Own Crypto by pvg on Tuesday December 20, 2016 @09:44PM (#13226423)
Yep, I saw your more general list further upthread as well. I'd argue that much of the time these things are bad and essentially a kind of unnecessary, self-inflicted cryptography. In most cases the same things can be accomplished with a secure authenticated channel, someone hanging on to the relevant state and a cryptographically secure random id. A prime example is all the 'state-carrying authenticated/encrypted session cookie' infrastructure typically built into ruby and python web frameworks.
Re:Rolling Your Own Crypto by paulddraper on Tuesday December 20, 2016 @02:30PM (#13223096)
And you used Python as the example, probably has the easiest cryptography libraries to use.

C/C++, Ruby, JS, etc. are much, much worse in usability.

Re:Rolling Your Own Crypto by PopsiclePete on Tuesday December 20, 2016 @04:09PM (#13223997)
The Python eco-system is a ghetto. I don't understand why, it really is one of the most popular languages.
Re:Rolling Your Own Crypto by niftich on Tuesday December 20, 2016 @01:41PM (#13222614)
Crypto APIs being hard to correctly use was the principal motivation behind Daniel Bernstein's nacl [1]. As others have said, nacl and its reimplementation libsodium try to adhere to this philosophy.

[1] https://cr.yp.to/talks/2012.08.08/slides.pdf

Re:Rolling Your Own Crypto by wolf550e on Tuesday December 20, 2016 @02:28PM (#13223070)
Re:Rolling Your Own Crypto by lisper on Tuesday December 20, 2016 @06:08PM (#13225188)
And Javascript:

https://tweetnacl.js.org/

And Python:

https://github.com/pyca/pynacl

This is one of my projects using these libraries, a PGP replacement based entirely on the NaCl API:

https://github.com/Spark-Innovations/SC4

Re:Rolling Your Own Crypto by Buge on Wednesday December 21, 2016 @03:36AM (#13227659)
I used that in a project and found that the Java and the Javascript implementations I was using did things slightly differently, so I had to modify the Java version to behave like the Javascript version.

Simpler than Openssl or whatever, but still not ideal.

Re:Rolling Your Own Crypto by lordnacho on Tuesday December 20, 2016 @01:34PM (#13222560)
I've run into the same issue.

One of the main frustrations is you don't know if the output is correct until you manage to reproduce some known key/document exactly.

When you're debugging anything else, you can sort of see what's wrong as you come closer to a correct solution. A crypto scheme is only correct (you've put the right things in the right places) when it's exactly right. Until then, you have a jumble of characters.

It took me ages to match ECDSA on java with Python. In the end, it was because of some fine print where I needed to hash one version but not the other before signing.

Re:Rolling Your Own Crypto by lvh on Tuesday December 20, 2016 @02:23PM (#13223022)
It's even worse than that, unfortunately :-( You can absolutely get the correct answer for a bunch of test cases and _still_ get insecure crypto; for example: small subgroup attacks on FFDH with p-1 smooth, small subgroup/off-curve attacks in ECDH, static/predictable k for ECDSA, MtE/M&e instead of EtM... Lots of passing unit tests, no good crypto.
Re:Rolling Your Own Crypto by tptacek on Tuesday December 20, 2016 @02:17PM (#13222955)
What's especially unfortunate about this is that experts would caution you against using ECDSA at all.
Re:Rolling Your Own Crypto by lordnacho on Tuesday December 20, 2016 @02:25PM (#13223036)
Tell me more?

I was doing some bitcoin calculations and needed it.

Re:Rolling Your Own Crypto by tptacek on Tuesday December 20, 2016 @02:35PM (#13223160)
If you have to use ECDSA you have to use it. Bitcoin is an example of where you have to use it.

Otherwise, though, it's an inferior and outmoded signature system. It's got the worst random nonce dependency of any modern crypto primitive: if it's even biased, just a little bit, you can recover keys from groups of signatures (a full repeat instantaneously destroys security with a single pair of signatures). It's weak against simultaneous attacks on multiple signatures, so it minimizes the effort attackers need to spend. Meanwhile, it's inefficient compared to the alternatives, so it tends to maximize the effort you have to spend. It's also hard to implement without side channels.

Modern cryptography engineers would recommend something like EdDSA instead.

Re:Rolling Your Own Crypto by wolf550e on Tuesday December 20, 2016 @02:45PM (#13223275)
Do you believe CFRG took so long to standardize EdDSA because of natural bikeshedding, or because the NSA worked to slow them down?
Re:Rolling Your Own Crypto by tptacek on Tuesday December 20, 2016 @02:51PM (#13223326)
It's obviously bikeshedding.

People have been misconstruing the bikeshedding and cliquishness of the IETF as enemy action for decades.

John Gilmore has a story about how, during IPSEC standardization, someone was pushing for a CBC chained-IV construction hard, and that he was both confident it could only be enemy action and had sources suggesting it was. This came out right after the Snowden leaks, so everyone took it seriously.

But if you look at it context, I'm pretty sure the people he was talking about were Perry Metzger and Bill Simpson† (both clearly not NSA plants). They were arguing with Phil Rogaway --- calling one of the most famous and prolific cryptographers a "so-called" cryptographer when he cautioned them not to do dumb things like chaining IVs.

There's a message thread you can look up on the Internet where this happened. Rogaway even got a petition put together from a bunch of other cryptographers, including Rivest. No luck! The IPSEC standards committee ignored them.

A decade or so later (earlier, really, but nobody took Bard's paper seriously) we discovered chained CBC IVs lead to the BEAST attack on TLS.

Enemy action? No. Crypto standards groups don't need enemy action. They are intrinsically evil, and need to be avoided.

† I think this is the case, but I haven't confirmed it with Gilmore; maybe he's talking about a different controversy during IPSEC standardization. But these are the ones where the details fit from what I can tell.

Re:Rolling Your Own Crypto by YAYERKA on Tuesday December 20, 2016 @05:49PM (#13225031)
lordnacho, as tptacek wrote below (which also applies to DSA);

>a full repeat instantaneously destroys security with a single pair of signatures

Roughly--assuming ECDSA parameters (H,K,E,q,G)--where H is a hash function, E the Elliptic Curve over finite field K w/ point G of prime order q. Suppose two different messages m and m' have been signed with private key x using the same (non-ephemeral) random nonce value of k.

According to ECDSA Signing these messages m, m' become signatures (r,s), and (r',s') where;

  r = r' = kG,

  s = (H(m) + x*r)/k   mod q,

  s' = (H(m') + x*r)/k  mod q.
Observe that,

  (H(m) + x*r)/s = k = (H(m') + x*r)/s'  mod q.
Or,

  x*r(s' - s) = s*H(m') - s'*H(m)  mod q.
Which allows us to recover the private key x.

Since,

  x = s*H(m') - s'*H(m) / r*(s' - s)  mod q.
Re:Rolling Your Own Crypto by tptacek on Tuesday December 20, 2016 @05:51PM (#13225055)
The problem is really much worse than this. You don't merely need a non-repeating nonce (the way you can get away with a GCM nonce that increments by 1 every session): you need an unbiased nonce.
Re:Rolling Your Own Crypto by YAYERKA on Tuesday December 20, 2016 @06:34PM (#13225388)
I believe an natural segue here is to remind people about cryptopals (especially set 8). Ie., I don't have the chops and wouldn't attempt to writeup EC/DSA nonce bias and partial key exposure attacks better than you all--not to mention the challenges regarding GCM. Cheers.
Re:Rolling Your Own Crypto by pvg on Tuesday December 20, 2016 @01:51PM (#13222715)
I had to encrypt something in PHP then decrypt it in ColdFusion.

That still ends up being 'rolling your own crypto' and mostly the kind of crypto the article is talking about. The author is describing putting together cryptographic constructs from the sort of low-level pieces provided by your typical runtime crypto library. This is probably the far bigger problem with the admonition - it's vague enough that someone might think that since they're not actually implementing AES themselves, they're not rolling their own crypto. Stackoverflow is full of questions just like your PHP/Coldfusion problem.

Re:Rolling Your Own Crypto by mindcrime on Tuesday December 20, 2016 @04:04PM (#13223954)
Tell me about it. I spent WAY too much time just yesterday, trying to use the Bouncy Castle OpenPGP stuff to encrypt a message such that I could turn around and decrypt it with GnuPG. In the end I got it to work, but what a rigmarole. Crypto API's are, as you said, full of many obscure options and bizarre permutations of how components can be put together, that it's ridiculous. And they also seem to change rapidly, meaning documentation and even Stack Overflow answers are often out-of-date and useless.

The thing that saved me finally turned out to be that Bouncy Castle actually do package some example programs in with the source. So once I cloned the git repo and dug into those, I was finally able to find an example of doing exactly what I needed. But trying to piece it together from the javadocs and the other online documentation? Hell no... I'd have been working on that until the heat death of the universe. :-(

Re:Rolling Your Own Crypto by lvh on Tuesday December 20, 2016 @04:26PM (#13224186)
Out of interest; why do you care about GnuPG decryption specifically? (I write cryptographic software. I care about usability. I might want to provide people with GnuPG-compatible crypto, but that's not necessarily where I'd start.)
Re:Rolling Your Own Crypto by mindcrime on Tuesday December 20, 2016 @05:03PM (#13224554)
I'm working on a SaaS offering where I might need to be able to email sensitive information to customers. Or even just make it available for download. In either case, I'd like the data to be encrypted. So I'm planning to ask users to upload a PGP/GPG compatible public key so that we can encrypt this stuff for them. I'm focused on GnuPG specifically just because it's freely available, well known, available on all the important platforms, etc.
Re:Rolling Your Own Crypto by cpach on Wednesday December 21, 2016 @04:40AM (#13227895)
Just a word of caution: If your customers are on Windows, using Gpg4win might not be a very smooth experience. I just helped someone to install that package and I found the UX to be really suboptimal. For one, it’s GTK-based, which makes it stick out like a sore thumb in a Windows environment.
Re:Rolling Your Own Crypto by mindcrime on Wednesday December 21, 2016 @11:30AM (#13230352)
Yep, that's part of the risk of this. I thought about that, but decided to give it a go on the basis of thinking that the people using this service will be pretty tech savvy, and will be OK with installing and using some variant of GPG or the commercial PGP. If that proves not to be the case we'll come up with a different approach.
Re:Rolling Your Own Crypto by j_s on Tuesday December 20, 2016 @05:37PM (#13224903)
When I tried this (.NET PGP) I could only get it working one direction based on this abandoned open source library:

https://crypter.codeplex.com/

Re:Rolling Your Own Crypto by andrewflnr on Tuesday December 20, 2016 @10:12PM (#13226546)
With SpongyCastle on Android, I didn't even get the example programs to work. Maybe in trying to modify it from using disk files (inconvenient when working with data from an EditText) to InputStreams, I messed something up, but man was that frustrating.
Re:Rolling Your Own Crypto by dom0 on Tuesday December 20, 2016 @01:30PM (#13222521)
If it's something sparkling new you probably want to use NaCl or for more involved use cases a Noise implementation.
Re:Rolling Your Own Crypto by tptacek on Tuesday December 20, 2016 @01:52PM (#13222732)
It's the opposite, I think: Noise is good for less-involved cases, the kinds of problems you would ordinarily solve by just using TLS. Nacl is better for when you need something customized to an application.

Incidentally: Noise is great, but it's also fine to use TLS, if you're just a little careful.

See also:

https://gist.github.com/tqbf/be58d2d39690c3b366ad

Re:Rolling Your Own Crypto by an_account_name on Wednesday December 21, 2016 @03:56AM (#13227744)
A bit of Googling reveals this to be a reply to this blog entry by Colin Percival, for those interested:

http://www.daemonology.net/blog/2009-06-11-cryptographic-rig...

Re:Rolling Your Own Crypto by jjnoakes on Tuesday December 20, 2016 @03:15PM (#13223519)
The "Avoid /dev/random" recommendation, can you elaborate on that?
Re:Rolling Your Own Crypto by tptacek on Tuesday December 20, 2016 @03:43PM (#13223729)
Re:Rolling Your Own Crypto by jjnoakes on Tuesday December 20, 2016 @03:55PM (#13223845)
You should post these reasons in your gist. As I thought, there are a few reasons one might want to use /dev/random.

Blanket "don't use X" statements are much more useful with context and information about why not to use X (and when using X may be required, useful, or a better choice).

Re:Rolling Your Own Crypto by Dylan16807 on Tuesday December 20, 2016 @05:06PM (#13224594)
There's no reason to pull bytes out of /dev/random. In the rare circumstance that you're worried about it being early in the first boot and getrandom doesn't exist, you might throw away a single byte from /dev/random to make sure it's ready. But then you're done, and use urandom. And your program almost certainly doesn't need to worry about that circumstance.
Re:Rolling Your Own Crypto by jjnoakes on Tuesday December 20, 2016 @11:24PM (#13226780)
Unless no programs ever need to worry about that case (which is untrue), why not mention in a security gist purporting to be a list of crypto implementation suggestions?

Why not be complete and list the caveat, instead of incomplete and possibly lead that one in a thousand down the wrong path?

Re:Rolling Your Own Crypto by Dylan16807 on Wednesday December 21, 2016 @12:17AM (#13226960)
Far more than one in a thousand will use it as an excuse to do the wrong thing.

And lots of articles about best practice leave out very rare edge cases. No advice is always always right.

Re:Rolling Your Own Crypto by jjnoakes on Wednesday December 21, 2016 @08:17AM (#13228823)
> lots of articles about best practice leave out very rare edge cases

I don't think that's an argument in support of leaving out edge cases, and even if you disagree in general, I think security articles should be more diligent than random best-practices articles.

> Far more than one in a thousand will use it as an excuse to do the wrong thing.

If an article says "always do X" and someone does X and the implementation is subtly wrong or insecure, that's an argument to improve the article (which is what I'm suggesting).

But if an article says "almost always do X, and be aware of this edge case" and someone gets it wrong by not following instructions, then I don't think the article is at fault.

I would personally want my security advice to cover any edge case I could think of, even if only in the footnotes.

Re:Rolling Your Own Crypto by tptacek on Tuesday December 20, 2016 @03:59PM (#13223896)
No, there aren't. Don't use /dev/random.
Re:Rolling Your Own Crypto by jjnoakes on Tuesday December 20, 2016 @04:52PM (#13224441)
The reasons I know about for using /dev/random are quoted in the article you yourself just posted here...

https://sockpuppet.org/blog/2014/02/25/safely-generate-rando...

Re:Rolling Your Own Crypto by tptacek on Tuesday December 20, 2016 @05:05PM (#13224575)
Since I wrote that article, I'm pretty confident that it doesn't recommend ever using /dev/random.
Re:Rolling Your Own Crypto by jjnoakes on Tuesday December 20, 2016 @11:12PM (#13226732)
I said the article mentioned reasons one might want to use /dev/random (or be careful about blindly using /dev/urandom), not that the article recommends using /dev/random. But since you wrote the article you should realize this.

Just because the article recommends seeding over using /dev/random early at boot time doesn't mean the original gist shouldn't mention these issues so that readers are aware of them.

Just saying "use /dev/urandom all the time" without mentioning the caveats we're discussing here means someone might read your article and in a (misguided) appeal to authority implement something solely on your recommendation without doing their research properly first.

I would have thought someone writing security articles would want to avoid misleading someone into implementing something that's accidentally insecure. I hope I'm not wrong.

Re:Rolling Your Own Crypto by tptacek on Wednesday December 21, 2016 @07:58AM (#13228715)
Re:Rolling Your Own Crypto by jjnoakes on Wednesday December 21, 2016 @08:28AM (#13228879)
> Here's another article you can argue with: > http://www.2uo.de/myths-about-urandom/

Which backs up my point that using /dev/urandom blindly without knowing about some of the edge cases isn't a good idea, and lists those edge cases and what to do about them (which is what I suggested you do too).

> And another: > http://security.stackexchange.com/questions/3936/is-a-rand-f....

Which also lists the edge cases I'm talking about.

Hey look if you just want to say "I'm aware of the edge cases and don't want to put them in my gist for others to see" that's fine with me, but dodging the issue by claiming there are no edge cases (and then listing 3 articles which all mention the edge cases) isn't the right reply I think.

Don't be surprised if someone suggests that a gist listing security best practices list some edge cases that go along with the blind advice too. Feel free to disagree, but at least disagree honestly.

Re:Rolling Your Own Crypto by tptacek on Wednesday December 21, 2016 @10:47AM (#13229967)
I honestly disagree.
Re:Rolling Your Own Crypto by jjnoakes on Wednesday December 21, 2016 @12:52PM (#13231064)
Appreciated.
Re:Rolling Your Own Crypto by ori_b on Tuesday December 20, 2016 @01:26PM (#13222486)
Have you looked at Libnacl or Libsodium?
Re:Rolling Your Own Crypto by pps43 on Tuesday December 20, 2016 @02:27PM (#13223060)
> Encrypt(data,key) and Decrypt(data,key) and be done.

That's the easy part. You can find a library that does exactly that, and only that. Will probably be just one file, not even a library [1].

But then you'll also need padding, MAC, signatures, key distribution, web of trust, etc.

[1] Example: https://github.com/dimview/speck_cipher

Re:Rolling Your Own Crypto by lvh on Tuesday December 20, 2016 @03:46PM (#13223752)
The linked repo is not a solution, single-file or otherwise. Speck is not only a weird and unusual block cipher to pick, it is more importantly only a block cipher. It does not let you encrypt more than a block size at a time, and it does not give you authentication! Both of those things are anything but trivial.

Furthermore, Speck has a variable block size between 32 and 128 bits. If you pick wrong, safe-looking things like CTR+HMAC-256 become unsafe (it's not hard to overflow a 32-bit counter).

Re:Rolling Your Own Crypto by pps43 on Tuesday December 20, 2016 @03:59PM (#13223905)
Well, it does Encrypt() and Decrypt(), which is what was asked. And it's not particularly difficult to pick 128 bit block size (after all, bigger is better).

The problem is, it's not nearly enough to just do Encrypt() and Decrypt(). Only when you see that, the benefits of a real crypto library NaCL become apparent.

Re:Rolling Your Own Crypto by lvh on Tuesday December 20, 2016 @04:14PM (#13224070)
It has things called "encrypt" and "decrypt", but it does not do anything a programmer could reasonably consider "encrypt" and "decrypt". If you don't authenticate your ciphertext, there's a decent chance your ciphertext won't remain secret. It doesn't give you an option for randomized encryption. Compare with Fernet: you get the same API, but you get to encrypt any message, and it's securely authenticated such that it stays secret. (secretbox is fine too; but it makes you pick a nonce).

Additionally, "bigger is better" is not a reasonable way to pick primitives. Defaults matter. Perf matters. From experience and stats, people pick according those two vectors a lot more often than they pick along the "bigger is better" axis. When's the last time you saw an RSA-16384 signature? AES-256 might have twice as big a number as AES-128, but how much faith do you have in that extended key expansion? You use AES-128 a lot more often than you use AES-256, and you definitely use RSA-2048 a lot more often than RSA-16384.

I don't think you can responsibly insist that this was an answer to the question. It is not a secure way to encrypt messages.

Re:Rolling Your Own Crypto by PeterisP on Tuesday December 20, 2016 @09:49PM (#13226441)
Well, that's kind of the point - the default Encrypt(data,key) should also implement padding, combine blocks for arbitrary length messages, and include MAC; so that it's reasonably secure out of the box with the default settings. Key distribution is a different issue, but doing the abovementioned things would be sufficient to ensure that you can just run Encrypt/Decrypt(data, key) and expect most of the common tampering attacks to be impossible.
Re:Rolling Your Own Crypto by tptacek on Tuesday December 20, 2016 @04:36PM (#13224277)
Why would you suggest someone investigating crypto for the first time use the NSA's lightweight cipher? That's a really weird recommendation.
Re:Rolling Your Own Crypto by pps43 on Tuesday December 20, 2016 @04:45PM (#13224375)
The point I was trying to make is that complexity is not in encrypt() and decrypt(). Those things can be very simple, yet cryptographically strong.

Complexity begins when you try doing something more involved than just symmetric block encryption.

Re:Rolling Your Own Crypto by tptacek on Tuesday December 20, 2016 @05:04PM (#13224565)
If by "symmetric block encryption" you mean "use the block permutation of the cipher directly", then nobody ever does that; the people who make the mistake of using the cipher's "Encrypt" and "Decrypt" are the ones who end up discovering that the default mode of a cipher is ECB.

I think I sort of see your point, but SPECK is a weird recommendation.

Re:Rolling Your Own Crypto by 77pt77 on Tuesday December 20, 2016 @05:03PM (#13224556)
Forget that.

How is the IV stored for example.

Re:Rolling Your Own Crypto by Rebelgecko on Tuesday December 20, 2016 @07:14PM (#13225628)
Block ciphers in ECB mode don't use an IV. If you were going to use this random crypto code on github (bad idea for various reasons), you'd want to wrap it in GCM or something similar (then you get to deal with IVs, tags, etc). I suppose part of the issue that people don't want to deal with (or don't see the need for) the added complexity of IVs and authentication.
Re:Rolling Your Own Crypto by tptacek on Tuesday December 20, 2016 @11:05PM (#13226707)
You can't just "wrap" SPECK in GCM-mode! In many of its configurations, it has a block too short to safely run GCM in.

Don't roll your own crypto.

Re:Rolling Your Own Crypto by Rebelgecko on Wednesday December 28, 2016 @10:18PM (#13275431)
By many configurations, do you mean with a block size ≠ 128 bits? I should've specified that when I posted (notwithstanding issues with rolling your own crypto)
Re:Rolling Your Own Crypto by WillSlim95 on Wednesday December 21, 2016 @12:11AM (#13226944)
Umm this is a bit off-topic , but I don't know how else to reach out. But I have been not able to access Star Fighters due to a certificate failure, could you please check it out or point me towards whom to contact,
Re:Rolling Your Own Crypto by tom_b on Wednesday December 21, 2016 @01:40PM (#13231500)
The founders wound it down. Thomas is threatening to actually do a write-up about the experience sometime (poke, poke).
Re:Rolling Your Own Crypto by tptacek on Wednesday December 21, 2016 @02:00PM (#13231659)
I really am doing it (I also really am publishing a bunch more challenges). I just had dinner with Patrick last night and talked about it a bit. I've got a lot on my plate at the moment, though.
Re:Rolling Your Own Crypto by tom_b on Wednesday December 21, 2016 @02:36PM (#13231947)
Cool - thanks to all three of you for Starfighter. I'm sad it didn't work out as envisioned. Looking forward to the eventual write-up when it fits into your time.
Re:Rolling Your Own Crypto by tptacek on Wednesday December 21, 2016 @03:32PM (#13232376)
We will for sure be taking another whack at this down the road, and in the meantime I'm pretty psyched to apply the same ideas again to a hiring practice I actually own (we'll surely be doing the same thing at Latacora); at least I'll get another finger-wagging blog post out of it!
Re:Rolling Your Own Crypto by pps43 on Tuesday December 20, 2016 @07:37PM (#13225772)
API is Encrypt(data,key) and Decrypt(data,key). There's no IV. It's just a block cipher.

Once you start adding things like CTR mode, MAC, etc. the API is no longer as simple.

Re:Rolling Your Own Crypto by j_s on Tuesday December 20, 2016 @05:32PM (#13224867)
I just found out about this 3 year old .NET crypto best practices book / library this past week:

http://securitydriven.net/inferno/

Re:Rolling Your Own Crypto by balls187 on Tuesday December 20, 2016 @04:45PM (#13224369)
> I had to encrypt something in PHP then decrypt it in ColdFusion. Despite being the same algorithm, key, etc, it didn't work. Strangely, the exact same data in the other direction (CF->PHP) worked just fine.

Padding issues most likely.

PHP might auto detect padding, while CF might not.