mbed client lightswitch demo

Dependencies:   mbed Socket lwip-eth lwip-sys lwip

Fork of mbed-client-classic-example-lwip by Austin Blackstone

Committer:
mbedAustin
Date:
Thu Jun 09 17:08:36 2016 +0000
Revision:
11:cada08fc8a70
Commit for public Consumption

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbedAustin 11:cada08fc8a70 1 /**
mbedAustin 11:cada08fc8a70 2 * \file pk.h
mbedAustin 11:cada08fc8a70 3 *
mbedAustin 11:cada08fc8a70 4 * \brief Public Key abstraction layer
mbedAustin 11:cada08fc8a70 5 *
mbedAustin 11:cada08fc8a70 6 * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
mbedAustin 11:cada08fc8a70 7 * SPDX-License-Identifier: Apache-2.0
mbedAustin 11:cada08fc8a70 8 *
mbedAustin 11:cada08fc8a70 9 * Licensed under the Apache License, Version 2.0 (the "License"); you may
mbedAustin 11:cada08fc8a70 10 * not use this file except in compliance with the License.
mbedAustin 11:cada08fc8a70 11 * You may obtain a copy of the License at
mbedAustin 11:cada08fc8a70 12 *
mbedAustin 11:cada08fc8a70 13 * http://www.apache.org/licenses/LICENSE-2.0
mbedAustin 11:cada08fc8a70 14 *
mbedAustin 11:cada08fc8a70 15 * Unless required by applicable law or agreed to in writing, software
mbedAustin 11:cada08fc8a70 16 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
mbedAustin 11:cada08fc8a70 17 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
mbedAustin 11:cada08fc8a70 18 * See the License for the specific language governing permissions and
mbedAustin 11:cada08fc8a70 19 * limitations under the License.
mbedAustin 11:cada08fc8a70 20 *
mbedAustin 11:cada08fc8a70 21 * This file is part of mbed TLS (https://tls.mbed.org)
mbedAustin 11:cada08fc8a70 22 */
mbedAustin 11:cada08fc8a70 23
mbedAustin 11:cada08fc8a70 24 #ifndef MBEDTLS_PK_H
mbedAustin 11:cada08fc8a70 25 #define MBEDTLS_PK_H
mbedAustin 11:cada08fc8a70 26
mbedAustin 11:cada08fc8a70 27 #if !defined(MBEDTLS_CONFIG_FILE)
mbedAustin 11:cada08fc8a70 28 #include "config.h"
mbedAustin 11:cada08fc8a70 29 #else
mbedAustin 11:cada08fc8a70 30 #include MBEDTLS_CONFIG_FILE
mbedAustin 11:cada08fc8a70 31 #endif
mbedAustin 11:cada08fc8a70 32
mbedAustin 11:cada08fc8a70 33 #include "md.h"
mbedAustin 11:cada08fc8a70 34
mbedAustin 11:cada08fc8a70 35 #if defined(MBEDTLS_RSA_C)
mbedAustin 11:cada08fc8a70 36 #include "rsa.h"
mbedAustin 11:cada08fc8a70 37 #endif
mbedAustin 11:cada08fc8a70 38
mbedAustin 11:cada08fc8a70 39 #if defined(MBEDTLS_ECP_C)
mbedAustin 11:cada08fc8a70 40 #include "ecp.h"
mbedAustin 11:cada08fc8a70 41 #endif
mbedAustin 11:cada08fc8a70 42
mbedAustin 11:cada08fc8a70 43 #if defined(MBEDTLS_ECDSA_C)
mbedAustin 11:cada08fc8a70 44 #include "ecdsa.h"
mbedAustin 11:cada08fc8a70 45 #endif
mbedAustin 11:cada08fc8a70 46
mbedAustin 11:cada08fc8a70 47 #if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && \
mbedAustin 11:cada08fc8a70 48 !defined(inline) && !defined(__cplusplus)
mbedAustin 11:cada08fc8a70 49 #define inline __inline
mbedAustin 11:cada08fc8a70 50 #endif
mbedAustin 11:cada08fc8a70 51
mbedAustin 11:cada08fc8a70 52 #define MBEDTLS_ERR_PK_ALLOC_FAILED -0x3F80 /**< Memory allocation failed. */
mbedAustin 11:cada08fc8a70 53 #define MBEDTLS_ERR_PK_TYPE_MISMATCH -0x3F00 /**< Type mismatch, eg attempt to encrypt with an ECDSA key */
mbedAustin 11:cada08fc8a70 54 #define MBEDTLS_ERR_PK_BAD_INPUT_DATA -0x3E80 /**< Bad input parameters to function. */
mbedAustin 11:cada08fc8a70 55 #define MBEDTLS_ERR_PK_FILE_IO_ERROR -0x3E00 /**< Read/write of file failed. */
mbedAustin 11:cada08fc8a70 56 #define MBEDTLS_ERR_PK_KEY_INVALID_VERSION -0x3D80 /**< Unsupported key version */
mbedAustin 11:cada08fc8a70 57 #define MBEDTLS_ERR_PK_KEY_INVALID_FORMAT -0x3D00 /**< Invalid key tag or value. */
mbedAustin 11:cada08fc8a70 58 #define MBEDTLS_ERR_PK_UNKNOWN_PK_ALG -0x3C80 /**< Key algorithm is unsupported (only RSA and EC are supported). */
mbedAustin 11:cada08fc8a70 59 #define MBEDTLS_ERR_PK_PASSWORD_REQUIRED -0x3C00 /**< Private key password can't be empty. */
mbedAustin 11:cada08fc8a70 60 #define MBEDTLS_ERR_PK_PASSWORD_MISMATCH -0x3B80 /**< Given private key password does not allow for correct decryption. */
mbedAustin 11:cada08fc8a70 61 #define MBEDTLS_ERR_PK_INVALID_PUBKEY -0x3B00 /**< The pubkey tag or value is invalid (only RSA and EC are supported). */
mbedAustin 11:cada08fc8a70 62 #define MBEDTLS_ERR_PK_INVALID_ALG -0x3A80 /**< The algorithm tag or value is invalid. */
mbedAustin 11:cada08fc8a70 63 #define MBEDTLS_ERR_PK_UNKNOWN_NAMED_CURVE -0x3A00 /**< Elliptic curve is unsupported (only NIST curves are supported). */
mbedAustin 11:cada08fc8a70 64 #define MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE -0x3980 /**< Unavailable feature, e.g. RSA disabled for RSA key. */
mbedAustin 11:cada08fc8a70 65 #define MBEDTLS_ERR_PK_SIG_LEN_MISMATCH -0x3900 /**< The signature is valid but its length is less than expected. */
mbedAustin 11:cada08fc8a70 66
mbedAustin 11:cada08fc8a70 67 #ifdef __cplusplus
mbedAustin 11:cada08fc8a70 68 extern "C" {
mbedAustin 11:cada08fc8a70 69 #endif
mbedAustin 11:cada08fc8a70 70
mbedAustin 11:cada08fc8a70 71 /**
mbedAustin 11:cada08fc8a70 72 * \brief Public key types
mbedAustin 11:cada08fc8a70 73 */
mbedAustin 11:cada08fc8a70 74 typedef enum {
mbedAustin 11:cada08fc8a70 75 MBEDTLS_PK_NONE=0,
mbedAustin 11:cada08fc8a70 76 MBEDTLS_PK_RSA,
mbedAustin 11:cada08fc8a70 77 MBEDTLS_PK_ECKEY,
mbedAustin 11:cada08fc8a70 78 MBEDTLS_PK_ECKEY_DH,
mbedAustin 11:cada08fc8a70 79 MBEDTLS_PK_ECDSA,
mbedAustin 11:cada08fc8a70 80 MBEDTLS_PK_RSA_ALT,
mbedAustin 11:cada08fc8a70 81 MBEDTLS_PK_RSASSA_PSS,
mbedAustin 11:cada08fc8a70 82 } mbedtls_pk_type_t;
mbedAustin 11:cada08fc8a70 83
mbedAustin 11:cada08fc8a70 84 /**
mbedAustin 11:cada08fc8a70 85 * \brief Options for RSASSA-PSS signature verification.
mbedAustin 11:cada08fc8a70 86 * See \c mbedtls_rsa_rsassa_pss_verify_ext()
mbedAustin 11:cada08fc8a70 87 */
mbedAustin 11:cada08fc8a70 88 typedef struct
mbedAustin 11:cada08fc8a70 89 {
mbedAustin 11:cada08fc8a70 90 mbedtls_md_type_t mgf1_hash_id;
mbedAustin 11:cada08fc8a70 91 int expected_salt_len;
mbedAustin 11:cada08fc8a70 92
mbedAustin 11:cada08fc8a70 93 } mbedtls_pk_rsassa_pss_options;
mbedAustin 11:cada08fc8a70 94
mbedAustin 11:cada08fc8a70 95 /**
mbedAustin 11:cada08fc8a70 96 * \brief Types for interfacing with the debug module
mbedAustin 11:cada08fc8a70 97 */
mbedAustin 11:cada08fc8a70 98 typedef enum
mbedAustin 11:cada08fc8a70 99 {
mbedAustin 11:cada08fc8a70 100 MBEDTLS_PK_DEBUG_NONE = 0,
mbedAustin 11:cada08fc8a70 101 MBEDTLS_PK_DEBUG_MPI,
mbedAustin 11:cada08fc8a70 102 MBEDTLS_PK_DEBUG_ECP,
mbedAustin 11:cada08fc8a70 103 } mbedtls_pk_debug_type;
mbedAustin 11:cada08fc8a70 104
mbedAustin 11:cada08fc8a70 105 /**
mbedAustin 11:cada08fc8a70 106 * \brief Item to send to the debug module
mbedAustin 11:cada08fc8a70 107 */
mbedAustin 11:cada08fc8a70 108 typedef struct
mbedAustin 11:cada08fc8a70 109 {
mbedAustin 11:cada08fc8a70 110 mbedtls_pk_debug_type type;
mbedAustin 11:cada08fc8a70 111 const char *name;
mbedAustin 11:cada08fc8a70 112 void *value;
mbedAustin 11:cada08fc8a70 113 } mbedtls_pk_debug_item;
mbedAustin 11:cada08fc8a70 114
mbedAustin 11:cada08fc8a70 115 /** Maximum number of item send for debugging, plus 1 */
mbedAustin 11:cada08fc8a70 116 #define MBEDTLS_PK_DEBUG_MAX_ITEMS 3
mbedAustin 11:cada08fc8a70 117
mbedAustin 11:cada08fc8a70 118 /**
mbedAustin 11:cada08fc8a70 119 * \brief Public key information and operations
mbedAustin 11:cada08fc8a70 120 */
mbedAustin 11:cada08fc8a70 121 typedef struct mbedtls_pk_info_t mbedtls_pk_info_t;
mbedAustin 11:cada08fc8a70 122
mbedAustin 11:cada08fc8a70 123 /**
mbedAustin 11:cada08fc8a70 124 * \brief Public key container
mbedAustin 11:cada08fc8a70 125 */
mbedAustin 11:cada08fc8a70 126 typedef struct
mbedAustin 11:cada08fc8a70 127 {
mbedAustin 11:cada08fc8a70 128 const mbedtls_pk_info_t * pk_info; /**< Public key informations */
mbedAustin 11:cada08fc8a70 129 void * pk_ctx; /**< Underlying public key context */
mbedAustin 11:cada08fc8a70 130 } mbedtls_pk_context;
mbedAustin 11:cada08fc8a70 131
mbedAustin 11:cada08fc8a70 132 #if defined(MBEDTLS_RSA_C)
mbedAustin 11:cada08fc8a70 133 /**
mbedAustin 11:cada08fc8a70 134 * Quick access to an RSA context inside a PK context.
mbedAustin 11:cada08fc8a70 135 *
mbedAustin 11:cada08fc8a70 136 * \warning You must make sure the PK context actually holds an RSA context
mbedAustin 11:cada08fc8a70 137 * before using this function!
mbedAustin 11:cada08fc8a70 138 */
mbedAustin 11:cada08fc8a70 139 static inline mbedtls_rsa_context *mbedtls_pk_rsa( const mbedtls_pk_context pk )
mbedAustin 11:cada08fc8a70 140 {
mbedAustin 11:cada08fc8a70 141 return( (mbedtls_rsa_context *) (pk).pk_ctx );
mbedAustin 11:cada08fc8a70 142 }
mbedAustin 11:cada08fc8a70 143 #endif /* MBEDTLS_RSA_C */
mbedAustin 11:cada08fc8a70 144
mbedAustin 11:cada08fc8a70 145 #if defined(MBEDTLS_ECP_C)
mbedAustin 11:cada08fc8a70 146 /**
mbedAustin 11:cada08fc8a70 147 * Quick access to an EC context inside a PK context.
mbedAustin 11:cada08fc8a70 148 *
mbedAustin 11:cada08fc8a70 149 * \warning You must make sure the PK context actually holds an EC context
mbedAustin 11:cada08fc8a70 150 * before using this function!
mbedAustin 11:cada08fc8a70 151 */
mbedAustin 11:cada08fc8a70 152 static inline mbedtls_ecp_keypair *mbedtls_pk_ec( const mbedtls_pk_context pk )
mbedAustin 11:cada08fc8a70 153 {
mbedAustin 11:cada08fc8a70 154 return( (mbedtls_ecp_keypair *) (pk).pk_ctx );
mbedAustin 11:cada08fc8a70 155 }
mbedAustin 11:cada08fc8a70 156 #endif /* MBEDTLS_ECP_C */
mbedAustin 11:cada08fc8a70 157
mbedAustin 11:cada08fc8a70 158 #if defined(MBEDTLS_PK_RSA_ALT_SUPPORT)
mbedAustin 11:cada08fc8a70 159 /**
mbedAustin 11:cada08fc8a70 160 * \brief Types for RSA-alt abstraction
mbedAustin 11:cada08fc8a70 161 */
mbedAustin 11:cada08fc8a70 162 typedef int (*mbedtls_pk_rsa_alt_decrypt_func)( void *ctx, int mode, size_t *olen,
mbedAustin 11:cada08fc8a70 163 const unsigned char *input, unsigned char *output,
mbedAustin 11:cada08fc8a70 164 size_t output_max_len );
mbedAustin 11:cada08fc8a70 165 typedef int (*mbedtls_pk_rsa_alt_sign_func)( void *ctx,
mbedAustin 11:cada08fc8a70 166 int (*f_rng)(void *, unsigned char *, size_t), void *p_rng,
mbedAustin 11:cada08fc8a70 167 int mode, mbedtls_md_type_t md_alg, unsigned int hashlen,
mbedAustin 11:cada08fc8a70 168 const unsigned char *hash, unsigned char *sig );
mbedAustin 11:cada08fc8a70 169 typedef size_t (*mbedtls_pk_rsa_alt_key_len_func)( void *ctx );
mbedAustin 11:cada08fc8a70 170 #endif /* MBEDTLS_PK_RSA_ALT_SUPPORT */
mbedAustin 11:cada08fc8a70 171
mbedAustin 11:cada08fc8a70 172 /**
mbedAustin 11:cada08fc8a70 173 * \brief Return information associated with the given PK type
mbedAustin 11:cada08fc8a70 174 *
mbedAustin 11:cada08fc8a70 175 * \param pk_type PK type to search for.
mbedAustin 11:cada08fc8a70 176 *
mbedAustin 11:cada08fc8a70 177 * \return The PK info associated with the type or NULL if not found.
mbedAustin 11:cada08fc8a70 178 */
mbedAustin 11:cada08fc8a70 179 const mbedtls_pk_info_t *mbedtls_pk_info_from_type( mbedtls_pk_type_t pk_type );
mbedAustin 11:cada08fc8a70 180
mbedAustin 11:cada08fc8a70 181 /**
mbedAustin 11:cada08fc8a70 182 * \brief Initialize a mbedtls_pk_context (as NONE)
mbedAustin 11:cada08fc8a70 183 */
mbedAustin 11:cada08fc8a70 184 void mbedtls_pk_init( mbedtls_pk_context *ctx );
mbedAustin 11:cada08fc8a70 185
mbedAustin 11:cada08fc8a70 186 /**
mbedAustin 11:cada08fc8a70 187 * \brief Free a mbedtls_pk_context
mbedAustin 11:cada08fc8a70 188 */
mbedAustin 11:cada08fc8a70 189 void mbedtls_pk_free( mbedtls_pk_context *ctx );
mbedAustin 11:cada08fc8a70 190
mbedAustin 11:cada08fc8a70 191 /**
mbedAustin 11:cada08fc8a70 192 * \brief Initialize a PK context with the information given
mbedAustin 11:cada08fc8a70 193 * and allocates the type-specific PK subcontext.
mbedAustin 11:cada08fc8a70 194 *
mbedAustin 11:cada08fc8a70 195 * \param ctx Context to initialize. Must be empty (type NONE).
mbedAustin 11:cada08fc8a70 196 * \param info Information to use
mbedAustin 11:cada08fc8a70 197 *
mbedAustin 11:cada08fc8a70 198 * \return 0 on success,
mbedAustin 11:cada08fc8a70 199 * MBEDTLS_ERR_PK_BAD_INPUT_DATA on invalid input,
mbedAustin 11:cada08fc8a70 200 * MBEDTLS_ERR_PK_ALLOC_FAILED on allocation failure.
mbedAustin 11:cada08fc8a70 201 *
mbedAustin 11:cada08fc8a70 202 * \note For contexts holding an RSA-alt key, use
mbedAustin 11:cada08fc8a70 203 * \c mbedtls_pk_setup_rsa_alt() instead.
mbedAustin 11:cada08fc8a70 204 */
mbedAustin 11:cada08fc8a70 205 int mbedtls_pk_setup( mbedtls_pk_context *ctx, const mbedtls_pk_info_t *info );
mbedAustin 11:cada08fc8a70 206
mbedAustin 11:cada08fc8a70 207 #if defined(MBEDTLS_PK_RSA_ALT_SUPPORT)
mbedAustin 11:cada08fc8a70 208 /**
mbedAustin 11:cada08fc8a70 209 * \brief Initialize an RSA-alt context
mbedAustin 11:cada08fc8a70 210 *
mbedAustin 11:cada08fc8a70 211 * \param ctx Context to initialize. Must be empty (type NONE).
mbedAustin 11:cada08fc8a70 212 * \param key RSA key pointer
mbedAustin 11:cada08fc8a70 213 * \param decrypt_func Decryption function
mbedAustin 11:cada08fc8a70 214 * \param sign_func Signing function
mbedAustin 11:cada08fc8a70 215 * \param key_len_func Function returning key length in bytes
mbedAustin 11:cada08fc8a70 216 *
mbedAustin 11:cada08fc8a70 217 * \return 0 on success, or MBEDTLS_ERR_PK_BAD_INPUT_DATA if the
mbedAustin 11:cada08fc8a70 218 * context wasn't already initialized as RSA_ALT.
mbedAustin 11:cada08fc8a70 219 *
mbedAustin 11:cada08fc8a70 220 * \note This function replaces \c mbedtls_pk_setup() for RSA-alt.
mbedAustin 11:cada08fc8a70 221 */
mbedAustin 11:cada08fc8a70 222 int mbedtls_pk_setup_rsa_alt( mbedtls_pk_context *ctx, void * key,
mbedAustin 11:cada08fc8a70 223 mbedtls_pk_rsa_alt_decrypt_func decrypt_func,
mbedAustin 11:cada08fc8a70 224 mbedtls_pk_rsa_alt_sign_func sign_func,
mbedAustin 11:cada08fc8a70 225 mbedtls_pk_rsa_alt_key_len_func key_len_func );
mbedAustin 11:cada08fc8a70 226 #endif /* MBEDTLS_PK_RSA_ALT_SUPPORT */
mbedAustin 11:cada08fc8a70 227
mbedAustin 11:cada08fc8a70 228 /**
mbedAustin 11:cada08fc8a70 229 * \brief Get the size in bits of the underlying key
mbedAustin 11:cada08fc8a70 230 *
mbedAustin 11:cada08fc8a70 231 * \param ctx Context to use
mbedAustin 11:cada08fc8a70 232 *
mbedAustin 11:cada08fc8a70 233 * \return Key size in bits, or 0 on error
mbedAustin 11:cada08fc8a70 234 */
mbedAustin 11:cada08fc8a70 235 size_t mbedtls_pk_get_bitlen( const mbedtls_pk_context *ctx );
mbedAustin 11:cada08fc8a70 236
mbedAustin 11:cada08fc8a70 237 /**
mbedAustin 11:cada08fc8a70 238 * \brief Get the length in bytes of the underlying key
mbedAustin 11:cada08fc8a70 239 * \param ctx Context to use
mbedAustin 11:cada08fc8a70 240 *
mbedAustin 11:cada08fc8a70 241 * \return Key length in bytes, or 0 on error
mbedAustin 11:cada08fc8a70 242 */
mbedAustin 11:cada08fc8a70 243 static inline size_t mbedtls_pk_get_len( const mbedtls_pk_context *ctx )
mbedAustin 11:cada08fc8a70 244 {
mbedAustin 11:cada08fc8a70 245 return( ( mbedtls_pk_get_bitlen( ctx ) + 7 ) / 8 );
mbedAustin 11:cada08fc8a70 246 }
mbedAustin 11:cada08fc8a70 247
mbedAustin 11:cada08fc8a70 248 /**
mbedAustin 11:cada08fc8a70 249 * \brief Tell if a context can do the operation given by type
mbedAustin 11:cada08fc8a70 250 *
mbedAustin 11:cada08fc8a70 251 * \param ctx Context to test
mbedAustin 11:cada08fc8a70 252 * \param type Target type
mbedAustin 11:cada08fc8a70 253 *
mbedAustin 11:cada08fc8a70 254 * \return 0 if context can't do the operations,
mbedAustin 11:cada08fc8a70 255 * 1 otherwise.
mbedAustin 11:cada08fc8a70 256 */
mbedAustin 11:cada08fc8a70 257 int mbedtls_pk_can_do( const mbedtls_pk_context *ctx, mbedtls_pk_type_t type );
mbedAustin 11:cada08fc8a70 258
mbedAustin 11:cada08fc8a70 259 /**
mbedAustin 11:cada08fc8a70 260 * \brief Verify signature (including padding if relevant).
mbedAustin 11:cada08fc8a70 261 *
mbedAustin 11:cada08fc8a70 262 * \param ctx PK context to use
mbedAustin 11:cada08fc8a70 263 * \param md_alg Hash algorithm used (see notes)
mbedAustin 11:cada08fc8a70 264 * \param hash Hash of the message to sign
mbedAustin 11:cada08fc8a70 265 * \param hash_len Hash length or 0 (see notes)
mbedAustin 11:cada08fc8a70 266 * \param sig Signature to verify
mbedAustin 11:cada08fc8a70 267 * \param sig_len Signature length
mbedAustin 11:cada08fc8a70 268 *
mbedAustin 11:cada08fc8a70 269 * \return 0 on success (signature is valid),
mbedAustin 11:cada08fc8a70 270 * MBEDTLS_ERR_PK_SIG_LEN_MISMATCH if the signature is
mbedAustin 11:cada08fc8a70 271 * valid but its actual length is less than sig_len,
mbedAustin 11:cada08fc8a70 272 * or a specific error code.
mbedAustin 11:cada08fc8a70 273 *
mbedAustin 11:cada08fc8a70 274 * \note For RSA keys, the default padding type is PKCS#1 v1.5.
mbedAustin 11:cada08fc8a70 275 * Use \c mbedtls_pk_verify_ext( MBEDTLS_PK_RSASSA_PSS, ... )
mbedAustin 11:cada08fc8a70 276 * to verify RSASSA_PSS signatures.
mbedAustin 11:cada08fc8a70 277 *
mbedAustin 11:cada08fc8a70 278 * \note If hash_len is 0, then the length associated with md_alg
mbedAustin 11:cada08fc8a70 279 * is used instead, or an error returned if it is invalid.
mbedAustin 11:cada08fc8a70 280 *
mbedAustin 11:cada08fc8a70 281 * \note md_alg may be MBEDTLS_MD_NONE, only if hash_len != 0
mbedAustin 11:cada08fc8a70 282 */
mbedAustin 11:cada08fc8a70 283 int mbedtls_pk_verify( mbedtls_pk_context *ctx, mbedtls_md_type_t md_alg,
mbedAustin 11:cada08fc8a70 284 const unsigned char *hash, size_t hash_len,
mbedAustin 11:cada08fc8a70 285 const unsigned char *sig, size_t sig_len );
mbedAustin 11:cada08fc8a70 286
mbedAustin 11:cada08fc8a70 287 /**
mbedAustin 11:cada08fc8a70 288 * \brief Verify signature, with options.
mbedAustin 11:cada08fc8a70 289 * (Includes verification of the padding depending on type.)
mbedAustin 11:cada08fc8a70 290 *
mbedAustin 11:cada08fc8a70 291 * \param type Signature type (inc. possible padding type) to verify
mbedAustin 11:cada08fc8a70 292 * \param options Pointer to type-specific options, or NULL
mbedAustin 11:cada08fc8a70 293 * \param ctx PK context to use
mbedAustin 11:cada08fc8a70 294 * \param md_alg Hash algorithm used (see notes)
mbedAustin 11:cada08fc8a70 295 * \param hash Hash of the message to sign
mbedAustin 11:cada08fc8a70 296 * \param hash_len Hash length or 0 (see notes)
mbedAustin 11:cada08fc8a70 297 * \param sig Signature to verify
mbedAustin 11:cada08fc8a70 298 * \param sig_len Signature length
mbedAustin 11:cada08fc8a70 299 *
mbedAustin 11:cada08fc8a70 300 * \return 0 on success (signature is valid),
mbedAustin 11:cada08fc8a70 301 * MBEDTLS_ERR_PK_TYPE_MISMATCH if the PK context can't be
mbedAustin 11:cada08fc8a70 302 * used for this type of signatures,
mbedAustin 11:cada08fc8a70 303 * MBEDTLS_ERR_PK_SIG_LEN_MISMATCH if the signature is
mbedAustin 11:cada08fc8a70 304 * valid but its actual length is less than sig_len,
mbedAustin 11:cada08fc8a70 305 * or a specific error code.
mbedAustin 11:cada08fc8a70 306 *
mbedAustin 11:cada08fc8a70 307 * \note If hash_len is 0, then the length associated with md_alg
mbedAustin 11:cada08fc8a70 308 * is used instead, or an error returned if it is invalid.
mbedAustin 11:cada08fc8a70 309 *
mbedAustin 11:cada08fc8a70 310 * \note md_alg may be MBEDTLS_MD_NONE, only if hash_len != 0
mbedAustin 11:cada08fc8a70 311 *
mbedAustin 11:cada08fc8a70 312 * \note If type is MBEDTLS_PK_RSASSA_PSS, then options must point
mbedAustin 11:cada08fc8a70 313 * to a mbedtls_pk_rsassa_pss_options structure,
mbedAustin 11:cada08fc8a70 314 * otherwise it must be NULL.
mbedAustin 11:cada08fc8a70 315 */
mbedAustin 11:cada08fc8a70 316 int mbedtls_pk_verify_ext( mbedtls_pk_type_t type, const void *options,
mbedAustin 11:cada08fc8a70 317 mbedtls_pk_context *ctx, mbedtls_md_type_t md_alg,
mbedAustin 11:cada08fc8a70 318 const unsigned char *hash, size_t hash_len,
mbedAustin 11:cada08fc8a70 319 const unsigned char *sig, size_t sig_len );
mbedAustin 11:cada08fc8a70 320
mbedAustin 11:cada08fc8a70 321 /**
mbedAustin 11:cada08fc8a70 322 * \brief Make signature, including padding if relevant.
mbedAustin 11:cada08fc8a70 323 *
mbedAustin 11:cada08fc8a70 324 * \param ctx PK context to use - must hold a private key
mbedAustin 11:cada08fc8a70 325 * \param md_alg Hash algorithm used (see notes)
mbedAustin 11:cada08fc8a70 326 * \param hash Hash of the message to sign
mbedAustin 11:cada08fc8a70 327 * \param hash_len Hash length or 0 (see notes)
mbedAustin 11:cada08fc8a70 328 * \param sig Place to write the signature
mbedAustin 11:cada08fc8a70 329 * \param sig_len Number of bytes written
mbedAustin 11:cada08fc8a70 330 * \param f_rng RNG function
mbedAustin 11:cada08fc8a70 331 * \param p_rng RNG parameter
mbedAustin 11:cada08fc8a70 332 *
mbedAustin 11:cada08fc8a70 333 * \return 0 on success, or a specific error code.
mbedAustin 11:cada08fc8a70 334 *
mbedAustin 11:cada08fc8a70 335 * \note For RSA keys, the default padding type is PKCS#1 v1.5.
mbedAustin 11:cada08fc8a70 336 * There is no interface in the PK module to make RSASSA-PSS
mbedAustin 11:cada08fc8a70 337 * signatures yet.
mbedAustin 11:cada08fc8a70 338 *
mbedAustin 11:cada08fc8a70 339 * \note If hash_len is 0, then the length associated with md_alg
mbedAustin 11:cada08fc8a70 340 * is used instead, or an error returned if it is invalid.
mbedAustin 11:cada08fc8a70 341 *
mbedAustin 11:cada08fc8a70 342 * \note For RSA, md_alg may be MBEDTLS_MD_NONE if hash_len != 0.
mbedAustin 11:cada08fc8a70 343 * For ECDSA, md_alg may never be MBEDTLS_MD_NONE.
mbedAustin 11:cada08fc8a70 344 */
mbedAustin 11:cada08fc8a70 345 int mbedtls_pk_sign( mbedtls_pk_context *ctx, mbedtls_md_type_t md_alg,
mbedAustin 11:cada08fc8a70 346 const unsigned char *hash, size_t hash_len,
mbedAustin 11:cada08fc8a70 347 unsigned char *sig, size_t *sig_len,
mbedAustin 11:cada08fc8a70 348 int (*f_rng)(void *, unsigned char *, size_t), void *p_rng );
mbedAustin 11:cada08fc8a70 349
mbedAustin 11:cada08fc8a70 350 /**
mbedAustin 11:cada08fc8a70 351 * \brief Decrypt message (including padding if relevant).
mbedAustin 11:cada08fc8a70 352 *
mbedAustin 11:cada08fc8a70 353 * \param ctx PK context to use - must hold a private key
mbedAustin 11:cada08fc8a70 354 * \param input Input to decrypt
mbedAustin 11:cada08fc8a70 355 * \param ilen Input size
mbedAustin 11:cada08fc8a70 356 * \param output Decrypted output
mbedAustin 11:cada08fc8a70 357 * \param olen Decrypted message length
mbedAustin 11:cada08fc8a70 358 * \param osize Size of the output buffer
mbedAustin 11:cada08fc8a70 359 * \param f_rng RNG function
mbedAustin 11:cada08fc8a70 360 * \param p_rng RNG parameter
mbedAustin 11:cada08fc8a70 361 *
mbedAustin 11:cada08fc8a70 362 * \note For RSA keys, the default padding type is PKCS#1 v1.5.
mbedAustin 11:cada08fc8a70 363 *
mbedAustin 11:cada08fc8a70 364 * \return 0 on success, or a specific error code.
mbedAustin 11:cada08fc8a70 365 */
mbedAustin 11:cada08fc8a70 366 int mbedtls_pk_decrypt( mbedtls_pk_context *ctx,
mbedAustin 11:cada08fc8a70 367 const unsigned char *input, size_t ilen,
mbedAustin 11:cada08fc8a70 368 unsigned char *output, size_t *olen, size_t osize,
mbedAustin 11:cada08fc8a70 369 int (*f_rng)(void *, unsigned char *, size_t), void *p_rng );
mbedAustin 11:cada08fc8a70 370
mbedAustin 11:cada08fc8a70 371 /**
mbedAustin 11:cada08fc8a70 372 * \brief Encrypt message (including padding if relevant).
mbedAustin 11:cada08fc8a70 373 *
mbedAustin 11:cada08fc8a70 374 * \param ctx PK context to use
mbedAustin 11:cada08fc8a70 375 * \param input Message to encrypt
mbedAustin 11:cada08fc8a70 376 * \param ilen Message size
mbedAustin 11:cada08fc8a70 377 * \param output Encrypted output
mbedAustin 11:cada08fc8a70 378 * \param olen Encrypted output length
mbedAustin 11:cada08fc8a70 379 * \param osize Size of the output buffer
mbedAustin 11:cada08fc8a70 380 * \param f_rng RNG function
mbedAustin 11:cada08fc8a70 381 * \param p_rng RNG parameter
mbedAustin 11:cada08fc8a70 382 *
mbedAustin 11:cada08fc8a70 383 * \note For RSA keys, the default padding type is PKCS#1 v1.5.
mbedAustin 11:cada08fc8a70 384 *
mbedAustin 11:cada08fc8a70 385 * \return 0 on success, or a specific error code.
mbedAustin 11:cada08fc8a70 386 */
mbedAustin 11:cada08fc8a70 387 int mbedtls_pk_encrypt( mbedtls_pk_context *ctx,
mbedAustin 11:cada08fc8a70 388 const unsigned char *input, size_t ilen,
mbedAustin 11:cada08fc8a70 389 unsigned char *output, size_t *olen, size_t osize,
mbedAustin 11:cada08fc8a70 390 int (*f_rng)(void *, unsigned char *, size_t), void *p_rng );
mbedAustin 11:cada08fc8a70 391
mbedAustin 11:cada08fc8a70 392 /**
mbedAustin 11:cada08fc8a70 393 * \brief Check if a public-private pair of keys matches.
mbedAustin 11:cada08fc8a70 394 *
mbedAustin 11:cada08fc8a70 395 * \param pub Context holding a public key.
mbedAustin 11:cada08fc8a70 396 * \param prv Context holding a private (and public) key.
mbedAustin 11:cada08fc8a70 397 *
mbedAustin 11:cada08fc8a70 398 * \return 0 on success or MBEDTLS_ERR_PK_BAD_INPUT_DATA
mbedAustin 11:cada08fc8a70 399 */
mbedAustin 11:cada08fc8a70 400 int mbedtls_pk_check_pair( const mbedtls_pk_context *pub, const mbedtls_pk_context *prv );
mbedAustin 11:cada08fc8a70 401
mbedAustin 11:cada08fc8a70 402 /**
mbedAustin 11:cada08fc8a70 403 * \brief Export debug information
mbedAustin 11:cada08fc8a70 404 *
mbedAustin 11:cada08fc8a70 405 * \param ctx Context to use
mbedAustin 11:cada08fc8a70 406 * \param items Place to write debug items
mbedAustin 11:cada08fc8a70 407 *
mbedAustin 11:cada08fc8a70 408 * \return 0 on success or MBEDTLS_ERR_PK_BAD_INPUT_DATA
mbedAustin 11:cada08fc8a70 409 */
mbedAustin 11:cada08fc8a70 410 int mbedtls_pk_debug( const mbedtls_pk_context *ctx, mbedtls_pk_debug_item *items );
mbedAustin 11:cada08fc8a70 411
mbedAustin 11:cada08fc8a70 412 /**
mbedAustin 11:cada08fc8a70 413 * \brief Access the type name
mbedAustin 11:cada08fc8a70 414 *
mbedAustin 11:cada08fc8a70 415 * \param ctx Context to use
mbedAustin 11:cada08fc8a70 416 *
mbedAustin 11:cada08fc8a70 417 * \return Type name on success, or "invalid PK"
mbedAustin 11:cada08fc8a70 418 */
mbedAustin 11:cada08fc8a70 419 const char * mbedtls_pk_get_name( const mbedtls_pk_context *ctx );
mbedAustin 11:cada08fc8a70 420
mbedAustin 11:cada08fc8a70 421 /**
mbedAustin 11:cada08fc8a70 422 * \brief Get the key type
mbedAustin 11:cada08fc8a70 423 *
mbedAustin 11:cada08fc8a70 424 * \param ctx Context to use
mbedAustin 11:cada08fc8a70 425 *
mbedAustin 11:cada08fc8a70 426 * \return Type on success, or MBEDTLS_PK_NONE
mbedAustin 11:cada08fc8a70 427 */
mbedAustin 11:cada08fc8a70 428 mbedtls_pk_type_t mbedtls_pk_get_type( const mbedtls_pk_context *ctx );
mbedAustin 11:cada08fc8a70 429
mbedAustin 11:cada08fc8a70 430 #if defined(MBEDTLS_PK_PARSE_C)
mbedAustin 11:cada08fc8a70 431 /** \ingroup pk_module */
mbedAustin 11:cada08fc8a70 432 /**
mbedAustin 11:cada08fc8a70 433 * \brief Parse a private key in PEM or DER format
mbedAustin 11:cada08fc8a70 434 *
mbedAustin 11:cada08fc8a70 435 * \param ctx key to be initialized
mbedAustin 11:cada08fc8a70 436 * \param key input buffer
mbedAustin 11:cada08fc8a70 437 * \param keylen size of the buffer
mbedAustin 11:cada08fc8a70 438 * (including the terminating null byte for PEM data)
mbedAustin 11:cada08fc8a70 439 * \param pwd password for decryption (optional)
mbedAustin 11:cada08fc8a70 440 * \param pwdlen size of the password
mbedAustin 11:cada08fc8a70 441 *
mbedAustin 11:cada08fc8a70 442 * \note On entry, ctx must be empty, either freshly initialised
mbedAustin 11:cada08fc8a70 443 * with mbedtls_pk_init() or reset with mbedtls_pk_free(). If you need a
mbedAustin 11:cada08fc8a70 444 * specific key type, check the result with mbedtls_pk_can_do().
mbedAustin 11:cada08fc8a70 445 *
mbedAustin 11:cada08fc8a70 446 * \note The key is also checked for correctness.
mbedAustin 11:cada08fc8a70 447 *
mbedAustin 11:cada08fc8a70 448 * \return 0 if successful, or a specific PK or PEM error code
mbedAustin 11:cada08fc8a70 449 */
mbedAustin 11:cada08fc8a70 450 int mbedtls_pk_parse_key( mbedtls_pk_context *ctx,
mbedAustin 11:cada08fc8a70 451 const unsigned char *key, size_t keylen,
mbedAustin 11:cada08fc8a70 452 const unsigned char *pwd, size_t pwdlen );
mbedAustin 11:cada08fc8a70 453
mbedAustin 11:cada08fc8a70 454 /** \ingroup pk_module */
mbedAustin 11:cada08fc8a70 455 /**
mbedAustin 11:cada08fc8a70 456 * \brief Parse a public key in PEM or DER format
mbedAustin 11:cada08fc8a70 457 *
mbedAustin 11:cada08fc8a70 458 * \param ctx key to be initialized
mbedAustin 11:cada08fc8a70 459 * \param key input buffer
mbedAustin 11:cada08fc8a70 460 * \param keylen size of the buffer
mbedAustin 11:cada08fc8a70 461 * (including the terminating null byte for PEM data)
mbedAustin 11:cada08fc8a70 462 *
mbedAustin 11:cada08fc8a70 463 * \note On entry, ctx must be empty, either freshly initialised
mbedAustin 11:cada08fc8a70 464 * with mbedtls_pk_init() or reset with mbedtls_pk_free(). If you need a
mbedAustin 11:cada08fc8a70 465 * specific key type, check the result with mbedtls_pk_can_do().
mbedAustin 11:cada08fc8a70 466 *
mbedAustin 11:cada08fc8a70 467 * \note The key is also checked for correctness.
mbedAustin 11:cada08fc8a70 468 *
mbedAustin 11:cada08fc8a70 469 * \return 0 if successful, or a specific PK or PEM error code
mbedAustin 11:cada08fc8a70 470 */
mbedAustin 11:cada08fc8a70 471 int mbedtls_pk_parse_public_key( mbedtls_pk_context *ctx,
mbedAustin 11:cada08fc8a70 472 const unsigned char *key, size_t keylen );
mbedAustin 11:cada08fc8a70 473
mbedAustin 11:cada08fc8a70 474 #if defined(MBEDTLS_FS_IO)
mbedAustin 11:cada08fc8a70 475 /** \ingroup pk_module */
mbedAustin 11:cada08fc8a70 476 /**
mbedAustin 11:cada08fc8a70 477 * \brief Load and parse a private key
mbedAustin 11:cada08fc8a70 478 *
mbedAustin 11:cada08fc8a70 479 * \param ctx key to be initialized
mbedAustin 11:cada08fc8a70 480 * \param path filename to read the private key from
mbedAustin 11:cada08fc8a70 481 * \param password password to decrypt the file (can be NULL)
mbedAustin 11:cada08fc8a70 482 *
mbedAustin 11:cada08fc8a70 483 * \note On entry, ctx must be empty, either freshly initialised
mbedAustin 11:cada08fc8a70 484 * with mbedtls_pk_init() or reset with mbedtls_pk_free(). If you need a
mbedAustin 11:cada08fc8a70 485 * specific key type, check the result with mbedtls_pk_can_do().
mbedAustin 11:cada08fc8a70 486 *
mbedAustin 11:cada08fc8a70 487 * \note The key is also checked for correctness.
mbedAustin 11:cada08fc8a70 488 *
mbedAustin 11:cada08fc8a70 489 * \return 0 if successful, or a specific PK or PEM error code
mbedAustin 11:cada08fc8a70 490 */
mbedAustin 11:cada08fc8a70 491 int mbedtls_pk_parse_keyfile( mbedtls_pk_context *ctx,
mbedAustin 11:cada08fc8a70 492 const char *path, const char *password );
mbedAustin 11:cada08fc8a70 493
mbedAustin 11:cada08fc8a70 494 /** \ingroup pk_module */
mbedAustin 11:cada08fc8a70 495 /**
mbedAustin 11:cada08fc8a70 496 * \brief Load and parse a public key
mbedAustin 11:cada08fc8a70 497 *
mbedAustin 11:cada08fc8a70 498 * \param ctx key to be initialized
mbedAustin 11:cada08fc8a70 499 * \param path filename to read the private key from
mbedAustin 11:cada08fc8a70 500 *
mbedAustin 11:cada08fc8a70 501 * \note On entry, ctx must be empty, either freshly initialised
mbedAustin 11:cada08fc8a70 502 * with mbedtls_pk_init() or reset with mbedtls_pk_free(). If you need a
mbedAustin 11:cada08fc8a70 503 * specific key type, check the result with mbedtls_pk_can_do().
mbedAustin 11:cada08fc8a70 504 *
mbedAustin 11:cada08fc8a70 505 * \note The key is also checked for correctness.
mbedAustin 11:cada08fc8a70 506 *
mbedAustin 11:cada08fc8a70 507 * \return 0 if successful, or a specific PK or PEM error code
mbedAustin 11:cada08fc8a70 508 */
mbedAustin 11:cada08fc8a70 509 int mbedtls_pk_parse_public_keyfile( mbedtls_pk_context *ctx, const char *path );
mbedAustin 11:cada08fc8a70 510 #endif /* MBEDTLS_FS_IO */
mbedAustin 11:cada08fc8a70 511 #endif /* MBEDTLS_PK_PARSE_C */
mbedAustin 11:cada08fc8a70 512
mbedAustin 11:cada08fc8a70 513 #if defined(MBEDTLS_PK_WRITE_C)
mbedAustin 11:cada08fc8a70 514 /**
mbedAustin 11:cada08fc8a70 515 * \brief Write a private key to a PKCS#1 or SEC1 DER structure
mbedAustin 11:cada08fc8a70 516 * Note: data is written at the end of the buffer! Use the
mbedAustin 11:cada08fc8a70 517 * return value to determine where you should start
mbedAustin 11:cada08fc8a70 518 * using the buffer
mbedAustin 11:cada08fc8a70 519 *
mbedAustin 11:cada08fc8a70 520 * \param ctx private to write away
mbedAustin 11:cada08fc8a70 521 * \param buf buffer to write to
mbedAustin 11:cada08fc8a70 522 * \param size size of the buffer
mbedAustin 11:cada08fc8a70 523 *
mbedAustin 11:cada08fc8a70 524 * \return length of data written if successful, or a specific
mbedAustin 11:cada08fc8a70 525 * error code
mbedAustin 11:cada08fc8a70 526 */
mbedAustin 11:cada08fc8a70 527 int mbedtls_pk_write_key_der( mbedtls_pk_context *ctx, unsigned char *buf, size_t size );
mbedAustin 11:cada08fc8a70 528
mbedAustin 11:cada08fc8a70 529 /**
mbedAustin 11:cada08fc8a70 530 * \brief Write a public key to a SubjectPublicKeyInfo DER structure
mbedAustin 11:cada08fc8a70 531 * Note: data is written at the end of the buffer! Use the
mbedAustin 11:cada08fc8a70 532 * return value to determine where you should start
mbedAustin 11:cada08fc8a70 533 * using the buffer
mbedAustin 11:cada08fc8a70 534 *
mbedAustin 11:cada08fc8a70 535 * \param ctx public key to write away
mbedAustin 11:cada08fc8a70 536 * \param buf buffer to write to
mbedAustin 11:cada08fc8a70 537 * \param size size of the buffer
mbedAustin 11:cada08fc8a70 538 *
mbedAustin 11:cada08fc8a70 539 * \return length of data written if successful, or a specific
mbedAustin 11:cada08fc8a70 540 * error code
mbedAustin 11:cada08fc8a70 541 */
mbedAustin 11:cada08fc8a70 542 int mbedtls_pk_write_pubkey_der( mbedtls_pk_context *ctx, unsigned char *buf, size_t size );
mbedAustin 11:cada08fc8a70 543
mbedAustin 11:cada08fc8a70 544 #if defined(MBEDTLS_PEM_WRITE_C)
mbedAustin 11:cada08fc8a70 545 /**
mbedAustin 11:cada08fc8a70 546 * \brief Write a public key to a PEM string
mbedAustin 11:cada08fc8a70 547 *
mbedAustin 11:cada08fc8a70 548 * \param ctx public key to write away
mbedAustin 11:cada08fc8a70 549 * \param buf buffer to write to
mbedAustin 11:cada08fc8a70 550 * \param size size of the buffer
mbedAustin 11:cada08fc8a70 551 *
mbedAustin 11:cada08fc8a70 552 * \return 0 if successful, or a specific error code
mbedAustin 11:cada08fc8a70 553 */
mbedAustin 11:cada08fc8a70 554 int mbedtls_pk_write_pubkey_pem( mbedtls_pk_context *ctx, unsigned char *buf, size_t size );
mbedAustin 11:cada08fc8a70 555
mbedAustin 11:cada08fc8a70 556 /**
mbedAustin 11:cada08fc8a70 557 * \brief Write a private key to a PKCS#1 or SEC1 PEM string
mbedAustin 11:cada08fc8a70 558 *
mbedAustin 11:cada08fc8a70 559 * \param ctx private to write away
mbedAustin 11:cada08fc8a70 560 * \param buf buffer to write to
mbedAustin 11:cada08fc8a70 561 * \param size size of the buffer
mbedAustin 11:cada08fc8a70 562 *
mbedAustin 11:cada08fc8a70 563 * \return 0 if successful, or a specific error code
mbedAustin 11:cada08fc8a70 564 */
mbedAustin 11:cada08fc8a70 565 int mbedtls_pk_write_key_pem( mbedtls_pk_context *ctx, unsigned char *buf, size_t size );
mbedAustin 11:cada08fc8a70 566 #endif /* MBEDTLS_PEM_WRITE_C */
mbedAustin 11:cada08fc8a70 567 #endif /* MBEDTLS_PK_WRITE_C */
mbedAustin 11:cada08fc8a70 568
mbedAustin 11:cada08fc8a70 569 /*
mbedAustin 11:cada08fc8a70 570 * WARNING: Low-level functions. You probably do not want to use these unless
mbedAustin 11:cada08fc8a70 571 * you are certain you do ;)
mbedAustin 11:cada08fc8a70 572 */
mbedAustin 11:cada08fc8a70 573
mbedAustin 11:cada08fc8a70 574 #if defined(MBEDTLS_PK_PARSE_C)
mbedAustin 11:cada08fc8a70 575 /**
mbedAustin 11:cada08fc8a70 576 * \brief Parse a SubjectPublicKeyInfo DER structure
mbedAustin 11:cada08fc8a70 577 *
mbedAustin 11:cada08fc8a70 578 * \param p the position in the ASN.1 data
mbedAustin 11:cada08fc8a70 579 * \param end end of the buffer
mbedAustin 11:cada08fc8a70 580 * \param pk the key to fill
mbedAustin 11:cada08fc8a70 581 *
mbedAustin 11:cada08fc8a70 582 * \return 0 if successful, or a specific PK error code
mbedAustin 11:cada08fc8a70 583 */
mbedAustin 11:cada08fc8a70 584 int mbedtls_pk_parse_subpubkey( unsigned char **p, const unsigned char *end,
mbedAustin 11:cada08fc8a70 585 mbedtls_pk_context *pk );
mbedAustin 11:cada08fc8a70 586 #endif /* MBEDTLS_PK_PARSE_C */
mbedAustin 11:cada08fc8a70 587
mbedAustin 11:cada08fc8a70 588 #if defined(MBEDTLS_PK_WRITE_C)
mbedAustin 11:cada08fc8a70 589 /**
mbedAustin 11:cada08fc8a70 590 * \brief Write a subjectPublicKey to ASN.1 data
mbedAustin 11:cada08fc8a70 591 * Note: function works backwards in data buffer
mbedAustin 11:cada08fc8a70 592 *
mbedAustin 11:cada08fc8a70 593 * \param p reference to current position pointer
mbedAustin 11:cada08fc8a70 594 * \param start start of the buffer (for bounds-checking)
mbedAustin 11:cada08fc8a70 595 * \param key public key to write away
mbedAustin 11:cada08fc8a70 596 *
mbedAustin 11:cada08fc8a70 597 * \return the length written or a negative error code
mbedAustin 11:cada08fc8a70 598 */
mbedAustin 11:cada08fc8a70 599 int mbedtls_pk_write_pubkey( unsigned char **p, unsigned char *start,
mbedAustin 11:cada08fc8a70 600 const mbedtls_pk_context *key );
mbedAustin 11:cada08fc8a70 601 #endif /* MBEDTLS_PK_WRITE_C */
mbedAustin 11:cada08fc8a70 602
mbedAustin 11:cada08fc8a70 603 /*
mbedAustin 11:cada08fc8a70 604 * Internal module functions. You probably do not want to use these unless you
mbedAustin 11:cada08fc8a70 605 * know you do.
mbedAustin 11:cada08fc8a70 606 */
mbedAustin 11:cada08fc8a70 607 #if defined(MBEDTLS_FS_IO)
mbedAustin 11:cada08fc8a70 608 int mbedtls_pk_load_file( const char *path, unsigned char **buf, size_t *n );
mbedAustin 11:cada08fc8a70 609 #endif
mbedAustin 11:cada08fc8a70 610
mbedAustin 11:cada08fc8a70 611 #ifdef __cplusplus
mbedAustin 11:cada08fc8a70 612 }
mbedAustin 11:cada08fc8a70 613 #endif
mbedAustin 11:cada08fc8a70 614
mbedAustin 11:cada08fc8a70 615 #endif /* MBEDTLS_PK_H */