0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-02-18 11:57:37 -05:00
Commit graph

31 commits

Author SHA1 Message Date
Pieter Wuille
995c548771 Introduce callback functions for dealing with errors. 2015-07-26 18:08:38 +02:00
Pieter Wuille
3e6f1e20dc Change rfc6979 implementation to be a generic PRNG 2015-07-24 22:07:14 +02:00
Thomas Daede
fbecc38a89 Add ability to use a statically generated ecmult context.
This vastly shrinks the size of the context required for signing on devices with
memory-mapped Flash.

Tables are generated by the new gen_context tool into a header.
2015-07-13 18:00:03 -07: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
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
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
Pieter Wuille
a0d3b89dd6
Merge pull request #233
6534ee1 initialize variable (Cory Fields)
2015-04-10 01:20:35 -07:00
Gregory Maxwell
4450e24a82 Add a comment about the avoidance of secret data in array indexes.
People elsewhere still seem to be writing crypto code making this
 mistake, so it must not be that well known.
2015-04-06 03:53:32 +00:00
Cory Fields
6534ee1259 initialize variable 2015-04-03 17:16:09 -04: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
27bc1311af Silence some warnings from pedantic static analysis tools, improve compatibility with C++.
C doesn't include the null in an array initilized from a
string literal if it doesn't fit, in C++ this is invalid.

The vararray style prototypes and init+calc also changed in
 this commit are not C89 enough for some tools.
2015-03-08 09:12:03 +00: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
55422b6aaf Switch ecmult_gen to use storage types 2015-01-25 00:46:31 -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
0295f0a33d weak normalization 2014-12-20 14:38:07 +01:00
Pieter Wuille
6a9901e15b
Merge pull request #137
39bd94d Variable time normalize (Pieter Wuille)
2014-12-07 14:35:23 +01:00
Pieter Wuille
a5759c572e Check return value of malloc 2014-12-07 02:58:24 +01:00
Pieter Wuille
39bd94d86d Variable time normalize 2014-12-06 18:18:28 +01:00
Pieter Wuille
efb7d4b299 Use constant-time conditional moves instead of byte slicing 2014-12-03 02:41:55 +01:00
Pieter Wuille
d907ebc0e3 Add bounds checking to field element setters 2014-11-26 15:21:31 +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
65a14abb48 Fix varrious signed/unsigned comparisons. 2014-11-12 15:47:12 -08:00
Gregory Maxwell
e9e0e21a6f Avoid a shadowed variable. 2014-11-12 15:47:12 -08:00
Gregory Maxwell
a4a43d7543 Reorder static to comply with C99 and switch to the inline macro. 2014-11-12 13:07:55 -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
9338dbf791 Branch-free point addition 2014-11-11 14:28:22 -08:00
Pieter Wuille
da55986fdf Label variable-time functions correctly and don't use those in sign 2014-11-04 02:50:06 -08: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
949c1ebb5e Split up ecmult and ecmult_gen entirely 2014-10-26 03:42:24 -07:00