70 Commits

Author SHA1 Message Date
Tim Ruffing
e626f00d1e Merge commits 'b314cf28 1f1bb78b 40f50d0f c891c5c2 ea47c82e e7210393 c1b49664 5814d848 07687e81 10e6d29b d3e29db8 e2c9888e 4197d667 5e9a4d7a 77af1da9 1a81df82 1ad5185c efe85c70 79e09451 d373bf6d 74b7c3b5 a9db9f2d 44378867 3bf4d68f e4af41c6 ' into temp-merge-1249 2024-01-23 16:04:45 +01:00
Sebastian Falbesoner
a0fb68a2e7 introduce and use SECP256K1_SCALAR_VERIFY macro
By providing an uppercase variant of these verification functions,
it is better visible that it is test code.
2023-12-01 01:36:29 +01:00
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
21f49d9bec Remove unused secp256k1_scalar_shr_int 2023-11-04 15:55:12 -04:00
Pieter Wuille
2140da9cd5 Add secp256k1_scalar_half for halving scalars (+ tests/benchmarks).
Co-authored-by: Jonas Nick <jonasd.nick@gmail.com>
Co-authored-by: Tim Ruffing <crypto@timruffing.de>
2023-11-04 15:54:08 -04:00
Jonas Nick
775f5e242b
Merge commits '1b13415d 374e2b54 96294c00 8d2960c8 ce765a5b b2f6712d eedd7810 b327abfc 5d8fa825 3d05c86d bcffeb14 de657c20 060e32cb 0ba2b945 48b1d939 6b9507ad 5373693e 2e6cf9ba 6ee14550 26a98992 4d7fe609 ea26b71c 65c79fe2 727bec5b 0b4640ae 199d27ce cbf3053f 49be5be9 b10ddd2b 4fd00f4b ba9cb6f3 ee7aaf21 ' into temp-merge-1395
- Replace fe_equal_var with fe_equal
- Use CHECK_ILLEGAL instead of CHECK/ecount
- Turn on secp256k1-zkp specific modules in CI
2023-09-20 09:38:36 +00:00
Tim Ruffing
aa3edea119 scalar: Remove unused secp256k1_scalar_chacha20
Unused since a11250330b24b3dffdf11d2de5d496397b4e4410.
2023-08-01 10:50:10 +02:00
Jonas Nick
579999b425
scalar: adjust muladd2 to new int128 interface 2023-07-27 16:31:40 +00:00
Jonas Nick
74d9073414
Merge commits '83186db3 e9e4526a 5f7903c7 d373a721 09df0bfb 20a5da5f 908e02d5 d75dc59b debf3e5c bf29f8d0 60556c9f cb1a5927 67214f5f 45c5ca76 30574f22 0702ecb0 705ce7ed 3c1a0fd3 10836832 926dd3e9 ac43613d fd491ea1 799f4eec ' into temp-merge-1356 2023-07-27 16:31:40 +00:00
stratospher
d23da6d557 use secp256k1_scalar_verify checks 2023-07-27 17:35:50 +05:30
Jonas Nick
7a07f3d33f
Merge commits '3bab71cf 4258c54f 566faa17 9ce9984f 04bf3f67 5be353d6 2e035af2 5b0444a3 a6f4bcf6 5ec1333d f6bef03c 1f33bb2b 1c895367 6b7e5b71 596b336f 4b84f4bf 024a4094 222ecaf6 4b0f711d 3c818388 f30c7486 1cf15ebd 24c768ae 341cc197 c63ec88e 54d34b6c 073d98a0 9eb6934f ab5a9171 fb3a8063 006ddc1f 3353d3c7 b54a0672 7d4f86d2 e8295d07 3e3d125b acf5c55a ' into temp-merge-1312 2023-07-24 20:15:07 +00:00
Jonas Nick
0d540ec942
Merge commits '88e80722 ff8edf89 f29a3270 a7a7bfaf a01a7d86 b1579cf5 ad7433b1 233822d8 5fbff5d3 2b77240b 1bff2005 e1817a6f 5596ec5c 8ebe5c52 1cca7c17 1b21aa51 cbd25559 09b1d466 57573187 8962fc95 9d1b458d eb8749fc 6048e6c0 ' into temp-merge-1222 2023-07-20 16:29:40 +00:00
Jonas Nick
e996d076da
Merge commits '44916ae9 86e3b38a ddf2b291 6138d73b e40fd277 ' into temp-merge-1156 2023-07-17 14:02:13 +00:00
Sebastian Falbesoner
740528caad scalar: use newly introduced secp256k1_{read,write}_be64 helpers (4x64 impl.) 2023-06-17 01:06:35 +02:00
Sebastian Falbesoner
887183e7de scalar: use secp256k1_{read,write}_be32 helpers (4x64 impl.)
An alternative would be to introduce special helpers for reading/writing
uint64_t in big endian `secp256k1_{read,write}_be64`.
2023-06-10 19:50:54 +02:00
Pieter Wuille
56a5d41429
Bugfix: mark outputs as early clobber in scalar x86_64 asm
In the existing code, the compiler is allowed to allocate the RSI register
for outputs m0, m1, or m2, which are written to before the input in RSI is
read from. Fix this by marking them as early clobber.

Reported by ehoffman2 in https://github.com/bitcoin-core/secp256k1/issues/766
2023-05-14 17:20:01 +00:00
Tim Ruffing
c8c0f55a11
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-14 17:19:04 +00:00
Tim Ruffing
3e94289966
ct: Use volatile trick in scalar_cond_negate 2023-05-14 17:16:50 +00:00
Pieter Wuille
0c729ba70d Bugfix: mark outputs as early clobber in scalar x86_64 asm
In the existing code, the compiler is allowed to allocate the RSI register
for outputs m0, m1, or m2, which are written to before the input in RSI is
read from. Fix this by marking them as early clobber.

Reported by ehoffman2 in https://github.com/bitcoin-core/secp256k1/issues/766
2023-05-12 05:23:07 -04: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
Tim Ruffing
5fb336f9ce ct: Use volatile trick in scalar_cond_negate 2023-05-11 16:32:07 +02:00
Tim Ruffing
a6f4bcf6e1
Merge bitcoin-core/secp256k1#1231: Move SECP256K1_INLINE macro definition out from include/secp256k1.h
8e142ca4102ade1b90dcb06d6c78405ef3220599 Move `SECP256K1_INLINE` macro definition out from `include/secp256k1.h` (Hennadii Stepanov)
77445898a5852ecd38ab95cfb329333a82673115 Remove `SECP256K1_INLINE` usage from examples (Hennadii Stepanov)

Pull request description:

  From [IRC](https://gnusha.org/secp256k1/2023-01-31.log):
  > 06:29 \< hebasto\> What are reasons to define the `SECP256K1_INLINE` macro in user's `include/secp256k1.h` header, while it is used internally only?
  > 06:32 \< hebasto\> I mean, any other (or a new dedicated) header in `src` looks more appropriate, no?
  > 06:35 \< sipa\> I think it may just predate any "utility" internal headers.
  > 06:42 \< sipa\> I think it makes sense to move it to util.h

  Pros:
  - it is a step in direction to better organized headers (in context of #924, #1039)

  Cons:
  - code duplication for `SECP256K1_GNUC_PREREQ` macro

ACKs for top commit:
  sipa:
    utACK 8e142ca4102ade1b90dcb06d6c78405ef3220599
  real-or-random:
    utACK 8e142ca410

Tree-SHA512: 180e0ba7c2ef242b765f20698b67d06c492b7b70866c21db27c18d8b2e85c3e11f86c6cb99ffa88bbd23891ce3ee8a24bc528f2c91167ec2fddc167463f78eac
2023-04-20 18:18:11 +02:00
Tim Ruffing
96f4853850 ct: Use volatile "trick" in all fe/scalar cmov implementations
Apparently clang 15 is able to compile our cmov code into a branch,
at least for fe_cmov and fe_storage_cmov. This commit makes the
condition volatile in all cmov implementations (except ge but that
one only calls into the fe impls).

This is just a quick fix. We should still look into other methods,
e.g., asm and #457. We should also consider not caring about
constant-time in scalar_low_impl.h

We should also consider testing on very new compilers in nightly CI,
see https://github.com/bitcoin-core/secp256k1/pull/864#issuecomment-769211867
2023-04-11 12:06:09 +02:00
Tim Ruffing
4a496a36fb ct: Use volatile "trick" in all fe/scalar cmov implementations
Apparently clang 15 is able to compile our cmov code into a branch,
at least for fe_cmov and fe_storage_cmov. This commit makes the
condition volatile in all cmov implementations (except ge but that
one only calls into the fe impls).

This is just a quick fix. We should still look into other methods,
e.g., asm and #457. We should also consider not caring about
constant-time in scalar_low_impl.h

We should also consider testing on very new compilers in nightly CI,
see https://github.com/bitcoin-core/secp256k1/pull/864#issuecomment-769211867
2023-04-01 15:58:24 +09:00
Hennadii Stepanov
8e142ca410
Move SECP256K1_INLINE macro definition out from include/secp256k1.h 2023-03-09 15:29:56 +00:00
Andrew Poelstra
0a6006989f Revert "Remove unused scalar_sqr"
This reverts commit 5437e7bdfbffddf69fdf7b4af7e997c78f5dafbf.
2023-01-23 10:18:21 -08:00
Pieter Wuille
0db05a770e Abstract interactions with valgrind behind new checkmem.h 2023-01-11 16:07:35 -05:00
Tim Ruffing
dceaa1f579 int128: Tidy #includes of int128.h and int128_impl.h
After this commit, int128.h and int128_impl.h are included as follows:
 - .c files which use int128 include int128_impl.h (after util.h)
 - .h files which use int128 include int128.h (after util.h)

This list is exhaustive. util.h needs to included first because it sets
up necessary #defines.
2022-11-07 16:38:30 -05:00
Russell O'Connor
2914bccbc0 Simulated int128 type. 2022-11-07 16:37:24 -05:00
Jonas Nick
edcacc2b2e Merge commits '26de4dfe 6e898534 c083cc6e 1e5d50fa cc2c09e3 efad3506 7012a188 34388af6 98e0358d d0bd2693 185a6af2 6c52ae87 69394879 1e78c18d 202a030f bf0ac460 399722a6 3dc8c072 50f33677 7973576f 1758a92f ' into temp-merge-950 2021-06-14 18:16:46 +00:00
Pieter Wuille
5437e7bdfb Remove unused scalar_sqr 2021-03-12 10:06:18 -08:00
Pieter Wuille
1e0e885c8a Make field/scalar code use the new modinv modules for inverses 2021-03-12 10:06:14 -08:00
Pieter Wuille
aa404d53be Move secp256k1_scalar_{inverse{_var},is_even} to per-impl files
This temporarily duplicates the inversion code across the 4x64 and 8x32
implementations. Those implementations will be replaced in a later commit.
2021-03-11 10:25:26 -08:00
Jonas Nick
d4ca81f48e Merge commits 'dc6e5c3a 2d9e7175 b61f9da5 98dac878 8c727b90 328aaef2 f2d9aeae b732701f db726782 5671e5f3 a4abaab7 659d0d47 f8c0b57e 24d1656c 3a8b47bc ebdba03c 4c3ba88c ' into temp-merge-901
Also add -zkp modules to .cirrus.yml.
2021-03-08 13:35:16 +00:00
Dimitris Apostolou
07aa4c70ff
Fix insecure links 2020-12-18 00:24:22 +02:00
Jonas Nick
b0917f3de1 Merge remote-tracking branch 'upstream/master' into temp-merge-835 2020-11-05 20:21:38 +00:00
Pieter Wuille
4232e5b7da Rip out non-endomorphism code 2020-10-13 11:31:13 -07:00
Russell O'Connor
acab934d24 Detailed comments for secp256k1_scalar_split_lambda 2020-10-13 11:31:13 -07:00
Andrew Poelstra
8b70795b5e Fix BE platforms by updating endianness macros to match upstream 2020-10-12 13:44:16 +00:00
Jonas Nick
0a5b60d8b0 Merge commit '6034a04f' into temp-merge-778 2020-09-28 21:59:46 +00:00
Tim Ruffing
5b196338f0 Remove redundant "? 1 : 0" after comparisons in scalar code
This prevents GCC from generating branches on PowerPC in certain
cases.

Fixes #771.
2020-07-26 14:59:56 +02:00
Andrew Poelstra
c59c602dd6 Add schnorrsig module which implements BIP-schnorr [0] compatible signing, verification and batch verification.
[0] https://github.com/sipa/bips/blob/bip-schnorr/bip-schnorr.mediawiki
2020-07-24 14:59:36 +02:00
Andrew Poelstra
a1f16a0a53 add chacha20 function 2020-07-24 14:50:49 +02:00
Andrew Poelstra
94425d4a67 rangeproof: several API changes
* add summing function for blinded generators
* drop `excess` and `gen` from `verify_tally`
* add extra_commit to rangeproof sign and verify
2020-07-24 14:49:33 +02:00
Elichai Turkel
f79a7adcf5
Add valgrind uninit check to cmovs output 2020-05-26 23:30:56 +03: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
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
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
Alex-GR
9d67afad96 Update scalar_4x64_impl.h
XOR reg,reg instead of MOV 0 to reg. It should be at least equal in all architectures and faster in some else.
2016-10-09 00:16:50 +03:00
Gregory Maxwell
9f6993f370 Remove some dead code. 2015-09-28 05:43:51 +00:00