Libsodium 1.0.0 released
libsodium.org
libsodium.org
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"
Plaintext all of the things! :P
If you're not concerned with man-in-the-middle attacks, then you could also use the ANON modes.
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.
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.
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.
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;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.
Being more precise would probably require thinking about all the possible int values.
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;
}Btw, what is the advantage of this over dividing? Is it faster, does it give better distribution?