Modified mbed TLS headers for AES functionality only to reduce build size
Dependents: BLE_Gateway_Linker_fix BLE_Gateway
Fork of mbedtls by
mbedtls/dhm.h@5:f09f5ed830ca, 2017-07-10 (annotated)
- Committer:
- electronichamsters
- Date:
- Mon Jul 10 04:00:25 2017 +0000
- Revision:
- 5:f09f5ed830ca
- Parent:
- 1:24750b9ad5ef
working gateway
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Christopher Haster |
1:24750b9ad5ef | 1 | /** |
Christopher Haster |
1:24750b9ad5ef | 2 | * \file dhm.h |
Christopher Haster |
1:24750b9ad5ef | 3 | * |
Christopher Haster |
1:24750b9ad5ef | 4 | * \brief Diffie-Hellman-Merkle key exchange |
Christopher Haster |
1:24750b9ad5ef | 5 | * |
Christopher Haster |
1:24750b9ad5ef | 6 | * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved |
Christopher Haster |
1:24750b9ad5ef | 7 | * SPDX-License-Identifier: Apache-2.0 |
Christopher Haster |
1:24750b9ad5ef | 8 | * |
Christopher Haster |
1:24750b9ad5ef | 9 | * Licensed under the Apache License, Version 2.0 (the "License"); you may |
Christopher Haster |
1:24750b9ad5ef | 10 | * not use this file except in compliance with the License. |
Christopher Haster |
1:24750b9ad5ef | 11 | * You may obtain a copy of the License at |
Christopher Haster |
1:24750b9ad5ef | 12 | * |
Christopher Haster |
1:24750b9ad5ef | 13 | * http://www.apache.org/licenses/LICENSE-2.0 |
Christopher Haster |
1:24750b9ad5ef | 14 | * |
Christopher Haster |
1:24750b9ad5ef | 15 | * Unless required by applicable law or agreed to in writing, software |
Christopher Haster |
1:24750b9ad5ef | 16 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
Christopher Haster |
1:24750b9ad5ef | 17 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
Christopher Haster |
1:24750b9ad5ef | 18 | * See the License for the specific language governing permissions and |
Christopher Haster |
1:24750b9ad5ef | 19 | * limitations under the License. |
Christopher Haster |
1:24750b9ad5ef | 20 | * |
Christopher Haster |
1:24750b9ad5ef | 21 | * This file is part of mbed TLS (https://tls.mbed.org) |
Christopher Haster |
1:24750b9ad5ef | 22 | */ |
Christopher Haster |
1:24750b9ad5ef | 23 | #ifndef MBEDTLS_DHM_H |
Christopher Haster |
1:24750b9ad5ef | 24 | #define MBEDTLS_DHM_H |
Christopher Haster |
1:24750b9ad5ef | 25 | |
Christopher Haster |
1:24750b9ad5ef | 26 | #include "bignum.h" |
Christopher Haster |
1:24750b9ad5ef | 27 | |
Christopher Haster |
1:24750b9ad5ef | 28 | /* |
Christopher Haster |
1:24750b9ad5ef | 29 | * DHM Error codes |
Christopher Haster |
1:24750b9ad5ef | 30 | */ |
Christopher Haster |
1:24750b9ad5ef | 31 | #define MBEDTLS_ERR_DHM_BAD_INPUT_DATA -0x3080 /**< Bad input parameters to function. */ |
Christopher Haster |
1:24750b9ad5ef | 32 | #define MBEDTLS_ERR_DHM_READ_PARAMS_FAILED -0x3100 /**< Reading of the DHM parameters failed. */ |
Christopher Haster |
1:24750b9ad5ef | 33 | #define MBEDTLS_ERR_DHM_MAKE_PARAMS_FAILED -0x3180 /**< Making of the DHM parameters failed. */ |
Christopher Haster |
1:24750b9ad5ef | 34 | #define MBEDTLS_ERR_DHM_READ_PUBLIC_FAILED -0x3200 /**< Reading of the public values failed. */ |
Christopher Haster |
1:24750b9ad5ef | 35 | #define MBEDTLS_ERR_DHM_MAKE_PUBLIC_FAILED -0x3280 /**< Making of the public value failed. */ |
Christopher Haster |
1:24750b9ad5ef | 36 | #define MBEDTLS_ERR_DHM_CALC_SECRET_FAILED -0x3300 /**< Calculation of the DHM secret failed. */ |
Christopher Haster |
1:24750b9ad5ef | 37 | #define MBEDTLS_ERR_DHM_INVALID_FORMAT -0x3380 /**< The ASN.1 data is not formatted correctly. */ |
Christopher Haster |
1:24750b9ad5ef | 38 | #define MBEDTLS_ERR_DHM_ALLOC_FAILED -0x3400 /**< Allocation of memory failed. */ |
Christopher Haster |
1:24750b9ad5ef | 39 | #define MBEDTLS_ERR_DHM_FILE_IO_ERROR -0x3480 /**< Read/write of file failed. */ |
Christopher Haster |
1:24750b9ad5ef | 40 | |
Christopher Haster |
1:24750b9ad5ef | 41 | /** |
Christopher Haster |
1:24750b9ad5ef | 42 | * RFC 3526 defines a number of standardized Diffie-Hellman groups |
Christopher Haster |
1:24750b9ad5ef | 43 | * for IKE. |
Christopher Haster |
1:24750b9ad5ef | 44 | * RFC 5114 defines a number of standardized Diffie-Hellman groups |
Christopher Haster |
1:24750b9ad5ef | 45 | * that can be used. |
Christopher Haster |
1:24750b9ad5ef | 46 | * |
Christopher Haster |
1:24750b9ad5ef | 47 | * Some are included here for convenience. |
Christopher Haster |
1:24750b9ad5ef | 48 | * |
Christopher Haster |
1:24750b9ad5ef | 49 | * Included are: |
Christopher Haster |
1:24750b9ad5ef | 50 | * RFC 3526 3. 2048-bit MODP Group |
Christopher Haster |
1:24750b9ad5ef | 51 | * RFC 3526 4. 3072-bit MODP Group |
Christopher Haster |
1:24750b9ad5ef | 52 | * RFC 3526 5. 4096-bit MODP Group |
Christopher Haster |
1:24750b9ad5ef | 53 | * RFC 5114 2.2. 2048-bit MODP Group with 224-bit Prime Order Subgroup |
Christopher Haster |
1:24750b9ad5ef | 54 | */ |
Christopher Haster |
1:24750b9ad5ef | 55 | #define MBEDTLS_DHM_RFC3526_MODP_2048_P \ |
Christopher Haster |
1:24750b9ad5ef | 56 | "FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD1" \ |
Christopher Haster |
1:24750b9ad5ef | 57 | "29024E088A67CC74020BBEA63B139B22514A08798E3404DD" \ |
Christopher Haster |
1:24750b9ad5ef | 58 | "EF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245" \ |
Christopher Haster |
1:24750b9ad5ef | 59 | "E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED" \ |
Christopher Haster |
1:24750b9ad5ef | 60 | "EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3D" \ |
Christopher Haster |
1:24750b9ad5ef | 61 | "C2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F" \ |
Christopher Haster |
1:24750b9ad5ef | 62 | "83655D23DCA3AD961C62F356208552BB9ED529077096966D" \ |
Christopher Haster |
1:24750b9ad5ef | 63 | "670C354E4ABC9804F1746C08CA18217C32905E462E36CE3B" \ |
Christopher Haster |
1:24750b9ad5ef | 64 | "E39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9" \ |
Christopher Haster |
1:24750b9ad5ef | 65 | "DE2BCBF6955817183995497CEA956AE515D2261898FA0510" \ |
Christopher Haster |
1:24750b9ad5ef | 66 | "15728E5A8AACAA68FFFFFFFFFFFFFFFF" |
Christopher Haster |
1:24750b9ad5ef | 67 | |
Christopher Haster |
1:24750b9ad5ef | 68 | #define MBEDTLS_DHM_RFC3526_MODP_2048_G "02" |
Christopher Haster |
1:24750b9ad5ef | 69 | |
Christopher Haster |
1:24750b9ad5ef | 70 | #define MBEDTLS_DHM_RFC3526_MODP_3072_P \ |
Christopher Haster |
1:24750b9ad5ef | 71 | "FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD1" \ |
Christopher Haster |
1:24750b9ad5ef | 72 | "29024E088A67CC74020BBEA63B139B22514A08798E3404DD" \ |
Christopher Haster |
1:24750b9ad5ef | 73 | "EF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245" \ |
Christopher Haster |
1:24750b9ad5ef | 74 | "E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED" \ |
Christopher Haster |
1:24750b9ad5ef | 75 | "EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3D" \ |
Christopher Haster |
1:24750b9ad5ef | 76 | "C2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F" \ |
Christopher Haster |
1:24750b9ad5ef | 77 | "83655D23DCA3AD961C62F356208552BB9ED529077096966D" \ |
Christopher Haster |
1:24750b9ad5ef | 78 | "670C354E4ABC9804F1746C08CA18217C32905E462E36CE3B" \ |
Christopher Haster |
1:24750b9ad5ef | 79 | "E39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9" \ |
Christopher Haster |
1:24750b9ad5ef | 80 | "DE2BCBF6955817183995497CEA956AE515D2261898FA0510" \ |
Christopher Haster |
1:24750b9ad5ef | 81 | "15728E5A8AAAC42DAD33170D04507A33A85521ABDF1CBA64" \ |
Christopher Haster |
1:24750b9ad5ef | 82 | "ECFB850458DBEF0A8AEA71575D060C7DB3970F85A6E1E4C7" \ |
Christopher Haster |
1:24750b9ad5ef | 83 | "ABF5AE8CDB0933D71E8C94E04A25619DCEE3D2261AD2EE6B" \ |
Christopher Haster |
1:24750b9ad5ef | 84 | "F12FFA06D98A0864D87602733EC86A64521F2B18177B200C" \ |
Christopher Haster |
1:24750b9ad5ef | 85 | "BBE117577A615D6C770988C0BAD946E208E24FA074E5AB31" \ |
Christopher Haster |
1:24750b9ad5ef | 86 | "43DB5BFCE0FD108E4B82D120A93AD2CAFFFFFFFFFFFFFFFF" |
Christopher Haster |
1:24750b9ad5ef | 87 | |
Christopher Haster |
1:24750b9ad5ef | 88 | #define MBEDTLS_DHM_RFC3526_MODP_3072_G "02" |
Christopher Haster |
1:24750b9ad5ef | 89 | |
Christopher Haster |
1:24750b9ad5ef | 90 | #define MBEDTLS_DHM_RFC3526_MODP_4096_P \ |
Christopher Haster |
1:24750b9ad5ef | 91 | "FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD1" \ |
Christopher Haster |
1:24750b9ad5ef | 92 | "29024E088A67CC74020BBEA63B139B22514A08798E3404DD" \ |
Christopher Haster |
1:24750b9ad5ef | 93 | "EF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245" \ |
Christopher Haster |
1:24750b9ad5ef | 94 | "E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED" \ |
Christopher Haster |
1:24750b9ad5ef | 95 | "EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3D" \ |
Christopher Haster |
1:24750b9ad5ef | 96 | "C2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F" \ |
Christopher Haster |
1:24750b9ad5ef | 97 | "83655D23DCA3AD961C62F356208552BB9ED529077096966D" \ |
Christopher Haster |
1:24750b9ad5ef | 98 | "670C354E4ABC9804F1746C08CA18217C32905E462E36CE3B" \ |
Christopher Haster |
1:24750b9ad5ef | 99 | "E39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9" \ |
Christopher Haster |
1:24750b9ad5ef | 100 | "DE2BCBF6955817183995497CEA956AE515D2261898FA0510" \ |
Christopher Haster |
1:24750b9ad5ef | 101 | "15728E5A8AAAC42DAD33170D04507A33A85521ABDF1CBA64" \ |
Christopher Haster |
1:24750b9ad5ef | 102 | "ECFB850458DBEF0A8AEA71575D060C7DB3970F85A6E1E4C7" \ |
Christopher Haster |
1:24750b9ad5ef | 103 | "ABF5AE8CDB0933D71E8C94E04A25619DCEE3D2261AD2EE6B" \ |
Christopher Haster |
1:24750b9ad5ef | 104 | "F12FFA06D98A0864D87602733EC86A64521F2B18177B200C" \ |
Christopher Haster |
1:24750b9ad5ef | 105 | "BBE117577A615D6C770988C0BAD946E208E24FA074E5AB31" \ |
Christopher Haster |
1:24750b9ad5ef | 106 | "43DB5BFCE0FD108E4B82D120A92108011A723C12A787E6D7" \ |
Christopher Haster |
1:24750b9ad5ef | 107 | "88719A10BDBA5B2699C327186AF4E23C1A946834B6150BDA" \ |
Christopher Haster |
1:24750b9ad5ef | 108 | "2583E9CA2AD44CE8DBBBC2DB04DE8EF92E8EFC141FBECAA6" \ |
Christopher Haster |
1:24750b9ad5ef | 109 | "287C59474E6BC05D99B2964FA090C3A2233BA186515BE7ED" \ |
Christopher Haster |
1:24750b9ad5ef | 110 | "1F612970CEE2D7AFB81BDD762170481CD0069127D5B05AA9" \ |
Christopher Haster |
1:24750b9ad5ef | 111 | "93B4EA988D8FDDC186FFB7DC90A6C08F4DF435C934063199" \ |
Christopher Haster |
1:24750b9ad5ef | 112 | "FFFFFFFFFFFFFFFF" |
Christopher Haster |
1:24750b9ad5ef | 113 | |
Christopher Haster |
1:24750b9ad5ef | 114 | #define MBEDTLS_DHM_RFC3526_MODP_4096_G "02" |
Christopher Haster |
1:24750b9ad5ef | 115 | |
Christopher Haster |
1:24750b9ad5ef | 116 | #define MBEDTLS_DHM_RFC5114_MODP_2048_P \ |
Christopher Haster |
1:24750b9ad5ef | 117 | "AD107E1E9123A9D0D660FAA79559C51FA20D64E5683B9FD1" \ |
Christopher Haster |
1:24750b9ad5ef | 118 | "B54B1597B61D0A75E6FA141DF95A56DBAF9A3C407BA1DF15" \ |
Christopher Haster |
1:24750b9ad5ef | 119 | "EB3D688A309C180E1DE6B85A1274A0A66D3F8152AD6AC212" \ |
Christopher Haster |
1:24750b9ad5ef | 120 | "9037C9EDEFDA4DF8D91E8FEF55B7394B7AD5B7D0B6C12207" \ |
Christopher Haster |
1:24750b9ad5ef | 121 | "C9F98D11ED34DBF6C6BA0B2C8BBC27BE6A00E0A0B9C49708" \ |
Christopher Haster |
1:24750b9ad5ef | 122 | "B3BF8A317091883681286130BC8985DB1602E714415D9330" \ |
Christopher Haster |
1:24750b9ad5ef | 123 | "278273C7DE31EFDC7310F7121FD5A07415987D9ADC0A486D" \ |
Christopher Haster |
1:24750b9ad5ef | 124 | "CDF93ACC44328387315D75E198C641A480CD86A1B9E587E8" \ |
Christopher Haster |
1:24750b9ad5ef | 125 | "BE60E69CC928B2B9C52172E413042E9B23F10B0E16E79763" \ |
Christopher Haster |
1:24750b9ad5ef | 126 | "C9B53DCF4BA80A29E3FB73C16B8E75B97EF363E2FFA31F71" \ |
Christopher Haster |
1:24750b9ad5ef | 127 | "CF9DE5384E71B81C0AC4DFFE0C10E64F" |
Christopher Haster |
1:24750b9ad5ef | 128 | |
Christopher Haster |
1:24750b9ad5ef | 129 | #define MBEDTLS_DHM_RFC5114_MODP_2048_G \ |
Christopher Haster |
1:24750b9ad5ef | 130 | "AC4032EF4F2D9AE39DF30B5C8FFDAC506CDEBE7B89998CAF"\ |
Christopher Haster |
1:24750b9ad5ef | 131 | "74866A08CFE4FFE3A6824A4E10B9A6F0DD921F01A70C4AFA"\ |
Christopher Haster |
1:24750b9ad5ef | 132 | "AB739D7700C29F52C57DB17C620A8652BE5E9001A8D66AD7"\ |
Christopher Haster |
1:24750b9ad5ef | 133 | "C17669101999024AF4D027275AC1348BB8A762D0521BC98A"\ |
Christopher Haster |
1:24750b9ad5ef | 134 | "E247150422EA1ED409939D54DA7460CDB5F6C6B250717CBE"\ |
Christopher Haster |
1:24750b9ad5ef | 135 | "F180EB34118E98D119529A45D6F834566E3025E316A330EF"\ |
Christopher Haster |
1:24750b9ad5ef | 136 | "BB77A86F0C1AB15B051AE3D428C8F8ACB70A8137150B8EEB"\ |
Christopher Haster |
1:24750b9ad5ef | 137 | "10E183EDD19963DDD9E263E4770589EF6AA21E7F5F2FF381"\ |
Christopher Haster |
1:24750b9ad5ef | 138 | "B539CCE3409D13CD566AFBB48D6C019181E1BCFE94B30269"\ |
Christopher Haster |
1:24750b9ad5ef | 139 | "EDFE72FE9B6AA4BD7B5A0F1C71CFFF4C19C418E1F6EC0179"\ |
Christopher Haster |
1:24750b9ad5ef | 140 | "81BC087F2A7065B384B890D3191F2BFA" |
Christopher Haster |
1:24750b9ad5ef | 141 | |
Christopher Haster |
1:24750b9ad5ef | 142 | #ifdef __cplusplus |
Christopher Haster |
1:24750b9ad5ef | 143 | extern "C" { |
Christopher Haster |
1:24750b9ad5ef | 144 | #endif |
Christopher Haster |
1:24750b9ad5ef | 145 | |
Christopher Haster |
1:24750b9ad5ef | 146 | /** |
Christopher Haster |
1:24750b9ad5ef | 147 | * \brief DHM context structure |
Christopher Haster |
1:24750b9ad5ef | 148 | */ |
Christopher Haster |
1:24750b9ad5ef | 149 | typedef struct |
Christopher Haster |
1:24750b9ad5ef | 150 | { |
Christopher Haster |
1:24750b9ad5ef | 151 | size_t len; /*!< size(P) in chars */ |
Christopher Haster |
1:24750b9ad5ef | 152 | mbedtls_mpi P; /*!< prime modulus */ |
Christopher Haster |
1:24750b9ad5ef | 153 | mbedtls_mpi G; /*!< generator */ |
Christopher Haster |
1:24750b9ad5ef | 154 | mbedtls_mpi X; /*!< secret value */ |
Christopher Haster |
1:24750b9ad5ef | 155 | mbedtls_mpi GX; /*!< self = G^X mod P */ |
Christopher Haster |
1:24750b9ad5ef | 156 | mbedtls_mpi GY; /*!< peer = G^Y mod P */ |
Christopher Haster |
1:24750b9ad5ef | 157 | mbedtls_mpi K; /*!< key = GY^X mod P */ |
Christopher Haster |
1:24750b9ad5ef | 158 | mbedtls_mpi RP; /*!< cached R^2 mod P */ |
Christopher Haster |
1:24750b9ad5ef | 159 | mbedtls_mpi Vi; /*!< blinding value */ |
Christopher Haster |
1:24750b9ad5ef | 160 | mbedtls_mpi Vf; /*!< un-blinding value */ |
Christopher Haster |
1:24750b9ad5ef | 161 | mbedtls_mpi pX; /*!< previous X */ |
Christopher Haster |
1:24750b9ad5ef | 162 | } |
Christopher Haster |
1:24750b9ad5ef | 163 | mbedtls_dhm_context; |
Christopher Haster |
1:24750b9ad5ef | 164 | |
Christopher Haster |
1:24750b9ad5ef | 165 | /** |
Christopher Haster |
1:24750b9ad5ef | 166 | * \brief Initialize DHM context |
Christopher Haster |
1:24750b9ad5ef | 167 | * |
Christopher Haster |
1:24750b9ad5ef | 168 | * \param ctx DHM context to be initialized |
Christopher Haster |
1:24750b9ad5ef | 169 | */ |
Christopher Haster |
1:24750b9ad5ef | 170 | void mbedtls_dhm_init( mbedtls_dhm_context *ctx ); |
Christopher Haster |
1:24750b9ad5ef | 171 | |
Christopher Haster |
1:24750b9ad5ef | 172 | /** |
Christopher Haster |
1:24750b9ad5ef | 173 | * \brief Parse the ServerKeyExchange parameters |
Christopher Haster |
1:24750b9ad5ef | 174 | * |
Christopher Haster |
1:24750b9ad5ef | 175 | * \param ctx DHM context |
Christopher Haster |
1:24750b9ad5ef | 176 | * \param p &(start of input buffer) |
Christopher Haster |
1:24750b9ad5ef | 177 | * \param end end of buffer |
Christopher Haster |
1:24750b9ad5ef | 178 | * |
Christopher Haster |
1:24750b9ad5ef | 179 | * \return 0 if successful, or an MBEDTLS_ERR_DHM_XXX error code |
Christopher Haster |
1:24750b9ad5ef | 180 | */ |
Christopher Haster |
1:24750b9ad5ef | 181 | int mbedtls_dhm_read_params( mbedtls_dhm_context *ctx, |
Christopher Haster |
1:24750b9ad5ef | 182 | unsigned char **p, |
Christopher Haster |
1:24750b9ad5ef | 183 | const unsigned char *end ); |
Christopher Haster |
1:24750b9ad5ef | 184 | |
Christopher Haster |
1:24750b9ad5ef | 185 | /** |
Christopher Haster |
1:24750b9ad5ef | 186 | * \brief Setup and write the ServerKeyExchange parameters |
Christopher Haster |
1:24750b9ad5ef | 187 | * |
Christopher Haster |
1:24750b9ad5ef | 188 | * \param ctx DHM context |
Christopher Haster |
1:24750b9ad5ef | 189 | * \param x_size private value size in bytes |
Christopher Haster |
1:24750b9ad5ef | 190 | * \param output destination buffer |
Christopher Haster |
1:24750b9ad5ef | 191 | * \param olen number of chars written |
Christopher Haster |
1:24750b9ad5ef | 192 | * \param f_rng RNG function |
Christopher Haster |
1:24750b9ad5ef | 193 | * \param p_rng RNG parameter |
Christopher Haster |
1:24750b9ad5ef | 194 | * |
Christopher Haster |
1:24750b9ad5ef | 195 | * \note This function assumes that ctx->P and ctx->G |
Christopher Haster |
1:24750b9ad5ef | 196 | * have already been properly set (for example |
Christopher Haster |
1:24750b9ad5ef | 197 | * using mbedtls_mpi_read_string or mbedtls_mpi_read_binary). |
Christopher Haster |
1:24750b9ad5ef | 198 | * |
Christopher Haster |
1:24750b9ad5ef | 199 | * \return 0 if successful, or an MBEDTLS_ERR_DHM_XXX error code |
Christopher Haster |
1:24750b9ad5ef | 200 | */ |
Christopher Haster |
1:24750b9ad5ef | 201 | int mbedtls_dhm_make_params( mbedtls_dhm_context *ctx, int x_size, |
Christopher Haster |
1:24750b9ad5ef | 202 | unsigned char *output, size_t *olen, |
Christopher Haster |
1:24750b9ad5ef | 203 | int (*f_rng)(void *, unsigned char *, size_t), |
Christopher Haster |
1:24750b9ad5ef | 204 | void *p_rng ); |
Christopher Haster |
1:24750b9ad5ef | 205 | |
Christopher Haster |
1:24750b9ad5ef | 206 | /** |
Christopher Haster |
1:24750b9ad5ef | 207 | * \brief Import the peer's public value G^Y |
Christopher Haster |
1:24750b9ad5ef | 208 | * |
Christopher Haster |
1:24750b9ad5ef | 209 | * \param ctx DHM context |
Christopher Haster |
1:24750b9ad5ef | 210 | * \param input input buffer |
Christopher Haster |
1:24750b9ad5ef | 211 | * \param ilen size of buffer |
Christopher Haster |
1:24750b9ad5ef | 212 | * |
Christopher Haster |
1:24750b9ad5ef | 213 | * \return 0 if successful, or an MBEDTLS_ERR_DHM_XXX error code |
Christopher Haster |
1:24750b9ad5ef | 214 | */ |
Christopher Haster |
1:24750b9ad5ef | 215 | int mbedtls_dhm_read_public( mbedtls_dhm_context *ctx, |
Christopher Haster |
1:24750b9ad5ef | 216 | const unsigned char *input, size_t ilen ); |
Christopher Haster |
1:24750b9ad5ef | 217 | |
Christopher Haster |
1:24750b9ad5ef | 218 | /** |
Christopher Haster |
1:24750b9ad5ef | 219 | * \brief Create own private value X and export G^X |
Christopher Haster |
1:24750b9ad5ef | 220 | * |
Christopher Haster |
1:24750b9ad5ef | 221 | * \param ctx DHM context |
Christopher Haster |
1:24750b9ad5ef | 222 | * \param x_size private value size in bytes |
Christopher Haster |
1:24750b9ad5ef | 223 | * \param output destination buffer |
Christopher Haster |
1:24750b9ad5ef | 224 | * \param olen must be equal to ctx->P.len |
Christopher Haster |
1:24750b9ad5ef | 225 | * \param f_rng RNG function |
Christopher Haster |
1:24750b9ad5ef | 226 | * \param p_rng RNG parameter |
Christopher Haster |
1:24750b9ad5ef | 227 | * |
Christopher Haster |
1:24750b9ad5ef | 228 | * \return 0 if successful, or an MBEDTLS_ERR_DHM_XXX error code |
Christopher Haster |
1:24750b9ad5ef | 229 | */ |
Christopher Haster |
1:24750b9ad5ef | 230 | int mbedtls_dhm_make_public( mbedtls_dhm_context *ctx, int x_size, |
Christopher Haster |
1:24750b9ad5ef | 231 | unsigned char *output, size_t olen, |
Christopher Haster |
1:24750b9ad5ef | 232 | int (*f_rng)(void *, unsigned char *, size_t), |
Christopher Haster |
1:24750b9ad5ef | 233 | void *p_rng ); |
Christopher Haster |
1:24750b9ad5ef | 234 | |
Christopher Haster |
1:24750b9ad5ef | 235 | /** |
Christopher Haster |
1:24750b9ad5ef | 236 | * \brief Derive and export the shared secret (G^Y)^X mod P |
Christopher Haster |
1:24750b9ad5ef | 237 | * |
Christopher Haster |
1:24750b9ad5ef | 238 | * \param ctx DHM context |
Christopher Haster |
1:24750b9ad5ef | 239 | * \param output destination buffer |
Christopher Haster |
1:24750b9ad5ef | 240 | * \param output_size size of the destination buffer |
Christopher Haster |
1:24750b9ad5ef | 241 | * \param olen on exit, holds the actual number of bytes written |
Christopher Haster |
1:24750b9ad5ef | 242 | * \param f_rng RNG function, for blinding purposes |
Christopher Haster |
1:24750b9ad5ef | 243 | * \param p_rng RNG parameter |
Christopher Haster |
1:24750b9ad5ef | 244 | * |
Christopher Haster |
1:24750b9ad5ef | 245 | * \return 0 if successful, or an MBEDTLS_ERR_DHM_XXX error code |
Christopher Haster |
1:24750b9ad5ef | 246 | * |
Christopher Haster |
1:24750b9ad5ef | 247 | * \note If non-NULL, f_rng is used to blind the input as |
Christopher Haster |
1:24750b9ad5ef | 248 | * countermeasure against timing attacks. Blinding is |
Christopher Haster |
1:24750b9ad5ef | 249 | * automatically used if and only if our secret value X is |
Christopher Haster |
1:24750b9ad5ef | 250 | * re-used and costs nothing otherwise, so it is recommended |
Christopher Haster |
1:24750b9ad5ef | 251 | * to always pass a non-NULL f_rng argument. |
Christopher Haster |
1:24750b9ad5ef | 252 | */ |
Christopher Haster |
1:24750b9ad5ef | 253 | int mbedtls_dhm_calc_secret( mbedtls_dhm_context *ctx, |
Christopher Haster |
1:24750b9ad5ef | 254 | unsigned char *output, size_t output_size, size_t *olen, |
Christopher Haster |
1:24750b9ad5ef | 255 | int (*f_rng)(void *, unsigned char *, size_t), |
Christopher Haster |
1:24750b9ad5ef | 256 | void *p_rng ); |
Christopher Haster |
1:24750b9ad5ef | 257 | |
Christopher Haster |
1:24750b9ad5ef | 258 | /** |
Christopher Haster |
1:24750b9ad5ef | 259 | * \brief Free and clear the components of a DHM key |
Christopher Haster |
1:24750b9ad5ef | 260 | * |
Christopher Haster |
1:24750b9ad5ef | 261 | * \param ctx DHM context to free and clear |
Christopher Haster |
1:24750b9ad5ef | 262 | */ |
Christopher Haster |
1:24750b9ad5ef | 263 | void mbedtls_dhm_free( mbedtls_dhm_context *ctx ); |
Christopher Haster |
1:24750b9ad5ef | 264 | |
Christopher Haster |
1:24750b9ad5ef | 265 | #if defined(MBEDTLS_ASN1_PARSE_C) |
Christopher Haster |
1:24750b9ad5ef | 266 | /** \ingroup x509_module */ |
Christopher Haster |
1:24750b9ad5ef | 267 | /** |
Christopher Haster |
1:24750b9ad5ef | 268 | * \brief Parse DHM parameters in PEM or DER format |
Christopher Haster |
1:24750b9ad5ef | 269 | * |
Christopher Haster |
1:24750b9ad5ef | 270 | * \param dhm DHM context to be initialized |
Christopher Haster |
1:24750b9ad5ef | 271 | * \param dhmin input buffer |
Christopher Haster |
1:24750b9ad5ef | 272 | * \param dhminlen size of the buffer |
Christopher Haster |
1:24750b9ad5ef | 273 | * (including the terminating null byte for PEM data) |
Christopher Haster |
1:24750b9ad5ef | 274 | * |
Christopher Haster |
1:24750b9ad5ef | 275 | * \return 0 if successful, or a specific DHM or PEM error code |
Christopher Haster |
1:24750b9ad5ef | 276 | */ |
Christopher Haster |
1:24750b9ad5ef | 277 | int mbedtls_dhm_parse_dhm( mbedtls_dhm_context *dhm, const unsigned char *dhmin, |
Christopher Haster |
1:24750b9ad5ef | 278 | size_t dhminlen ); |
Christopher Haster |
1:24750b9ad5ef | 279 | |
Christopher Haster |
1:24750b9ad5ef | 280 | #if defined(MBEDTLS_FS_IO) |
Christopher Haster |
1:24750b9ad5ef | 281 | /** \ingroup x509_module */ |
Christopher Haster |
1:24750b9ad5ef | 282 | /** |
Christopher Haster |
1:24750b9ad5ef | 283 | * \brief Load and parse DHM parameters |
Christopher Haster |
1:24750b9ad5ef | 284 | * |
Christopher Haster |
1:24750b9ad5ef | 285 | * \param dhm DHM context to be initialized |
Christopher Haster |
1:24750b9ad5ef | 286 | * \param path filename to read the DHM Parameters from |
Christopher Haster |
1:24750b9ad5ef | 287 | * |
Christopher Haster |
1:24750b9ad5ef | 288 | * \return 0 if successful, or a specific DHM or PEM error code |
Christopher Haster |
1:24750b9ad5ef | 289 | */ |
Christopher Haster |
1:24750b9ad5ef | 290 | int mbedtls_dhm_parse_dhmfile( mbedtls_dhm_context *dhm, const char *path ); |
Christopher Haster |
1:24750b9ad5ef | 291 | #endif /* MBEDTLS_FS_IO */ |
Christopher Haster |
1:24750b9ad5ef | 292 | #endif /* MBEDTLS_ASN1_PARSE_C */ |
Christopher Haster |
1:24750b9ad5ef | 293 | |
Christopher Haster |
1:24750b9ad5ef | 294 | /** |
Christopher Haster |
1:24750b9ad5ef | 295 | * \brief Checkup routine |
Christopher Haster |
1:24750b9ad5ef | 296 | * |
Christopher Haster |
1:24750b9ad5ef | 297 | * \return 0 if successful, or 1 if the test failed |
Christopher Haster |
1:24750b9ad5ef | 298 | */ |
Christopher Haster |
1:24750b9ad5ef | 299 | int mbedtls_dhm_self_test( int verbose ); |
Christopher Haster |
1:24750b9ad5ef | 300 | |
Christopher Haster |
1:24750b9ad5ef | 301 | #ifdef __cplusplus |
Christopher Haster |
1:24750b9ad5ef | 302 | } |
Christopher Haster |
1:24750b9ad5ef | 303 | #endif |
Christopher Haster |
1:24750b9ad5ef | 304 | |
Christopher Haster |
1:24750b9ad5ef | 305 | #endif /* dhm.h */ |