blob: 4823294e83166758fad3e2b9b4c1e40a1236ebcb [file] [log] [blame]
Manuel Pégourié-Gonnardd73b3c12013-08-12 17:06:05 +02001/**
2 * \file pk.h
3 *
Gilles Peskinebadc5292017-09-21 14:56:36 +02004 * \brief Public Key cryptography abstraction layer: wrapper functions
Manuel Pégourié-Gonnardd73b3c12013-08-12 17:06:05 +02005 *
Manuel Pégourié-Gonnard6fb81872015-07-27 11:11:48 +02006 * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
Manuel Pégourié-Gonnard37ff1402015-09-04 14:21:07 +02007 * SPDX-License-Identifier: Apache-2.0
8 *
9 * Licensed under the Apache License, Version 2.0 (the "License"); you may
10 * not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
12 *
13 * http://www.apache.org/licenses/LICENSE-2.0
14 *
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
17 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
Manuel Pégourié-Gonnardd73b3c12013-08-12 17:06:05 +020020 *
Manuel Pégourié-Gonnardfe446432015-03-06 13:17:10 +000021 * This file is part of mbed TLS (https://tls.mbed.org)
Manuel Pégourié-Gonnardd73b3c12013-08-12 17:06:05 +020022 */
23
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020024#ifndef MBEDTLS_PK_WRAP_H
25#define MBEDTLS_PK_WRAP_H
Manuel Pégourié-Gonnardd73b3c12013-08-12 17:06:05 +020026
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020027#if !defined(MBEDTLS_CONFIG_FILE)
Manuel Pégourié-Gonnardd73b3c12013-08-12 17:06:05 +020028#include "config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020029#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020030#include MBEDTLS_CONFIG_FILE
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020031#endif
Manuel Pégourié-Gonnardd73b3c12013-08-12 17:06:05 +020032
33#include "pk.h"
34
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020035struct mbedtls_pk_info_t
Manuel Pégourié-Gonnardc89d6cf2015-03-31 14:43:19 +020036{
Gilles Peskinebadc5292017-09-21 14:56:36 +020037 /** Key pair type with indication of supported algorithms */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020038 mbedtls_pk_type_t type;
Manuel Pégourié-Gonnardc89d6cf2015-03-31 14:43:19 +020039
40 /** Type name */
41 const char *name;
42
43 /** Get key size in bits */
Gilles Peskine373deea2017-10-26 12:03:35 +020044 size_t (*get_bitlen)( const void *ctx );
Manuel Pégourié-Gonnardc89d6cf2015-03-31 14:43:19 +020045
46 /** Tell if the context implements this type (e.g. ECKEY can do ECDSA) */
Gilles Peskine373deea2017-10-26 12:03:35 +020047 int (*can_do)( const void * ctx, mbedtls_pk_type_t type );
Manuel Pégourié-Gonnardc89d6cf2015-03-31 14:43:19 +020048
49 /** Verify signature */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020050 int (*verify_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,
52 const unsigned char *sig, size_t sig_len );
53
54 /** Make signature */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020055 int (*sign_func)( void *ctx, mbedtls_md_type_t md_alg,
Manuel Pégourié-Gonnardc89d6cf2015-03-31 14:43:19 +020056 const unsigned char *hash, size_t hash_len,
57 unsigned char *sig, size_t *sig_len,
58 int (*f_rng)(void *, unsigned char *, size_t),
59 void *p_rng );
60
61 /** Decrypt message */
62 int (*decrypt_func)( void *ctx, const unsigned char *input, size_t ilen,
63 unsigned char *output, size_t *olen, size_t osize,
64 int (*f_rng)(void *, unsigned char *, size_t),
65 void *p_rng );
66
67 /** Encrypt message */
68 int (*encrypt_func)( void *ctx, const unsigned char *input, size_t ilen,
69 unsigned char *output, size_t *olen, size_t osize,
70 int (*f_rng)(void *, unsigned char *, size_t),
71 void *p_rng );
72
73 /** Check public-private key pair */
74 int (*check_pair_func)( const void *pub, const void *prv );
75
76 /** Allocate a new context */
77 void * (*ctx_alloc_func)( void );
78
79 /** Free the given context */
80 void (*ctx_free_func)( void *ctx );
81
82 /** Interface with the debug module */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020083 void (*debug_func)( const void *ctx, mbedtls_pk_debug_item *items );
Manuel Pégourié-Gonnardc89d6cf2015-03-31 14:43:19 +020084
Gilles Peskinecd062d82017-11-02 17:16:43 +010085 /** Signature size */
86 size_t (*signature_size_func)( const void *ctx );
Manuel Pégourié-Gonnardc89d6cf2015-03-31 14:43:19 +020087};
Gilles Peskinecd062d82017-11-02 17:16:43 +010088
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020089#if defined(MBEDTLS_PK_RSA_ALT_SUPPORT)
Manuel Pégourié-Gonnard12c1ff02013-08-21 12:28:31 +020090/* Container for RSA-alt */
91typedef struct
92{
93 void *key;
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020094 mbedtls_pk_rsa_alt_decrypt_func decrypt_func;
95 mbedtls_pk_rsa_alt_sign_func sign_func;
96 mbedtls_pk_rsa_alt_key_len_func key_len_func;
97} mbedtls_rsa_alt_context;
Manuel Pégourié-Gonnard348bcb32015-03-31 14:01:33 +020098#endif
Manuel Pégourié-Gonnard12c1ff02013-08-21 12:28:31 +020099
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200100#if defined(MBEDTLS_RSA_C)
101extern const mbedtls_pk_info_t mbedtls_rsa_info;
Manuel Pégourié-Gonnardd73b3c12013-08-12 17:06:05 +0200102#endif
103
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200104#if defined(MBEDTLS_ECP_C)
105extern const mbedtls_pk_info_t mbedtls_eckey_info;
106extern const mbedtls_pk_info_t mbedtls_eckeydh_info;
Manuel Pégourié-Gonnardd73b3c12013-08-12 17:06:05 +0200107#endif
108
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200109#if defined(MBEDTLS_ECDSA_C)
110extern const mbedtls_pk_info_t mbedtls_ecdsa_info;
Manuel Pégourié-Gonnardd73b3c12013-08-12 17:06:05 +0200111#endif
112
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200113#if defined(MBEDTLS_PK_RSA_ALT_SUPPORT)
114extern const mbedtls_pk_info_t mbedtls_rsa_alt_info;
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#endif /* MBEDTLS_PK_WRAP_H */