-
Notifications
You must be signed in to change notification settings - Fork 3
/
ec_pqr.h
95 lines (77 loc) · 2.03 KB
/
ec_pqr.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*
* Copyright 2016 naehrwert
* Licensed under the terms of the GNU GPL, version 2
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
*/
#ifndef _EC_PQR_H_
#define _EC_PQR_H_
#include "pqr.h"
#define POINT_CMP_E 1
#define POINT_CMP_NE 0
/*! Elliptic curve (over polynomial quotient ring) point. */
typedef struct _ec_pqr_point
{
/*! x coord. */
poly_t *x;
/*! y coord. */
poly_t *y;
} ec_pqr_point_t;
/*! Elliptic curve (over polynomial quotient ring) group parameters (defining equation: y^2 = x^3 + ax + b). */
typedef struct _ec_pqr_group
{
/*! Modulus. */
poly_t *p;
/*! Parameter a. (mon!) */
poly_t *a;
/*! Parameter b. (mon!) */
poly_t *b;
} ec_pqr_group_t;
/*!
* \brief Allocate point.
*/
ec_pqr_point_t *ec_pqr_point_alloc(ec_pqr_group_t *ecg);
/*!
* \brief Free point.
*/
void ec_pqr_point_free(ec_pqr_point_t *p);
/*!
* \brief Copy point.
*/
ec_pqr_point_t *ec_pqr_point_copy(ec_pqr_point_t *d, ec_pqr_point_t *s);
/*!
* \brief Compare points.
*/
int ec_pqr_point_cmp(ec_pqr_point_t *p, ec_pqr_point_t *q);
/*!
* \brief Zero out point.
*/
ec_pqr_point_t *ec_pqr_point_zero(ec_pqr_point_t *p);
/*!
* \brief Test for zero point.
*/
int ec_pqr_point_is_zero(ec_pqr_point_t *p);
/*!
* \brief Convert point to montgomery form.
*/
void ec_pqr_point_to_mon(ec_pqr_point_t *p);
/*!
* \brief Convert point from montgomery form.
*/
void ec_pqr_point_from_mon(ec_pqr_point_t *p);
/*!
* \brief Negate point.
*/
ec_pqr_point_t *ec_pqr_point_neg(ec_pqr_point_t *r, ec_pqr_point_t *p, ec_pqr_group_t *ecg);
/*!
* \brief Double point.
*/
ec_pqr_point_t *ec_pqr_point_double(ec_pqr_point_t *r, ec_pqr_point_t *p, ec_pqr_group_t *ecg);
/*!
* \brief Add two points.
*/
ec_pqr_point_t *ec_pqr_point_add(ec_pqr_point_t *r, ec_pqr_point_t *p, ec_pqr_point_t *q, ec_pqr_group_t *ecg);
/*!
* \brief Multiply point with bignum (d = a * b).
*/
ec_pqr_point_t *ec_pqr_point_mul(ec_pqr_point_t *d, bn_t *a, ec_pqr_point_t *b, ec_pqr_group_t *ecg);
#endif // _EC_PQR_H_