]> git.codecow.com Git - Monocypher.git/log
Monocypher.git
7 years agoAvoids the first doubling for EdDSA signatures
Loup Vaillant [Sat, 4 Aug 2018 19:47:40 +0000 (21:47 +0200)]
Avoids the first doubling for EdDSA signatures

The overhead of this first multiplication is not much, but it's
measurable.

Note the use of a macro for the constant time lookup and addition. It
could have been a function, but the function call overhead eats up all
the gains (I guess there are too many arguments to push to and pop from
the stack).

7 years agoAvoids the first few doublings in EdDSA verification
Loup Vaillant [Sat, 4 Aug 2018 19:37:14 +0000 (21:37 +0200)]
Avoids the first few doublings in EdDSA verification

Legitimate scalars with EdDSA verification are at most 253-bit long.
That's 3 bits less than the full 256 bits.  By starting the loop at the
highest bit set, we can save a couple doublings.  It's not much, but
it's measurable.

7 years agoComb for EdDSA signatures in Niels coordinates
Loup Vaillant [Sat, 4 Aug 2018 19:08:53 +0000 (21:08 +0200)]
Comb for EdDSA signatures in Niels coordinates

While it takes a bit more space to encode, this also avoids some initial
overhead, and significantly reduces stack size.

Note: we could do away with the T2 coordinate to reduce the overhead of
constant time lookup, but this would also require more work per point
addition.  Experiments suggest the bigger table is a little faster.

7 years agoAll field element constants have the proper invariants
Loup Vaillant [Sat, 4 Aug 2018 13:30:54 +0000 (15:30 +0200)]
All field element constants have the proper invariants

A number of pre-computed constant didn't follow the ideal invariants set
forth by the carry propagation logic.  This increased the risk of limb
overflow.

Now all such constants are generated with fe_frombytes(), which
guarantees they can withstand the same number of additions and
subtraction before needing carry propagation. This reduces the risks,
and simplifies the analysis of code using field arithmetic.

7 years agoRevert "Cleaner fe_frombytes() (loading field elements)"
Loup Vaillant [Sat, 4 Aug 2018 11:25:23 +0000 (13:25 +0200)]
Revert "Cleaner fe_frombytes() (loading field elements)"

This reverts commit 6ee8787e61b3918789eab0ab38ce176abc767abb.

Turns out this commit was a huge blunder.  Carry propagation works by
minimising the absolute value of each limb.  The reverted patch did not
do that, resulting in limbs that were basically twice as big as they
should be.

While it could still work, this would at least reduce the margin for
error.  Better safe than sorry, and keep the more versatile loading
routine we had before.

Likewise, constants should minimise the absolute value of their limbs.
Failing to do so caused what was described in issue #107.

7 years agoCleaner fe_frombytes() (loading field elements)
Loup Vaillant [Fri, 3 Aug 2018 21:25:55 +0000 (23:25 +0200)]
Cleaner fe_frombytes() (loading field elements)

The old version of fe_frombytes() from the ref10 implementation was not
as clean as I wanted it to be: instead of loading exactly the right
bytes, it played fast and loose, then used a carry operation to
compensate.

It works, but there's a more direct, simpler, and I suspect faster
approach: put the right bits in the right place to begin with.

7 years agoMerged the Montgomery ladder back to crypto_x25519()
Loup Vaillant [Fri, 3 Aug 2018 18:58:38 +0000 (20:58 +0200)]
Merged the Montgomery ladder back  to crypto_x25519()

EdDSA stopped using the ladder, making it a separate function no longer
makes sense.

7 years agoSpecialised adding code for EdDSA signatures
Loup Vaillant [Fri, 3 Aug 2018 17:28:31 +0000 (19:28 +0200)]
Specialised adding code for EdDSA signatures

- Saved one multiplication by assuming Z=1
- Hoisted wipes out of loops
- Removed wipes for variable time additions

This made both signatures and verification a bit faster.  (Note: current
signature verification speed is only 23% slower than key exchange.  I
didn't think it could be that fast.)

7 years agoFull pre-computed table for EdDSA signatures
Loup Vaillant [Fri, 3 Aug 2018 16:47:15 +0000 (18:47 +0200)]
Full pre-computed table for EdDSA signatures

The main gain for now comes from reducing the amount of constant time
lookup.  We could reduce the table's size even further, *or* save a few
multiplications.

I'm currently a little suspicious of the way I generated the table. If
it passes the tests, it shouldn't have any error, but it still requires
some checking.

7 years agoge_double() is now more readable
Loup Vaillant [Mon, 30 Jul 2018 15:28:49 +0000 (17:28 +0200)]
ge_double() is now more readable

It's also become easier to hoist buffers out of loops

7 years agoCleaner point addition for EdDSA
Loup Vaillant [Sun, 29 Jul 2018 22:20:27 +0000 (00:20 +0200)]
Cleaner point addition for EdDSA

Point addition used to use 8 intermediate variables.  That's 6 more than
what was needed.  Removing them made wiping faster, and shrank the stack
by 240 bytes. (Stack size may matter in embedded systems.)

7 years agoProper comb algorithm for EdDSA
Loup Vaillant [Thu, 26 Jul 2018 20:40:21 +0000 (22:40 +0200)]
Proper comb algorithm for EdDSA

This will require some tweaking yet.  We could use signed combs to add 1
bit to the table (currently 4) without making it any bigger.  We should
hoist buffer wipes out of the double and add operations.  We could
consider other means of adding and doubling, to save multiplications and
to reduce table sizes (smaller tables have faster constant time lookup).

But we're faster than key exchange already.  We're on the right track.

7 years agoDon't use the Montgomery ladder for EdDSA
Loup Vaillant [Thu, 26 Jul 2018 18:29:11 +0000 (20:29 +0200)]
Don't use the Montgomery ladder for EdDSA

Again.

There are two reasons: the first is that there are 2 special cases where
the ladder or conversion gives the wrong results (the ladder is correct,
it was just hijacked for another purpose).

The second reason is, fixed based scalar multiplication can be made even
faster in Twisted Edwards space, by using a comb algorithm.  The current
patch uses a window, so it is slower.  It will get faster again.

7 years agoForgot to static the fe_pow22523() function
Loup Vaillant [Sun, 22 Jul 2018 21:15:10 +0000 (23:15 +0200)]
Forgot to static the fe_pow22523() function

7 years agoWording nitpick
Loup Vaillant [Wed, 18 Jul 2018 20:42:12 +0000 (22:42 +0200)]
Wording nitpick

7 years agoUpdated the examples for key exchange.
Loup Vaillant [Wed, 18 Jul 2018 20:33:27 +0000 (22:33 +0200)]
Updated the examples for key exchange.

Related to #102

The crypto_key_exchange() and crypto_x25519() examples no longer use the
return value, which has been deprecated.

Also harmonised the phrasing between the two man pages (I liked one more
than the other).

7 years agoMerge pull request #106 from fscoto/master+return-doc
Loup Vaillant [Wed, 18 Jul 2018 19:44:06 +0000 (21:44 +0200)]
Merge pull request #106 from fscoto/master+return-doc

Deprecate return values in crypto_x25519

7 years agoUnsigned sliding windows for EdDSA verification
Loup Vaillant [Wed, 18 Jul 2018 19:08:40 +0000 (21:08 +0200)]
Unsigned sliding windows for EdDSA verification

Reduces the number of additions in ge_double_scalarmult_vartime().
Verification is now 80% as fast as signing (in naive implementations,
it's only 50% as fast).

It could be even faster, but it's probably not worth the trouble:

- We could precompute the lookup table for the base point instead of
  constructing a cache.  This would save about 8 point additions total,
  at the cost of 64 lines of code just to lay out the 320 precomputed
  constants.

- We could use special, cheaper additions for the precomputed base
  point, at the cost of an additional addition function.

- We could use *signed* sliding windows to further reduce the number of
  additions, at the cost of an additional point subtraction function
  (two if combined with special additions for the base point).  Besides,
  I don't understand how they work.

The low hanging fruits have been taken.  Signature verification is
faster than ever before.  This is good enough.

7 years agoDeprecate return values in crypto_x25519
Fabio Scotoni [Wed, 18 Jul 2018 14:43:23 +0000 (16:43 +0200)]
Deprecate return values in crypto_x25519

This addresses #102.

This also adds a note that the public key function returns nothing, as
is noted on crypto_key_exchange(3monocypher).

7 years agoEasier access to scalar's bits
Loup Vaillant [Wed, 18 Jul 2018 11:41:16 +0000 (13:41 +0200)]
Easier access to scalar's bits

7 years agoMerge pull request #105 from fscoto/master+return-doc
Loup Vaillant [Wed, 18 Jul 2018 11:31:39 +0000 (13:31 +0200)]
Merge pull request #105 from fscoto/master+return-doc

Deprecate return values of crypto_key_exchange()

7 years agoDeprecate return values
Fabio Scotoni [Tue, 17 Jul 2018 13:40:47 +0000 (15:40 +0200)]
Deprecate return values

This addresses #102.

7 years agoShuffled functions around
Loup Vaillant [Sun, 15 Jul 2018 23:48:43 +0000 (01:48 +0200)]
Shuffled functions around

7 years agocosmetic
Loup Vaillant [Sun, 15 Jul 2018 23:47:14 +0000 (01:47 +0200)]
cosmetic

7 years agoCached points for EdDSA point addition
Loup Vaillant [Sun, 15 Jul 2018 23:44:01 +0000 (01:44 +0200)]
Cached points for EdDSA point addition

This saves one multiplication per addition, with a small but noticeable
increase in performance.

7 years agoBetter EdDSA point doubling (from ref10)
Loup Vaillant [Sun, 15 Jul 2018 21:45:59 +0000 (23:45 +0200)]
Better EdDSA point doubling (from ref10)

7 years agoFused doublings in EdDSA double scalarmult
Loup Vaillant [Sun, 15 Jul 2018 13:27:36 +0000 (15:27 +0200)]
Fused doublings in EdDSA double scalarmult

Fusing the two scalar multiplication together halves the number of
required doublings.  The code is just as simple, speeds up signature
verification quite a bit.

7 years agoUse variable time scalarmult for EdDSA checks
Loup Vaillant [Sat, 14 Jul 2018 17:54:54 +0000 (19:54 +0200)]
Use variable time scalarmult for EdDSA checks

Related to #101

General scalar multiplication for EdDSA was only used for checking, and
thus no longer needs to be constant time.  Removing buffer wipes and
using a variable time ladder simplifies and speeds up checks quite a
bit.

7 years agoRestored EdDSA optimisation
Loup Vaillant [Sat, 14 Jul 2018 16:16:42 +0000 (18:16 +0200)]
Restored EdDSA optimisation

The one that was removed for version 2.0.4, because a bogus special
cases caused it to accept forged signature (a big fat vulnerability).

To avoid the vulnerability, this optimisation is only used for signing
and public key generation.  Those never multiply the base point by zero,
and as such should not hit any nasty special case.  More specifically:

- Public key generation works the same as X25519: the scalar is trimmed
  before it is multiplied by the base point.
- Signing multiplies the base point by a nonce, which by construction is
  a random number between 1 and L-1 (L is the order of the curve).

External scrutiny will be needed to confirm this is safe.

Note: signing is now even faster than it was, because multiplying by a
known point (the base point) lets us avoid a conversion and a division.

Related to #101

7 years agoSeparated EdDSA scalarmult internal APIs
Loup Vaillant [Sat, 14 Jul 2018 11:55:59 +0000 (13:55 +0200)]
Separated EdDSA scalarmult internal APIs

- crypto_sign() and crypto_sign() public keys only use
  ge_scalarmult_base().
- crypto_check() only use ge_double_scalarmult_vartime().

They will be optimised separately.

7 years agofree(NULL) was not undefined after all
Loup Vaillant [Sat, 14 Jul 2018 11:06:54 +0000 (13:06 +0200)]
free(NULL) was not undefined after all

Reverts 79f8285ea6cae0db2e906bf3eb65c8fcadabdaf8
This simplifies the test suite a tiny bit.
Fixes #104

7 years agoDocumented EdDSA signature malleability
Loup Vaillant [Mon, 2 Jul 2018 11:29:03 +0000 (13:29 +0200)]
Documented EdDSA signature malleability

Some users tend to rely on security properties that are not provided by
cryptographic signatures.  This has lead to serious problems int the
past, such as BitCoin transaction malleability (a replay attack where
the recipient could repeat a previously existing transaction).

Mitigations for signature malleability are possible, but they're at best
easily misunderstood, and at worst incomplete.  Better warn the users in
the manual than encouraging the reliance on non-standard security
properties.

Fixes #100

7 years agoRemoved debug printf() calls
Loup Vaillant [Sat, 30 Jun 2018 19:09:00 +0000 (21:09 +0200)]
Removed debug printf() calls

7 years agoIntegrated Wicherproof Ed25519 test vectors
Loup Vaillant [Sat, 30 Jun 2018 18:23:55 +0000 (20:23 +0200)]
Integrated Wicherproof Ed25519 test vectors

Those test vectors assume SHA-512, and thus are only activated with the
-DED25519_SHA512 compilation option.

Note the omission of malleability test vectors.  Monocypher will
happily accept signatures even when S is not in canonical form.  This
is contrary to RFC 8032, which requires implementations to check that S
is lower than L.

I believe RFC 8032 is wrong.  Non-malleability means that someone who
only knows the public key, message, and signature, cannot produce
another valid signature.  It does *not* mean there is only one valid
signature.  In fact, when we know the private key, we can produce a
virtually unlimited number of different, valid, canonical signatures.

Like ECDSA, EdDSA uses a nonce.  Unlike ECDSA, that nonce doesn't come
from a random source, it comes from a hash of the message itself.  This
determinism prevents nonce reuse, among other problems.  However,
nothing prevents someone to bypass this rule, and use a random nonce
instead.  This will naturally produce a different, yet valid, signature.

EdDSA signatures are not unique. The difference between this and
malleability is subtle enough that advertising non-malleability will
lead users to believe in uniqueness, and bake that faulty assumption in
their designs, which will then be insecure.

Fixes #99

7 years agoEasier tarball generation
Loup Vaillant [Wed, 27 Jun 2018 09:16:56 +0000 (11:16 +0200)]
Easier tarball generation

- TARBALL_VERSION now defaults to the contents of VERSION.md
- TARBALL_DIR     now defaults to the current directory
- tarball_ignore is now included in the tarball (one can use the tarball
  to generate other tarballs).

7 years agoAdded VERSION file
Loup Vaillant [Wed, 27 Jun 2018 08:51:14 +0000 (10:51 +0200)]
Added VERSION file

7 years agoTypo
Loup Vaillant [Wed, 27 Jun 2018 08:48:44 +0000 (10:48 +0200)]
Typo

7 years ago2.0.4 changelog
Loup Vaillant [Sun, 24 Jun 2018 14:03:35 +0000 (16:03 +0200)]
2.0.4 changelog

7 years agoDon't free() NULL pointers
Loup Vaillant [Sun, 24 Jun 2018 13:58:55 +0000 (15:58 +0200)]
Don't free() NULL pointers

The alloc() function in the test suite unconditionally succeeds when
trying to allocate zero bytes.  It does so by returning NULL right away,
without exiting the program.  This was for portability for platforms
that refuse to allocate zero bytes.

Unfortunately, this meant that the test suite later called free() on
those NULL pointers, which is undefined.  Wrapping free() in a dealloc()
function avoids this error.

7 years agoEdDSA no longer accepts all zero signatures
Loup Vaillant [Sat, 23 Jun 2018 18:34:48 +0000 (20:34 +0200)]
EdDSA no longer accepts all zero signatures

This fixes the critical vulnerability in commit
e4cbf84384ffdce194895078c88680be0c341d76 (compute signatures in
Montgomery space (faster)), somewhere between versions 0.8 and 1.0, and
detected by the tests in the parent commit.

The fix basically reverts the optimisation, effectively halving the
performance of EdDSA.

It appears the conversion to Montgomery space and back didn't handle
every edge case correctly.  That optimisation will be re-introduced once
the issue has been fully understood.  This will probably require expert
advice.

7 years agoAdded anti-forgery tests for EdDSA
Loup Vaillant [Sat, 23 Jun 2018 17:30:01 +0000 (19:30 +0200)]
Added anti-forgery tests for EdDSA

Note how EdDSA fails miserably to reject all-zero signatures.  This is
the first critical vulnerability since 1.0.

7 years agoAdded tests vectors for public key generation
Loup Vaillant [Sat, 23 Jun 2018 13:42:18 +0000 (15:42 +0200)]
Added tests vectors for public key generation

Public key generation was up until now only tested implicitly.  Test
vectors can make us more confident.

7 years agoFixed wrong dependency in the makefile
Loup Vaillant [Tue, 19 Jun 2018 22:58:43 +0000 (00:58 +0200)]
Fixed wrong dependency in the makefile

7 years agoDon't try to malloc() zero bytes
Loup Vaillant [Tue, 19 Jun 2018 22:53:37 +0000 (00:53 +0200)]
Don't try to malloc() zero bytes

Some platforms refuse to allocate zero bytes.  This causes the entire
test suite to fail miserably.

To avoid this, we now fake success, and return the NULL pointer.  It
won't be dereferenced anyway.

7 years agoCorrected failing test on 32-bit systems
Loup Vaillant [Tue, 19 Jun 2018 22:26:41 +0000 (00:26 +0200)]
Corrected failing test on 32-bit systems

When size_t is not uint64_t, converting "negative" size_t integers to
uint64_t yields nonsensical results.  That is, the following isn't
portable:

    size_t   x = 42;
    uint64_t y = -i;

Because y might be missing the high order bits if size_t is smaller than
uint64_t. Instead, we want to convert to a large sized integer *before*
we negate it:

    size_t   x = 42;
    uint64_t y = -(uint64_t)i;

7 years agoChangelog formatting
Loup Vaillant [Mon, 18 Jun 2018 09:21:34 +0000 (11:21 +0200)]
Changelog formatting

7 years agoMerge pull request #97 from MikeA1/patch-1
Loup Vaillant [Mon, 18 Jun 2018 09:07:28 +0000 (11:07 +0200)]
Merge pull request #97 from MikeA1/patch-1

Update makefile

7 years agoTests for crypto_verify*() catch more errors
Loup Vaillant [Sun, 17 Jun 2018 18:05:36 +0000 (20:05 +0200)]
Tests for crypto_verify*() catch more errors

The test had a symmetry that caused them to miss a possible error, where
the implementer would replace an `|` operator by an `&` operator.
Breaking that symmetry allow them to catch that error.

The other errors are caught all the same.

7 years agoFaster crypto_verify*() tests
Loup Vaillant [Sun, 17 Jun 2018 17:47:46 +0000 (19:47 +0200)]
Faster crypto_verify*() tests

There was no need to test every possible value to catch the errors the
tests caugth.  Cutting them down makes the test 64000 times faster,
which matters quite a lot when we run the TIS interpreter.

The new tests catch just as many errors as the old ones.

7 years agoProperly ignore the formal-analysis folder
Loup Vaillant [Sun, 17 Jun 2018 17:30:41 +0000 (19:30 +0200)]
Properly ignore the formal-analysis folder

The way it was done earlier was also ignoring the formal-analysis.sh
script, which was then absent from the tarball releases.

7 years agoRun the TIS interpreter in 2 commands instead of 3.
Loup Vaillant [Sun, 17 Jun 2018 17:19:20 +0000 (19:19 +0200)]
Run the TIS interpreter in 2 commands instead of 3.

The TIS interpreter doesn't need to be run from inside the
formal-analysis folder. We can refer to the relevant C files directly.
This simplify the README a tiny little bit.

7 years agoCorrected formal analysis setup script
Loup Vaillant [Sun, 17 Jun 2018 17:13:39 +0000 (19:13 +0200)]
Corrected formal analysis setup script

The script did not create the right directory, so the files didn't copy
properly.

7 years agoCorrected variable sized buffer in the tests.
Loup Vaillant [Sun, 17 Jun 2018 17:06:12 +0000 (19:06 +0200)]
Corrected variable sized buffer in the tests.

The p_eddsa_random() test was triggering the TIS interbreter because of
a variable sized array allocated on the stack.  The test run properly
with a fixed sized buffer.  (Variable size buffers are tested elsewhere,
most notably with the test vectors).

7 years agoUpdate makefile
Mike [Sat, 16 Jun 2018 23:12:09 +0000 (17:12 -0600)]
Update makefile

Very minor spelling/punctuation change.

7 years ago2.0.3 changelog
Loup Vaillant [Sat, 16 Jun 2018 19:57:27 +0000 (21:57 +0200)]
2.0.3 changelog

7 years agoImproved the test suite
Loup Vaillant [Sat, 16 Jun 2018 10:29:34 +0000 (12:29 +0200)]
Improved the test suite

The test suite has been trimmed down a little, and improved a bit.  The
main goal was to have the TIS interpreter to run the entire test suite
in less than 20 hours, so I (and others) could realistically run it on
each new release.

- We now have much less Argon2i test vectors.  Only those at block size
  boundaries have been kept (for instance, it is important that we test
  both below and above 512 blocks, and below and above 64 bytes hashes,
  to hit all code paths.

- X25519 test vectors have been cut in half.  We have official test
  vectors and the Monte Carlo test already, we don't need too many
  vectors.  The main advantage here is to reduce the size of the test
  vector header file.

- The tests for chacha20_set_ctr() explore the test space more
  efficiently.

- The comparison between crypto_argon2i() and crypto_argon2i_general()
  is no longer repeated 128 times.

- The overlap tests for Argon2i have been cut down, and the overlap
  space has been reduced to compensate (so we're still sure there will
  be lots of overlap).

- The incremental tests for Blake2b and SHA-512 were cut down to a
  number of iterations, and total message size, that is *not* a multiple
  of a block length, so tests can fail more reliably if the MIN() macro
  has an error.

- The roundtrip tests for EdDSA have now been cut down, and try several
  message sizes as well.

- The random tests for EdDSA (which are mostly meant to test what
  happens when the point is outside the curve), have beet cut down (from
  1000 to 100), and try several message sizes as well.

7 years agoReset SHA-512 input buffer like Blake2b's
Loup Vaillant [Sat, 16 Jun 2018 10:03:22 +0000 (12:03 +0200)]
Reset SHA-512 input buffer like Blake2b's

This is mostly for consistency (code that follow the same patterns
everywhere are more easily reviewed).  The generated code is also a tiny
bit more efficient that way.

7 years agoFixed undefined behaviour in Blake2b
Loup Vaillant [Sat, 16 Jun 2018 09:35:52 +0000 (11:35 +0200)]
Fixed undefined behaviour in Blake2b

Fixes #96

The function blake2b_set_input() was reading uninitialised memory.
While this didn't matter in practice (most platforms don't have trap
representations for unsigned integers), it is undefined behaviour under
the C and C++ standards.  To fix it, we reset the whole input buffer
before setting its first byte.

The fix introduces a conditional, but that conditional only depend
on an index, which itself depends on the size of the input, which is not
secret.  We're still "constant time" with respect to secrets.

7 years ago80 columns OCD
Loup Vaillant [Sun, 10 Jun 2018 18:10:35 +0000 (20:10 +0200)]
80 columns OCD

7 years agodon't recomend 16 bytes for argon2i digests
Loup Vaillant [Sat, 12 May 2018 16:06:18 +0000 (18:06 +0200)]
don't recomend 16 bytes for argon2i digests

Listing 16 bytes as a possible size sounds like an endorsement.
But really, 16 bytes is a bit short, and weakens the security
of the subsequent symmetric crypto. You kind have to know what
you are doing to select such a size, so let's not list it.

7 years ago2.0.2 changelog
Loup Vaillant [Sun, 22 Apr 2018 22:47:04 +0000 (00:47 +0200)]
2.0.2 changelog

7 years agoComment: no need to wipe if it is not secret
Loup Vaillant [Sun, 22 Apr 2018 22:19:42 +0000 (00:19 +0200)]
Comment: no need to wipe if it is not secret

7 years agocosmetic
Loup Vaillant [Sun, 22 Apr 2018 21:48:26 +0000 (23:48 +0200)]
cosmetic

7 years agoremoved redundant wipe
Loup Vaillant [Sun, 22 Apr 2018 21:32:44 +0000 (23:32 +0200)]
removed redundant wipe

`crypto_*_final()` functions wipe their contexts already.  No need to
wipe again.

7 years ago80 columns conformity
Loup Vaillant [Sun, 22 Apr 2018 21:30:14 +0000 (23:30 +0200)]
80 columns conformity

7 years agocosmetic
Loup Vaillant [Sun, 22 Apr 2018 21:17:32 +0000 (23:17 +0200)]
cosmetic

7 years agoWarned about undefined behaviour
Loup Vaillant [Sat, 21 Apr 2018 19:27:14 +0000 (21:27 +0200)]
Warned about undefined behaviour

7 years agoRemoved "cannot fail" from the manual
Loup Vaillant [Sat, 21 Apr 2018 18:31:22 +0000 (20:31 +0200)]
Removed "cannot fail" from the manual

This is C we're talking about.  Functions that return void cannot fail
only if they're used correctly.  Incorrect inputs can still trigger
undefined behaviour.  In this sense, those functions _can_ fail.

Returning void should be an obvious enough hint that the function
requires no error handling. At least it is if you're familiar enough
with C. (If one is not, one is not qualified to use a crypto library in
an unsafe language.)

An unqualified "cannot fail" give any more information than `void`, and
may even mislead some users.  Better stay on the safe side.

7 years agouse RANDOM_INPUT macro everywhere
Loup Vaillant [Sat, 21 Apr 2018 17:48:38 +0000 (19:48 +0200)]
use RANDOM_INPUT macro everywhere

7 years agoTests: properly align argon2i work area
Loup Vaillant [Sat, 21 Apr 2018 17:39:30 +0000 (19:39 +0200)]
Tests: properly align argon2i work area

7 years agoMakefile cleanup
Loup Vaillant [Sat, 21 Apr 2018 15:20:48 +0000 (17:20 +0200)]
Makefile cleanup

7 years agoTest vectors no longer depend on Monocypher
Loup Vaillant [Sat, 21 Apr 2018 14:26:32 +0000 (16:26 +0200)]
Test vectors no longer depend on Monocypher

Test vectors for EdDSA used to use Moncoypher's Blake2b hash. This
didn't make much sense, and could even conceivably be construed as
circular.  Blake2b vectors were properly generated, so it wasn't really
circular, but that's still ugly.

Now the test vectors only depend on Libsodium and ed25519-donna.

7 years agofixed memory leak in Argon2i tests
Loup Vaillant [Fri, 20 Apr 2018 22:53:59 +0000 (00:53 +0200)]
fixed memory leak in Argon2i tests

7 years agoAdded ed25519 tests
Loup Vaillant [Fri, 20 Apr 2018 22:37:41 +0000 (00:37 +0200)]
Added ed25519 tests

Monocypher failed to compile with -DED25519_SHA512 since we added the
incremental interface.  The error has been corrected by the #95 Pull
Request by @vbmithr.

To make sure this doesn't happen again, the test suite has been expanded
to include the official Ed25519 construction.  You can test it thus:

    $ make clean
    $ make test CFLAGS="-DED25519_SHA512 -O3"

Or just run `tests/test.sh` to have the whole shebang.

7 years agoIndent #ifdef
Loup Vaillant [Fri, 20 Apr 2018 22:34:50 +0000 (00:34 +0200)]
Indent #ifdef

7 years agoNo Libsodium for Blake2b EdDSA
Loup Vaillant [Fri, 20 Apr 2018 21:46:52 +0000 (23:46 +0200)]
No Libsodium for Blake2b EdDSA

7 years agoMerge pull request #95 from vbmithr/fix-include
Loup Vaillant [Fri, 20 Apr 2018 18:54:21 +0000 (20:54 +0200)]
Merge pull request #95 from vbmithr/fix-include

fix include when using ED25519_SHA512

7 years agofix include when using ED25519_SHA512
Vincent Bernardoff [Wed, 18 Apr 2018 08:25:26 +0000 (10:25 +0200)]
fix include when using ED25519_SHA512

7 years agocrypto_check does not wipe context
Loup Vaillant [Mon, 16 Apr 2018 22:52:14 +0000 (00:52 +0200)]
crypto_check does not wipe context

7 years agoManual: minor rewording
Loup Vaillant [Mon, 16 Apr 2018 22:45:16 +0000 (00:45 +0200)]
Manual: minor rewording

7 years agoManual: verifiation->validation
Loup Vaillant [Mon, 16 Apr 2018 12:42:18 +0000 (14:42 +0200)]
Manual: verifiation->validation

7 years agoManual: void returns cannot fail
Loup Vaillant [Mon, 16 Apr 2018 12:39:34 +0000 (14:39 +0200)]
Manual: void returns cannot fail

7 years agoBlake2b empty messages may be NULL
Loup Vaillant [Mon, 16 Apr 2018 12:33:24 +0000 (14:33 +0200)]
Blake2b empty messages may be NULL

7 years agoCorreted minor inaccuracy in the manual
Loup Vaillant [Mon, 16 Apr 2018 11:49:49 +0000 (13:49 +0200)]
Correted minor inaccuracy in the manual

7 years agoformatting typo
Loup Vaillant [Mon, 16 Apr 2018 11:40:34 +0000 (13:40 +0200)]
formatting typo

7 years agoTweaked Chacha20 summary
Loup Vaillant [Mon, 16 Apr 2018 11:35:31 +0000 (13:35 +0200)]
Tweaked Chacha20 summary

7 years agoMissing plural in the manual
Loup Vaillant [Mon, 16 Apr 2018 11:24:13 +0000 (13:24 +0200)]
Missing plural in the manual

7 years agoremoved spurious consts in the manual
Loup Vaillant [Mon, 16 Apr 2018 11:09:02 +0000 (13:09 +0200)]
removed spurious consts in the manual

7 years agoRemoved obsolete warning in the manual
Loup Vaillant [Mon, 16 Apr 2018 10:33:49 +0000 (12:33 +0200)]
Removed obsolete warning in the manual

The length of additional data in authenticated encryption is now
authenticated.  The user no longer have to worry about it, ever.

7 years agoUsed a single zero buffer
Loup Vaillant [Sun, 15 Apr 2018 15:35:23 +0000 (17:35 +0200)]
Used a single zero buffer

7 years agoFixed missing wipes
Loup Vaillant [Sun, 15 Apr 2018 15:23:17 +0000 (17:23 +0200)]
Fixed missing wipes

Found 4 internal buffers that were not properly wiped.  While this were
unlikely to turn into an exploitable vulnerability, we can never be too
cautious.

- XChacha20 initialisation failed to wipe its intermediate key.
- Blake2b initialisation failed to wipe a copy of its secret key.
- EdDSA failed to wipe an internal field element
- EdDSA failed to wipe an internal group element

7 years agoReplaced GNU-all permissive licence by the CC-0
Loup Vaillant [Sat, 7 Apr 2018 16:58:23 +0000 (18:58 +0200)]
Replaced GNU-all permissive licence by the CC-0

I always wanted to release Monocypher to the public domain, at least to
the extent possible.  My amputated version of the GNU all permissive
licence was nice and concise, but had no real legal basis.  We need
something solid, hence CC-0 from Creative Commons.

In case that's still not enough, the better known BSD licence has been
kept as a fallback.

7 years agoCorrected the BSD licence
Loup Vaillant [Fri, 6 Apr 2018 22:45:23 +0000 (00:45 +0200)]
Corrected the BSD licence

It was missing "All rights reserved", "(c)", and a coma.

8 years agoAvoid negating unsigned numbers (for MSVC)
Loup Vaillant [Tue, 3 Apr 2018 19:54:49 +0000 (21:54 +0200)]
Avoid negating unsigned numbers (for MSVC)

MSVC doesn't like when people negate unsigned numbers, and the result is
still unsigned.  By default, it's an error.  Moreover, section 6.5.6 of
the C11 standard doesn't clearly specify what -x means when x is an
unsigned integer.  It does however specify ~x.

So I replaced -x by ~x+1.  This was getting ugly, though, so I made the
ALIGN macro.  ALIGN(x, block_size) returns how many bytes we need to
reach the next block size, assuming we've already consumed x bytes.  For
instance, ALIGN(11, 8) == 5.  It uses bit twiddling trickery, so the
block size must be a power of 2.

8 years agoExplicit conversions to small integers (for MSVC)
Loup Vaillant [Tue, 3 Apr 2018 19:39:47 +0000 (21:39 +0200)]
Explicit conversions to small integers (for MSVC)

MSVC warns about possible loss of information when doing implicit
conversion from bigger integers to smaller integers, such as u64 to u32.

Those were intentional, so I added explicit conversions.

8 years agoReplaced "Double Ratchet" by "X3DH" in the manual
Loup Vaillant [Thu, 22 Mar 2018 21:36:48 +0000 (22:36 +0100)]
Replaced "Double Ratchet" by "X3DH" in the manual

The Double Ratchet algorithm has other purposes than simple forward
secrecy, and is quite complicated, and rely on some prior key exchange
protocol to boot.  Pointing to it wasn't good general purpose advice.

X3DH is what we were looking for.  It is simple enough, and addresses
the main issues around key exchange (forward secrecy, replay attacks, and
deniability).

8 years agoBetter tests for incremental interfaces
Loup Vaillant [Thu, 22 Mar 2018 21:29:41 +0000 (22:29 +0100)]
Better tests for incremental interfaces

Less of them, and better guarantee of exhaustiveness, because we test
every possible chunk length between 0 and twice the input size.

8 years agoMonte Carlo works up to 1M, not 100k
Loup Vaillant [Thu, 22 Mar 2018 21:03:25 +0000 (22:03 +0100)]
Monte Carlo works up to 1M, not 100k

8 years agoAdjusted the number of test vectors
Loup Vaillant [Thu, 22 Mar 2018 20:51:06 +0000 (21:51 +0100)]
Adjusted the number of test vectors

There were too many tests vectors.  This is redundant, takes more time
to test, and bloats the generated vectors header file, which then takes
longer to compile.

I reduced their numbers, while making sure they were as effective as
they used to be (maximum code coverage, and every relevant lengths
still tested).

For those who worry about dangerously reducing the number of tests for
Poly1305: don't.  There is nothing the random tests can catch that the
official, hand crafted test vectors cannot.  The random tests don't
really test the core algorithm, they test the loading code.

8 years agoCorrected possible misalignment in the tests
Loup Vaillant [Thu, 22 Mar 2018 20:47:13 +0000 (21:47 +0100)]
Corrected possible misalignment in the tests

Argon2i must have its work area aligned for uint64_t.  I don't recall
any guarantee of alignment when allocating an array of uint8_t on the
stack.  So we allocate on the heap instead.