News for hackers. Stuff that matters.
Re:Libsodium 1.0.0 released by lifeisstillgood on Wednesday September 24, 2014 @06:03PM (#8364432)
I was reading around the zeroMQ implementation of secure messaging that uses this library. It seemed sensible enough (plaintext handshake, exchange session keys and hashes to verify long term keys). But it was entirely couched in "I am not a cryptographer" and "strawman only" caveats.

I appreciate the dangers of thinking "encryption cures all other bad decisions" but it would be useful to have a spectrum of security we can talk about.

I would love to see something like Big O notation for security - where we are 95% confident that the implementation has closed off vulnerabilities "on the order of published exploits, on the order of passive sniffing inside network, on the order of State level actor targeting your data"

I just wonder if we ever can say "hell yes this will do" as opposed to "well even Fort Knox might have a vulnerable point"

Edit: perhaps I mean "design patterns for security layers"

Re:Libsodium 1.0.0 released by kefka on Wednesday September 24, 2014 @02:36PM (#8363253)
Can someone much smarter than I tell me if this is safe to use? Or better yet, when a time period has passed to consider it safe to use?
Re:Libsodium 1.0.0 released by tptacek on Wednesday September 24, 2014 @02:56PM (#8363391)
It's better if you don't build crypto directly into your application at all, because you can still screw things up even if you build on Nacl. But with that said: Sodium/Nacl is better than virtually any of your other options for working directly with cryptography.
Re:Libsodium 1.0.0 released by nly on Wednesday September 24, 2014 @06:22PM (#8364512)
> It's better if you don't build crypto directly into your application at all, because you can still screw things up even if you build on Nacl.

Nacl was built to provide an API that is incredibly hard to screw up. That was one of djbs primary motivations. If you just need asymmetric encryption, or signing, or hashing, then it's the bees knees. These broad concepts aren't difficult to comprehend, and every developer should strive to understand and be able to use them. We shouldn't be encouraging people to be afraid... especially when things like dumb, plaintext username and password authentication is routinely implemented by developers without a second thought already.

Re:Libsodium 1.0.0 released by tptacek on Wednesday September 24, 2014 @07:51PM (#8364807)
Nacl makes it hard to screw up the constructions. It doesn't make it hard to make invalid assumptions about what a signed encrypted blob actually means.
Re:Libsodium 1.0.0 released by illumen on Thursday September 25, 2014 @06:53AM (#8366507)
+ makes it easy to add two numbers. It doesn't make it hard to make invalid assumptions about what adding two numbers together actually means.
Re:Libsodium 1.0.0 released by tptacek on Thursday September 25, 2014 @09:20AM (#8366924)
Nacl is a good thing. But crypto is just a tool. It's not a magic wand. People have already built vulnerable systems by making bogus assumptions about what Nacl can do.
Re:Libsodium 1.0.0 released by sarciszewski on Sunday September 28, 2014 @01:00AM (#8378974)
That's a shame :(
Re:Libsodium 1.0.0 released by sitkack on Wednesday September 24, 2014 @09:53PM (#8365147)
Can you recommend how to wrap crypto _around_ our applications if we aren't building it in?
Re:Libsodium 1.0.0 released by sarciszewski on Wednesday September 24, 2014 @03:49PM (#8363695)
"It's better if you don't build crypto directly into your application at all"

Plaintext all of the things! :P

Re:Libsodium 1.0.0 released by ary on Wednesday September 24, 2014 @03:57PM (#8363742)
I'm curious to know what you'd recommend for people who are looking to build applications around novel network protocols that aren't interested in the the certificate authority aspect of TLS?
Re:Libsodium 1.0.0 released by tptacek on Wednesday September 24, 2014 @05:40PM (#8364302)
There's no reason you have to use CAs to authenticate TLS. Plenty of enterprise tools keep whitelists of certificate hashes instead.
Re:Libsodium 1.0.0 released by bjornsing on Wednesday September 24, 2014 @04:26PM (#8363925)
There's an RFC on TLS with raw public keys that you should probably check out: http://tools.ietf.org/html/draft-ietf-tls-oob-pubkey-02.
Re:Libsodium 1.0.0 released by jewel on Wednesday September 24, 2014 @07:03PM (#8364656)
There are several TLS modes that don't use certificates. SRP and PSK are the two that I have some limited experience with. Both require sharing a password or key beforehand through some other medium.

If you're not concerned with man-in-the-middle attacks, then you could also use the ANON modes.

Re:Libsodium 1.0.0 released by revelation on Thursday September 25, 2014 @08:33AM (#8366782)
If you control the client software, theres no reason to use a certificate authority instead of making your own CA or just using self-signed certificates.
Re:Libsodium 1.0.0 released by higherpurpose on Wednesday September 24, 2014 @07:34PM (#8364741)
Re:Libsodium 1.0.0 released by Panino on Wednesday September 24, 2014 @07:59PM (#8364821)
To add to what others have said here, I'll point you to the authors of TweetNaCl, which sort-of competes with Sodium:

http://tweetnacl.cr.yp.to/papers.html

Little is said, other than that TweetNaCl is smaller and thus more easily auditable. No criticism. No pointing out failures. Considering the source, that's IMO a serious compliment. (For comparison, read what is said of OpenSSL...)

So in short, Sodium is a great library. It was forked from NaCl (the most trustable there is) and has some good features added, like scrypt, BLAKE2 and ChaCha.

I think NaCl, TweetNaCl, and Sodium are a great ecosystem, each with different strengths. All great libraries, and the only ones I'd recommend unless you're doing TLS.

Re:Libsodium 1.0.0 released by jedisct1 on Wednesday September 24, 2014 @09:58PM (#8365162)
The ecosystem is actually bigger, and includes projects such as TweetNaCl.js (pure Javascript implementation), Salt (pure PHP implementation) and Chaos.NaCl (pure C# implementation).

All these projects play well with each other: they have a decent set of primitives and constructions in common, accessible via a very similar API.

Re:Libsodium 1.0.0 released by duaneb on Wednesday September 24, 2014 @04:23PM (#8363908)
I believe it's safe to use in the sense of being stable. I don't believe they've had a full security audit yet, though.
Re:Libsodium 1.0.0 released by tptacek on Wednesday September 24, 2014 @07:52PM (#8364810)
People have weird ideas about the protective powers of a "full security audit". This is Bernstein, Lange, and Schwabe's code. There aren't many auditors qualified to review it.
Re:Libsodium 1.0.0 released by duaneb on Thursday September 25, 2014 @06:42PM (#8370232)
It's more about having a third party look at it rather than the credentials of the authors being in question.
Re:Libsodium 1.0.0 released by tptacek on Thursday September 25, 2014 @07:43PM (#8370470)
I understand the idea, but again: there aren't many third parties that are qualified to evaluate crypto code at all.
Re:Libsodium 1.0.0 released by sitkack on Wednesday September 24, 2014 @09:55PM (#8365156)
Theorem provers?
Re:Libsodium 1.0.0 released by nickmeharry on Wednesday September 24, 2014 @10:34PM (#8365271)
If you want proven crypto, there's always this project: https://github.com/idris-hackers/idris-crypto
Re:Libsodium 1.0.0 released by sarciszewski on Wednesday September 24, 2014 @04:25PM (#8363922)
Let's not wait 5 years then crowdfund it like TrueCrypt ;)
Re:Libsodium 1.0.0 released by tete on Wednesday September 24, 2014 @02:44PM (#8363306)
It's probably save to use in the sense that there are a number of projects (dnscrypt, zeromq, tox, ...) are using it already.
Re:Libsodium 1.0.0 released by zrail on Wednesday September 24, 2014 @03:00PM (#8363424)
When I first started paging through the docs it seemed like sort of a useless, dangerous thing. But now (after reading your comment and looking those projects up) it seems like it's an officially blessed version of NaCL, which makes it seem much safer.
Re:Libsodium 1.0.0 released by ZoFreX on Wednesday September 24, 2014 @03:07PM (#8363470)
The only part of this I care about right now is the random number generation. It looks good. Pity there's no way to get a float though, for a drop-in drand replacement.
Re:Libsodium 1.0.0 released by TillE on Wednesday September 24, 2014 @04:26PM (#8363924)
Generate 8 random bytes, shove them in an unsigned 64-bit int, then divide that number by 2^64 - 1. I assume that's what any function which returns a random value between 0.0 and 1.0 is actually doing.
Re:Libsodium 1.0.0 released by mjevans on Wednesday September 24, 2014 @06:35PM (#8364551)
It would probably be faster to directly 'hack' a raw IEEE 754 floating number:

http://en.wikipedia.org/wiki/IEEE_754-1985

The helpful Examples section already contains the numbers 0 and 1.

Let us assume that the output is supposed to be between 0 and 1; it seems that 0 should be inclusive and 1 exclusive for the most balanced 'quick' output.

Those two numbers have the leading binary format:

0 (8 or 11 bits exponent) (23 or 52 bits fraction) For either 32 or 64 bit floats.

Thus for a float (32 bit):

0 0 (7 bits) (23 bits) 30 bits of randomness are necessary, HOWEVER 0 01111111 is already one when the fraction is all 0s. The easiest solution I can see is to evenly drop some precision:

A reference for the casting procedure: http://en.wikipedia.org/wiki/Fast_inverse_square_root#Overvi...

Pseudo:

    uint32 randomNumber;
    ... set the random somehow, maybe rand() maybe /dev/urandom etc ...
    randomNumber &= 0x3F7FFFFF;
    return * (float *) &randomNumber;
Re:Libsodium 1.0.0 released by ZoFreX on Wednesday September 24, 2014 @07:20PM (#8364704)
There's a really big problem with dumping random bytes straight into a float, which is that you'll end up with a distribution that, while random, is not linear - i.e. the chance of it being between 0 and 0.5 will not be the same as the chance of it being between 0.5 and 1.0. This is because the gaps between representable numbers increases as the magnitude increases, i.e. there are "more numbers" between 0 and 1 than 100 and 101. The best technique I've found (so far) is to dump the bytes into an int, and divide.
Re:Libsodium 1.0.0 released by gjm11 on Wednesday September 24, 2014 @08:45PM (#8364962)
If you put 0 (i.e., plus) in the sign bit, and 1023 (i.e., zero) in the exponent field, and 52 random bits in the fraction field, of an IEEE double, then you get a number between 1 (inclusive) and 2 (exclusive); the representable numbers in that range are evenly spaced, and if your random bits are good then they are all equally likely, so you've got a uniform random number between 1 and 2. Subtract 1 if you want a uniform random number between 0 and 1 (this doesn't lose information; if a number between 1 and 2 is representable, subtracting 1 yields a representable number).

If your machine happens to work the same way as mine, the following will do it (unportable, untested, yadda yadda):

    double randomDouble() {
      uint64_t bits = random64bits();
      bits &= ~(3ull<<62); // clear sign and MSB of expt
      bits |= (1023ull<<52); // rest of exponent is 1-bits
      return (*(double*)&bits) - 1;
    }
Re:Libsodium 1.0.0 released by ZoFreX on Wednesday September 24, 2014 @09:41PM (#8365117)
Interesting, I'll test this. Thanks!

Btw, what is the advantage of this over dividing? Is it faster, does it give better distribution?

Re:Libsodium 1.0.0 released by lmm on Thursday September 25, 2014 @03:12AM (#8366008)
It should be faster than dividing. It will give you a uniform distribution over some (but not all) of the representable values between 0.0 and 1.0 (there are as many representable values between e.g. 0.25 and 0.5 as there are between 0.5 and 1.0, so a uniform distribution over representable values probably isn't what you want), which is probably as good as you can do.
Re:Libsodium 1.0.0 released by mjevans on Wednesday September 24, 2014 @07:53PM (#8364812)
Now that you mention it, that would also be an issue for the technique you describe; specifiable to the rounding characteristics for truncated numbers.

It's probably a better design idea to have a predictable sequence of float (like, application dependent) results and randomly select from within said sequence.

Re:Libsodium 1.0.0 released by ZoFreX on Wednesday September 24, 2014 @09:26PM (#8365065)
In my (naive and possibly flawed) tests, the division method is giving uniformly distributed results. Can you explain more what the limitations of that approach are?
Re:Libsodium 1.0.0 released by lmm on Thursday September 25, 2014 @07:57AM (#8366674)
The default rounding method is round-to-even, so e.g. 0.9999999 would be expected to come up slightly more often than 0.99999994 (the last two floats smaller than 1).

Being more precise would probably require thinking about all the possible int values.

Re:Libsodium 1.0.0 released by ZoFreX on Wednesday September 24, 2014 @07:17PM (#8364694)
I'm dividing by UULONG_MAX + 1.0, because it expects a number between 0 (inclusive) and 1.0 (exclusive). I'm not sure how portable it is though.
Re:Libsodium 1.0.0 released by dbaupp on Wednesday September 24, 2014 @05:04PM (#8364140)
How often do you need cryptographically secure random floats? (I'm genuinely interested in the use cases.)
Re:Libsodium 1.0.0 released by ZoFreX on Wednesday September 24, 2014 @07:15PM (#8364687)
I don't think it would be a common use-case when creating new software, but when patching legacy software to use better RNGs it's not unheard of for them to be using older RNGs that return a float between 0 and 1 (drand48 as an example).
Re:Libsodium 1.0.0 released by sarciszewski on Wednesday September 24, 2014 @04:34PM (#8363977)
Open an issue on GitHub?