2 * Copyright (C) 2011-2012 Free Software Foundation, Inc.
4 * Author: Ilya Tumaykin
6 * This file is part of GNUTLS.
8 * The GNUTLS library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public License
10 * as published by the Free Software Foundation; either version 3 of
11 * the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>
26 Check if the given point is the neutral point
27 @param P The point to check
28 @param modulus The modulus of the field the ECC curve is in
29 @return 0 if given point is a neutral point
30 @return 1 if given point is not a neutral point
31 @return negative value in case of error
34 ecc_projective_isneutral (ecc_point
* P
, mpz_t modulus
)
39 if (P
== NULL
|| modulus
== NULL
)
40 return GNUTLS_E_RECEIVED_ILLEGAL_PARAMETER
;
43 * neutral point is a point with projective
44 * coordinates (x,y,0) such that y^2 == x^3
45 * excluding point (0,0,0)
51 if ((err
= mp_init_multi (&t1
, &t2
, NULL
)) != 0)
57 mpz_mul (t1
, P
->x
, P
->x
);
58 mpz_mod (t1
, t1
, modulus
);
59 mpz_mul (t1
, t1
, P
->x
);
60 mpz_mod (t1
, t1
, modulus
);
62 mpz_mul (t2
, P
->y
, P
->y
);
63 mpz_mod (t2
, t2
, modulus
);
65 if ((!mpz_cmp (t1
, t2
)) && (mpz_sgn (t1
)))
67 /* Z == 0 and X^3 == Y^2 != 0
73 /* Z == 0 and X^3 != Y^2 or
75 * this should never happen */
76 err
= GNUTLS_E_RECEIVED_ILLEGAL_PARAMETER
;
79 mp_clear_multi (&t1
, &t2
, NULL
);