blob: 6c3b4a8b456d9152e80623fb2793d576ff4aac49 [file] [log] [blame]
Manuel Pégourié-Gonnard39d2adb2012-10-31 09:26:55 +01001/*
2 * Elliptic curves over GF(p)
3 *
4 * Copyright (C) 2012, Brainspark B.V.
5 *
6 * This file is part of PolarSSL (http://www.polarssl.org)
7 * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
8 *
9 * All rights reserved.
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License along
22 * with this program; if not, write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 */
25
26/*
27 * References:
28 *
Manuel Pégourié-Gonnard883f3132012-11-02 09:40:25 +010029 * SEC1 http://www.secg.org/index.php?action=secg,docs_secg
Manuel Pégourié-Gonnard39d2adb2012-10-31 09:26:55 +010030 * Guide to Elliptic Curve Cryptography - Hankerson, Menezes, Vanstone
31 */
32
33#include "polarssl/config.h"
34
35#if defined(POLARSSL_ECP_C)
36
37#include "polarssl/ecp.h"
38
Manuel Pégourié-Gonnard1e8c8ec2012-10-31 19:24:21 +010039/*
40 * Unallocate (the components of) a point
41 */
42void ecp_point_free( ecp_point *pt )
43{
44 if( pt == NULL )
45 return;
46
Manuel Pégourié-Gonnard5179e462012-10-31 19:37:54 +010047 pt->is_zero = 1;
Manuel Pégourié-Gonnard1e8c8ec2012-10-31 19:24:21 +010048 mpi_free( &( pt->X ) );
49 mpi_free( &( pt->Y ) );
50}
51
52/*
53 * Unallocate (the components of) a group
54 */
55void ecp_group_free( ecp_group *grp )
56{
57 if( grp == NULL )
58 return;
59
Manuel Pégourié-Gonnard883f3132012-11-02 09:40:25 +010060 mpi_free( &grp->P );
61 mpi_free( &grp->B );
62 ecp_point_free( &grp->G );
63 mpi_free( &grp->N );
Manuel Pégourié-Gonnard1e8c8ec2012-10-31 19:24:21 +010064}
Manuel Pégourié-Gonnard39d2adb2012-10-31 09:26:55 +010065
Manuel Pégourié-Gonnard883f3132012-11-02 09:40:25 +010066/*
67 * Copy the contents of Q into P
68 */
69int ecp_copy( ecp_point *P, const ecp_point *Q )
70{
71 int ret;
72
73 P->is_zero = Q->is_zero;
74 MPI_CHK( mpi_copy( &P->X, &Q->X ) );
75 MPI_CHK( mpi_copy( &P->Y, &Q->Y ) );
76
77cleanup:
78 return( ret );
79}
Manuel Pégourié-Gonnard5179e462012-10-31 19:37:54 +010080
81
Manuel Pégourié-Gonnard39d2adb2012-10-31 09:26:55 +010082#if defined(POLARSSL_SELF_TEST)
83
84/*
85 * Checkup routine
86 */
87int ecp_self_test( int verbose )
88{
89 return( verbose++ );
90}
91
92#endif
93
94#endif