- For a block cipher you should use AES-128. If you don't understand your protocol well enough to know whether there are birthday attacks on your keys, you have bigger issues. (Shame on Schneier for still trying to revisit the AES design competition by yammering on about Twofish.)
- For an encryption mode, you should always use CTR, and always use a nonce of zero, and never reuse keys.
- For a hash function, you should use sha-256 until the winner of the sha-3 design competition is announced, and then you should use sha-3.
- You should always do encryption as a layer outside of authentication.
- For entropy, you should always do whatever the Python os.urandom() call does on the local platform.
- For a data format, you should use JSON. (Not XML!)
- For an RSA exponent, you should always use 2. Technically that's Rabin-Williams, and requires slightly different implementation, but that actually works in its favor. Rabin-Williams has a reduction to factoring, RSA does not.
- You should never use the same key for both encryption and authentication. If you need both encryption and authentication, you should use two keys. One for encryption, and one for authentication.
- If you're going to be using RSA, you should learn about encoding for it! This is by far the most historically error-prone part of crypto protocols, and Practical Cryptography bizarrely doesn't even mention it as an issue.
- You should not parameterize your protocols! That just creates compatibility problems. If necessary you can parameterize it by having two values, one good for the next twenty years, and one good until the end of time, but key sizes have gotten big enough that skipping that first one should be the default.
Maybe someday Schneier will write a book which I can recommend to people who are getting started in cryptography, but I'm not holding my breath.
Are you a good programmer? Try this coding challenge.
May 19 2011, 20:39:23 UTC 9 years ago
It also seems to assume that it's a straight line or at least a one-dimensional space - a curve is certainly a line. If it's not a straight line, then there isn't sufficient information to solve the problem in two dimensions.
Overall, this problem sounds an awful lot like a variant of the 8 Queens puzzle.
May 19 2011, 20:49:04 UTC 9 years ago
9 years ago
9 years ago
May 19 2011, 20:43:12 UTC 9 years ago
I don't think you mean modulus here.
May 19 2011, 20:48:27 UTC 9 years ago
May 19 2011, 21:08:08 UTC 9 years ago
Strongly disagree.
Authenticate-then-encrypt (AtE) is subject to attacks that encrypt-then-authenticate (EtA) is not. How practical those attacks are depend on exactly what you're using for your encryption, but they can occur surprisingly often, and you don't want to have to worry about them.
The most prevalent class of such attack (in my opinion) is when you've got a (possibly public-key) encryption system that isn't reaction resistant. The encryption might be somewhat homomorphic, in that the adversary can modify the ciphertext in such a way as to make it come out to the same plaintext some of the time, and a different plaintext (or \bottom) some of the time. Then the inner authentication will fail, and the adversary will know which happened. Lattice-based crypto often has this problem, as does McElice (see our 1999 paper on this). Other encryption systems may have this or similar problems, as protecting against this isn't generally something that's a design goal of semantically secure encryption. (If your encryption is IND-CCA2, you're safe, but then you've basically got the authentication built in, anyway.)
Authenticating the ciphertext avoids the whole issue.
Of course, it may have its own issues, if you're using signatures (and not MACs) for authentication, and you want, say, to hide the information of who's signing the message. If you have complex requirements like that, though, you might think twice about designing the crypto protocol yourself.
May 19 2011, 21:25:39 UTC 9 years ago
That more complicated stuff you mention really shouldn't be done by people who don't already know these issues well, and my advice is for people who don't really know what they're doing by are trying to do something simple (which still might not be a good idea, but they're better off with good advice than without).
May 19 2011, 21:29:04 UTC 9 years ago
For an encryption mode, you should always use CTR, and always use a nonce of zero, and never reuse keys.
I'm interested to hear more about why this is true. Certainly there are times when you want to reuse keys and use modes that provide more security than that :-).
You should always do encryption as a layer outside of authentication.
It sounds like you are suggesting the opposite of what you should do, which is encrypt first, and then authenticate the ciphertext. Authenticating the plaintext before encrypting is not safe.
For an RSA exponent, you should always use 2. Technically that's Rabin-Williams, and requires slightly different implementation, but that actually works in its favor. Rabin-Williams has a reduction to factoring, RSA does not.
I think suggesting that practitioners dig into implementations of the number-theoretic algorithms (as would be necessary here) is likely to lead to exploitable bugs. Moreover, even a proper implementation of Rabin-Williams would not increase security in practice, unless the sky falls and we find algorithms for inverting the RSA trapdoor function that do something other than factoring. And what's worse is that in practice you'll be using a padding scheme like PKCS#1v1.5, which means the reduction no longer applies. Even if you used OAEP instead, the reduction would be in the random oracle model, further clouding the significance of a reduction to factoring vs RSA inversion.
This is all ignoring the fact that low-exponent (e=3) RSA has lead to vulnerabilities in the past...
You should never use the same key for both encryption and authentication. If you need both encryption and authentication, you should use two keys. One for encryption, and one for authentication.
This is good advice, unless you're using an authenticated encryption mode like GCM. It would be good to be more complete on when it applies.
May 19 2011, 23:36:46 UTC 9 years ago
I don't know what your issue is with encrypting outside of authenticating is. If nothing else, it leaks authentication information which one may want to keep secret, and this is one case where I'm agreeing with Practical Cryptography, just making the recommendation more straightforwardly. My simplest explanation for this is that doing encryption on the outside allows for clean layering of the software implementation, where the other way does not.
RSA exponents more than 2 are at least twice as slow, which should not be simply ignored for speculative reasons. Encoding issues should be dealt with by using a good encoding, which is a dangerous issue in any case, as I explained.
I might start recommending GCM in the future, after more chips support in and I've spent some time analyzing its implications. For the time being simply using a secure hash and CTR is the reasonable conservative approach.
May 20 2011, 01:32:22 UTC 9 years ago
http://www.daemonology.net/blog/2009-06-11-cryptographic-right-answers.html
Seems somewhat similar at times to what you wrote. Interesting how the recommendations then are still pretty much the same you made above, now.
What are the guarantees of Python os.urandom?
May 20 2011, 02:35:27 UTC 9 years ago
Re: What are the guarantees of Python os.urandom?
May 20 2011, 12:23:34 UTC 9 years ago
May 20 2011, 07:03:27 UTC 9 years ago
May 20 2011, 12:25:47 UTC 9 years ago
May 20 2011, 11:32:17 UTC 9 years ago
Authentication should be done after encryption because this is the way that can be proved to work for any encryption and authentication schemes.
May 20 2011, 12:30:18 UTC 9 years ago
I have no idea what 'proved to work' you're babbling about.
9 years ago
9 years ago
9 years ago
I almost entirely agree; some nits:
May 20 2011, 15:14:59 UTC 9 years ago
Ian brought up some of the issues with Authenticate-then-Encrypt; frankly, I'm a fan of the way we handle it in RFC 4880, with the user-verifiable authentication, then encryption, then message authentication.
So, it looks like the only remaining thing I have an issue with is your comments on parameterization; I strongly argue that one should design one's protocol in a parameterized fashion, but provide only one option per needed component. E.g., you need a hash function; fine; design your protocol such that it supports multiple hash functions, but only specify SHA-2. By building parameterization into the protocol, transitioning to SHA-3 becomes a much less painful process.
I say this in part because of the awful experience of transitioning to 160-bit hashes after assuming MD5 in a non-parameterized fashion. Parameterization does not automatically imply multiple choices.
Re: I almost entirely agree; some nits:
May 20 2011, 16:36:56 UTC 9 years ago
Having a generic handshake at the beginning of a protocol where dictionaries are exchanged to help with future upgrades is a very good idea, but I don't think that making specific hooks for particular upgrades beyond that makes life any easier in the future.
Re: I almost entirely agree; some nits:
9 years ago
'that's entropy and I hope that you're all down with it'
May 21 2011, 01:16:31 UTC 9 years ago
Disagreed. If you need entropy, you should use real random numbers. If that isn't waht os.urandom() does on your platform, you should rewrite your platform to make it do that.
If that incurs too much overhead you should talk to your isp, random.org, your local network admin, the person who designed your computer or whatever. But if you need random numbers there is a source for them.
( bramcohen -> jwz -> exoskeleton -> masuimi -> ruthanolis -> themusicgod1 -> caponex -> pope_guilty -> bramcohen )
Re: 'that's entropy and I hope that you're all down with it'
May 21 2011, 02:34:53 UTC 9 years ago