Commit Graph

1174 Commits

Author SHA1 Message Date
Seonpyo Kim 069870d92a Clear a copied secret key after negation 2019-05-15 15:55:01 +09: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
Gregory Maxwell 84a808598b
Merge #612: Allow field_10x26_arm.s to compile for ARMv7 architecture
d4d270a Allow field_10x26_arm.s to compile for ARMv7 architecture (Roman Zeyde)

Pull request description:

  It would allow using optimized field operations on the TREZOR device, which is using ARMv7 Cortex-M4.
  Following https://github.com/trezor/trezor-core/pull/500 and part of https://github.com/trezor/trezor-firmware/issues/66.

Tree-SHA512: 73c0f03503feff01c6f4efd884e916ae1f43f55d525e8c3ea9372cf777aef6901585b74774c316dd7937abfff5e86be5b1acb569f9eeee9b73ae088f0f6b589d
2019-05-09 22:23:49 +00:00
Roman Zeyde d4d270a59c
Allow field_10x26_arm.s to compile for ARMv7 architecture 2019-05-07 22:37:35 +03:00
Gregory Maxwell b19c000063
Merge #607: Use size_t shifts when computing a size_t
e6d01e9 Use size_t shifts when computing a size_t (Pieter Wuille)

Pull request description:

  This was detected by compiling with MSVC; it triggers warning C4334.

  I don't think this is necessary, as we know the maximum shift is a very small integer, but this makes the code more obviously correct.

Tree-SHA512: 3c0cf412c75b4361d01e78bf13fe81c3f28b82abd40b0706285cc691124381cb1ff1f1c3512420250180b7612a471ce48357b282b1e34a08f5359e58af25e198
2019-03-31 09:37:33 +00:00
Gregory Maxwell 4d01bc2d9c
Merge #606: travis: Remove unused sudo:false
7667532 travis: Remove unused sudo:false (MarcoFalke)

Pull request description:

  Builds in sudo-disabled docker containers are no longer available as of last year and all builds happen on sudo enabled vms.

  Source: https://blog.travis-ci.com/2018-11-19-required-linux-infrastructure-migration#timeline---its-happening-fast

Tree-SHA512: 882585ba4e1596ad34ddf163acecd043da63443fa95653fba63b03dacf3a669128f1ed142527484cc8dab98de341b425425f418b8151cf7303b0e906ae259a9a
2019-03-31 00:41:54 +00:00
Pieter Wuille e6d01e9347 Use size_t shifts when computing a size_t 2019-03-30 16:09:17 -07:00
MarcoFalke 7667532bd7 travis: Remove unused sudo:false 2019-03-30 12:35:32 -04:00
practicalswift 248f046611 Make sure we're not using an uninitialized variable in secp256k1_wnaf_const(...) 2019-03-21 19:06:08 +01:00
Jonas Nick 9ab96f7b12 Use trivial algorithm in ecmult_multi if scratch space is small 2019-03-18 15:15:35 +00:00
Gregory Maxwell ee99f12f3d
Merge #599: Switch x86_64 asm to use "i" instead of "n" for immediate values.
d58bc93 Switch x86_64 asm to use "i" instead of "n" for immediate values. (Gregory Maxwell)

Pull request description:

  The constraint "n" is a more obscure setting which is needed for
   special cases that don't apply to our use.

  Use of "n" exposed some bugs in pre-release versions of clang.
  This fixes #594

Tree-SHA512: 1ffba02aa6bfcd0b6f731196e5d007f4ddb0f03f53b30a2633f0e376578cf7f828570579502f2de721dcda8034fd8e7bea822542bf36032d98ef802b4cf27725
2019-03-11 18:31:03 +00:00
Gregory Maxwell d58bc93f2c Switch x86_64 asm to use "i" instead of "n" for immediate values.
The constraint "n" is a more obscure setting which is needed for
 special cases that don't apply to our use.

Use of "n" exposed some bugs in pre-release versions of clang.
This fixes #594
2019-03-10 22:52:12 +00:00
Gregory Maxwell 05362ee042
Merge #597: Add $(COMMON_LIB) to exhaustive tests to fix ARM asm build
8348386 Add $(COMMON_LIB) to exhaustive tests to fix ARM asm build (Gregory Maxwell)

Pull request description:

Tree-SHA512: ef091b86189a2235710866689024f2b190ebcc5741667be0921e6b4a50d53ddf9a63f4c90b1509f25e46631d75338913143a2a1335a74c842f84b98739a9d306
2019-03-10 22:44:45 +00:00
Gregory Maxwell 83483869ac Add $(COMMON_LIB) to exhaustive tests to fix ARM asm build 2019-03-09 06:17:27 +00:00
Gregory Maxwell aa15154a48
Merge #568: Fix integer overflow in ecmult_multi_var when n is large
2277af5 Fix integer overflow in ecmult_multi_var when n is large (Jonas Nick)

Pull request description:

  Without this PR ecmult_multi could return wrong results. If the number of points `n` is large enough then some or all multiplications could be skipped or the function could end up in an infinite loop. This PR adds two checks to prevent `n` from wrapping around.

Tree-SHA512: 342944369b24776fa3ec0694eee159259ff67e94d2d8176c1d3159875f387d943d5bfdff7cde59f058e13f07fd09bde1cbc609426e63c8a5b8040e382dd865d8
2019-02-25 21:09:17 +00:00
Jonas Nick 2277af5ff0 Fix integer overflow in ecmult_multi_var when n is large 2019-02-25 16:13:17 +00:00
DesWurstes dbed75d969 Undefine `STATIC_PRECOMPUTATION` if using the basic config 2019-02-25 11:36:39 +03:00
DesWurstes 310111e093
Keep LDFLAGS if `--coverage` 2019-02-25 11:34:52 +03:00
Gregory Maxwell 85d0e1bcce
Merge #591: Make bench_internal obey secp256k1_fe_sqrt's contract wrt aliasing.
b76e45d Make bench_internal obey secp256k1_fe_sqrt's contract wrt aliasing. (Gregory Maxwell)

Pull request description:

  Bench_internal was previously incorrect but wasn't detected by -DVERIFY until PR #551.

Tree-SHA512: 5ecb9e3ba63ddf28cde4012154dbb1dda9b7178016d970dba58a4af20c31aa1ec3458ba2623541233fb16fceff7b3053054d6eee0229d0bfb6281d1a10554e9f
2019-02-24 19:20:54 +00:00
Gregory Maxwell 14196379ec
Merge #580: Add trivial ecmult_multi algorithm which does not require a scratch space
a697d82 Add trivial ecmult_multi to the benchmark tool (Jonas Nick)
bade617 Add trivial ecmult_multi algorithm. It is selected when no scratch space is given and just multiplies and adds the points. (Jonas Nick)

Pull request description:

  This commit adds a new ecmult_multi algorithm that is automatically selected when `ecmult_multi_var` is called with scratch space set to `NULL`. This is a trivial algorithm that simply multiplies the points with the corresponding scalars and adds them up.

  The use case is to allow creating exposed function that uses `ecmult_multi` but without requiring a scratch space argument. For example, in MuSig when computing the combined public key we need to compute a weighted sum of points but we most likely don't care about the performance. And if we do we can still provide a scratch space. Having the option of not providing a scratch space is useful because creating a scratch space is not entirely trivial. One needs to decide on a size and it needs to be destroyed.

Tree-SHA512: 2de20feeff00902ca0936ec1f8d81cf7a95d0917f80e76e9eacbd739c8c2e248fbdaeb468a0aeaf715ec251c2c79b5e271ff4d77456218d02332e26e003d796e
2019-02-24 03:06:54 +00:00
Jonas Nick a697d82da9 Add trivial ecmult_multi to the benchmark tool 2019-02-23 20:30:31 +00:00
Jonas Nick bade617417 Add trivial ecmult_multi algorithm. It is selected when no scratch space is given and just multiplies and adds the points. 2019-02-23 20:24:28 +00:00
Gregory Maxwell 5545e13dea
Merge #584: configure: Use CFLAGS_FOR_BUILD when checking native compiler
a34bcaa Actually pass CFLAGS_FOR_BUILD and LDFLAGS_FOR_BUILD to linker (Tim Ruffing)
2d5f4ce configure: Use CFLAGS_FOR_BUILD when checking native compiler (Tim Ruffing)

Pull request description:

  This fixes a bug where configure would fail or disable static
  ecmult tables because it wrongly checks the native compiler using
  the target CFLAGS (instead of the native CFLAGS_FOR_BUILD).

  Moreover, this commit adds tests to figure out whether the native
  compiler supports the warning flags passed during the build, and it
  contains a few minor improvements to the code that checks the native
  compiler.

Tree-SHA512: 31a92a5516cf2f9801c918edfba0059aa4f8549b0c1de94fc166b5e92ad1868a480c48cdc5ff62679ba20e26f4a0e2948c71fd2b3e80766673d2bf7512da3875
2019-02-22 01:29:02 +00:00
Gregory Maxwell 20c5869df2
Merge #516: improvements to random seed in src/tests.c
be40c4d Fixup for C90 mixed declarations. (Gregory Maxwell)
8b3841c fix bug in fread() failure check (Don Viszneki)
cddef0c tests: add warning message when /dev/urandom fails (Don Viszneki)

Pull request description:

  I've made two small changes to `src/tests.c` circa random seed generation.

  Added a warning when `/dev/urandom` fails, mostly to defend against the case that someone should use the code verbatim, but also to enhance its illustrative power.

  Also I fixed a bug with how the return value of `fread()` was being evaluated. In fact, `/dev/urandom` was never being applied before as the check on the return value of `fread()` always failed!

Tree-SHA512: 239dbe8316220c2f0e5b370bf9a18f78196e96cc4a7edea58cf2521b2c9cbc8da065be96aa859f90324d57e388d30f7670ce6bc1cca52e5162e5ca66b1a55b34
2019-02-21 11:46:13 +00:00
Gregory Maxwell b76e45d5d6 Make bench_internal obey secp256k1_fe_sqrt's contract wrt aliasing.
Bench_internal was previously incorrect but wasn't detected by
 -DVERIFY until PR #551.
2019-02-21 05:58:33 +00:00
Gregory Maxwell 870a977644
Merge #562: Make use of TAG_PUBKEY constants in secp256k1_eckey_pubkey_parse
d3cb1f9 Make use of TAG_PUBKEY constants in secp256k1_eckey_pubkey_parse (Ben Woosley)

Pull request description:

  This results in more self-documenting code.

  Constants defined here:
  1e6f1f5ad5/include/secp256k1.h (L175-L180)

Tree-SHA512: 2026103c487a5ebdea9a2f5ec2be96d74e38d5b2269b4df11e354bb54aba2925b47c3185f530205019840b00fc3501121acfa5234faf1d095d71777826414f69
2019-02-21 05:35:10 +00:00
Gregory Maxwell be40c4d0b5 Fixup for C90 mixed declarations.
Reported-by: Jonas Nick <jonasd.nick@gmail.com>
2019-02-21 05:00:29 +00:00
Gregory Maxwell c71dd2c08f
Merge #509: Fix algorithm selection in bench_ecmult
0f05173 Fix algorithm selection in bench_ecmult (Jonas Nick)

Pull request description:

  Without this commit using an unknown argument results in a segmentation fault.

Tree-SHA512: 85b8f977e62fa360ff6dc923bd86f08725c30e178d58f43d33cbd8eb69e54fa4ec76e4407624611a80554cf9961689bce6b216da735ac95b256d0d2f60fe3328
2019-02-21 04:47:12 +00:00
Gregory Maxwell 6492bf88cc
Merge #518: Summarize build options after running configure
3965027 Summarize build options in configure script (Evan Klitzke)

Pull request description:

  This is a trivial build system change to summarize the build options after running configure.

  Example output:
  ```
  $ ./configure
  ....
  <many lines omitted>
  ...
  config.status: src/libsecp256k1-config.h is unchanged
  config.status: executing depfiles commands
  config.status: executing libtool commands

  Build Options:
    with endomorphism   = no
    with ecmult precomp = yes
    with jni            = no
    module ecdh         = no
    module recovery     = no

    asm                 = x86_64
    bignum              = gmp
    field               = 64bit
    scalar              = 64bit

    CC                  = gcc
    CFLAGS              = -g -O2 -W -std=c89 -pedantic -Wall -Wextra -Wcast-align -Wnested-externs -Wshadow -Wstrict-prototypes -Wno-unused-function -Wno-long-long -Wno-overlength-strings -fvisibility=hidden -O3
    CPPFLAGS            =
    LDFLAGS             =
  ```

  I tried to just include the configure options that looked interesting; let me know if there are any I didn't include that I should have.

Tree-SHA512: 428381654d772f76bc81210d39ba5c3f07a94dc6a6378a02ccc6f23ebce7f501896268bcd2e94e2b0d8aea54c9c70c44a9238a0f0960600f463b1e2847c7ed1f
2019-02-21 04:44:01 +00:00
Gregory Maxwell 0e9ada1941
Merge #567: Correct order of libs returned on pkg-config --libs --static libsecp2…
89a20a8 Correct order of libs returned on pkg-config --libs --static libsecp256k1 call. (Phillip Mienk)

Pull request description:

  …56k1 call.

Tree-SHA512: 095f5e71837e63a2bb6e9cf04cabe7f1ec55cf0fc32b44c80a89c232efb7d74bf0f148a8cd29f9fa2999f02bbc638d9a086ffd50888aab6f9fd5db74e37ae4d4
2019-02-21 04:36:40 +00:00
Gregory Maxwell e96901a4b9
Merge #587: Make randomization of a non-signing context a noop
6198375 Make randomization of a non-signing context a noop (Tim Ruffing)

Pull request description:

  Before this commit secp256k1_context_randomize called illegal_callback
  when called on a context not initialized for signing. This is not
  documented. Moreover, it is not desirable because non-signing contexts
  may use randomization in the future.

  This commit makes secp256k1_context_randomize a noop in this case. This
  is safe because the context cannot be used for signing anyway.

  This fixes #573 and it fixes rust-bitcoin/rust-secp256k1#82.

Tree-SHA512: 34ddfeb004d9da8f4a77c739fa2110544c28939378e779226da52f410a0e36b3aacb3ebd2e3f3918832a9027684c161789cfdc27a133f2f0e0f1c47e8363029c
2019-02-21 04:33:59 +00:00
Gregory Maxwell 58df8d03ad
Merge #511: Portability fix for the configure scripts generated
270f6c8 Portability fix for the configure scripts generated (Pierre Pronchery)

Pull request description:

  Found thanks to the developer checks from the pkgsrc software
  distribution (for NetBSD, SmartOS, Minix, MacOS X, Linux, and more).

Tree-SHA512: 2589545aa4d0620db66e79df1dc148a487384b5169ba7323937490d802973388859d30d45b35ee3e614be6d49cb694f37f585a16caa87ad1e500a0b7368dcc0a
2019-02-21 04:28:20 +00:00
Gregory Maxwell 2ebdad772a
Merge #552: Make constants static:
496c5b4 Make constants static: static const secp256k1_ge secp256k1_ge_const_g; static const int CURVE_B; (Russell O'Connor)

Pull request description:

  static const secp256k1_ge secp256k1_ge_const_g;
  static const int CURVE_B;

Tree-SHA512: df8d34777d3b1b90eef875d50c2870e2480f08685b399a22eaf584ce294766e0de3a41523757a23e311e633886c89400313421282beca791326a06695f348940
2019-02-21 04:26:40 +00:00
Gregory Maxwell 1c131affd3
Merge #551: secp256k1_fe_sqrt: Verify that the arguments don't alias.
bf8b86c secp256k1_fe_sqrt: Verify that the arguments don't alias. (Russell O'Connor)

Pull request description:

Tree-SHA512: 4e9128625817be83a1259e7dbdb82c4be8ee0174af7d5e76eeac3245d23d6bf01378d9697dcb870eb61577afd7c0556cb3c6633e3b27504add14c10b18f7c607
2019-02-21 04:23:50 +00:00
Gregory Maxwell ba698f883b
Merge #539: Assorted minor corrections
52ab96f clean dependendies in field_*_impl.h (Russell O'Connor)
deff5ed Correct math typos in field_*.h (Russell O'Connor)
4efb3f8 Add check that restrict pointers don't alias with all parameters. (Russell O'Connor)

Pull request description:

  * add more checks for restrict pointers.
  * correct math typos.
  * refine dependencies on "num.h"

Tree-SHA512: c368f577927db2ace3e7f46850cb2fdf9d7d169b698a9697767e1f82e9e7091f2b2fea0f7cf173048eb4c1bb56824c884fa849c04c595ee97766c01f346a54ec
2019-02-21 04:20:35 +00:00
Gregory Maxwell 949e85b009
Merge #550: Optimize secp256k1_fe_normalize_weak calls.
9bd89c8 Optimize secp256k1_fe_normalize_weak calls. Move secp256k1_fe_normalize_weak calls out of ECMULT_TABLE_GET_GE and ECMULT_TABLE_GET_GE_STORAGE and into secp256k1_ge_globalz_set_table_gej instead. (Russell O'Connor)

Pull request description:

  Move secp256k1_fe_normalize_weak calls out of ECMULT_TABLE_GET_GE and ECMULT_TABLE_GET_GE_STORAGE and into secp256k1_ge_globalz_set_table_gej instead.

Tree-SHA512: 7bbb1aca8e37a268a26d7061bd1f390db129e697792f1d5ddd10ea34927616edc26ef118b500c3e5e14d1d463196033ef64e4d34b765380325c24835458b7a9b
2019-02-21 04:14:40 +00:00
Tim Ruffing a34bcaadf1 Actually pass CFLAGS_FOR_BUILD and LDFLAGS_FOR_BUILD to linker 2019-02-10 11:58:52 +01:00
Tim Ruffing 2d5f4cebdc configure: Use CFLAGS_FOR_BUILD when checking native compiler
This fixes a bug where configure would fail or disable static
ecmult tables because it wrongly checks the native compiler using
the target CFLAGS (instead of the native CFLAGS_FOR_BUILD), and
similar for CPPFLAGS and LDFLAGS.

Moreover, this commit adds tests to figure out whether the native
compiler supports the warning flags passed during the build, and it
contains a few minor improvements to the code that checks the native
compiler.
2019-02-10 11:56:36 +01:00
Pieter Wuille b408c6a8b2
Merge #579: Use __GNUC_PREREQ for detecting __builtin_expect
c663397 Use __GNUC_PREREQ for detecting __builtin_expect (Tim Ruffing)

Pull request description:

Tree-SHA512: 659a721da835eb15966a2a5386d6ae4c3defbb6ad473905f14161a3cf36d1556d44d887602019c89ebeffdfd82ed469ff27914dc2aaee6648d1e0c8a22151c27
2019-02-04 14:33:03 -08:00
Tim Ruffing 6198375218 Make randomization of a non-signing context a noop
Before this commit secp256k1_context_randomize called illegal_callback
when called on a context not initialized for signing. This is not
documented. Moreover, it is not desirable because non-signing contexts
may use randomization in the future.

This commit makes secp256k1_context_randomize a noop in this case. This
is safe because the context cannot be used for signing anyway.

This fixes #573 and it fixes rust-bitcoin/rust-secp256k1#82.
2019-01-27 13:33:52 +01:00
liuyujun 74e2dbd68e JNI: fix use sig array 2019-01-03 09:08:58 +08:00
Tim Ruffing c663397f46 Use __GNUC_PREREQ for detecting __builtin_expect 2018-12-17 11:47:25 +01:00
Tim Ruffing 3cb057f842 Fix possible integer overflow in DER parsing
If we’re in the last loop iteration, then `lenleft == 1` and it could
be the case that `ret == MAX_SIZE`, and so `ret +  lenleft` will
overflow to 0 and the sanity check will not catch it. Then we will
return `(int) MAX_SIZE`, which should be avoided because this value is
implementation-defined. (However, this is harmless because
`(int) MAX_SIZE == -1` on all supported platforms.)
2018-12-14 11:43:47 +01:00
Pieter Wuille e34ceb333b
Merge #557: Eliminate scratch memory used when generating contexts
b3bf5f9 ecmult_impl: expand comment to explain how effective affine interacts with everything (Andrew Poelstra)
efa783f Store z-ratios in the 'x' coord they'll recover (Peter Dettman)
ffd3b34 add `secp256k1_ge_set_all_gej_var` test which deals with many infinite points (Andrew Poelstra)
84740ac ecmult_impl: save one fe_inv_var (Andrew Poelstra)
4704527 ecmult_impl: eliminate scratch memory used when generating context (Andrew Poelstra)
7f7a2ed ecmult_gen_impl: eliminate scratch memory used when generating context (Andrew Poelstra)

Pull request description:

  Builds on #553

Tree-SHA512: 6031a601a4a476c1d21fc8db219383e7930434d2f199543c61aca0118412322dd814a0109c385ff1f83d16897170dd0c25051697b0f88f15234b0059b661af41
2018-11-26 09:14:58 -08:00
Andrew Poelstra b3bf5f99a3 ecmult_impl: expand comment to explain how effective affine interacts with everything 2018-11-10 14:01:13 +00:00
Peter Dettman efa783f8f0 Store z-ratios in the 'x' coord they'll recover 2018-11-10 13:14:43 +00:00
Andrew Poelstra ffd3b346fe add `secp256k1_ge_set_all_gej_var` test which deals with many infinite points 2018-11-09 00:20:53 +00:00
Andrew Poelstra 84740acd2a ecmult_impl: save one fe_inv_var 2018-11-09 00:20:53 +00:00
Andrew Poelstra 47045270fa ecmult_impl: eliminate scratch memory used when generating context 2018-11-09 00:20:51 +00:00
Andrew Poelstra 7f7a2ed3a8 ecmult_gen_impl: eliminate scratch memory used when generating context 2018-11-09 00:16:06 +00:00