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