blob: 6f5addf75b75a51182cc4d949238dfee1b71ae1d [file] [log] [blame]
Manuel Pégourié-Gonnardd73b3c12013-08-12 17:06:05 +02001/**
Chris Jonesdaacb592021-03-09 17:03:29 +00002 * \file pk_wrap.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/*
Bence Szépkúti1e148272020-08-07 13:07:28 +02007 * Copyright The Mbed TLS Contributors
Manuel Pégourié-Gonnard37ff1402015-09-04 14:21:07 +02008 * SPDX-License-Identifier: Apache-2.0
9 *
10 * Licensed under the Apache License, Version 2.0 (the "License"); you may
11 * not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
13 *
14 * http://www.apache.org/licenses/LICENSE-2.0
15 *
16 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
18 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and
20 * limitations under the License.
Manuel Pégourié-Gonnardd73b3c12013-08-12 17:06:05 +020021 */
22
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020023#ifndef MBEDTLS_PK_WRAP_H
24#define MBEDTLS_PK_WRAP_H
Manuel Pégourié-Gonnardd73b3c12013-08-12 17:06:05 +020025
Bence Szépkútic662b362021-05-27 11:25:03 +020026#include "mbedtls/build_info.h"
Manuel Pégourié-Gonnardd73b3c12013-08-12 17:06:05 +020027
Jaeden Ameroc49fbbf2019-07-04 20:01:14 +010028#include "mbedtls/pk.h"
Manuel Pégourié-Gonnardd73b3c12013-08-12 17:06:05 +020029
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020030struct mbedtls_pk_info_t
Manuel Pégourié-Gonnardc89d6cf2015-03-31 14:43:19 +020031{
32 /** Public key type */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020033 mbedtls_pk_type_t type;
Manuel Pégourié-Gonnardc89d6cf2015-03-31 14:43:19 +020034
35 /** Type name */
36 const char *name;
37
38 /** Get key size in bits */
Manuel Pégourié-Gonnard39a48f42015-06-18 16:06:55 +020039 size_t (*get_bitlen)( const void * );
Manuel Pégourié-Gonnardc89d6cf2015-03-31 14:43:19 +020040
41 /** Tell if the context implements this type (e.g. ECKEY can do ECDSA) */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020042 int (*can_do)( mbedtls_pk_type_t type );
Manuel Pégourié-Gonnardc89d6cf2015-03-31 14:43:19 +020043
44 /** Verify signature */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020045 int (*verify_func)( void *ctx, mbedtls_md_type_t md_alg,
Manuel Pégourié-Gonnardc89d6cf2015-03-31 14:43:19 +020046 const unsigned char *hash, size_t hash_len,
47 const unsigned char *sig, size_t sig_len );
48
49 /** Make signature */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020050 int (*sign_func)( void *ctx, mbedtls_md_type_t md_alg,
Manuel Pégourié-Gonnardc89d6cf2015-03-31 14:43:19 +020051 const unsigned char *hash, size_t hash_len,
Gilles Peskinef00f1522021-06-22 00:09:00 +020052 unsigned char *sig, size_t sig_size, size_t *sig_len,
Manuel Pégourié-Gonnardc89d6cf2015-03-31 14:43:19 +020053 int (*f_rng)(void *, unsigned char *, size_t),
54 void *p_rng );
55
Manuel Pégourié-Gonnardaaa98142017-08-18 17:30:37 +020056#if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
Manuel Pégourié-Gonnard1f596062017-05-09 10:42:40 +020057 /** Verify signature (restartable) */
58 int (*verify_rs_func)( void *ctx, mbedtls_md_type_t md_alg,
59 const unsigned char *hash, size_t hash_len,
60 const unsigned char *sig, size_t sig_len,
61 void *rs_ctx );
62
63 /** Make signature (restartable) */
64 int (*sign_rs_func)( void *ctx, mbedtls_md_type_t md_alg,
65 const unsigned char *hash, size_t hash_len,
Gilles Peskinef00f1522021-06-22 00:09:00 +020066 unsigned char *sig, size_t sig_size, size_t *sig_len,
Manuel Pégourié-Gonnard1f596062017-05-09 10:42:40 +020067 int (*f_rng)(void *, unsigned char *, size_t),
68 void *p_rng, void *rs_ctx );
Manuel Pégourié-Gonnardaaa98142017-08-18 17:30:37 +020069#endif /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */
Manuel Pégourié-Gonnard1f596062017-05-09 10:42:40 +020070
Manuel Pégourié-Gonnardc89d6cf2015-03-31 14:43:19 +020071 /** Decrypt message */
72 int (*decrypt_func)( void *ctx, const unsigned char *input, size_t ilen,
73 unsigned char *output, size_t *olen, size_t osize,
74 int (*f_rng)(void *, unsigned char *, size_t),
75 void *p_rng );
76
77 /** Encrypt message */
78 int (*encrypt_func)( void *ctx, const unsigned char *input, size_t ilen,
79 unsigned char *output, size_t *olen, size_t osize,
80 int (*f_rng)(void *, unsigned char *, size_t),
81 void *p_rng );
82
83 /** Check public-private key pair */
Manuel Pégourié-Gonnard39be1412021-06-15 11:29:26 +020084 int (*check_pair_func)( const void *pub, const void *prv,
85 int (*f_rng)(void *, unsigned char *, size_t),
86 void *p_rng );
Manuel Pégourié-Gonnardc89d6cf2015-03-31 14:43:19 +020087
88 /** Allocate a new context */
89 void * (*ctx_alloc_func)( void );
90
91 /** Free the given context */
92 void (*ctx_free_func)( void *ctx );
93
Manuel Pégourié-Gonnardaaa98142017-08-18 17:30:37 +020094#if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
Manuel Pégourié-Gonnard0bbc66c2017-08-18 16:22:06 +020095 /** Allocate the restart context */
96 void * (*rs_alloc_func)( void );
97
98 /** Free the restart context */
99 void (*rs_free_func)( void *rs_ctx );
Manuel Pégourié-Gonnardaaa98142017-08-18 17:30:37 +0200100#endif /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */
Manuel Pégourié-Gonnard0bbc66c2017-08-18 16:22:06 +0200101
Manuel Pégourié-Gonnardc89d6cf2015-03-31 14:43:19 +0200102 /** Interface with the debug module */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200103 void (*debug_func)( const void *ctx, mbedtls_pk_debug_item *items );
Manuel Pégourié-Gonnardc89d6cf2015-03-31 14:43:19 +0200104
105};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200106#if defined(MBEDTLS_PK_RSA_ALT_SUPPORT)
Manuel Pégourié-Gonnard12c1ff02013-08-21 12:28:31 +0200107/* Container for RSA-alt */
108typedef struct
109{
110 void *key;
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200111 mbedtls_pk_rsa_alt_decrypt_func decrypt_func;
112 mbedtls_pk_rsa_alt_sign_func sign_func;
113 mbedtls_pk_rsa_alt_key_len_func key_len_func;
114} mbedtls_rsa_alt_context;
Manuel Pégourié-Gonnard348bcb32015-03-31 14:01:33 +0200115#endif
Manuel Pégourié-Gonnard12c1ff02013-08-21 12:28:31 +0200116
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200117#if defined(MBEDTLS_RSA_C)
118extern const mbedtls_pk_info_t mbedtls_rsa_info;
Manuel Pégourié-Gonnardd73b3c12013-08-12 17:06:05 +0200119#endif
120
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200121#if defined(MBEDTLS_ECP_C)
122extern const mbedtls_pk_info_t mbedtls_eckey_info;
123extern const mbedtls_pk_info_t mbedtls_eckeydh_info;
Manuel Pégourié-Gonnardd73b3c12013-08-12 17:06:05 +0200124#endif
125
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200126#if defined(MBEDTLS_ECDSA_C)
127extern const mbedtls_pk_info_t mbedtls_ecdsa_info;
Manuel Pégourié-Gonnardd73b3c12013-08-12 17:06:05 +0200128#endif
129
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200130#if defined(MBEDTLS_PK_RSA_ALT_SUPPORT)
131extern const mbedtls_pk_info_t mbedtls_rsa_alt_info;
Manuel Pégourié-Gonnard348bcb32015-03-31 14:01:33 +0200132#endif
Manuel Pégourié-Gonnard12c1ff02013-08-21 12:28:31 +0200133
Manuel Pégourié-Gonnard1ecf92c32018-10-22 12:11:15 +0200134#if defined(MBEDTLS_USE_PSA_CRYPTO)
Manuel Pégourié-Gonnard276cb642018-11-06 09:34:30 +0100135extern const mbedtls_pk_info_t mbedtls_pk_opaque_info;
Manuel Pégourié-Gonnard1ecf92c32018-10-22 12:11:15 +0200136#endif
137
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200138#endif /* MBEDTLS_PK_WRAP_H */