38 Commits

Author SHA1 Message Date
Sebastian Falbesoner
5d89bc031b remove superfluous #ifdef VERIFY/#endif preprocessor conditions
Now that the `VERIFY_CHECK` compiles to empty in non-VERIFY mode, blocks
that only consist of these macros don't need surrounding `#ifdef VERIFY`
conditions anymore.

At some places intentional blank lines are inserted for grouping and
better readadbility.
2023-12-01 00:54:41 +01:00
Pieter Wuille
115fdc7232 Remove unused secp256k1_wnaf_const 2023-11-04 15:55:12 -04:00
Pieter Wuille
4d16e90111 Signed-digit based ecmult_const algorithm 2023-11-04 15:55:12 -04:00
Alejandro
b6b9834e8d small fixes
restoring wycheproof files

restoring wycheproof files2
2023-07-03 17:05:55 +02:00
Jonas Nick
ab5a917128
Merge bitcoin-core/secp256k1#1303: ct: Use more volatile
17fa21733aae97bf671fede3ce528c7a3b2f5f14 ct: Be cautious and use volatile trick in more "conditional" paths (Tim Ruffing)
5fb336f9ce7d287015ada5d1d6be35d63469c9a4 ct: Use volatile trick in scalar_cond_negate (Tim Ruffing)

Pull request description:

ACKs for top commit:
  sipa:
    ACK 17fa21733aae97bf671fede3ce528c7a3b2f5f14
  jonasnick:
    ACK 17fa21733aae97bf671fede3ce528c7a3b2f5f14

Tree-SHA512: 4a0fbee7b1cce4f4647bff697c0e645d93aa8fb49777feef5eb1e1eadce2116bafdcc6175c066ee4fe4bf1340047311e2d7d2c48bb288867a837ecd6c8687121
2023-05-11 16:14:44 +00:00
Tim Ruffing
17fa21733a ct: Be cautious and use volatile trick in more "conditional" paths
- secp256k1_scalar_cadd_bit
 - secp256k1_modinvXX_normalize_YY
 - secp256k1_modinvXX_divsteps_ZZ
 - ECMULT_CONST_TABLE_GET_GE

Even though those code loations are not problematic right now
(with current compilers).
2023-05-11 16:32:07 +02:00
Gregory Maxwell
a0e696fd4d Make secp256k1_ecmult_const handle infinity
Infinity isn't currently needed here, but correctly handling it is a
little more safe against future changes.

Update docs for it to make it clear that it is not constant time in A
(the input point). It never was constant time in Q (and would be a little
complicated to make constant time in A).

If it was later made constant time in A, infinity support would be easy
to preserve, e.g. by running it on a dummy value and cmoving infinity into
the output.
2023-05-10 09:06:02 -04:00
Pieter Wuille
a575339c02 Remove bits argument from secp256k1_wnaf_const (always 256) 2023-04-10 06:40:21 -04:00
Pieter Wuille
4485926ace Add x-only ecmult_const version for x=n/d 2023-04-08 15:24:36 -04:00
Russell O'Connor
e5c18892db Eliminate the prej array from ecmult_strauss_wnaf. 2022-01-19 11:51:42 -05:00
Peter Dettman
e82144edfb Fixup skew before global Z fixup 2021-12-26 14:56:51 +07:00
Peter Dettman
8c13a9bfe1 ECDH skews by 0 or 1 2021-12-26 14:56:51 +07:00
Peter Dettman
1515099433 Simpler and faster ecdh skew fixup 2021-12-26 14:56:51 +07:00
siv2r
05e049b73c ecmult: move _ecmult_odd_multiples_table_globalz_windowa
Changes:
    - move `secp256k1_ecmult_odd_multiples_table_globalz_windowa` function from ecmult to ecmult_const
    - remove outdated comment
2021-12-24 16:22:49 +05:30
Russell O'Connor
099bad945e Comment and check a parameter for inf in secp256k1_ecmult_const. 2021-12-03 13:57:38 -05:00
Dimitris Apostolou
07aa4c70ff
Fix insecure links 2020-12-18 00:24:22 +02:00
Pieter Wuille
4232e5b7da Rip out non-endomorphism code 2020-10-13 11:31:13 -07:00
Pieter Wuille
18d36327fd secp256k1_gej_double_nonzero supports infinity 2020-07-28 18:12:30 -07:00
Tim Ruffing
3e5cfc5c73
Merge #741: Remove unnecessary sign variable from wnaf_const
37dba329c6cb0f7a4228a11dc26aa3a342a3a5d0 Remove unnecessary sign variable from wnaf_const (Jonas Nick)
6bb0b77e158fc2f9e56e4b65b08bcb660d4c588b Fix test_constant_wnaf for -1 and add a test for it. (Jonas Nick)

Pull request description:

  There currently is a single branch in the `ecmul_const` function that is not being exercised by the tests. This branch is unreachable and therefore I'm suggesting to remove it.

  For your convenience the paper the wnaf algorithm can be found [here (The Width-w NAF Method Provides Small Memory and Fast Elliptic Scalar Multiplications Secure against Side Channel Attacks)](http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.563.1267&rep=rep1&type=pdf). Similarly, unless I'm missing something important, I don't see how their algorithm needs to consider `sign(u[i-1])` unless `d` can be negative - which doesn't make much sense to me either.

ACKs for top commit:
  real-or-random:
    ACK 37dba329c6cb0f7a4228a11dc26aa3a342a3a5d0 I verified the correctness of the change and claimed invariant by manual inspection. I tested the code, both with 32bit and 64bit scalars.

Tree-SHA512: 9db45f76bd881d00a81923b6d2ae1c3e0f49a82a5d55347f01e1ce4e924d9a3bf55483a0697f25039c327e33edca6796ba3205c068d9f2f99aa5d655e46b15be
2020-07-26 12:21:14 +02:00
Elichai Turkel
a39c2b09de
Fixed UB(arithmetics on uninit values) in cmovs 2020-05-22 13:25:26 +03:00
Jonas Nick
37dba329c6 Remove unnecessary sign variable from wnaf_const 2020-04-29 12:38:23 +00:00
f-daniel
4e284655d9
Fix typo in ecmult_const_impl.h
Fix small typo in the reference given for the wNAF method
2020-04-18 12:53:06 +02:00
Gregory Maxwell
d567b779fe Clarify comments about use of rzr on ge functions and abs function. 2020-01-11 00:54:52 +00:00
Gregory Maxwell
2241ae6d14 Remove secret-dependant non-constant time operation in ecmult_const.
ECMULT_CONST_TABLE_GET_GE was branching on its secret input.

Also makes secp256k1_gej_double_var implemented as a wrapper
 on secp256k1_gej_double_nonzero instead of the other way
 around.  This wasn't a constant time bug but it was fragile
 and could easily become one in the future if the double_var
 algorithm is changed.
2020-01-09 12:21:28 +00:00
Gregory Maxwell
5df77a0eda
Merge #533: Make sure we're not using an uninitialized variable in secp256k1_wnaf_const(...)
248f046 Make sure we're not using an uninitialized variable in secp256k1_wnaf_const(...) (practicalswift)

Pull request description:

  Make sure we're not using an uninitialized variable in `secp256k1_wnaf_const(...)`:

  ```
  In file included from src/secp256k1.c:15:0,
                   from src/tests.c:17:
  src/ecmult_const_impl.h: In function ‘secp256k1_wnaf_const’:
  src/ecmult_const_impl.h:117:20: warning: ‘u’ may be used uninitialized in this function [-Wmaybe-uninitialized]
       wnaf[word] = u * global_sign;
                      ^
  ```

  **Note to reviewers:** Perhaps an `assert(…);` is a bit drastic. What would be a more graceful way to handle this? :-)

Tree-SHA512: 536cd7cc5b87a84fbaac578cecbba81b8d82e4672a30a2db9a674b82856132e79b0158a6a88609bc24942ebdbf1fcd2c4399a4c31ab0654b88ace9c0e6f1eaf3
2019-05-22 04:44:29 +00:00
Tim Ruffing
8979ec0d9a Pass scalar by reference in secp256k1_wnaf_const()
After this change, no struct or union is passed by value in the
entire codebase. This makes it easier to compile the library with
CompCert.
2019-05-14 11:43:54 +02:00
practicalswift
248f046611 Make sure we're not using an uninitialized variable in secp256k1_wnaf_const(...) 2019-03-21 19:06:08 +01:00
Andrew Poelstra
7c1b91ba4b parameterize ecmult_const over input size 2018-04-05 21:05:13 +00:00
Jonas Nick
355a38f113 Add pippenger_wnaf ecmult_multi 2017-12-07 20:13:04 +00:00
Dan Raviv
abe2d3e84b Fix header guards using reserved identifiers
Identifiers starting with an underscore and followed immediately by a capital letter are reserved by the C++ standard.

The only header guards not fixed are those in the headers auto-generated from java.
2017-08-26 18:44:21 +03:00
Jonas Nick
768514bac0 Fix wnaf_const documentation with respect to return value and number of words set 2017-08-09 10:54:30 +02: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
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
Gregory Maxwell
cfe0ed916a Fix miscellaneous style nits that irritate overactive static analysis.
Also increase consistency with how overflow && zero is tested, and
 avoid some mixed declarations and code that GCC wasn't detecting.
2015-09-24 08:42:37 +00:00
Pieter Wuille
dd891e0ed5 Get rid of _t as it is POSIX reserved 2015-09-21 21:03:37 +02:00
Peter Dettman
72ae443afb Improve perf. of cmov-based table lookup 2015-08-01 10:57:36 -05:00
Andrew Poelstra
92e53fc4c8 Implement endomorphism optimization for secp256k1_ecmult_const 2015-08-01 10:57:36 -05:00
Andrew Poelstra
4401500060 Add constant-time multiply secp256k1_ecmult_const for ECDH
Designed with clear separation of the wNAF conversion, precomputation
and exponentiation (since the precomp at least we will probably want
to separate in the API for users who reuse points a lot.

Future work:
  - actually separate precomp in the API
  - do multiexp rather than single exponentiation
2015-07-31 12:39:09 -05:00