]> git.codecow.com Git - Monocypher.git/log
Monocypher.git
3 years agoReorder monocypher.h a bit
Loup Vaillant [Sun, 4 Dec 2022 16:37:06 +0000 (17:37 +0100)]
Reorder monocypher.h a bit

We're down to only 2 structs, with a clear place for each.
The separate section is no longer warranted.

3 years agoRemove deprecated crypto_key_exchange()
Loup Vaillant [Sun, 4 Dec 2022 16:32:55 +0000 (17:32 +0100)]
Remove deprecated crypto_key_exchange()

3 years agoFix tis-ci
Loup Vaillant [Sat, 3 Dec 2022 11:26:17 +0000 (12:26 +0100)]
Fix tis-ci

Also integrated tis-ci tests into github CI

3 years agoFix speed tests
Loup Vaillant [Sat, 3 Dec 2022 10:54:12 +0000 (11:54 +0100)]
Fix speed tests

3 years agoSafer interface for EdDSA
Loup Vaillant [Fri, 2 Dec 2022 22:45:45 +0000 (23:45 +0100)]
Safer interface for EdDSA

Now the private key is 64 bytes, and is the concatenation of the seed
and the public key just like Libsodium.  The idea is to make sure users
never sign messages with the wrong public key, which can leak the secret
scalar and allow forgeries.

Users who can't afford the overhead of storing 32 additional bytes for
the secret key (say they need to burn the key into expensive fuses),
they can always only store the first 32 bytes, and re-derive the entire
key pair when they need it.

TODO: update the manual.

Fixes #240

3 years agoReplaced stray uint8_t by u8
Loup Vaillant [Fri, 2 Dec 2022 22:45:13 +0000 (23:45 +0100)]
Replaced stray uint8_t by u8

3 years agoRemove EdDSA incremental & custom hash API
Loup Vaillant [Thu, 1 Dec 2022 15:27:08 +0000 (16:27 +0100)]
Remove EdDSA incremental & custom hash API

The incremental and custom hash API was too complex and too niche to
justify itself.  I'm removing them in favour of a more flexible
approach: giving the basic building blocks necessary to implement EdDSA
manually.

Those building blocks comprise 5 specialised functions:

- crypto_eddsa_trim_scalar: turn 32 random bytes into a proper scalar.
- crypto_eddsa_reduce     : reduces a 64 bytes number modulo L.
- crypto_eddsa_mul_add    : like MUL_ADD, except modulo L.
- crypto_eddsa_scalarbase : multiplies a scalar by the base point.
- crypto_eddsa_r_check    : generates R independently for verification.

These make it fairly easy to implement EdDSA (including Ed25519) in
various ways, including the streaming and custom hash functions I just
removed, replacing the deterministic nonce by a random one, or adding a
random prefix to mitigate the energy side channel in some settings.

I believe only minimal tweaks are required to implement the Edwards25519
half of RFC 8032 entirely (including the context and pre-hash variants),
as well as XEdDSA (which should only require a single Montgomery to
Edwards conversion function).

This is a prototype, and the extensibility promises remain to be tested.
Ideally that means implementing all the fancy extensions in a separate
project, and _maybe_ include some of them in the optional files.

Related to #227

3 years agoSwitch indentation from spaces to tabs.
Loup Vaillant [Tue, 29 Nov 2022 23:49:15 +0000 (00:49 +0100)]
Switch indentation from spaces to tabs.

For the longest time I had a fairly strong personal preference for
spaces.  Then it came to my attention that using tabs meaningfully
increases accessibility.

As a cryptography library, Monocypher is supposed to ultimately help,
among other people, the most vulnerable among us.  It would be a shame
to potentially exclude disabled contributors or auditors.

Note that this patches sometimes changes a little more than just
spacing.  A few pieces of code in particular relied on indentation
width, and had to be reworked a little bit to make them tab width
agnostic.

3 years agoRemove deprecated functions.
Loup Vaillant [Mon, 28 Nov 2022 22:58:53 +0000 (23:58 +0100)]
Remove deprecated functions.

Deprecated functions are redundant with previous major branches of
Monocypher, and as such don't serve any meaningful purpose.  Maintaining
old branches is cheaper anyway.

Note: this will also remove them from the manual, including on the
website when updated.  We could compensate by publishing older versions
of the manual, or we could punt on it and rely on the fact that the
tarball contain the associated manual.

3 years agoDocumented BLAKE2_NO_UNROLLING
Loup Vaillant [Thu, 1 Sep 2022 16:47:41 +0000 (18:47 +0200)]
Documented BLAKE2_NO_UNROLLING

3 years agoFixed various compiler warnings
Loup Vaillant [Thu, 1 Sep 2022 16:26:27 +0000 (18:26 +0200)]
Fixed various compiler warnings

- Global constant should have been `static`
- Reserved identifier (double underscores)
- Loss of precision in implicit conversions
- Implicit change of sign

3 years agodoc: crypto_sign: suggest safer API
Loup Vaillant [Mon, 11 Jul 2022 16:04:33 +0000 (18:04 +0200)]
doc: crypto_sign: suggest safer API

Users may wonder why we didn't provide the safer API from the outset.
We could explain this is for backwards compatibility, but this man page
is quite cluttered already.

TODO: the next major version of Monocypher should definitely adopt this
safer API.

Partially addresses #240

3 years agodoc: crypto_sign: fat -> composite (in C code)
Loup Vaillant [Mon, 11 Jul 2022 15:58:21 +0000 (17:58 +0200)]
doc: crypto_sign: fat -> composite (in C code)

3 years agodoc: crypto_sign: fix memcmp() instead of memcpy() in example
Fabio Scotoni [Sat, 9 Jul 2022 09:07:57 +0000 (11:07 +0200)]
doc: crypto_sign: fix memcmp() instead of memcpy() in example

3 years agodoc: crypto_sign: fat -> composite
Fabio Scotoni [Sat, 9 Jul 2022 09:06:35 +0000 (11:06 +0200)]
doc: crypto_sign: fat -> composite

It's a matter of taste ("fat pointer" is a term, too),
but I feel like that's not a term fitting the rest of the manual style.

3 years agodoc: crypto_sign: fix wording nits, grammar
Fabio Scotoni [Sat, 9 Jul 2022 09:01:38 +0000 (11:01 +0200)]
doc: crypto_sign: fix wording nits, grammar

In particular:

- clarify NULL goes in public_key (not secret_key)
- add parenthetical note to define the term "fat public key" inline
- fix commas (I actually had to look up the rules for comma-before-but)
- avoid colloquial "we"

3 years agodoc: fix crypto_sign metadata to reflect 8697f2ffd
Fabio Scotoni [Sat, 9 Jul 2022 08:51:37 +0000 (10:51 +0200)]
doc: fix crypto_sign metadata to reflect 8697f2ffd

3 years agoDocument EdDSA API misuse
Loup Vaillant [Fri, 8 Jul 2022 20:58:53 +0000 (22:58 +0200)]
Document EdDSA API misuse

Partially addresses #240

We may want to write a safer API on top of the low-level one, that
bundles the seed and public key together as a single 64 bytes blob.

3 years agomakefile: fix cross-compilation
Nikolay Korotkiy [Thu, 16 Jun 2022 19:04:36 +0000 (22:04 +0300)]
makefile: fix cross-compilation

3 years agoDocument MONOCYPHER_CPP_NAMESPACE
Loup Vaillant [Mon, 25 Apr 2022 20:37:19 +0000 (22:37 +0200)]
Document MONOCYPHER_CPP_NAMESPACE

3 years agoFixed CHANGELOG
Loup Vaillant [Mon, 25 Apr 2022 18:46:36 +0000 (20:46 +0200)]
Fixed CHANGELOG

3 years agoChangelog for version 3.1.3
Loup Vaillant [Tue, 19 Apr 2022 21:35:54 +0000 (23:35 +0200)]
Changelog for version 3.1.3

3 years agoRestore simple fe_frombytes()
Loup Vaillant [Tue, 19 Apr 2022 21:01:49 +0000 (23:01 +0200)]
Restore simple fe_frombytes()

Though I think the option of choosing how many bits we mask off at the
end is useful, it made the code more confusing. Better leave it for the
one case where we really need it: parsing Elligator representatives,
which are represented with one less bit than usual.

This does cost us 4 lines of code, but I think they're worth it. The
previous code was too much like code golf for my comfort.

4 years agoFixed Elligator reverse map comments
Loup Vaillant [Sun, 20 Mar 2022 20:29:07 +0000 (21:29 +0100)]
Fixed Elligator reverse map comments

Also took the opportunity to fix the Python inverse map when the point
is zero (it used to fail, now it returns the all zero representative).

4 years agoRemoved redundant Valgrind tests
Loup Vaillant [Sun, 13 Mar 2022 09:57:52 +0000 (10:57 +0100)]
Removed redundant Valgrind tests

I think we don't need to test both -O2 and -O3. We're checking memory
error here, they should not be much different under different
optimisation settings (though maybe -O3 can trigger more bugs).

Also did not add myself to the list of authors, I think this trivial
change is not copyrightable.

4 years agoOnly Christ Fogelklou wrote ci.yml
Loup Vaillant [Sun, 13 Mar 2022 09:56:56 +0000 (10:56 +0100)]
Only Christ Fogelklou wrote ci.yml

4 years agoSquashed commit of the following:
Chris Fogelklou [Fri, 11 Mar 2022 05:24:20 +0000 (06:24 +0100)]
Squashed commit of the following:

commit 41cd7c9a3270c5a3c94d379dee2e4242ec69fc25
Author: Chris Fogelklou <chris.fogelklou@gmail.com>
Date:   Fri Mar 11 06:20:14 2022 +0100

    Remove some extraneous lines.

commit b0a7dddc5a3bf03a7bec2621cce5dd1c2620753e
Author: Chris Fogelklou <chris.fogelklou@gmail.com>
Date:   Fri Mar 11 06:10:01 2022 +0100

    Add crashy builds.

commit 3a6b343df68f074aa626f619d7ac9c8fe860e23a
Author: Chris Fogelklou <chris.fogelklou@gmail.com>
Date:   Fri Mar 11 06:09:09 2022 +0100

    One more test - crashy flags

commit 2c399f4fd42488f6aae205b369ea10d91b824050
Author: Chris Fogelklou <chris.fogelklou@gmail.com>
Date:   Fri Mar 11 06:05:14 2022 +0100

    Install valgrind before using it.

commit a57a7abd526934f5d90ad2a20c651bc832ea3047
Author: Chris Fogelklou <chris.fogelklou@gmail.com>
Date:   Fri Mar 11 06:02:39 2022 +0100

    Try GCC and Clang, build with different varieties of compiler and cflags

commit 07f435959c6cfc10f4d6a46d9ba5048bbe30a410
Author: Chris Fogelklou <chris.fogelklou@gmail.com>
Date:   Fri Mar 11 05:58:41 2022 +0100

    Try slightly better optimization.

commit d5d8b6ba7eb453a2fe8e5aca7715477443135b64
Author: Chris Fogelklou <chris.fogelklou@gmail.com>
Date:   Fri Mar 11 05:55:45 2022 +0100

    Missed the make clean command.

commit cf60bc603ce28eb6671414edb5e003f9bf4a6e87
Author: Chris Fogelklou <chris.fogelklou@gmail.com>
Date:   Fri Mar 11 05:52:07 2022 +0100

    Try with optimization level 0

commit 630b0a957555adb0b22af9eb720fb25bee56f728
Author: Chris Fogelklou <chris.fogelklou@gmail.com>
Date:   Fri Mar 11 05:41:30 2022 +0100

    Start a new PR so as to not keep working in the old one.

4 years agoAdd badge pointing to LoupVaillant Github Actions (#2)
Chris Fogelklou [Sat, 5 Mar 2022 06:49:07 +0000 (07:49 +0100)]
Add badge pointing to LoupVaillant Github Actions (#2)

* Add a comment to the ci.yml file about also running on macos.
* Add a link to the new CI badge using Github Actions.

4 years agoRun basic tests taken from the readme.md file using Github Actions.
Chris Fogelklou [Sat, 5 Mar 2022 06:33:16 +0000 (07:33 +0100)]
Run basic tests taken from the readme.md file using Github Actions.

* Add a github workflow which follows the basic install flow in the readme.md.
* Add installation of libsodium.
* Add valgrind as a dependency.
* Add llvm to list of dependencies.

4 years agodoc/x25519: Mention hashing the public keys
Samuel Lucas [Wed, 23 Feb 2022 19:14:22 +0000 (19:14 +0000)]
doc/x25519: Mention hashing the public keys

#232 but for crypto_x25519.

4 years agoManual: hash shared secret *and* public keys
Loup Vaillant [Mon, 14 Feb 2022 10:02:10 +0000 (11:02 +0100)]
Manual: hash shared secret *and* public keys

4 years agoAdjust man2html.sh to deprecated crypto_key_exchange
Loup Vaillant [Mon, 14 Feb 2022 09:35:36 +0000 (10:35 +0100)]
Adjust man2html.sh to deprecated crypto_key_exchange

4 years agocrypto_hchacha20: Remove reference to deprecated crypto_chacha20_encrypt
Fabio Scotoni [Sun, 13 Feb 2022 15:07:52 +0000 (16:07 +0100)]
crypto_hchacha20: Remove reference to deprecated crypto_chacha20_encrypt

Addresses @LoupVaillant's comment in #233.

4 years agoDeprecate crypto_key_exchange
Fabio Scotoni [Sun, 13 Feb 2022 05:44:40 +0000 (06:44 +0100)]
Deprecate crypto_key_exchange

See #230.
In summary:
The way crypto_key_exchange() works was not optimal.
Several combinations of (private, public) key pairs produce the same
shared secret (see 54a7ef551078dda001f94f1045e142af0fc1008a);
crypto_key_exchange() did nothing to mitigate that.

Since this is a high-level function that cannot be saved even with
documentation because it is so fundamentally misguided,
it is now deprecated (see #232).
Users are encouraged to either adopt the function into their own code
if and only if they require it for backwards compatibility,
starting with the release that removes it,
or preferably migrate to implementing an existing protocol,
such as instantiating a Noise protocol pattern or a protocol like X3DH.

4 years agodoc: Mention hashing the public keys (#232)
Samuel Lucas [Sat, 12 Feb 2022 22:29:38 +0000 (22:29 +0000)]
doc: Mention hashing the public keys (#232)

Mention hashing the public keys

Closes #230.

4 years agoFix invsqrt() boolean return
Loup Vaillant [Sat, 12 Feb 2022 10:13:22 +0000 (11:13 +0100)]
Fix invsqrt() boolean return

The invsqrt() function used to return true when its operand was a
non-zero square.  Thing is, it was used to determine whether it was a
square, *period*.  If the operand was zero, we had the wrong answer.

This introduced two "errors" visible by the end user:

* The all-zero X25519 point could not be mapped back to an Elligator 2
  representative.  In practice that point is never used, but that does
  not comply with the original paper.

* The (0, 1) EdDSa public key could not be serialised, causing any
  signature verification associated with it to fail. This one we really
  don't care, because even though it is on the curve, that point has low
  order, and legitimate public keys all have prime order.

Fixes #231

4 years agoRephrased awkward sentence in documentation
Loup Vaillant [Mon, 31 Jan 2022 11:15:04 +0000 (12:15 +0100)]
Rephrased awkward sentence in documentation

4 years agoReadability nitpick
Loup Vaillant [Sun, 30 Jan 2022 13:48:09 +0000 (14:48 +0100)]
Readability nitpick

4 years agoReverted 'log in' back into 'login'
Loup Vaillant [Sun, 30 Jan 2022 12:34:23 +0000 (13:34 +0100)]
Reverted 'log in' back into 'login'

Turns out even though many dictionaries don't recognise it,
'login' was correct.

4 years agoFixed typo in AUTHORS.md
Loup Vaillant [Tue, 25 Jan 2022 22:18:30 +0000 (23:18 +0100)]
Fixed typo in AUTHORS.md

4 years agoFixed many typos
Loup Vaillant [Tue, 25 Jan 2022 08:32:36 +0000 (09:32 +0100)]
Fixed many typos

Found by Samuel Lucas, applied at my discretion

4 years agoUse global constant L instead of duplicating it
Loup Vaillant [Sat, 15 Jan 2022 14:10:54 +0000 (15:10 +0100)]
Use global constant L instead of duplicating it

4 years agoRenamed 'Sha512' to 'SHA-512'
Loup Vaillant [Fri, 14 Jan 2022 22:03:32 +0000 (23:03 +0100)]
Renamed 'Sha512' to 'SHA-512'

4 years agoRename 'Blake2' to 'BLAKE2'
Loup Vaillant [Fri, 14 Jan 2022 21:46:41 +0000 (22:46 +0100)]
Rename 'Blake2' to 'BLAKE2'

4 years agoAllow headers to declare a C++ namespace
Jens Alfke [Wed, 12 Jan 2022 19:36:44 +0000 (11:36 -0800)]
Allow headers to declare a C++ namespace

If the preprocessor symbol `MONOCYPHER_CPP_NAMESPACE` is defined,
the Monocypher headers will be wrapped in a C++ namespace instead of
in `extern "C"`. The name of the namespace is the value of the symbol.

This requires also compiling Monocypher's .c files as C++, either by:
- Using a compiler option like `--x c++`;
- Using an IDE setting, like the Identity & Type inspector in Xcode;
- Putting `#include "monocypher.c" in a C++ file

4 years agoAdded a script that renames the 'crypto_' prefix
Loup Vaillant [Tue, 11 Jan 2022 20:48:05 +0000 (21:48 +0100)]
Added a script that renames the 'crypto_' prefix

Fixes #224

This is not a perfect fix (hard to have one without proper namespaces),
but at least users now an easy way to avoid name clashes.

4 years agoFixed Python 3.10 deprecation warning
Loup Vaillant [Tue, 11 Jan 2022 01:03:53 +0000 (02:03 +0100)]
Fixed Python 3.10 deprecation warning

The randrange function will soon only accept integer arguments,
so I switched to integer division.

4 years agoFixed example in HMAC documentation
Loup Vaillant [Sun, 9 Jan 2022 17:58:23 +0000 (18:58 +0100)]
Fixed example in HMAC documentation

4 years agoSpelled libsodium with lowercase
Loup Vaillant [Sun, 9 Jan 2022 17:42:52 +0000 (18:42 +0100)]
Spelled libsodium with lowercase

Just conforming to the original documentation.

4 years agodoc: Argon2 now has an RFC, not just a draft
Fabio Scotoni [Wed, 8 Sep 2021 14:34:55 +0000 (16:34 +0200)]
doc: Argon2 now has an RFC, not just a draft

4 years agoInlined ge_r_check()
Loup Vaillant [Wed, 18 Aug 2021 19:09:11 +0000 (21:09 +0200)]
Inlined ge_r_check()

This saves 9 lines of code.

ge_r_check() was once separated to enhance readability, but it turns out
that inlining it saves more lines of code than expected. The code is
almost more readable now, though the comments are still needed.

4 years agoEdDSA: parsing public key negate it right away
Loup Vaillant [Wed, 18 Aug 2021 18:56:04 +0000 (20:56 +0200)]
EdDSA: parsing public key negate it right away

This saves 2 lines of code, without hurting readability.

4 years agoge_frombytes_vartime() does not parse (0, 1)
Loup Vaillant [Wed, 18 Aug 2021 18:54:01 +0000 (20:54 +0200)]
ge_frombytes_vartime() does not parse (0, 1)

But that's okay, because that point has low order.

4 years agoFixed MSVC warnings
Loup Vaillant [Tue, 20 Jul 2021 14:07:08 +0000 (16:07 +0200)]
Fixed MSVC warnings

Fixes #215

MSVC doesn't like when we expand unsigned integers after a bitwise
negation.  A fair distaste, except this time it's wrong. Writing
`(~x & 0xffffffff)` instead of just `~x` shows MSVC the error of its ways.

Also made a potentially lossy conversion to `int` explicit (and
explained in a comment why there is no actual loss).

4 years agoPoly1305: simplified input loading
Loup Vaillant [Sun, 18 Jul 2021 10:09:17 +0000 (12:09 +0200)]
Poly1305: simplified input loading

The trick is to parse the input bytes into words at the last moment.
This simplifies incremental loading, and saves around 10 lines of code.
The performance impact is barely measurable.

4 years agoBlake2b, Poly1305: fixed undefined behaviour
Loup Vaillant [Sun, 18 Jul 2021 07:48:19 +0000 (09:48 +0200)]
Blake2b, Poly1305: fixed undefined behaviour

Caugth by TIS-CI and the latest Clang's UBSan.
Incrementing a NULL pointer, even by a NULL offset, is not permitted.
This was caused by the removal of a conditional that exited early if the
message was empty.
The fix was to move the increment inside the alignment loop.

It may be tiny bit slower, but this was the slow path already.
Users can avoid it by aligning their increments to block boundaries.

4 years agoComments: typo & clarification
Loup Vaillant [Sat, 17 Jul 2021 23:39:50 +0000 (01:39 +0200)]
Comments: typo & clarification

4 years agoEdDSA: defined ge_msub() in terms of ge_madd()
Loup Vaillant [Sat, 17 Jul 2021 23:24:39 +0000 (01:24 +0200)]
EdDSA: defined ge_msub() in terms of ge_madd()

Previous changes caused ge_msub() to only be used for signature
verification (it was previously used for signature generation as well,
but this hurted readability).  It thus became reasonable to use
temporary buffers, since we no longer have to wipe them (at a sizeable
performance cost).

The trick is the same as how ge_sub() is defined in terms of ge_add().
This saves 9 lines of code, and the performance cost is negligible.

4 years agoEdDSA: Inlined fe_sq2()
Loup Vaillant [Sat, 17 Jul 2021 23:15:10 +0000 (01:15 +0200)]
EdDSA: Inlined fe_sq2()

This function was used only once and was one more function to worry
about with respect to carry propagation.
Plus, inlining it saves 4 lines.

4 years agoArgon2: Inlined g_copy(), g_xor(), and unary_g()
Loup Vaillant [Sat, 17 Jul 2021 23:05:41 +0000 (01:05 +0200)]
Argon2: Inlined g_copy(), g_xor(), and unary_g()

This saved 16 lines of code. It is not clear how readability is impacted
(the calling code is a bit more complex, but it is also more local).
Overall, I believe it's a win.

4 years agoStreamlined Blake2b
Loup Vaillant [Sat, 17 Jul 2021 22:22:49 +0000 (00:22 +0200)]
Streamlined Blake2b

- Moved   blake2b_incr() inside of blake2b_compress()
- Inlined blake2b_end_block()
- Inlined blake2b_update()

This removed some redundancy and saved 11 lines of code.

4 years agoInlined poly_clear_c() and poly_update()
Loup Vaillant [Sat, 17 Jul 2021 19:50:40 +0000 (21:50 +0200)]
Inlined poly_clear_c() and poly_update()

And gained quite a few lines of code in the process.
crypto_poly1305_update() may be a bit clearer as a result.

4 years agoRearranged Chacha20 initialisation
Loup Vaillant [Sat, 17 Jul 2021 19:10:40 +0000 (21:10 +0200)]
Rearranged Chacha20 initialisation

The init_key function was too short to justify itself.
It was used only twice, so I inlined it, and saved 2 SLoC.

This also had the effect of making the init code more systematic,
and I believe more readable as well.

4 years agoSimplified crypto_x25519_dirty_fast()
Loup Vaillant [Tue, 13 Jul 2021 22:19:56 +0000 (00:19 +0200)]
Simplified crypto_x25519_dirty_fast()

I noticed a pattern that I didn't exploit optimally.  The current code
is a bit simpler.

Also, I couldn't reverse engineer my own code, so I've expanded the
comments to explain the trick in more detail.

4 years agoAvoid wiping buffers in two places
Loup Vaillant [Sun, 27 Jun 2021 17:10:24 +0000 (19:10 +0200)]
Avoid wiping buffers in two places

4 years agoMore generic fe_frombytes()
Loup Vaillant [Sun, 27 Jun 2021 17:00:10 +0000 (19:00 +0200)]
More generic fe_frombytes()

This simplifies crypto_hidden_to_curve() a bit

4 years agoFactored out redundant squaring in Elligator
Loup Vaillant [Sun, 27 Jun 2021 16:29:28 +0000 (18:29 +0200)]
Factored out redundant squaring in Elligator

4 years agoMerge pull request #213 from fscoto/master+canonical-names
Loup Vaillant [Sun, 13 Jun 2021 19:49:39 +0000 (21:49 +0200)]
Merge pull request #213 from fscoto/master+canonical-names

Canonicalize spellings of algorithms

4 years agodoc: Use canonical spelling of BLAKE2(b)
Fabio Scotoni [Fri, 11 Jun 2021 18:37:46 +0000 (20:37 +0200)]
doc: Use canonical spelling of BLAKE2(b)

Spelling according to Jean-Philippe Aumasson, Samuel Neves, Zooko
Wilcox-O’Hearn, Christian Winnerlein. "BLAKE2: Simpler, Smaller, Fast as
MD5." ACNS 2013. Lecture Notes in Computer Science, vol 7954,
and also https://twitter.com/veorq/status/1396728032883322884

4 years agodoc: Use canonical spelling of ChaCha20
Fabio Scotoni [Fri, 11 Jun 2021 18:33:40 +0000 (20:33 +0200)]
doc: Use canonical spelling of ChaCha20

Spelled with two capital Cs according to Daniel J. Bernstein. "ChaCha,
a variant of Salsa20." Workshop Record of SASC 2008: The State of the
Art of Stream Ciphers.

4 years agoAdvertise public key cryptography in the manual
Loup Vaillant [Sun, 6 Jun 2021 21:47:11 +0000 (23:47 +0200)]
Advertise public key cryptography in the manual

Followup on the modifications of the README: if users can't make the
connection between public key cryptography and key exchange there, they
won't make it either when reading the manual (which by the way is
automatically copied to the website).

4 years agoFixed local variable shadowing
Loup Vaillant [Fri, 4 Jun 2021 21:51:20 +0000 (23:51 +0200)]
Fixed local variable shadowing

In crypto_x25519_inverse(), line 2949 and 2953, we use the ZERO macro in
a context where the enclosing scope already defines the varible `i`.

Turns out ZERO defines `i` for internal use in an enclosed scope. This
trigger a warning in some compilers about variable shadowing: declaring
a local variable with the same name as an enclosing local variable. This
warning is especially annoying when combined with -Werror.

To prevent this, the macros COPY and ZERO have been modified so they use
a variable name that is unlikely to be used anywhere else (`i__`).

4 years agoAdvertise Monocypher's features more clearly
Loup Vaillant [Fri, 4 Jun 2021 21:21:23 +0000 (23:21 +0200)]
Advertise Monocypher's features more clearly

For the second time, I've stumbled upon a user that believed Monocypher
did not support public key cryptography, despite the presence of a
fairly high-level key exchange API.

Looking at the README and website, I noticed that while key exchange is
fairly well publicised, "public key cryptography" is not.  I suspect
many users simply don't know that key exchange is a valid way to do
public key cryptography.  In hindsihght, we should not expected them to.

Let's not dwell on how many potential users we may have lost to this
oversight.  Hopefully, writing "Public key cryptography" directly will
help people notice.

4 years agoDefine fe_invert() in terms of invsqrt()
Loup Vaillant [Sat, 22 May 2021 13:30:02 +0000 (15:30 +0200)]
Define fe_invert() in terms of invsqrt()

Pros:
- The code is a couple lines shorter.
- Stack usage may be lowered a tiny little bit (we saved two temporary
  field elements).

Cons:
- Inversion is one field multiplication slower.

Note that fully optimised inversion can be 6 field multiplications
faster than the current version. It would cost quite a bit of code
though (we'd need a dedicated addition chain).

4 years agoMerge pull request #211 from fscoto/master+doc-incremental
Loup Vaillant [Tue, 25 May 2021 18:15:36 +0000 (20:15 +0200)]
Merge pull request #211 from fscoto/master+doc-incremental

doc: Compute secret/public key in some examples

4 years agoInstall advanced man pages
Loup Vaillant [Tue, 25 May 2021 18:11:47 +0000 (20:11 +0200)]
Install advanced man pages

Note that deprecated man pages are omitted.
I believe we should not clutter man pages with them.
Advanced functions however should have their place in the user manual.

4 years agoClarified wording in incremental signatures man page
Loup Vaillant [Tue, 25 May 2021 18:08:47 +0000 (20:08 +0200)]
Clarified wording in incremental signatures man page

Thanks Fabio for suggestions on this patch.
(Any error is still mine, though.)

4 years agodoc: Compute secret/public key in some examples
Fabio Scotoni [Tue, 25 May 2021 14:51:41 +0000 (16:51 +0200)]
doc: Compute secret/public key in some examples

crypto_sign_init_first_pass(3monocypher) gets two initializations of sk
and pk.
They're long-lived keys, but at least now it's possible to run the
example without wondering why nothing works.

4 years agoSimplified crypto_x25519_dirty_small() a tiny bit
Loup Vaillant [Sat, 22 May 2021 13:46:44 +0000 (15:46 +0200)]
Simplified crypto_x25519_dirty_small() a tiny bit

To give the same results as crypto_x25519_dirty_fast(), we originally
multiplied the cofactor by 5 before we multiplied it by L. I noticed
however that this multiplication by 5 could be baked in the base point
itself, and simplifies the computation a little bit.

This also saves a single MUL instruction.

4 years agoExpand Blake2b tests to full length keys and hashes
Loup Vaillant [Fri, 23 Apr 2021 12:08:46 +0000 (14:08 +0200)]
Expand Blake2b tests to full length keys and hashes

4 years agoTypo
Loup Vaillant [Sun, 18 Apr 2021 14:54:43 +0000 (16:54 +0200)]
Typo

4 years agoTest many combinations of input lengths for blake2b
Loup Vaillant [Sun, 18 Apr 2021 14:54:19 +0000 (16:54 +0200)]
Test many combinations of input lengths for blake2b

5 years agoUse official Blake2b test vectors
Loup Vaillant [Thu, 1 Apr 2021 09:19:58 +0000 (11:19 +0200)]
Use official Blake2b test vectors

Should have done this years ago. The test vectors we had were pretty
good, but the official ones are, well, official.

Note that we kept a good deal of our own vectors: while the official
test vectors tested all possible key sizes, they did not test all
possible hash sizes or all possible key sizes.

5 years agoAdded tests vectors for Blake2b
Loup Vaillant [Wed, 31 Mar 2021 19:42:13 +0000 (21:42 +0200)]
Added tests vectors for Blake2b

- We tested with no key, and an empty message.
- We tested with no key, and a non-empty message.
- We tested with a key, and a non-empty message.
- We did *not* test with a key and an empty message.

Well, now we do. Libsodium seems to agree with us. Phew.

5 years agoSpeed benchmark: fixed buffer overflow
Loup Vaillant [Fri, 5 Mar 2021 11:02:24 +0000 (12:02 +0100)]
Speed benchmark: fixed buffer overflow

5 years agoArgon2i: remove useless intermediate block
Loup Vaillant [Fri, 19 Feb 2021 13:33:58 +0000 (14:33 +0100)]
Argon2i: remove useless intermediate block

5 years agoTests suite: fixed C++ compatibility
Loup Vaillant [Sun, 27 Dec 2020 21:23:51 +0000 (22:23 +0100)]
Tests suite: fixed C++ compatibility

5 years agoUpdated CHANGELOG
Loup Vaillant [Sun, 27 Dec 2020 20:50:26 +0000 (21:50 +0100)]
Updated CHANGELOG

5 years agoMerge pull request #203 from fscoto/master+chacha20-doc
Loup Vaillant [Sun, 27 Dec 2020 13:55:09 +0000 (14:55 +0100)]
Merge pull request #203 from fscoto/master+chacha20-doc

crypto_ietf_chacha20: note nonce overflow handling

5 years agocrypto_ietf_chacha20: note nonce overflow handling
Fabio Scotoni [Sun, 27 Dec 2020 12:28:37 +0000 (13:28 +0100)]
crypto_ietf_chacha20: note nonce overflow handling

IETF ChaCha20 has a 32-bit counter.
This means a practical limit of 256 GiB of data for each nonce.
Additionally, IETF QUIC seems to require being able to handle
0xffffffff (I-D.draft-ietf-quic-tls-33 § 5.4.4),
thus getting very close to the overflow,
though not triggering it.

Unlike libsodium and other libraries, we do not have the option to
panic and take down whatever process is running the code and triggering
the overflow condition because Monocypher is neither allowed to use the C
standard library nor allowed to invoke undefined behavior to cause a
crash;
the applicable RFC provides no guidance what to do in this case, either.

Therefore, staying within the (nonce, counter) limits is necessarily
application responsibility;
it is an invariant that, when voided, Monocypher is allowed to do
anything,
similar to the non-guarantee we make for the crypto_blake2b family
and the crypto_argon2i family.

While already here, fix the wrong function prototype in the synopsis.

5 years agoDefined IETF Chacha20 in terms of DJB Chacha20
Loup Vaillant [Fri, 25 Dec 2020 22:50:06 +0000 (23:50 +0100)]
Defined IETF Chacha20 in terms of DJB Chacha20

- It's simpler.
- It makes clear that only the initialisation differ.
- It allows us to inline chacha20_core() and gain a few more lines.

5 years agoTests: fixed array size mismatch warning
Loup Vaillant [Tue, 22 Dec 2020 17:01:00 +0000 (18:01 +0100)]
Tests: fixed array size mismatch warning

5 years agoFix dead store
Loup Vaillant [Wed, 16 Dec 2020 08:33:47 +0000 (09:33 +0100)]
Fix dead store

Fixes #201

5 years agoRemoved spurious comment
Loup Vaillant [Sun, 6 Dec 2020 21:10:05 +0000 (22:10 +0100)]
Removed spurious comment

5 years agoRestricted TIS-CI to the most different platforms
Loup Vaillant [Fri, 4 Dec 2020 23:19:40 +0000 (00:19 +0100)]
Restricted TIS-CI to the most different platforms

We don't care about floating points & such, so we only need to select
a few platforms among all proposed.  This change cuts the number of
platforms by half.

5 years agoTweaked EdDSA signature pre-computed table
Loup Vaillant [Fri, 4 Dec 2020 22:21:02 +0000 (23:21 +0100)]
Tweaked EdDSA signature pre-computed table

Moved from a single 5-bit comb to a dual 4-bit comb.  The size of the
comb is unchanged, but we perform fewer operations.

Before:
- 50 doublings, 51 additions (101 operations)
- 51 16-way constant time lookups
After:
- 30 doublings, 62 additions (92 operations)
- 62 8-way constant time lookups

Note: I hoped for a 6% speedup, barely observed 3.5%. I suspect this is
because additions, even from pre-computed tables, cost a little more
than doublings.

Note: we could save an additional addition by assuming scalars modulo L
all fit in 252 bits.  They do not, but if we pick one at random, they
will in practice (with 2^-128 probability of being wrong, i.e. never).

This would work well in EdDSA, where the scalar is a hash of the private
key.  Finding a private key that makes the scalar overflow 252 bits is
about as hard as breaking a 128-bit key, which we can safely assume will
never happen by accident.

However, this scalar multiplication is also used in the dirty public key
generation, which we use to create hidden X25519 keys with Elligator
(from Edwards, because it's twice as fast as the Montgomery ladder).
Here, users provide the scalar directly. Overflowing 252 bits *can*
happen by accident, if users shoot themselves in the foot with a
non-random scalar.

The risk is small, but a measly 1% performance is not worth leaving
ourselves open to subtle corner cases like that.

5 years agoFaster reduction modulo L
Loup Vaillant [Sun, 29 Nov 2020 20:27:25 +0000 (21:27 +0100)]
Faster reduction modulo L

Replaced TweetNaCl's code by Barrett reduction.

- mod_l(), reduce(), and mul_add() use less stack.
- mod_l(), reduce(), and mul_add() are now much faster.
- Signature generation is noticeably faster (~7% on my Skylake laptop).
- Now I understand all the code. No more black boxes.

The change cost a total of 8 lines of code.

5 years agoAdded speed benchmark for ed25519-donna
Loup Vaillant [Wed, 25 Nov 2020 22:11:53 +0000 (23:11 +0100)]
Added speed benchmark for ed25519-donna

5 years agos/Monocypher/Libsodium in a string
Loup Vaillant [Wed, 25 Nov 2020 21:55:57 +0000 (22:55 +0100)]
s/Monocypher/Libsodium in a string

5 years agoUpdate CHANGELOG for next version
Loup Vaillant [Mon, 9 Nov 2020 22:57:06 +0000 (23:57 +0100)]
Update CHANGELOG for next version