Manuel Pégourié-Gonnard | 12e0ed9 | 2013-07-04 13:31:32 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Public Key abstraction layer |
| 3 | * |
| 4 | * Copyright (C) 2006-2013, Brainspark B.V. |
| 5 | * |
| 6 | * This file is part of PolarSSL (http://www.polarssl.org) |
| 7 | * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org> |
| 8 | * |
| 9 | * All rights reserved. |
| 10 | * |
| 11 | * This program is free software; you can redistribute it and/or modify |
| 12 | * it under the terms of the GNU General Public License as published by |
| 13 | * the Free Software Foundation; either version 2 of the License, or |
| 14 | * (at your option) any later version. |
| 15 | * |
| 16 | * This program is distributed in the hope that it will be useful, |
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | * GNU General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU General Public License along |
| 22 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 23 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 24 | */ |
| 25 | |
Manuel Pégourié-Gonnard | cef4ad2 | 2014-04-29 12:39:06 +0200 | [diff] [blame] | 26 | #if !defined(POLARSSL_CONFIG_FILE) |
Manuel Pégourié-Gonnard | 12e0ed9 | 2013-07-04 13:31:32 +0200 | [diff] [blame] | 27 | #include "polarssl/config.h" |
Manuel Pégourié-Gonnard | cef4ad2 | 2014-04-29 12:39:06 +0200 | [diff] [blame] | 28 | #else |
| 29 | #include POLARSSL_CONFIG_FILE |
| 30 | #endif |
Manuel Pégourié-Gonnard | 12e0ed9 | 2013-07-04 13:31:32 +0200 | [diff] [blame] | 31 | |
Manuel Pégourié-Gonnard | c40b4c3 | 2013-08-22 13:29:31 +0200 | [diff] [blame] | 32 | #if defined(POLARSSL_PK_C) |
| 33 | |
Manuel Pégourié-Gonnard | 12e0ed9 | 2013-07-04 13:31:32 +0200 | [diff] [blame] | 34 | #include "polarssl/pk.h" |
Manuel Pégourié-Gonnard | d73b3c1 | 2013-08-12 17:06:05 +0200 | [diff] [blame] | 35 | #include "polarssl/pk_wrap.h" |
Manuel Pégourié-Gonnard | 12e0ed9 | 2013-07-04 13:31:32 +0200 | [diff] [blame] | 36 | |
Manuel Pégourié-Gonnard | 81c313c | 2013-07-09 10:35:54 +0200 | [diff] [blame] | 37 | #if defined(POLARSSL_RSA_C) |
| 38 | #include "polarssl/rsa.h" |
| 39 | #endif |
| 40 | #if defined(POLARSSL_ECP_C) |
| 41 | #include "polarssl/ecp.h" |
| 42 | #endif |
Manuel Pégourié-Gonnard | 7c5819e | 2013-07-10 12:29:57 +0200 | [diff] [blame] | 43 | #if defined(POLARSSL_ECDSA_C) |
| 44 | #include "polarssl/ecdsa.h" |
| 45 | #endif |
Manuel Pégourié-Gonnard | 81c313c | 2013-07-09 10:35:54 +0200 | [diff] [blame] | 46 | |
Manuel Pégourié-Gonnard | 12e0ed9 | 2013-07-04 13:31:32 +0200 | [diff] [blame] | 47 | /* |
| 48 | * Initialise a pk_context |
| 49 | */ |
| 50 | void pk_init( pk_context *ctx ) |
| 51 | { |
| 52 | if( ctx == NULL ) |
| 53 | return; |
| 54 | |
Manuel Pégourié-Gonnard | 3fb5c5e | 2013-08-14 18:26:41 +0200 | [diff] [blame] | 55 | ctx->pk_info = NULL; |
| 56 | ctx->pk_ctx = NULL; |
Manuel Pégourié-Gonnard | 12e0ed9 | 2013-07-04 13:31:32 +0200 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | /* |
| 60 | * Free (the components of) a pk_context |
| 61 | */ |
| 62 | void pk_free( pk_context *ctx ) |
| 63 | { |
Manuel Pégourié-Gonnard | 3fb5c5e | 2013-08-14 18:26:41 +0200 | [diff] [blame] | 64 | if( ctx == NULL || ctx->pk_info == NULL) |
Manuel Pégourié-Gonnard | 12e0ed9 | 2013-07-04 13:31:32 +0200 | [diff] [blame] | 65 | return; |
| 66 | |
Manuel Pégourié-Gonnard | 3fb5c5e | 2013-08-14 18:26:41 +0200 | [diff] [blame] | 67 | ctx->pk_info->ctx_free_func( ctx->pk_ctx ); |
| 68 | ctx->pk_ctx = NULL; |
Manuel Pégourié-Gonnard | 1f73a65 | 2013-07-09 10:26:41 +0200 | [diff] [blame] | 69 | |
Manuel Pégourié-Gonnard | 3fb5c5e | 2013-08-14 18:26:41 +0200 | [diff] [blame] | 70 | ctx->pk_info = NULL; |
Manuel Pégourié-Gonnard | 765db07 | 2013-08-14 15:00:27 +0200 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | /* |
| 74 | * Get pk_info structure from type |
| 75 | */ |
Manuel Pégourié-Gonnard | ab46694 | 2013-08-15 11:30:27 +0200 | [diff] [blame] | 76 | const pk_info_t * pk_info_from_type( pk_type_t pk_type ) |
Manuel Pégourié-Gonnard | 765db07 | 2013-08-14 15:00:27 +0200 | [diff] [blame] | 77 | { |
| 78 | switch( pk_type ) { |
| 79 | #if defined(POLARSSL_RSA_C) |
| 80 | case POLARSSL_PK_RSA: |
| 81 | return &rsa_info; |
| 82 | #endif |
| 83 | #if defined(POLARSSL_ECP_C) |
| 84 | case POLARSSL_PK_ECKEY: |
| 85 | return &eckey_info; |
| 86 | case POLARSSL_PK_ECKEY_DH: |
| 87 | return &eckeydh_info; |
| 88 | #endif |
| 89 | #if defined(POLARSSL_ECDSA_C) |
| 90 | case POLARSSL_PK_ECDSA: |
| 91 | return &ecdsa_info; |
| 92 | #endif |
Paul Bakker | 75342a6 | 2014-04-08 17:35:40 +0200 | [diff] [blame] | 93 | /* POLARSSL_PK_RSA_ALT omitted on purpose */ |
Manuel Pégourié-Gonnard | 765db07 | 2013-08-14 15:00:27 +0200 | [diff] [blame] | 94 | default: |
| 95 | return NULL; |
| 96 | } |
Manuel Pégourié-Gonnard | 12e0ed9 | 2013-07-04 13:31:32 +0200 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | /* |
Manuel Pégourié-Gonnard | ab46694 | 2013-08-15 11:30:27 +0200 | [diff] [blame] | 100 | * Initialise context |
Manuel Pégourié-Gonnard | 12e0ed9 | 2013-07-04 13:31:32 +0200 | [diff] [blame] | 101 | */ |
Manuel Pégourié-Gonnard | ab46694 | 2013-08-15 11:30:27 +0200 | [diff] [blame] | 102 | int pk_init_ctx( pk_context *ctx, const pk_info_t *info ) |
Manuel Pégourié-Gonnard | 12e0ed9 | 2013-07-04 13:31:32 +0200 | [diff] [blame] | 103 | { |
Manuel Pégourié-Gonnard | ab46694 | 2013-08-15 11:30:27 +0200 | [diff] [blame] | 104 | if( ctx == NULL || info == NULL || ctx->pk_info != NULL ) |
Manuel Pégourié-Gonnard | 1569938 | 2013-08-14 19:22:48 +0200 | [diff] [blame] | 105 | return( POLARSSL_ERR_PK_BAD_INPUT_DATA ); |
Manuel Pégourié-Gonnard | 12e0ed9 | 2013-07-04 13:31:32 +0200 | [diff] [blame] | 106 | |
Manuel Pégourié-Gonnard | 3fb5c5e | 2013-08-14 18:26:41 +0200 | [diff] [blame] | 107 | if( ( ctx->pk_ctx = info->ctx_alloc_func() ) == NULL ) |
Manuel Pégourié-Gonnard | 7a6c946 | 2013-07-09 10:04:07 +0200 | [diff] [blame] | 108 | return( POLARSSL_ERR_PK_MALLOC_FAILED ); |
Manuel Pégourié-Gonnard | 12e0ed9 | 2013-07-04 13:31:32 +0200 | [diff] [blame] | 109 | |
Manuel Pégourié-Gonnard | 3fb5c5e | 2013-08-14 18:26:41 +0200 | [diff] [blame] | 110 | ctx->pk_info = info; |
Manuel Pégourié-Gonnard | 12e0ed9 | 2013-07-04 13:31:32 +0200 | [diff] [blame] | 111 | |
| 112 | return( 0 ); |
| 113 | } |
Manuel Pégourié-Gonnard | b3d9187 | 2013-08-14 15:56:19 +0200 | [diff] [blame] | 114 | |
Manuel Pégourié-Gonnard | b4fae57 | 2014-01-20 11:22:25 +0100 | [diff] [blame] | 115 | /* |
Manuel Pégourié-Gonnard | 12c1ff0 | 2013-08-21 12:28:31 +0200 | [diff] [blame] | 116 | * Initialize an RSA-alt context |
| 117 | */ |
| 118 | int pk_init_ctx_rsa_alt( pk_context *ctx, void * key, |
| 119 | pk_rsa_alt_decrypt_func decrypt_func, |
| 120 | pk_rsa_alt_sign_func sign_func, |
| 121 | pk_rsa_alt_key_len_func key_len_func ) |
| 122 | { |
| 123 | rsa_alt_context *rsa_alt; |
| 124 | const pk_info_t *info = &rsa_alt_info; |
| 125 | |
| 126 | if( ctx == NULL || ctx->pk_info != NULL ) |
| 127 | return( POLARSSL_ERR_PK_BAD_INPUT_DATA ); |
| 128 | |
| 129 | if( ( ctx->pk_ctx = info->ctx_alloc_func() ) == NULL ) |
| 130 | return( POLARSSL_ERR_PK_MALLOC_FAILED ); |
| 131 | |
| 132 | ctx->pk_info = info; |
| 133 | |
| 134 | rsa_alt = (rsa_alt_context *) ctx->pk_ctx; |
| 135 | |
| 136 | rsa_alt->key = key; |
| 137 | rsa_alt->decrypt_func = decrypt_func; |
| 138 | rsa_alt->sign_func = sign_func; |
| 139 | rsa_alt->key_len_func = key_len_func; |
| 140 | |
| 141 | return( 0 ); |
| 142 | } |
| 143 | |
| 144 | /* |
Manuel Pégourié-Gonnard | b3d9187 | 2013-08-14 15:56:19 +0200 | [diff] [blame] | 145 | * Tell if a PK can do the operations of the given type |
| 146 | */ |
| 147 | int pk_can_do( pk_context *ctx, pk_type_t type ) |
| 148 | { |
Manuel Pégourié-Gonnard | f73da02 | 2013-08-17 14:36:32 +0200 | [diff] [blame] | 149 | /* null or NONE context can't do anything */ |
Manuel Pégourié-Gonnard | 3fb5c5e | 2013-08-14 18:26:41 +0200 | [diff] [blame] | 150 | if( ctx == NULL || ctx->pk_info == NULL ) |
Manuel Pégourié-Gonnard | b3d9187 | 2013-08-14 15:56:19 +0200 | [diff] [blame] | 151 | return( 0 ); |
| 152 | |
Manuel Pégourié-Gonnard | 3fb5c5e | 2013-08-14 18:26:41 +0200 | [diff] [blame] | 153 | return( ctx->pk_info->can_do( type ) ); |
Manuel Pégourié-Gonnard | b3d9187 | 2013-08-14 15:56:19 +0200 | [diff] [blame] | 154 | } |
| 155 | |
| 156 | /* |
Manuel Pégourié-Gonnard | bfe32ef | 2013-08-22 14:55:30 +0200 | [diff] [blame] | 157 | * Helper for pk_sign and pk_verify |
| 158 | */ |
| 159 | static inline int pk_hashlen_helper( md_type_t md_alg, size_t *hash_len ) |
| 160 | { |
| 161 | const md_info_t *md_info; |
| 162 | |
| 163 | if( *hash_len != 0 ) |
| 164 | return( 0 ); |
| 165 | |
| 166 | if( ( md_info = md_info_from_type( md_alg ) ) == NULL ) |
| 167 | return( -1 ); |
| 168 | |
| 169 | *hash_len = md_info->size; |
| 170 | return( 0 ); |
| 171 | } |
| 172 | |
| 173 | /* |
Manuel Pégourié-Gonnard | b3d9187 | 2013-08-14 15:56:19 +0200 | [diff] [blame] | 174 | * Verify a signature |
| 175 | */ |
Manuel Pégourié-Gonnard | f73da02 | 2013-08-17 14:36:32 +0200 | [diff] [blame] | 176 | int pk_verify( pk_context *ctx, md_type_t md_alg, |
| 177 | const unsigned char *hash, size_t hash_len, |
Manuel Pégourié-Gonnard | b3d9187 | 2013-08-14 15:56:19 +0200 | [diff] [blame] | 178 | const unsigned char *sig, size_t sig_len ) |
| 179 | { |
Manuel Pégourié-Gonnard | bfe32ef | 2013-08-22 14:55:30 +0200 | [diff] [blame] | 180 | if( ctx == NULL || ctx->pk_info == NULL || |
| 181 | pk_hashlen_helper( md_alg, &hash_len ) != 0 ) |
Manuel Pégourié-Gonnard | 1569938 | 2013-08-14 19:22:48 +0200 | [diff] [blame] | 182 | return( POLARSSL_ERR_PK_BAD_INPUT_DATA ); |
Manuel Pégourié-Gonnard | b3d9187 | 2013-08-14 15:56:19 +0200 | [diff] [blame] | 183 | |
Manuel Pégourié-Gonnard | fff80f8 | 2013-08-17 15:20:06 +0200 | [diff] [blame] | 184 | if( ctx->pk_info->verify_func == NULL ) |
| 185 | return( POLARSSL_ERR_PK_TYPE_MISMATCH ); |
| 186 | |
Manuel Pégourié-Gonnard | 8df2769 | 2013-08-21 10:34:38 +0200 | [diff] [blame] | 187 | return( ctx->pk_info->verify_func( ctx->pk_ctx, md_alg, hash, hash_len, |
Manuel Pégourié-Gonnard | f73da02 | 2013-08-17 14:36:32 +0200 | [diff] [blame] | 188 | sig, sig_len ) ); |
Manuel Pégourié-Gonnard | b3d9187 | 2013-08-14 15:56:19 +0200 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | /* |
Manuel Pégourié-Gonnard | 20422e9 | 2014-06-05 13:41:44 +0200 | [diff] [blame] | 192 | * Verify a signature with options |
| 193 | */ |
| 194 | int pk_verify_ext( pk_type_t type, const void *options, |
| 195 | pk_context *ctx, md_type_t md_alg, |
| 196 | const unsigned char *hash, size_t hash_len, |
| 197 | const unsigned char *sig, size_t sig_len ) |
| 198 | { |
| 199 | if( ctx == NULL || ctx->pk_info == NULL ) |
| 200 | return( POLARSSL_ERR_PK_BAD_INPUT_DATA ); |
| 201 | |
| 202 | if( ! pk_can_do( ctx, type ) ) |
| 203 | return( POLARSSL_ERR_PK_TYPE_MISMATCH ); |
| 204 | |
| 205 | if( type == POLARSSL_PK_RSASSA_PSS ) |
| 206 | { |
| 207 | #if defined(POLARSSL_RSA_C) && defined(POLARSSL_PKCS1_V21) |
| 208 | int ret; |
| 209 | const pk_rsassa_pss_options *pss_opts; |
| 210 | |
| 211 | if( options == NULL ) |
| 212 | return( POLARSSL_ERR_PK_BAD_INPUT_DATA ); |
| 213 | |
| 214 | pss_opts = (const pk_rsassa_pss_options *) options; |
| 215 | |
| 216 | if( sig_len < pk_get_len( ctx ) ) |
| 217 | return( POLARSSL_ERR_RSA_VERIFY_FAILED ); |
| 218 | |
| 219 | ret = rsa_rsassa_pss_verify_ext( pk_rsa( *ctx ), |
| 220 | NULL, NULL, RSA_PUBLIC, |
| 221 | md_alg, hash_len, hash, |
| 222 | pss_opts->mgf1_hash_id, |
| 223 | pss_opts->expected_salt_len, |
| 224 | sig ); |
| 225 | if( ret != 0 ) |
| 226 | return( ret ); |
| 227 | |
| 228 | if( sig_len > pk_get_len( ctx ) ) |
| 229 | return( POLARSSL_ERR_PK_SIG_LEN_MISMATCH ); |
| 230 | |
| 231 | return( 0 ); |
| 232 | #else |
| 233 | return( POLARSSL_ERR_PK_FEATURE_UNAVAILABLE ); |
| 234 | #endif |
| 235 | } |
| 236 | |
| 237 | /* General case: no options */ |
| 238 | if( options != NULL ) |
| 239 | return( POLARSSL_ERR_PK_BAD_INPUT_DATA ); |
| 240 | |
| 241 | return( pk_verify( ctx, md_alg, hash, hash_len, sig, sig_len ) ); |
| 242 | } |
| 243 | |
| 244 | /* |
Manuel Pégourié-Gonnard | 8df2769 | 2013-08-21 10:34:38 +0200 | [diff] [blame] | 245 | * Make a signature |
| 246 | */ |
| 247 | int pk_sign( pk_context *ctx, md_type_t md_alg, |
| 248 | const unsigned char *hash, size_t hash_len, |
| 249 | unsigned char *sig, size_t *sig_len, |
| 250 | int (*f_rng)(void *, unsigned char *, size_t), void *p_rng ) |
| 251 | { |
Manuel Pégourié-Gonnard | bfe32ef | 2013-08-22 14:55:30 +0200 | [diff] [blame] | 252 | if( ctx == NULL || ctx->pk_info == NULL || |
| 253 | pk_hashlen_helper( md_alg, &hash_len ) != 0 ) |
Manuel Pégourié-Gonnard | 8df2769 | 2013-08-21 10:34:38 +0200 | [diff] [blame] | 254 | return( POLARSSL_ERR_PK_BAD_INPUT_DATA ); |
| 255 | |
| 256 | if( ctx->pk_info->sign_func == NULL ) |
| 257 | return( POLARSSL_ERR_PK_TYPE_MISMATCH ); |
| 258 | |
| 259 | return( ctx->pk_info->sign_func( ctx->pk_ctx, md_alg, hash, hash_len, |
| 260 | sig, sig_len, f_rng, p_rng ) ); |
| 261 | } |
| 262 | |
| 263 | /* |
Manuel Pégourié-Gonnard | a2d3f22 | 2013-08-21 11:51:08 +0200 | [diff] [blame] | 264 | * Decrypt message |
| 265 | */ |
| 266 | int pk_decrypt( pk_context *ctx, |
| 267 | const unsigned char *input, size_t ilen, |
| 268 | unsigned char *output, size_t *olen, size_t osize, |
| 269 | int (*f_rng)(void *, unsigned char *, size_t), void *p_rng ) |
| 270 | { |
| 271 | if( ctx == NULL || ctx->pk_info == NULL ) |
| 272 | return( POLARSSL_ERR_PK_BAD_INPUT_DATA ); |
| 273 | |
| 274 | if( ctx->pk_info->decrypt_func == NULL ) |
| 275 | return( POLARSSL_ERR_PK_TYPE_MISMATCH ); |
| 276 | |
| 277 | return( ctx->pk_info->decrypt_func( ctx->pk_ctx, input, ilen, |
| 278 | output, olen, osize, f_rng, p_rng ) ); |
| 279 | } |
| 280 | |
| 281 | /* |
| 282 | * Encrypt message |
| 283 | */ |
| 284 | int pk_encrypt( pk_context *ctx, |
| 285 | const unsigned char *input, size_t ilen, |
| 286 | unsigned char *output, size_t *olen, size_t osize, |
| 287 | int (*f_rng)(void *, unsigned char *, size_t), void *p_rng ) |
| 288 | { |
| 289 | if( ctx == NULL || ctx->pk_info == NULL ) |
| 290 | return( POLARSSL_ERR_PK_BAD_INPUT_DATA ); |
| 291 | |
| 292 | if( ctx->pk_info->encrypt_func == NULL ) |
| 293 | return( POLARSSL_ERR_PK_TYPE_MISMATCH ); |
| 294 | |
| 295 | return( ctx->pk_info->encrypt_func( ctx->pk_ctx, input, ilen, |
| 296 | output, olen, osize, f_rng, p_rng ) ); |
| 297 | } |
| 298 | |
| 299 | /* |
Manuel Pégourié-Gonnard | b3d9187 | 2013-08-14 15:56:19 +0200 | [diff] [blame] | 300 | * Get key size in bits |
| 301 | */ |
| 302 | size_t pk_get_size( const pk_context *ctx ) |
| 303 | { |
Manuel Pégourié-Gonnard | 3fb5c5e | 2013-08-14 18:26:41 +0200 | [diff] [blame] | 304 | if( ctx == NULL || ctx->pk_info == NULL ) |
Manuel Pégourié-Gonnard | b3d9187 | 2013-08-14 15:56:19 +0200 | [diff] [blame] | 305 | return( 0 ); |
| 306 | |
Manuel Pégourié-Gonnard | 3fb5c5e | 2013-08-14 18:26:41 +0200 | [diff] [blame] | 307 | return( ctx->pk_info->get_size( ctx->pk_ctx ) ); |
Manuel Pégourié-Gonnard | b3d9187 | 2013-08-14 15:56:19 +0200 | [diff] [blame] | 308 | } |
Manuel Pégourié-Gonnard | c6ac887 | 2013-08-14 18:04:18 +0200 | [diff] [blame] | 309 | |
| 310 | /* |
| 311 | * Export debug information |
| 312 | */ |
| 313 | int pk_debug( const pk_context *ctx, pk_debug_item *items ) |
| 314 | { |
Manuel Pégourié-Gonnard | 3fb5c5e | 2013-08-14 18:26:41 +0200 | [diff] [blame] | 315 | if( ctx == NULL || ctx->pk_info == NULL ) |
Manuel Pégourié-Gonnard | 1569938 | 2013-08-14 19:22:48 +0200 | [diff] [blame] | 316 | return( POLARSSL_ERR_PK_BAD_INPUT_DATA ); |
Manuel Pégourié-Gonnard | c6ac887 | 2013-08-14 18:04:18 +0200 | [diff] [blame] | 317 | |
Manuel Pégourié-Gonnard | 0148875 | 2014-04-03 22:09:18 +0200 | [diff] [blame] | 318 | if( ctx->pk_info->debug_func == NULL ) |
| 319 | return( POLARSSL_ERR_PK_TYPE_MISMATCH ); |
| 320 | |
Manuel Pégourié-Gonnard | 3fb5c5e | 2013-08-14 18:26:41 +0200 | [diff] [blame] | 321 | ctx->pk_info->debug_func( ctx->pk_ctx, items ); |
Manuel Pégourié-Gonnard | c6ac887 | 2013-08-14 18:04:18 +0200 | [diff] [blame] | 322 | return( 0 ); |
| 323 | } |
Manuel Pégourié-Gonnard | 3fb5c5e | 2013-08-14 18:26:41 +0200 | [diff] [blame] | 324 | |
| 325 | /* |
| 326 | * Access the PK type name |
| 327 | */ |
| 328 | const char * pk_get_name( const pk_context *ctx ) |
| 329 | { |
| 330 | if( ctx == NULL || ctx->pk_info == NULL ) |
| 331 | return( "invalid PK" ); |
| 332 | |
| 333 | return( ctx->pk_info->name ); |
| 334 | } |
Manuel Pégourié-Gonnard | c40b4c3 | 2013-08-22 13:29:31 +0200 | [diff] [blame] | 335 | |
Manuel Pégourié-Gonnard | 8053da4 | 2013-09-11 22:28:30 +0200 | [diff] [blame] | 336 | /* |
| 337 | * Access the PK type |
| 338 | */ |
| 339 | pk_type_t pk_get_type( const pk_context *ctx ) |
| 340 | { |
| 341 | if( ctx == NULL || ctx->pk_info == NULL ) |
| 342 | return( POLARSSL_PK_NONE ); |
| 343 | |
| 344 | return( ctx->pk_info->type ); |
| 345 | } |
| 346 | |
Manuel Pégourié-Gonnard | c40b4c3 | 2013-08-22 13:29:31 +0200 | [diff] [blame] | 347 | #endif /* POLARSSL_PK_C */ |