blob: e996b6cadd954191fb1e1c0284ec9a1e15aa08e4 [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é-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{
37 /** Public key type */
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 */
Manuel Pégourié-Gonnard39a48f42015-06-18 16:06:55 +020044 size_t (*get_bitlen)( const void * );
Manuel Pégourié-Gonnardc89d6cf2015-03-31 14:43:19 +020045
46 /** Tell if the context implements this type (e.g. ECKEY can do ECDSA) */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020047 int (*can_do)( 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
Manuel Pégourié-Gonnard1f596062017-05-09 10:42:40 +020061#if defined(MBEDTLS_ECP_RESTARTABLE)
62 /** Verify signature (restartable) */
63 int (*verify_rs_func)( void *ctx, mbedtls_md_type_t md_alg,
64 const unsigned char *hash, size_t hash_len,
65 const unsigned char *sig, size_t sig_len,
66 void *rs_ctx );
67
68 /** Make signature (restartable) */
69 int (*sign_rs_func)( void *ctx, mbedtls_md_type_t md_alg,
70 const unsigned char *hash, size_t hash_len,
71 unsigned char *sig, size_t *sig_len,
72 int (*f_rng)(void *, unsigned char *, size_t),
73 void *p_rng, void *rs_ctx );
74#endif /* MBEDTLS_ECP_RESTARTABLE */
75
Manuel Pégourié-Gonnardc89d6cf2015-03-31 14:43:19 +020076 /** Decrypt message */
77 int (*decrypt_func)( void *ctx, const unsigned char *input, size_t ilen,
78 unsigned char *output, size_t *olen, size_t osize,
79 int (*f_rng)(void *, unsigned char *, size_t),
80 void *p_rng );
81
82 /** Encrypt message */
83 int (*encrypt_func)( void *ctx, const unsigned char *input, size_t ilen,
84 unsigned char *output, size_t *olen, size_t osize,
85 int (*f_rng)(void *, unsigned char *, size_t),
86 void *p_rng );
87
88 /** Check public-private key pair */
89 int (*check_pair_func)( const void *pub, const void *prv );
90
91 /** Allocate a new context */
92 void * (*ctx_alloc_func)( void );
93
94 /** Free the given context */
95 void (*ctx_free_func)( void *ctx );
96
97 /** Interface with the debug module */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020098 void (*debug_func)( const void *ctx, mbedtls_pk_debug_item *items );
Manuel Pégourié-Gonnardc89d6cf2015-03-31 14:43:19 +020099
100};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200101#if defined(MBEDTLS_PK_RSA_ALT_SUPPORT)
Manuel Pégourié-Gonnard12c1ff02013-08-21 12:28:31 +0200102/* Container for RSA-alt */
103typedef struct
104{
105 void *key;
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200106 mbedtls_pk_rsa_alt_decrypt_func decrypt_func;
107 mbedtls_pk_rsa_alt_sign_func sign_func;
108 mbedtls_pk_rsa_alt_key_len_func key_len_func;
109} mbedtls_rsa_alt_context;
Manuel Pégourié-Gonnard348bcb32015-03-31 14:01:33 +0200110#endif
Manuel Pégourié-Gonnard12c1ff02013-08-21 12:28:31 +0200111
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200112#if defined(MBEDTLS_RSA_C)
113extern const mbedtls_pk_info_t mbedtls_rsa_info;
Manuel Pégourié-Gonnardd73b3c12013-08-12 17:06:05 +0200114#endif
115
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200116#if defined(MBEDTLS_ECP_C)
117extern const mbedtls_pk_info_t mbedtls_eckey_info;
118extern const mbedtls_pk_info_t mbedtls_eckeydh_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_ECDSA_C)
122extern const mbedtls_pk_info_t mbedtls_ecdsa_info;
Manuel Pégourié-Gonnardd73b3c12013-08-12 17:06:05 +0200123#endif
124
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200125#if defined(MBEDTLS_PK_RSA_ALT_SUPPORT)
126extern const mbedtls_pk_info_t mbedtls_rsa_alt_info;
Manuel Pégourié-Gonnard348bcb32015-03-31 14:01:33 +0200127#endif
Manuel Pégourié-Gonnard12c1ff02013-08-21 12:28:31 +0200128
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200129#endif /* MBEDTLS_PK_WRAP_H */