blob: 7eb4f72b36d7f4e76c95c1f792a2e4a55ea5d479 [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
25#ifndef POLARSSL_PK_WRAP_H
26#define POLARSSL_PK_WRAP_H
27
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020028#if !defined(POLARSSL_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
31#include POLARSSL_CONFIG_FILE
32#endif
Manuel Pégourié-Gonnardd73b3c12013-08-12 17:06:05 +020033
34#include "pk.h"
35
Manuel Pégourié-Gonnardc89d6cf2015-03-31 14:43:19 +020036struct _pk_info_t
37{
38 /** Public key type */
39 pk_type_t type;
40
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) */
48 int (*can_do)( pk_type_t type );
49
50 /** Verify signature */
51 int (*verify_func)( void *ctx, md_type_t md_alg,
52 const unsigned char *hash, size_t hash_len,
53 const unsigned char *sig, size_t sig_len );
54
55 /** Make signature */
56 int (*sign_func)( void *ctx, md_type_t md_alg,
57 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 */
84 void (*debug_func)( const void *ctx, pk_debug_item *items );
85
86};
Manuel Pégourié-Gonnard348bcb32015-03-31 14:01:33 +020087#if defined(POLARSSL_PK_RSA_ALT_SUPPORT)
Manuel Pégourié-Gonnard12c1ff02013-08-21 12:28:31 +020088/* Container for RSA-alt */
89typedef struct
90{
91 void *key;
92 pk_rsa_alt_decrypt_func decrypt_func;
93 pk_rsa_alt_sign_func sign_func;
94 pk_rsa_alt_key_len_func key_len_func;
95} 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é-Gonnardd73b3c12013-08-12 17:06:05 +020098#if defined(POLARSSL_RSA_C)
99extern const pk_info_t rsa_info;
100#endif
101
102#if defined(POLARSSL_ECP_C)
103extern const pk_info_t eckey_info;
Manuel Pégourié-Gonnard835eb592013-08-12 18:51:26 +0200104extern const pk_info_t eckeydh_info;
Manuel Pégourié-Gonnardd73b3c12013-08-12 17:06:05 +0200105#endif
106
107#if defined(POLARSSL_ECDSA_C)
108extern const pk_info_t ecdsa_info;
109#endif
110
Manuel Pégourié-Gonnard348bcb32015-03-31 14:01:33 +0200111#if defined(POLARSSL_PK_RSA_ALT_SUPPORT)
Manuel Pégourié-Gonnard12c1ff02013-08-21 12:28:31 +0200112extern const pk_info_t 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é-Gonnardd73b3c12013-08-12 17:06:05 +0200115#endif /* POLARSSL_PK_WRAP_H */