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.
ec_curves.h
00001 /** 00002 * @file ec_curves.h 00003 * @brief Elliptic curves 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_CURVES_H 00030 #define _EC_CURVES_H 00031 00032 //Dependencies 00033 #include "crypto.h" 00034 #include "mpi.h" 00035 00036 //SECG curves 00037 #define SECP112R1_CURVE (&secp112r1Curve) 00038 #define SECP112R2_CURVE (&secp112r2Curve) 00039 #define SECP128R1_CURVE (&secp128r1Curve) 00040 #define SECP128R2_CURVE (&secp128r2Curve) 00041 #define SECP160K1_CURVE (&secp160k1Curve) 00042 #define SECP160R1_CURVE (&secp160r1Curve) 00043 #define SECP160R2_CURVE (&secp160r2Curve) 00044 #define SECP192K1_CURVE (&secp192k1Curve) 00045 #define SECP192R1_CURVE (&secp192r1Curve) 00046 #define SECP224K1_CURVE (&secp224k1Curve) 00047 #define SECP224R1_CURVE (&secp224r1Curve) 00048 #define SECP256K1_CURVE (&secp256k1Curve) 00049 #define SECP256R1_CURVE (&secp256r1Curve) 00050 #define SECP384R1_CURVE (&secp384r1Curve) 00051 #define SECP521R1_CURVE (&secp521r1Curve) 00052 00053 //Brainpool curves 00054 #define BRAINPOOLP160R1_CURVE (&brainpoolP160r1Curve) 00055 #define BRAINPOOLP192R1_CURVE (&brainpoolP192r1Curve) 00056 #define BRAINPOOLP224R1_CURVE (&brainpoolP224r1Curve) 00057 #define BRAINPOOLP256R1_CURVE (&brainpoolP256r1Curve) 00058 #define BRAINPOOLP320R1_CURVE (&brainpoolP320r1Curve) 00059 #define BRAINPOOLP384R1_CURVE (&brainpoolP384r1Curve) 00060 #define BRAINPOOLP512R1_CURVE (&brainpoolP512r1Curve) 00061 00062 00063 /** 00064 * @brief Elliptic curve type 00065 **/ 00066 00067 typedef enum 00068 { 00069 EC_CURVE_TYPE_NONE = 0, 00070 EC_CURVE_TYPE_SECT_K1 = 1, 00071 EC_CURVE_TYPE_SECT_R1 = 2, 00072 EC_CURVE_TYPE_SECT_R2 = 3, 00073 EC_CURVE_TYPE_SECP_K1 = 4, 00074 EC_CURVE_TYPE_SECP_R1 = 5, 00075 EC_CURVE_TYPE_SECP_R2 = 6, 00076 EC_CURVE_TYPE_BRAINPOOLP_R1 = 7 00077 } EcCurveType; 00078 00079 00080 /** 00081 * @brief Fast modular reduction 00082 **/ 00083 00084 typedef error_t (*EcFastModAlgo)(Mpi *a, const Mpi *p); 00085 00086 00087 /** 00088 * @brief Elliptic curve parameters 00089 **/ 00090 00091 typedef struct 00092 { 00093 const char_t *name; ///<Curve name 00094 const uint8_t *oid; ///<Object identifier 00095 size_t oidSize; ///<OID size 00096 EcCurveType type; ///<Curve type 00097 const uint8_t p[66]; ///<Prime modulus p 00098 size_t pLen; ///<Length of p 00099 const uint8_t a[66]; ///<Curve parameter a 00100 size_t aLen; ///<Length of a 00101 const uint8_t b[66]; ///<Curve parameter b 00102 size_t bLen; ///<Length of b 00103 const uint8_t gx[66]; ///<x-coordinate of the base point G 00104 size_t gxLen; ///<Length of Gx 00105 const uint8_t gy[66]; ///<y-coordinate of the base point G 00106 size_t gyLen; ///<Length of Gy 00107 const uint8_t q[66]; ///<Order of the base point G 00108 size_t qLen; ///<Length of q 00109 uint32_t h; ///<Cofactor h 00110 EcFastModAlgo mod; ///<Fast modular reduction 00111 } EcCurveInfo; 00112 00113 00114 //Constants 00115 extern const uint8_t SECP112R1_OID[5]; 00116 extern const uint8_t SECP112R2_OID[5]; 00117 extern const uint8_t SECP128R1_OID[5]; 00118 extern const uint8_t SECP128R2_OID[5]; 00119 extern const uint8_t SECP160K1_OID[5]; 00120 extern const uint8_t SECP160R1_OID[5]; 00121 extern const uint8_t SECP160R2_OID[5]; 00122 extern const uint8_t SECP192K1_OID[5]; 00123 extern const uint8_t SECP192R1_OID[8]; 00124 extern const uint8_t SECP224K1_OID[5]; 00125 extern const uint8_t SECP224R1_OID[5]; 00126 extern const uint8_t SECP256K1_OID[5]; 00127 extern const uint8_t SECP256R1_OID[8]; 00128 extern const uint8_t SECP384R1_OID[5]; 00129 extern const uint8_t SECP521R1_OID[5]; 00130 extern const uint8_t BRAINPOOLP160R1_OID[10]; 00131 extern const uint8_t BRAINPOOLP192R1_OID[10]; 00132 extern const uint8_t BRAINPOOLP224R1_OID[10]; 00133 extern const uint8_t BRAINPOOLP256R1_OID[10]; 00134 extern const uint8_t BRAINPOOLP320R1_OID[10]; 00135 extern const uint8_t BRAINPOOLP384R1_OID[10]; 00136 extern const uint8_t BRAINPOOLP512R1_OID[10]; 00137 00138 extern const EcCurveInfo secp112r1Curve; 00139 extern const EcCurveInfo secp112r2Curve; 00140 extern const EcCurveInfo secp128r1Curve; 00141 extern const EcCurveInfo secp128r2Curve; 00142 extern const EcCurveInfo secp160k1Curve; 00143 extern const EcCurveInfo secp160r1Curve; 00144 extern const EcCurveInfo secp160r2Curve; 00145 extern const EcCurveInfo secp192k1Curve; 00146 extern const EcCurveInfo secp192r1Curve; 00147 extern const EcCurveInfo secp224k1Curve; 00148 extern const EcCurveInfo secp224r1Curve; 00149 extern const EcCurveInfo secp256k1Curve; 00150 extern const EcCurveInfo secp256r1Curve; 00151 extern const EcCurveInfo secp384r1Curve; 00152 extern const EcCurveInfo secp521r1Curve; 00153 extern const EcCurveInfo brainpoolP160r1Curve; 00154 extern const EcCurveInfo brainpoolP192r1Curve; 00155 extern const EcCurveInfo brainpoolP224r1Curve; 00156 extern const EcCurveInfo brainpoolP256r1Curve; 00157 extern const EcCurveInfo brainpoolP320r1Curve; 00158 extern const EcCurveInfo brainpoolP384r1Curve; 00159 extern const EcCurveInfo brainpoolP512r1Curve; 00160 00161 //Fast modular reduction 00162 error_t secp128r1Mod(Mpi *a, const Mpi *p); 00163 error_t secp128r2Mod(Mpi *a, const Mpi *p); 00164 error_t secp160k1Mod(Mpi *a, const Mpi *p); 00165 error_t secp160r1Mod(Mpi *a, const Mpi *p); 00166 error_t secp160r2Mod(Mpi *a, const Mpi *p); 00167 error_t secp192k1Mod(Mpi *a, const Mpi *p); 00168 error_t secp192r1Mod(Mpi *a, const Mpi *p); 00169 error_t secp224k1Mod(Mpi *a, const Mpi *p); 00170 error_t secp224r1Mod(Mpi *a, const Mpi *p); 00171 error_t secp256k1Mod(Mpi *a, const Mpi *p); 00172 error_t secp256r1Mod(Mpi *a, const Mpi *p); 00173 error_t secp384r1Mod(Mpi *a, const Mpi *p); 00174 error_t secp521r1Mod(Mpi *a, const Mpi *p); 00175 00176 const EcCurveInfo *ecGetCurveInfo(const uint8_t *oid, size_t length); 00177 00178 #endif 00179
Generated on Tue Jul 12 2022 17:10:13 by
1.7.2