Webserver+3d print
cyclone_crypto/ec_curves.h@0:8918a71cdbe9, 2017-02-04 (annotated)
- Committer:
- Sergunb
- Date:
- Sat Feb 04 18:15:49 2017 +0000
- Revision:
- 0:8918a71cdbe9
nothing else
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Sergunb | 0:8918a71cdbe9 | 1 | /** |
Sergunb | 0:8918a71cdbe9 | 2 | * @file ec_curves.h |
Sergunb | 0:8918a71cdbe9 | 3 | * @brief Elliptic curves |
Sergunb | 0:8918a71cdbe9 | 4 | * |
Sergunb | 0:8918a71cdbe9 | 5 | * @section License |
Sergunb | 0:8918a71cdbe9 | 6 | * |
Sergunb | 0:8918a71cdbe9 | 7 | * Copyright (C) 2010-2017 Oryx Embedded SARL. All rights reserved. |
Sergunb | 0:8918a71cdbe9 | 8 | * |
Sergunb | 0:8918a71cdbe9 | 9 | * This file is part of CycloneCrypto Open. |
Sergunb | 0:8918a71cdbe9 | 10 | * |
Sergunb | 0:8918a71cdbe9 | 11 | * This program is free software; you can redistribute it and/or |
Sergunb | 0:8918a71cdbe9 | 12 | * modify it under the terms of the GNU General Public License |
Sergunb | 0:8918a71cdbe9 | 13 | * as published by the Free Software Foundation; either version 2 |
Sergunb | 0:8918a71cdbe9 | 14 | * of the License, or (at your option) any later version. |
Sergunb | 0:8918a71cdbe9 | 15 | * |
Sergunb | 0:8918a71cdbe9 | 16 | * This program is distributed in the hope that it will be useful, |
Sergunb | 0:8918a71cdbe9 | 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
Sergunb | 0:8918a71cdbe9 | 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
Sergunb | 0:8918a71cdbe9 | 19 | * GNU General Public License for more details. |
Sergunb | 0:8918a71cdbe9 | 20 | * |
Sergunb | 0:8918a71cdbe9 | 21 | * You should have received a copy of the GNU General Public License |
Sergunb | 0:8918a71cdbe9 | 22 | * along with this program; if not, write to the Free Software Foundation, |
Sergunb | 0:8918a71cdbe9 | 23 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
Sergunb | 0:8918a71cdbe9 | 24 | * |
Sergunb | 0:8918a71cdbe9 | 25 | * @author Oryx Embedded SARL (www.oryx-embedded.com) |
Sergunb | 0:8918a71cdbe9 | 26 | * @version 1.7.6 |
Sergunb | 0:8918a71cdbe9 | 27 | **/ |
Sergunb | 0:8918a71cdbe9 | 28 | |
Sergunb | 0:8918a71cdbe9 | 29 | #ifndef _EC_CURVES_H |
Sergunb | 0:8918a71cdbe9 | 30 | #define _EC_CURVES_H |
Sergunb | 0:8918a71cdbe9 | 31 | |
Sergunb | 0:8918a71cdbe9 | 32 | //Dependencies |
Sergunb | 0:8918a71cdbe9 | 33 | #include "crypto.h" |
Sergunb | 0:8918a71cdbe9 | 34 | #include "mpi.h" |
Sergunb | 0:8918a71cdbe9 | 35 | |
Sergunb | 0:8918a71cdbe9 | 36 | //SECG curves |
Sergunb | 0:8918a71cdbe9 | 37 | #define SECP112R1_CURVE (&secp112r1Curve) |
Sergunb | 0:8918a71cdbe9 | 38 | #define SECP112R2_CURVE (&secp112r2Curve) |
Sergunb | 0:8918a71cdbe9 | 39 | #define SECP128R1_CURVE (&secp128r1Curve) |
Sergunb | 0:8918a71cdbe9 | 40 | #define SECP128R2_CURVE (&secp128r2Curve) |
Sergunb | 0:8918a71cdbe9 | 41 | #define SECP160K1_CURVE (&secp160k1Curve) |
Sergunb | 0:8918a71cdbe9 | 42 | #define SECP160R1_CURVE (&secp160r1Curve) |
Sergunb | 0:8918a71cdbe9 | 43 | #define SECP160R2_CURVE (&secp160r2Curve) |
Sergunb | 0:8918a71cdbe9 | 44 | #define SECP192K1_CURVE (&secp192k1Curve) |
Sergunb | 0:8918a71cdbe9 | 45 | #define SECP192R1_CURVE (&secp192r1Curve) |
Sergunb | 0:8918a71cdbe9 | 46 | #define SECP224K1_CURVE (&secp224k1Curve) |
Sergunb | 0:8918a71cdbe9 | 47 | #define SECP224R1_CURVE (&secp224r1Curve) |
Sergunb | 0:8918a71cdbe9 | 48 | #define SECP256K1_CURVE (&secp256k1Curve) |
Sergunb | 0:8918a71cdbe9 | 49 | #define SECP256R1_CURVE (&secp256r1Curve) |
Sergunb | 0:8918a71cdbe9 | 50 | #define SECP384R1_CURVE (&secp384r1Curve) |
Sergunb | 0:8918a71cdbe9 | 51 | #define SECP521R1_CURVE (&secp521r1Curve) |
Sergunb | 0:8918a71cdbe9 | 52 | |
Sergunb | 0:8918a71cdbe9 | 53 | //Brainpool curves |
Sergunb | 0:8918a71cdbe9 | 54 | #define BRAINPOOLP160R1_CURVE (&brainpoolP160r1Curve) |
Sergunb | 0:8918a71cdbe9 | 55 | #define BRAINPOOLP192R1_CURVE (&brainpoolP192r1Curve) |
Sergunb | 0:8918a71cdbe9 | 56 | #define BRAINPOOLP224R1_CURVE (&brainpoolP224r1Curve) |
Sergunb | 0:8918a71cdbe9 | 57 | #define BRAINPOOLP256R1_CURVE (&brainpoolP256r1Curve) |
Sergunb | 0:8918a71cdbe9 | 58 | #define BRAINPOOLP320R1_CURVE (&brainpoolP320r1Curve) |
Sergunb | 0:8918a71cdbe9 | 59 | #define BRAINPOOLP384R1_CURVE (&brainpoolP384r1Curve) |
Sergunb | 0:8918a71cdbe9 | 60 | #define BRAINPOOLP512R1_CURVE (&brainpoolP512r1Curve) |
Sergunb | 0:8918a71cdbe9 | 61 | |
Sergunb | 0:8918a71cdbe9 | 62 | |
Sergunb | 0:8918a71cdbe9 | 63 | /** |
Sergunb | 0:8918a71cdbe9 | 64 | * @brief Elliptic curve type |
Sergunb | 0:8918a71cdbe9 | 65 | **/ |
Sergunb | 0:8918a71cdbe9 | 66 | |
Sergunb | 0:8918a71cdbe9 | 67 | typedef enum |
Sergunb | 0:8918a71cdbe9 | 68 | { |
Sergunb | 0:8918a71cdbe9 | 69 | EC_CURVE_TYPE_NONE = 0, |
Sergunb | 0:8918a71cdbe9 | 70 | EC_CURVE_TYPE_SECT_K1 = 1, |
Sergunb | 0:8918a71cdbe9 | 71 | EC_CURVE_TYPE_SECT_R1 = 2, |
Sergunb | 0:8918a71cdbe9 | 72 | EC_CURVE_TYPE_SECT_R2 = 3, |
Sergunb | 0:8918a71cdbe9 | 73 | EC_CURVE_TYPE_SECP_K1 = 4, |
Sergunb | 0:8918a71cdbe9 | 74 | EC_CURVE_TYPE_SECP_R1 = 5, |
Sergunb | 0:8918a71cdbe9 | 75 | EC_CURVE_TYPE_SECP_R2 = 6, |
Sergunb | 0:8918a71cdbe9 | 76 | EC_CURVE_TYPE_BRAINPOOLP_R1 = 7 |
Sergunb | 0:8918a71cdbe9 | 77 | } EcCurveType; |
Sergunb | 0:8918a71cdbe9 | 78 | |
Sergunb | 0:8918a71cdbe9 | 79 | |
Sergunb | 0:8918a71cdbe9 | 80 | /** |
Sergunb | 0:8918a71cdbe9 | 81 | * @brief Fast modular reduction |
Sergunb | 0:8918a71cdbe9 | 82 | **/ |
Sergunb | 0:8918a71cdbe9 | 83 | |
Sergunb | 0:8918a71cdbe9 | 84 | typedef error_t (*EcFastModAlgo)(Mpi *a, const Mpi *p); |
Sergunb | 0:8918a71cdbe9 | 85 | |
Sergunb | 0:8918a71cdbe9 | 86 | |
Sergunb | 0:8918a71cdbe9 | 87 | /** |
Sergunb | 0:8918a71cdbe9 | 88 | * @brief Elliptic curve parameters |
Sergunb | 0:8918a71cdbe9 | 89 | **/ |
Sergunb | 0:8918a71cdbe9 | 90 | |
Sergunb | 0:8918a71cdbe9 | 91 | typedef struct |
Sergunb | 0:8918a71cdbe9 | 92 | { |
Sergunb | 0:8918a71cdbe9 | 93 | const char_t *name; ///<Curve name |
Sergunb | 0:8918a71cdbe9 | 94 | const uint8_t *oid; ///<Object identifier |
Sergunb | 0:8918a71cdbe9 | 95 | size_t oidSize; ///<OID size |
Sergunb | 0:8918a71cdbe9 | 96 | EcCurveType type; ///<Curve type |
Sergunb | 0:8918a71cdbe9 | 97 | const uint8_t p[66]; ///<Prime modulus p |
Sergunb | 0:8918a71cdbe9 | 98 | size_t pLen; ///<Length of p |
Sergunb | 0:8918a71cdbe9 | 99 | const uint8_t a[66]; ///<Curve parameter a |
Sergunb | 0:8918a71cdbe9 | 100 | size_t aLen; ///<Length of a |
Sergunb | 0:8918a71cdbe9 | 101 | const uint8_t b[66]; ///<Curve parameter b |
Sergunb | 0:8918a71cdbe9 | 102 | size_t bLen; ///<Length of b |
Sergunb | 0:8918a71cdbe9 | 103 | const uint8_t gx[66]; ///<x-coordinate of the base point G |
Sergunb | 0:8918a71cdbe9 | 104 | size_t gxLen; ///<Length of Gx |
Sergunb | 0:8918a71cdbe9 | 105 | const uint8_t gy[66]; ///<y-coordinate of the base point G |
Sergunb | 0:8918a71cdbe9 | 106 | size_t gyLen; ///<Length of Gy |
Sergunb | 0:8918a71cdbe9 | 107 | const uint8_t q[66]; ///<Order of the base point G |
Sergunb | 0:8918a71cdbe9 | 108 | size_t qLen; ///<Length of q |
Sergunb | 0:8918a71cdbe9 | 109 | uint32_t h; ///<Cofactor h |
Sergunb | 0:8918a71cdbe9 | 110 | EcFastModAlgo mod; ///<Fast modular reduction |
Sergunb | 0:8918a71cdbe9 | 111 | } EcCurveInfo; |
Sergunb | 0:8918a71cdbe9 | 112 | |
Sergunb | 0:8918a71cdbe9 | 113 | |
Sergunb | 0:8918a71cdbe9 | 114 | //Constants |
Sergunb | 0:8918a71cdbe9 | 115 | extern const uint8_t SECP112R1_OID[5]; |
Sergunb | 0:8918a71cdbe9 | 116 | extern const uint8_t SECP112R2_OID[5]; |
Sergunb | 0:8918a71cdbe9 | 117 | extern const uint8_t SECP128R1_OID[5]; |
Sergunb | 0:8918a71cdbe9 | 118 | extern const uint8_t SECP128R2_OID[5]; |
Sergunb | 0:8918a71cdbe9 | 119 | extern const uint8_t SECP160K1_OID[5]; |
Sergunb | 0:8918a71cdbe9 | 120 | extern const uint8_t SECP160R1_OID[5]; |
Sergunb | 0:8918a71cdbe9 | 121 | extern const uint8_t SECP160R2_OID[5]; |
Sergunb | 0:8918a71cdbe9 | 122 | extern const uint8_t SECP192K1_OID[5]; |
Sergunb | 0:8918a71cdbe9 | 123 | extern const uint8_t SECP192R1_OID[8]; |
Sergunb | 0:8918a71cdbe9 | 124 | extern const uint8_t SECP224K1_OID[5]; |
Sergunb | 0:8918a71cdbe9 | 125 | extern const uint8_t SECP224R1_OID[5]; |
Sergunb | 0:8918a71cdbe9 | 126 | extern const uint8_t SECP256K1_OID[5]; |
Sergunb | 0:8918a71cdbe9 | 127 | extern const uint8_t SECP256R1_OID[8]; |
Sergunb | 0:8918a71cdbe9 | 128 | extern const uint8_t SECP384R1_OID[5]; |
Sergunb | 0:8918a71cdbe9 | 129 | extern const uint8_t SECP521R1_OID[5]; |
Sergunb | 0:8918a71cdbe9 | 130 | extern const uint8_t BRAINPOOLP160R1_OID[10]; |
Sergunb | 0:8918a71cdbe9 | 131 | extern const uint8_t BRAINPOOLP192R1_OID[10]; |
Sergunb | 0:8918a71cdbe9 | 132 | extern const uint8_t BRAINPOOLP224R1_OID[10]; |
Sergunb | 0:8918a71cdbe9 | 133 | extern const uint8_t BRAINPOOLP256R1_OID[10]; |
Sergunb | 0:8918a71cdbe9 | 134 | extern const uint8_t BRAINPOOLP320R1_OID[10]; |
Sergunb | 0:8918a71cdbe9 | 135 | extern const uint8_t BRAINPOOLP384R1_OID[10]; |
Sergunb | 0:8918a71cdbe9 | 136 | extern const uint8_t BRAINPOOLP512R1_OID[10]; |
Sergunb | 0:8918a71cdbe9 | 137 | |
Sergunb | 0:8918a71cdbe9 | 138 | extern const EcCurveInfo secp112r1Curve; |
Sergunb | 0:8918a71cdbe9 | 139 | extern const EcCurveInfo secp112r2Curve; |
Sergunb | 0:8918a71cdbe9 | 140 | extern const EcCurveInfo secp128r1Curve; |
Sergunb | 0:8918a71cdbe9 | 141 | extern const EcCurveInfo secp128r2Curve; |
Sergunb | 0:8918a71cdbe9 | 142 | extern const EcCurveInfo secp160k1Curve; |
Sergunb | 0:8918a71cdbe9 | 143 | extern const EcCurveInfo secp160r1Curve; |
Sergunb | 0:8918a71cdbe9 | 144 | extern const EcCurveInfo secp160r2Curve; |
Sergunb | 0:8918a71cdbe9 | 145 | extern const EcCurveInfo secp192k1Curve; |
Sergunb | 0:8918a71cdbe9 | 146 | extern const EcCurveInfo secp192r1Curve; |
Sergunb | 0:8918a71cdbe9 | 147 | extern const EcCurveInfo secp224k1Curve; |
Sergunb | 0:8918a71cdbe9 | 148 | extern const EcCurveInfo secp224r1Curve; |
Sergunb | 0:8918a71cdbe9 | 149 | extern const EcCurveInfo secp256k1Curve; |
Sergunb | 0:8918a71cdbe9 | 150 | extern const EcCurveInfo secp256r1Curve; |
Sergunb | 0:8918a71cdbe9 | 151 | extern const EcCurveInfo secp384r1Curve; |
Sergunb | 0:8918a71cdbe9 | 152 | extern const EcCurveInfo secp521r1Curve; |
Sergunb | 0:8918a71cdbe9 | 153 | extern const EcCurveInfo brainpoolP160r1Curve; |
Sergunb | 0:8918a71cdbe9 | 154 | extern const EcCurveInfo brainpoolP192r1Curve; |
Sergunb | 0:8918a71cdbe9 | 155 | extern const EcCurveInfo brainpoolP224r1Curve; |
Sergunb | 0:8918a71cdbe9 | 156 | extern const EcCurveInfo brainpoolP256r1Curve; |
Sergunb | 0:8918a71cdbe9 | 157 | extern const EcCurveInfo brainpoolP320r1Curve; |
Sergunb | 0:8918a71cdbe9 | 158 | extern const EcCurveInfo brainpoolP384r1Curve; |
Sergunb | 0:8918a71cdbe9 | 159 | extern const EcCurveInfo brainpoolP512r1Curve; |
Sergunb | 0:8918a71cdbe9 | 160 | |
Sergunb | 0:8918a71cdbe9 | 161 | //Fast modular reduction |
Sergunb | 0:8918a71cdbe9 | 162 | error_t secp128r1Mod(Mpi *a, const Mpi *p); |
Sergunb | 0:8918a71cdbe9 | 163 | error_t secp128r2Mod(Mpi *a, const Mpi *p); |
Sergunb | 0:8918a71cdbe9 | 164 | error_t secp160k1Mod(Mpi *a, const Mpi *p); |
Sergunb | 0:8918a71cdbe9 | 165 | error_t secp160r1Mod(Mpi *a, const Mpi *p); |
Sergunb | 0:8918a71cdbe9 | 166 | error_t secp160r2Mod(Mpi *a, const Mpi *p); |
Sergunb | 0:8918a71cdbe9 | 167 | error_t secp192k1Mod(Mpi *a, const Mpi *p); |
Sergunb | 0:8918a71cdbe9 | 168 | error_t secp192r1Mod(Mpi *a, const Mpi *p); |
Sergunb | 0:8918a71cdbe9 | 169 | error_t secp224k1Mod(Mpi *a, const Mpi *p); |
Sergunb | 0:8918a71cdbe9 | 170 | error_t secp224r1Mod(Mpi *a, const Mpi *p); |
Sergunb | 0:8918a71cdbe9 | 171 | error_t secp256k1Mod(Mpi *a, const Mpi *p); |
Sergunb | 0:8918a71cdbe9 | 172 | error_t secp256r1Mod(Mpi *a, const Mpi *p); |
Sergunb | 0:8918a71cdbe9 | 173 | error_t secp384r1Mod(Mpi *a, const Mpi *p); |
Sergunb | 0:8918a71cdbe9 | 174 | error_t secp521r1Mod(Mpi *a, const Mpi *p); |
Sergunb | 0:8918a71cdbe9 | 175 | |
Sergunb | 0:8918a71cdbe9 | 176 | const EcCurveInfo *ecGetCurveInfo(const uint8_t *oid, size_t length); |
Sergunb | 0:8918a71cdbe9 | 177 | |
Sergunb | 0:8918a71cdbe9 | 178 | #endif |
Sergunb | 0:8918a71cdbe9 | 179 |