-
Notifications
You must be signed in to change notification settings - Fork 6
/
ecp_is_inverse.c
37 lines (30 loc) · 738 Bytes
/
ecp_is_inverse.c
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
/*
* ecp_is_inverse.c
*
* Created on: Nov 20, 2015
* Author: tslld
*/
#include "ecdsa.h"
#include "ec.h"
#include "ec_point.h"
/** Compare two points P, Q on the elliptic curve EC
* \param P pointer to an ec_point structure
* \param Q pointer to an ec_point structure
* \param field BIG number, field characteristic
* \return 1 if P = -Q, otherwise returns 0
*/
bool ec_point_is_inverse(ec_point P, ec_point Q, mpz_t field) {
bool rop;
//If at infinity
if(P->infinity && Q->infinity)
return true;
else if(P->infinity || Q->infinity)
return false;
else {
mpz_t tmp; mpz_init(tmp);
mpz_sub(tmp, field, P->y);
rop = !mpz_cmp(P->x,Q->x) && !mpz_cmp(tmp,Q->y);;
mpz_clear(tmp);
return rop;
}
}