163 Commits

Author SHA1 Message Date
Pieter Wuille
23cfa914d2 Introduce secp256k1_pubkey_t type 2015-07-26 15:59:07 +02:00
Pieter Wuille
3e6f1e20dc Change rfc6979 implementation to be a generic PRNG 2015-07-24 22:07:14 +02:00
Pieter Wuille
4fb174df08
Merge pull request #263
99fd963 Add secp256k1_ec_pubkey_compress(), with test similar to the related decompress() function. (Thomas Kerin)
2015-07-13 20:55:34 -04:00
Peter Dettman
55399c23f7 Further performance improvements to _ecmult_wnaf
- Initialize 'wnaf' to zeroes using memset
- Add new 'len' arg to speed up smaller scalars (mostly for endo=yes)
2015-07-13 22:46:42 +10:00
Thomas Kerin
99fd963bd5
Add secp256k1_ec_pubkey_compress(), with test similar to the related decompress() function. 2015-07-13 13:09:00 +01:00
Peter Dettman
3f3964e49c Add specific VERIFY tests for _fe_cmov 2015-07-06 12:41:30 +09:30
Peter Dettman
a0601cd79c Fix VERIFY calculations in _fe_cmov methods 2015-07-04 13:50:15 +09:30
Pieter Wuille
765742021a
Add tests for adding P+Q with P.x!=Q.x and P.y=-Q.y 2015-06-29 08:22:06 -07:00
Andrew Poelstra
8c5d5f7b5b
tests: Add failing unit test for #257 (bad addition formula) 2015-06-29 08:22:06 -07:00
Andrew Poelstra
210ffed5cd Use separate in and out pointers in secp256k1_ec_pubkey_decompress
Right now `secp256k1_ec_pubkey_decompress` takes an in/out pointer to
a public key and replaces the input key with its decompressed variant.
This forces users who store compressed keys in small (<65 byte) fixed
size buffers (for example, the Rust bindings do this) to explicitly
and wastefully copy their key to a larger buffer.

[API BREAK]
2015-05-13 17:07:34 -05:00
Peter Dettman
2d5a186cee Apply effective-affine trick to precomp 2015-04-30 09:25:44 -07:00
Peter Dettman
4f9791abba Effective affine addition in EC multiplication
* Make secp256k1_gej_add_var and secp256k1_gej_double return the
  Z ratio to go from a.z to r.z.
* Use these Z ratios to speed up batch point conversion to affine
  coordinates, and to speed up batch conversion of points to a
  common Z coordinate.
* Add a point addition function that takes a point with a known
  Z inverse.
* Due to secp256k1's endomorphism, all additions in the EC
  multiplication code can work on affine coordinate (with an
  implicit common Z coordinate), correcting the Z coordinate of
  the result afterwards.

Refactoring by Pieter Wuille:
* Move more global-z logic into the group code.
* Separate code for computing the odd multiples from the code to bring it
  to either storage or globalz format.
* Rename functions.
* Make all addition operations return Z ratios, and test them.
* Make the zr table format compatible with future batch chaining
  (the first entry in zr becomes the ratio between the input and the
  first output).

Original idea and code by Peter Dettman.
2015-04-30 09:23:21 -07:00
Pieter Wuille
22f60a6280
Merge pull request #245
c146b4a Add bench_internal to gitignore. (Gregory Maxwell)
9c4fb23 Add a secp256k1_fe_cmov unit test. (Gregory Maxwell)
2015-04-22 12:55:08 -07:00
Gregory Maxwell
d2275795ff Add scalar blinding and a secp256k1_context_randomize() call.
This computes (n-b)G + bG with random value b, in place of nG in
 ecmult_gen() for signing.

This is intended to reduce exposure to potential power/EMI sidechannels
 during signing and pubkey generation by blinding the secret value with
 another value which is hopefully unknown to the attacker.

It may not be very helpful if the attacker is able to observe the setup
 or if even the scalar addition has an unacceptable leak, but it has low
 overhead in any case and the security should be purely additive on top
 of the existing defenses against sidechannels.
2015-04-22 19:25:16 +00:00
Gregory Maxwell
9c4fb23dd9 Add a secp256k1_fe_cmov unit test.
(Also add my name to the top of tests.c: I wrote a bunch of that
 and update the copyright dates)
2015-04-22 19:10:17 +00:00
Andrew Poelstra
5c2a4fad1c Fix memory leak in context unit test
Before fix, `valgrind ./tests 1` outputs
  ==21959==     in use at exit: 2,228,288 bytes in 8 blocks

after:
  ==23974==     in use at exit: 0 bytes in 0 blocks
2015-04-16 15:56:04 -05:00
Andrew Poelstra
d899b5b67c Expose ability to deep-copy a context 2015-04-11 22:16:03 -05:00
Pieter Wuille
a9b6595ef8 [API BREAK] Introduce explicit contexts 2015-04-11 01:01:10 -07:00
Gregory Maxwell
c01df1adc9 Avoid some implicit type conversions to make C++ compilers happy. 2015-03-28 02:20:36 +00:00
Gregory Maxwell
2632019713 Brace all the if/for/while.
Unbraced statements spanning multiple lines has been shown in many
 projects to contribute to the introduction of bugs and a failure
 to catch them in review, especially for maintenance on infrequently
 modified code.

Most, but not all, of the existing practice in the codebase were not
 cases that I would have expected to eventually result in bugs but
 applying it as a rule makes it easier for other people to safely
 contribute.

I'm not aware of any such evidence for the case with the statement
 on a single line, but some people strongly prefer to never do that
 and the opposite rule of "_always_ use a single line for single
 statement blocks" isn't a reasonable rule for formatting reasons.
 Might as well brace all these too, since that's more universally
 acceptable.

[In any case, I seem to have introduced the vast majority of the
 single-line form (as they're my preference where they fit).]

This also removes a broken test which is no longer needed.
2015-03-27 23:24:32 +00:00
Gregory Maxwell
efc571ceea Add simple testcases for signing with rfc6979 extra entropy. 2015-03-27 13:46:02 -07:00
Pieter Wuille
1573a102c0 Add ability to pass extra entropy to rfc6979
Suggested by Greg Maxwell.
2015-03-23 05:39:56 -07:00
Pieter Wuille
3b7ea633fb
Merge pull request #221
443cd4b Get rid of hex format and some binary conversions (Pieter Wuille)
2015-03-02 02:45:32 -08:00
Pieter Wuille
8956111802 use 128-bit hex seed 2015-02-23 07:32:37 -08:00
Pieter Wuille
443cd4b8ee Get rid of hex format and some binary conversions 2015-02-23 04:37:21 -08:00
Pieter Wuille
8030d7c0e5 Improve signing API documentation & specification 2015-02-14 15:38:27 -08:00
Gregory Maxwell
f735446c4d Convert the rest of the codebase to C89.
Update build system to enforce -std=c89 -pedantic.
2015-01-25 17:44:10 +00:00
Gregory Maxwell
bf2e1ac7cd Convert tests to C89. (also fixes a use of bare "inline" in field) 2015-01-25 15:47:04 +00:00
Pieter Wuille
fcc48c4561 Remove the non-storage cmov 2015-01-25 00:56:22 -04:00
Pieter Wuille
ff889f7d90 Field storage type 2015-01-25 00:11:20 -04:00
Pieter Wuille
0768bd55a1 Get rid of variable-length hex string conversions 2015-01-24 21:52:48 -04:00
Pieter Wuille
4732d26069 Convert the field/group/ecdsa constant initialization to static consts 2015-01-22 22:44:52 -05:00
Pieter Wuille
f1ebfe399f Convert the scalar constant initialization to static consts 2015-01-22 22:44:48 -05:00
Gregory Maxwell
941e221f66 Add tests for handling of the nonce function in signing. 2015-01-04 17:28:39 -08:00
Pieter Wuille
9ab93355f2 Add a reference consistency test to ge_tests.
This adds all points used in the test together in random order, which
should result in infinity.

Suggested by Greg Maxwell.
2014-12-29 17:21:39 +01:00
Pieter Wuille
60571c6e45 Rework group tests 2014-12-29 15:38:17 +01:00
Pieter Wuille
b450c34843
Merge pull request #163
bbd5ba7 Use rfc6979 as default nonce generation function (Pieter Wuille)
b37fbc2 Implement SHA256 / HMAC-SHA256 / RFC6979. (Pieter Wuille)
c6e7f4e [API BREAK] Use a nonce-generation function instead of a nonce (Pieter Wuille)
2014-12-23 14:40:47 +01:00
Pieter Wuille
d7174edf5f Weak normalization for secp256k1_fe_equal 2014-12-20 14:38:20 +01:00
Pieter Wuille
bbd5ba7cfa Use rfc6979 as default nonce generation function 2014-12-20 14:36:13 +01:00
Pieter Wuille
b37fbc280e Implement SHA256 / HMAC-SHA256 / RFC6979. 2014-12-20 14:36:13 +01:00
Pieter Wuille
c6e7f4e8d8 [API BREAK] Use a nonce-generation function instead of a nonce 2014-12-20 14:36:11 +01:00
Pieter Wuille
603c33bc80 Make signing fail if a too small buffer is passed.
Bug discovered by Sergio Demian Lerner.
2014-12-18 01:28:06 +01:00
Pieter Wuille
cf7b2b4647 Fix ECDSA message hashes to 32 bytes 2014-12-09 12:50:47 +01:00
Pieter Wuille
ee1eaa792d
Merge pull request #141
7c6fed2 Add a few more additional tests. (Gregory Maxwell)
8d11164 Add some additional tests. (Gregory Maxwell)
2014-12-09 01:38:01 +01:00
Gregory Maxwell
7c6fed2857 Add a few more additional tests. 2014-12-08 14:15:09 -08:00
Pavel Janík
e06a9244bf Include time.h header for time(). 2014-12-08 20:48:58 +01:00
Gregory Maxwell
8d11164bc0 Add some additional tests. 2014-12-08 09:13:35 -08:00
Pieter Wuille
6a9901e15b
Merge pull request #137
39bd94d Variable time normalize (Pieter Wuille)
2014-12-07 14:35:23 +01:00
Pieter Wuille
39bd94d86d Variable time normalize 2014-12-06 18:18:28 +01:00
Pieter Wuille
2b9388b647 Remove unused secp256k1_fe_inv_all 2014-12-05 18:13:51 +01:00