A super trimmed down TLS stack, GPL licensed

Dependents:   MiniTLS-HTTPS-Example

MiniTLS - A super trimmed down TLS/SSL Library for embedded devices Author: Donatien Garnier Copyright (C) 2013-2014 AppNearMe Ltd

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

Committer:
MiniTLS
Date:
Fri Jun 06 10:49:02 2014 +0000
Revision:
0:35aa5be3b78d
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
MiniTLS 0:35aa5be3b78d 1 /*
MiniTLS 0:35aa5be3b78d 2 MuTLS - A super trimmed down TLS/SSL Library for embedded devices
MiniTLS 0:35aa5be3b78d 3 Author: Donatien Garnier
MiniTLS 0:35aa5be3b78d 4 Copyright (C) 2013-2014 AppNearMe Ltd
MiniTLS 0:35aa5be3b78d 5
MiniTLS 0:35aa5be3b78d 6 This program is free software; you can redistribute it and/or
MiniTLS 0:35aa5be3b78d 7 modify it under the terms of the GNU General Public License
MiniTLS 0:35aa5be3b78d 8 as published by the Free Software Foundation; either version 2
MiniTLS 0:35aa5be3b78d 9 of the License, or (at your option) any later version.
MiniTLS 0:35aa5be3b78d 10
MiniTLS 0:35aa5be3b78d 11 This program is distributed in the hope that it will be useful,
MiniTLS 0:35aa5be3b78d 12 but WITHOUT ANY WARRANTY; without even the implied warranty of
MiniTLS 0:35aa5be3b78d 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
MiniTLS 0:35aa5be3b78d 14 GNU General Public License for more details.
MiniTLS 0:35aa5be3b78d 15
MiniTLS 0:35aa5be3b78d 16 You should have received a copy of the GNU General Public License
MiniTLS 0:35aa5be3b78d 17 along with this program; if not, write to the Free Software
MiniTLS 0:35aa5be3b78d 18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
MiniTLS 0:35aa5be3b78d 19 *//* LibTomCrypt, modular cryptographic library -- Tom St Denis
MiniTLS 0:35aa5be3b78d 20 *
MiniTLS 0:35aa5be3b78d 21 * LibTomCrypt is a library that provides various cryptographic
MiniTLS 0:35aa5be3b78d 22 * algorithms in a highly modular and flexible manner.
MiniTLS 0:35aa5be3b78d 23 *
MiniTLS 0:35aa5be3b78d 24 * The library is free for all purposes without any express
MiniTLS 0:35aa5be3b78d 25 * guarantee it works.
MiniTLS 0:35aa5be3b78d 26 *
MiniTLS 0:35aa5be3b78d 27 * Tom St Denis, tomstdenis@gmail.com, http://libtom.org
MiniTLS 0:35aa5be3b78d 28 */
MiniTLS 0:35aa5be3b78d 29
MiniTLS 0:35aa5be3b78d 30 /* Implements ECC over Z/pZ for curve y^2 = x^3 - 3x + b
MiniTLS 0:35aa5be3b78d 31 *
MiniTLS 0:35aa5be3b78d 32 * All curves taken from NIST recommendation paper of July 1999
MiniTLS 0:35aa5be3b78d 33 * Available at http://csrc.nist.gov/cryptval/dss.htm
MiniTLS 0:35aa5be3b78d 34 */
MiniTLS 0:35aa5be3b78d 35 #include "ltc.h"
MiniTLS 0:35aa5be3b78d 36
MiniTLS 0:35aa5be3b78d 37 /**
MiniTLS 0:35aa5be3b78d 38 @file ltc_ecc_map.c
MiniTLS 0:35aa5be3b78d 39 ECC Crypto, Tom St Denis
MiniTLS 0:35aa5be3b78d 40 */
MiniTLS 0:35aa5be3b78d 41
MiniTLS 0:35aa5be3b78d 42 #ifdef LTC_MECC
MiniTLS 0:35aa5be3b78d 43
MiniTLS 0:35aa5be3b78d 44 /**
MiniTLS 0:35aa5be3b78d 45 Map a projective jacbobian point back to affine space
MiniTLS 0:35aa5be3b78d 46 @param P [in/out] The point to map
MiniTLS 0:35aa5be3b78d 47 @param modulus The modulus of the field the ECC curve is in
MiniTLS 0:35aa5be3b78d 48 @param mp The "b" value from montgomery_setup()
MiniTLS 0:35aa5be3b78d 49 @return MUTLS_OK on success
MiniTLS 0:35aa5be3b78d 50 */
MiniTLS 0:35aa5be3b78d 51 int ltc_ecc_map(ecc_point *P, void *modulus, void *mp)
MiniTLS 0:35aa5be3b78d 52 {
MiniTLS 0:35aa5be3b78d 53 fp_int t1, t2;
MiniTLS 0:35aa5be3b78d 54 int err;
MiniTLS 0:35aa5be3b78d 55
MiniTLS 0:35aa5be3b78d 56 LTC_ARGCHK(P != NULL);
MiniTLS 0:35aa5be3b78d 57 LTC_ARGCHK(modulus != NULL);
MiniTLS 0:35aa5be3b78d 58 LTC_ARGCHK(mp != NULL);
MiniTLS 0:35aa5be3b78d 59
MiniTLS 0:35aa5be3b78d 60 if ((err = mp_init_multi(&t1, &t2, NULL)) != MUTLS_OK) {
MiniTLS 0:35aa5be3b78d 61 return MUTLS_ERR_MEMORY;
MiniTLS 0:35aa5be3b78d 62 }
MiniTLS 0:35aa5be3b78d 63
MiniTLS 0:35aa5be3b78d 64 /* first map z back to normal */
MiniTLS 0:35aa5be3b78d 65 /*if ((err = */mp_montgomery_reduce(&P->z, modulus, mp);/*) != MUTLS_OK) { goto done; }*/
MiniTLS 0:35aa5be3b78d 66
MiniTLS 0:35aa5be3b78d 67 /* get 1/z */
MiniTLS 0:35aa5be3b78d 68 if ((err = mp_invmod(&P->z, modulus, &t1)) != MUTLS_OK) { goto done; }
MiniTLS 0:35aa5be3b78d 69
MiniTLS 0:35aa5be3b78d 70 /* get 1/z^2 and 1/z^3 */
MiniTLS 0:35aa5be3b78d 71 /*if ((err = */mp_sqr(&t1, &t2);/*) != MUTLS_OK) { goto done; }*/
MiniTLS 0:35aa5be3b78d 72 if ((err = mp_mod(&t2, modulus, &t2)) != MUTLS_OK) { goto done; }
MiniTLS 0:35aa5be3b78d 73 /*if ((err =*/ mp_mul(&t1, &t2, &t1);/*) != MUTLS_OK) { goto done; }*/
MiniTLS 0:35aa5be3b78d 74 /*if ((err =*/ mp_mod(&t1, modulus, &t1);/*) != MUTLS_OK) { goto done; }*/
MiniTLS 0:35aa5be3b78d 75
MiniTLS 0:35aa5be3b78d 76 /* multiply against x/y */
MiniTLS 0:35aa5be3b78d 77 /*if ((err =*/ mp_mul(&P->x, &t2, &P->x);/*) != MUTLS_OK) { goto done; }*/
MiniTLS 0:35aa5be3b78d 78 /*if ((err =*/ mp_montgomery_reduce(&P->x, modulus, mp);/*) != MUTLS_OK) { goto done; }*/
MiniTLS 0:35aa5be3b78d 79 /*if ((err =*/ mp_mul(&P->y, &t1, &P->y);/*) != MUTLS_OK) { goto done; }*/
MiniTLS 0:35aa5be3b78d 80 /*if ((err =*/ mp_montgomery_reduce(&P->y, modulus, mp);/*) != MUTLS_OK) { goto done; }*/
MiniTLS 0:35aa5be3b78d 81 /*if ((err =*/ mp_set(&P->z, 1);/*) != MUTLS_OK) { goto done; }*/
MiniTLS 0:35aa5be3b78d 82
MiniTLS 0:35aa5be3b78d 83 err = MUTLS_OK;
MiniTLS 0:35aa5be3b78d 84 done:
MiniTLS 0:35aa5be3b78d 85 mp_clear_multi(&t1, &t2, NULL);
MiniTLS 0:35aa5be3b78d 86 return err;
MiniTLS 0:35aa5be3b78d 87 }
MiniTLS 0:35aa5be3b78d 88
MiniTLS 0:35aa5be3b78d 89 #endif
MiniTLS 0:35aa5be3b78d 90
MiniTLS 0:35aa5be3b78d 91 /* $Source: /cvs/libtom/libtomcrypt/src/pk/ecc/ltc_ecc_map.c,v $ */
MiniTLS 0:35aa5be3b78d 92 /* $Revision: 1.7 $ */
MiniTLS 0:35aa5be3b78d 93 /* $Date: 2007/05/12 14:32:35 $ */
MiniTLS 0:35aa5be3b78d 94