Webserver+3d print

Dependents:   Nucleo

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers ec.h Source File

ec.h

Go to the documentation of this file.
00001 /**
00002  * @file ec.h
00003  * @brief ECC (Elliptic Curve Cryptography)
00004  *
00005  * @section License
00006  *
00007  * Copyright (C) 2010-2017 Oryx Embedded SARL. All rights reserved.
00008  *
00009  * This file is part of CycloneCrypto Open.
00010  *
00011  * This program is free software; you can redistribute it and/or
00012  * modify it under the terms of the GNU General Public License
00013  * as published by the Free Software Foundation; either version 2
00014  * of the License, or (at your option) any later version.
00015  *
00016  * This program is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  * GNU General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU General Public License
00022  * along with this program; if not, write to the Free Software Foundation,
00023  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00024  *
00025  * @author Oryx Embedded SARL (www.oryx-embedded.com)
00026  * @version 1.7.6
00027  **/
00028 
00029 #ifndef _EC_H
00030 #define _EC_H
00031 
00032 //Dependencies
00033 #include "crypto.h"
00034 #include "ec_curves.h"
00035 
00036 //Error code checking
00037 #define EC_CHECK(f) if((error = f) != NO_ERROR) goto end
00038 
00039 
00040 /**
00041  * @brief Elliptic curve point
00042  **/
00043 
00044 typedef struct
00045 {
00046    Mpi x; ///<x-coordinate
00047    Mpi y; ///<y-coordinate
00048    Mpi z; ///<z-coordinate
00049 } EcPoint;
00050 
00051 
00052 /**
00053  * @brief EC domain parameters
00054  **/
00055 
00056 typedef struct
00057 {
00058    EcCurveType type;  ///<Curve type
00059    Mpi p;             ///<Prime
00060    Mpi a;             ///<Curve parameter a
00061    Mpi b;             ///<Curve parameter b
00062    EcPoint g;         ///<Base point G
00063    Mpi q;             ///<Order of the point G
00064    EcFastModAlgo mod; ///<Fast modular reduction
00065 } EcDomainParameters;
00066 
00067 
00068 //EC related constants
00069 extern const uint8_t EC_PUBLIC_KEY_OID[7];
00070 
00071 //EC related functions
00072 void ecInitDomainParameters(EcDomainParameters *params);
00073 void ecFreeDomainParameters(EcDomainParameters *params);
00074 
00075 error_t ecLoadDomainParameters(EcDomainParameters *params, const EcCurveInfo *curveInfo);
00076 
00077 void ecInit(EcPoint *r);
00078 void ecFree(EcPoint *r);
00079 
00080 error_t ecCopy(EcPoint *r, const EcPoint *s);
00081 
00082 error_t ecImport(const EcDomainParameters *params,
00083    EcPoint *r, const uint8_t *data, size_t length);
00084 
00085 error_t ecExport(const EcDomainParameters *params,
00086    const EcPoint *a, uint8_t *data, size_t *length);
00087 
00088 error_t ecProjectify(const EcDomainParameters *params, EcPoint *r, const EcPoint *s);
00089 error_t ecAffinify(const EcDomainParameters *params, EcPoint *r, const EcPoint *s);
00090 
00091 bool_t ecIsPointAffine(const EcDomainParameters *params, const EcPoint *s);
00092 
00093 error_t ecDouble(const EcDomainParameters *params, EcPoint *r, const EcPoint *s);
00094 
00095 error_t ecAdd(const EcDomainParameters *params, EcPoint *r, const EcPoint *s, const EcPoint *t);
00096 error_t ecFullAdd(const EcDomainParameters *params, EcPoint *r, const EcPoint *s, const EcPoint *t);
00097 error_t ecFullSub(const EcDomainParameters *params, EcPoint *r, const EcPoint *s, const EcPoint *t);
00098 
00099 error_t ecMult(const EcDomainParameters *params, EcPoint *r, const Mpi *d, const EcPoint *s);
00100 
00101 error_t ecTwinMult(const EcDomainParameters *params, EcPoint *r,
00102    const Mpi *d0, const EcPoint *s, const Mpi *d1, const EcPoint *t);
00103 
00104 error_t ecAddMod(const EcDomainParameters *params, Mpi *r, const Mpi *a, const Mpi *b);
00105 error_t ecSubMod(const EcDomainParameters *params, Mpi *r, const Mpi *a, const Mpi *b);
00106 error_t ecMulMod(const EcDomainParameters *params, Mpi *r, const Mpi *a, const Mpi *b);
00107 error_t ecSqrMod(const EcDomainParameters *params, Mpi *r, const Mpi *a);
00108 
00109 #endif
00110