532 Commits

Author SHA1 Message Date
Andrew Poelstra
6f8ae2f3c0 ecdh: test NULL-checking of arguments
Boosts the ECDH module to 100% coverage
2016-11-26 20:17:14 +00:00
Andrew Poelstra
25e3cfbf9b ecdsa_impl: replace scalar if-checks with VERIFY_CHECKs in ecdsa_sig_sign
Whenever ecdsa_sig_sign is called, in the case that r == 0 or r overflows,
we want to retry with a different nonce rather than fail signing entirely.
Because of this, we always check the nonce conditions before calling
sig_sign, so these checks should always pass (and in particular, they
are inaccessible through the API and appear as uncovered code in test
coverage).
2016-11-26 20:14:19 +00:00
Andrew Poelstra
b4ceedf14f Add exhaustive test for verification 2016-11-26 00:35:02 +00:00
Andrew Poelstra
83836a9547 Add exhaustive tests for group arithmetic, signing, and ecmult on a small group
If you compile without ./configure --enable-exhaustive-tests=no,
this will create a binary ./exhaustive_tests which will execute
every function possible on a group of small order obtained by
moving to a twist of our curve and locating a generator of small
order.

Currently defaults to order 13, though by changing some #ifdefs
you can get a couple other ones. (Currently 199, which will take
forever to run, and 14, which won't work because it's composite.)

TODO exhaustive tests for the various modules
2016-11-26 00:35:00 +00:00
Andrew Poelstra
20b8877be1 Add exhaustive test for group functions on a low-order subgroup
We observe that when changing the b-value in the elliptic curve formula
`y^2 = x^3 + ax + b`, the group law is unchanged. Therefore our functions
for secp256k1 will be correct if and only if they are correct when applied
to the curve defined by `y^2 = x^3 + 4` defined over the same field. This
curve has a point P of order 199.

This commit adds a test which computes the subgroup generated by P and
exhaustively checks that addition of every pair of points gives the correct
result.

Unfortunately we cannot test const-time scalar multiplication by the same
mechanism. The reason is that these ecmult functions both compute a wNAF
representation of the scalar, and this representation is tied to the order
of the group.

Testing with the incomplete version of gej_add_ge (found in 5de4c5dff^)
shows that this detects the incompleteness when adding P - 106P, which
is exactly what we expected since 106 is a cube root of 1 mod 199.
2016-11-25 20:45:29 +00:00
Pieter Wuille
e06e878fd7 Remove Schnorr experiment 2016-11-17 18:55:06 -08:00
Pieter Wuille
04c8ef36ad
Merge #407: Modify parameter order of internal functions to match API parameter order
353c1bf Fix secp256k1_ge_set_table_gej_var parameter order (llamasoft)
541b783 Fix secp256k1_ge_set_all_gej_var parameter order (llamasoft)
7d893f4 Fix secp256k1_fe_inv_all_var parameter order (llamasoft)
2016-10-26 15:05:26 -07:00
Pieter Wuille
40c8d7e8bf
Merge #421: Update scalar_4x64_impl.h
9d67afa Update scalar_4x64_impl.h (Alex-GR)
2016-10-26 14:26:23 -07:00
bgorlick
37697832d6 Restructure nonce clearing
Make sure we clear the nonce data even if the nonce function fails (it may have written partial data), and call memset only once in the case we iterate to produce a valid signature.
2016-10-21 04:59:32 -07:00
bgorlick
0f9e69db55 Restructure nonce clearing
Make sure we clear the nonce data even if the nonce function fails (it may have written partial data), and call memset only once in the case we iterate to produce a valid signature.
2016-10-21 03:50:10 -07:00
Alex-GR
9d67afad96 Update scalar_4x64_impl.h
XOR reg,reg instead of MOV 0 to reg. It should be at least equal in all architectures and faster in some else.
2016-10-09 00:16:50 +03:00
Wladimir J. van der Laan
0bbd5d4025 Add string.h include to ecmult_impl
`memcpy` and `memset` are used, so include the appropriate header
for the declaration.
2016-08-04 12:58:29 +02:00
llamasoft
353c1bf0d7 Fix secp256k1_ge_set_table_gej_var parameter order
Rearranged secp256k1_ge_set_table_gej_var parameters so length comes last (it modifies both *a and *zr).
2016-07-26 14:24:45 -05:00
llamasoft
541b783920 Fix secp256k1_ge_set_all_gej_var parameter order
Rearranged secp256k1_ge_set_all_gej_var parameters so length comes after *a.
2016-07-26 14:24:42 -05:00
llamasoft
7d893f4980 Fix secp256k1_fe_inv_all_var parameter order
Rearranged secp256k1_fe_inv_all_var parameters so length is after array.
Text editor removed some trailing whitespaces.
2016-07-26 12:15:19 -05:00
Pieter Wuille
926836ad36 Make secp256k1_fe_sqrt constant time 2016-07-09 14:23:44 +02:00
Pieter Wuille
e2a8e92125
Merge #404: Replace 3M + 4S doubling formula with 2M + 5S one
8ec49d8 Add note about 2M + 5S doubling formula (Andrew Poelstra)
2016-07-07 17:06:49 +02:00
Andrew Poelstra
8ec49d8a5a Add note about 2M + 5S doubling formula 2016-07-07 15:04:36 +00:00
Andrew Poelstra
a6c6f994b5 Remove a bunch of unused stdlib #includes 2016-07-06 11:40:37 +00:00
Pieter Wuille
65285a63ee
Merge #403: configure: add flag to disable OpenSSL tests
a9b2a5d configure: add flag to disable OpenSSL tests (Andrew Poelstra)
2016-07-06 12:08:16 +02:00
Andrew Poelstra
a9b2a5d850 configure: add flag to disable OpenSSL tests
OpenSSL messes up valgrind.
2016-07-06 08:25:33 +00:00
Pieter Wuille
e6e9805fc4 Add function for testing quadratic residue field/group elements. 2016-07-04 13:55:04 +02:00
Peter Dettman
efd953a7a7 Add Jacobi symbol test via GMP
Also add native Jacobi symbol test (Andrew)

Rebased-by: Andrew Poelstra
Rebased-by: Pieter Wuille
2016-07-04 13:16:35 +02:00
Pieter Wuille
fa36a0ddb8
Merge #401: ecmult_const: unify endomorphism and non-endomorphism skew cases
c6191fd ecmult_const: unify endomorphism and non-endomorphism skew cases (Andrew Poelstra)
2016-06-30 15:52:21 +02:00
Andrew Poelstra
c6191fded8 ecmult_const: unify endomorphism and non-endomorphism skew cases
We now do a skew correction even without the endomorphism optimization,
which costs one additional group addition but unifies a lot of code.
2016-06-30 13:28:47 +00:00
Pieter Wuille
6042217d5d
Merge #384: JNI: align shared files copyright/comments to bitcoinj's
6ceea2c align shared files copyright/comments to bitcoinj's (GreenAddress)
2016-06-29 11:18:12 +02:00
Pieter Wuille
7b0fb18b75
Merge #366: ARM assembly implementation of field_10x26 inner (rebase of #173)
001f176 ARM assembly implementation of field_10x26 inner (Wladimir J. van der Laan)
2016-05-25 19:02:12 +02:00
Wladimir J. van der Laan
001f1763c7 ARM assembly implementation of field_10x26 inner
Rebased-by: Pieter Wuille <pieter.wuille@gmail.com>
2016-05-25 18:27:47 +02:00
Kirill Fomichev
3f8b78e5e9 Fix undefs in hash_impl.h 2016-05-21 10:18:57 +03:00
Kirill Fomichev
2ab46954cb Fix state size in sha256 struct 2016-05-21 10:17:06 +03:00
Pieter Wuille
6875b013e6
Merge #386: Add some missing VERIFY_CHECK(ctx != NULL)
bcc4881 Add some missing `VERIFY_CHECK(ctx != NULL)` for functions that use `ARG_CHECK` (Andrew Poelstra)
2016-05-08 20:02:45 +02:00
Pieter Wuille
2c52b5d244
Merge #389: Cast pointers through uintptr_t under JNI
47b9e78 Cast pointers through uintptr_t under JNI (Jon Griffiths)
2016-05-08 19:58:26 +02:00
Pieter Wuille
43097a44ef
Merge #390: Update bitcoin-core GitHub links
faa2a11 Update bitcoin-core GitHub links (MarcoFalke)
2016-05-08 19:56:34 +02:00
Pieter Wuille
31c9c12130
Merge #391: JNI: Only call ecdsa_verify if its inputs parsed correctly
a40c701 JNI: Only call ecdsa_verify if its inputs parsed correctly (Jon Griffiths)
2016-05-08 19:55:41 +02:00
Pieter Wuille
1cb2302cad
Merge #392: Add testcase which hits additional branch in secp256k1_scalar_sqr
093a497 Add testcase which hits additional branch in secp256k1_scalar_sqr (Jonas Nick)
2016-05-08 19:52:53 +02:00
Jonas Nick
093a497ac9 Add testcase which hits additional branch in secp256k1_scalar_sqr 2016-05-02 20:19:00 -07:00
Jon Griffiths
a40c701c83 JNI: Only call ecdsa_verify if its inputs parsed correctly
Return 0 otherwise instead of calling it with bad parameters.
2016-05-02 23:21:43 +12:00
MarcoFalke
faa2a11ce5 Update bitcoin-core GitHub links 2016-04-29 23:14:45 +02:00
Jon Griffiths
47b9e78e07 Cast pointers through uintptr_t under JNI
Fixes warnings of the form "warning: cast to pointer from integer of
different size" when building on 32 bit platforms. This is the same
approach used for pointer conversions in the openjdk sources.
2016-04-28 20:41:00 +12:00
Andrew Poelstra
f36f9c64bb bench_ecdh: fix call to secp256k1_context_create 2016-04-27 10:16:18 +00:00
Andrew Poelstra
bcc4881d3a Add some missing VERIFY_CHECK(ctx != NULL) for functions that use ARG_CHECK
The `ARG_CHECK` macro requires that a variable called `ctx` exist and be
non-NULL. However, in several functions that do not use the context variable,
we simply ignore it with `(void)ctx`. Replace these with explicit checks for
non-NULLness to avoid invalid memory accesses.
2016-04-26 15:49:02 +00:00
GreenAddress
6ceea2c527 align shared files copyright/comments to bitcoinj's 2016-03-27 16:21:34 +02:00
Pieter Wuille
bc7c93c6cd
Merge #374: Add note about y=0 being possible on one of the sextic twists
e72e93a Add note about y=0 being possible on one of the sextic twists (Andrew Poelstra)
2016-02-16 20:43:16 +01:00
GreenAddress
86e2d07e4c JNI library: cleanup, removed unimplemented code 2016-02-01 14:07:29 +01:00
GreenAddress
3093576aa4 JNI library
Squashed and rebased. Thanks to @theuni and @faizkhan00 for doing
the majority of work here! Also thanks to @btchip for help with debugging
and review.
2016-02-01 14:07:18 +01:00
Andrew Poelstra
e72e93ad9c Add note about y=0 being possible on one of the sextic twists 2016-01-10 08:35:59 +00:00
paveljanik
e5a904788e [Trivial] Remove double semicolons 2015-12-30 08:42:42 +01:00
Gregory Maxwell
5d4c5a31b9 Prevent damage_array in the signature test from going out of bounds. 2015-11-26 21:02:27 +00:00
Pieter Wuille
03d84a427f Benchmark against OpenSSL verification 2015-11-15 15:47:49 +01:00
Pieter Wuille
06aeea555e Turn secp256k1_ec_pubkey_serialize outlen to in/out 2015-11-05 06:01:56 +01:00