Manuel Pégourié-Gonnard | 2aea141 | 2013-01-26 16:33:44 +0100 | [diff] [blame] | 1 | /** |
| 2 | * \file ecdsa.h |
| 3 | * |
Rose Zadik | 817297f | 2018-03-27 11:30:14 +0100 | [diff] [blame] | 4 | * \brief This file contains ECDSA definitions and functions. |
Manuel Pégourié-Gonnard | 2aea141 | 2013-01-26 16:33:44 +0100 | [diff] [blame] | 5 | * |
Rose Zadik | 817297f | 2018-03-27 11:30:14 +0100 | [diff] [blame] | 6 | * The Elliptic Curve Digital Signature Algorithm (ECDSA) is defined in |
| 7 | * <em>Standards for Efficient Cryptography Group (SECG): |
Rose Zadik | bff87d9 | 2018-01-25 21:58:53 +0000 | [diff] [blame] | 8 | * SEC1 Elliptic Curve Cryptography</em>. |
| 9 | * The use of ECDSA for TLS is defined in <em>RFC-4492: Elliptic Curve |
| 10 | * Cryptography (ECC) Cipher Suites for Transport Layer Security (TLS)</em>. |
| 11 | * |
Darryl Green | a40a101 | 2018-01-05 15:33:17 +0000 | [diff] [blame] | 12 | */ |
| 13 | /* |
Rose Zadik | bff87d9 | 2018-01-25 21:58:53 +0000 | [diff] [blame] | 14 | * Copyright (C) 2006-2018, Arm Limited (or its affiliates), All Rights Reserved |
Manuel Pégourié-Gonnard | 37ff140 | 2015-09-04 14:21:07 +0200 | [diff] [blame] | 15 | * SPDX-License-Identifier: Apache-2.0 |
| 16 | * |
| 17 | * Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 18 | * not use this file except in compliance with the License. |
| 19 | * You may obtain a copy of the License at |
| 20 | * |
| 21 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 22 | * |
| 23 | * Unless required by applicable law or agreed to in writing, software |
| 24 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 25 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 26 | * See the License for the specific language governing permissions and |
| 27 | * limitations under the License. |
Manuel Pégourié-Gonnard | 2aea141 | 2013-01-26 16:33:44 +0100 | [diff] [blame] | 28 | * |
Rose Zadik | bff87d9 | 2018-01-25 21:58:53 +0000 | [diff] [blame] | 29 | * This file is part of Mbed TLS (https://tls.mbed.org) |
Manuel Pégourié-Gonnard | 2aea141 | 2013-01-26 16:33:44 +0100 | [diff] [blame] | 30 | */ |
Rose Zadik | bff87d9 | 2018-01-25 21:58:53 +0000 | [diff] [blame] | 31 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 32 | #ifndef MBEDTLS_ECDSA_H |
| 33 | #define MBEDTLS_ECDSA_H |
Manuel Pégourié-Gonnard | 2aea141 | 2013-01-26 16:33:44 +0100 | [diff] [blame] | 34 | |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 35 | #if !defined(MBEDTLS_CONFIG_FILE) |
Jaeden Amero | 203fdf7 | 2019-07-04 20:01:14 +0100 | [diff] [blame] | 36 | #include "mbedtls/config.h" |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 37 | #else |
| 38 | #include MBEDTLS_CONFIG_FILE |
| 39 | #endif |
| 40 | |
Jaeden Amero | 203fdf7 | 2019-07-04 20:01:14 +0100 | [diff] [blame] | 41 | #include "mbedtls/ecp.h" |
| 42 | #include "mbedtls/md.h" |
Jaeden Amero | 59ebddf | 2019-07-10 11:03:03 +0100 | [diff] [blame] | 43 | #include "mbedtls/platform_util.h" |
Manuel Pégourié-Gonnard | 4daaef7 | 2014-01-06 14:25:56 +0100 | [diff] [blame] | 44 | |
Manuel Pégourié-Gonnard | 2f2b396 | 2018-11-12 15:06:57 +0100 | [diff] [blame] | 45 | /** |
| 46 | * \brief Maximum ECDSA signature size for a given curve bit size |
Manuel Pégourié-Gonnard | 63e9319 | 2015-03-31 11:15:48 +0200 | [diff] [blame] | 47 | * |
Manuel Pégourié-Gonnard | 2f2b396 | 2018-11-12 15:06:57 +0100 | [diff] [blame] | 48 | * \param bits Curve size in bits |
| 49 | * \return Maximum signature size in bytes |
| 50 | * |
| 51 | * \note This macro returns a compile-time constant if its argument |
| 52 | * is one. It may evaluate its argument multiple times. |
| 53 | */ |
| 54 | /* |
Manuel Pégourié-Gonnard | 63e9319 | 2015-03-31 11:15:48 +0200 | [diff] [blame] | 55 | * Ecdsa-Sig-Value ::= SEQUENCE { |
| 56 | * r INTEGER, |
| 57 | * s INTEGER |
| 58 | * } |
| 59 | * |
Manuel Pégourié-Gonnard | 2f2b396 | 2018-11-12 15:06:57 +0100 | [diff] [blame] | 60 | * For each of r and s, the value (V) may include an extra initial "0" bit. |
Manuel Pégourié-Gonnard | 63e9319 | 2015-03-31 11:15:48 +0200 | [diff] [blame] | 61 | */ |
Manuel Pégourié-Gonnard | 2f2b396 | 2018-11-12 15:06:57 +0100 | [diff] [blame] | 62 | #define MBEDTLS_ECDSA_MAX_SIG_LEN( bits ) \ |
| 63 | ( /*T,L of SEQUENCE*/ ( ( bits ) >= 61 * 8 ? 3 : 2 ) + \ |
| 64 | /*T,L of r,s*/ 2 * ( ( ( bits ) >= 127 * 8 ? 3 : 2 ) + \ |
| 65 | /*V of r,s*/ ( ( bits ) + 8 ) / 8 ) ) |
| 66 | |
Rose Zadik | bff87d9 | 2018-01-25 21:58:53 +0000 | [diff] [blame] | 67 | /** The maximal size of an ECDSA signature in Bytes. */ |
Manuel Pégourié-Gonnard | 2f2b396 | 2018-11-12 15:06:57 +0100 | [diff] [blame] | 68 | #define MBEDTLS_ECDSA_MAX_LEN MBEDTLS_ECDSA_MAX_SIG_LEN( MBEDTLS_ECP_MAX_BITS ) |
Manuel Pégourié-Gonnard | 63e9319 | 2015-03-31 11:15:48 +0200 | [diff] [blame] | 69 | |
Manuel Pégourié-Gonnard | 32aa437 | 2017-04-21 10:29:13 +0200 | [diff] [blame] | 70 | #ifdef __cplusplus |
| 71 | extern "C" { |
| 72 | #endif |
| 73 | |
Manuel Pégourié-Gonnard | bec2f45 | 2013-06-27 10:17:07 +0200 | [diff] [blame] | 74 | /** |
Manuel Pégourié-Gonnard | da19f4c | 2018-06-12 12:40:54 +0200 | [diff] [blame] | 75 | * \brief The ECDSA context structure. |
Manuel Pégourié-Gonnard | eaf55be | 2017-08-23 14:40:21 +0200 | [diff] [blame] | 76 | * |
| 77 | * \warning Performing multiple operations concurrently on the same |
| 78 | * ECDSA context is not supported; objects of this type |
| 79 | * should not be shared between multiple threads. |
Manuel Pégourié-Gonnard | bec2f45 | 2013-06-27 10:17:07 +0200 | [diff] [blame] | 80 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 81 | typedef mbedtls_ecp_keypair mbedtls_ecdsa_context; |
Manuel Pégourié-Gonnard | bec2f45 | 2013-06-27 10:17:07 +0200 | [diff] [blame] | 82 | |
Manuel Pégourié-Gonnard | 32aa437 | 2017-04-21 10:29:13 +0200 | [diff] [blame] | 83 | #if defined(MBEDTLS_ECP_RESTARTABLE) |
| 84 | |
| 85 | /** |
Manuel Pégourié-Gonnard | a0c5bcc | 2017-04-21 11:33:57 +0200 | [diff] [blame] | 86 | * \brief Internal restart context for ecdsa_verify() |
| 87 | * |
Manuel Pégourié-Gonnard | f0bbd7e | 2018-10-15 13:22:41 +0200 | [diff] [blame] | 88 | * \note Opaque struct, defined in ecdsa.c |
Manuel Pégourié-Gonnard | a0c5bcc | 2017-04-21 11:33:57 +0200 | [diff] [blame] | 89 | */ |
| 90 | typedef struct mbedtls_ecdsa_restart_ver mbedtls_ecdsa_restart_ver_ctx; |
| 91 | |
| 92 | /** |
Manuel Pégourié-Gonnard | b90883d | 2017-04-25 11:33:10 +0200 | [diff] [blame] | 93 | * \brief Internal restart context for ecdsa_sign() |
| 94 | * |
| 95 | * \note Opaque struct, defined in ecdsa.c |
| 96 | */ |
| 97 | typedef struct mbedtls_ecdsa_restart_sig mbedtls_ecdsa_restart_sig_ctx; |
| 98 | |
| 99 | #if defined(MBEDTLS_ECDSA_DETERMINISTIC) |
| 100 | /** |
| 101 | * \brief Internal restart context for ecdsa_sign_det() |
| 102 | * |
| 103 | * \note Opaque struct, defined in ecdsa.c |
| 104 | */ |
| 105 | typedef struct mbedtls_ecdsa_restart_det mbedtls_ecdsa_restart_det_ctx; |
| 106 | #endif |
| 107 | |
| 108 | /** |
Manuel Pégourié-Gonnard | 32aa437 | 2017-04-21 10:29:13 +0200 | [diff] [blame] | 109 | * \brief General context for resuming ECDSA operations |
| 110 | */ |
| 111 | typedef struct |
| 112 | { |
Manuel Pégourié-Gonnard | 12e4a8b | 2018-09-12 10:55:15 +0200 | [diff] [blame] | 113 | mbedtls_ecp_restart_ctx ecp; /*!< base context for ECP restart and |
| 114 | shared administrative info */ |
Manuel Pégourié-Gonnard | a0c5bcc | 2017-04-21 11:33:57 +0200 | [diff] [blame] | 115 | mbedtls_ecdsa_restart_ver_ctx *ver; /*!< ecdsa_verify() sub-context */ |
Manuel Pégourié-Gonnard | b90883d | 2017-04-25 11:33:10 +0200 | [diff] [blame] | 116 | mbedtls_ecdsa_restart_sig_ctx *sig; /*!< ecdsa_sign() sub-context */ |
| 117 | #if defined(MBEDTLS_ECDSA_DETERMINISTIC) |
| 118 | mbedtls_ecdsa_restart_det_ctx *det; /*!< ecdsa_sign_det() sub-context */ |
| 119 | #endif |
Manuel Pégourié-Gonnard | 32aa437 | 2017-04-21 10:29:13 +0200 | [diff] [blame] | 120 | } mbedtls_ecdsa_restart_ctx; |
| 121 | |
| 122 | #else /* MBEDTLS_ECP_RESTARTABLE */ |
| 123 | |
| 124 | /* Now we can declare functions that take a pointer to that */ |
| 125 | typedef void mbedtls_ecdsa_restart_ctx; |
| 126 | |
| 127 | #endif /* MBEDTLS_ECP_RESTARTABLE */ |
Manuel Pégourié-Gonnard | 2aea141 | 2013-01-26 16:33:44 +0100 | [diff] [blame] | 128 | |
| 129 | /** |
Rose Zadik | bff87d9 | 2018-01-25 21:58:53 +0000 | [diff] [blame] | 130 | * \brief This function computes the ECDSA signature of a |
| 131 | * previously-hashed message. |
Manuel Pégourié-Gonnard | b309ab2 | 2013-01-26 17:24:59 +0100 | [diff] [blame] | 132 | * |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 133 | * \note The deterministic version implemented in |
| 134 | * mbedtls_ecdsa_sign_det() is usually preferred. |
Manuel Pégourié-Gonnard | b309ab2 | 2013-01-26 17:24:59 +0100 | [diff] [blame] | 135 | * |
Janos Follath | 0a5154b | 2017-03-10 11:31:41 +0000 | [diff] [blame] | 136 | * \note If the bitlength of the message hash is larger than the |
Rose Zadik | 817297f | 2018-03-27 11:30:14 +0100 | [diff] [blame] | 137 | * bitlength of the group order, then the hash is truncated |
| 138 | * as defined in <em>Standards for Efficient Cryptography Group |
| 139 | * (SECG): SEC1 Elliptic Curve Cryptography</em>, section |
| 140 | * 4.1.3, step 5. |
Janos Follath | 0a5154b | 2017-03-10 11:31:41 +0000 | [diff] [blame] | 141 | * |
Rose Zadik | 817297f | 2018-03-27 11:30:14 +0100 | [diff] [blame] | 142 | * \see ecp.h |
| 143 | * |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 144 | * \param grp The context for the elliptic curve to use. |
| 145 | * This must be initialized and have group parameters |
| 146 | * set, for example through mbedtls_ecp_group_load(). |
| 147 | * \param r The MPI context in which to store the first part |
| 148 | * the signature. This must be initialized. |
| 149 | * \param s The MPI context in which to store the second part |
| 150 | * the signature. This must be initialized. |
| 151 | * \param d The private signing key. This must be initialized. |
| 152 | * \param buf The content to be signed. This is usually the hash of |
| 153 | * the original data to be signed. This must be a readable |
| 154 | * buffer of length \p blen Bytes. It may be \c NULL if |
| 155 | * \p blen is zero. |
| 156 | * \param blen The length of \p buf in Bytes. |
| 157 | * \param f_rng The RNG function. This must not be \c NULL. |
| 158 | * \param p_rng The RNG context to be passed to \p f_rng. This may be |
| 159 | * \c NULL if \p f_rng doesn't need a context parameter. |
Manuel Pégourié-Gonnard | b309ab2 | 2013-01-26 17:24:59 +0100 | [diff] [blame] | 160 | * |
Rose Zadik | 817297f | 2018-03-27 11:30:14 +0100 | [diff] [blame] | 161 | * \return \c 0 on success. |
| 162 | * \return An \c MBEDTLS_ERR_ECP_XXX |
Rose Zadik | bff87d9 | 2018-01-25 21:58:53 +0000 | [diff] [blame] | 163 | * or \c MBEDTLS_MPI_XXX error code on failure. |
Manuel Pégourié-Gonnard | b309ab2 | 2013-01-26 17:24:59 +0100 | [diff] [blame] | 164 | */ |
Jaeden Amero | dfc7f4a | 2019-07-10 11:33:37 +0100 | [diff] [blame^] | 165 | MBEDTLS_DEPRECATED |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 166 | int mbedtls_ecdsa_sign( mbedtls_ecp_group *grp, mbedtls_mpi *r, mbedtls_mpi *s, |
| 167 | const mbedtls_mpi *d, const unsigned char *buf, size_t blen, |
Manuel Pégourié-Gonnard | b309ab2 | 2013-01-26 17:24:59 +0100 | [diff] [blame] | 168 | int (*f_rng)(void *, unsigned char *, size_t), void *p_rng ); |
| 169 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 170 | #if defined(MBEDTLS_ECDSA_DETERMINISTIC) |
Manuel Pégourié-Gonnard | 4daaef7 | 2014-01-06 14:25:56 +0100 | [diff] [blame] | 171 | /** |
Rose Zadik | bff87d9 | 2018-01-25 21:58:53 +0000 | [diff] [blame] | 172 | * \brief This function computes the ECDSA signature of a |
| 173 | * previously-hashed message, deterministic version. |
Manuel Pégourié-Gonnard | 4daaef7 | 2014-01-06 14:25:56 +0100 | [diff] [blame] | 174 | * |
Rose Zadik | bff87d9 | 2018-01-25 21:58:53 +0000 | [diff] [blame] | 175 | * For more information, see <em>RFC-6979: Deterministic |
| 176 | * Usage of the Digital Signature Algorithm (DSA) and Elliptic |
| 177 | * Curve Digital Signature Algorithm (ECDSA)</em>. |
Manuel Pégourié-Gonnard | 4daaef7 | 2014-01-06 14:25:56 +0100 | [diff] [blame] | 178 | * |
Janos Follath | 0a5154b | 2017-03-10 11:31:41 +0000 | [diff] [blame] | 179 | * \note If the bitlength of the message hash is larger than the |
| 180 | * bitlength of the group order, then the hash is truncated as |
Rose Zadik | 817297f | 2018-03-27 11:30:14 +0100 | [diff] [blame] | 181 | * defined in <em>Standards for Efficient Cryptography Group |
| 182 | * (SECG): SEC1 Elliptic Curve Cryptography</em>, section |
| 183 | * 4.1.3, step 5. |
Janos Follath | 0a5154b | 2017-03-10 11:31:41 +0000 | [diff] [blame] | 184 | * |
Rose Zadik | 817297f | 2018-03-27 11:30:14 +0100 | [diff] [blame] | 185 | * \see ecp.h |
| 186 | * |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 187 | * \param grp The context for the elliptic curve to use. |
| 188 | * This must be initialized and have group parameters |
| 189 | * set, for example through mbedtls_ecp_group_load(). |
| 190 | * \param r The MPI context in which to store the first part |
| 191 | * the signature. This must be initialized. |
| 192 | * \param s The MPI context in which to store the second part |
| 193 | * the signature. This must be initialized. |
| 194 | * \param d The private signing key. This must be initialized |
| 195 | * and setup, for example through mbedtls_ecp_gen_privkey(). |
| 196 | * \param buf The hashed content to be signed. This must be a readable |
| 197 | * buffer of length \p blen Bytes. It may be \c NULL if |
| 198 | * \p blen is zero. |
| 199 | * \param blen The length of \p buf in Bytes. |
| 200 | * \param md_alg The hash algorithm used to hash the original data. |
Manuel Pégourié-Gonnard | 4daaef7 | 2014-01-06 14:25:56 +0100 | [diff] [blame] | 201 | * |
Rose Zadik | 817297f | 2018-03-27 11:30:14 +0100 | [diff] [blame] | 202 | * \return \c 0 on success. |
Rose Zadik | 14d0d57 | 2018-04-16 16:09:30 +0100 | [diff] [blame] | 203 | * \return An \c MBEDTLS_ERR_ECP_XXX or \c MBEDTLS_MPI_XXX |
Rose Zadik | bff87d9 | 2018-01-25 21:58:53 +0000 | [diff] [blame] | 204 | * error code on failure. |
Manuel Pégourié-Gonnard | 4daaef7 | 2014-01-06 14:25:56 +0100 | [diff] [blame] | 205 | */ |
Jaeden Amero | dfc7f4a | 2019-07-10 11:33:37 +0100 | [diff] [blame^] | 206 | MBEDTLS_DEPRECATED |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 207 | int mbedtls_ecdsa_sign_det( mbedtls_ecp_group *grp, mbedtls_mpi *r, |
| 208 | mbedtls_mpi *s, const mbedtls_mpi *d, |
| 209 | const unsigned char *buf, size_t blen, |
| 210 | mbedtls_md_type_t md_alg ); |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 211 | #endif /* MBEDTLS_ECDSA_DETERMINISTIC */ |
Manuel Pégourié-Gonnard | 4daaef7 | 2014-01-06 14:25:56 +0100 | [diff] [blame] | 212 | |
Manuel Pégourié-Gonnard | b309ab2 | 2013-01-26 17:24:59 +0100 | [diff] [blame] | 213 | /** |
Rose Zadik | bff87d9 | 2018-01-25 21:58:53 +0000 | [diff] [blame] | 214 | * \brief This function verifies the ECDSA signature of a |
| 215 | * previously-hashed message. |
Manuel Pégourié-Gonnard | 3aeb5a7 | 2013-01-26 18:05:50 +0100 | [diff] [blame] | 216 | * |
Janos Follath | 0a5154b | 2017-03-10 11:31:41 +0000 | [diff] [blame] | 217 | * \note If the bitlength of the message hash is larger than the |
| 218 | * bitlength of the group order, then the hash is truncated as |
Rose Zadik | 817297f | 2018-03-27 11:30:14 +0100 | [diff] [blame] | 219 | * defined in <em>Standards for Efficient Cryptography Group |
| 220 | * (SECG): SEC1 Elliptic Curve Cryptography</em>, section |
| 221 | * 4.1.4, step 3. |
Janos Follath | 0a5154b | 2017-03-10 11:31:41 +0000 | [diff] [blame] | 222 | * |
Rose Zadik | 817297f | 2018-03-27 11:30:14 +0100 | [diff] [blame] | 223 | * \see ecp.h |
| 224 | * |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 225 | * \param grp The ECP group to use. |
| 226 | * This must be initialized and have group parameters |
| 227 | * set, for example through mbedtls_ecp_group_load(). |
| 228 | * \param buf The hashed content that was signed. This must be a readable |
| 229 | * buffer of length \p blen Bytes. It may be \c NULL if |
| 230 | * \p blen is zero. |
| 231 | * \param blen The length of \p buf in Bytes. |
| 232 | * \param Q The public key to use for verification. This must be |
| 233 | * initialized and setup. |
Rose Zadik | bff87d9 | 2018-01-25 21:58:53 +0000 | [diff] [blame] | 234 | * \param r The first integer of the signature. |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 235 | * This must be initialized. |
Rose Zadik | bff87d9 | 2018-01-25 21:58:53 +0000 | [diff] [blame] | 236 | * \param s The second integer of the signature. |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 237 | * This must be initialized. |
Manuel Pégourié-Gonnard | 3aeb5a7 | 2013-01-26 18:05:50 +0100 | [diff] [blame] | 238 | * |
Rose Zadik | 817297f | 2018-03-27 11:30:14 +0100 | [diff] [blame] | 239 | * \return \c 0 on success. |
Rose Zadik | 14d0d57 | 2018-04-16 16:09:30 +0100 | [diff] [blame] | 240 | * \return #MBEDTLS_ERR_ECP_BAD_INPUT_DATA if the signature |
| 241 | * is invalid. |
Rose Zadik | 817297f | 2018-03-27 11:30:14 +0100 | [diff] [blame] | 242 | * \return An \c MBEDTLS_ERR_ECP_XXX or \c MBEDTLS_MPI_XXX |
Rose Zadik | bff87d9 | 2018-01-25 21:58:53 +0000 | [diff] [blame] | 243 | * error code on failure for any other reason. |
Manuel Pégourié-Gonnard | 3aeb5a7 | 2013-01-26 18:05:50 +0100 | [diff] [blame] | 244 | */ |
Jaeden Amero | dfc7f4a | 2019-07-10 11:33:37 +0100 | [diff] [blame^] | 245 | MBEDTLS_DEPRECATED |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 246 | int mbedtls_ecdsa_verify( mbedtls_ecp_group *grp, |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 247 | const unsigned char *buf, size_t blen, |
| 248 | const mbedtls_ecp_point *Q, const mbedtls_mpi *r, |
| 249 | const mbedtls_mpi *s); |
Manuel Pégourié-Gonnard | 3aeb5a7 | 2013-01-26 18:05:50 +0100 | [diff] [blame] | 250 | |
| 251 | /** |
Rose Zadik | bff87d9 | 2018-01-25 21:58:53 +0000 | [diff] [blame] | 252 | * \brief This function computes the ECDSA signature and writes it |
| 253 | * to a buffer, serialized as defined in <em>RFC-4492: |
| 254 | * Elliptic Curve Cryptography (ECC) Cipher Suites for |
| 255 | * Transport Layer Security (TLS)</em>. |
Manuel Pégourié-Gonnard | b694b48 | 2013-08-08 13:30:57 +0200 | [diff] [blame] | 256 | * |
Rose Zadik | bff87d9 | 2018-01-25 21:58:53 +0000 | [diff] [blame] | 257 | * \warning It is not thread-safe to use the same context in |
| 258 | * multiple threads. |
Manuel Pégourié-Gonnard | dfdcac9 | 2015-03-31 11:41:42 +0200 | [diff] [blame] | 259 | * |
Rose Zadik | bff87d9 | 2018-01-25 21:58:53 +0000 | [diff] [blame] | 260 | * \note The deterministic version is used if |
| 261 | * #MBEDTLS_ECDSA_DETERMINISTIC is defined. For more |
| 262 | * information, see <em>RFC-6979: Deterministic Usage |
| 263 | * of the Digital Signature Algorithm (DSA) and Elliptic |
| 264 | * Curve Digital Signature Algorithm (ECDSA)</em>. |
Manuel Pégourié-Gonnard | b694b48 | 2013-08-08 13:30:57 +0200 | [diff] [blame] | 265 | * |
Janos Follath | 0a5154b | 2017-03-10 11:31:41 +0000 | [diff] [blame] | 266 | * \note If the bitlength of the message hash is larger than the |
| 267 | * bitlength of the group order, then the hash is truncated as |
Rose Zadik | bff87d9 | 2018-01-25 21:58:53 +0000 | [diff] [blame] | 268 | * defined in <em>Standards for Efficient Cryptography Group |
| 269 | * (SECG): SEC1 Elliptic Curve Cryptography</em>, section |
| 270 | * 4.1.3, step 5. |
Janos Follath | 0a5154b | 2017-03-10 11:31:41 +0000 | [diff] [blame] | 271 | * |
Rose Zadik | bff87d9 | 2018-01-25 21:58:53 +0000 | [diff] [blame] | 272 | * \see ecp.h |
Rose Zadik | 817297f | 2018-03-27 11:30:14 +0100 | [diff] [blame] | 273 | * |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 274 | * \param ctx The ECDSA context to use. This must be initialized |
| 275 | * and have a group and private key bound to it, for example |
| 276 | * via mbedtls_ecdsa_genkey() or mbedtls_ecdsa_from_keypair(). |
Rose Zadik | 817297f | 2018-03-27 11:30:14 +0100 | [diff] [blame] | 277 | * \param md_alg The message digest that was used to hash the message. |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 278 | * \param hash The message hash to be signed. This must be a readable |
| 279 | * buffer of length \p blen Bytes. |
| 280 | * \param hlen The length of the hash \p hash in Bytes. |
| 281 | * \param sig The buffer to which to write the signature. This must be a |
| 282 | * writable buffer of length at least twice as large as the |
| 283 | * size of the curve used, plus 9. For example, 73 Bytes if |
| 284 | * a 256-bit curve is used. A buffer length of |
| 285 | * #MBEDTLS_ECDSA_MAX_LEN is always safe. |
| 286 | * \param slen The address at which to store the actual length of |
| 287 | * the signature written. Must not be \c NULL. |
| 288 | * \param f_rng The RNG function. This must not be \c NULL if |
| 289 | * #MBEDTLS_ECDSA_DETERMINISTIC is unset. Otherwise, |
| 290 | * it is unused and may be set to \c NULL. |
| 291 | * \param p_rng The RNG context to be passed to \p f_rng. This may be |
| 292 | * \c NULL if \p f_rng is \c NULL or doesn't use a context. |
Rose Zadik | 817297f | 2018-03-27 11:30:14 +0100 | [diff] [blame] | 293 | * |
| 294 | * \return \c 0 on success. |
| 295 | * \return An \c MBEDTLS_ERR_ECP_XXX, \c MBEDTLS_ERR_MPI_XXX or |
| 296 | * \c MBEDTLS_ERR_ASN1_XXX error code on failure. |
Manuel Pégourié-Gonnard | b694b48 | 2013-08-08 13:30:57 +0200 | [diff] [blame] | 297 | */ |
Jaeden Amero | dfc7f4a | 2019-07-10 11:33:37 +0100 | [diff] [blame^] | 298 | MBEDTLS_DEPRECATED |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 299 | int mbedtls_ecdsa_write_signature( mbedtls_ecdsa_context *ctx, |
| 300 | mbedtls_md_type_t md_alg, |
Manuel Pégourié-Gonnard | b694b48 | 2013-08-08 13:30:57 +0200 | [diff] [blame] | 301 | const unsigned char *hash, size_t hlen, |
| 302 | unsigned char *sig, size_t *slen, |
| 303 | int (*f_rng)(void *, unsigned char *, size_t), |
| 304 | void *p_rng ); |
| 305 | |
Manuel Pégourié-Gonnard | addb10e | 2017-04-21 12:54:46 +0200 | [diff] [blame] | 306 | /** |
Manuel Pégourié-Gonnard | da19f4c | 2018-06-12 12:40:54 +0200 | [diff] [blame] | 307 | * \brief This function computes the ECDSA signature and writes it |
| 308 | * to a buffer, in a restartable way. |
Manuel Pégourié-Gonnard | addb10e | 2017-04-21 12:54:46 +0200 | [diff] [blame] | 309 | * |
Manuel Pégourié-Gonnard | da19f4c | 2018-06-12 12:40:54 +0200 | [diff] [blame] | 310 | * \see \c mbedtls_ecdsa_write_signature() |
| 311 | * |
| 312 | * \note This function is like \c mbedtls_ecdsa_write_signature() |
| 313 | * but it can return early and restart according to the limit |
Manuel Pégourié-Gonnard | addb10e | 2017-04-21 12:54:46 +0200 | [diff] [blame] | 314 | * set with \c mbedtls_ecp_set_max_ops() to reduce blocking. |
| 315 | * |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 316 | * \param ctx The ECDSA context to use. This must be initialized |
| 317 | * and have a group and private key bound to it, for example |
| 318 | * via mbedtls_ecdsa_genkey() or mbedtls_ecdsa_from_keypair(). |
Manuel Pégourié-Gonnard | da19f4c | 2018-06-12 12:40:54 +0200 | [diff] [blame] | 319 | * \param md_alg The message digest that was used to hash the message. |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 320 | * \param hash The message hash to be signed. This must be a readable |
| 321 | * buffer of length \p blen Bytes. |
| 322 | * \param hlen The length of the hash \p hash in Bytes. |
| 323 | * \param sig The buffer to which to write the signature. This must be a |
| 324 | * writable buffer of length at least twice as large as the |
| 325 | * size of the curve used, plus 9. For example, 73 Bytes if |
| 326 | * a 256-bit curve is used. A buffer length of |
| 327 | * #MBEDTLS_ECDSA_MAX_LEN is always safe. |
| 328 | * \param slen The address at which to store the actual length of |
| 329 | * the signature written. Must not be \c NULL. |
| 330 | * \param f_rng The RNG function. This must not be \c NULL if |
| 331 | * #MBEDTLS_ECDSA_DETERMINISTIC is unset. Otherwise, |
| 332 | * it is unused and may be set to \c NULL. |
| 333 | * \param p_rng The RNG context to be passed to \p f_rng. This may be |
| 334 | * \c NULL if \p f_rng is \c NULL or doesn't use a context. |
| 335 | * \param rs_ctx The restart context to use. This may be \c NULL to disable |
| 336 | * restarting. If it is not \c NULL, it must point to an |
| 337 | * initialized restart context. |
Manuel Pégourié-Gonnard | addb10e | 2017-04-21 12:54:46 +0200 | [diff] [blame] | 338 | * |
Manuel Pégourié-Gonnard | da19f4c | 2018-06-12 12:40:54 +0200 | [diff] [blame] | 339 | * \return \c 0 on success. |
Manuel Pégourié-Gonnard | da19f4c | 2018-06-12 12:40:54 +0200 | [diff] [blame] | 340 | * \return #MBEDTLS_ERR_ECP_IN_PROGRESS if maximum number of |
Manuel Pégourié-Gonnard | addb10e | 2017-04-21 12:54:46 +0200 | [diff] [blame] | 341 | * operations was reached: see \c mbedtls_ecp_set_max_ops(). |
Manuel Pégourié-Gonnard | f0bbd7e | 2018-10-15 13:22:41 +0200 | [diff] [blame] | 342 | * \return Another \c MBEDTLS_ERR_ECP_XXX, \c MBEDTLS_ERR_MPI_XXX or |
| 343 | * \c MBEDTLS_ERR_ASN1_XXX error code on failure. |
Manuel Pégourié-Gonnard | addb10e | 2017-04-21 12:54:46 +0200 | [diff] [blame] | 344 | */ |
Jaeden Amero | dfc7f4a | 2019-07-10 11:33:37 +0100 | [diff] [blame^] | 345 | MBEDTLS_DEPRECATED |
Manuel Pégourié-Gonnard | addb10e | 2017-04-21 12:54:46 +0200 | [diff] [blame] | 346 | int mbedtls_ecdsa_write_signature_restartable( mbedtls_ecdsa_context *ctx, |
| 347 | mbedtls_md_type_t md_alg, |
| 348 | const unsigned char *hash, size_t hlen, |
| 349 | unsigned char *sig, size_t *slen, |
| 350 | int (*f_rng)(void *, unsigned char *, size_t), |
| 351 | void *p_rng, |
| 352 | mbedtls_ecdsa_restart_ctx *rs_ctx ); |
| 353 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 354 | #if defined(MBEDTLS_ECDSA_DETERMINISTIC) |
| 355 | #if ! defined(MBEDTLS_DEPRECATED_REMOVED) |
Manuel Pégourié-Gonnard | 937340b | 2014-01-06 10:27:16 +0100 | [diff] [blame] | 356 | /** |
Rose Zadik | 817297f | 2018-03-27 11:30:14 +0100 | [diff] [blame] | 357 | * \brief This function computes an ECDSA signature and writes |
| 358 | * it to a buffer, serialized as defined in <em>RFC-4492: |
| 359 | * Elliptic Curve Cryptography (ECC) Cipher Suites for |
| 360 | * Transport Layer Security (TLS)</em>. |
Manuel Pégourié-Gonnard | 937340b | 2014-01-06 10:27:16 +0100 | [diff] [blame] | 361 | * |
Rose Zadik | 817297f | 2018-03-27 11:30:14 +0100 | [diff] [blame] | 362 | * The deterministic version is defined in <em>RFC-6979: |
| 363 | * Deterministic Usage of the Digital Signature Algorithm (DSA) |
| 364 | * and Elliptic Curve Digital Signature Algorithm (ECDSA)</em>. |
Manuel Pégourié-Gonnard | dfdcac9 | 2015-03-31 11:41:42 +0200 | [diff] [blame] | 365 | * |
Rose Zadik | bff87d9 | 2018-01-25 21:58:53 +0000 | [diff] [blame] | 366 | * \warning It is not thread-safe to use the same context in |
| 367 | * multiple threads. |
Manuel Pégourié-Gonnard | 937340b | 2014-01-06 10:27:16 +0100 | [diff] [blame] | 368 | * |
Janos Follath | 0a5154b | 2017-03-10 11:31:41 +0000 | [diff] [blame] | 369 | * \note If the bitlength of the message hash is larger than the |
| 370 | * bitlength of the group order, then the hash is truncated as |
Rose Zadik | bff87d9 | 2018-01-25 21:58:53 +0000 | [diff] [blame] | 371 | * defined in <em>Standards for Efficient Cryptography Group |
| 372 | * (SECG): SEC1 Elliptic Curve Cryptography</em>, section |
| 373 | * 4.1.3, step 5. |
Janos Follath | 0a5154b | 2017-03-10 11:31:41 +0000 | [diff] [blame] | 374 | * |
Rose Zadik | bff87d9 | 2018-01-25 21:58:53 +0000 | [diff] [blame] | 375 | * \see ecp.h |
Rose Zadik | 817297f | 2018-03-27 11:30:14 +0100 | [diff] [blame] | 376 | * |
Rose Zadik | ec5d416 | 2018-04-17 15:55:28 +0100 | [diff] [blame] | 377 | * \deprecated Superseded by mbedtls_ecdsa_write_signature() in |
| 378 | * Mbed TLS version 2.0 and later. |
Rose Zadik | 817297f | 2018-03-27 11:30:14 +0100 | [diff] [blame] | 379 | * |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 380 | * \param ctx The ECDSA context to use. This must be initialized |
| 381 | * and have a group and private key bound to it, for example |
| 382 | * via mbedtls_ecdsa_genkey() or mbedtls_ecdsa_from_keypair(). |
| 383 | * \param hash The message hash to be signed. This must be a readable |
| 384 | * buffer of length \p blen Bytes. |
| 385 | * \param hlen The length of the hash \p hash in Bytes. |
| 386 | * \param sig The buffer to which to write the signature. This must be a |
| 387 | * writable buffer of length at least twice as large as the |
| 388 | * size of the curve used, plus 9. For example, 73 Bytes if |
| 389 | * a 256-bit curve is used. A buffer length of |
| 390 | * #MBEDTLS_ECDSA_MAX_LEN is always safe. |
| 391 | * \param slen The address at which to store the actual length of |
| 392 | * the signature written. Must not be \c NULL. |
| 393 | * \param md_alg The message digest that was used to hash the message. |
Rose Zadik | 817297f | 2018-03-27 11:30:14 +0100 | [diff] [blame] | 394 | * |
| 395 | * \return \c 0 on success. |
| 396 | * \return An \c MBEDTLS_ERR_ECP_XXX, \c MBEDTLS_ERR_MPI_XXX or |
| 397 | * \c MBEDTLS_ERR_ASN1_XXX error code on failure. |
Manuel Pégourié-Gonnard | 937340b | 2014-01-06 10:27:16 +0100 | [diff] [blame] | 398 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 399 | int mbedtls_ecdsa_write_signature_det( mbedtls_ecdsa_context *ctx, |
Manuel Pégourié-Gonnard | 937340b | 2014-01-06 10:27:16 +0100 | [diff] [blame] | 400 | const unsigned char *hash, size_t hlen, |
| 401 | unsigned char *sig, size_t *slen, |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 402 | mbedtls_md_type_t md_alg ) MBEDTLS_DEPRECATED; |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 403 | #endif /* MBEDTLS_DEPRECATED_REMOVED */ |
| 404 | #endif /* MBEDTLS_ECDSA_DETERMINISTIC */ |
Manuel Pégourié-Gonnard | 937340b | 2014-01-06 10:27:16 +0100 | [diff] [blame] | 405 | |
Manuel Pégourié-Gonnard | b694b48 | 2013-08-08 13:30:57 +0200 | [diff] [blame] | 406 | /** |
Rose Zadik | bff87d9 | 2018-01-25 21:58:53 +0000 | [diff] [blame] | 407 | * \brief This function reads and verifies an ECDSA signature. |
Manuel Pégourié-Gonnard | b694b48 | 2013-08-08 13:30:57 +0200 | [diff] [blame] | 408 | * |
Janos Follath | 0a5154b | 2017-03-10 11:31:41 +0000 | [diff] [blame] | 409 | * \note If the bitlength of the message hash is larger than the |
| 410 | * bitlength of the group order, then the hash is truncated as |
Rose Zadik | bff87d9 | 2018-01-25 21:58:53 +0000 | [diff] [blame] | 411 | * defined in <em>Standards for Efficient Cryptography Group |
| 412 | * (SECG): SEC1 Elliptic Curve Cryptography</em>, section |
| 413 | * 4.1.4, step 3. |
Janos Follath | 0a5154b | 2017-03-10 11:31:41 +0000 | [diff] [blame] | 414 | * |
Rose Zadik | bff87d9 | 2018-01-25 21:58:53 +0000 | [diff] [blame] | 415 | * \see ecp.h |
Rose Zadik | 817297f | 2018-03-27 11:30:14 +0100 | [diff] [blame] | 416 | * |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 417 | * \param ctx The ECDSA context to use. This must be initialized |
| 418 | * and have a group and public key bound to it. |
| 419 | * \param hash The message hash that was signed. This must be a readable |
| 420 | * buffer of length \p size Bytes. |
| 421 | * \param hlen The size of the hash \p hash. |
| 422 | * \param sig The signature to read and verify. This must be a readable |
| 423 | * buffer of length \p slen Bytes. |
| 424 | * \param slen The size of \p sig in Bytes. |
Rose Zadik | 817297f | 2018-03-27 11:30:14 +0100 | [diff] [blame] | 425 | * |
| 426 | * \return \c 0 on success. |
| 427 | * \return #MBEDTLS_ERR_ECP_BAD_INPUT_DATA if signature is invalid. |
Rose Zadik | abc9ec7 | 2018-04-23 06:16:40 +0100 | [diff] [blame] | 428 | * \return #MBEDTLS_ERR_ECP_SIG_LEN_MISMATCH if there is a valid |
| 429 | * signature in \p sig, but its length is less than \p siglen. |
Rose Zadik | 817297f | 2018-03-27 11:30:14 +0100 | [diff] [blame] | 430 | * \return An \c MBEDTLS_ERR_ECP_XXX or \c MBEDTLS_ERR_MPI_XXX |
| 431 | * error code on failure for any other reason. |
Manuel Pégourié-Gonnard | b694b48 | 2013-08-08 13:30:57 +0200 | [diff] [blame] | 432 | */ |
Jaeden Amero | dfc7f4a | 2019-07-10 11:33:37 +0100 | [diff] [blame^] | 433 | MBEDTLS_DEPRECATED |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 434 | int mbedtls_ecdsa_read_signature( mbedtls_ecdsa_context *ctx, |
Manuel Pégourié-Gonnard | b694b48 | 2013-08-08 13:30:57 +0200 | [diff] [blame] | 435 | const unsigned char *hash, size_t hlen, |
| 436 | const unsigned char *sig, size_t slen ); |
| 437 | |
| 438 | /** |
Manuel Pégourié-Gonnard | da19f4c | 2018-06-12 12:40:54 +0200 | [diff] [blame] | 439 | * \brief This function reads and verifies an ECDSA signature, |
| 440 | * in a restartable way. |
Manuel Pégourié-Gonnard | 32aa437 | 2017-04-21 10:29:13 +0200 | [diff] [blame] | 441 | * |
Manuel Pégourié-Gonnard | da19f4c | 2018-06-12 12:40:54 +0200 | [diff] [blame] | 442 | * \see \c mbedtls_ecdsa_read_signature() |
| 443 | * |
| 444 | * \note This function is like \c mbedtls_ecdsa_read_signature() |
| 445 | * but it can return early and restart according to the limit |
Manuel Pégourié-Gonnard | 32aa437 | 2017-04-21 10:29:13 +0200 | [diff] [blame] | 446 | * set with \c mbedtls_ecp_set_max_ops() to reduce blocking. |
| 447 | * |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 448 | * \param ctx The ECDSA context to use. This must be initialized |
| 449 | * and have a group and public key bound to it. |
| 450 | * \param hash The message hash that was signed. This must be a readable |
| 451 | * buffer of length \p size Bytes. |
| 452 | * \param hlen The size of the hash \p hash. |
| 453 | * \param sig The signature to read and verify. This must be a readable |
| 454 | * buffer of length \p slen Bytes. |
| 455 | * \param slen The size of \p sig in Bytes. |
| 456 | * \param rs_ctx The restart context to use. This may be \c NULL to disable |
| 457 | * restarting. If it is not \c NULL, it must point to an |
| 458 | * initialized restart context. |
Manuel Pégourié-Gonnard | 32aa437 | 2017-04-21 10:29:13 +0200 | [diff] [blame] | 459 | * |
Manuel Pégourié-Gonnard | da19f4c | 2018-06-12 12:40:54 +0200 | [diff] [blame] | 460 | * \return \c 0 on success. |
| 461 | * \return #MBEDTLS_ERR_ECP_BAD_INPUT_DATA if signature is invalid. |
| 462 | * \return #MBEDTLS_ERR_ECP_SIG_LEN_MISMATCH if there is a valid |
| 463 | * signature in \p sig, but its length is less than \p siglen. |
Manuel Pégourié-Gonnard | da19f4c | 2018-06-12 12:40:54 +0200 | [diff] [blame] | 464 | * \return #MBEDTLS_ERR_ECP_IN_PROGRESS if maximum number of |
Manuel Pégourié-Gonnard | 32aa437 | 2017-04-21 10:29:13 +0200 | [diff] [blame] | 465 | * operations was reached: see \c mbedtls_ecp_set_max_ops(). |
Manuel Pégourié-Gonnard | f0bbd7e | 2018-10-15 13:22:41 +0200 | [diff] [blame] | 466 | * \return Another \c MBEDTLS_ERR_ECP_XXX or \c MBEDTLS_ERR_MPI_XXX |
| 467 | * error code on failure for any other reason. |
Manuel Pégourié-Gonnard | 32aa437 | 2017-04-21 10:29:13 +0200 | [diff] [blame] | 468 | */ |
Jaeden Amero | dfc7f4a | 2019-07-10 11:33:37 +0100 | [diff] [blame^] | 469 | MBEDTLS_DEPRECATED |
Manuel Pégourié-Gonnard | 32aa437 | 2017-04-21 10:29:13 +0200 | [diff] [blame] | 470 | int mbedtls_ecdsa_read_signature_restartable( mbedtls_ecdsa_context *ctx, |
| 471 | const unsigned char *hash, size_t hlen, |
| 472 | const unsigned char *sig, size_t slen, |
| 473 | mbedtls_ecdsa_restart_ctx *rs_ctx ); |
| 474 | |
| 475 | /** |
Rose Zadik | bff87d9 | 2018-01-25 21:58:53 +0000 | [diff] [blame] | 476 | * \brief This function generates an ECDSA keypair on the given curve. |
Manuel Pégourié-Gonnard | 8eebd01 | 2013-08-09 16:21:34 +0200 | [diff] [blame] | 477 | * |
Rose Zadik | 817297f | 2018-03-27 11:30:14 +0100 | [diff] [blame] | 478 | * \see ecp.h |
Manuel Pégourié-Gonnard | 8eebd01 | 2013-08-09 16:21:34 +0200 | [diff] [blame] | 479 | * |
Rose Zadik | bff87d9 | 2018-01-25 21:58:53 +0000 | [diff] [blame] | 480 | * \param ctx The ECDSA context to store the keypair in. |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 481 | * This must be initialized. |
Rose Zadik | bff87d9 | 2018-01-25 21:58:53 +0000 | [diff] [blame] | 482 | * \param gid The elliptic curve to use. One of the various |
| 483 | * \c MBEDTLS_ECP_DP_XXX macros depending on configuration. |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 484 | * \param f_rng The RNG function to use. This must not be \c NULL. |
| 485 | * \param p_rng The RNG context to be passed to \p f_rng. This may be |
| 486 | * \c NULL if \p f_rng doesn't need a context argument. |
Manuel Pégourié-Gonnard | 8eebd01 | 2013-08-09 16:21:34 +0200 | [diff] [blame] | 487 | * |
Rose Zadik | 817297f | 2018-03-27 11:30:14 +0100 | [diff] [blame] | 488 | * \return \c 0 on success. |
| 489 | * \return An \c MBEDTLS_ERR_ECP_XXX code on failure. |
Manuel Pégourié-Gonnard | 8eebd01 | 2013-08-09 16:21:34 +0200 | [diff] [blame] | 490 | */ |
Jaeden Amero | dfc7f4a | 2019-07-10 11:33:37 +0100 | [diff] [blame^] | 491 | MBEDTLS_DEPRECATED |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 492 | int mbedtls_ecdsa_genkey( mbedtls_ecdsa_context *ctx, mbedtls_ecp_group_id gid, |
Manuel Pégourié-Gonnard | 8eebd01 | 2013-08-09 16:21:34 +0200 | [diff] [blame] | 493 | int (*f_rng)(void *, unsigned char *, size_t), void *p_rng ); |
| 494 | |
| 495 | /** |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 496 | * \brief This function sets up an ECDSA context from an EC key pair. |
Manuel Pégourié-Gonnard | f499993 | 2013-08-12 17:02:59 +0200 | [diff] [blame] | 497 | * |
Rose Zadik | 817297f | 2018-03-27 11:30:14 +0100 | [diff] [blame] | 498 | * \see ecp.h |
Manuel Pégourié-Gonnard | f499993 | 2013-08-12 17:02:59 +0200 | [diff] [blame] | 499 | * |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 500 | * \param ctx The ECDSA context to setup. This must be initialized. |
| 501 | * \param key The EC key to use. This must be initialized and hold |
| 502 | * a private-public key pair or a public key. In the former |
| 503 | * case, the ECDSA context may be used for signature creation |
| 504 | * and verification after this call. In the latter case, it |
| 505 | * may be used for signature verification. |
Manuel Pégourié-Gonnard | f499993 | 2013-08-12 17:02:59 +0200 | [diff] [blame] | 506 | * |
Rose Zadik | 817297f | 2018-03-27 11:30:14 +0100 | [diff] [blame] | 507 | * \return \c 0 on success. |
| 508 | * \return An \c MBEDTLS_ERR_ECP_XXX code on failure. |
Manuel Pégourié-Gonnard | f499993 | 2013-08-12 17:02:59 +0200 | [diff] [blame] | 509 | */ |
Jaeden Amero | dfc7f4a | 2019-07-10 11:33:37 +0100 | [diff] [blame^] | 510 | MBEDTLS_DEPRECATED |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 511 | int mbedtls_ecdsa_from_keypair( mbedtls_ecdsa_context *ctx, |
| 512 | const mbedtls_ecp_keypair *key ); |
Manuel Pégourié-Gonnard | f499993 | 2013-08-12 17:02:59 +0200 | [diff] [blame] | 513 | |
| 514 | /** |
Rose Zadik | bff87d9 | 2018-01-25 21:58:53 +0000 | [diff] [blame] | 515 | * \brief This function initializes an ECDSA context. |
Manuel Pégourié-Gonnard | 7c8934e | 2013-06-27 12:54:02 +0200 | [diff] [blame] | 516 | * |
Rose Zadik | bff87d9 | 2018-01-25 21:58:53 +0000 | [diff] [blame] | 517 | * \param ctx The ECDSA context to initialize. |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 518 | * This must not be \c NULL. |
Manuel Pégourié-Gonnard | 7c8934e | 2013-06-27 12:54:02 +0200 | [diff] [blame] | 519 | */ |
Jaeden Amero | dfc7f4a | 2019-07-10 11:33:37 +0100 | [diff] [blame^] | 520 | MBEDTLS_DEPRECATED |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 521 | void mbedtls_ecdsa_init( mbedtls_ecdsa_context *ctx ); |
Manuel Pégourié-Gonnard | 7c8934e | 2013-06-27 12:54:02 +0200 | [diff] [blame] | 522 | |
| 523 | /** |
Rose Zadik | bff87d9 | 2018-01-25 21:58:53 +0000 | [diff] [blame] | 524 | * \brief This function frees an ECDSA context. |
Manuel Pégourié-Gonnard | 7c8934e | 2013-06-27 12:54:02 +0200 | [diff] [blame] | 525 | * |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 526 | * \param ctx The ECDSA context to free. This may be \c NULL, |
| 527 | * in which case this function does nothing. If it |
| 528 | * is not \c NULL, it must be initialized. |
Manuel Pégourié-Gonnard | 7c8934e | 2013-06-27 12:54:02 +0200 | [diff] [blame] | 529 | */ |
Jaeden Amero | dfc7f4a | 2019-07-10 11:33:37 +0100 | [diff] [blame^] | 530 | MBEDTLS_DEPRECATED |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 531 | void mbedtls_ecdsa_free( mbedtls_ecdsa_context *ctx ); |
Manuel Pégourié-Gonnard | 7c8934e | 2013-06-27 12:54:02 +0200 | [diff] [blame] | 532 | |
Manuel Pégourié-Gonnard | 32aa437 | 2017-04-21 10:29:13 +0200 | [diff] [blame] | 533 | #if defined(MBEDTLS_ECP_RESTARTABLE) |
| 534 | /** |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 535 | * \brief Initialize a restart context. |
| 536 | * |
| 537 | * \param ctx The restart context to initialize. |
| 538 | * This must not be \c NULL. |
Manuel Pégourié-Gonnard | 32aa437 | 2017-04-21 10:29:13 +0200 | [diff] [blame] | 539 | */ |
Jaeden Amero | dfc7f4a | 2019-07-10 11:33:37 +0100 | [diff] [blame^] | 540 | MBEDTLS_DEPRECATED |
Manuel Pégourié-Gonnard | 32aa437 | 2017-04-21 10:29:13 +0200 | [diff] [blame] | 541 | void mbedtls_ecdsa_restart_init( mbedtls_ecdsa_restart_ctx *ctx ); |
| 542 | |
| 543 | /** |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 544 | * \brief Free the components of a restart context. |
| 545 | * |
| 546 | * \param ctx The restart context to free. This may be \c NULL, |
| 547 | * in which case this function does nothing. If it |
| 548 | * is not \c NULL, it must be initialized. |
Manuel Pégourié-Gonnard | 32aa437 | 2017-04-21 10:29:13 +0200 | [diff] [blame] | 549 | */ |
Jaeden Amero | dfc7f4a | 2019-07-10 11:33:37 +0100 | [diff] [blame^] | 550 | MBEDTLS_DEPRECATED |
Manuel Pégourié-Gonnard | 32aa437 | 2017-04-21 10:29:13 +0200 | [diff] [blame] | 551 | void mbedtls_ecdsa_restart_free( mbedtls_ecdsa_restart_ctx *ctx ); |
| 552 | #endif /* MBEDTLS_ECP_RESTARTABLE */ |
| 553 | |
Manuel Pégourié-Gonnard | 2aea141 | 2013-01-26 16:33:44 +0100 | [diff] [blame] | 554 | #ifdef __cplusplus |
| 555 | } |
| 556 | #endif |
| 557 | |
Paul Bakker | 9af723c | 2014-05-01 13:03:14 +0200 | [diff] [blame] | 558 | #endif /* ecdsa.h */ |