Bitcoin ABC 0.33.6
P2P Digital Currency
testutil.h
Go to the documentation of this file.
1/***********************************************************************
2 * Distributed under the MIT software license, see the accompanying *
3 * file COPYING or https://www.opensource.org/licenses/mit-license.php.*
4 ***********************************************************************/
5
6#ifndef SECP256K1_TESTUTIL_H
7#define SECP256K1_TESTUTIL_H
8
9#include "field.h"
10#include "testrand.h"
11#include "util.h"
12
13static void random_fe(secp256k1_fe *x) {
14 unsigned char bin[32];
15 do {
17 if (secp256k1_fe_set_b32_limit(x, bin)) {
18 return;
19 }
20 } while(1);
21}
22
24 do {
25 random_fe(nz);
26 } while (secp256k1_fe_is_zero(nz));
27}
28
29static void ge_equals_ge(const secp256k1_ge *a, const secp256k1_ge *b) {
30 CHECK(a->infinity == b->infinity);
31 if (a->infinity) {
32 return;
33 }
34 CHECK(secp256k1_fe_equal(&a->x, &b->x));
35 CHECK(secp256k1_fe_equal(&a->y, &b->y));
36}
37
38static void ge_equals_gej(const secp256k1_ge *a, const secp256k1_gej *b) {
39 secp256k1_fe z2s;
40 secp256k1_fe u1, u2, s1, s2;
41 CHECK(a->infinity == b->infinity);
42 if (a->infinity) {
43 return;
44 }
45 /* Check a.x * b.z^2 == b.x && a.y * b.z^3 == b.y, to avoid inverses. */
46 secp256k1_fe_sqr(&z2s, &b->z);
47 secp256k1_fe_mul(&u1, &a->x, &z2s);
48 u2 = b->x;
49 secp256k1_fe_mul(&s1, &a->y, &z2s); secp256k1_fe_mul(&s1, &s1, &b->z);
50 s2 = b->y;
51 CHECK(secp256k1_fe_equal(&u1, &u2));
52 CHECK(secp256k1_fe_equal(&s1, &s2));
53}
54
55#endif /* SECP256K1_TESTUTIL_H */
#define secp256k1_fe_mul
Definition: field.h:94
#define secp256k1_fe_is_zero
Definition: field.h:85
#define secp256k1_fe_set_b32_limit
Definition: field.h:89
#define secp256k1_fe_sqr
Definition: field.h:95
static int secp256k1_fe_equal(const secp256k1_fe *a, const secp256k1_fe *b)
Determine whether two field elements are equal.
#define CHECK(cond)
Definition: util.h:128
This field implementation represents the value as 10 uint32_t limbs in base 2^26.
Definition: field_10x26.h:14
A group element in affine coordinates on the secp256k1 curve, or occasionally on an isomorphic curve ...
Definition: group.h:16
int infinity
Definition: group.h:19
secp256k1_fe x
Definition: group.h:17
secp256k1_fe y
Definition: group.h:18
A group element of the secp256k1 curve, in jacobian coordinates.
Definition: group.h:28
secp256k1_fe y
Definition: group.h:30
secp256k1_fe x
Definition: group.h:29
int infinity
Definition: group.h:32
secp256k1_fe z
Definition: group.h:31
static void secp256k1_testrand256(unsigned char *b32)
Generate a pseudorandom 32-byte array.
static void ge_equals_ge(const secp256k1_ge *a, const secp256k1_ge *b)
Definition: testutil.h:29
static void ge_equals_gej(const secp256k1_ge *a, const secp256k1_gej *b)
Definition: testutil.h:38
static void random_fe(secp256k1_fe *x)
Definition: testutil.h:13
static void random_fe_non_zero(secp256k1_fe *nz)
Definition: testutil.h:23