blob: ce91984799373ba2d33472fd78038236befae28b [file] [log] [blame]
Manuel Pégourié-Gonnardd73b3c12013-08-12 17:06:05 +02001/**
2 * \file pk.h
3 *
4 * \brief Public Key abstraction layer: wrapper functions
5 *
Manuel Pégourié-Gonnarda658a402015-01-23 09:45:19 +00006 * Copyright (C) 2006-2013, ARM Limited, All Rights Reserved
Manuel Pégourié-Gonnardd73b3c12013-08-12 17:06:05 +02007 *
Manuel Pégourié-Gonnardfe446432015-03-06 13:17:10 +00008 * This file is part of mbed TLS (https://tls.mbed.org)
Manuel Pégourié-Gonnardd73b3c12013-08-12 17:06:05 +02009 *
Manuel Pégourié-Gonnardd73b3c12013-08-12 17:06:05 +020010 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 */
24
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020025#ifndef MBEDTLS_PK_WRAP_H
26#define MBEDTLS_PK_WRAP_H
Manuel Pégourié-Gonnardd73b3c12013-08-12 17:06:05 +020027
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020028#if !defined(MBEDTLS_CONFIG_FILE)
Manuel Pégourié-Gonnardd73b3c12013-08-12 17:06:05 +020029#include "config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020030#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020031#include MBEDTLS_CONFIG_FILE
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020032#endif
Manuel Pégourié-Gonnardd73b3c12013-08-12 17:06:05 +020033
34#include "pk.h"
35
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020036struct mbedtls_pk_info_t
Manuel Pégourié-Gonnardc89d6cf2015-03-31 14:43:19 +020037{
38 /** Public key type */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020039 mbedtls_pk_type_t type;
Manuel Pégourié-Gonnardc89d6cf2015-03-31 14:43:19 +020040
41 /** Type name */
42 const char *name;
43
44 /** Get key size in bits */
45 size_t (*get_size)( const void * );
46
47 /** Tell if the context implements this type (e.g. ECKEY can do ECDSA) */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020048 int (*can_do)( mbedtls_pk_type_t type );
Manuel Pégourié-Gonnardc89d6cf2015-03-31 14:43:19 +020049
50 /** Verify signature */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020051 int (*verify_func)( void *ctx, mbedtls_md_type_t md_alg,
Manuel Pégourié-Gonnardc89d6cf2015-03-31 14:43:19 +020052 const unsigned char *hash, size_t hash_len,
53 const unsigned char *sig, size_t sig_len );
54
55 /** Make signature */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020056 int (*sign_func)( void *ctx, mbedtls_md_type_t md_alg,
Manuel Pégourié-Gonnardc89d6cf2015-03-31 14:43:19 +020057 const unsigned char *hash, size_t hash_len,
58 unsigned char *sig, size_t *sig_len,
59 int (*f_rng)(void *, unsigned char *, size_t),
60 void *p_rng );
61
62 /** Decrypt message */
63 int (*decrypt_func)( void *ctx, const unsigned char *input, size_t ilen,
64 unsigned char *output, size_t *olen, size_t osize,
65 int (*f_rng)(void *, unsigned char *, size_t),
66 void *p_rng );
67
68 /** Encrypt message */
69 int (*encrypt_func)( void *ctx, const unsigned char *input, size_t ilen,
70 unsigned char *output, size_t *olen, size_t osize,
71 int (*f_rng)(void *, unsigned char *, size_t),
72 void *p_rng );
73
74 /** Check public-private key pair */
75 int (*check_pair_func)( const void *pub, const void *prv );
76
77 /** Allocate a new context */
78 void * (*ctx_alloc_func)( void );
79
80 /** Free the given context */
81 void (*ctx_free_func)( void *ctx );
82
83 /** Interface with the debug module */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020084 void (*debug_func)( const void *ctx, mbedtls_pk_debug_item *items );
Manuel Pégourié-Gonnardc89d6cf2015-03-31 14:43:19 +020085
86};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020087#if defined(MBEDTLS_PK_RSA_ALT_SUPPORT)
Manuel Pégourié-Gonnard12c1ff02013-08-21 12:28:31 +020088/* Container for RSA-alt */
89typedef struct
90{
91 void *key;
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020092 mbedtls_pk_rsa_alt_decrypt_func decrypt_func;
93 mbedtls_pk_rsa_alt_sign_func sign_func;
94 mbedtls_pk_rsa_alt_key_len_func key_len_func;
95} mbedtls_rsa_alt_context;
Manuel Pégourié-Gonnard348bcb32015-03-31 14:01:33 +020096#endif
Manuel Pégourié-Gonnard12c1ff02013-08-21 12:28:31 +020097
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020098#if defined(MBEDTLS_RSA_C)
99extern const mbedtls_pk_info_t mbedtls_rsa_info;
Manuel Pégourié-Gonnardd73b3c12013-08-12 17:06:05 +0200100#endif
101
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200102#if defined(MBEDTLS_ECP_C)
103extern const mbedtls_pk_info_t mbedtls_eckey_info;
104extern const mbedtls_pk_info_t mbedtls_eckeydh_info;
Manuel Pégourié-Gonnardd73b3c12013-08-12 17:06:05 +0200105#endif
106
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200107#if defined(MBEDTLS_ECDSA_C)
108extern const mbedtls_pk_info_t mbedtls_ecdsa_info;
Manuel Pégourié-Gonnardd73b3c12013-08-12 17:06:05 +0200109#endif
110
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200111#if defined(MBEDTLS_PK_RSA_ALT_SUPPORT)
112extern const mbedtls_pk_info_t mbedtls_rsa_alt_info;
Manuel Pégourié-Gonnard348bcb32015-03-31 14:01:33 +0200113#endif
Manuel Pégourié-Gonnard12c1ff02013-08-21 12:28:31 +0200114
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200115#endif /* MBEDTLS_PK_WRAP_H */