Live data from Hacker News

Some gripes about nacl

tedunangst.com

21–30 of 47 posts

Re: Some gripes about nacl

#21
As someone who didn't really know what they were doing, I used NaCl recently to write a program to tunnel packets over UDP.

I started by reading the NaCl source and all the introductory material available—the web site, the two NaCl papers ("Cryptography in NaCl", "The security impact of a new cryptography library"), and quickly reviewed a couple of other papers (e.g. to understand deterministic encryption and D-H key exchange). I think the biggest problem I had was to understand nonce generation and handling properly. The "Cryptography …" paper does contain some advice that I ultimately implemented. But I had to think very hard about what it said before I was confident that I was doing what it said. For example, it says:

«…the nonce can be chosen as a simple counter: 0 for Alice’s first packet, 1 for Bob’s first packet, 2 for Alice’s second packet, 3 for Bob’s second packet, 4 for Alice’s third packet, 5 for Bob’s third packet, etc. Choosing the nonce as a counter followed by (e.g.) 32 random bits helps protect some protocols against denial-of-service attacks. In many applications it is better to increase the counter to, e.g., the number of nanoseconds that have passed since a standard epoch in the local clock, so that the current value of the counter does not leak the traffic rate.»

I managed to figure it out, but I would certainly have welcomed a more detailed explanation, and would have been very happy to have help from the code to do the right thing.

In contrast, the cryptography functions were easy enough to figure out and use (with the C API). The only mistake I kept making was specifying the secret key first and the public key second in all my function calls. Once I got used to doing it the other way around, it was fine. Zero-padding the messages was slightly ugly, but I didn't develop any especially strong feelings about it. (Aside: I actually ended up using TweetNaCl, but of course all the documentation is the same.)

I'm very pleased with the resulting code, anyway.

P.S. I looked at libsodium, but greatly preferred the unadorned library.

Re: Some gripes about nacl

#23
post #17

Paging @tptacek for comment

I like nacl.

I like the author of this article and think he knows what he's talking about.

I like libsodium but do worry about the project getting away from them; cleaning up the API is one thing, adding new crypto primitives is another. Still: use libsodium.

The person whose opinion you really want on this article is 'pbsd.

Re: Some gripes about nacl

#24
post #22

Can anyone comment on the use of formal verification in NaCl? Is it used at all? Would it even be valuable? [0] doesn't mention anything about it. [0] http://nacl.cr.yp.to/valid.html

There's a section in the tweetNaCl paper that discusses some limited formal verification.

For some interesting commentary on the difficulty in formally verifying c code (with crypto examples) see: https://www.imperialviolet.org/2014/09/07/provers.html

and the followup

https://www.imperialviolet.org/2014/09/11/moveprovers.html

Re: Some gripes about nacl

#25
post #15

Isn't the fact that nacl is written by such highly reputable guy(in the crypto community) and that it sees relatively lots of review by experts important here ?

He's a highly reputable cryptographer, and a ... controversial ... software developer. I would trust my life to the algorithms. I wouldn't trust my appendix to the code.

The software is delivered over HTTP (not HTTPS) and not cryptographically signed. I've always interpreted this as a statement that, if you're not qualified to review what you just downloaded and make sure it's not malicious and that it faithfully implements the algorithms, that download isn't for you.

For what it's worth, Debian considered qmail "so buggy that it is not supportable": https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=510415 There's a fork called netqmail that's more actually usable.

In a similar way, libsodium is effectively a nacl fork that's actually usable by normal people. I think I've seen more people review libsodium than nacl's code itself (especially the custom assembly versions of various algorithms).

Re: Some gripes about nacl

#26
post #23
post #17

Paging @tptacek for comment

I like nacl. I like the author of this article and think he knows what he's talking about. I like libsodium but do worry about the project getting away from them; cleaning up the API is one thing, adding new crypto primitives is another. Still: use libsodium. The person whose opinion you really want on this article is 'pbsd.

I've been worried about that too. Recently I learned that libsodium includes a way to generate crypto_box keys from a fixed argument entropy chunk. It sounds really convenient but also circumvents all of the labor around centralizing entropy generation.

Is that a good thing to have? Maybe! It's convenient feeling. Is it dangerous? I have no idea—probably? Should it be part of the interface to libsodium? No clue.

Re: Some gripes about nacl

#27

As someone who didn't really know what they were doing, I used NaCl recently to write a program to tunnel packets over UDP. I started by reading the NaCl source and all the introductory material available—the web site, the two NaCl papers ("Cryptography in NaCl", "The security impact of a new cryptography library"), and quickly reviewed a couple of other papers (e.g. to understand deterministic encryption and D-H key…

A former colleague wrote a tool for just such a thing (Encrypted UDP tunneling) http://nardcore.org/ctunnel/

Re: Some gripes about nacl

#28
It's quite interesting to study why crypto_(secret)box requires zero padding. It's not to avoid memory allocation, as tedu suggests, but to make the implementation stupidly simple. For every invocation of crypto_secretbox, NaCl needs to generate a single-use 32 byte key for the Poly1305 MAC. Since the first 32 bytes of the message are zero, NaCl can simply encrypt the entire message with Salsa20, and the first 32 bytes of the resulting ciphertext conveniently become a suitable key for Poly1305. (So when the documentation says the padding has to actually be zero, it's not kidding.)

By making the implementation more complex (some memcpys and special casing of short messages), as libsodium has done for its crypto_secretbox_easy[1], you can avoid the need for this padding.

Personally, I think djb should have avoided exposing this implementation detail in the interface. To simplify the implementation, he could have used the first output block (stream position 0) of Salsa20 only for the Poly1305 key, and then encrypted the message starting with stream position 1, instead of trying to use the first output block for both the Poly1305 key and the message. The implementation would have been only marginally more complex (not as complex as the libsodium implementation, as you wouldn't need special casing). Unfortunately this can't be changed now without breaking interoperability with messages encrypted with the current version of crypto_secretbox.

[1] https://github.com/jedisct1/libsodium/blob/17932c782e5900ac8...

Re: Some gripes about nacl

#29
post #5

Simply put, use the reference nacl implementation only when you really know what you're doing. As with all things crypto it's easy to shoot yourself in the foot, and libsodium makes it a bit harder than reference nacl.

If you really know what you are doing you aren't even using NaCl, you use the individual algorithms.

For example: https://github.com/orlp/ed25519 .

Re: Some gripes about nacl

#30
Is nacl deprecated in favor of the libsodium fork? Or are both projects strong and continuing in parallel?

  [libsodium] is a portable, cross-compilable, installable, 
  packageable fork of NaCl, with a compatible API, and an 
  extended API to improve usability even further.
Source: https://github.com/jedisct1/libsodium/blob/master/README.mar...

I see DJB (original nacl creator http://nacl.cr.yp.to/) appears to contribute to libsodium: https://github.com/jedisct1/libsodium/blob/master/AUTHORS

The website for nacl seems to be a bit outdated (many dates seem to refer to 2013), although there is still this tantalizing bit about features in the 'next' nacl release:

  Major features in the next release of NaCl: full PIC support, 
  for easy integration into other languages; Ed25519 signatures 
  (currently available in SUPERCOP); NEON optimizations.
Thanks for any help clarifying this.
Post reply on HN