I added functionality to get the RSSI, BER, and Cell Neighbor for reporting connection issues to M2X

Dependencies:   WncControllerK64F

Committer:
JMF
Date:
Thu Nov 17 16:13:29 2016 +0000
Revision:
18:198e9b0acf11
Parent:
12:0071cb144c7a
Updates to mbed os resulted in mutex.h going away and rtos.h needed to be used; This fixes the Mutex typedef failure.  Also cast data buffers from 'char *' to (const std::uint8_t*) to conform with Fred's changes in WncController

Who changed what in which revision?

UserRevisionLine numberNew contents of line
JMF 12:0071cb144c7a 1 /**
JMF 12:0071cb144c7a 2 * \file ecdh.h
JMF 12:0071cb144c7a 3 *
JMF 12:0071cb144c7a 4 * \brief Elliptic curve Diffie-Hellman
JMF 12:0071cb144c7a 5 *
JMF 12:0071cb144c7a 6 * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
JMF 12:0071cb144c7a 7 * SPDX-License-Identifier: Apache-2.0
JMF 12:0071cb144c7a 8 *
JMF 12:0071cb144c7a 9 * Licensed under the Apache License, Version 2.0 (the "License"); you may
JMF 12:0071cb144c7a 10 * not use this file except in compliance with the License.
JMF 12:0071cb144c7a 11 * You may obtain a copy of the License at
JMF 12:0071cb144c7a 12 *
JMF 12:0071cb144c7a 13 * http://www.apache.org/licenses/LICENSE-2.0
JMF 12:0071cb144c7a 14 *
JMF 12:0071cb144c7a 15 * Unless required by applicable law or agreed to in writing, software
JMF 12:0071cb144c7a 16 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
JMF 12:0071cb144c7a 17 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
JMF 12:0071cb144c7a 18 * See the License for the specific language governing permissions and
JMF 12:0071cb144c7a 19 * limitations under the License.
JMF 12:0071cb144c7a 20 *
JMF 12:0071cb144c7a 21 * This file is part of mbed TLS (https://tls.mbed.org)
JMF 12:0071cb144c7a 22 */
JMF 12:0071cb144c7a 23 #ifndef MBEDTLS_ECDH_H
JMF 12:0071cb144c7a 24 #define MBEDTLS_ECDH_H
JMF 12:0071cb144c7a 25
JMF 12:0071cb144c7a 26 #include "ecp.h"
JMF 12:0071cb144c7a 27
JMF 12:0071cb144c7a 28 #ifdef __cplusplus
JMF 12:0071cb144c7a 29 extern "C" {
JMF 12:0071cb144c7a 30 #endif
JMF 12:0071cb144c7a 31
JMF 12:0071cb144c7a 32 /**
JMF 12:0071cb144c7a 33 * When importing from an EC key, select if it is our key or the peer's key
JMF 12:0071cb144c7a 34 */
JMF 12:0071cb144c7a 35 typedef enum
JMF 12:0071cb144c7a 36 {
JMF 12:0071cb144c7a 37 MBEDTLS_ECDH_OURS,
JMF 12:0071cb144c7a 38 MBEDTLS_ECDH_THEIRS,
JMF 12:0071cb144c7a 39 } mbedtls_ecdh_side;
JMF 12:0071cb144c7a 40
JMF 12:0071cb144c7a 41 /**
JMF 12:0071cb144c7a 42 * \brief ECDH context structure
JMF 12:0071cb144c7a 43 */
JMF 12:0071cb144c7a 44 typedef struct
JMF 12:0071cb144c7a 45 {
JMF 12:0071cb144c7a 46 mbedtls_ecp_group grp; /*!< elliptic curve used */
JMF 12:0071cb144c7a 47 mbedtls_mpi d; /*!< our secret value (private key) */
JMF 12:0071cb144c7a 48 mbedtls_ecp_point Q; /*!< our public value (public key) */
JMF 12:0071cb144c7a 49 mbedtls_ecp_point Qp; /*!< peer's public value (public key) */
JMF 12:0071cb144c7a 50 mbedtls_mpi z; /*!< shared secret */
JMF 12:0071cb144c7a 51 int point_format; /*!< format for point export in TLS messages */
JMF 12:0071cb144c7a 52 mbedtls_ecp_point Vi; /*!< blinding value (for later) */
JMF 12:0071cb144c7a 53 mbedtls_ecp_point Vf; /*!< un-blinding value (for later) */
JMF 12:0071cb144c7a 54 mbedtls_mpi _d; /*!< previous d (for later) */
JMF 12:0071cb144c7a 55 }
JMF 12:0071cb144c7a 56 mbedtls_ecdh_context;
JMF 12:0071cb144c7a 57
JMF 12:0071cb144c7a 58 /**
JMF 12:0071cb144c7a 59 * \brief Generate a public key.
JMF 12:0071cb144c7a 60 * Raw function that only does the core computation.
JMF 12:0071cb144c7a 61 *
JMF 12:0071cb144c7a 62 * \param grp ECP group
JMF 12:0071cb144c7a 63 * \param d Destination MPI (secret exponent, aka private key)
JMF 12:0071cb144c7a 64 * \param Q Destination point (public key)
JMF 12:0071cb144c7a 65 * \param f_rng RNG function
JMF 12:0071cb144c7a 66 * \param p_rng RNG parameter
JMF 12:0071cb144c7a 67 *
JMF 12:0071cb144c7a 68 * \return 0 if successful,
JMF 12:0071cb144c7a 69 * or a MBEDTLS_ERR_ECP_XXX or MBEDTLS_MPI_XXX error code
JMF 12:0071cb144c7a 70 */
JMF 12:0071cb144c7a 71 int mbedtls_ecdh_gen_public( mbedtls_ecp_group *grp, mbedtls_mpi *d, mbedtls_ecp_point *Q,
JMF 12:0071cb144c7a 72 int (*f_rng)(void *, unsigned char *, size_t),
JMF 12:0071cb144c7a 73 void *p_rng );
JMF 12:0071cb144c7a 74
JMF 12:0071cb144c7a 75 /**
JMF 12:0071cb144c7a 76 * \brief Compute shared secret
JMF 12:0071cb144c7a 77 * Raw function that only does the core computation.
JMF 12:0071cb144c7a 78 *
JMF 12:0071cb144c7a 79 * \param grp ECP group
JMF 12:0071cb144c7a 80 * \param z Destination MPI (shared secret)
JMF 12:0071cb144c7a 81 * \param Q Public key from other party
JMF 12:0071cb144c7a 82 * \param d Our secret exponent (private key)
JMF 12:0071cb144c7a 83 * \param f_rng RNG function (see notes)
JMF 12:0071cb144c7a 84 * \param p_rng RNG parameter
JMF 12:0071cb144c7a 85 *
JMF 12:0071cb144c7a 86 * \return 0 if successful,
JMF 12:0071cb144c7a 87 * or a MBEDTLS_ERR_ECP_XXX or MBEDTLS_MPI_XXX error code
JMF 12:0071cb144c7a 88 *
JMF 12:0071cb144c7a 89 * \note If f_rng is not NULL, it is used to implement
JMF 12:0071cb144c7a 90 * countermeasures against potential elaborate timing
JMF 12:0071cb144c7a 91 * attacks, see \c mbedtls_ecp_mul() for details.
JMF 12:0071cb144c7a 92 */
JMF 12:0071cb144c7a 93 int mbedtls_ecdh_compute_shared( mbedtls_ecp_group *grp, mbedtls_mpi *z,
JMF 12:0071cb144c7a 94 const mbedtls_ecp_point *Q, const mbedtls_mpi *d,
JMF 12:0071cb144c7a 95 int (*f_rng)(void *, unsigned char *, size_t),
JMF 12:0071cb144c7a 96 void *p_rng );
JMF 12:0071cb144c7a 97
JMF 12:0071cb144c7a 98 /**
JMF 12:0071cb144c7a 99 * \brief Initialize context
JMF 12:0071cb144c7a 100 *
JMF 12:0071cb144c7a 101 * \param ctx Context to initialize
JMF 12:0071cb144c7a 102 */
JMF 12:0071cb144c7a 103 void mbedtls_ecdh_init( mbedtls_ecdh_context *ctx );
JMF 12:0071cb144c7a 104
JMF 12:0071cb144c7a 105 /**
JMF 12:0071cb144c7a 106 * \brief Free context
JMF 12:0071cb144c7a 107 *
JMF 12:0071cb144c7a 108 * \param ctx Context to free
JMF 12:0071cb144c7a 109 */
JMF 12:0071cb144c7a 110 void mbedtls_ecdh_free( mbedtls_ecdh_context *ctx );
JMF 12:0071cb144c7a 111
JMF 12:0071cb144c7a 112 /**
JMF 12:0071cb144c7a 113 * \brief Generate a public key and a TLS ServerKeyExchange payload.
JMF 12:0071cb144c7a 114 * (First function used by a TLS server for ECDHE.)
JMF 12:0071cb144c7a 115 *
JMF 12:0071cb144c7a 116 * \param ctx ECDH context
JMF 12:0071cb144c7a 117 * \param olen number of chars written
JMF 12:0071cb144c7a 118 * \param buf destination buffer
JMF 12:0071cb144c7a 119 * \param blen length of buffer
JMF 12:0071cb144c7a 120 * \param f_rng RNG function
JMF 12:0071cb144c7a 121 * \param p_rng RNG parameter
JMF 12:0071cb144c7a 122 *
JMF 12:0071cb144c7a 123 * \note This function assumes that ctx->grp has already been
JMF 12:0071cb144c7a 124 * properly set (for example using mbedtls_ecp_group_load).
JMF 12:0071cb144c7a 125 *
JMF 12:0071cb144c7a 126 * \return 0 if successful, or an MBEDTLS_ERR_ECP_XXX error code
JMF 12:0071cb144c7a 127 */
JMF 12:0071cb144c7a 128 int mbedtls_ecdh_make_params( mbedtls_ecdh_context *ctx, size_t *olen,
JMF 12:0071cb144c7a 129 unsigned char *buf, size_t blen,
JMF 12:0071cb144c7a 130 int (*f_rng)(void *, unsigned char *, size_t),
JMF 12:0071cb144c7a 131 void *p_rng );
JMF 12:0071cb144c7a 132
JMF 12:0071cb144c7a 133 /**
JMF 12:0071cb144c7a 134 * \brief Parse and procress a TLS ServerKeyExhange payload.
JMF 12:0071cb144c7a 135 * (First function used by a TLS client for ECDHE.)
JMF 12:0071cb144c7a 136 *
JMF 12:0071cb144c7a 137 * \param ctx ECDH context
JMF 12:0071cb144c7a 138 * \param buf pointer to start of input buffer
JMF 12:0071cb144c7a 139 * \param end one past end of buffer
JMF 12:0071cb144c7a 140 *
JMF 12:0071cb144c7a 141 * \return 0 if successful, or an MBEDTLS_ERR_ECP_XXX error code
JMF 12:0071cb144c7a 142 */
JMF 12:0071cb144c7a 143 int mbedtls_ecdh_read_params( mbedtls_ecdh_context *ctx,
JMF 12:0071cb144c7a 144 const unsigned char **buf, const unsigned char *end );
JMF 12:0071cb144c7a 145
JMF 12:0071cb144c7a 146 /**
JMF 12:0071cb144c7a 147 * \brief Setup an ECDH context from an EC key.
JMF 12:0071cb144c7a 148 * (Used by clients and servers in place of the
JMF 12:0071cb144c7a 149 * ServerKeyEchange for static ECDH: import ECDH parameters
JMF 12:0071cb144c7a 150 * from a certificate's EC key information.)
JMF 12:0071cb144c7a 151 *
JMF 12:0071cb144c7a 152 * \param ctx ECDH constext to set
JMF 12:0071cb144c7a 153 * \param key EC key to use
JMF 12:0071cb144c7a 154 * \param side Is it our key (1) or the peer's key (0) ?
JMF 12:0071cb144c7a 155 *
JMF 12:0071cb144c7a 156 * \return 0 if successful, or an MBEDTLS_ERR_ECP_XXX error code
JMF 12:0071cb144c7a 157 */
JMF 12:0071cb144c7a 158 int mbedtls_ecdh_get_params( mbedtls_ecdh_context *ctx, const mbedtls_ecp_keypair *key,
JMF 12:0071cb144c7a 159 mbedtls_ecdh_side side );
JMF 12:0071cb144c7a 160
JMF 12:0071cb144c7a 161 /**
JMF 12:0071cb144c7a 162 * \brief Generate a public key and a TLS ClientKeyExchange payload.
JMF 12:0071cb144c7a 163 * (Second function used by a TLS client for ECDH(E).)
JMF 12:0071cb144c7a 164 *
JMF 12:0071cb144c7a 165 * \param ctx ECDH context
JMF 12:0071cb144c7a 166 * \param olen number of bytes actually written
JMF 12:0071cb144c7a 167 * \param buf destination buffer
JMF 12:0071cb144c7a 168 * \param blen size of destination buffer
JMF 12:0071cb144c7a 169 * \param f_rng RNG function
JMF 12:0071cb144c7a 170 * \param p_rng RNG parameter
JMF 12:0071cb144c7a 171 *
JMF 12:0071cb144c7a 172 * \return 0 if successful, or an MBEDTLS_ERR_ECP_XXX error code
JMF 12:0071cb144c7a 173 */
JMF 12:0071cb144c7a 174 int mbedtls_ecdh_make_public( mbedtls_ecdh_context *ctx, size_t *olen,
JMF 12:0071cb144c7a 175 unsigned char *buf, size_t blen,
JMF 12:0071cb144c7a 176 int (*f_rng)(void *, unsigned char *, size_t),
JMF 12:0071cb144c7a 177 void *p_rng );
JMF 12:0071cb144c7a 178
JMF 12:0071cb144c7a 179 /**
JMF 12:0071cb144c7a 180 * \brief Parse and process a TLS ClientKeyExchange payload.
JMF 12:0071cb144c7a 181 * (Second function used by a TLS server for ECDH(E).)
JMF 12:0071cb144c7a 182 *
JMF 12:0071cb144c7a 183 * \param ctx ECDH context
JMF 12:0071cb144c7a 184 * \param buf start of input buffer
JMF 12:0071cb144c7a 185 * \param blen length of input buffer
JMF 12:0071cb144c7a 186 *
JMF 12:0071cb144c7a 187 * \return 0 if successful, or an MBEDTLS_ERR_ECP_XXX error code
JMF 12:0071cb144c7a 188 */
JMF 12:0071cb144c7a 189 int mbedtls_ecdh_read_public( mbedtls_ecdh_context *ctx,
JMF 12:0071cb144c7a 190 const unsigned char *buf, size_t blen );
JMF 12:0071cb144c7a 191
JMF 12:0071cb144c7a 192 /**
JMF 12:0071cb144c7a 193 * \brief Derive and export the shared secret.
JMF 12:0071cb144c7a 194 * (Last function used by both TLS client en servers.)
JMF 12:0071cb144c7a 195 *
JMF 12:0071cb144c7a 196 * \param ctx ECDH context
JMF 12:0071cb144c7a 197 * \param olen number of bytes written
JMF 12:0071cb144c7a 198 * \param buf destination buffer
JMF 12:0071cb144c7a 199 * \param blen buffer length
JMF 12:0071cb144c7a 200 * \param f_rng RNG function, see notes for \c mbedtls_ecdh_compute_shared()
JMF 12:0071cb144c7a 201 * \param p_rng RNG parameter
JMF 12:0071cb144c7a 202 *
JMF 12:0071cb144c7a 203 * \return 0 if successful, or an MBEDTLS_ERR_ECP_XXX error code
JMF 12:0071cb144c7a 204 */
JMF 12:0071cb144c7a 205 int mbedtls_ecdh_calc_secret( mbedtls_ecdh_context *ctx, size_t *olen,
JMF 12:0071cb144c7a 206 unsigned char *buf, size_t blen,
JMF 12:0071cb144c7a 207 int (*f_rng)(void *, unsigned char *, size_t),
JMF 12:0071cb144c7a 208 void *p_rng );
JMF 12:0071cb144c7a 209
JMF 12:0071cb144c7a 210 #ifdef __cplusplus
JMF 12:0071cb144c7a 211 }
JMF 12:0071cb144c7a 212 #endif
JMF 12:0071cb144c7a 213
JMF 12:0071cb144c7a 214 #endif /* ecdh.h */