blob: 1cd05943bac0c8b93ad4c3c87e7d78324246106a [file] [log] [blame]
Manuel Pégourié-Gonnardd73b3c12013-08-12 17:06:05 +02001/**
Darryl Greena40a1012018-01-05 15:33:17 +00002 * \file pk_internal.h
Manuel Pégourié-Gonnardd73b3c12013-08-12 17:06:05 +02003 *
4 * \brief Public Key abstraction layer: wrapper functions
Darryl Greena40a1012018-01-05 15:33:17 +00005 */
6/*
Manuel Pégourié-Gonnard6fb81872015-07-27 11:11:48 +02007 * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
Bence Szépkútif744bd72020-06-05 13:02:18 +02008 * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
9 *
10 * This file is provided under the Apache License 2.0, or the
11 * GNU General Public License v2.0 or later.
12 *
13 * **********
14 * Apache License 2.0:
Manuel Pégourié-Gonnard37ff1402015-09-04 14:21:07 +020015 *
16 * Licensed under the Apache License, Version 2.0 (the "License"); you may
17 * not use this file except in compliance with the License.
18 * You may obtain a copy of the License at
19 *
20 * http://www.apache.org/licenses/LICENSE-2.0
21 *
22 * Unless required by applicable law or agreed to in writing, software
23 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
24 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25 * See the License for the specific language governing permissions and
26 * limitations under the License.
Manuel Pégourié-Gonnardd73b3c12013-08-12 17:06:05 +020027 *
Bence Szépkútif744bd72020-06-05 13:02:18 +020028 * **********
29 *
30 * **********
31 * GNU General Public License v2.0 or later:
32 *
33 * This program is free software; you can redistribute it and/or modify
34 * it under the terms of the GNU General Public License as published by
35 * the Free Software Foundation; either version 2 of the License, or
36 * (at your option) any later version.
37 *
38 * This program is distributed in the hope that it will be useful,
39 * but WITHOUT ANY WARRANTY; without even the implied warranty of
40 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
41 * GNU General Public License for more details.
42 *
43 * You should have received a copy of the GNU General Public License along
44 * with this program; if not, write to the Free Software Foundation, Inc.,
45 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
46 *
47 * **********
48 *
Manuel Pégourié-Gonnardfe446432015-03-06 13:17:10 +000049 * This file is part of mbed TLS (https://tls.mbed.org)
Manuel Pégourié-Gonnardd73b3c12013-08-12 17:06:05 +020050 */
51
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020052#ifndef MBEDTLS_PK_WRAP_H
53#define MBEDTLS_PK_WRAP_H
Manuel Pégourié-Gonnardd73b3c12013-08-12 17:06:05 +020054
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020055#if !defined(MBEDTLS_CONFIG_FILE)
Manuel Pégourié-Gonnardd73b3c12013-08-12 17:06:05 +020056#include "config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020057#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020058#include MBEDTLS_CONFIG_FILE
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020059#endif
Manuel Pégourié-Gonnardd73b3c12013-08-12 17:06:05 +020060
61#include "pk.h"
62
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020063struct mbedtls_pk_info_t
Manuel Pégourié-Gonnardc89d6cf2015-03-31 14:43:19 +020064{
65 /** Public key type */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020066 mbedtls_pk_type_t type;
Manuel Pégourié-Gonnardc89d6cf2015-03-31 14:43:19 +020067
68 /** Type name */
69 const char *name;
70
71 /** Get key size in bits */
Manuel Pégourié-Gonnard39a48f42015-06-18 16:06:55 +020072 size_t (*get_bitlen)( const void * );
Manuel Pégourié-Gonnardc89d6cf2015-03-31 14:43:19 +020073
74 /** Tell if the context implements this type (e.g. ECKEY can do ECDSA) */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020075 int (*can_do)( mbedtls_pk_type_t type );
Manuel Pégourié-Gonnardc89d6cf2015-03-31 14:43:19 +020076
77 /** Verify signature */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020078 int (*verify_func)( void *ctx, mbedtls_md_type_t md_alg,
Manuel Pégourié-Gonnardc89d6cf2015-03-31 14:43:19 +020079 const unsigned char *hash, size_t hash_len,
80 const unsigned char *sig, size_t sig_len );
81
82 /** Make signature */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020083 int (*sign_func)( void *ctx, mbedtls_md_type_t md_alg,
Manuel Pégourié-Gonnardc89d6cf2015-03-31 14:43:19 +020084 const unsigned char *hash, size_t hash_len,
85 unsigned char *sig, size_t *sig_len,
86 int (*f_rng)(void *, unsigned char *, size_t),
87 void *p_rng );
88
Manuel Pégourié-Gonnardaaa98142017-08-18 17:30:37 +020089#if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
Manuel Pégourié-Gonnard1f596062017-05-09 10:42:40 +020090 /** Verify signature (restartable) */
91 int (*verify_rs_func)( void *ctx, mbedtls_md_type_t md_alg,
92 const unsigned char *hash, size_t hash_len,
93 const unsigned char *sig, size_t sig_len,
94 void *rs_ctx );
95
96 /** Make signature (restartable) */
97 int (*sign_rs_func)( void *ctx, mbedtls_md_type_t md_alg,
98 const unsigned char *hash, size_t hash_len,
99 unsigned char *sig, size_t *sig_len,
100 int (*f_rng)(void *, unsigned char *, size_t),
101 void *p_rng, void *rs_ctx );
Manuel Pégourié-Gonnardaaa98142017-08-18 17:30:37 +0200102#endif /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */
Manuel Pégourié-Gonnard1f596062017-05-09 10:42:40 +0200103
Manuel Pégourié-Gonnardc89d6cf2015-03-31 14:43:19 +0200104 /** Decrypt message */
105 int (*decrypt_func)( void *ctx, const unsigned char *input, size_t ilen,
106 unsigned char *output, size_t *olen, size_t osize,
107 int (*f_rng)(void *, unsigned char *, size_t),
108 void *p_rng );
109
110 /** Encrypt message */
111 int (*encrypt_func)( void *ctx, const unsigned char *input, size_t ilen,
112 unsigned char *output, size_t *olen, size_t osize,
113 int (*f_rng)(void *, unsigned char *, size_t),
114 void *p_rng );
115
116 /** Check public-private key pair */
117 int (*check_pair_func)( const void *pub, const void *prv );
118
119 /** Allocate a new context */
120 void * (*ctx_alloc_func)( void );
121
122 /** Free the given context */
123 void (*ctx_free_func)( void *ctx );
124
Manuel Pégourié-Gonnardaaa98142017-08-18 17:30:37 +0200125#if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
Manuel Pégourié-Gonnard0bbc66c2017-08-18 16:22:06 +0200126 /** Allocate the restart context */
127 void * (*rs_alloc_func)( void );
128
129 /** Free the restart context */
130 void (*rs_free_func)( void *rs_ctx );
Manuel Pégourié-Gonnardaaa98142017-08-18 17:30:37 +0200131#endif /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */
Manuel Pégourié-Gonnard0bbc66c2017-08-18 16:22:06 +0200132
Manuel Pégourié-Gonnardc89d6cf2015-03-31 14:43:19 +0200133 /** Interface with the debug module */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200134 void (*debug_func)( const void *ctx, mbedtls_pk_debug_item *items );
Manuel Pégourié-Gonnardc89d6cf2015-03-31 14:43:19 +0200135
136};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200137#if defined(MBEDTLS_PK_RSA_ALT_SUPPORT)
Manuel Pégourié-Gonnard12c1ff02013-08-21 12:28:31 +0200138/* Container for RSA-alt */
139typedef struct
140{
141 void *key;
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200142 mbedtls_pk_rsa_alt_decrypt_func decrypt_func;
143 mbedtls_pk_rsa_alt_sign_func sign_func;
144 mbedtls_pk_rsa_alt_key_len_func key_len_func;
145} mbedtls_rsa_alt_context;
Manuel Pégourié-Gonnard348bcb32015-03-31 14:01:33 +0200146#endif
Manuel Pégourié-Gonnard12c1ff02013-08-21 12:28:31 +0200147
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200148#if defined(MBEDTLS_RSA_C)
149extern const mbedtls_pk_info_t mbedtls_rsa_info;
Manuel Pégourié-Gonnardd73b3c12013-08-12 17:06:05 +0200150#endif
151
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200152#if defined(MBEDTLS_ECP_C)
153extern const mbedtls_pk_info_t mbedtls_eckey_info;
154extern const mbedtls_pk_info_t mbedtls_eckeydh_info;
Manuel Pégourié-Gonnardd73b3c12013-08-12 17:06:05 +0200155#endif
156
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200157#if defined(MBEDTLS_ECDSA_C)
158extern const mbedtls_pk_info_t mbedtls_ecdsa_info;
Manuel Pégourié-Gonnardd73b3c12013-08-12 17:06:05 +0200159#endif
160
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200161#if defined(MBEDTLS_PK_RSA_ALT_SUPPORT)
162extern const mbedtls_pk_info_t mbedtls_rsa_alt_info;
Manuel Pégourié-Gonnard348bcb32015-03-31 14:01:33 +0200163#endif
Manuel Pégourié-Gonnard12c1ff02013-08-21 12:28:31 +0200164
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200165#endif /* MBEDTLS_PK_WRAP_H */