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