]> git.codecow.com Git - Monocypher.git/log
Monocypher.git
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.

6 years agoProperly ommit lib directory from tarball
Loup Vaillant [Sat, 19 Oct 2019 11:20:41 +0000 (13:20 +0200)]
Properly ommit lib directory from tarball

6 years agoCosmetic nitpick
Loup Vaillant [Thu, 17 Oct 2019 21:34:16 +0000 (23:34 +0200)]
Cosmetic nitpick

6 years agoMerge pull request #128 from fscoto/master+remove-kex-doc
Loup Vaillant [Fri, 18 Oct 2019 14:44:53 +0000 (16:44 +0200)]
Merge pull request #128 from fscoto/master+remove-kex-doc

Clean up kex documentation removal

6 years agoClean up kex documentation removal
Fabio Scotoni [Fri, 18 Oct 2019 12:14:20 +0000 (14:14 +0200)]
Clean up kex documentation removal

Related to git commit 6163d8195a3acf2e143d20843a602fd5fb7671d5.

6 years agoTidied up sliding windows, minor cosmetic nitpicks
Loup Vaillant [Wed, 16 Oct 2019 22:14:11 +0000 (00:14 +0200)]
Tidied up sliding windows, minor cosmetic nitpicks

Added `static` to the sliding window functions, reworked those functions
a bit to improve the (internal) API.  Simplified the double scalarmult
accordingly.

Added FOR_T macro, for when the index should be a type other than
size_t.  Helped remove explicit conversions in Argon2i and sliding
windows.  Hopefully this new macro will be obvious to reviewers.  I
could have used the regular `for` loop, but it took too much horizontal
space in Argon2i (we use long names there).

6 years agoCorrected some spelling mistakes
Loup Vaillant [Mon, 14 Oct 2019 09:16:59 +0000 (11:16 +0200)]
Corrected some spelling mistakes

6 years agoStart sliding windows at bit 252
Loup Vaillant [Mon, 14 Oct 2019 08:55:12 +0000 (10:55 +0200)]
Start sliding windows at bit 252

When performing the double scalar multiplication, bit 253, 254, and 255
are guaranteed to be zero.  No need to check them, we can start from
252.

Also added a comment warning about a possible off-by-one error.

6 years agoUpdated AUTHORS.md for EdDSA
Loup Vaillant [Sun, 13 Oct 2019 23:06:43 +0000 (01:06 +0200)]
Updated AUTHORS.md for EdDSA

The EdDSA code is now unrecognisable from what we saw in either SUPERCOP
and TweetNaCl.  Some significant pieces are still from ref10 or
TweetNaCl, but the overall structure is different enough that I should
consider myself the primary author...

...and clearly take responsibility for this code.

6 years agocrypto_check saves 32 more bytes of stack
Loup Vaillant [Mon, 7 Oct 2019 14:21:37 +0000 (16:21 +0200)]
crypto_check saves 32 more bytes of stack

6 years agoCosmetic arg shuffling
Loup Vaillant [Mon, 7 Oct 2019 13:56:50 +0000 (15:56 +0200)]
Cosmetic arg shuffling

6 years agoSaved 32 more bytes
Loup Vaillant [Sun, 6 Oct 2019 23:18:43 +0000 (01:18 +0200)]
Saved 32 more bytes

Also took care of Clang warnings in the process

6 years agoFused sliding windows and scalar multiplication
Loup Vaillant [Sun, 6 Oct 2019 22:45:05 +0000 (00:45 +0200)]
Fused sliding windows and scalar multiplication

At last, we saved some stack. 320 bytes on my machine, which is a bit
disappointing. We may be able to shave off a couple more, but we're
reaching the limit.

6 years agoIncremental left to right sliding windows
Loup Vaillant [Sun, 6 Oct 2019 21:58:38 +0000 (23:58 +0200)]
Incremental left to right sliding windows

The main loop of the scalar multiplication goes one by one, so we can't
have the sliding loop skip indices.  By adding a context that keeps
track of the next needed addition (as well as its value), we'll be able
to fuse the two slides and the scalar multiplication together.

6 years agoSlide from left to right
Loup Vaillant [Sun, 6 Oct 2019 20:12:42 +0000 (22:12 +0200)]
Slide from left to right

Scalar multiplication goes from left to right (from MSB to
LSB). Computing the sliding windows used to go from *right to left*.

This direction mismatch forced us to keep all the signed digits in
memory, which currently incur a little over 500 bytes of stack overhead.
That overhead is avoidable. Avoiding it will allow Monocypher to fit in
smaller embedded devices.

Right now we just change the direction of the sliding. Interleaving will
come later.

6 years agoCosmetic
Loup Vaillant [Sat, 5 Oct 2019 00:03:35 +0000 (02:03 +0200)]
Cosmetic

6 years agoRemoved kex documentation
Loup Vaillant [Fri, 4 Oct 2019 21:15:03 +0000 (23:15 +0200)]
Removed kex documentation

It will be corrected and added later, once we integrate the latest Monokex.

6 years agoCorrected C++ warning
Loup Vaillant [Sun, 29 Sep 2019 19:40:23 +0000 (21:40 +0200)]
Corrected C++ warning

6 years agoRemoved obsolete Monokex
Loup Vaillant [Sun, 29 Sep 2019 19:23:16 +0000 (21:23 +0200)]
Removed obsolete Monokex

That attempt had a crappy API, and was possibly insecure. Monokex has
since evolved significantly.

It will come back later, once we are sure everything is ironed out. In
the mean time, Monokex will ship separately.

6 years agoMissing variable time comment
Loup Vaillant [Sun, 29 Sep 2019 18:23:24 +0000 (20:23 +0200)]
Missing variable time comment

6 years agoignore QtCreator IDE files
Loup Vaillant [Sat, 28 Sep 2019 09:34:20 +0000 (11:34 +0200)]
ignore QtCreator IDE files

Assuming the project is called 'monocypher'.

6 years agoCorrected clang warnings
Loup Vaillant [Sat, 28 Sep 2019 09:30:47 +0000 (11:30 +0200)]
Corrected clang warnings

Those are easily visible through the QtCreator IDE intellisense, but
somehow never showed up when compiling at the command line.  This should
help silence MSVC warnings as well.

6 years agoHoisted negations out of loops
Loup Vaillant [Mon, 29 Jul 2019 22:43:35 +0000 (00:43 +0200)]
Hoisted negations out of loops

Turns out compilers don't do this naturally, and this leads to
observable slow downs in some cases.

Also noted that we are relying on 2's complement representation (we
already were).  We could be more portable by going unsigned, but by this
logic the entire field arithmetic should go unsigned.  It's possible,
but it's not trivial.  I've kinda tried it in the past, and failed.

Every architecture of interest is 2's complement anyway, so I think this
will be good enough.

6 years agoMoved trim_scalar() and scalar_bits() up a slot
Loup Vaillant [Mon, 29 Jul 2019 22:30:22 +0000 (00:30 +0200)]
Moved trim_scalar() and scalar_bits() up a slot

Those functions are used for both X25519 and EdDSA. Moving them up one
section makes it easier for user to delete the X-25519 section without
affecting EdDSA.

(Overall, Monocypher should let users delete the code they don't
need. This wasn't an explicit goal initially, but the code naturally
turned out that way.  Supporting this use case cost us nothing.)

6 years agoCosmetic
Loup Vaillant [Mon, 29 Jul 2019 22:28:03 +0000 (00:28 +0200)]
Cosmetic

6 years agoSaved 40 bytes of stack for EdDSA signing
Loup Vaillant [Sun, 28 Jul 2019 11:40:01 +0000 (13:40 +0200)]
Saved 40 bytes of stack for EdDSA signing

6 years agoSave some more stack
Loup Vaillant [Thu, 25 Jul 2019 09:23:55 +0000 (11:23 +0200)]
Save some more stack

6 years agoAdded X25519 Whycheproof test vectors
Loup Vaillant [Thu, 25 Jul 2019 06:49:16 +0000 (08:49 +0200)]
Added X25519 Whycheproof test vectors

6 years agoMinor cleanups
Loup Vaillant [Thu, 27 Jun 2019 20:36:23 +0000 (22:36 +0200)]
Minor cleanups

Multiplications by powers of two are supposed to be shifts.
It was not clear how we were ignoring the MSB of curve25519 points.

6 years agoWorked around TIS interpreter volatile bug
Loup Vaillant [Thu, 30 May 2019 22:33:54 +0000 (00:33 +0200)]
Worked around TIS interpreter volatile bug

6 years agoCorrected wrong man page redirection
Loup Vaillant [Tue, 28 May 2019 13:19:44 +0000 (15:19 +0200)]
Corrected wrong man page redirection

6 years agoFixed TweetNaCl speed tests
Loup Vaillant [Mon, 13 May 2019 21:26:26 +0000 (23:26 +0200)]
Fixed TweetNaCl speed tests