Manuel Pégourié-Gonnard | 39d2adb | 2012-10-31 09:26:55 +0100 | [diff] [blame] | 1 | /* |
| 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é-Gonnard | 883f313 | 2012-11-02 09:40:25 +0100 | [diff] [blame^] | 29 | * SEC1 http://www.secg.org/index.php?action=secg,docs_secg |
Manuel Pégourié-Gonnard | 39d2adb | 2012-10-31 09:26:55 +0100 | [diff] [blame] | 30 | * 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é-Gonnard | 1e8c8ec | 2012-10-31 19:24:21 +0100 | [diff] [blame] | 39 | /* |
| 40 | * Unallocate (the components of) a point |
| 41 | */ |
| 42 | void ecp_point_free( ecp_point *pt ) |
| 43 | { |
| 44 | if( pt == NULL ) |
| 45 | return; |
| 46 | |
Manuel Pégourié-Gonnard | 5179e46 | 2012-10-31 19:37:54 +0100 | [diff] [blame] | 47 | pt->is_zero = 1; |
Manuel Pégourié-Gonnard | 1e8c8ec | 2012-10-31 19:24:21 +0100 | [diff] [blame] | 48 | mpi_free( &( pt->X ) ); |
| 49 | mpi_free( &( pt->Y ) ); |
| 50 | } |
| 51 | |
| 52 | /* |
| 53 | * Unallocate (the components of) a group |
| 54 | */ |
| 55 | void ecp_group_free( ecp_group *grp ) |
| 56 | { |
| 57 | if( grp == NULL ) |
| 58 | return; |
| 59 | |
Manuel Pégourié-Gonnard | 883f313 | 2012-11-02 09:40:25 +0100 | [diff] [blame^] | 60 | mpi_free( &grp->P ); |
| 61 | mpi_free( &grp->B ); |
| 62 | ecp_point_free( &grp->G ); |
| 63 | mpi_free( &grp->N ); |
Manuel Pégourié-Gonnard | 1e8c8ec | 2012-10-31 19:24:21 +0100 | [diff] [blame] | 64 | } |
Manuel Pégourié-Gonnard | 39d2adb | 2012-10-31 09:26:55 +0100 | [diff] [blame] | 65 | |
Manuel Pégourié-Gonnard | 883f313 | 2012-11-02 09:40:25 +0100 | [diff] [blame^] | 66 | /* |
| 67 | * Copy the contents of Q into P |
| 68 | */ |
| 69 | int 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 | |
| 77 | cleanup: |
| 78 | return( ret ); |
| 79 | } |
Manuel Pégourié-Gonnard | 5179e46 | 2012-10-31 19:37:54 +0100 | [diff] [blame] | 80 | |
| 81 | |
Manuel Pégourié-Gonnard | 39d2adb | 2012-10-31 09:26:55 +0100 | [diff] [blame] | 82 | #if defined(POLARSSL_SELF_TEST) |
| 83 | |
| 84 | /* |
| 85 | * Checkup routine |
| 86 | */ |
| 87 | int ecp_self_test( int verbose ) |
| 88 | { |
| 89 | return( verbose++ ); |
| 90 | } |
| 91 | |
| 92 | #endif |
| 93 | |
| 94 | #endif |