]> git.codecow.com Git - Monocypher.git/log
Monocypher.git
6 years agomakefile: Honor LDFLAGS variable if given
Fabio Scotoni [Thu, 12 Dec 2019 08:48:36 +0000 (09:48 +0100)]
makefile: Honor LDFLAGS variable if given

This allows specifying e.g. hardening options like -Wl,-z,relro
for link-time options.
It *is* normally possible to add these to CFLAGS,
but LDFLAGS is the established way to do this and tooling expects
it to work.
See also POSIX on make(1), whose default rules use LDFLAGS.

6 years agoMoved TweetNaCl to its own folder
Loup Vaillant [Wed, 11 Dec 2019 22:08:16 +0000 (23:08 +0100)]
Moved TweetNaCl to its own folder

6 years agoTweaked dist.sh
Loup Vaillant [Tue, 10 Dec 2019 20:37:42 +0000 (21:37 +0100)]
Tweaked dist.sh

6 years agoMerge pull request #139 from fscoto/master+new-man
Loup Vaillant [Tue, 10 Dec 2019 17:45:15 +0000 (18:45 +0100)]
Merge pull request #139 from fscoto/master+new-man

Miscellaneous documentation fixes

6 years agoDocumentation: bump date for custom hash man pages
Fabio Scotoni [Tue, 10 Dec 2019 10:37:47 +0000 (11:37 +0100)]
Documentation: bump date for custom hash man pages

6 years agoCHANGELOG: Use correct path for optional files
Fabio Scotoni [Tue, 10 Dec 2019 10:29:21 +0000 (11:29 +0100)]
CHANGELOG: Use correct path for optional files

6 years agoMake custom hash length requirements more explicit
Fabio Scotoni [Tue, 10 Dec 2019 10:21:39 +0000 (11:21 +0100)]
Make custom hash length requirements more explicit

Related to 0074dfab1.

Also note that vtable->final must actually write the hash,
not only finalize the context.

6 years agoDocumentation: Minor wording improvment for custom hash functions
Fabio Scotoni [Tue, 10 Dec 2019 10:15:00 +0000 (11:15 +0100)]
Documentation: Minor wording improvment for custom hash functions

6 years agoVersion 3.0.0 change log
Loup Vaillant [Mon, 9 Dec 2019 16:23:22 +0000 (17:23 +0100)]
Version 3.0.0 change log

6 years agoFixed c25519 speed benchmark
Loup Vaillant [Mon, 9 Dec 2019 16:09:56 +0000 (17:09 +0100)]
Fixed c25519 speed benchmark

6 years agoConsistent naming with 'make dist'
Loup Vaillant [Mon, 9 Dec 2019 16:07:14 +0000 (17:07 +0100)]
Consistent naming with 'make dist'

6 years agoCompleted test coverage
Loup Vaillant [Mon, 9 Dec 2019 13:14:21 +0000 (14:14 +0100)]
Completed test coverage

6 years agoAdded tests for IETF Chacha20
Loup Vaillant [Mon, 9 Dec 2019 10:49:34 +0000 (11:49 +0100)]
Added tests for IETF Chacha20

6 years agoFixed mistakenly ignored files
Loup Vaillant [Fri, 6 Dec 2019 18:12:15 +0000 (19:12 +0100)]
Fixed mistakenly ignored files

6 years agoMerge pull request #138 from fscoto/master+new-man
Loup Vaillant [Fri, 6 Dec 2019 18:01:32 +0000 (19:01 +0100)]
Merge pull request #138 from fscoto/master+new-man

Address man page review concerns

6 years agoDocumentation: complete SEE ALSO in intro(3monocypher)
Fabio Scotoni [Fri, 6 Dec 2019 07:32:47 +0000 (08:32 +0100)]
Documentation: complete SEE ALSO in intro(3monocypher)

This is supposed to be a complete and exhaustive list of
all documented functions,
as can be seen with all incremental functions being listed
separately, rather than only the "main" page that is symlinked to.

6 years agoDocumentation: Address Loup's review via GitHub PR #137
Fabio Scotoni [Fri, 6 Dec 2019 07:23:06 +0000 (08:23 +0100)]
Documentation: Address Loup's review via GitHub PR #137

- Fix typo in crypto_sign_init_first_pass_custom_hash(3monocypher)
- Wipe sk in crypto_sign_init_first_pass_custom_hash(3monocypher);
  while it is just a test program, it is arguably good form to do so
  in any case, especially in documentation code that people might be
  copying and pasting.
- Note that HMACs can be safely truncated.

6 years agoAdjust .In directives in optional/ for new prefix
Fabio Scotoni [Fri, 6 Dec 2019 07:14:10 +0000 (08:14 +0100)]
Adjust .In directives in optional/ for new prefix

6 years agoPrefixed optional files with "monocypher-"
Loup Vaillant [Thu, 5 Dec 2019 21:07:26 +0000 (22:07 +0100)]
Prefixed optional files with "monocypher-"

Monocypher is a "single file" library, with optional files. As a single
file library, it is best to occupy the global namespace directly. It's
only one include, no need for a folder.

The optional file kinda throw things off. We could put it in a
sub-folder, but we probably want both header to be at the same
place. And we certainly don't want to put monocypher.h itself in
sub-folder.

The solution is to have those files, none in a sub folder.

    monocypher.h
    monocypher.c
    monocypher-ed25519.h  (optional)
    monocypher-ed25519.c  (optional)

Namespace pollution is limited to a prefix.  Should be reasonable both
for projects that import those files directly, or for packaging in a
Linux or BSD distribution.

6 years agoMerge pull request #137 from fscoto/master+new-man
Loup Vaillant [Thu, 5 Dec 2019 18:38:25 +0000 (19:38 +0100)]
Merge pull request #137 from fscoto/master+new-man

Man page updates

6 years agointro: Be more accurate about constant-time multiplication
Fabio Scotoni [Thu, 5 Dec 2019 08:09:01 +0000 (09:09 +0100)]
intro: Be more accurate about constant-time multiplication

Information obtained via https://bearssl.org/cmul.html

Considering the interest in Monocypher on embedded platforms,
some ARM Cortex-M CPUs lacking constant-time multiplication needs
special emphasis.

6 years agointro: format link with .Lk
Fabio Scotoni [Thu, 5 Dec 2019 08:02:39 +0000 (09:02 +0100)]
intro: format link with .Lk

6 years agoDocumentation: Get rid of "we" for more neutral style
Fabio Scotoni [Thu, 5 Dec 2019 07:54:58 +0000 (08:54 +0100)]
Documentation: Get rid of "we" for more neutral style

6 years agoUpdate man pages for recent changes
Fabio Scotoni [Thu, 5 Dec 2019 07:31:25 +0000 (08:31 +0100)]
Update man pages for recent changes

Squashed commit of the following:

commit a7b2c919a76aab4b709dc4eb45f04234a8745ad1
Author: Fabio Scotoni <34964387+fscoto@users.noreply.github.com>
Date:   Thu Dec 5 08:25:33 2019 +0100

    Documentation: fix crypto_sha512 prototype

commit 7204c59458ce57f0967b42fe7998a411a097da55
Author: Fabio Scotoni <34964387+fscoto@users.noreply.github.com>
Date:   Thu Dec 5 08:23:10 2019 +0100

    Documentation: follow rename of HMAC functions

    crypto_hmac_* were renamed to crypto_hmac_sha512_* in 32525e92.

commit 2068f01e28cd2a5a4e2bc5ae4dd1a161e469f835
Author: Fabio Scotoni <34964387+fscoto@users.noreply.github.com>
Date:   Wed Dec 4 09:12:41 2019 +0100

    Adjust intro for new functions

commit 9cea43d2fa38b7249babe74f1c04066b4eaf90fa
Author: Fabio Scotoni <34964387+fscoto@users.noreply.github.com>
Date:   Wed Dec 4 09:00:34 2019 +0100

    Copy symbolic links as such

    cp -r copies symbolic links by dereferencing the link,
    essentially causing massive duplication of the man pages when installed.

    cp -PR copies the symlinks in place so that we have the contents on disk
    only once.

commit 19afe7d0f864acae143b0568956851dadddf2edc
Author: Fabio Scotoni <34964387+fscoto@users.noreply.github.com>
Date:   Wed Dec 4 08:47:43 2019 +0100

    Hook optional/ man pages to build

commit 668921527f186249dc8c54c87c0727b68ca30348
Author: Fabio Scotoni <34964387+fscoto@users.noreply.github.com>
Date:   Wed Dec 4 08:32:02 2019 +0100

    Remove mentions of context in Chacha20 documentation

    Contexts for Chacha20 as a whole were removed entirely.

commit e539f22ee036375a0ca7a3de4c84f30ba50d2738
Author: Fabio Scotoni <34964387+fscoto@users.noreply.github.com>
Date:   Wed Dec 4 08:30:26 2019 +0100

    Remove crypto_{mem,zero}cmp man pages

    These were deprecated in 2.0.0 already,
    which means they're due for removal now.

commit 8b04f0380dc0b7b8e81bcee86184c8b0100ca14a
Author: Fabio Scotoni <34964387+fscoto@users.noreply.github.com>
Date:   Tue Dec 3 11:41:24 2019 +0100

    Document custom hash EdDSA functions

commit 5663c8e1a5031eb7921e13cd9b717a924a6e458b
Author: Fabio Scotoni <34964387+fscoto@users.noreply.github.com>
Date:   Tue Dec 3 09:58:42 2019 +0100

    Document Ed25519 functions

commit 19478589d8afc1b1e782d33b9d6053ae89714f8b
Author: Fabio Scotoni <34964387+fscoto@users.noreply.github.com>
Date:   Tue Dec 3 09:31:14 2019 +0100

    Document HMAC functions

commit c75e9474a57d738141d64630ba6b7c28bf999f80
Author: Fabio Scotoni <34964387+fscoto@users.noreply.github.com>
Date:   Tue Dec 3 09:09:46 2019 +0100

    Document SHA-512 functions

commit 4fee40d5dfe7f65494a9ac43ac5ce114361063fa
Author: Fabio Scotoni <34964387+fscoto@users.noreply.github.com>
Date:   Mon Dec 2 11:13:29 2019 +0100

    Update Chacha20 documentation

6 years agoRenamed "crypto_hmac_*" to "crypto_hmac_sha512_*"
Loup Vaillant [Wed, 4 Dec 2019 18:24:59 +0000 (19:24 +0100)]
Renamed "crypto_hmac_*" to "crypto_hmac_sha512_*"

There are several types of HMAC, and users may want to use other
versions of HMAC as well. (For instance, they could code their own
Blake2b HMAC to implement Noise).  Plus, most primitives are named by
their technical name. "hmac" alone is not enough.

The names are longer, but this is the optional part, after all.

6 years agoFixed crypto_sha512 (and HMAC) prototypes
Loup Vaillant [Wed, 4 Dec 2019 18:18:06 +0000 (19:18 +0100)]
Fixed crypto_sha512 (and HMAC) prototypes

The output hash (and MAC) has a fixed size: 64 bytes.

6 years agoFixed unwiped buffer in SHA-512
Loup Vaillant [Tue, 3 Dec 2019 22:31:03 +0000 (23:31 +0100)]
Fixed unwiped buffer in SHA-512

6 years agoFixed buffer overflow in test vector generation
Loup Vaillant [Tue, 3 Dec 2019 18:49:27 +0000 (19:49 +0100)]
Fixed buffer overflow in test vector generation

6 years agoMoved SHA 512 work area to local stack
Loup Vaillant [Tue, 3 Dec 2019 07:52:01 +0000 (08:52 +0100)]
Moved SHA 512 work area to local stack

While some users could perhaps benefit from saving 640 bytes of stack
space by allocating the context statically, or in the heap, in practice
it's not he bottleneck.  Besides, putting the work area there actually
*increases* stack usage on signatures and signature verification, which
are the most stack hungry parts of Monocypher to begin with.

Better not try to be clever.

6 years agoProperty based tests for HMAC SHA-512
Loup Vaillant [Mon, 2 Dec 2019 23:06:45 +0000 (00:06 +0100)]
Property based tests for HMAC SHA-512

6 years agoFixed HMAC SHA-512 (and added tests)
Loup Vaillant [Mon, 2 Dec 2019 22:49:25 +0000 (23:49 +0100)]
Fixed HMAC SHA-512 (and added tests)

Test vectors were generated with Libsodium, with various key sizes (both
shorter and longer than the message), and every message size from 0 to
256 (twice the SHA 512 block size).

Also added Test vectors from RFC 4231, except the one with truncated
output (we don't support truncated outputs, users will have to do that
manually).

6 years agoAdded HMAC SHA512
Loup Vaillant [Sun, 1 Dec 2019 21:36:00 +0000 (22:36 +0100)]
Added HMAC SHA512

EXPERIMENTAL. MAY BE REMOVED.

Monocypher is supposed to be small.  This is why we use Blake2b for both
Argon2 and EdDSA signatures.  Some users however need Ed25519 for
compatibility with other tools.  This means using SHA 512.

We could hide SHA 512 from the public interface entirely, but this seems
like a waste: it could replace Blake2b to make the library smaller. It
will come at a performance loss, but when you verify signatures on a
small device, the hash is rarely the bottleneck.

The main problem with SHA 512 is length extension attacks.  It just
cannot be used as a prefix MAC like Blake2b can.  We need HMAC if we
want SHA 512 to entirely displace Blake2b, so the Monocypher binary
stays small.

Users could use Poly1305 and our version of RFC 8439 of course, but if
they're so tight on space, they're likely to get rid of Poly1305 as
well.  When we have SHA 512 already, HMAC requires much less code.

This is kind of a special corner case. But it could come in handy.

TODO: the tests.

6 years agoREADME typo
Loup Vaillant [Sun, 1 Dec 2019 19:36:11 +0000 (20:36 +0100)]
README typo

6 years agoFixed X25519 speed test
Loup Vaillant [Sun, 1 Dec 2019 19:35:10 +0000 (20:35 +0100)]
Fixed X25519 speed test

6 years agoRemoved deprecated X25519 return value
Loup Vaillant [Sun, 1 Dec 2019 17:27:01 +0000 (18:27 +0100)]
Removed deprecated X25519 return value

6 years agoAdded USE_ED25519 makefile option
Loup Vaillant [Sun, 1 Dec 2019 14:56:34 +0000 (15:56 +0100)]
Added USE_ED25519 makefile option

6 years agoRenamed crypto_sign_sha512_ctx into crypto_sign_ed25519_ctx
Loup Vaillant [Sun, 1 Dec 2019 13:29:16 +0000 (14:29 +0100)]
Renamed crypto_sign_sha512_ctx into crypto_sign_ed25519_ctx

Also renamed crypto_check_sha512_ctx into crypto_check_ed25519_ctx

This is for consistency with the naming of the functions themselves.

6 years agoRenamed crypto_hash_vtable into crypto_sign_vtable
Loup Vaillant [Sun, 1 Dec 2019 12:57:17 +0000 (13:57 +0100)]
Renamed crypto_hash_vtable into crypto_sign_vtable

The vtable holds hash functions, but it's really a vtable for
crypto_sign_ctx_abstract (and its check typedef). It's more tied to
EdDSA than to the hash itself.

6 years agoRemoved obsolete test-legacy include
Loup Vaillant [Sun, 1 Dec 2019 12:53:27 +0000 (13:53 +0100)]
Removed obsolete test-legacy include

6 years agoAdded aliases for Ed25519
Loup Vaillant [Sun, 1 Dec 2019 11:26:47 +0000 (12:26 +0100)]
Added aliases for Ed25519

6 years agoMarked the vtable as part of the public API
Loup Vaillant [Sun, 1 Dec 2019 11:18:27 +0000 (12:18 +0100)]
Marked the vtable as part of the public API

6 years agoRenamed crypto_sign_blake2b_ctx back to crypto_sign_ctx
Loup Vaillant [Sun, 1 Dec 2019 11:01:15 +0000 (12:01 +0100)]
Renamed crypto_sign_blake2b_ctx back to crypto_sign_ctx

Also renamed crypto_check_blake2b_ctx back to crypto_check_ctx.

This serves two purposes: avoid breaking the API when users upgrade from
Monocypher 2.x, and keep the idea that Blake2b is the default hash (the
default settings are implied and need not be named).

Note that although old code is not broken, it will still have warnings.
Those are easily silenced by casting to (void*).

6 years agoCosmetic (whitespace)
Loup Vaillant [Sun, 1 Dec 2019 11:01:07 +0000 (12:01 +0100)]
Cosmetic (whitespace)

6 years agoCosmetic (convert pointers directly)
Loup Vaillant [Sun, 1 Dec 2019 10:55:48 +0000 (11:55 +0100)]
Cosmetic (convert pointers directly)

6 years agoFixed undefined function pointer conversion
Loup Vaillant [Sun, 1 Dec 2019 10:42:30 +0000 (11:42 +0100)]
Fixed undefined function pointer conversion

The TIS interpreter is not happy when we call a function from an
incompatible pointer type.  GCC and Clang don't seem to mind as long as
we explicitly convert the pointer, but apparently that's undefined
behaviour, even though the only incompatibility is transforming a
pointer argument into a void* argument.

I don't know if it's a false positive, but better safe than sorry. The
conversion now uses explicit wrappers instead of a brutal type cast.

I've taken the opportunity to remove the offset. The wrappers now
perform the offset themselves, by accessing the member field the normal
way (after converting from void*, but that can't be avoided).

6 years agoFixed Clang warning
Loup Vaillant [Sun, 1 Dec 2019 09:33:01 +0000 (10:33 +0100)]
Fixed Clang warning

6 years agoFixed outdated include in speed.c
Loup Vaillant [Sat, 30 Nov 2019 23:36:12 +0000 (00:36 +0100)]
Fixed outdated include in speed.c

6 years agochacha20_*_ctr functions now return the new ctr
Loup Vaillant [Sat, 30 Nov 2019 23:08:08 +0000 (00:08 +0100)]
chacha20_*_ctr functions now return the new ctr

This should facilitate building piecemeal streams.  Normally you'd just
increment the nonce, but in some (admittedly rare) cases we may want to
increment the counter instead.

Incrementing the counter is fairly dangerous, because we may overlap the
streams, thus revealing the XOR of two pieces of plain text. Using the
new return value makes sure this doesn't happen.

6 years agoEnabled cohabitation of several EdDSA instances
Loup Vaillant [Sat, 30 Nov 2019 19:36:28 +0000 (20:36 +0100)]
Enabled cohabitation of several EdDSA instances

EdDSA can now use a custom hash! And that hash is not set in stone at
compile time, it can be decided at runtime!  It was done inheritance and
subtype polymorphism.  Don't worry, we are still using pure C.

Custom hashes are defined through vtables. The vtable contains function
pointers, an offset, and a size. (We need the size to wipe the context,
and the offset to find the location of the hash context inside the
signing context.)

An abstract signing context is defined. It is not instantiated
directly. It is instead the first member of the specialised signing
context.  The incremental interface takes pointers to abstract contexts,
but actually requires specialised contexts.

By default, we use the Blake2b specialised context. The incremental
interface doesn't change, except for the need to give it a specialised
context instead of the old crypto_sign_ctx. To enable the use of
different contexts, 3 "custom_hash" functions have been added:

    crypto_sign_public_key_custom_hash
    crypto_sign_init_first_pass_custom_hash
    crypto_check_init_custom_hash

They take a vtable as an additional parameter.

Ed25519 uses the custom hash interface to provide the following:

    crypto_ed25519_public_key
    crypto_ed25519_sign
    crypto_ed25519_check
    crypto_ed25519_sign_init_first_pass
    crypto_ed25519_check_init

To use them, we just have to add ed25519.h and ed25519.c to the project.

Note a slight orthogonality violation. The following work with any
specialised context:

    crypto_sign_update
    crypto_sign_final
    crypto_check_init
    crypto_check_update
    crypto_check_final

But the following requires a *Blake2b* signing context:

    crypto_sign_init_second_pass
    crypto_sign_init_first_pass

This lets us preserve the old function names (making it easier to update
user code), and maybe conveys that Blake2b remains the default hash.

---

Overall, I think we did pretty good: only 3 additional functions in the
main library (and a fourth exported symbol), and we spare the user the
pain of juggling with two contexts instead of just one. The only
drawback are slightly breaking compatibility in the incremental
interface, and requiring an explicit cast to avoid compiler warnings.

6 years agoMerge pull request #136 from fscoto/master+stdint
Loup Vaillant [Sat, 30 Nov 2019 10:34:56 +0000 (11:34 +0100)]
Merge pull request #136 from fscoto/master+stdint

Use stdint.h over inttypes.h

6 years agoUse stdint.h over inttypes.h
Fabio Scotoni [Sat, 30 Nov 2019 07:49:23 +0000 (08:49 +0100)]
Use stdint.h over inttypes.h

Monocypher uses nothing from inttypes.h, other than stdint.h that
inttypes.h indirectly includes.

This seems to make clang --target=wasm32 more amenable to Monocypher in
a freestanding environment.

6 years agoUpdated Wycheproof test vectors
Loup Vaillant [Thu, 28 Nov 2019 21:55:40 +0000 (22:55 +0100)]
Updated Wycheproof test vectors

6 years agoFixed buffer length in test.
Loup Vaillant [Mon, 25 Nov 2019 22:29:39 +0000 (23:29 +0100)]
Fixed buffer length in test.

The buffers tested for equality were too short.  Now we test the whole
of them.

Note: this may not be the only instance of this error.

6 years agoAdded Chacha20 consistency test
Loup Vaillant [Mon, 25 Nov 2019 22:26:45 +0000 (23:26 +0100)]
Added Chacha20 consistency test

I figured the equivalence between giving a stream of zeroes and a null
pointer was insufficiently tested. This is now fixed.

6 years agoSlightly better Chacha20 performance
Loup Vaillant [Mon, 25 Nov 2019 22:14:24 +0000 (23:14 +0100)]
Slightly better Chacha20 performance

6 years agoLocal functions should be static
Loup Vaillant [Mon, 25 Nov 2019 14:47:34 +0000 (15:47 +0100)]
Local functions should be static

6 years agoBumped soname (next release will break the ABI)
Loup Vaillant [Mon, 25 Nov 2019 14:43:34 +0000 (15:43 +0100)]
Bumped soname  (next release will break the ABI)

6 years agoAdded tests/utils.c to formal-analysis folder
Loup Vaillant [Mon, 25 Nov 2019 11:26:16 +0000 (12:26 +0100)]
Added tests/utils.c to formal-analysis folder

This should fix the TIS interpreter.

6 years agoFixed speed benchmark build
Loup Vaillant [Mon, 25 Nov 2019 11:19:10 +0000 (12:19 +0100)]
Fixed speed benchmark build

6 years agoSeparated legacy tests from regular tests
Loup Vaillant [Sun, 24 Nov 2019 21:39:42 +0000 (22:39 +0100)]
Separated legacy tests from regular tests

6 years agoFixed XChacha20 bug (wrong key)
Loup Vaillant [Sun, 24 Nov 2019 21:39:22 +0000 (22:39 +0100)]
Fixed XChacha20 bug (wrong key)

6 years agoRemoved legacy Chacha20 dependency from aead-incr
Loup Vaillant [Sun, 24 Nov 2019 21:04:05 +0000 (22:04 +0100)]
Removed legacy Chacha20 dependency from aead-incr

6 years agoRemoved AEAD streaming interface. BREAKS COMPATIBILITY
Loup Vaillant [Sun, 24 Nov 2019 20:35:33 +0000 (21:35 +0100)]
Removed AEAD streaming interface. BREAKS COMPATIBILITY

The streaming interface for AEAD was a bad idea: it's harder to test and
encourages unsafe protocol design (unsafe handling of unauthenticated
data, denial of service amplification...).

Its rightful place is the trash bin.

6 years agoPut common test utilities in its own module
Loup Vaillant [Sun, 24 Nov 2019 13:09:41 +0000 (14:09 +0100)]
Put common test utilities in its own module

This will help making separate test suite.

6 years agoNon-exported util functions should be static
Loup Vaillant [Sun, 24 Nov 2019 13:05:45 +0000 (14:05 +0100)]
Non-exported util functions should be static

6 years agoPut the soname in a variable for easier updates
Loup Vaillant [Thu, 21 Nov 2019 18:59:18 +0000 (19:59 +0100)]
Put the soname in a variable for easier updates

6 years agoMerge pull request #135 from fscoto/master+soname
Loup Vaillant [Thu, 21 Nov 2019 18:51:16 +0000 (19:51 +0100)]
Merge pull request #135 from fscoto/master+soname

Add SONAME to shared library

6 years agoAdd SONAME to shared library
Fabio Scotoni [Thu, 21 Nov 2019 18:43:58 +0000 (19:43 +0100)]
Add SONAME to shared library

6 years agoFixed Clang warnings
Loup Vaillant [Tue, 19 Nov 2019 23:05:26 +0000 (00:05 +0100)]
Fixed Clang warnings

Reverts 0073a9c8941a0e04a10035e7cc00ffddc8c0f083

Turns out the C99 standard guarantees a 2's complement representation
for fixed width integers: section 7.20.1.1, paragraph 1:

> The typedef name intN_t designates a signed integer type with width N,
> no padding bits, and a two's complement representation.

The comment was not needed though (those line are fully portable C99),
so I preserved its removal.

6 years agoMerge pull request #133 from michaelforney/2s-complement
Loup Vaillant [Tue, 19 Nov 2019 22:53:35 +0000 (23:53 +0100)]
Merge pull request #133 from michaelforney/2s-complement

Remove unnecessary dependency on 2's complement

6 years agoMerge pull request #134 from michaelforney/check-exit
Loup Vaillant [Tue, 19 Nov 2019 22:51:12 +0000 (23:51 +0100)]
Merge pull request #134 from michaelforney/check-exit

Fix makefile rule when test/vectors.h is missing

6 years agoFix makefile rule when test/vectors.h is missing
Michael Forney [Tue, 19 Nov 2019 20:41:02 +0000 (12:41 -0800)]
Fix makefile rule when test/vectors.h is missing

`return` only works in functions, so when I run `make check` with no
tests/vectors.h, I get

return 1
make: return: Command not found
make: *** [makefile:189: tests/vectors.h] Error 127

While I guess this does the job, the right thing to do here is `exit 1`.

6 years agoRemove unnecessary dependency on 2's complement
Michael Forney [Tue, 19 Nov 2019 20:15:16 +0000 (12:15 -0800)]
Remove unnecessary dependency on 2's complement

Although the bit-representation of signed integer types in C99 is
implementation-defined and can be sign-magnitude, one's complement, or
two's complement[0], the conversion of negative values to an unsigned
integer type is defined to be adding 1 plus the maximum value of the
unsigned type[1].

Since -1 + 0xffffffff + 1 == 0xffffffff, just using u32 here has the
right behavior without relying on the representation of signed integers.

[0] http://port70.net/~nsz/c/c99/n1256.html#6.2.6.2p2
[1] http://port70.net/~nsz/c/c99/n1256.html#6.3.1.3p2

6 years agoTypo: 2^255 - 23 => 2^255 - 21
Loup Vaillant [Tue, 19 Nov 2019 07:33:03 +0000 (08:33 +0100)]
Typo: 2^255 - 23 => 2^255 - 21

The previous commit message has the same mistake. Sorry.

6 years agoLeveraged fe_pow22523 to to simplify fe_invert
Loup Vaillant [Mon, 18 Nov 2019 21:41:41 +0000 (22:41 +0100)]
Leveraged fe_pow22523 to to simplify fe_invert

The multiplication chain used in those two function is probably optimal,
but it is also kind of black magic, and takes quite a bit of code.
TweetNaCl has a much shorter, much easier to read, much slower addition
chain. I figured maybe a middle ground were possible.

Turns out it's difficult. I couldn't come up with a nice multiplication
chain on my own. But I did notice a relationship between 2^252 - 3 and
2^255 - 23 (the latter is used to invert): they start with the same bit
pattern. More specifically:

    2^255 - 23 = (2^252 - 3) * 8 + 3

I can use the same multiplication chain for both function, and just
finish the job for the inversion.

The cost of this patch compared to the ref10 multiplication chain is
five field multiplications, three of which are squaring. The effect on
the benchmark is so small that we don't even notice the difference.

The benefit is 10 meaty lines of code, and a corresponding decrease in
binary size.

6 years agoAdded comment
Loup Vaillant [Sat, 2 Nov 2019 19:48:45 +0000 (20:48 +0100)]
Added comment

6 years agoUse TweetNaCl 20140427 without modification
Loup Vaillant [Sat, 2 Nov 2019 19:47:25 +0000 (20:47 +0100)]
Use TweetNaCl 20140427 without modification

6 years agoFixed uninitialised read in speed-c25519
Loup Vaillant [Tue, 29 Oct 2019 22:43:21 +0000 (23:43 +0100)]
Fixed uninitialised read in speed-c25519

6 years agoAdded c25519 speed benchmarks
Loup Vaillant [Mon, 28 Oct 2019 22:24:41 +0000 (23:24 +0100)]
Added c25519 speed benchmarks

6 years agoMoved libhydrogen pkg-config file to the makefile
Loup Vaillant [Fri, 25 Oct 2019 17:53:09 +0000 (19:53 +0200)]
Moved libhydrogen pkg-config file to the makefile

That's the simplest way I know of to respect the PREFIX variable.

6 years agoDocumented LibHydrogen speed benchmark
Loup Vaillant [Fri, 25 Oct 2019 17:42:14 +0000 (19:42 +0200)]
Documented LibHydrogen speed benchmark

6 years agoAdded Libhydrogen speed tests
Loup Vaillant [Wed, 23 Oct 2019 21:39:48 +0000 (23:39 +0200)]
Added Libhydrogen speed tests

6 years agoCosmetic: removed useless comment
Loup Vaillant [Wed, 23 Oct 2019 21:38:31 +0000 (23:38 +0200)]
Cosmetic: removed useless comment

6 years agoRemoved old (now unused) #define
Loup Vaillant [Wed, 23 Oct 2019 06:25:47 +0000 (08:25 +0200)]
Removed old (now unused) #define

6 years agoFixed Clang warning about Doxygen comments
Loup Vaillant [Tue, 22 Oct 2019 21:38:15 +0000 (23:38 +0200)]
Fixed Clang warning about Doxygen comments

comments that begin by //< can be Doxygen comments, and Clang with all
warnings doesn't like that.

I originally packed the comment to satisfy my 80 column OCD.  By
sacrificing space around the + operator however, we can reclaim that
space and please Clang.

6 years agoMerge pull request #131 from fscoto/master+remove-kex-doc
Loup Vaillant [Mon, 21 Oct 2019 18:23:14 +0000 (20:23 +0200)]
Merge pull request #131 from fscoto/master+remove-kex-doc

Remove remaining pieces of kex documentation

6 years agoMerge pull request #130 from fscoto/master+fix-release
Loup Vaillant [Mon, 21 Oct 2019 18:20:51 +0000 (20:20 +0200)]
Merge pull request #130 from fscoto/master+fix-release

Change release.sh to use find -exec

6 years agoRemove remaining pieces of kex documentation
Fabio Scotoni [Mon, 21 Oct 2019 17:49:38 +0000 (19:49 +0200)]
Remove remaining pieces of kex documentation

Related to git commits 6163d8195a3acf2e143d20843a602fd5fb7671d5 and
56b81ae4ec987ba39a2f0ec8b434a4f8efddfef9.

6 years agoChange release.sh to use find -exec
Fabio Scotoni [Mon, 21 Oct 2019 17:46:21 +0000 (19:46 +0200)]
Change release.sh to use find -exec

This avoids some potential weirdness with whitespace in find and for.

6 years agoNo longer overwrite __git__ -> $VERSION replacement
Loup Vaillant [Mon, 21 Oct 2019 15:53:32 +0000 (17:53 +0200)]
No longer overwrite __git__ ->  $VERSION replacement

The replacement was going fine, except for makefile.  This happened
because the new makefile was overwritten by the old (truncated).

Now we truncate in place.

6 years agoUpdated CHANGELOG (2.0.6)
Loup Vaillant [Mon, 21 Oct 2019 13:43:02 +0000 (15:43 +0200)]
Updated CHANGELOG (2.0.6)

6 years agoRemoved tests/vectors.h target from the tarballed makefile
Loup Vaillant [Mon, 21 Oct 2019 13:03:52 +0000 (15:03 +0200)]
Removed tests/vectors.h target from the tarballed makefile

The tests/vectors.h file ships with the tarball, we don't need to make
it a target.

6 years agoCleaned up the tests/ folder
Loup Vaillant [Mon, 21 Oct 2019 12:57:03 +0000 (14:57 +0200)]
Cleaned up the tests/ folder

Just moving files around so it's better organised.

Also changed the vectors.h header a little:
- It now includes inttypes.h and and stddef.h only once.
- There's a note at the top saying where it comes from.

6 years agoTightened up the release script
Loup Vaillant [Sat, 19 Oct 2019 23:01:43 +0000 (01:01 +0200)]
Tightened up the release script

- Run tests/test.sh prior to release
- Removed the dist target from the shipped makefile
- Removed the contributor notes from the shipped README
- Don't include files that only serve to generate vectors.h
- Reworded some of README a little bit.

6 years agoRevert "Added version number to binaries"
Loup Vaillant [Sat, 19 Oct 2019 15:54:36 +0000 (17:54 +0200)]
Revert "Added version number to binaries"

This reverts commit 30737a99843ac9f33698ea7e06afae1e7c6133df.

Exposing version numbers in the binary can expose them to attackers.
Without the version number, they have to try the exploit and hope.  With
the version number, they may perform a cheap check before they proceed
any further.  Better not take the risk.

Furthermore, changing the length of the string may break ABI.  This will
happen if a version number (major, minor, or patch) ever reaches 10.

That patch was nice, but it potentially impact security and stability.
Not worth it in the end.

6 years agoRemoved spurious space
Loup Vaillant [Sat, 19 Oct 2019 15:44:04 +0000 (17:44 +0200)]
Removed spurious space

6 years agoHandle several "__git__" per line
Loup Vaillant [Sat, 19 Oct 2019 15:40:45 +0000 (17:40 +0200)]
Handle several "__git__" per line

6 years agoAdded version number to binaries
Loup Vaillant [Sat, 19 Oct 2019 13:14:48 +0000 (15:14 +0200)]
Added version number to binaries

Sometimes, we don't have the sources, and we want to check the version
number of the binaries themselves. (For instance when distributing
Monocypher as a library.)

To that end, I've added the global string constant "monocypher_version".
It can be used from the calling program, or scanned directly by tools.

6 years agoREADME nitpick
Loup Vaillant [Sat, 19 Oct 2019 13:03:34 +0000 (15:03 +0200)]
README nitpick

6 years agoInclude version in released source files
Loup Vaillant [Sat, 19 Oct 2019 12:44:28 +0000 (14:44 +0200)]
Include version in released source files

I realised that determining which Monocypher version was used in a
project was not trivial. We could look at Monocypher's code and deduce
the release, but that's tedious and error prone. So I've made those
versions more explicit:

- Source and header files begin by a comment describing the version.
- The pkg-config file created by `make install` include that version.
- The version number of unreleased code (under git) is "__git__"
- The version number of released code is whatever `git describe --tags`
  tells us.
- the "tarball" target in the makefile was changed to the more standard
  "dist".

To release a new version, we just add a tag, then call `makefile dist`.
The version of the released source file will appear at a glance, right
there on the first line.

Note: the release process blindly replaces all instances of "__git__" by
the suitable version number.  This could be used to version things other
than comments, like string constants.