forked from bitcoin/bitcoin
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge bitcoin-core/secp256k1#1371: Add exhaustive tests for ellswift …
…(with create+decode roundtrip) 2792119 Add exhaustive test for ellswift (create+decode roundtrip) (Sebastian Falbesoner) Pull request description: This PR adds the basic structure for ellswift exhaustive tests. Right now only a `secp256k1_ellswift_create` + `secp256k1_ellswift_decode` indirect roundtrip (exhaustive loop scalar -> ellswift pubkey -> decoded pubkey -> decoded group element, compared with exhaustive precomputed group element) is included. The exhaustive tests passes locally with all currently supported orders (n=13 [default] and n=199). Note that for n=7, the test is skipped, as the used curve in this case is even-ordered and ellswift only supports odd-ordered curves. ACKs for top commit: sipa: utACK 2792119 real-or-random: utACK 2792119 Tree-SHA512: c51d3d99e9839793b3c15d75b9a29f01080db160ab8819973abd877288f9f0af972ea4264290220ab1cd035fdebcfac7767436aa39154d924ef0bf6a5733a55d
- Loading branch information
Showing
3 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/*********************************************************************** | ||
* Distributed under the MIT software license, see the accompanying * | ||
* file COPYING or https://www.opensource.org/licenses/mit-license.php.* | ||
***********************************************************************/ | ||
|
||
#ifndef SECP256K1_MODULE_ELLSWIFT_TESTS_EXHAUSTIVE_H | ||
#define SECP256K1_MODULE_ELLSWIFT_TESTS_EXHAUSTIVE_H | ||
|
||
#include "../../../include/secp256k1_ellswift.h" | ||
#include "main_impl.h" | ||
|
||
static void test_exhaustive_ellswift(const secp256k1_context *ctx, const secp256k1_ge *group) { | ||
int i; | ||
|
||
/* Note that SwiftEC/ElligatorSwift are inherently curve operations, not | ||
* group operations, and this test only checks the curve points which are in | ||
* a tiny subgroup. In that sense it can't be really seen as exhaustive as | ||
* it doesn't (and for computational reasons obviously cannot) test the | ||
* entire domain ellswift operates under. */ | ||
for (i = 1; i < EXHAUSTIVE_TEST_ORDER; i++) { | ||
secp256k1_scalar scalar_i; | ||
unsigned char sec32[32]; | ||
unsigned char ell64[64]; | ||
secp256k1_pubkey pub_decoded; | ||
secp256k1_ge ge_decoded; | ||
|
||
/* Construct ellswift pubkey from exhaustive loop scalar i. */ | ||
secp256k1_scalar_set_int(&scalar_i, i); | ||
secp256k1_scalar_get_b32(sec32, &scalar_i); | ||
CHECK(secp256k1_ellswift_create(ctx, ell64, sec32, NULL)); | ||
|
||
/* Decode ellswift pubkey and check that it matches the precomputed group element. */ | ||
secp256k1_ellswift_decode(ctx, &pub_decoded, ell64); | ||
secp256k1_pubkey_load(ctx, &ge_decoded, &pub_decoded); | ||
ge_equals_ge(&ge_decoded, &group[i]); | ||
} | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters