957 Commits

Author SHA1 Message Date
Marko Bencun
dabfea7e21
field: extend docstring of secp256k1_fe_normalize 2020-01-17 12:41:35 +01:00
Marko Bencun
dc7d8fd9e2
scalar: extend docstring of secp256k1_scalar_set_b32 2020-01-17 12:41:35 +01: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
Jonas Nick
642cd062bd Remove Java Native Interface 2020-01-08 09:13:09 +00:00
Tim Ruffing
d644dda5c9
Merge #689: Remove "except in benchmarks" exception for fp math
bde2a32286c697dd1056aa3eb1ea2a5353f0bede Convert bench.h to fixed-point math (Wladimir J. van der Laan)

Pull request description:

  Convert `bench.h` to fixed-point math, removing all use of float math from the repository:

  - Use 64-bit integer microsecond timestamps
  - Use decimal fixed-point math for formatting numbers

  It turned out to be a little trickier than I expected because of formatting and rounding. But, output should be the same before and after.

  I used the following to test the number formatting: https://gist.github.com/laanwj/f971bfbe018e39c19677a21ff954d0c7

ACKs for top commit:
  real-or-random:
    ACK bde2a32286c697dd1056aa3eb1ea2a5353f0bede I've read the code in detail and I've tested it. I haven't explicitly tested the formatting function with known/hardcoded inputs.

Tree-SHA512: 41ab6024b88c65a4b194272097c70d527bedb396dc7ab9d3d93165f1a19d31092798370f66399443a8d5393d0a6dcf5825679de5a325550865cfdef3586bf64c
2019-12-13 13:17:10 +01:00
Wladimir J. van der Laan
bde2a32286 Convert bench.h to fixed-point math
- Use 64-bit integer microsecond timestamps
- Use fixed-point math for formatting numbers

Then, remove "except in benchmarks" exception from `README.md`.
2019-12-13 11:23:39 +01:00
Elichai Turkel
47a7b8382f
Clear field elements when writing infinity 2019-12-10 18:10:18 +02:00
Elichai Turkel
61d1ecb028
Added test with additions resulting in infinity 2019-12-10 18:08:25 +02:00
Jonas Nick
a0771d15e6 Explicitly disable buffering for stderr in tests 2019-11-25 10:23:21 +00:00
Jonas Nick
fb424fbba2 Make travis show the ./tests seed by removing stdout buffering and always cat tests.log after a travis run. 2019-11-25 10:23:21 +00:00
Elichai Turkel
362bb25608
Modified bench_scalar_split so it won't get optimized out 2019-10-28 16:50:09 +02:00
Elichai Turkel
73a30c6b58
Added accumulators and checks on benchmarks so they won't get optimized out 2019-10-28 16:50:07 +02:00
Jonas Nick
b76142ff25 Remove note about heap allocation in secp256k1_ecmult_odd_multiples_table_storage_var which was removed in 47045270fa90f81205d989f7107769bce1e71c4d 2019-10-28 12:21:36 +00:00
Tim Ruffing
137d304a6b
Merge #647: Increase robustness against UB in secp256k1_scalar_cadd_bit
0d82732 Improve VERIFY_CHECK of overflow in secp256k1_scalar_cadd_bit. This added check ensures that any curve order overflow doesn't go undetected due a uint32_t overflow. (Russell O'Connor)
8fe63e5 Increase robustness against UB. Thanks to elichai2 who noted that the literal '1' is a signed integer, and that shifting a signed 32-bit integer by 31 bits causes an overflow and yields undefined behaviour. While 'scalar_low_impl''s 'secp256k1_scalar_cadd_bit' is only used for testing purposes and currently the 'bit' parameter is only 0 or 1, it is better to avoid undefined behaviour in case the used domain of 'secp256k1_scalar_cadd_bit' expands. (roconnor-blockstream)

Pull request description:

  Avoid possible, but unlikely undefined behaviour in `scalar_low_impl`'s `secp256k1_scalar_cadd_bit`.
  Thanks to elichai2 who noted that the literal `1` is a signed integer, and that shifting a signed 32-bit integer by 31 bits causes an overflow and yields undefined behaviour.

  Using the unsigned literal `1u` addresses the issue.

ACKs for commit 0d8273:
  real-or-random:
    ACK 0d82732a9a16cecc445e61c718ce9bdc2d228e76
  jonasnick:
    ACK 0d82732a9a16cecc445e61c718ce9bdc2d228e76

Tree-SHA512: 905be3b8b00aa5cc9bd6dabb543745119da8f34181d37765071f28abbc1d6ff3659e3f195b72c2f2d003006678823919668bc0d169ac8b8d4bcc5da671813c99
2019-10-28 11:55:00 +01:00
djb
dcb2e3b3ff
variable signing precompute table
make ECMULT_GEN_PREC_BITS configurable

ecmult_static_context.h: add compile time config assertion (#3) - Prevents accidentally using a file which was generated with a
different configuration.

README: mention valgrind issue

With --with-ecmult-gen-precision=8, valgrind needs a max stack size
adjustment to not run into a stack switching heuristic:

http://valgrind.org/docs/manual/manual-core.html

> -max-stackframe= [default: 2000000]
> The maximum size of a stack frame. If the stack pointer moves by more than this amount then Valgrind will assume that the program is switching to a different stack.
You may need to use this option if your program has large stack-allocated arrays.

basic-config: undef ECMULT_WINDOW_SIZE before (re-)defining it
2019-09-05 09:19:41 +02:00
Elichai Turkel
b64a2e2597
Fix a nit in the recovery tests 2019-08-21 10:07:22 -04:00
Jonas Nick
e028aa33d3
Merge #650: secp256k1/src/tests.c: Properly handle sscanf return value
a11c76c59a431e3492994f71a968a838e398fb58 secp256k1/src/tests.c:  Properly handle sscanf return value (Mustapha Abiola)

Pull request description:

  This pull request fixes a bug which allows the `sh` variable to be used uninitialised
  when sscanf(3) returns EOF.

  Signed-off-by: Mustapha Abiola <mustapha@trilemma.net>

ACKs for top commit:
  sipa:
    ACK a11c76c59a431e3492994f71a968a838e398fb58.
  practicalswift:
    utACK a11c76c59a431e3492994f71a968a838e398fb58
  real-or-random:
    ACK a11c76c59a431e3492994f71a968a838e398fb58 I looked at the code

Tree-SHA512: fd9660a18e39ecf9366db94ccbcec2682b020223f4f982a4356ddf56c2fbdafa5edcd830db37be12b661c1ec0b15c57b9f34ba59ef4460187c9c2478376fbc88
2019-08-18 22:51:22 +00:00
Tim Ruffing
f1e11d363d
Merge #654: Fix typo (∞)
271582b3b7aadf6dc00e7a5e88a251dcf15a6c1a Fix typo (practicalswift)

Pull request description:

  Fix ∞ typo :-)

ACKs for top commit:
  real-or-random:
    ACK 271582b3b7aadf6dc00e7a5e88a251dcf15a6c1a

Tree-SHA512: 41b8134e2572707d8a1ea1e5a79fffcc206b6093ec761ee1f93e4529506553c9cc8e3839b046210468f6c4c0d7af9d78a3e7e546bb0026656f1db1c793244296
2019-08-17 16:18:41 +02:00
Russell O'Connor
0d82732a9a Improve VERIFY_CHECK of overflow in secp256k1_scalar_cadd_bit.
This added check ensures that any curve order overflow doesn't go undetected due a uint32_t overflow.
2019-08-07 12:04:59 -04:00
Pieter Wuille
786dfb49f5
Merge #583: JNI: fix use sig array
74e2dbd JNI: fix use sig array (liuyujun)

Pull request description:

ACKs for commit 74e2db:
  sipa:
    ACK 74e2dbd68e07f752ac326a578e3071f9efa55e55. This is clearly an improvement.
  real-or-random:
    ACK 74e2dbd68e07f752ac326a578e3071f9efa55e55 I've read the code but haven't tested it

Tree-SHA512: 850b32e893463be4be28185dcc127d429afe4b6076036a078b7c61d590e0f4ea89127e448760b71c087cf70ffbefc52d87db77a5131bee81f3e4f95cfbd3bd3e
2019-08-06 15:33:10 -07:00
Pieter Wuille
e95f8ab098
Merge #644: Avoid optimizing out a verify_check
94ae7cb Moved a dereference so the null check will be before the dereferencing (Elichai Turkel)

Pull request description:

  Before that even on debug the compiler could've assumed `a` isn't null and optimized `VERIFY_CHECK(a != NULL);` out.
  This put the dereference after the check
  Resolves #643

ACKs for commit 94ae7c:
  sipa:
    ACK 94ae7cbf83a34456e5cad721f61ea77fcc023a3f

Tree-SHA512: 8b986f202ede5bde1f14a8ecf25e339d64ee6cd5cb391c5f18b4ff58f946c3845902d1230bc80d110a0a33b37025d281bd4532afbdf03b1c9ca321097374eb8e
2019-08-06 15:30:19 -07:00
Pieter Wuille
7b9b117230
Merge #640: scalar_impl.h: fix includes
2cb73b1 scalar_impl.h: fix includes (Marko Bencun)

Pull request description:

  group.h functions are not referenced.
  utils.h added as functions like VERIFY_CHECK are used.

ACKs for commit 2cb73b:
  sipa:
    ACK 2cb73b1064c796f5902189e0850066299e87aa93

Tree-SHA512: b9c7367061c2a22d2c9266c61261edd47798551b03b878ecd2e005d858701487145589793406cb4e88e85cd3c769007132efac9c228d5ee288e487e7d308e1c2
2019-08-06 15:02:00 -07:00
Tim Ruffing
2abcf951af
jni: Use only Guava for hex encoding and decoding
This removes a dependency on javax.xml.bind, which is no longer
available in JDK >= 11, see
https://openjdk.java.net/jeps/320#Java-EE-modules .
2019-08-05 17:09:54 +02:00
practicalswift
271582b3b7 Fix typo 2019-08-05 13:47:23 +00:00
Tim Ruffing
60f7f2de5d Don't assume that ALIGNMENT > 1 in tests 2019-07-30 15:54:31 +00:00
Jonas Nick
ada6361dec Use ROUND_TO_ALIGN in scratch_create 2019-07-30 15:54:31 +00:00
Jonas Nick
8ecc6ce50e Add check preventing rounding to alignment from wrapping around in scratch_alloc 2019-07-30 15:54:31 +00:00
Jonas Nick
4edaf06fb0 Add check preventing integer multiplication wrapping around in scratch_max_allocation 2019-07-30 15:54:31 +00:00
Mustapha Abiola
a11c76c59a secp256k1/src/tests.c: Properly handle sscanf return value
This pull request fixes a bug which allows the `sh` variable to be used uninitialized when sscanf returns EOF.

Signed-off-by: Mustapha Abiola <mustapha@trilemma.net>
2019-07-14 17:36:57 +02:00
roconnor-blockstream
8fe63e5654 Increase robustness against UB.
Thanks to elichai2 who noted that the literal '1' is a signed integer, and that shifting a signed 32-bit integer by 31 bits causes an overflow and yields undefined behaviour.
While 'scalar_low_impl''s 'secp256k1_scalar_cadd_bit' is only used for testing purposes and currently the 'bit' parameter is only 0 or 1, it is better to avoid undefined behaviour in case the used domain of 'secp256k1_scalar_cadd_bit' expands.
2019-07-04 22:35:28 -04:00
Elichai Turkel
94ae7cbf83
Moved a dereference so the null check will be before the dereferencing 2019-07-03 09:41:41 -04:00
Marko Bencun
2cb73b1064
scalar_impl.h: fix includes
group.h functions are not referenced.
utils.h added as functions like VERIFY_CHECK are used.
2019-06-20 17:33:47 +02:00
Gregory Maxwell
ee9e68cd30 Add a descriptive comment for secp256k1_ecmult_const. 2019-06-04 01:52:44 +00:00
Gregory Maxwell
e541a90ef6
Merge #629: Avoid calling _is_zero when _set_b32 fails.
cd473e0 Avoid calling secp256k1_*_is_zero when secp256k1_*_set_b32 fails. (Gregory Maxwell)

Pull request description:

  Most of the codebase correctly used short-cutting to avoid calling
   _is_zero on possibly incompletely initialized elements, but a few
   places were missed.

ACKs for commit cd473e:
  sipa:
    utACK cd473e02c372217c3a6608ce5afaa543ed78f891
  jonasnick:
    utACK cd473e02c372217c3a6608ce5afaa543ed78f891

Tree-SHA512: d6af2863f6795d2df26f2bd05a4e33085e88c45f7794601ea57e67238a2073ef1ee3ba0feab62a7fcbc0636c48dfd80eea07d0ca4f194414127f914b0478c732
2019-05-29 21:47:45 +00:00
Gregory Maxwell
1669bb2865
Merge #628: Fix ability to compile tests without -DVERIFY.
dcf3920 Fix ability to compile tests without -DVERIFY. (Gregory Maxwell)

Pull request description:

  Broken by 3f3964e4.

  It's important that the tests are also run without -DVERIFY due to
   the possibility that side-effects of a VERIFY_CHECK fix a bug that
   would otherwise be detected.

  Use of the verify_check macro in tests isn't sufficient.

ACKs for commit dcf392:

Tree-SHA512: ff7ca0e89e33f845656a4d7d18c0195d1378b020d67f89e900b18cf3d702aa81dd91ffd05a98953a481b83e4247eaf0c484bea12eab020efb3c966a456e8129f
2019-05-29 14:24:42 +00:00
Gregory Maxwell
ecc94abcc8
Merge #627: Guard memcmp in tests against mixed size inputs.
248bffb Guard memcmp in tests against mixed size inputs. (Gregory Maxwell)

Pull request description:

  Reported by real-or-random.

  Fixes #623.

ACKs for commit 248bff:
  practicalswift:
    utACK 248bffb0526ce8d829ce22f4d63d0d4a9ccfe137

Tree-SHA512: 29867c79d2d6852f495334a5a9129c7feac2df639dd7f752067380689b0ce9f9b35e94524834c01e698df5c0b83dc9855204ec09f5dfe488a388b509c9b861d9
2019-05-29 14:23:58 +00:00
Gregory Maxwell
544435fc90
Merge #578: Avoid implementation-defined and undefined behavior when dealing with sizes
14c7dbd Simplify control flow in DER parsing (Tim Ruffing)
ec8f20b Avoid out-of-bound pointers and integer overflows in size comparisons (Tim Ruffing)
01ee1b3 Parse DER-enconded length into a size_t instead of an int (Tim Ruffing)
3cb057f Fix possible integer overflow in DER parsing (Tim Ruffing)

Pull request description:

  This is a result of auditing the code for overflow issues at random places. None of this is critical but I think all of it should be fixed.

  I know this touches "red" code. I double-checked and triple-checked this but I can understand if some of the changes are not desirable because they change well-tested code.

  Best reviewed in individual commits.

ACKs for commit 14c7db:

Tree-SHA512: 312dd3f961739752e1a861e75bd755920f634f87ee9668793e102c224434e8d21367452e114de729322c71a89f4fa82126aa5d32742f2bbbc091777c99515e10
2019-05-29 11:06:19 +00:00
Tim Ruffing
e49f7991c2 Add missing #(un)defines to base-config.h 2019-05-26 22:32:36 +02:00
Tim Ruffing
77defd2c3b Add secp256k1_ prefix to default callback functions 2019-05-26 22:32:36 +02:00
Tim Ruffing
908bdce64e Include stdio.h and stdlib.h explicitly in secp256k1.c 2019-05-26 22:32:36 +02:00
Tim Ruffing
5db782e655 Allow usage of external default callbacks 2019-05-26 22:32:36 +02:00
Tim Ruffing
6095a863fa Replace CHECKs for no_precomp ctx by ARG_CHECKs without a return 2019-05-26 22:31:36 +02:00
Gregory Maxwell
cd473e02c3 Avoid calling secp256k1_*_is_zero when secp256k1_*_set_b32 fails.
Most of the codebase correctly used short-cutting to avoid calling
 _is_zero on possibly incompletely initialized elements, but a few
 places were missed.
2019-05-26 10:28:49 +00:00
Andrew Poelstra
98836b11f0 scratch: replace frames with "checkpoint" system 2019-05-26 01:05:09 +00:00
Andrew Poelstra
7623cf2b97 scratch: save a couple bytes of unnecessarily-allocated memory 2019-05-25 23:01:08 +00:00
Andrew Poelstra
a7a164f2c6 scratch: rename max_size to size, document that extra will actually be allocated 2019-05-25 23:01:07 +00:00
Andrew Poelstra
5a4bc0bb95 scratch: unify allocations 2019-05-25 22:59:51 +00:00
Andrew Poelstra
c2b028a281 scratch space: thread error_callback into all scratch space functions
Use it when checking magic bytes
2019-05-25 22:59:50 +00:00
Andrew Poelstra
0be1a4ae62 scratch: add magic bytes to beginning of structure 2019-05-25 22:55:39 +00:00