Manuel Pégourié-Gonnard | 2aea141 | 2013-01-26 16:33:44 +0100 | [diff] [blame] | 1 | /** |
| 2 | * \file ecdsa.h |
| 3 | * |
| 4 | * \brief Elliptic curve DSA |
| 5 | * |
Manuel Pégourié-Gonnard | 6fb8187 | 2015-07-27 11:11:48 +0200 | [diff] [blame] | 6 | * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved |
Manuel Pégourié-Gonnard | 37ff140 | 2015-09-04 14:21:07 +0200 | [diff] [blame] | 7 | * SPDX-License-Identifier: Apache-2.0 |
| 8 | * |
| 9 | * Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 10 | * not use this file except in compliance with the License. |
| 11 | * You may obtain a copy of the License at |
| 12 | * |
| 13 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 14 | * |
| 15 | * Unless required by applicable law or agreed to in writing, software |
| 16 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 17 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 18 | * See the License for the specific language governing permissions and |
| 19 | * limitations under the License. |
Manuel Pégourié-Gonnard | 2aea141 | 2013-01-26 16:33:44 +0100 | [diff] [blame] | 20 | * |
Manuel Pégourié-Gonnard | fe44643 | 2015-03-06 13:17:10 +0000 | [diff] [blame] | 21 | * 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] | 22 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 23 | #ifndef MBEDTLS_ECDSA_H |
| 24 | #define MBEDTLS_ECDSA_H |
Manuel Pégourié-Gonnard | 2aea141 | 2013-01-26 16:33:44 +0100 | [diff] [blame] | 25 | |
Manuel Pégourié-Gonnard | bdc9676 | 2013-10-03 11:50:39 +0200 | [diff] [blame] | 26 | #include "ecp.h" |
Manuel Pégourié-Gonnard | 887aa5b | 2014-04-04 13:57:20 +0200 | [diff] [blame] | 27 | #include "md.h" |
Manuel Pégourié-Gonnard | 4daaef7 | 2014-01-06 14:25:56 +0100 | [diff] [blame] | 28 | |
Manuel Pégourié-Gonnard | 63e9319 | 2015-03-31 11:15:48 +0200 | [diff] [blame] | 29 | /* |
| 30 | * RFC 4492 page 20: |
| 31 | * |
| 32 | * Ecdsa-Sig-Value ::= SEQUENCE { |
| 33 | * r INTEGER, |
| 34 | * s INTEGER |
| 35 | * } |
| 36 | * |
| 37 | * Size is at most |
| 38 | * 1 (tag) + 1 (len) + 1 (initial 0) + ECP_MAX_BYTES for each of r and s, |
| 39 | * twice that + 1 (tag) + 2 (len) for the sequence |
| 40 | * (assuming ECP_MAX_BYTES is less than 126 for r and s, |
| 41 | * and less than 124 (total len <= 255) for the sequence) |
| 42 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 43 | #if MBEDTLS_ECP_MAX_BYTES > 124 |
| 44 | #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] | 45 | #endif |
Manuel Pégourié-Gonnard | 5bf262d | 2015-03-31 11:46:01 +0200 | [diff] [blame] | 46 | /** Maximum size of an ECDSA signature in bytes */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 47 | #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] | 48 | |
Manuel Pégourié-Gonnard | bec2f45 | 2013-06-27 10:17:07 +0200 | [diff] [blame] | 49 | /** |
| 50 | * \brief ECDSA context structure |
| 51 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 52 | typedef mbedtls_ecp_keypair mbedtls_ecdsa_context; |
Manuel Pégourié-Gonnard | bec2f45 | 2013-06-27 10:17:07 +0200 | [diff] [blame] | 53 | |
Manuel Pégourié-Gonnard | 2aea141 | 2013-01-26 16:33:44 +0100 | [diff] [blame] | 54 | #ifdef __cplusplus |
| 55 | extern "C" { |
| 56 | #endif |
| 57 | |
| 58 | /** |
Manuel Pégourié-Gonnard | b309ab2 | 2013-01-26 17:24:59 +0100 | [diff] [blame] | 59 | * \brief Compute ECDSA signature of a previously hashed message |
| 60 | * |
Manuel Pégourié-Gonnard | b8cfe3f | 2015-03-31 11:04:45 +0200 | [diff] [blame] | 61 | * \note The deterministic version is usually prefered. |
| 62 | * |
Manuel Pégourié-Gonnard | b309ab2 | 2013-01-26 17:24:59 +0100 | [diff] [blame] | 63 | * \param grp ECP group |
| 64 | * \param r First output integer |
| 65 | * \param s Second output integer |
| 66 | * \param d Private signing key |
| 67 | * \param buf Message hash |
| 68 | * \param blen Length of buf |
| 69 | * \param f_rng RNG function |
| 70 | * \param p_rng RNG parameter |
| 71 | * |
Janos Follath | 0a5154b | 2017-03-10 11:31:41 +0000 | [diff] [blame] | 72 | * \note If the bitlength of the message hash is larger than the |
| 73 | * bitlength of the group order, then the hash is truncated as |
| 74 | * prescribed by SEC1 4.1.3 step 5. |
| 75 | * |
Manuel Pégourié-Gonnard | b309ab2 | 2013-01-26 17:24:59 +0100 | [diff] [blame] | 76 | * \return 0 if successful, |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 77 | * or a MBEDTLS_ERR_ECP_XXX or MBEDTLS_MPI_XXX error code |
Manuel Pégourié-Gonnard | b309ab2 | 2013-01-26 17:24:59 +0100 | [diff] [blame] | 78 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 79 | int mbedtls_ecdsa_sign( mbedtls_ecp_group *grp, mbedtls_mpi *r, mbedtls_mpi *s, |
| 80 | 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] | 81 | int (*f_rng)(void *, unsigned char *, size_t), void *p_rng ); |
| 82 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 83 | #if defined(MBEDTLS_ECDSA_DETERMINISTIC) |
Manuel Pégourié-Gonnard | 4daaef7 | 2014-01-06 14:25:56 +0100 | [diff] [blame] | 84 | /** |
Manuel Pégourié-Gonnard | b8cfe3f | 2015-03-31 11:04:45 +0200 | [diff] [blame] | 85 | * \brief Compute ECDSA signature of a previously hashed message, |
| 86 | * deterministic version (RFC 6979). |
Manuel Pégourié-Gonnard | 4daaef7 | 2014-01-06 14:25:56 +0100 | [diff] [blame] | 87 | * |
| 88 | * \param grp ECP group |
| 89 | * \param r First output integer |
| 90 | * \param s Second output integer |
| 91 | * \param d Private signing key |
| 92 | * \param buf Message hash |
| 93 | * \param blen Length of buf |
| 94 | * \param md_alg MD algorithm used to hash the message |
| 95 | * |
Janos Follath | 0a5154b | 2017-03-10 11:31:41 +0000 | [diff] [blame] | 96 | * \note If the bitlength of the message hash is larger than the |
| 97 | * bitlength of the group order, then the hash is truncated as |
| 98 | * prescribed by SEC1 4.1.3 step 5. |
| 99 | * |
Manuel Pégourié-Gonnard | 4daaef7 | 2014-01-06 14:25:56 +0100 | [diff] [blame] | 100 | * \return 0 if successful, |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 101 | * or a MBEDTLS_ERR_ECP_XXX or MBEDTLS_MPI_XXX error code |
Manuel Pégourié-Gonnard | 4daaef7 | 2014-01-06 14:25:56 +0100 | [diff] [blame] | 102 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 103 | int mbedtls_ecdsa_sign_det( mbedtls_ecp_group *grp, mbedtls_mpi *r, mbedtls_mpi *s, |
| 104 | const mbedtls_mpi *d, const unsigned char *buf, size_t blen, |
| 105 | mbedtls_md_type_t md_alg ); |
| 106 | #endif /* MBEDTLS_ECDSA_DETERMINISTIC */ |
Manuel Pégourié-Gonnard | 4daaef7 | 2014-01-06 14:25:56 +0100 | [diff] [blame] | 107 | |
Manuel Pégourié-Gonnard | b309ab2 | 2013-01-26 17:24:59 +0100 | [diff] [blame] | 108 | /** |
Manuel Pégourié-Gonnard | 3aeb5a7 | 2013-01-26 18:05:50 +0100 | [diff] [blame] | 109 | * \brief Verify ECDSA signature of a previously hashed message |
| 110 | * |
| 111 | * \param grp ECP group |
| 112 | * \param buf Message hash |
| 113 | * \param blen Length of buf |
| 114 | * \param Q Public key to use for verification |
| 115 | * \param r First integer of the signature |
| 116 | * \param s Second integer of the signature |
| 117 | * |
Janos Follath | 0a5154b | 2017-03-10 11:31:41 +0000 | [diff] [blame] | 118 | * \note If the bitlength of the message hash is larger than the |
| 119 | * bitlength of the group order, then the hash is truncated as |
| 120 | * prescribed by SEC1 4.1.4 step 3. |
| 121 | * |
Manuel Pégourié-Gonnard | 3aeb5a7 | 2013-01-26 18:05:50 +0100 | [diff] [blame] | 122 | * \return 0 if successful, |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 123 | * MBEDTLS_ERR_ECP_BAD_INPUT_DATA if signature is invalid |
| 124 | * or a MBEDTLS_ERR_ECP_XXX or MBEDTLS_MPI_XXX error code |
Manuel Pégourié-Gonnard | 3aeb5a7 | 2013-01-26 18:05:50 +0100 | [diff] [blame] | 125 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 126 | int mbedtls_ecdsa_verify( mbedtls_ecp_group *grp, |
Manuel Pégourié-Gonnard | 3aeb5a7 | 2013-01-26 18:05:50 +0100 | [diff] [blame] | 127 | const unsigned char *buf, size_t blen, |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 128 | const mbedtls_ecp_point *Q, const mbedtls_mpi *r, const mbedtls_mpi *s); |
Manuel Pégourié-Gonnard | 3aeb5a7 | 2013-01-26 18:05:50 +0100 | [diff] [blame] | 129 | |
| 130 | /** |
Manuel Pégourié-Gonnard | aa43161 | 2013-08-09 17:10:27 +0200 | [diff] [blame] | 131 | * \brief Compute ECDSA signature and write it to buffer, |
| 132 | * serialized as defined in RFC 4492 page 20. |
Paul Bakker | 6838bd1 | 2013-09-30 13:56:38 +0200 | [diff] [blame] | 133 | * (Not thread-safe to use same context in multiple threads) |
Manuel Pégourié-Gonnard | b694b48 | 2013-08-08 13:30:57 +0200 | [diff] [blame] | 134 | * |
Janos Follath | 0a5154b | 2017-03-10 11:31:41 +0000 | [diff] [blame] | 135 | * \note The deterministic version (RFC 6979) is used if |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 136 | * MBEDTLS_ECDSA_DETERMINISTIC is defined. |
Manuel Pégourié-Gonnard | dfdcac9 | 2015-03-31 11:41:42 +0200 | [diff] [blame] | 137 | * |
Manuel Pégourié-Gonnard | b694b48 | 2013-08-08 13:30:57 +0200 | [diff] [blame] | 138 | * \param ctx ECDSA context |
Manuel Pégourié-Gonnard | dfdcac9 | 2015-03-31 11:41:42 +0200 | [diff] [blame] | 139 | * \param md_alg Algorithm that was used to hash the message |
Manuel Pégourié-Gonnard | b694b48 | 2013-08-08 13:30:57 +0200 | [diff] [blame] | 140 | * \param hash Message hash |
| 141 | * \param hlen Length of hash |
| 142 | * \param sig Buffer that will hold the signature |
| 143 | * \param slen Length of the signature written |
| 144 | * \param f_rng RNG function |
| 145 | * \param p_rng RNG parameter |
| 146 | * |
| 147 | * \note The "sig" buffer must be at least as large as twice the |
Manuel Pégourié-Gonnard | 5bf262d | 2015-03-31 11:46:01 +0200 | [diff] [blame] | 148 | * size of the curve used, plus 9 (eg. 73 bytes if a 256-bit |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 149 | * curve is used). MBEDTLS_ECDSA_MAX_LEN is always safe. |
Manuel Pégourié-Gonnard | b694b48 | 2013-08-08 13:30:57 +0200 | [diff] [blame] | 150 | * |
Janos Follath | 0a5154b | 2017-03-10 11:31:41 +0000 | [diff] [blame] | 151 | * \note If the bitlength of the message hash is larger than the |
| 152 | * bitlength of the group order, then the hash is truncated as |
| 153 | * prescribed by SEC1 4.1.3 step 5. |
| 154 | * |
Manuel Pégourié-Gonnard | b694b48 | 2013-08-08 13:30:57 +0200 | [diff] [blame] | 155 | * \return 0 if successful, |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 156 | * or a MBEDTLS_ERR_ECP_XXX, MBEDTLS_ERR_MPI_XXX or |
| 157 | * MBEDTLS_ERR_ASN1_XXX error code |
Manuel Pégourié-Gonnard | b694b48 | 2013-08-08 13:30:57 +0200 | [diff] [blame] | 158 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 159 | int mbedtls_ecdsa_write_signature( mbedtls_ecdsa_context *ctx, mbedtls_md_type_t md_alg, |
Manuel Pégourié-Gonnard | b694b48 | 2013-08-08 13:30:57 +0200 | [diff] [blame] | 160 | const unsigned char *hash, size_t hlen, |
| 161 | unsigned char *sig, size_t *slen, |
| 162 | int (*f_rng)(void *, unsigned char *, size_t), |
| 163 | void *p_rng ); |
| 164 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 165 | #if defined(MBEDTLS_ECDSA_DETERMINISTIC) |
| 166 | #if ! defined(MBEDTLS_DEPRECATED_REMOVED) |
| 167 | #if defined(MBEDTLS_DEPRECATED_WARNING) |
| 168 | #define MBEDTLS_DEPRECATED __attribute__((deprecated)) |
Manuel Pégourié-Gonnard | dfdcac9 | 2015-03-31 11:41:42 +0200 | [diff] [blame] | 169 | #else |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 170 | #define MBEDTLS_DEPRECATED |
Manuel Pégourié-Gonnard | dfdcac9 | 2015-03-31 11:41:42 +0200 | [diff] [blame] | 171 | #endif |
Manuel Pégourié-Gonnard | 937340b | 2014-01-06 10:27:16 +0100 | [diff] [blame] | 172 | /** |
| 173 | * \brief Compute ECDSA signature and write it to buffer, |
| 174 | * serialized as defined in RFC 4492 page 20. |
| 175 | * Deterministic version, RFC 6979. |
| 176 | * (Not thread-safe to use same context in multiple threads) |
| 177 | * |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 178 | * \deprecated Superseded by mbedtls_ecdsa_write_signature() in 2.0.0 |
Manuel Pégourié-Gonnard | dfdcac9 | 2015-03-31 11:41:42 +0200 | [diff] [blame] | 179 | * |
Manuel Pégourié-Gonnard | 937340b | 2014-01-06 10:27:16 +0100 | [diff] [blame] | 180 | * \param ctx ECDSA context |
| 181 | * \param hash Message hash |
| 182 | * \param hlen Length of hash |
| 183 | * \param sig Buffer that will hold the signature |
| 184 | * \param slen Length of the signature written |
| 185 | * \param md_alg MD algorithm used to hash the message |
| 186 | * |
| 187 | * \note The "sig" buffer must be at least as large as twice the |
Manuel Pégourié-Gonnard | 5bf262d | 2015-03-31 11:46:01 +0200 | [diff] [blame] | 188 | * size of the curve used, plus 9 (eg. 73 bytes if a 256-bit |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 189 | * curve is used). MBEDTLS_ECDSA_MAX_LEN is always safe. |
Manuel Pégourié-Gonnard | 937340b | 2014-01-06 10:27:16 +0100 | [diff] [blame] | 190 | * |
Janos Follath | 0a5154b | 2017-03-10 11:31:41 +0000 | [diff] [blame] | 191 | * \note If the bitlength of the message hash is larger than the |
| 192 | * bitlength of the group order, then the hash is truncated as |
| 193 | * prescribed by SEC1 4.1.3 step 5. |
| 194 | * |
Manuel Pégourié-Gonnard | 937340b | 2014-01-06 10:27:16 +0100 | [diff] [blame] | 195 | * \return 0 if successful, |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 196 | * or a MBEDTLS_ERR_ECP_XXX, MBEDTLS_ERR_MPI_XXX or |
| 197 | * MBEDTLS_ERR_ASN1_XXX error code |
Manuel Pégourié-Gonnard | 937340b | 2014-01-06 10:27:16 +0100 | [diff] [blame] | 198 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 199 | int mbedtls_ecdsa_write_signature_det( mbedtls_ecdsa_context *ctx, |
Manuel Pégourié-Gonnard | 937340b | 2014-01-06 10:27:16 +0100 | [diff] [blame] | 200 | const unsigned char *hash, size_t hlen, |
| 201 | unsigned char *sig, size_t *slen, |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 202 | mbedtls_md_type_t md_alg ) MBEDTLS_DEPRECATED; |
| 203 | #undef MBEDTLS_DEPRECATED |
| 204 | #endif /* MBEDTLS_DEPRECATED_REMOVED */ |
| 205 | #endif /* MBEDTLS_ECDSA_DETERMINISTIC */ |
Manuel Pégourié-Gonnard | 937340b | 2014-01-06 10:27:16 +0100 | [diff] [blame] | 206 | |
Manuel Pégourié-Gonnard | b694b48 | 2013-08-08 13:30:57 +0200 | [diff] [blame] | 207 | /** |
| 208 | * \brief Read and verify an ECDSA signature |
| 209 | * |
| 210 | * \param ctx ECDSA context |
| 211 | * \param hash Message hash |
| 212 | * \param hlen Size of hash |
| 213 | * \param sig Signature to read and verify |
| 214 | * \param slen Size of sig |
| 215 | * |
Janos Follath | 0a5154b | 2017-03-10 11:31:41 +0000 | [diff] [blame] | 216 | * \note If the bitlength of the message hash is larger than the |
| 217 | * bitlength of the group order, then the hash is truncated as |
| 218 | * prescribed by SEC1 4.1.4 step 3. |
| 219 | * |
Manuel Pégourié-Gonnard | b694b48 | 2013-08-08 13:30:57 +0200 | [diff] [blame] | 220 | * \return 0 if successful, |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 221 | * MBEDTLS_ERR_ECP_BAD_INPUT_DATA if signature is invalid, |
| 222 | * MBEDTLS_ERR_ECP_SIG_LEN_MISMATCH if the signature is |
Manuel Pégourié-Gonnard | 35e95dd | 2014-04-08 12:17:41 +0200 | [diff] [blame] | 223 | * valid but its actual length is less than siglen, |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 224 | * or a MBEDTLS_ERR_ECP_XXX or MBEDTLS_ERR_MPI_XXX error code |
Manuel Pégourié-Gonnard | b694b48 | 2013-08-08 13:30:57 +0200 | [diff] [blame] | 225 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 226 | int mbedtls_ecdsa_read_signature( mbedtls_ecdsa_context *ctx, |
Manuel Pégourié-Gonnard | b694b48 | 2013-08-08 13:30:57 +0200 | [diff] [blame] | 227 | const unsigned char *hash, size_t hlen, |
| 228 | const unsigned char *sig, size_t slen ); |
| 229 | |
| 230 | /** |
Manuel Pégourié-Gonnard | 8eebd01 | 2013-08-09 16:21:34 +0200 | [diff] [blame] | 231 | * \brief Generate an ECDSA keypair on the given curve |
| 232 | * |
| 233 | * \param ctx ECDSA context in which the keypair should be stored |
Paul Bakker | dcbfdcc | 2013-09-10 16:16:50 +0200 | [diff] [blame] | 234 | * \param gid Group (elliptic curve) to use. One of the various |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 235 | * MBEDTLS_ECP_DP_XXX macros depending on configuration. |
Manuel Pégourié-Gonnard | 8eebd01 | 2013-08-09 16:21:34 +0200 | [diff] [blame] | 236 | * \param f_rng RNG function |
| 237 | * \param p_rng RNG parameter |
| 238 | * |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 239 | * \return 0 on success, or a MBEDTLS_ERR_ECP_XXX code. |
Manuel Pégourié-Gonnard | 8eebd01 | 2013-08-09 16:21:34 +0200 | [diff] [blame] | 240 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 241 | 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] | 242 | int (*f_rng)(void *, unsigned char *, size_t), void *p_rng ); |
| 243 | |
| 244 | /** |
Manuel Pégourié-Gonnard | f499993 | 2013-08-12 17:02:59 +0200 | [diff] [blame] | 245 | * \brief Set an ECDSA context from an EC key pair |
| 246 | * |
| 247 | * \param ctx ECDSA context to set |
| 248 | * \param key EC key to use |
| 249 | * |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 250 | * \return 0 on success, or a MBEDTLS_ERR_ECP_XXX code. |
Manuel Pégourié-Gonnard | f499993 | 2013-08-12 17:02:59 +0200 | [diff] [blame] | 251 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 252 | int mbedtls_ecdsa_from_keypair( mbedtls_ecdsa_context *ctx, const mbedtls_ecp_keypair *key ); |
Manuel Pégourié-Gonnard | f499993 | 2013-08-12 17:02:59 +0200 | [diff] [blame] | 253 | |
| 254 | /** |
Manuel Pégourié-Gonnard | 7c8934e | 2013-06-27 12:54:02 +0200 | [diff] [blame] | 255 | * \brief Initialize context |
| 256 | * |
| 257 | * \param ctx Context to initialize |
| 258 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 259 | void mbedtls_ecdsa_init( mbedtls_ecdsa_context *ctx ); |
Manuel Pégourié-Gonnard | 7c8934e | 2013-06-27 12:54:02 +0200 | [diff] [blame] | 260 | |
| 261 | /** |
| 262 | * \brief Free context |
| 263 | * |
| 264 | * \param ctx Context to free |
| 265 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 266 | void mbedtls_ecdsa_free( mbedtls_ecdsa_context *ctx ); |
Manuel Pégourié-Gonnard | 7c8934e | 2013-06-27 12:54:02 +0200 | [diff] [blame] | 267 | |
Manuel Pégourié-Gonnard | 2aea141 | 2013-01-26 16:33:44 +0100 | [diff] [blame] | 268 | #ifdef __cplusplus |
| 269 | } |
| 270 | #endif |
| 271 | |
Paul Bakker | 9af723c | 2014-05-01 13:03:14 +0200 | [diff] [blame] | 272 | #endif /* ecdsa.h */ |