Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 1 | /** |
| 2 | * \file dhm.h |
Paul Bakker | e0ccd0a | 2009-01-04 16:27:10 +0000 | [diff] [blame] | 3 | * |
Paul Bakker | 37ca75d | 2011-01-06 12:28:03 +0000 | [diff] [blame] | 4 | * \brief Diffie-Hellman-Merkle key exchange |
| 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. |
Paul Bakker | b96f154 | 2010-07-18 20:36:00 +0000 | [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) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 22 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 23 | #ifndef MBEDTLS_DHM_H |
| 24 | #define MBEDTLS_DHM_H |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 25 | |
Paul Bakker | 314052f | 2011-08-15 09:07:52 +0000 | [diff] [blame] | 26 | #include "bignum.h" |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 27 | |
Paul Bakker | f3b86c1 | 2011-01-27 15:24:17 +0000 | [diff] [blame] | 28 | /* |
| 29 | * DHM Error codes |
| 30 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 31 | #define MBEDTLS_ERR_DHM_BAD_INPUT_DATA -0x3080 /**< Bad input parameters to function. */ |
| 32 | #define MBEDTLS_ERR_DHM_READ_PARAMS_FAILED -0x3100 /**< Reading of the DHM parameters failed. */ |
| 33 | #define MBEDTLS_ERR_DHM_MAKE_PARAMS_FAILED -0x3180 /**< Making of the DHM parameters failed. */ |
| 34 | #define MBEDTLS_ERR_DHM_READ_PUBLIC_FAILED -0x3200 /**< Reading of the public values failed. */ |
| 35 | #define MBEDTLS_ERR_DHM_MAKE_PUBLIC_FAILED -0x3280 /**< Making of the public value failed. */ |
| 36 | #define MBEDTLS_ERR_DHM_CALC_SECRET_FAILED -0x3300 /**< Calculation of the DHM secret failed. */ |
| 37 | #define MBEDTLS_ERR_DHM_INVALID_FORMAT -0x3380 /**< The ASN.1 data is not formatted correctly. */ |
Manuel Pégourié-Gonnard | 6a8ca33 | 2015-05-28 09:33:39 +0200 | [diff] [blame] | 38 | #define MBEDTLS_ERR_DHM_ALLOC_FAILED -0x3400 /**< Allocation of memory failed. */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 39 | #define MBEDTLS_ERR_DHM_FILE_IO_ERROR -0x3480 /**< Read/write of file failed. */ |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 40 | |
Hanno Becker | 0e6dc84 | 2017-09-27 11:48:02 +0100 | [diff] [blame] | 41 | #if ! defined(MBEDTLS_DEPRECATED_REMOVED) |
| 42 | #if defined(MBEDTLS_DEPRECATED_WARNING) |
| 43 | #define MBEDTLS_DEPRECATED __attribute__((deprecated)) |
| 44 | #else |
| 45 | #define MBEDTLS_DEPRECATED |
| 46 | #endif |
| 47 | #endif |
| 48 | |
Paul Bakker | f3b86c1 | 2011-01-27 15:24:17 +0000 | [diff] [blame] | 49 | /** |
Hanno Becker | b2bad80 | 2017-09-27 11:49:31 +0100 | [diff] [blame^] | 50 | * RFC 3526, RFC 5114 and RFC 7919 standardize a number of |
| 51 | * Diffie-Hellman groups, some of which are included here |
| 52 | * for use within the SSL/TLS module and the user's convenience |
| 53 | * when configuring the Diffie-Hellman parameters by hand |
| 54 | * through \c mbedtls_ssl_conf_dh_param. |
Paul Bakker | 29b6476 | 2012-09-25 09:36:44 +0000 | [diff] [blame] | 55 | * |
| 56 | * Included are: |
Hanno Becker | b2bad80 | 2017-09-27 11:49:31 +0100 | [diff] [blame^] | 57 | * RFC 5114 2.2. 2048-bit MODP Group with 224-bit Prime Order Subgroup |
Paul Bakker | da7e3f2 | 2012-09-28 07:18:17 +0000 | [diff] [blame] | 58 | * RFC 3526 3. 2048-bit MODP Group |
| 59 | * RFC 3526 4. 3072-bit MODP Group |
Manuel Pégourié-Gonnard | 7893103 | 2015-07-03 17:06:39 +0200 | [diff] [blame] | 60 | * RFC 3526 5. 4096-bit MODP Group |
Hanno Becker | b2bad80 | 2017-09-27 11:49:31 +0100 | [diff] [blame^] | 61 | * RFC 7919 A.1 ffdhe2048 |
| 62 | * RFC 7919 A.2 ffdhe3072 |
| 63 | * RFC 7919 A.3 ffdhe4096 |
| 64 | * RFC 7919 A.4 ffdhe6144 |
| 65 | * RFC 7919 A.5 ffdhe8192 |
| 66 | * |
Hanno Becker | 0e6dc84 | 2017-09-27 11:48:02 +0100 | [diff] [blame] | 67 | * The constants with suffix "_p" denote the chosen prime moduli, while |
| 68 | * the constants with suffix "_g" denote the chosen generator |
| 69 | * of the associated prime field. |
| 70 | * |
| 71 | * All constants are represented as null-terminated strings containing the |
| 72 | * hexadecimal presentation of the respective numbers. |
| 73 | * |
| 74 | * \warning The origin of the primes in RFC 5114 is not documented and |
| 75 | * their use therefore constitutes a security risk! |
| 76 | * |
| 77 | * \deprecated The primes from RFC 5114 are superseded by the primes |
| 78 | * from RFC 3526 and RFC 7919 and should no longer be used. |
| 79 | * They will be removed in the next major revision. |
Paul Bakker | 29b6476 | 2012-09-25 09:36:44 +0000 | [diff] [blame] | 80 | */ |
Paul Bakker | da7e3f2 | 2012-09-28 07:18:17 +0000 | [diff] [blame] | 81 | |
Hanno Becker | 0e6dc84 | 2017-09-27 11:48:02 +0100 | [diff] [blame] | 82 | const char *mbedtls_dhm_rfc3526_modp_2048_p; |
| 83 | const char *mbedtls_dhm_rfc3526_modp_2048_g; |
| 84 | const char *mbedtls_dhm_rfc3526_modp_3072_p; |
| 85 | const char *mbedtls_dhm_rfc3526_modp_3072_g; |
| 86 | const char *mbedtls_dhm_rfc3526_modp_4096_p; |
| 87 | const char *mbedtls_dhm_rfc3526_modp_4096_g; |
Paul Bakker | da7e3f2 | 2012-09-28 07:18:17 +0000 | [diff] [blame] | 88 | |
Hanno Becker | b2bad80 | 2017-09-27 11:49:31 +0100 | [diff] [blame^] | 89 | const char *mbedtls_dhm_rfc7919_ffdhe2048_p; |
| 90 | const char *mbedtls_dhm_rfc7919_ffdhe2048_g; |
| 91 | const char *mbedtls_dhm_rfc7919_ffdhe3072_p; |
| 92 | const char *mbedtls_dhm_rfc7919_ffdhe3072_g; |
| 93 | const char *mbedtls_dhm_rfc7919_ffdhe4096_p; |
| 94 | const char *mbedtls_dhm_rfc7919_ffdhe4096_g; |
| 95 | const char *mbedtls_dhm_rfc7919_ffdhe6144_p; |
| 96 | const char *mbedtls_dhm_rfc7919_ffdhe6144_g; |
| 97 | const char *mbedtls_dhm_rfc7919_ffdhe8192_p; |
| 98 | const char *mbedtls_dhm_rfc7919_ffdhe8192_g; |
Paul Bakker | da7e3f2 | 2012-09-28 07:18:17 +0000 | [diff] [blame] | 99 | |
Hanno Becker | 0e6dc84 | 2017-09-27 11:48:02 +0100 | [diff] [blame] | 100 | #if !defined(MBEDTLS_DEPRECATED_REMOVED) |
| 101 | MBEDTLS_DEPRECATED const char *mbedtls_dhm_rfc5114_modp_2048_p; |
| 102 | MBEDTLS_DEPRECATED const char *mbedtls_dhm_rfc5114_modp_2048_g; |
| 103 | #endif |
Paul Bakker | da7e3f2 | 2012-09-28 07:18:17 +0000 | [diff] [blame] | 104 | |
Hanno Becker | 0e6dc84 | 2017-09-27 11:48:02 +0100 | [diff] [blame] | 105 | /** |
| 106 | * \deprecated These macros are superseded by direct access to the corresponding |
| 107 | * global variables and will be removed in the next major revision. |
| 108 | */ |
| 109 | #if !defined(MBEDTLS_DEPRECATED_REMOVED) |
| 110 | #define MBEDTLS_DHM_RFC5114_MODP_2048_P mbedtls_dhm_rfc5114_modp_2048_p |
| 111 | #define MBEDTLS_DHM_RFC5114_MODP_2048_G mbedtls_dhm_rfc5114_modp_2048_g |
| 112 | #define MBEDTLS_DHM_RFC3526_MODP_2048_P mbedtls_dhm_rfc3526_modp_2048_p |
| 113 | #define MBEDTLS_DHM_RFC3526_MODP_2048_G mbedtls_dhm_rfc3526_modp_2048_g |
| 114 | #define MBEDTLS_DHM_RFC3526_MODP_3072_P mbedtls_dhm_rfc3526_modp_3072_p |
| 115 | #define MBEDTLS_DHM_RFC3526_MODP_3072_G mbedtls_dhm_rfc3526_modp_3072_g |
| 116 | #define MBEDTLS_DHM_RFC3526_MODP_4096_P mbedtls_dhm_rfc3526_modp_4096_p |
| 117 | #define MBEDTLS_DHM_RFC3526_MODP_4096_G mbedtls_dhm_rfc3526_modp_4096_g |
| 118 | #endif |
Paul Bakker | 29b6476 | 2012-09-25 09:36:44 +0000 | [diff] [blame] | 119 | |
Paul Bakker | 407a0da | 2013-06-27 14:29:21 +0200 | [diff] [blame] | 120 | #ifdef __cplusplus |
| 121 | extern "C" { |
| 122 | #endif |
| 123 | |
Paul Bakker | 29b6476 | 2012-09-25 09:36:44 +0000 | [diff] [blame] | 124 | /** |
Paul Bakker | f3b86c1 | 2011-01-27 15:24:17 +0000 | [diff] [blame] | 125 | * \brief DHM context structure |
| 126 | */ |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 127 | typedef struct |
| 128 | { |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 129 | size_t len; /*!< size(P) in chars */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 130 | mbedtls_mpi P; /*!< prime modulus */ |
| 131 | mbedtls_mpi G; /*!< generator */ |
| 132 | mbedtls_mpi X; /*!< secret value */ |
| 133 | mbedtls_mpi GX; /*!< self = G^X mod P */ |
| 134 | mbedtls_mpi GY; /*!< peer = G^Y mod P */ |
| 135 | mbedtls_mpi K; /*!< key = GY^X mod P */ |
| 136 | mbedtls_mpi RP; /*!< cached R^2 mod P */ |
| 137 | mbedtls_mpi Vi; /*!< blinding value */ |
| 138 | mbedtls_mpi Vf; /*!< un-blinding value */ |
| 139 | mbedtls_mpi pX; /*!< previous X */ |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 140 | } |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 141 | mbedtls_dhm_context; |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 142 | |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 143 | /** |
Paul Bakker | 8f870b0 | 2014-06-20 13:32:38 +0200 | [diff] [blame] | 144 | * \brief Initialize DHM context |
| 145 | * |
| 146 | * \param ctx DHM context to be initialized |
| 147 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 148 | void mbedtls_dhm_init( mbedtls_dhm_context *ctx ); |
Paul Bakker | 8f870b0 | 2014-06-20 13:32:38 +0200 | [diff] [blame] | 149 | |
| 150 | /** |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 151 | * \brief Parse the ServerKeyExchange parameters |
| 152 | * |
| 153 | * \param ctx DHM context |
| 154 | * \param p &(start of input buffer) |
| 155 | * \param end end of buffer |
| 156 | * |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 157 | * \return 0 if successful, or an MBEDTLS_ERR_DHM_XXX error code |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 158 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 159 | int mbedtls_dhm_read_params( mbedtls_dhm_context *ctx, |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 160 | unsigned char **p, |
Paul Bakker | ff60ee6 | 2010-03-16 21:09:09 +0000 | [diff] [blame] | 161 | const unsigned char *end ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 162 | |
| 163 | /** |
| 164 | * \brief Setup and write the ServerKeyExchange parameters |
| 165 | * |
| 166 | * \param ctx DHM context |
Paul Bakker | ff7fe67 | 2010-07-18 09:45:05 +0000 | [diff] [blame] | 167 | * \param x_size private value size in bytes |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 168 | * \param output destination buffer |
| 169 | * \param olen number of chars written |
| 170 | * \param f_rng RNG function |
| 171 | * \param p_rng RNG parameter |
| 172 | * |
| 173 | * \note This function assumes that ctx->P and ctx->G |
| 174 | * have already been properly set (for example |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 175 | * using mbedtls_mpi_read_string or mbedtls_mpi_read_binary). |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 176 | * |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 177 | * \return 0 if successful, or an MBEDTLS_ERR_DHM_XXX error code |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 178 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 179 | int mbedtls_dhm_make_params( mbedtls_dhm_context *ctx, int x_size, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 180 | unsigned char *output, size_t *olen, |
Paul Bakker | a3d195c | 2011-11-27 21:07:34 +0000 | [diff] [blame] | 181 | int (*f_rng)(void *, unsigned char *, size_t), |
| 182 | void *p_rng ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 183 | |
| 184 | /** |
| 185 | * \brief Import the peer's public value G^Y |
| 186 | * |
| 187 | * \param ctx DHM context |
| 188 | * \param input input buffer |
| 189 | * \param ilen size of buffer |
| 190 | * |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 191 | * \return 0 if successful, or an MBEDTLS_ERR_DHM_XXX error code |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 192 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 193 | int mbedtls_dhm_read_public( mbedtls_dhm_context *ctx, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 194 | const unsigned char *input, size_t ilen ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 195 | |
| 196 | /** |
| 197 | * \brief Create own private value X and export G^X |
| 198 | * |
| 199 | * \param ctx DHM context |
Paul Bakker | 84bef1d | 2012-04-20 13:42:02 +0000 | [diff] [blame] | 200 | * \param x_size private value size in bytes |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 201 | * \param output destination buffer |
Simon Butcher | 2917b9e | 2016-05-25 00:59:37 +0100 | [diff] [blame] | 202 | * \param olen must be at least equal to the size of P, ctx->len |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 203 | * \param f_rng RNG function |
| 204 | * \param p_rng RNG parameter |
| 205 | * |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 206 | * \return 0 if successful, or an MBEDTLS_ERR_DHM_XXX error code |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 207 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 208 | int mbedtls_dhm_make_public( mbedtls_dhm_context *ctx, int x_size, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 209 | unsigned char *output, size_t olen, |
Paul Bakker | a3d195c | 2011-11-27 21:07:34 +0000 | [diff] [blame] | 210 | int (*f_rng)(void *, unsigned char *, size_t), |
| 211 | void *p_rng ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 212 | |
| 213 | /** |
| 214 | * \brief Derive and export the shared secret (G^Y)^X mod P |
| 215 | * |
| 216 | * \param ctx DHM context |
| 217 | * \param output destination buffer |
Manuel Pégourié-Gonnard | 3335205 | 2015-06-02 16:17:08 +0100 | [diff] [blame] | 218 | * \param output_size size of the destination buffer |
| 219 | * \param olen on exit, holds the actual number of bytes written |
Manuel Pégourié-Gonnard | 2d62764 | 2013-09-04 14:22:07 +0200 | [diff] [blame] | 220 | * \param f_rng RNG function, for blinding purposes |
| 221 | * \param p_rng RNG parameter |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 222 | * |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 223 | * \return 0 if successful, or an MBEDTLS_ERR_DHM_XXX error code |
Manuel Pégourié-Gonnard | 143b502 | 2013-09-04 16:29:59 +0200 | [diff] [blame] | 224 | * |
Manuel Pégourié-Gonnard | 15d5de1 | 2013-09-17 11:34:11 +0200 | [diff] [blame] | 225 | * \note If non-NULL, f_rng is used to blind the input as |
| 226 | * countermeasure against timing attacks. Blinding is |
| 227 | * automatically used if and only if our secret value X is |
| 228 | * re-used and costs nothing otherwise, so it is recommended |
| 229 | * to always pass a non-NULL f_rng argument. |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 230 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 231 | int mbedtls_dhm_calc_secret( mbedtls_dhm_context *ctx, |
Manuel Pégourié-Gonnard | 3335205 | 2015-06-02 16:17:08 +0100 | [diff] [blame] | 232 | unsigned char *output, size_t output_size, size_t *olen, |
Manuel Pégourié-Gonnard | 2d62764 | 2013-09-04 14:22:07 +0200 | [diff] [blame] | 233 | int (*f_rng)(void *, unsigned char *, size_t), |
| 234 | void *p_rng ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 235 | |
Paul Bakker | 9a73632 | 2012-11-14 12:39:52 +0000 | [diff] [blame] | 236 | /** |
Paul Bakker | 8f870b0 | 2014-06-20 13:32:38 +0200 | [diff] [blame] | 237 | * \brief Free and clear the components of a DHM key |
| 238 | * |
| 239 | * \param ctx DHM context to free and clear |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 240 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 241 | void mbedtls_dhm_free( mbedtls_dhm_context *ctx ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 242 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 243 | #if defined(MBEDTLS_ASN1_PARSE_C) |
Paul Bakker | 40ce79f | 2013-09-15 17:43:54 +0200 | [diff] [blame] | 244 | /** \ingroup x509_module */ |
| 245 | /** |
Manuel Pégourié-Gonnard | 43b37cb | 2015-05-12 11:20:10 +0200 | [diff] [blame] | 246 | * \brief Parse DHM parameters in PEM or DER format |
Paul Bakker | 40ce79f | 2013-09-15 17:43:54 +0200 | [diff] [blame] | 247 | * |
| 248 | * \param dhm DHM context to be initialized |
| 249 | * \param dhmin input buffer |
| 250 | * \param dhminlen size of the buffer |
Manuel Pégourié-Gonnard | 43b37cb | 2015-05-12 11:20:10 +0200 | [diff] [blame] | 251 | * (including the terminating null byte for PEM data) |
Paul Bakker | 40ce79f | 2013-09-15 17:43:54 +0200 | [diff] [blame] | 252 | * |
| 253 | * \return 0 if successful, or a specific DHM or PEM error code |
| 254 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 255 | int mbedtls_dhm_parse_dhm( mbedtls_dhm_context *dhm, const unsigned char *dhmin, |
Paul Bakker | 40ce79f | 2013-09-15 17:43:54 +0200 | [diff] [blame] | 256 | size_t dhminlen ); |
| 257 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 258 | #if defined(MBEDTLS_FS_IO) |
Paul Bakker | 40ce79f | 2013-09-15 17:43:54 +0200 | [diff] [blame] | 259 | /** \ingroup x509_module */ |
| 260 | /** |
| 261 | * \brief Load and parse DHM parameters |
| 262 | * |
| 263 | * \param dhm DHM context to be initialized |
| 264 | * \param path filename to read the DHM Parameters from |
| 265 | * |
| 266 | * \return 0 if successful, or a specific DHM or PEM error code |
| 267 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 268 | int mbedtls_dhm_parse_dhmfile( mbedtls_dhm_context *dhm, const char *path ); |
| 269 | #endif /* MBEDTLS_FS_IO */ |
| 270 | #endif /* MBEDTLS_ASN1_PARSE_C */ |
Paul Bakker | 40ce79f | 2013-09-15 17:43:54 +0200 | [diff] [blame] | 271 | |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 272 | /** |
| 273 | * \brief Checkup routine |
| 274 | * |
| 275 | * \return 0 if successful, or 1 if the test failed |
| 276 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 277 | int mbedtls_dhm_self_test( int verbose ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 278 | |
| 279 | #ifdef __cplusplus |
| 280 | } |
| 281 | #endif |
| 282 | |
Paul Bakker | 9af723c | 2014-05-01 13:03:14 +0200 | [diff] [blame] | 283 | #endif /* dhm.h */ |