Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of MiniTLS-GPL by
ltc_ecc_map.c
00001 /* 00002 MiniTLS - A super trimmed down TLS/SSL Library for embedded devices 00003 Author: Donatien Garnier 00004 Copyright (C) 2013-2014 AppNearMe Ltd 00005 00006 This program is free software; you can redistribute it and/or 00007 modify it under the terms of the GNU General Public License 00008 as published by the Free Software Foundation; either version 2 00009 of the License, or (at your option) any later version. 00010 00011 This program is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 GNU General Public License for more details. 00015 00016 You should have received a copy of the GNU General Public License 00017 along with this program; if not, write to the Free Software 00018 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00019 *//* LibTomCrypt, modular cryptographic library -- Tom St Denis 00020 * 00021 * LibTomCrypt is a library that provides various cryptographic 00022 * algorithms in a highly modular and flexible manner. 00023 * 00024 * The library is free for all purposes without any express 00025 * guarantee it works. 00026 * 00027 * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 00028 */ 00029 00030 /* Implements ECC over Z/pZ for curve y^2 = x^3 - 3x + b 00031 * 00032 * All curves taken from NIST recommendation paper of July 1999 00033 * Available at http://csrc.nist.gov/cryptval/dss.htm 00034 */ 00035 #include "ltc.h" 00036 00037 /** 00038 @file ltc_ecc_map.c 00039 ECC Crypto, Tom St Denis 00040 */ 00041 00042 #ifdef LTC_MECC 00043 00044 /** 00045 Map a projective jacbobian point back to affine space 00046 @param P [in/out] The point to map 00047 @param modulus The modulus of the field the ECC curve is in 00048 @param mp The "b" value from montgomery_setup() 00049 @return MINITLS_OK on success 00050 */ 00051 int ltc_ecc_map(ecc_point *P, void *modulus, void *mp) 00052 { 00053 fp_int t1, t2; 00054 int err; 00055 00056 LTC_ARGCHK(P != NULL); 00057 LTC_ARGCHK(modulus != NULL); 00058 LTC_ARGCHK(mp != NULL); 00059 00060 if ((err = mp_init_multi(&t1, &t2, NULL)) != MINITLS_OK) { 00061 return MINITLS_ERR_MEMORY; 00062 } 00063 00064 /* first map z back to normal */ 00065 /*if ((err = */mp_montgomery_reduce(&P->z, modulus, mp);/*) != MINITLS_OK) { goto done; }*/ 00066 00067 /* get 1/z */ 00068 if ((err = mp_invmod(&P->z, modulus, &t1)) != MINITLS_OK) { goto done; } 00069 00070 /* get 1/z^2 and 1/z^3 */ 00071 /*if ((err = */mp_sqr(&t1, &t2);/*) != MINITLS_OK) { goto done; }*/ 00072 if ((err = mp_mod(&t2, modulus, &t2)) != MINITLS_OK) { goto done; } 00073 /*if ((err =*/ mp_mul(&t1, &t2, &t1);/*) != MINITLS_OK) { goto done; }*/ 00074 /*if ((err =*/ mp_mod(&t1, modulus, &t1);/*) != MINITLS_OK) { goto done; }*/ 00075 00076 /* multiply against x/y */ 00077 /*if ((err =*/ mp_mul(&P->x, &t2, &P->x);/*) != MINITLS_OK) { goto done; }*/ 00078 /*if ((err =*/ mp_montgomery_reduce(&P->x, modulus, mp);/*) != MINITLS_OK) { goto done; }*/ 00079 /*if ((err =*/ mp_mul(&P->y, &t1, &P->y);/*) != MINITLS_OK) { goto done; }*/ 00080 /*if ((err =*/ mp_montgomery_reduce(&P->y, modulus, mp);/*) != MINITLS_OK) { goto done; }*/ 00081 /*if ((err =*/ mp_set(&P->z, 1);/*) != MINITLS_OK) { goto done; }*/ 00082 00083 err = MINITLS_OK; 00084 done: 00085 mp_clear_multi(&t1, &t2, NULL); 00086 return err; 00087 } 00088 00089 #endif 00090 00091 /* $Source: /cvs/libtom/libtomcrypt/src/pk/ecc/ltc_ecc_map.c,v $ */ 00092 /* $Revision: 1.7 $ */ 00093 /* $Date: 2007/05/12 14:32:35 $ */ 00094
Generated on Tue Jul 12 2022 19:20:10 by
1.7.2
