]> Git Repo - secp256k1.git/blame - src/group.h
Label variable-time functions correctly and don't use those in sign
[secp256k1.git] / src / group.h
CommitLineData
0a433ea2
PW
1// Copyright (c) 2013 Pieter Wuille
2// Distributed under the MIT/X11 software license, see the accompanying
3// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
b394396b
PW
5#ifndef _SECP256K1_GROUP_
6#define _SECP256K1_GROUP_
7
607884fc 8#include "num.h"
b394396b
PW
9#include "field.h"
10
7fef6619 11/** A group element of the secp256k1 curve, in affine coordinates. */
254327e4
PW
12typedef struct {
13 secp256k1_fe_t x;
14 secp256k1_fe_t y;
7fef6619 15 int infinity; // whether this represents the point at infinity
254327e4
PW
16} secp256k1_ge_t;
17
7fef6619 18/** A group element of the secp256k1 curve, in jacobian coordinates. */
254327e4 19typedef struct {
7fef6619
PW
20 secp256k1_fe_t x; // actual X: x/z^2
21 secp256k1_fe_t y; // actual Y: y/z^3
254327e4 22 secp256k1_fe_t z;
7fef6619 23 int infinity; // whether this represents the point at infinity
254327e4
PW
24} secp256k1_gej_t;
25
7fef6619 26/** Global constants related to the group */
254327e4 27typedef struct {
7fef6619 28 secp256k1_num_t order; // the order of the curve (= order of its generator)
d0b33489 29 secp256k1_num_t half_order; // half the order of the curve (= order of its generator)
7fef6619
PW
30 secp256k1_ge_t g; // the generator point
31
4d79bebd 32#ifdef USE_ENDOMORPHISM
7fef6619 33 // constants related to secp256k1's efficiently computable endomorphism
254327e4
PW
34 secp256k1_fe_t beta;
35 secp256k1_num_t lambda, a1b2, b1, a2;
4d79bebd 36#endif
254327e4
PW
37} secp256k1_ge_consts_t;
38
f491cd35 39static const secp256k1_ge_consts_t *secp256k1_ge_consts = NULL;
254327e4 40
7fef6619 41/** Initialize the group module. */
254327e4 42void static secp256k1_ge_start(void);
7fef6619
PW
43
44/** De-initialize the group module. */
254327e4 45void static secp256k1_ge_stop(void);
7fef6619
PW
46
47/** Set a group element equal to the point at infinity */
254327e4 48void static secp256k1_ge_set_infinity(secp256k1_ge_t *r);
7fef6619
PW
49
50/** Set a group element equal to the point with given X and Y coordinates */
254327e4 51void static secp256k1_ge_set_xy(secp256k1_ge_t *r, const secp256k1_fe_t *x, const secp256k1_fe_t *y);
7fef6619 52
09ca4f32
PD
53/** Set a group element (affine) equal to the point with the given X coordinate, and given oddness
54 * for Y. Return value indicates whether the result is valid. */
55int static secp256k1_ge_set_xo(secp256k1_ge_t *r, const secp256k1_fe_t *x, int odd);
764332d0 56
7fef6619 57/** Check whether a group element is the point at infinity. */
254327e4 58int static secp256k1_ge_is_infinity(const secp256k1_ge_t *a);
7fef6619 59
764332d0
PW
60/** Check whether a group element is valid (i.e., on the curve). */
61int static secp256k1_ge_is_valid(const secp256k1_ge_t *a);
62
254327e4 63void static secp256k1_ge_neg(secp256k1_ge_t *r, const secp256k1_ge_t *a);
7fef6619
PW
64
65/** Get a hex representation of a point. *rlen will be overwritten with the real length. */
254327e4 66void static secp256k1_ge_get_hex(char *r, int *rlen, const secp256k1_ge_t *a);
7fef6619
PW
67
68/** Set a group element equal to another which is given in jacobian coordinates */
f11ff5be 69void static secp256k1_ge_set_gej(secp256k1_ge_t *r, secp256k1_gej_t *a);
254327e4 70
f16be77f 71/** Set a batch of group elements equal to the inputs given in jacobian coordinates */
da55986f 72void static secp256k1_ge_set_all_gej_var(size_t len, secp256k1_ge_t r[len], const secp256k1_gej_t a[len]);
f16be77f 73
7fef6619
PW
74
75/** Set a group element (jacobian) equal to the point at infinity. */
254327e4 76void static secp256k1_gej_set_infinity(secp256k1_gej_t *r);
7fef6619
PW
77
78/** Set a group element (jacobian) equal to the point with given X and Y coordinates. */
254327e4 79void static secp256k1_gej_set_xy(secp256k1_gej_t *r, const secp256k1_fe_t *x, const secp256k1_fe_t *y);
7fef6619 80
7fef6619 81/** Set a group element (jacobian) equal to another which is given in affine coordinates. */
254327e4 82void static secp256k1_gej_set_ge(secp256k1_gej_t *r, const secp256k1_ge_t *a);
7fef6619
PW
83
84/** Get the X coordinate of a group element (jacobian). */
da55986f 85void static secp256k1_gej_get_x_var(secp256k1_fe_t *r, const secp256k1_gej_t *a);
7fef6619
PW
86
87/** Set r equal to the inverse of a (i.e., mirrored around the X axis) */
254327e4 88void static secp256k1_gej_neg(secp256k1_gej_t *r, const secp256k1_gej_t *a);
7fef6619
PW
89
90/** Check whether a group element is the point at infinity. */
254327e4 91int static secp256k1_gej_is_infinity(const secp256k1_gej_t *a);
7fef6619 92
7fef6619 93/** Set r equal to the double of a. */
da55986f 94void static secp256k1_gej_double_var(secp256k1_gej_t *r, const secp256k1_gej_t *a);
7fef6619
PW
95
96/** Set r equal to the sum of a and b. */
da55986f 97void static secp256k1_gej_add_var(secp256k1_gej_t *r, const secp256k1_gej_t *a, const secp256k1_gej_t *b);
7fef6619 98
09ca4f32 99/** Set r equal to the sum of a and b (with b given in affine coordinates). This is more efficient
7fef6619 100 than secp256k1_gej_add. */
da55986f 101void static secp256k1_gej_add_ge_var(secp256k1_gej_t *r, const secp256k1_gej_t *a, const secp256k1_ge_t *b);
7fef6619
PW
102
103/** Get a hex representation of a point. *rlen will be overwritten with the real length. */
254327e4 104void static secp256k1_gej_get_hex(char *r, int *rlen, const secp256k1_gej_t *a);
7fef6619 105
399c03f2 106#ifdef USE_ENDOMORPHISM
7fef6619 107/** Set r to be equal to lambda times a, where lambda is chosen in a way such that this is very fast. */
254327e4 108void static secp256k1_gej_mul_lambda(secp256k1_gej_t *r, const secp256k1_gej_t *a);
7fef6619
PW
109
110/** Find r1 and r2 such that r1+r2*lambda = a, and r1 and r2 are maximum 128 bits long (given that a is
111 not more than 256 bits). */
da55986f 112void static secp256k1_gej_split_exp_var(secp256k1_num_t *r1, secp256k1_num_t *r2, const secp256k1_num_t *a);
399c03f2 113#endif
254327e4 114
2f6c8019
GM
115/** Clear a secp256k1_gej_t to prevent leaking sensitive information. */
116void static secp256k1_gej_clear(secp256k1_gej_t *r);
117
118/** Clear a secp256k1_ge_t to prevent leaking sensitive information. */
119void static secp256k1_ge_clear(secp256k1_ge_t *r);
120
121
b394396b 122#endif
This page took 0.041702 seconds and 4 git commands to generate.