0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-02-21 12:22:50 -05:00
Commit graph

51 commits

Author SHA1 Message Date
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
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
Andrew Poelstra
93226a54b4 secp256k1.c: Add missing DEBUG_CHECKs for sufficiently capable contexts 2015-04-13 21:56:50 -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
Pieter Wuille
1573a102c0 Add ability to pass extra entropy to rfc6979
Suggested by Greg Maxwell.
2015-03-23 05:39:56 -07:00
Gregory Maxwell
0065a8fb9c Eliminate multiple-returns from secp256k1.c.
Goto, multiple returns, continue, and/or multiple breaks in a
 loop are often used to build complex or non-local control
 flow in software.

(They're all basically the same thing, and anyone axiomatically
 opposing goto and not the rest is probably cargo-culting from
 the title of Dijkstra's essay without thinking hard about it.)

Personally, I think the current use of these constructs in the
 code base is fine: no where are we using them to create control-
 flow that couldn't easily be described in plain English, which
 is hard to read or reason about, or which looks like a trap for
 future developers.

Some, however, prefer a more rules based approach to software
 quality.  In particular, MISRA forbids all of these constructs,
 and for good experience based reasons.  Rules also have the
 benefit of being machine checkable and surviving individual
 developers.

(To be fair-- MISRA also has a process for accommodating code that
 breaks the rules for good reason).

I think that in general we should also try to satisfy the rules-
 based measures of software quality, except where there is an
 objective reason not do: a measurable performance difference,
 logic that turns to spaghetti, etc.

Changing out all the multiple returns in secp256k1.c appears to
 be basically neutral:  Some parts become slightly less clear,
 some parts slightly more.
2015-03-08 16:36:29 -07:00
Gregory Maxwell
354ffa33e6 Make secp256k1_ec_pubkey_create reject oversized secrets. 2015-03-08 16:36:29 -07:00
Pieter Wuille
8030d7c0e5 Improve signing API documentation & specification 2015-02-14 15:38:27 -08:00
Iang
11690d3bb9 Removed gotos, which are hard to trace and maintain. 2015-02-12 18:18:31 -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
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
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
4285a98722 Move lambda-splitting code to scalar.
It's not really an operation on group elements.
2014-11-30 23:38:01 +01:00
Pieter Wuille
f24041d6aa Switch all EC/ECDSA logic from num to scalar 2014-11-30 23:38:01 +01:00
Pieter Wuille
bbe67d8b29 Make secp256k1_eckey_pubkey_serialize fail for infinity 2014-11-18 12:37:38 +01:00
Gregory Maxwell
71712b27e5 Switch to C89 comments in prep for making the whole codebase C89 compatible.
This should be whitespace/comment only changes and should produce the same
object code.
2014-11-15 07:33:07 -08:00
Gregory Maxwell
8563713a4f Add non-null and unused-result warnings for the external API.
GCC (and clang) supports extensions to annotate functions so that their
 results must be used and so that their arguments can't be statically
 provable to be null. If a caller violates these requirements they
 get a warning, so this helps them write correct code.

I deployed this in libopus a couple years ago with good success, and
 the implementation here is basically copied straight from that.

One consideration is that the non-null annotation teaches the optimizer
 and will actually compile out runtime non-nullness checks as dead-code.
 Since this is usually not whats wanted, the non-null annotations are
 disabled when compiling the library itself.

The commit also removes some dead inclusions of assert.h and introduces
 compatibility macros for restrict and inline in preparation for some
 portability improvements.
2014-11-12 12:23:09 -08:00
Pieter Wuille
501d58f098 Get rid of {num,scalar,ecdsa_sig}_{init,free} 2014-11-03 01:31:04 -08:00
Pieter Wuille
eca6cdb123 Switch scalar to use get/set 32-byte arrays 2014-10-29 00:40:56 -07:00
Pieter Wuille
a9f5c8b875 Introduce secp256k1_scalar_t for future constant-time mod order operations 2014-10-28 04:33:23 -07:00
Pieter Wuille
eb74c36bd2 Abstract out tweak logic to secp256k1_eckey_* functions 2014-10-27 03:27:55 -07:00
Pieter Wuille
ffffc87855 Use internal secp256k1_eckey_ prefix for functions in eckey 2014-10-27 03:01:51 -07:00
Pieter Wuille
e2f71f1efe Move non-ECDSA operations from ecdsa to eckey 2014-10-27 02:58:09 -07:00
Pieter Wuille
ae6bc76e32 [API CHANGE] Use secp256k1_ec_ prefix for non-ECDSA key operations 2014-10-27 02:51:58 -07:00
Pieter Wuille
949c1ebb5e Split up ecmult and ecmult_gen entirely 2014-10-26 03:42:24 -07:00
Pieter Wuille
04e34d18c3 Split up signing and verification initialization 2014-09-13 17:14:17 +02:00
Pieter Wuille
1c7fa133a6 Add VERIFY_CHECK/DEBUG_CHECK and use CHECK macros more 2014-08-26 01:23:51 +02:00
Gregory Maxwell
2f6c801911
Try to not leave secret data on the stack or heap.
This makes a basic effort and has not been audited.
Doesn't appear to have a measurable performance impact on bench.

It also adds a secp256k1_num_free to secp256k1_ecdsa_pubkey_create.
2014-08-14 07:06:36 -07:00
Pieter Wuille
0592d117da Introduce CHECK() for tests that works with NDEBUG. 2014-06-16 01:30:17 +02:00
William Swanson
ba8fc0e28f Check signature nonces for validity
The documentation implies that this check is happening, so make it so.
Without this check, passing an invalid nonce will trigger an internal assertion.
2014-04-24 14:18:44 -07:00
Pieter Wuille
11ab562203 Move implementations from impl/*.h to *_impl.h 2014-03-12 18:40:02 +01:00
Pieter Wuille
350ade2ab4 Tweak fixes & variable name improvement 2013-07-14 20:49:37 +02:00
Pieter Wuille
86d3cce2a9 Add support for multiplicative tweaking 2013-07-14 17:58:23 +02:00
Pieter Wuille
b0be6aba91 Invert buggy logic in secp256k1_ecdsa_seckey_verify 2013-07-13 01:31:41 +02:00
Pieter Wuille
561b0e1044 Private/public key tweaking 2013-05-27 01:18:48 +02:00
Pieter Wuille
0a433ea23c MIT License 2013-05-09 15:24:32 +02:00
Pieter Wuille
da3038c757 Privkey import/export 2013-05-05 05:12:43 +02:00
Pieter Wuille
50eb498ece Compact signatures/pubkey recovery 2013-05-05 02:46:07 +02:00
Pieter Wuille
764332d05d Make pubkeys, set_xo, ... ge instead of gej 2013-05-05 01:18:23 +02:00
Pieter Wuille
42cccdaf55 More public implementations 2013-05-05 01:02:05 +02:00
Pieter Wuille
7823916781 Add signing to public interface 2013-05-05 00:21:03 +02:00
Pieter Wuille
d06e61cbb5 Builtin random 2013-04-20 23:57:20 +02:00
Pieter Wuille
7a4b7691b6 Reorganize source tree: no .c for non-objects 2013-04-05 02:09:37 +02:00