Skip to content

Commit a69df3a

Browse files
Merge bitcoin-core/secp256k1#816: Improve checks at top of _fe_negate methods
515e795 Improve checks at top of _fe_negate methods (Peter Dettman) Pull request description: In theory we could have a single static assertion that would ensure all of these are always true (for any magnitude up to the limit), but I think this small redundancy is clearer. ACKs for top commit: sipa: utACK 515e795 real-or-random: ACK 515e795 bounds hold by inspection and by robot-dreams's script Tree-SHA512: c33e47e186b37ca0b4e8d23712f8e5ab0c113024a0229fc6ce63b8cbad21bddbecc0c50029721a1fb3376b2d1da678c1ddb69c5ae971d84ddb7993c755867da4
2 parents be6944a + 515e795 commit a69df3a

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

src/field_10x26_impl.h

+4
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,10 @@ SECP256K1_INLINE static void secp256k1_fe_negate(secp256k1_fe *r, const secp256k
391391
#ifdef VERIFY
392392
VERIFY_CHECK(a->magnitude <= m);
393393
secp256k1_fe_verify(a);
394+
VERIFY_CHECK(0x3FFFC2FUL * 2 * (m + 1) >= 0x3FFFFFFUL * 2 * m);
395+
VERIFY_CHECK(0x3FFFFBFUL * 2 * (m + 1) >= 0x3FFFFFFUL * 2 * m);
396+
VERIFY_CHECK(0x3FFFFFFUL * 2 * (m + 1) >= 0x3FFFFFFUL * 2 * m);
397+
VERIFY_CHECK(0x03FFFFFUL * 2 * (m + 1) >= 0x03FFFFFUL * 2 * m);
394398
#endif
395399
r->n[0] = 0x3FFFC2FUL * 2 * (m + 1) - a->n[0];
396400
r->n[1] = 0x3FFFFBFUL * 2 * (m + 1) - a->n[1];

src/field_5x52_impl.h

+3
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,9 @@ SECP256K1_INLINE static void secp256k1_fe_negate(secp256k1_fe *r, const secp256k
377377
#ifdef VERIFY
378378
VERIFY_CHECK(a->magnitude <= m);
379379
secp256k1_fe_verify(a);
380+
VERIFY_CHECK(0xFFFFEFFFFFC2FULL * 2 * (m + 1) >= 0xFFFFFFFFFFFFFULL * 2 * m);
381+
VERIFY_CHECK(0xFFFFFFFFFFFFFULL * 2 * (m + 1) >= 0xFFFFFFFFFFFFFULL * 2 * m);
382+
VERIFY_CHECK(0x0FFFFFFFFFFFFULL * 2 * (m + 1) >= 0x0FFFFFFFFFFFFULL * 2 * m);
380383
#endif
381384
r->n[0] = 0xFFFFEFFFFFC2FULL * 2 * (m + 1) - a->n[0];
382385
r->n[1] = 0xFFFFFFFFFFFFFULL * 2 * (m + 1) - a->n[1];

0 commit comments

Comments
 (0)