corrected copyright notices
[gnutls.git] / lib / nettle / ecc_projective_negate_point.c
blob0021e050efe0e750b0d094784c4a0a9754c4b418
1 /*
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/>
23 #include "ecc.h"
26 Negate an ECC point
27 @param P The point to negate
28 @param R [out] The destination of the negate
29 @param modulus The modulus of the field the ECC curve is in
30 @return GNUTLS_E_SUCCESS on success
32 int
33 ecc_projective_negate_point (ecc_point * P, ecc_point * R, mpz_t modulus)
36 if (P == NULL || R == NULL)
37 return GNUTLS_E_RECEIVED_ILLEGAL_PARAMETER;
39 if (ecc_projective_isneutral (P, modulus))
41 /* we set R.y to (modulus - P.y) to avoid negative coordinates */
42 mpz_set (R->x, P->x);
43 mpz_sub (R->y, modulus, P->y);
44 mpz_mod (R->y, R->y, modulus);
45 mpz_set (R->z, P->z);
47 else
49 /* -neutral = neutral */
50 mpz_set_ui (R->x, 1);
51 mpz_set_ui (R->y, 1);
52 mpz_set_ui (R->z, 0);
55 return GNUTLS_E_SUCCESS;