]> git.codecow.com Git - Monocypher.git/log
Monocypher.git
6 years agos/dangerous/dirty
Loup Vaillant [Tue, 24 Mar 2020 18:05:28 +0000 (19:05 +0100)]
s/dangerous/dirty

Those functions are not that dangerous, and such a scary word
would send the wrong message.  The manual though will make clear
this is not for everyone

6 years agoForgot to wipe buffers
Loup Vaillant [Tue, 24 Mar 2020 12:34:55 +0000 (13:34 +0100)]
Forgot to wipe buffers

6 years agoAdded dangerous X25519 speed benchmarks
Loup Vaillant [Tue, 24 Mar 2020 12:34:29 +0000 (13:34 +0100)]
Added dangerous X25519 speed benchmarks

6 years agoMerge pull request #161 from fscoto/master+new-doc
Loup Vaillant [Tue, 24 Mar 2020 07:54:06 +0000 (08:54 +0100)]
Merge pull request #161 from fscoto/master+new-doc

doc: contributory behavior may be required sometimes

6 years agodoc: contributory behavior may be required sometimes
Fabio Scotoni [Tue, 24 Mar 2020 07:41:48 +0000 (08:41 +0100)]
doc: contributory behavior may be required sometimes

While already there, hoist the explanation about contributory behavior
from RETURN VALUES to the main DESCRIPTION section.
The only reason it was in RETURN VALUES is because of historical
reasons; we used to justify why the return value was deprecated there,
so the position of the explanation made sense before removal of the
return value.

6 years agoRefined the Elligator interface
Loup Vaillant [Mon, 23 Mar 2020 19:46:43 +0000 (20:46 +0100)]
Refined the Elligator interface

Also added a new lightweight (but slower) path for embedded devices

6 years agoElligator script: alternate way to co-clear
Loup Vaillant [Mon, 23 Mar 2020 15:36:27 +0000 (16:36 +0100)]
Elligator script: alternate way to co-clear

6 years agoHave trim_scalar() copy its own buffer
Loup Vaillant [Mon, 23 Mar 2020 10:39:59 +0000 (11:39 +0100)]
Have trim_scalar() copy its own buffer

6 years agoCommented inverse square root
Loup Vaillant [Mon, 23 Mar 2020 10:32:53 +0000 (11:32 +0100)]
Commented inverse square root

6 years agoElligator script: simplified Montgomery ladder
Loup Vaillant [Sun, 22 Mar 2020 21:05:46 +0000 (22:05 +0100)]
Elligator script: simplified Montgomery ladder

6 years agoRenamed Elligator2 functions
Loup Vaillant [Sun, 22 Mar 2020 18:54:00 +0000 (19:54 +0100)]
Renamed Elligator2 functions

6 years agoSave more LOC with load/store routines
Loup Vaillant [Sun, 22 Mar 2020 18:38:07 +0000 (19:38 +0100)]
Save more LOC with load/store routines

6 years agoMore honest LOC count for scalarmult
Loup Vaillant [Sun, 22 Mar 2020 16:43:49 +0000 (17:43 +0100)]
More honest LOC count for scalarmult

6 years agoAdded ZERO helper to save some more lines
Loup Vaillant [Sun, 22 Mar 2020 16:27:35 +0000 (17:27 +0100)]
Added ZERO helper to save some more lines

6 years agoAdded COPY helper to save some LOC
Loup Vaillant [Sun, 22 Mar 2020 16:05:25 +0000 (17:05 +0100)]
Added COPY helper to save some LOC

Note: we generally copy bytes, maybe it could be a function...

6 years agoAdded scalar multiplication by inverse
Loup Vaillant [Sun, 22 Mar 2020 00:07:01 +0000 (01:07 +0100)]
Added scalar multiplication by inverse

6 years agoElligator script: added padding to test vectors
Loup Vaillant [Sat, 21 Mar 2020 12:18:48 +0000 (13:18 +0100)]
Elligator script: added padding to test vectors

So we properly test Monocypher ignores the padding

6 years agoElligator script: small refactor
Loup Vaillant [Sat, 21 Mar 2020 12:14:32 +0000 (13:14 +0100)]
Elligator script: small refactor

6 years agoAdded vectors from hash_to_curve RFC
Loup Vaillant [Sat, 21 Mar 2020 11:57:15 +0000 (12:57 +0100)]
Added vectors from hash_to_curve RFC

6 years agoElligator: take cofactor from secret key instead of tweak
Loup Vaillant [Wed, 18 Mar 2020 14:40:04 +0000 (15:40 +0100)]
Elligator: take cofactor from secret key instead of tweak

This allows the simplification of the implementation of higher level
interfaces.

The idea is, only the scalar and cofactor have any influence over
whether the inverse map succeeds or fail. This means that when it fails,
the padding & sign have not be used at all, and can be "reused" to
generate another random seed.

In practice, this means we can use Chacha20 or Blake2, or any hash that
outputs 64 random bytes from 32 random bytes, use 32 bytes to make an
attempt, then use the *other* 32 bytes to either generate more random
bytes (if we failed), or to use the tweak (if we succeed).

The tweak has also been modified to simplify the implementation. The
sign bit is now the least significant bit, and the padding bits are the
most significant bits. The computational savings are negligible, but
this allows neat micro-simplifications.

6 years agoAdded easy interface for Elligator
Loup Vaillant [Wed, 18 Mar 2020 11:27:31 +0000 (12:27 +0100)]
Added easy interface for Elligator

Note a small problem in the implementation: we are reusing one byte for
both the tweak and the next random seed.  This makes them *not*
independent, and a possible source of vulnerability.

In practice, this is only a problem for the 3 bits comprising the
cofactor, since the sign and the padding do not play a role in deciding
whether the mapping fails or succeeds.

TODO: take the cofactor from the clamped bits of the scalar, instead of
the tweak. This will ensure proper independence, while keeping the high
level code simple and maximally efficient.

6 years agoDon't try to re-generate test vectors upon release
Loup Vaillant [Tue, 17 Mar 2020 22:13:00 +0000 (23:13 +0100)]
Don't try to re-generate test vectors upon release

6 years agoIgnore the right release script
Loup Vaillant [Tue, 17 Mar 2020 22:12:14 +0000 (23:12 +0100)]
Ignore the right release script

6 years agoMinor bits & fixes
Loup Vaillant [Tue, 17 Mar 2020 07:40:37 +0000 (08:40 +0100)]
Minor bits & fixes

6 years agoCommented how clamping biases Elligator keys
Loup Vaillant [Mon, 16 Mar 2020 23:52:11 +0000 (00:52 +0100)]
Commented how clamping biases Elligator keys

6 years agoElligator/X25519 compatibility test
Loup Vaillant [Mon, 16 Mar 2020 22:42:16 +0000 (23:42 +0100)]
Elligator/X25519 compatibility test

6 years agoWhitespace nitpick
Loup Vaillant [Mon, 16 Mar 2020 22:41:31 +0000 (23:41 +0100)]
Whitespace nitpick

6 years agoElligator Script: fixed short test vectors
Loup Vaillant [Mon, 16 Mar 2020 21:01:15 +0000 (22:01 +0100)]
Elligator Script: fixed short test vectors

6 years agoOverlapping tests for Elligator2 (inverse)
Loup Vaillant [Mon, 16 Mar 2020 15:45:32 +0000 (16:45 +0100)]
Overlapping tests for Elligator2 (inverse)

6 years agoAdded Elligator2 inverse mapping
Loup Vaillant [Mon, 16 Mar 2020 12:13:06 +0000 (13:13 +0100)]
Added Elligator2 inverse mapping

6 years agoRemoved temporary to save some more stack
Loup Vaillant [Tue, 10 Mar 2020 07:18:05 +0000 (08:18 +0100)]
Removed temporary to save some more stack

6 years agoForgot to wipe a buffer
Loup Vaillant [Mon, 9 Mar 2020 23:05:53 +0000 (00:05 +0100)]
Forgot to wipe a buffer

6 years agoComment nitpick
Loup Vaillant [Mon, 9 Mar 2020 23:00:55 +0000 (00:00 +0100)]
Comment nitpick

6 years agoSeparated EdDSA parsing and negation
Loup Vaillant [Mon, 9 Mar 2020 22:54:39 +0000 (23:54 +0100)]
Separated EdDSA parsing and negation

The goal is to make the code easier to understand.  Merging parsing and
negation was clever, but it also was confusing.  Better not be clever.

The cost is 2 field negations. Arguably negligible.

6 years agoSimplified Edwards point parsing
Loup Vaillant [Mon, 9 Mar 2020 22:38:38 +0000 (23:38 +0100)]
Simplified Edwards point parsing

6 years agoElligator tests: overlapping I/O
Loup Vaillant [Mon, 9 Mar 2020 21:40:52 +0000 (22:40 +0100)]
Elligator tests: overlapping I/O

6 years agoElligator script: removed unused imports
Loup Vaillant [Mon, 9 Mar 2020 21:16:38 +0000 (22:16 +0100)]
Elligator script: removed unused imports

6 years agogit ignore __pycache__
Loup Vaillant [Mon, 9 Mar 2020 21:14:40 +0000 (22:14 +0100)]
git ignore __pycache__

6 years agoTypo, comment fe_isnegative()
Loup Vaillant [Mon, 9 Mar 2020 19:40:24 +0000 (20:40 +0100)]
Typo, comment fe_isnegative()

6 years agoElligator: fixed failure to ignore padding
Loup Vaillant [Mon, 9 Mar 2020 15:48:22 +0000 (16:48 +0100)]
Elligator: fixed failure to ignore padding

6 years agoAdded tests for Elligator direct mappings
Loup Vaillant [Mon, 9 Mar 2020 15:47:37 +0000 (16:47 +0100)]
Added tests for Elligator direct mappings

6 years agoFixed broken compilation
Loup Vaillant [Mon, 9 Mar 2020 15:09:53 +0000 (16:09 +0100)]
Fixed broken compilation

6 years agoElligator script: removed unnecessary temporary
Loup Vaillant [Mon, 9 Mar 2020 12:16:15 +0000 (13:16 +0100)]
Elligator script: removed unnecessary temporary

6 years agoAdded Elligator2 direct map
Loup Vaillant [Mon, 9 Mar 2020 11:33:39 +0000 (12:33 +0100)]
Added Elligator2 direct map

6 years agoMerge pull request #158 from fscoto/master+randombytes
Loup Vaillant [Mon, 2 Mar 2020 10:24:02 +0000 (11:24 +0100)]
Merge pull request #158 from fscoto/master+randombytes

Add random_bytes() to crypto_lock examples

6 years agocrypto_sign example: sign the *entire* message
Fabio Scotoni [Mon, 2 Mar 2020 08:53:09 +0000 (09:53 +0100)]
crypto_sign example: sign the *entire* message

6 years agoextract_examples.sh: warning cleanup
Fabio Scotoni [Mon, 2 Mar 2020 07:36:52 +0000 (08:36 +0100)]
extract_examples.sh: warning cleanup

1. Remove now-unused random_bytes().
2. "warning: empty struct has size 0 in C, size 1 in C++ [-Wc++-compat]"
   "warning: empty struct is a GNU extension [-Wgnu-empty-struct]"
   clang -Weverything

6 years agoMerge branch 'master' into master+randombytes
Fabio Scotoni [Mon, 2 Mar 2020 07:35:42 +0000 (08:35 +0100)]
Merge branch 'master' into master+randombytes

6 years agocrypto_sha512 example overhaul
Fabio Scotoni [Mon, 2 Mar 2020 07:33:38 +0000 (08:33 +0100)]
crypto_sha512 example overhaul

Just gives it a message to hash, matching crypto_blake2b(3monocypher).
Nothing to randomize.

6 years agocrypto_hmac_sha512 example overhaul
Fabio Scotoni [Mon, 2 Mar 2020 07:28:18 +0000 (08:28 +0100)]
crypto_hmac_sha512 example overhaul

1. Randomize the key.
2. Key for HMAC is NOT optional.
3. Give it an actual example message to authenticate.

6 years agocrypto_x25519 example overhaul
Fabio Scotoni [Mon, 2 Mar 2020 07:21:31 +0000 (08:21 +0100)]
crypto_x25519 example overhaul

Just adds arc4random_buf().

6 years agocrypto_sign example overhaul
Fabio Scotoni [Mon, 2 Mar 2020 07:15:29 +0000 (08:15 +0100)]
crypto_sign example overhaul

1. Randomize key.
2. Give it an actual example message to sign.

6 years agocrypto_poly1305 example overhaul
Fabio Scotoni [Mon, 2 Mar 2020 07:08:37 +0000 (08:08 +0100)]
crypto_poly1305 example overhaul

1. Randomize key.
2. Give it an actual example message to MAC.

6 years agocrypto_key_exchange example overhaul
Fabio Scotoni [Mon, 2 Mar 2020 07:03:20 +0000 (08:03 +0100)]
crypto_key_exchange example overhaul

Just adds arc4random_buf().

6 years agocrypto_hchacha20 example overhaul
Fabio Scotoni [Mon, 2 Mar 2020 07:00:58 +0000 (08:00 +0100)]
crypto_hchacha20 example overhaul

Just adds arc4random_buf() for the key.

6 years agocrypto_chacha20 example overhaul
Fabio Scotoni [Mon, 2 Mar 2020 06:57:22 +0000 (07:57 +0100)]
crypto_chacha20 example overhaul

1. Randomize keys and nonces.
2. Minor alignment fix in second example.
3. Make i unsigned to avoid clang warning about 500-(i-64) changing
   signedness with -Weverything.
4. Initialize ctr to 0.
5. Fix obviously wrong encryption by jumping around example
   (repeating ctr issue [!], wrong function used in the example).

6 years agocrypto_blake2b example overhaul
Fabio Scotoni [Mon, 2 Mar 2020 06:41:02 +0000 (07:41 +0100)]
crypto_blake2b example overhaul

1. A key when "Computing a message authentication code" is NOT optional.
2. Randomize keys.

6 years agocrypto_argon2i example overhaul
Fabio Scotoni [Mon, 2 Mar 2020 06:34:14 +0000 (07:34 +0100)]
crypto_argon2i example overhaul

1. The common type for a password is char*; use a cast instead.
   C11, para. 6.5(7) suggests this will be largely okay.
2. Wipe the password on failure.
3. Initialize the password size while there.
   Does not use strlen(3) to avoid extra stdlib functions.
4. Branch on allocation failure.

6 years agoElligator script: clean up & comments
Loup Vaillant [Sun, 1 Mar 2020 21:50:39 +0000 (22:50 +0100)]
Elligator script: clean up & comments

6 years agoAnother attempt at crypto_lock example overhaul
Fabio Scotoni [Sun, 1 Mar 2020 11:40:43 +0000 (12:40 +0100)]
Another attempt at crypto_lock example overhaul

6 years agoMerge pull request #160 from fscoto/master+test-typo
Loup Vaillant [Sun, 1 Mar 2020 10:46:34 +0000 (11:46 +0100)]
Merge pull request #160 from fscoto/master+test-typo

tests: fix typo in messages

6 years agotests: fix typo in messages
Fabio Scotoni [Sun, 1 Mar 2020 10:09:47 +0000 (11:09 +0100)]
tests: fix typo in messages

6 years agoMerge pull request #159 from richwalm/master
Loup Vaillant [Sat, 29 Feb 2020 23:32:49 +0000 (00:32 +0100)]
Merge pull request #159 from richwalm/master

Document & test overlapping of key_exchange.

6 years agoPerform a full overlapping range for test.
Richard Walmsley [Sat, 29 Feb 2020 21:53:35 +0000 (10:53 +1300)]
Perform a full overlapping range for test.

Also done the same for x25519 and included copyright details.

6 years agoDocument & test overlapping of key_exchange.
Richard Walmsley [Sat, 29 Feb 2020 10:48:51 +0000 (23:48 +1300)]
Document & test overlapping of key_exchange.

6 years agoElligator script: added paper URL
Loup Vaillant [Sat, 29 Feb 2020 10:33:45 +0000 (11:33 +0100)]
Elligator script: added paper URL

6 years agoAdd random_bytes() to crypto_lock examples
Fabio Scotoni [Sat, 29 Feb 2020 06:50:31 +0000 (07:50 +0100)]
Add random_bytes() to crypto_lock examples

6 years agoElligator script: comments & proofs
Loup Vaillant [Fri, 28 Feb 2020 23:18:58 +0000 (00:18 +0100)]
Elligator script: comments & proofs

6 years agoElligator script: general organisation
Loup Vaillant [Thu, 27 Feb 2020 23:40:23 +0000 (00:40 +0100)]
Elligator script: general organisation

6 years agoElligator script: removed slow scalarmult
Loup Vaillant [Thu, 27 Feb 2020 21:49:20 +0000 (22:49 +0100)]
Elligator script: removed slow scalarmult

6 years agoElligator script: clarified non-square
Loup Vaillant [Thu, 27 Feb 2020 21:43:58 +0000 (22:43 +0100)]
Elligator script: clarified non-square

6 years agoElligator Script: ackwowledge Andrew Moon's contribution
Loup Vaillant [Thu, 27 Feb 2020 19:58:22 +0000 (20:58 +0100)]
Elligator Script: ackwowledge Andrew Moon's contribution

6 years agoReplaced fast mappings by even better ones
Loup Vaillant [Wed, 26 Feb 2020 21:14:57 +0000 (22:14 +0100)]
Replaced fast mappings by even better ones

Turned out there were much simpler ways to compute the mapping, thanks
to the fact that when the prime p is congruent to 5 modulo 8, we have
this nice equality:

    x^((p-5)/8) = sqrt(1/x)          if x is square,
    x^((p-5)/8) = sqrt(sqrt(-1)/x)   otherwise

The code was kindly given by Andrew Moon, who got the original trick
from Mike Hamburg.

6 years agoMerge pull request #157 from fscoto/master+examples
Loup Vaillant [Wed, 26 Feb 2020 17:34:02 +0000 (18:34 +0100)]
Merge pull request #157 from fscoto/master+examples

Examples: const correctness

6 years agoExamples: const correctness
Fabio Scotoni [Tue, 25 Feb 2020 08:53:24 +0000 (09:53 +0100)]
Examples: const correctness

It's unfortunate that we can't both tell users to wipe keys and
illustrate which arguments are inputs and which ones are outputs
at the same time, but that's just how it is.

6 years agoElligator scritp: positive/negative cosmetic
Loup Vaillant [Tue, 25 Feb 2020 00:13:03 +0000 (01:13 +0100)]
Elligator scritp: positive/negative cosmetic

6 years agoElligator script: hoisted constant out
Loup Vaillant [Mon, 24 Feb 2020 00:06:12 +0000 (01:06 +0100)]
Elligator script: hoisted constant out

6 years agoElligator script: added explicit curve to hash
Loup Vaillant [Sun, 23 Feb 2020 23:39:41 +0000 (00:39 +0100)]
Elligator script: added explicit curve to hash

Now we can finally begin the C implementation, which should be a
straightforward transliteration of the Python code.

6 years agoMan page: fixed const in code example
Loup Vaillant [Sun, 23 Feb 2020 15:45:43 +0000 (16:45 +0100)]
Man page: fixed const in code example

6 years agoElligator script: whitespace nitpick
Loup Vaillant [Sun, 23 Feb 2020 14:52:00 +0000 (15:52 +0100)]
Elligator script: whitespace nitpick

6 years agoAdded Elligator to vector generation
Loup Vaillant [Sun, 23 Feb 2020 14:51:16 +0000 (15:51 +0100)]
Added Elligator to vector generation

6 years agovector_to_header now handles leading empty lines
Loup Vaillant [Sun, 23 Feb 2020 14:50:23 +0000 (15:50 +0100)]
vector_to_header now handles leading empty lines

6 years agoREADME.md: fixed test dir path
Loup Vaillant [Sun, 23 Feb 2020 14:32:50 +0000 (15:32 +0100)]
README.md: fixed test dir path

6 years agoElligator script: ordering nitpick
Loup Vaillant [Sun, 23 Feb 2020 14:23:42 +0000 (15:23 +0100)]
Elligator script: ordering nitpick

6 years agoElligator script: take vectors from stdin
Loup Vaillant [Sun, 23 Feb 2020 11:12:15 +0000 (12:12 +0100)]
Elligator script: take vectors from stdin

6 years agoElligator script: added fast_curve_to_hash
Loup Vaillant [Sun, 23 Feb 2020 11:05:32 +0000 (12:05 +0100)]
Elligator script: added fast_curve_to_hash

6 years agoElligator script: test explicit_hash_to_curve
Loup Vaillant [Sun, 23 Feb 2020 10:46:27 +0000 (11:46 +0100)]
Elligator script: test explicit_hash_to_curve

6 years agoElligator script: remove redundant test
Loup Vaillant [Sun, 23 Feb 2020 10:41:04 +0000 (11:41 +0100)]
Elligator script: remove redundant test

6 years agoElligator script: test fast_scalarbase
Loup Vaillant [Sun, 23 Feb 2020 10:37:46 +0000 (11:37 +0100)]
Elligator script: test fast_scalarbase

6 years agoElligator script: moved final tests
Loup Vaillant [Sun, 23 Feb 2020 10:29:05 +0000 (11:29 +0100)]
Elligator script: moved final tests

6 years agoElligator script: naming nitpick
Loup Vaillant [Sun, 23 Feb 2020 09:44:44 +0000 (10:44 +0100)]
Elligator script: naming nitpick

6 years agoElligator script: use x25519_pk test vectors
Loup Vaillant [Fri, 21 Feb 2020 22:17:29 +0000 (23:17 +0100)]
Elligator script: use x25519_pk test vectors

We're now reading the `x25519_pk.all.vec` generated by Libsodium in
`x25519.c`, to make sure scalarmult is correctly implemented in the
Python script.

While we're at it, we also use them to generate Elligator 2 vectors.
Any addition to the X25519 public key generation will automatically
benefit Elligator 2 as well

TODO: update the makefile to make sure the vectors are generated before
we run `elligator.py`

6 years agoElligator script: avoid redundant computaton
Loup Vaillant [Fri, 21 Feb 2020 21:07:55 +0000 (22:07 +0100)]
Elligator script: avoid redundant computaton

6 years agoElligator script: added fast_from_edwards
Loup Vaillant [Thu, 20 Feb 2020 23:21:21 +0000 (00:21 +0100)]
Elligator script: added fast_from_edwards

6 years agoElligator script: readability nitpick
Loup Vaillant [Thu, 20 Feb 2020 23:06:40 +0000 (00:06 +0100)]
Elligator script: readability nitpick

The can_curve_to_hash() test takes a Montgomery point as input, whose
coordinates are generally called (u, v), not (x, y).

6 years agoElligator script: removed erroneous .abs()
Loup Vaillant [Thu, 20 Feb 2020 23:00:44 +0000 (00:00 +0100)]
Elligator script: removed erroneous .abs()

Changing the sign of the v coordinate had an effect on the final value
of the final hash, but wasn't detected because my initial tests only
compare to the u coordinate, which appears to be correct.

This doesn't affect the success or failure of the Elligator mapping,
which only look at the u coordinate.  Yet another example of incorrect
crypto that looks like it works...

6 years agoElligator 2 script: fast scalarmult, explicit hash_to_curve
Loup Vaillant [Wed, 19 Feb 2020 22:51:12 +0000 (23:51 +0100)]
Elligator 2 script: fast scalarmult, explicit hash_to_curve

The fast scalar multiplication will let us explore the merging of the
various exponentiations required to perform the conversion to Montgomery
then curve_to_hash.

The explicit hash_to_curve() serves as an implementation guide.  Note
the omission of the v coordinate, not needed for X25519.  I am not
aware of a compelling use case to convert to Edwards (not all PAKEs need
point addition).

6 years agoAdded the fe (field element) type for readability
Loup Vaillant [Wed, 19 Feb 2020 20:30:47 +0000 (21:30 +0100)]
Added the fe (field element) type for readability

Having to write those modulo operators everywhere was tiresome. Having
an explicit field element type allows a more direct writing. It also
helps Python throw type errors if we misuse anything.

6 years agoPortability nitpick
Loup Vaillant [Tue, 18 Feb 2020 17:26:38 +0000 (18:26 +0100)]
Portability nitpick

6 years agoUse pow() for exponentiation in Python 3
Loup Vaillant [Tue, 18 Feb 2020 17:25:11 +0000 (18:25 +0100)]
Use pow() for exponentiation in Python 3

Much faster this way.