Manuel Pégourié-Gonnard | 39d2adb | 2012-10-31 09:26:55 +0100 | [diff] [blame] | 1 | /** |
| 2 | * \file ecp.h |
| 3 | * |
| 4 | * \brief Elliptic curves over GF(p) |
Darryl Green | a40a101 | 2018-01-05 15:33:17 +0000 | [diff] [blame] | 5 | */ |
| 6 | /* |
Bence Szépkúti | 44bfbe3 | 2020-08-19 16:54:51 +0200 | [diff] [blame^] | 7 | * Copyright The Mbed TLS Contributors |
Bence Szépkúti | 4e9f712 | 2020-06-05 13:02:18 +0200 | [diff] [blame] | 8 | * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later |
| 9 | * |
| 10 | * This file is provided under the Apache License 2.0, or the |
| 11 | * GNU General Public License v2.0 or later. |
| 12 | * |
| 13 | * ********** |
| 14 | * Apache License 2.0: |
Manuel Pégourié-Gonnard | 37ff140 | 2015-09-04 14:21:07 +0200 | [diff] [blame] | 15 | * |
| 16 | * Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 17 | * not use this file except in compliance with the License. |
| 18 | * You may obtain a copy of the License at |
| 19 | * |
| 20 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 21 | * |
| 22 | * Unless required by applicable law or agreed to in writing, software |
| 23 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 24 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 25 | * See the License for the specific language governing permissions and |
| 26 | * limitations under the License. |
Manuel Pégourié-Gonnard | 39d2adb | 2012-10-31 09:26:55 +0100 | [diff] [blame] | 27 | * |
Bence Szépkúti | 4e9f712 | 2020-06-05 13:02:18 +0200 | [diff] [blame] | 28 | * ********** |
| 29 | * |
| 30 | * ********** |
| 31 | * GNU General Public License v2.0 or later: |
| 32 | * |
| 33 | * This program is free software; you can redistribute it and/or modify |
| 34 | * it under the terms of the GNU General Public License as published by |
| 35 | * the Free Software Foundation; either version 2 of the License, or |
| 36 | * (at your option) any later version. |
| 37 | * |
| 38 | * This program is distributed in the hope that it will be useful, |
| 39 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 40 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 41 | * GNU General Public License for more details. |
| 42 | * |
| 43 | * You should have received a copy of the GNU General Public License along |
| 44 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 45 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 46 | * |
| 47 | * ********** |
Manuel Pégourié-Gonnard | 39d2adb | 2012-10-31 09:26:55 +0100 | [diff] [blame] | 48 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 49 | #ifndef MBEDTLS_ECP_H |
| 50 | #define MBEDTLS_ECP_H |
Manuel Pégourié-Gonnard | 39d2adb | 2012-10-31 09:26:55 +0100 | [diff] [blame] | 51 | |
Ron Eldor | 0559c66 | 2018-02-14 16:02:41 +0200 | [diff] [blame] | 52 | #if !defined(MBEDTLS_CONFIG_FILE) |
| 53 | #include "config.h" |
| 54 | #else |
| 55 | #include MBEDTLS_CONFIG_FILE |
| 56 | #endif |
| 57 | |
Manuel Pégourié-Gonnard | bdc9676 | 2013-10-03 11:50:39 +0200 | [diff] [blame] | 58 | #include "bignum.h" |
Manuel Pégourié-Gonnard | 39d2adb | 2012-10-31 09:26:55 +0100 | [diff] [blame] | 59 | |
| 60 | /* |
Manuel Pégourié-Gonnard | 7cfcea3 | 2012-11-05 10:06:12 +0100 | [diff] [blame] | 61 | * ECP error codes |
Manuel Pégourié-Gonnard | 39d2adb | 2012-10-31 09:26:55 +0100 | [diff] [blame] | 62 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 63 | #define MBEDTLS_ERR_ECP_BAD_INPUT_DATA -0x4F80 /**< Bad input parameters to function. */ |
| 64 | #define MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL -0x4F00 /**< The buffer is too small to write to. */ |
| 65 | #define MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE -0x4E80 /**< Requested curve not available. */ |
| 66 | #define MBEDTLS_ERR_ECP_VERIFY_FAILED -0x4E00 /**< The signature is not valid. */ |
Manuel Pégourié-Gonnard | 6a8ca33 | 2015-05-28 09:33:39 +0200 | [diff] [blame] | 67 | #define MBEDTLS_ERR_ECP_ALLOC_FAILED -0x4D80 /**< Memory allocation failed. */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 68 | #define MBEDTLS_ERR_ECP_RANDOM_FAILED -0x4D00 /**< Generation of random value, such as (ephemeral) key, failed. */ |
| 69 | #define MBEDTLS_ERR_ECP_INVALID_KEY -0x4C80 /**< Invalid private or public key. */ |
Gilles Peskine | 5114d3e | 2018-03-30 07:12:15 +0200 | [diff] [blame] | 70 | #define MBEDTLS_ERR_ECP_SIG_LEN_MISMATCH -0x4C00 /**< The buffer contains a valid signature followed by more data. */ |
Gilles Peskine | 7ecab3d | 2018-01-26 17:56:38 +0100 | [diff] [blame] | 71 | #define MBEDTLS_ERR_ECP_HW_ACCEL_FAILED -0x4B80 /**< ECP hardware accelerator failed. */ |
Manuel Pégourié-Gonnard | 883f313 | 2012-11-02 09:40:25 +0100 | [diff] [blame] | 72 | |
Janos Follath | b069753 | 2016-08-18 12:38:46 +0100 | [diff] [blame] | 73 | #if !defined(MBEDTLS_ECP_ALT) |
Janos Follath | c44ab97 | 2016-11-18 16:38:23 +0000 | [diff] [blame] | 74 | /* |
| 75 | * default mbed TLS elliptic curve arithmetic implementation |
| 76 | * |
| 77 | * (in case MBEDTLS_ECP_ALT is defined then the developer has to provide an |
| 78 | * alternative implementation for the whole module and it will replace this |
| 79 | * one.) |
| 80 | */ |
Janos Follath | b069753 | 2016-08-18 12:38:46 +0100 | [diff] [blame] | 81 | |
Paul Bakker | 407a0da | 2013-06-27 14:29:21 +0200 | [diff] [blame] | 82 | #ifdef __cplusplus |
| 83 | extern "C" { |
| 84 | #endif |
| 85 | |
Manuel Pégourié-Gonnard | 39d2adb | 2012-10-31 09:26:55 +0100 | [diff] [blame] | 86 | /** |
Manuel Pégourié-Gonnard | 7038039 | 2013-09-16 16:19:53 +0200 | [diff] [blame] | 87 | * Domain parameters (curve, subgroup and generator) identifiers. |
| 88 | * |
| 89 | * Only curves over prime fields are supported. |
| 90 | * |
| 91 | * \warning This library does not support validation of arbitrary domain |
| 92 | * parameters. Therefore, only well-known domain parameters from trusted |
Manuel Pégourié-Gonnard | e3a062b | 2015-05-11 18:46:47 +0200 | [diff] [blame] | 93 | * sources should be used. See mbedtls_ecp_group_load(). |
Manuel Pégourié-Gonnard | 7038039 | 2013-09-16 16:19:53 +0200 | [diff] [blame] | 94 | */ |
| 95 | typedef enum |
| 96 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 97 | MBEDTLS_ECP_DP_NONE = 0, |
| 98 | MBEDTLS_ECP_DP_SECP192R1, /*!< 192-bits NIST curve */ |
| 99 | MBEDTLS_ECP_DP_SECP224R1, /*!< 224-bits NIST curve */ |
| 100 | MBEDTLS_ECP_DP_SECP256R1, /*!< 256-bits NIST curve */ |
| 101 | MBEDTLS_ECP_DP_SECP384R1, /*!< 384-bits NIST curve */ |
| 102 | MBEDTLS_ECP_DP_SECP521R1, /*!< 521-bits NIST curve */ |
| 103 | MBEDTLS_ECP_DP_BP256R1, /*!< 256-bits Brainpool curve */ |
| 104 | MBEDTLS_ECP_DP_BP384R1, /*!< 384-bits Brainpool curve */ |
| 105 | MBEDTLS_ECP_DP_BP512R1, /*!< 512-bits Brainpool curve */ |
Manuel Pégourié-Gonnard | 0789433 | 2015-06-23 00:18:41 +0200 | [diff] [blame] | 106 | MBEDTLS_ECP_DP_CURVE25519, /*!< Curve25519 */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 107 | MBEDTLS_ECP_DP_SECP192K1, /*!< 192-bits "Koblitz" curve */ |
| 108 | MBEDTLS_ECP_DP_SECP224K1, /*!< 224-bits "Koblitz" curve */ |
| 109 | MBEDTLS_ECP_DP_SECP256K1, /*!< 256-bits "Koblitz" curve */ |
| 110 | } mbedtls_ecp_group_id; |
Manuel Pégourié-Gonnard | 7038039 | 2013-09-16 16:19:53 +0200 | [diff] [blame] | 111 | |
| 112 | /** |
Manuel Pégourié-Gonnard | 6615366 | 2013-12-03 14:12:26 +0100 | [diff] [blame] | 113 | * Number of supported curves (plus one for NONE). |
| 114 | * |
| 115 | * (Montgomery curves excluded for now.) |
Manuel Pégourié-Gonnard | f24b4a7 | 2013-09-23 18:14:50 +0200 | [diff] [blame] | 116 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 117 | #define MBEDTLS_ECP_DP_MAX 12 |
Manuel Pégourié-Gonnard | f24b4a7 | 2013-09-23 18:14:50 +0200 | [diff] [blame] | 118 | |
| 119 | /** |
Manuel Pégourié-Gonnard | da179e4 | 2013-09-18 15:31:24 +0200 | [diff] [blame] | 120 | * Curve information for use by other modules |
Manuel Pégourié-Gonnard | 568c9cf | 2013-09-16 17:30:04 +0200 | [diff] [blame] | 121 | */ |
| 122 | typedef struct |
| 123 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 124 | mbedtls_ecp_group_id grp_id; /*!< Internal identifier */ |
Manuel Pégourié-Gonnard | 797f48a | 2015-06-18 15:45:05 +0200 | [diff] [blame] | 125 | uint16_t tls_id; /*!< TLS NamedCurve identifier */ |
| 126 | uint16_t bit_size; /*!< Curve size in bits */ |
| 127 | const char *name; /*!< Human-friendly name */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 128 | } mbedtls_ecp_curve_info; |
Manuel Pégourié-Gonnard | 568c9cf | 2013-09-16 17:30:04 +0200 | [diff] [blame] | 129 | |
| 130 | /** |
Manuel Pégourié-Gonnard | 1c2782c | 2012-11-19 20:16:28 +0100 | [diff] [blame] | 131 | * \brief ECP point structure (jacobian coordinates) |
Manuel Pégourié-Gonnard | ae180d0 | 2012-11-02 18:14:40 +0100 | [diff] [blame] | 132 | * |
Manuel Pégourié-Gonnard | 1c2782c | 2012-11-19 20:16:28 +0100 | [diff] [blame] | 133 | * \note All functions expect and return points satisfying |
| 134 | * the following condition: Z == 0 or Z == 1. (Other |
| 135 | * values of Z are used by internal functions only.) |
| 136 | * The point is zero, or "at infinity", if Z == 0. |
| 137 | * Otherwise, X and Y are its standard (affine) coordinates. |
Manuel Pégourié-Gonnard | 39d2adb | 2012-10-31 09:26:55 +0100 | [diff] [blame] | 138 | */ |
| 139 | typedef struct |
| 140 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 141 | mbedtls_mpi X; /*!< the point's X coordinate */ |
| 142 | mbedtls_mpi Y; /*!< the point's Y coordinate */ |
| 143 | mbedtls_mpi Z; /*!< the point's Z coordinate */ |
Manuel Pégourié-Gonnard | 39d2adb | 2012-10-31 09:26:55 +0100 | [diff] [blame] | 144 | } |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 145 | mbedtls_ecp_point; |
Manuel Pégourié-Gonnard | 39d2adb | 2012-10-31 09:26:55 +0100 | [diff] [blame] | 146 | |
| 147 | /** |
| 148 | * \brief ECP group structure |
| 149 | * |
Manuel Pégourié-Gonnard | 7a949d3 | 2013-12-05 10:26:01 +0100 | [diff] [blame] | 150 | * We consider two types of curves equations: |
| 151 | * 1. Short Weierstrass y^2 = x^3 + A x + B mod P (SEC1 + RFC 4492) |
Manuel Pégourié-Gonnard | 0789433 | 2015-06-23 00:18:41 +0200 | [diff] [blame] | 152 | * 2. Montgomery, y^2 = x^3 + A x^2 + x mod P (Curve25519 + draft) |
Manuel Pégourié-Gonnard | 7a949d3 | 2013-12-05 10:26:01 +0100 | [diff] [blame] | 153 | * In both cases, a generator G for a prime-order subgroup is fixed. In the |
| 154 | * short weierstrass, this subgroup is actually the whole curve, and its |
| 155 | * cardinal is denoted by N. |
Manuel Pégourié-Gonnard | 62aad14 | 2012-11-10 00:27:12 +0100 | [diff] [blame] | 156 | * |
Manuel Pégourié-Gonnard | dd75c31 | 2014-03-31 11:55:42 +0200 | [diff] [blame] | 157 | * In the case of Short Weierstrass curves, our code requires that N is an odd |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 158 | * prime. (Use odd in mbedtls_ecp_mul() and prime in mbedtls_ecdsa_sign() for blinding.) |
Manuel Pégourié-Gonnard | dd75c31 | 2014-03-31 11:55:42 +0200 | [diff] [blame] | 159 | * |
Manuel Pégourié-Gonnard | 7a949d3 | 2013-12-05 10:26:01 +0100 | [diff] [blame] | 160 | * In the case of Montgomery curves, we don't store A but (A + 2) / 4 which is |
Paul Bakker | 75342a6 | 2014-04-08 17:35:40 +0200 | [diff] [blame] | 161 | * the quantity actually used in the formulas. Also, nbits is not the size of N |
Manuel Pégourié-Gonnard | 7a949d3 | 2013-12-05 10:26:01 +0100 | [diff] [blame] | 162 | * but the required size for private keys. |
Manuel Pégourié-Gonnard | 4712325 | 2012-11-10 14:44:24 +0100 | [diff] [blame] | 163 | * |
Manuel Pégourié-Gonnard | c972770 | 2013-09-16 18:56:28 +0200 | [diff] [blame] | 164 | * If modp is NULL, reduction modulo P is done using a generic algorithm. |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 165 | * Otherwise, it must point to a function that takes an mbedtls_mpi in the range |
Manuel Pégourié-Gonnard | c972770 | 2013-09-16 18:56:28 +0200 | [diff] [blame] | 166 | * 0..2^(2*pbits)-1 and transforms it in-place in an integer of little more |
| 167 | * than pbits, so that the integer may be efficiently brought in the 0..P-1 |
| 168 | * range by a few additions or substractions. It must return 0 on success and |
| 169 | * non-zero on failure. |
Manuel Pégourié-Gonnard | 39d2adb | 2012-10-31 09:26:55 +0100 | [diff] [blame] | 170 | */ |
| 171 | typedef struct |
| 172 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 173 | mbedtls_ecp_group_id id; /*!< internal group identifier */ |
| 174 | mbedtls_mpi P; /*!< prime modulus of the base field */ |
| 175 | mbedtls_mpi A; /*!< 1. A in the equation, or 2. (A + 2) / 4 */ |
| 176 | mbedtls_mpi B; /*!< 1. B in the equation, or 2. unused */ |
| 177 | mbedtls_ecp_point G; /*!< generator of the (sub)group used */ |
| 178 | mbedtls_mpi N; /*!< 1. the order of G, or 2. unused */ |
Manuel Pégourié-Gonnard | cd7458a | 2013-10-08 13:11:30 +0200 | [diff] [blame] | 179 | size_t pbits; /*!< number of bits in P */ |
Manuel Pégourié-Gonnard | 7a949d3 | 2013-12-05 10:26:01 +0100 | [diff] [blame] | 180 | size_t nbits; /*!< number of bits in 1. P, or 2. private keys */ |
Manuel Pégourié-Gonnard | 1f82b04 | 2013-12-06 12:51:50 +0100 | [diff] [blame] | 181 | unsigned int h; /*!< internal: 1 if the constants are static */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 182 | int (*modp)(mbedtls_mpi *); /*!< function for fast reduction mod P */ |
| 183 | int (*t_pre)(mbedtls_ecp_point *, void *); /*!< unused */ |
| 184 | int (*t_post)(mbedtls_ecp_point *, void *); /*!< unused */ |
Manuel Pégourié-Gonnard | 7a949d3 | 2013-12-05 10:26:01 +0100 | [diff] [blame] | 185 | void *t_data; /*!< unused */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 186 | mbedtls_ecp_point *T; /*!< pre-computed points for ecp_mul_comb() */ |
Manuel Pégourié-Gonnard | cd7458a | 2013-10-08 13:11:30 +0200 | [diff] [blame] | 187 | size_t T_size; /*!< number for pre-computed points */ |
Manuel Pégourié-Gonnard | 39d2adb | 2012-10-31 09:26:55 +0100 | [diff] [blame] | 188 | } |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 189 | mbedtls_ecp_group; |
Manuel Pégourié-Gonnard | 39d2adb | 2012-10-31 09:26:55 +0100 | [diff] [blame] | 190 | |
| 191 | /** |
Manuel Pégourié-Gonnard | b8c6e0e | 2013-07-01 13:40:52 +0200 | [diff] [blame] | 192 | * \brief ECP key pair structure |
| 193 | * |
| 194 | * A generic key pair that could be used for ECDSA, fixed ECDH, etc. |
Manuel Pégourié-Gonnard | 09162dd | 2013-08-14 18:16:50 +0200 | [diff] [blame] | 195 | * |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 196 | * \note Members purposefully in the same order as struc mbedtls_ecdsa_context. |
Manuel Pégourié-Gonnard | b8c6e0e | 2013-07-01 13:40:52 +0200 | [diff] [blame] | 197 | */ |
| 198 | typedef struct |
| 199 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 200 | mbedtls_ecp_group grp; /*!< Elliptic curve and base point */ |
| 201 | mbedtls_mpi d; /*!< our secret value */ |
| 202 | mbedtls_ecp_point Q; /*!< our public value */ |
Manuel Pégourié-Gonnard | b8c6e0e | 2013-07-01 13:40:52 +0200 | [diff] [blame] | 203 | } |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 204 | mbedtls_ecp_keypair; |
Manuel Pégourié-Gonnard | b8c6e0e | 2013-07-01 13:40:52 +0200 | [diff] [blame] | 205 | |
Paul Bakker | 088c5c5 | 2014-04-25 11:11:10 +0200 | [diff] [blame] | 206 | /** |
| 207 | * \name SECTION: Module settings |
| 208 | * |
| 209 | * The configuration options you can set for this module are in this section. |
| 210 | * Either change them in config.h or define them on the compiler command line. |
| 211 | * \{ |
| 212 | */ |
| 213 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 214 | #if !defined(MBEDTLS_ECP_MAX_BITS) |
Manuel Pégourié-Gonnard | b8c6e0e | 2013-07-01 13:40:52 +0200 | [diff] [blame] | 215 | /** |
Manuel Pégourié-Gonnard | b694b48 | 2013-08-08 13:30:57 +0200 | [diff] [blame] | 216 | * Maximum size of the groups (that is, of N and P) |
Manuel Pégourié-Gonnard | b63f9e9 | 2012-11-21 13:00:58 +0100 | [diff] [blame] | 217 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 218 | #define MBEDTLS_ECP_MAX_BITS 521 /**< Maximum bit size of groups */ |
Paul Bakker | e1b665e | 2013-12-11 16:02:58 +0100 | [diff] [blame] | 219 | #endif |
| 220 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 221 | #define MBEDTLS_ECP_MAX_BYTES ( ( MBEDTLS_ECP_MAX_BITS + 7 ) / 8 ) |
| 222 | #define MBEDTLS_ECP_MAX_PT_LEN ( 2 * MBEDTLS_ECP_MAX_BYTES + 1 ) |
Manuel Pégourié-Gonnard | b63f9e9 | 2012-11-21 13:00:58 +0100 | [diff] [blame] | 223 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 224 | #if !defined(MBEDTLS_ECP_WINDOW_SIZE) |
Manuel Pégourié-Gonnard | 8555607 | 2012-11-17 19:54:20 +0100 | [diff] [blame] | 225 | /* |
Manuel Pégourié-Gonnard | c30200e | 2013-11-20 18:39:55 +0100 | [diff] [blame] | 226 | * Maximum "window" size used for point multiplication. |
| 227 | * Default: 6. |
| 228 | * Minimum value: 2. Maximum value: 7. |
Manuel Pégourié-Gonnard | 8555607 | 2012-11-17 19:54:20 +0100 | [diff] [blame] | 229 | * |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 230 | * Result is an array of at most ( 1 << ( MBEDTLS_ECP_WINDOW_SIZE - 1 ) ) |
Manuel Pégourié-Gonnard | 9e4191c | 2013-12-30 18:41:16 +0100 | [diff] [blame] | 231 | * points used for point multiplication. This value is directly tied to EC |
| 232 | * peak memory usage, so decreasing it by one should roughly cut memory usage |
| 233 | * by two (if large curves are in use). |
Manuel Pégourié-Gonnard | 8555607 | 2012-11-17 19:54:20 +0100 | [diff] [blame] | 234 | * |
Manuel Pégourié-Gonnard | 9e4191c | 2013-12-30 18:41:16 +0100 | [diff] [blame] | 235 | * Reduction in size may reduce speed, but larger curves are impacted first. |
| 236 | * Sample performances (in ECDHE handshakes/s, with FIXED_POINT_OPTIM = 1): |
| 237 | * w-size: 6 5 4 3 2 |
| 238 | * 521 145 141 135 120 97 |
| 239 | * 384 214 209 198 177 146 |
| 240 | * 256 320 320 303 262 226 |
Paul Bakker | 088c5c5 | 2014-04-25 11:11:10 +0200 | [diff] [blame] | 241 | |
Manuel Pégourié-Gonnard | 9e4191c | 2013-12-30 18:41:16 +0100 | [diff] [blame] | 242 | * 224 475 475 453 398 342 |
| 243 | * 192 640 640 633 587 476 |
Manuel Pégourié-Gonnard | 8555607 | 2012-11-17 19:54:20 +0100 | [diff] [blame] | 244 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 245 | #define MBEDTLS_ECP_WINDOW_SIZE 6 /**< Maximum window size used */ |
| 246 | #endif /* MBEDTLS_ECP_WINDOW_SIZE */ |
Manuel Pégourié-Gonnard | 9e4191c | 2013-12-30 18:41:16 +0100 | [diff] [blame] | 247 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 248 | #if !defined(MBEDTLS_ECP_FIXED_POINT_OPTIM) |
Manuel Pégourié-Gonnard | 9e4191c | 2013-12-30 18:41:16 +0100 | [diff] [blame] | 249 | /* |
| 250 | * Trade memory for speed on fixed-point multiplication. |
| 251 | * |
| 252 | * This speeds up repeated multiplication of the generator (that is, the |
| 253 | * multiplication in ECDSA signatures, and half of the multiplications in |
| 254 | * ECDSA verification and ECDHE) by a factor roughly 3 to 4. |
| 255 | * |
| 256 | * The cost is increasing EC peak memory usage by a factor roughly 2. |
| 257 | * |
| 258 | * Change this value to 0 to reduce peak memory usage. |
| 259 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 260 | #define MBEDTLS_ECP_FIXED_POINT_OPTIM 1 /**< Enable fixed-point speed-up */ |
| 261 | #endif /* MBEDTLS_ECP_FIXED_POINT_OPTIM */ |
Manuel Pégourié-Gonnard | 8555607 | 2012-11-17 19:54:20 +0100 | [diff] [blame] | 262 | |
Paul Bakker | 088c5c5 | 2014-04-25 11:11:10 +0200 | [diff] [blame] | 263 | /* \} name SECTION: Module settings */ |
| 264 | |
Manuel Pégourié-Gonnard | 37d218a | 2012-11-24 15:19:55 +0100 | [diff] [blame] | 265 | /* |
Manuel Pégourié-Gonnard | 0079405 | 2013-02-09 19:00:07 +0100 | [diff] [blame] | 266 | * Point formats, from RFC 4492's enum ECPointFormat |
Manuel Pégourié-Gonnard | 37d218a | 2012-11-24 15:19:55 +0100 | [diff] [blame] | 267 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 268 | #define MBEDTLS_ECP_PF_UNCOMPRESSED 0 /**< Uncompressed point format */ |
| 269 | #define MBEDTLS_ECP_PF_COMPRESSED 1 /**< Compressed point format */ |
Manuel Pégourié-Gonnard | 37d218a | 2012-11-24 15:19:55 +0100 | [diff] [blame] | 270 | |
Manuel Pégourié-Gonnard | 1a96728 | 2013-02-09 17:03:58 +0100 | [diff] [blame] | 271 | /* |
Manuel Pégourié-Gonnard | 0079405 | 2013-02-09 19:00:07 +0100 | [diff] [blame] | 272 | * Some other constants from RFC 4492 |
Manuel Pégourié-Gonnard | 1a96728 | 2013-02-09 17:03:58 +0100 | [diff] [blame] | 273 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 274 | #define MBEDTLS_ECP_TLS_NAMED_CURVE 3 /**< ECCurveType's named_curve */ |
Manuel Pégourié-Gonnard | 1a96728 | 2013-02-09 17:03:58 +0100 | [diff] [blame] | 275 | |
Manuel Pégourié-Gonnard | 39d2adb | 2012-10-31 09:26:55 +0100 | [diff] [blame] | 276 | /** |
Manuel Pégourié-Gonnard | ac71941 | 2014-02-04 14:48:50 +0100 | [diff] [blame] | 277 | * \brief Get the list of supported curves in order of preferrence |
| 278 | * (full information) |
Manuel Pégourié-Gonnard | da179e4 | 2013-09-18 15:31:24 +0200 | [diff] [blame] | 279 | * |
| 280 | * \return A statically allocated array, the last entry is 0. |
| 281 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 282 | const mbedtls_ecp_curve_info *mbedtls_ecp_curve_list( void ); |
Manuel Pégourié-Gonnard | da179e4 | 2013-09-18 15:31:24 +0200 | [diff] [blame] | 283 | |
| 284 | /** |
Manuel Pégourié-Gonnard | ac71941 | 2014-02-04 14:48:50 +0100 | [diff] [blame] | 285 | * \brief Get the list of supported curves in order of preferrence |
| 286 | * (grp_id only) |
| 287 | * |
| 288 | * \return A statically allocated array, |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 289 | * terminated with MBEDTLS_ECP_DP_NONE. |
Manuel Pégourié-Gonnard | ac71941 | 2014-02-04 14:48:50 +0100 | [diff] [blame] | 290 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 291 | const mbedtls_ecp_group_id *mbedtls_ecp_grp_id_list( void ); |
Manuel Pégourié-Gonnard | ac71941 | 2014-02-04 14:48:50 +0100 | [diff] [blame] | 292 | |
| 293 | /** |
Manuel Pégourié-Gonnard | cae6f3e | 2013-10-23 20:19:57 +0200 | [diff] [blame] | 294 | * \brief Get curve information from an internal group identifier |
| 295 | * |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 296 | * \param grp_id A MBEDTLS_ECP_DP_XXX value |
Manuel Pégourié-Gonnard | cae6f3e | 2013-10-23 20:19:57 +0200 | [diff] [blame] | 297 | * |
| 298 | * \return The associated curve information or NULL |
| 299 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 300 | const mbedtls_ecp_curve_info *mbedtls_ecp_curve_info_from_grp_id( mbedtls_ecp_group_id grp_id ); |
Manuel Pégourié-Gonnard | cae6f3e | 2013-10-23 20:19:57 +0200 | [diff] [blame] | 301 | |
| 302 | /** |
| 303 | * \brief Get curve information from a TLS NamedCurve value |
| 304 | * |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 305 | * \param tls_id A MBEDTLS_ECP_DP_XXX value |
Manuel Pégourié-Gonnard | cae6f3e | 2013-10-23 20:19:57 +0200 | [diff] [blame] | 306 | * |
| 307 | * \return The associated curve information or NULL |
| 308 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 309 | const mbedtls_ecp_curve_info *mbedtls_ecp_curve_info_from_tls_id( uint16_t tls_id ); |
Manuel Pégourié-Gonnard | cae6f3e | 2013-10-23 20:19:57 +0200 | [diff] [blame] | 310 | |
| 311 | /** |
Manuel Pégourié-Gonnard | 0267e3d | 2013-11-30 15:10:14 +0100 | [diff] [blame] | 312 | * \brief Get curve information from a human-readable name |
| 313 | * |
| 314 | * \param name The name |
| 315 | * |
| 316 | * \return The associated curve information or NULL |
| 317 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 318 | const mbedtls_ecp_curve_info *mbedtls_ecp_curve_info_from_name( const char *name ); |
Manuel Pégourié-Gonnard | 0267e3d | 2013-11-30 15:10:14 +0100 | [diff] [blame] | 319 | |
| 320 | /** |
Manuel Pégourié-Gonnard | 847395a | 2012-11-05 13:13:44 +0100 | [diff] [blame] | 321 | * \brief Initialize a point (as zero) |
Manuel Pégourié-Gonnard | ae180d0 | 2012-11-02 18:14:40 +0100 | [diff] [blame] | 322 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 323 | void mbedtls_ecp_point_init( mbedtls_ecp_point *pt ); |
Manuel Pégourié-Gonnard | ae180d0 | 2012-11-02 18:14:40 +0100 | [diff] [blame] | 324 | |
| 325 | /** |
Manuel Pégourié-Gonnard | b505c27 | 2012-11-05 17:27:54 +0100 | [diff] [blame] | 326 | * \brief Initialize a group (to something meaningless) |
| 327 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 328 | void mbedtls_ecp_group_init( mbedtls_ecp_group *grp ); |
Manuel Pégourié-Gonnard | b505c27 | 2012-11-05 17:27:54 +0100 | [diff] [blame] | 329 | |
| 330 | /** |
Manuel Pégourié-Gonnard | b8c6e0e | 2013-07-01 13:40:52 +0200 | [diff] [blame] | 331 | * \brief Initialize a key pair (as an invalid one) |
| 332 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 333 | void mbedtls_ecp_keypair_init( mbedtls_ecp_keypair *key ); |
Manuel Pégourié-Gonnard | b8c6e0e | 2013-07-01 13:40:52 +0200 | [diff] [blame] | 334 | |
| 335 | /** |
Manuel Pégourié-Gonnard | 883f313 | 2012-11-02 09:40:25 +0100 | [diff] [blame] | 336 | * \brief Free the components of a point |
| 337 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 338 | void mbedtls_ecp_point_free( mbedtls_ecp_point *pt ); |
Manuel Pégourié-Gonnard | 883f313 | 2012-11-02 09:40:25 +0100 | [diff] [blame] | 339 | |
| 340 | /** |
| 341 | * \brief Free the components of an ECP group |
| 342 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 343 | void mbedtls_ecp_group_free( mbedtls_ecp_group *grp ); |
Manuel Pégourié-Gonnard | 883f313 | 2012-11-02 09:40:25 +0100 | [diff] [blame] | 344 | |
| 345 | /** |
Manuel Pégourié-Gonnard | b8c6e0e | 2013-07-01 13:40:52 +0200 | [diff] [blame] | 346 | * \brief Free the components of a key pair |
| 347 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 348 | void mbedtls_ecp_keypair_free( mbedtls_ecp_keypair *key ); |
Manuel Pégourié-Gonnard | b8c6e0e | 2013-07-01 13:40:52 +0200 | [diff] [blame] | 349 | |
| 350 | /** |
Manuel Pégourié-Gonnard | 883f313 | 2012-11-02 09:40:25 +0100 | [diff] [blame] | 351 | * \brief Copy the contents of point Q into P |
| 352 | * |
| 353 | * \param P Destination point |
| 354 | * \param Q Source point |
| 355 | * |
Manuel Pégourié-Gonnard | 7cfcea3 | 2012-11-05 10:06:12 +0100 | [diff] [blame] | 356 | * \return 0 if successful, |
Manuel Pégourié-Gonnard | 6a8ca33 | 2015-05-28 09:33:39 +0200 | [diff] [blame] | 357 | * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed |
Manuel Pégourié-Gonnard | 883f313 | 2012-11-02 09:40:25 +0100 | [diff] [blame] | 358 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 359 | int mbedtls_ecp_copy( mbedtls_ecp_point *P, const mbedtls_ecp_point *Q ); |
Manuel Pégourié-Gonnard | 883f313 | 2012-11-02 09:40:25 +0100 | [diff] [blame] | 360 | |
| 361 | /** |
Manuel Pégourié-Gonnard | e09631b | 2013-08-12 15:44:31 +0200 | [diff] [blame] | 362 | * \brief Copy the contents of a group object |
| 363 | * |
| 364 | * \param dst Destination group |
| 365 | * \param src Source group |
| 366 | * |
| 367 | * \return 0 if successful, |
Manuel Pégourié-Gonnard | 6a8ca33 | 2015-05-28 09:33:39 +0200 | [diff] [blame] | 368 | * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed |
Manuel Pégourié-Gonnard | e09631b | 2013-08-12 15:44:31 +0200 | [diff] [blame] | 369 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 370 | int mbedtls_ecp_group_copy( mbedtls_ecp_group *dst, const mbedtls_ecp_group *src ); |
Manuel Pégourié-Gonnard | e09631b | 2013-08-12 15:44:31 +0200 | [diff] [blame] | 371 | |
| 372 | /** |
Manuel Pégourié-Gonnard | cae6f3e | 2013-10-23 20:19:57 +0200 | [diff] [blame] | 373 | * \brief Set a point to zero |
| 374 | * |
| 375 | * \param pt Destination point |
| 376 | * |
| 377 | * \return 0 if successful, |
Manuel Pégourié-Gonnard | 6a8ca33 | 2015-05-28 09:33:39 +0200 | [diff] [blame] | 378 | * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed |
Manuel Pégourié-Gonnard | cae6f3e | 2013-10-23 20:19:57 +0200 | [diff] [blame] | 379 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 380 | int mbedtls_ecp_set_zero( mbedtls_ecp_point *pt ); |
Manuel Pégourié-Gonnard | cae6f3e | 2013-10-23 20:19:57 +0200 | [diff] [blame] | 381 | |
| 382 | /** |
| 383 | * \brief Tell if a point is zero |
| 384 | * |
| 385 | * \param pt Point to test |
| 386 | * |
| 387 | * \return 1 if point is zero, 0 otherwise |
| 388 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 389 | int mbedtls_ecp_is_zero( mbedtls_ecp_point *pt ); |
Manuel Pégourié-Gonnard | cae6f3e | 2013-10-23 20:19:57 +0200 | [diff] [blame] | 390 | |
| 391 | /** |
Manuel Pégourié-Gonnard | 6029a85 | 2015-08-11 15:44:41 +0200 | [diff] [blame] | 392 | * \brief Compare two points |
| 393 | * |
| 394 | * \note This assumes the points are normalized. Otherwise, |
| 395 | * they may compare as "not equal" even if they are. |
| 396 | * |
| 397 | * \param P First point to compare |
| 398 | * \param Q Second point to compare |
| 399 | * |
| 400 | * \return 0 if the points are equal, |
| 401 | * MBEDTLS_ERR_ECP_BAD_INPUT_DATA otherwise |
| 402 | */ |
| 403 | int mbedtls_ecp_point_cmp( const mbedtls_ecp_point *P, |
| 404 | const mbedtls_ecp_point *Q ); |
| 405 | |
| 406 | /** |
Manuel Pégourié-Gonnard | 847395a | 2012-11-05 13:13:44 +0100 | [diff] [blame] | 407 | * \brief Import a non-zero point from two ASCII strings |
| 408 | * |
| 409 | * \param P Destination point |
| 410 | * \param radix Input numeric base |
| 411 | * \param x First affine coordinate as a null-terminated string |
| 412 | * \param y Second affine coordinate as a null-terminated string |
| 413 | * |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 414 | * \return 0 if successful, or a MBEDTLS_ERR_MPI_XXX error code |
Manuel Pégourié-Gonnard | 847395a | 2012-11-05 13:13:44 +0100 | [diff] [blame] | 415 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 416 | int mbedtls_ecp_point_read_string( mbedtls_ecp_point *P, int radix, |
Manuel Pégourié-Gonnard | 847395a | 2012-11-05 13:13:44 +0100 | [diff] [blame] | 417 | const char *x, const char *y ); |
| 418 | |
| 419 | /** |
Manuel Pégourié-Gonnard | 37d218a | 2012-11-24 15:19:55 +0100 | [diff] [blame] | 420 | * \brief Export a point into unsigned binary data |
Manuel Pégourié-Gonnard | e19feb5 | 2012-11-24 14:10:14 +0100 | [diff] [blame] | 421 | * |
Manuel Pégourié-Gonnard | 5e402d8 | 2012-11-24 16:19:42 +0100 | [diff] [blame] | 422 | * \param grp Group to which the point should belong |
Manuel Pégourié-Gonnard | e19feb5 | 2012-11-24 14:10:14 +0100 | [diff] [blame] | 423 | * \param P Point to export |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 424 | * \param format Point format, should be a MBEDTLS_ECP_PF_XXX macro |
Manuel Pégourié-Gonnard | 0079405 | 2013-02-09 19:00:07 +0100 | [diff] [blame] | 425 | * \param olen Length of the actual output |
Manuel Pégourié-Gonnard | e19feb5 | 2012-11-24 14:10:14 +0100 | [diff] [blame] | 426 | * \param buf Output buffer |
| 427 | * \param buflen Length of the output buffer |
| 428 | * |
Manuel Pégourié-Gonnard | 0079405 | 2013-02-09 19:00:07 +0100 | [diff] [blame] | 429 | * \return 0 if successful, |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 430 | * or MBEDTLS_ERR_ECP_BAD_INPUT_DATA |
| 431 | * or MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL |
Manuel Pégourié-Gonnard | e19feb5 | 2012-11-24 14:10:14 +0100 | [diff] [blame] | 432 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 433 | int mbedtls_ecp_point_write_binary( const mbedtls_ecp_group *grp, const mbedtls_ecp_point *P, |
Manuel Pégourié-Gonnard | 420f1eb | 2013-02-10 12:22:46 +0100 | [diff] [blame] | 434 | int format, size_t *olen, |
Manuel Pégourié-Gonnard | 7e86025 | 2013-02-10 10:58:48 +0100 | [diff] [blame] | 435 | unsigned char *buf, size_t buflen ); |
Manuel Pégourié-Gonnard | e19feb5 | 2012-11-24 14:10:14 +0100 | [diff] [blame] | 436 | |
| 437 | /** |
Manuel Pégourié-Gonnard | 5e402d8 | 2012-11-24 16:19:42 +0100 | [diff] [blame] | 438 | * \brief Import a point from unsigned binary data |
| 439 | * |
| 440 | * \param grp Group to which the point should belong |
| 441 | * \param P Point to import |
Manuel Pégourié-Gonnard | 5e402d8 | 2012-11-24 16:19:42 +0100 | [diff] [blame] | 442 | * \param buf Input buffer |
| 443 | * \param ilen Actual length of input |
| 444 | * |
| 445 | * \return 0 if successful, |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 446 | * MBEDTLS_ERR_ECP_BAD_INPUT_DATA if input is invalid, |
Manuel Pégourié-Gonnard | 6a8ca33 | 2015-05-28 09:33:39 +0200 | [diff] [blame] | 447 | * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed, |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 448 | * MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE if the point format |
Manuel Pégourié-Gonnard | 5246ee5 | 2014-03-19 16:18:38 +0100 | [diff] [blame] | 449 | * is not implemented. |
Manuel Pégourié-Gonnard | 5e402d8 | 2012-11-24 16:19:42 +0100 | [diff] [blame] | 450 | * |
| 451 | * \note This function does NOT check that the point actually |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 452 | * belongs to the given group, see mbedtls_ecp_check_pubkey() for |
Manuel Pégourié-Gonnard | 5e402d8 | 2012-11-24 16:19:42 +0100 | [diff] [blame] | 453 | * that. |
| 454 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 455 | int mbedtls_ecp_point_read_binary( const mbedtls_ecp_group *grp, mbedtls_ecp_point *P, |
Manuel Pégourié-Gonnard | 7e86025 | 2013-02-10 10:58:48 +0100 | [diff] [blame] | 456 | const unsigned char *buf, size_t ilen ); |
Manuel Pégourié-Gonnard | 1a96728 | 2013-02-09 17:03:58 +0100 | [diff] [blame] | 457 | |
Manuel Pégourié-Gonnard | 5e402d8 | 2012-11-24 16:19:42 +0100 | [diff] [blame] | 458 | /** |
Manuel Pégourié-Gonnard | cae6f3e | 2013-10-23 20:19:57 +0200 | [diff] [blame] | 459 | * \brief Import a point from a TLS ECPoint record |
| 460 | * |
| 461 | * \param grp ECP group used |
| 462 | * \param pt Destination point |
| 463 | * \param buf $(Start of input buffer) |
| 464 | * \param len Buffer length |
| 465 | * |
Manuel Pégourié-Gonnard | 150c4f6 | 2014-11-21 09:14:52 +0100 | [diff] [blame] | 466 | * \note buf is updated to point right after the ECPoint on exit |
| 467 | * |
Manuel Pégourié-Gonnard | eecb43c | 2015-05-12 12:56:41 +0200 | [diff] [blame] | 468 | * \return 0 if successful, |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 469 | * MBEDTLS_ERR_MPI_XXX if initialization failed |
| 470 | * MBEDTLS_ERR_ECP_BAD_INPUT_DATA if input is invalid |
Manuel Pégourié-Gonnard | cae6f3e | 2013-10-23 20:19:57 +0200 | [diff] [blame] | 471 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 472 | int mbedtls_ecp_tls_read_point( const mbedtls_ecp_group *grp, mbedtls_ecp_point *pt, |
Manuel Pégourié-Gonnard | cae6f3e | 2013-10-23 20:19:57 +0200 | [diff] [blame] | 473 | const unsigned char **buf, size_t len ); |
| 474 | |
| 475 | /** |
| 476 | * \brief Export a point as a TLS ECPoint record |
| 477 | * |
| 478 | * \param grp ECP group used |
| 479 | * \param pt Point to export |
| 480 | * \param format Export format |
| 481 | * \param olen length of data written |
| 482 | * \param buf Buffer to write to |
| 483 | * \param blen Buffer length |
| 484 | * |
| 485 | * \return 0 if successful, |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 486 | * or MBEDTLS_ERR_ECP_BAD_INPUT_DATA |
| 487 | * or MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL |
Manuel Pégourié-Gonnard | cae6f3e | 2013-10-23 20:19:57 +0200 | [diff] [blame] | 488 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 489 | int mbedtls_ecp_tls_write_point( const mbedtls_ecp_group *grp, const mbedtls_ecp_point *pt, |
Manuel Pégourié-Gonnard | cae6f3e | 2013-10-23 20:19:57 +0200 | [diff] [blame] | 490 | int format, size_t *olen, |
| 491 | unsigned char *buf, size_t blen ); |
| 492 | |
| 493 | /** |
Manuel Pégourié-Gonnard | a5402fe | 2012-11-07 20:24:05 +0100 | [diff] [blame] | 494 | * \brief Set a group using well-known domain parameters |
| 495 | * |
| 496 | * \param grp Destination group |
Hanno Becker | 61937d4 | 2017-04-26 15:01:23 +0100 | [diff] [blame] | 497 | * \param id Index in the list of well-known domain parameters |
Manuel Pégourié-Gonnard | a5402fe | 2012-11-07 20:24:05 +0100 | [diff] [blame] | 498 | * |
Manuel Pégourié-Gonnard | eecb43c | 2015-05-12 12:56:41 +0200 | [diff] [blame] | 499 | * \return 0 if successful, |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 500 | * MBEDTLS_ERR_MPI_XXX if initialization failed |
| 501 | * MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE for unkownn groups |
Manuel Pégourié-Gonnard | a5402fe | 2012-11-07 20:24:05 +0100 | [diff] [blame] | 502 | * |
Manuel Pégourié-Gonnard | aff37e5 | 2015-05-11 18:11:57 +0200 | [diff] [blame] | 503 | * \note Index should be a value of RFC 4492's enum NamedCurve, |
| 504 | * usually in the form of a MBEDTLS_ECP_DP_XXX macro. |
Manuel Pégourié-Gonnard | a5402fe | 2012-11-07 20:24:05 +0100 | [diff] [blame] | 505 | */ |
Hanno Becker | 61937d4 | 2017-04-26 15:01:23 +0100 | [diff] [blame] | 506 | int mbedtls_ecp_group_load( mbedtls_ecp_group *grp, mbedtls_ecp_group_id id ); |
Manuel Pégourié-Gonnard | 1a96728 | 2013-02-09 17:03:58 +0100 | [diff] [blame] | 507 | |
| 508 | /** |
Manuel Pégourié-Gonnard | 0079405 | 2013-02-09 19:00:07 +0100 | [diff] [blame] | 509 | * \brief Set a group from a TLS ECParameters record |
Manuel Pégourié-Gonnard | 1a96728 | 2013-02-09 17:03:58 +0100 | [diff] [blame] | 510 | * |
| 511 | * \param grp Destination group |
Manuel Pégourié-Gonnard | 7c145c6 | 2013-02-10 13:20:52 +0100 | [diff] [blame] | 512 | * \param buf &(Start of input buffer) |
Manuel Pégourié-Gonnard | 1a96728 | 2013-02-09 17:03:58 +0100 | [diff] [blame] | 513 | * \param len Buffer length |
| 514 | * |
Manuel Pégourié-Gonnard | 150c4f6 | 2014-11-21 09:14:52 +0100 | [diff] [blame] | 515 | * \note buf is updated to point right after ECParameters on exit |
| 516 | * |
Manuel Pégourié-Gonnard | eecb43c | 2015-05-12 12:56:41 +0200 | [diff] [blame] | 517 | * \return 0 if successful, |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 518 | * MBEDTLS_ERR_MPI_XXX if initialization failed |
| 519 | * MBEDTLS_ERR_ECP_BAD_INPUT_DATA if input is invalid |
Manuel Pégourié-Gonnard | 1a96728 | 2013-02-09 17:03:58 +0100 | [diff] [blame] | 520 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 521 | int mbedtls_ecp_tls_read_group( mbedtls_ecp_group *grp, const unsigned char **buf, size_t len ); |
Manuel Pégourié-Gonnard | a5402fe | 2012-11-07 20:24:05 +0100 | [diff] [blame] | 522 | |
| 523 | /** |
Manuel Pégourié-Gonnard | b325887 | 2013-02-10 12:06:19 +0100 | [diff] [blame] | 524 | * \brief Write the TLS ECParameters record for a group |
| 525 | * |
| 526 | * \param grp ECP group used |
| 527 | * \param olen Number of bytes actually written |
| 528 | * \param buf Buffer to write to |
| 529 | * \param blen Buffer length |
| 530 | * |
| 531 | * \return 0 if successful, |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 532 | * or MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL |
Manuel Pégourié-Gonnard | b325887 | 2013-02-10 12:06:19 +0100 | [diff] [blame] | 533 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 534 | int mbedtls_ecp_tls_write_group( const mbedtls_ecp_group *grp, size_t *olen, |
Manuel Pégourié-Gonnard | b325887 | 2013-02-10 12:06:19 +0100 | [diff] [blame] | 535 | unsigned char *buf, size_t blen ); |
| 536 | |
| 537 | /** |
Manuel Pégourié-Gonnard | 39d2adb | 2012-10-31 09:26:55 +0100 | [diff] [blame] | 538 | * \brief Multiplication by an integer: R = m * P |
Paul Bakker | 6838bd1 | 2013-09-30 13:56:38 +0200 | [diff] [blame] | 539 | * (Not thread-safe to use same group in multiple threads) |
Manuel Pégourié-Gonnard | 39d2adb | 2012-10-31 09:26:55 +0100 | [diff] [blame] | 540 | * |
Manuel Pégourié-Gonnard | 56cc88a | 2015-05-11 18:40:45 +0200 | [diff] [blame] | 541 | * \note In order to prevent timing attacks, this function |
| 542 | * executes the exact same sequence of (base field) |
| 543 | * operations for any valid m. It avoids any if-branch or |
| 544 | * array index depending on the value of m. |
| 545 | * |
Manuel Pégourié-Gonnard | 966cb79 | 2020-06-04 10:20:12 +0200 | [diff] [blame] | 546 | * \note If \p f_rng is not NULL, it is used to randomize |
| 547 | * intermediate results to prevent potential timing attacks |
| 548 | * targeting these results. We recommend always providing |
| 549 | * a non-NULL \p f_rng. The overhead is negligible. |
| 550 | * Note: unless #MBEDTLS_ECP_NO_INTERNAL_RNG is defined, when |
| 551 | * \p f_rng is NULL, an internal RNG (seeded from the value |
| 552 | * of \p m) will be used instead. |
Manuel Pégourié-Gonnard | 56cc88a | 2015-05-11 18:40:45 +0200 | [diff] [blame] | 553 | * |
Manuel Pégourié-Gonnard | 39d2adb | 2012-10-31 09:26:55 +0100 | [diff] [blame] | 554 | * \param grp ECP group |
| 555 | * \param R Destination point |
| 556 | * \param m Integer by which to multiply |
| 557 | * \param P Point to multiply |
Manuel Pégourié-Gonnard | e09d2f8 | 2013-09-02 14:29:09 +0200 | [diff] [blame] | 558 | * \param f_rng RNG function (see notes) |
| 559 | * \param p_rng RNG parameter |
Manuel Pégourié-Gonnard | 39d2adb | 2012-10-31 09:26:55 +0100 | [diff] [blame] | 560 | * |
Manuel Pégourié-Gonnard | 7cfcea3 | 2012-11-05 10:06:12 +0100 | [diff] [blame] | 561 | * \return 0 if successful, |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 562 | * MBEDTLS_ERR_ECP_INVALID_KEY if m is not a valid privkey |
Manuel Pégourié-Gonnard | ff27b7c | 2013-11-21 09:28:03 +0100 | [diff] [blame] | 563 | * or P is not a valid pubkey, |
Manuel Pégourié-Gonnard | 6a8ca33 | 2015-05-28 09:33:39 +0200 | [diff] [blame] | 564 | * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed |
Manuel Pégourié-Gonnard | 39d2adb | 2012-10-31 09:26:55 +0100 | [diff] [blame] | 565 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 566 | int mbedtls_ecp_mul( mbedtls_ecp_group *grp, mbedtls_ecp_point *R, |
| 567 | const mbedtls_mpi *m, const mbedtls_ecp_point *P, |
Manuel Pégourié-Gonnard | 09ceaf4 | 2013-11-20 23:06:14 +0100 | [diff] [blame] | 568 | int (*f_rng)(void *, unsigned char *, size_t), void *p_rng ); |
Manuel Pégourié-Gonnard | 39d2adb | 2012-10-31 09:26:55 +0100 | [diff] [blame] | 569 | |
| 570 | /** |
Manuel Pégourié-Gonnard | 56cc88a | 2015-05-11 18:40:45 +0200 | [diff] [blame] | 571 | * \brief Multiplication and addition of two points by integers: |
| 572 | * R = m * P + n * Q |
| 573 | * (Not thread-safe to use same group in multiple threads) |
| 574 | * |
Manuel Pégourié-Gonnard | 151dc77 | 2015-05-14 13:55:51 +0200 | [diff] [blame] | 575 | * \note In contrast to mbedtls_ecp_mul(), this function does not guarantee |
Manuel Pégourié-Gonnard | 56cc88a | 2015-05-11 18:40:45 +0200 | [diff] [blame] | 576 | * a constant execution flow and timing. |
| 577 | * |
| 578 | * \param grp ECP group |
| 579 | * \param R Destination point |
| 580 | * \param m Integer by which to multiply P |
| 581 | * \param P Point to multiply by m |
| 582 | * \param n Integer by which to multiply Q |
| 583 | * \param Q Point to be multiplied by n |
| 584 | * |
| 585 | * \return 0 if successful, |
| 586 | * MBEDTLS_ERR_ECP_INVALID_KEY if m or n is not a valid privkey |
| 587 | * or P or Q is not a valid pubkey, |
Manuel Pégourié-Gonnard | 6a8ca33 | 2015-05-28 09:33:39 +0200 | [diff] [blame] | 588 | * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed |
Manuel Pégourié-Gonnard | 56cc88a | 2015-05-11 18:40:45 +0200 | [diff] [blame] | 589 | */ |
| 590 | int mbedtls_ecp_muladd( mbedtls_ecp_group *grp, mbedtls_ecp_point *R, |
| 591 | const mbedtls_mpi *m, const mbedtls_ecp_point *P, |
| 592 | const mbedtls_mpi *n, const mbedtls_ecp_point *Q ); |
| 593 | |
| 594 | /** |
Manuel Pégourié-Gonnard | c8dc295 | 2013-07-01 14:06:13 +0200 | [diff] [blame] | 595 | * \brief Check that a point is a valid public key on this curve |
| 596 | * |
| 597 | * \param grp Curve/group the point should belong to |
| 598 | * \param pt Point to check |
| 599 | * |
| 600 | * \return 0 if point is a valid public key, |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 601 | * MBEDTLS_ERR_ECP_INVALID_KEY otherwise. |
Manuel Pégourié-Gonnard | c8dc295 | 2013-07-01 14:06:13 +0200 | [diff] [blame] | 602 | * |
| 603 | * \note This function only checks the point is non-zero, has valid |
| 604 | * coordinates and lies on the curve, but not that it is |
| 605 | * indeed a multiple of G. This is additional check is more |
| 606 | * expensive, isn't required by standards, and shouldn't be |
| 607 | * necessary if the group used has a small cofactor. In |
| 608 | * particular, it is useless for the NIST groups which all |
| 609 | * have a cofactor of 1. |
| 610 | * |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 611 | * \note Uses bare components rather than an mbedtls_ecp_keypair structure |
Manuel Pégourié-Gonnard | c8dc295 | 2013-07-01 14:06:13 +0200 | [diff] [blame] | 612 | * in order to ease use with other structures such as |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 613 | * mbedtls_ecdh_context of mbedtls_ecdsa_context. |
Manuel Pégourié-Gonnard | c8dc295 | 2013-07-01 14:06:13 +0200 | [diff] [blame] | 614 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 615 | int mbedtls_ecp_check_pubkey( const mbedtls_ecp_group *grp, const mbedtls_ecp_point *pt ); |
Manuel Pégourié-Gonnard | c8dc295 | 2013-07-01 14:06:13 +0200 | [diff] [blame] | 616 | |
| 617 | /** |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 618 | * \brief Check that an mbedtls_mpi is a valid private key for this curve |
Manuel Pégourié-Gonnard | c8dc295 | 2013-07-01 14:06:13 +0200 | [diff] [blame] | 619 | * |
| 620 | * \param grp Group used |
| 621 | * \param d Integer to check |
| 622 | * |
| 623 | * \return 0 if point is a valid private key, |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 624 | * MBEDTLS_ERR_ECP_INVALID_KEY otherwise. |
Manuel Pégourié-Gonnard | c8dc295 | 2013-07-01 14:06:13 +0200 | [diff] [blame] | 625 | * |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 626 | * \note Uses bare components rather than an mbedtls_ecp_keypair structure |
Manuel Pégourié-Gonnard | c8dc295 | 2013-07-01 14:06:13 +0200 | [diff] [blame] | 627 | * in order to ease use with other structures such as |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 628 | * mbedtls_ecdh_context of mbedtls_ecdsa_context. |
Manuel Pégourié-Gonnard | c8dc295 | 2013-07-01 14:06:13 +0200 | [diff] [blame] | 629 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 630 | int mbedtls_ecp_check_privkey( const mbedtls_ecp_group *grp, const mbedtls_mpi *d ); |
Manuel Pégourié-Gonnard | c8dc295 | 2013-07-01 14:06:13 +0200 | [diff] [blame] | 631 | |
| 632 | /** |
Manuel Pégourié-Gonnard | c80555d | 2017-04-20 15:37:46 +0200 | [diff] [blame] | 633 | * \brief Generate a private key |
| 634 | * |
| 635 | * \param grp ECP group |
| 636 | * \param d Destination MPI (secret part) |
| 637 | * \param f_rng RNG function |
| 638 | * \param p_rng RNG parameter |
| 639 | * |
| 640 | * \return 0 if successful, |
| 641 | * or a MBEDTLS_ERR_ECP_XXX or MBEDTLS_MPI_XXX error code |
| 642 | */ |
| 643 | int mbedtls_ecp_gen_privkey( const mbedtls_ecp_group *grp, |
| 644 | mbedtls_mpi *d, |
| 645 | int (*f_rng)(void *, unsigned char *, size_t), |
| 646 | void *p_rng ); |
| 647 | |
| 648 | /** |
Manuel Pégourié-Gonnard | d9a3f47 | 2015-08-11 14:31:03 +0200 | [diff] [blame] | 649 | * \brief Generate a keypair with configurable base point |
| 650 | * |
| 651 | * \param grp ECP group |
| 652 | * \param G Chosen base point |
| 653 | * \param d Destination MPI (secret part) |
| 654 | * \param Q Destination point (public part) |
| 655 | * \param f_rng RNG function |
| 656 | * \param p_rng RNG parameter |
| 657 | * |
| 658 | * \return 0 if successful, |
| 659 | * or a MBEDTLS_ERR_ECP_XXX or MBEDTLS_MPI_XXX error code |
| 660 | * |
| 661 | * \note Uses bare components rather than an mbedtls_ecp_keypair structure |
| 662 | * in order to ease use with other structures such as |
| 663 | * mbedtls_ecdh_context of mbedtls_ecdsa_context. |
| 664 | */ |
| 665 | int mbedtls_ecp_gen_keypair_base( mbedtls_ecp_group *grp, |
| 666 | const mbedtls_ecp_point *G, |
| 667 | mbedtls_mpi *d, mbedtls_ecp_point *Q, |
| 668 | int (*f_rng)(void *, unsigned char *, size_t), |
| 669 | void *p_rng ); |
| 670 | |
| 671 | /** |
Manuel Pégourié-Gonnard | 45a035a | 2013-01-26 14:42:45 +0100 | [diff] [blame] | 672 | * \brief Generate a keypair |
| 673 | * |
| 674 | * \param grp ECP group |
| 675 | * \param d Destination MPI (secret part) |
| 676 | * \param Q Destination point (public part) |
| 677 | * \param f_rng RNG function |
| 678 | * \param p_rng RNG parameter |
| 679 | * |
| 680 | * \return 0 if successful, |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 681 | * or a MBEDTLS_ERR_ECP_XXX or MBEDTLS_MPI_XXX error code |
Manuel Pégourié-Gonnard | c8dc295 | 2013-07-01 14:06:13 +0200 | [diff] [blame] | 682 | * |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 683 | * \note Uses bare components rather than an mbedtls_ecp_keypair structure |
Manuel Pégourié-Gonnard | c8dc295 | 2013-07-01 14:06:13 +0200 | [diff] [blame] | 684 | * in order to ease use with other structures such as |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 685 | * mbedtls_ecdh_context of mbedtls_ecdsa_context. |
Manuel Pégourié-Gonnard | 45a035a | 2013-01-26 14:42:45 +0100 | [diff] [blame] | 686 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 687 | int mbedtls_ecp_gen_keypair( mbedtls_ecp_group *grp, mbedtls_mpi *d, mbedtls_ecp_point *Q, |
Manuel Pégourié-Gonnard | 45a035a | 2013-01-26 14:42:45 +0100 | [diff] [blame] | 688 | int (*f_rng)(void *, unsigned char *, size_t), |
| 689 | void *p_rng ); |
| 690 | |
| 691 | /** |
Manuel Pégourié-Gonnard | 104ee1d | 2013-11-30 14:13:16 +0100 | [diff] [blame] | 692 | * \brief Generate a keypair |
| 693 | * |
| 694 | * \param grp_id ECP group identifier |
| 695 | * \param key Destination keypair |
| 696 | * \param f_rng RNG function |
| 697 | * \param p_rng RNG parameter |
| 698 | * |
| 699 | * \return 0 if successful, |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 700 | * or a MBEDTLS_ERR_ECP_XXX or MBEDTLS_MPI_XXX error code |
Manuel Pégourié-Gonnard | 104ee1d | 2013-11-30 14:13:16 +0100 | [diff] [blame] | 701 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 702 | int mbedtls_ecp_gen_key( mbedtls_ecp_group_id grp_id, mbedtls_ecp_keypair *key, |
Manuel Pégourié-Gonnard | 104ee1d | 2013-11-30 14:13:16 +0100 | [diff] [blame] | 703 | int (*f_rng)(void *, unsigned char *, size_t), void *p_rng ); |
| 704 | |
Manuel Pégourié-Gonnard | 30668d6 | 2014-11-06 15:25:32 +0100 | [diff] [blame] | 705 | /** |
| 706 | * \brief Check a public-private key pair |
| 707 | * |
| 708 | * \param pub Keypair structure holding a public key |
| 709 | * \param prv Keypair structure holding a private (plus public) key |
| 710 | * |
Manuel Pégourié-Gonnard | 862d503 | 2015-04-15 11:30:46 +0200 | [diff] [blame] | 711 | * \return 0 if successful (keys are valid and match), or |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 712 | * MBEDTLS_ERR_ECP_BAD_INPUT_DATA, or |
| 713 | * a MBEDTLS_ERR_ECP_XXX or MBEDTLS_ERR_MPI_XXX code. |
Manuel Pégourié-Gonnard | 30668d6 | 2014-11-06 15:25:32 +0100 | [diff] [blame] | 714 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 715 | int mbedtls_ecp_check_pub_priv( const mbedtls_ecp_keypair *pub, const mbedtls_ecp_keypair *prv ); |
Manuel Pégourié-Gonnard | 30668d6 | 2014-11-06 15:25:32 +0100 | [diff] [blame] | 716 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 717 | #if defined(MBEDTLS_SELF_TEST) |
Janos Follath | b069753 | 2016-08-18 12:38:46 +0100 | [diff] [blame] | 718 | |
Manuel Pégourié-Gonnard | 104ee1d | 2013-11-30 14:13:16 +0100 | [diff] [blame] | 719 | /** |
Manuel Pégourié-Gonnard | 39d2adb | 2012-10-31 09:26:55 +0100 | [diff] [blame] | 720 | * \brief Checkup routine |
| 721 | * |
Manuel Pégourié-Gonnard | 13a1ef8 | 2014-03-27 20:12:44 +0100 | [diff] [blame] | 722 | * \return 0 if successful, or 1 if a test failed |
Manuel Pégourié-Gonnard | 39d2adb | 2012-10-31 09:26:55 +0100 | [diff] [blame] | 723 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 724 | int mbedtls_ecp_self_test( int verbose ); |
Janos Follath | b069753 | 2016-08-18 12:38:46 +0100 | [diff] [blame] | 725 | |
Janos Follath | 372697b | 2016-10-28 16:53:11 +0100 | [diff] [blame] | 726 | #endif /* MBEDTLS_SELF_TEST */ |
Manuel Pégourié-Gonnard | 39d2adb | 2012-10-31 09:26:55 +0100 | [diff] [blame] | 727 | |
| 728 | #ifdef __cplusplus |
| 729 | } |
| 730 | #endif |
| 731 | |
Janos Follath | b069753 | 2016-08-18 12:38:46 +0100 | [diff] [blame] | 732 | #else /* MBEDTLS_ECP_ALT */ |
| 733 | #include "ecp_alt.h" |
| 734 | #endif /* MBEDTLS_ECP_ALT */ |
| 735 | |
Paul Bakker | 9af723c | 2014-05-01 13:03:14 +0200 | [diff] [blame] | 736 | #endif /* ecp.h */ |