55 Commits

Author SHA1 Message Date
Russell O'Connor
2914bccbc0 Simulated int128 type. 2022-11-07 16:37:24 -05:00
Tim Ruffing
da6514a04a config: Introduce DEBUG_CONFIG macro for debug output of config 2022-07-07 20:32:08 +02:00
Tim Ruffing
616b43dd3b util: Remove endianness detection 2022-03-25 11:32:22 +01:00
Tim Ruffing
8d89b9e6e5 hash: Make code agnostic of endianness
Recent compilers compile the two new functions to very efficient code
on various platforms. In particular, already GCC >= 5 and clang >= 5
understand do this for the read function, which is the one critical
for performance (called 16 times per SHA256 transform).

Fixes #1080.
2022-03-25 11:32:14 +01:00
Tim Ruffing
ac49361ed0 prealloc: Get rid of manual memory management for prealloc contexts 2021-12-09 20:52:28 +01:00
Tim Ruffing
a4875e30a6 refactor: Move default callbacks to util.h 2021-12-03 11:23:33 +01:00
Jonas Nick
189f6bcfef Fix unused parameter warnings when building without VERIFY 2021-10-04 19:06:41 +00:00
Pieter Wuille
de0a643c3d Add secp256k1_ctz{32,64}_var functions
These functions count the number of trailing zeroes in non-zero integers.
2021-03-08 09:56:07 -08:00
Tim Ruffing
659d0d4798
Merge #880: Add parens around ROUND_TO_ALIGN's parameter.
b6f649889ae78573f1959f04172a8e1fe15beab7 Add parens around ROUND_TO_ALIGN's parameter. This makes the macro robust against a hypothetical ROUND_TO_ALIGN(foo ? sizeA : size B) invocation. (Russell O'Connor)

Pull request description:

  This makes the macro robust against a hypothetical `ROUND_TO_ALIGN(foo ? sizeA : size B)` invocation.

  See also <https://wiki.sei.cmu.edu/confluence/display/c/PRE01-C.+Use+parentheses+within+macros+around+parameter+names>.

ACKs for top commit:
  sipa:
    ACK b6f649889ae78573f1959f04172a8e1fe15beab7. This is the way.
  jonasnick:
    utACK b6f649889ae78573f1959f04172a8e1fe15beab7
  real-or-random:
    utACK b6f649889ae78573f1959f04172a8e1fe15beab7

Tree-SHA512: 6a2685f959e8ae472259e5ea75fe12e8e6213f56f5aec7603a896c294e6a8833caae25c412607d9c9a3125370a7765a3e506127b101a1b87203f95e326f6c6c6
2021-01-26 09:39:00 +01:00
Russell O'Connor
b6f649889a Add parens around ROUND_TO_ALIGN's parameter.
This makes the macro robust against a hypothetical ROUND_TO_ALIGN(foo ? sizeA : size B) invocation.
2021-01-25 11:43:45 -05:00
Russell O'Connor
2730618604 Avoid casting (void**) values.
Replaced with an expression that only casts (void*) values.
2021-01-23 15:22:54 -05:00
Dimitris Apostolou
07aa4c70ff
Fix insecure links 2020-12-18 00:24:22 +02:00
Tim Ruffing
1f4dd03838 Typedef (u)int128_t only when they're not provided by the compiler 2020-10-27 20:18:18 +01:00
Tim Ruffing
e89278f211 Don't use reserved identifiers memczero and benchmark_verify_t
As identified in #829 and #833. Fixes #829.

Since we touch this anyway, this commit additionally makes the
identifiers in the benchmark files a little bit more consistent.
2020-10-20 15:00:19 +02:00
Tim Ruffing
6173839c90 Switch to our own memcmp function
Fixes #823.
2020-10-11 10:39:20 -07:00
Tim Ruffing
54caf2e74f
Merge #799: Add fallback LE/BE for architectures with known endianness + SHA256 selftest
8bc6aeffa9a191e677cb9e3a22fff130f16990f3 Add SHA256 selftest (Pieter Wuille)
5e5fb28b4a45d7e35e55b5f5feead2be07bccc28 Use additional system macros to figure out endianness (Pieter Wuille)

Pull request description:

  These are all the architecture macros I could find with known endianness. Use those as a fallback when __BYTE_ORDER__ isn't available.

  See https://github.com/bitcoin-core/secp256k1/pull/787#issuecomment-673764652

  It also adds a SHA256 selftest, so that improperly overriding the endianness detection will be detected at runtime.

ACKs for top commit:
  real-or-random:
    ACK 8bc6aeffa9a191e677cb9e3a22fff130f16990f3 I read the diff, and tested that the self-test passes/fails with/without the correct endianness setting
  gmaxwell:
    ACK 8bc6aeffa9a191e677cb9e3a22fff130f16990f3  looks good and I also ran the tests on MIPS-BE and verified that forcing it to LE makes the runtime test  fail.

Tree-SHA512: aca4cebcd0715dcf5b58f5763cb4283af238987f43bd83a650e38e127f348131692b2eed7ae5b2ae96046d9b971fc77c6ab44467689399fe470a605c3458ecc5
2020-09-09 15:57:45 +02:00
Pieter Wuille
5e5fb28b4a Use additional system macros to figure out endianness
Also permit it being overridden by explicitly passing SECP256K1_{BIG,LITTLE}_ENDIAN
2020-08-15 20:31:51 -07:00
Pieter Wuille
02b6c87b52 Add support for (signed) __int128 2020-08-13 11:46:34 -07:00
Tim Ruffing
979961c506
Merge #787: Use preprocessor macros instead of autoconf to detect endianness
0dccf98a21beb245f6cd9ed76fb7368529df09c7 Use preprocessor macros instead of autoconf to detect endianness (Tim Ruffing)

Pull request description:

  This does not fix any particular issue but it's preferable to not
  rely on autoconf. This avoids endianness mess for users on BE hosts
  if they use their build without autoconf.

  The macros are carefully written to err on the side of the caution,
  e.g., we #error if the user manually configures a different endianness
  than what we detect.

  Supersedes #770 .

ACKs for top commit:
  sipa:
    ACK 0dccf98a21beb245f6cd9ed76fb7368529df09c7
  gmaxwell:
    ACK 0dccf98a21beb245f6cd9ed76fb7368529df09c7

Tree-SHA512: 6779458de5cb6eaef2ac37f9d4b8fa6c9b299f58f6e5b72f2b0d7e36c12ea06074e483acfb85085a147e0f4b51cd67d897f61a67250ec1cea284a0f7680eb2e8
2020-08-13 12:36:53 +02:00
Tim Ruffing
0dccf98a21 Use preprocessor macros instead of autoconf to detect endianness
This does not fix any particular issue but it's preferable to not
rely on autoconf. This avoids endianness mess for users on BE hosts
if they use their build without autoconf.

The macros are carefully written to err on the side of the caution,
e.g., we #error if the user manually configures a different endianness
than what we detect.
2020-08-11 11:25:39 +02:00
Pieter Wuille
79f1f7a4f1 Autodetect __int128 availability on the C side
Instead of supporting configuration of the field and scalar size independently,
both are now controlled by the availability of a 64x64->128 bit multiplication
(currently only through __int128). This is autodetected from the C code through
__SIZEOF_INT128__, but can be overridden using configure's
--with-test-override-wide-multiply, or by defining
USE_FORCE_WIDEMUL_{INT64,INT128} manually.
2020-08-10 14:56:39 -07:00
Tim Ruffing
67a429f31f Suppress a harmless variable-time optimization by clang in _int_cmov
Follow up on 52a03512c1d800603b5c923c1a28bdba12dadb30
2020-07-27 14:35:05 +02:00
Elichai Turkel
2876af4f8d
Split ecdsa_sign logic into a new function and use it from ecdsa_sign and recovery 2020-06-03 13:19:09 +03:00
Elichai Turkel
f79a7adcf5
Add valgrind uninit check to cmovs output 2020-05-26 23:30:56 +03:00
Tim Ruffing
01993878bb Add test for memczero() 2020-03-27 11:07:10 +01:00
Tim Ruffing
52a03512c1 Suppress a harmless variable-time optimization by clang in memczero
This has been not been caught by the new constant-time tests because
valgrind currently gives us a zero exit code even if finds errors, see
https://github.com/bitcoin-core/secp256k1/pull/723#discussion_r388246806 .

This commit also simplifies the arithmetic in memczero.

Note that the timing leak here was the bit whether a secret key was
out of range. This leak is harmless and not exploitable. It is just
our overcautious practice to prefer constant-time code even here.
2020-03-27 10:23:45 +01:00
Gregory Maxwell
34a67c773b Eliminate harmless non-constant time operations on secret data.
There were several places where the code was non-constant time
 for invalid secret inputs.  These are harmless under sane use
 but get in the way of automatic const-time validation.

(Nonce overflow in signing is not addressed, nor is s==0 in
 signing)
2020-02-20 17:27:03 +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
Tim Ruffing
1bf7c056ba Prepare for manual memory management in preallocated memory
* Determine ALIGNMENT more cleverly and move it to util.h
 * Implement manual_malloc() helper function
2019-05-25 13:58:09 +02:00
Tim Ruffing
c663397f46 Use __GNUC_PREREQ for detecting __builtin_expect 2018-12-17 11:47:25 +01:00
Andrew Poelstra
548de42ecf add resizeable scratch space API
Alignment support by Pieter Wuille.
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
Andrew Poelstra
a724d7296d configure: add --enable-coverage to set options for coverage analysis 2016-11-28 03:29:01 +00:00
Pieter Wuille
dd891e0ed5 Get rid of _t as it is POSIX reserved 2015-09-21 21:03:37 +02:00
Luke Dashjr
05732c5a5f Callback data: Accept pointers to either const or non-const data 2015-09-19 19:33:28 +00:00
Peter Dettman
72ae443afb Improve perf. of cmov-based table lookup 2015-08-01 10:57:36 -05:00
Pieter Wuille
995c548771 Introduce callback functions for dealing with errors. 2015-07-26 18:08:38 +02: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
Gregory Maxwell
4be8d6fc42 Centralize the definition of uint128_t and use it uniformly.
This needs to be renamed along with the other _t types, because _t
 is reserved.  But that will be done later.
2015-01-25 05:10:40 +00:00
Pieter Wuille
45cdf4479d
Merge pull request #193
25b35c7 Convert field code to strict C89 (+ long long, +__int128) (Gregory Maxwell)
3627437 C89 nits and dead code removal. (Gregory Maxwell)
2015-01-24 18:51:50 -04:00
mb300sd
402878ae11 fix ifdef/ifndef 2015-01-23 17:09:50 -05:00
Gregory Maxwell
3627437d80 C89 nits and dead code removal. 2015-01-23 04:17:12 +00:00
Pieter Wuille
a5759c572e Check return value of malloc 2014-12-07 02:58:24 +01:00
Pieter Wuille
be82e92fc4 Require that r and b are different for field multiplication.
Suggested by Peter Dettman, this prepares for slightly faster muitiplication
which writes results immediately to r before finishing reading b.
2014-12-01 13:40:34 +01:00
Pieter Wuille
f49b2ef840 Add DETERMINISTIC to avoid line number/source dependent binaries
This will make it easier to detect changes without semantic impact.
2014-11-18 11:08:44 +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
f0709ac57e Avoid forward static decl of undefined functions, also fix a paren warning in the tests. 2014-11-13 01:45:49 -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
9974d8693e Misc. Warning and cosmetic error cleanups.
This fixes a cosmetic precedence bug in the tests along with some
 type warnings.

It also adds a dummy cast to the CHECK macro to avoid hundreds
 of statement with no effect warnings on compilers that warn about
 such things.
2014-11-04 13:17:45 -08:00
Pieter Wuille
01097ddf19 Make bench deterministic 2014-10-31 03:34:36 -07:00