1/**
2 * \file pk_internal.h
3 *
4 * \brief Public Key abstraction layer: wrapper functions
5 */
6/*
7 * Copyright The Mbed TLS Contributors
8 * 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.
21 */
22
23#ifndef MBEDTLS_PK_WRAP_H
24#define MBEDTLS_PK_WRAP_H
25
26#if !defined(MBEDTLS_CONFIG_FILE)
27#include "mbedtls/config.h"
28#else
29#include MBEDTLS_CONFIG_FILE
30#endif
31
32#include "mbedtls/pk.h"
33
34struct mbedtls_pk_info_t {
35 /** Public key type */
36 mbedtls_pk_type_t type;
37
38 /** Type name */
39 const char *name;
40
41 /** Get key size in bits */
42 size_t (*get_bitlen)(const void *);
43
44 /** Tell if the context implements this type (e.g. ECKEY can do ECDSA) */
45 int (*can_do)(mbedtls_pk_type_t type);
46
47 /** Verify signature */
48 int (*verify_func)(void *ctx, mbedtls_md_type_t md_alg,
49 const unsigned char *hash, size_t hash_len,
50 const unsigned char *sig, size_t sig_len);
51
52 /** Make signature */
53 int (*sign_func)(void *ctx, mbedtls_md_type_t md_alg,
54 const unsigned char *hash, size_t hash_len,
55 unsigned char *sig, size_t *sig_len,
56 int (*f_rng)(void *, unsigned char *, size_t),
57 void *p_rng);
58
59#if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
60 /** Verify signature (restartable) */
61 int (*verify_rs_func)(void *ctx, mbedtls_md_type_t md_alg,
62 const unsigned char *hash, size_t hash_len,
63 const unsigned char *sig, size_t sig_len,
64 void *rs_ctx);
65
66 /** Make signature (restartable) */
67 int (*sign_rs_func)(void *ctx, mbedtls_md_type_t md_alg,
68 const unsigned char *hash, size_t hash_len,
69 unsigned char *sig, size_t *sig_len,
70 int (*f_rng)(void *, unsigned char *, size_t),
71 void *p_rng, void *rs_ctx);
72#endif /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */
73
74 /** Decrypt message */
75 int (*decrypt_func)(void *ctx, const unsigned char *input, size_t ilen,
76 unsigned char *output, size_t *olen, size_t osize,
77 int (*f_rng)(void *, unsigned char *, size_t),
78 void *p_rng);
79
80 /** Encrypt message */
81 int (*encrypt_func)(void *ctx, const unsigned char *input, size_t ilen,
82 unsigned char *output, size_t *olen, size_t osize,
83 int (*f_rng)(void *, unsigned char *, size_t),
84 void *p_rng);
85
86 /** Check public-private key pair */
87 int (*check_pair_func)(const void *pub, const void *prv);
88
89 /** Allocate a new context */
90 void * (*ctx_alloc_func)(void);
91
92 /** Free the given context */
93 void (*ctx_free_func)(void *ctx);
94
95#if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
96 /** Allocate the restart context */
97 void *(*rs_alloc_func)(void);
98
99 /** Free the restart context */
100 void (*rs_free_func)(void *rs_ctx);
101#endif /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */
102
103 /** Interface with the debug module */
104 void (*debug_func)(const void *ctx, mbedtls_pk_debug_item *items);
105
106};
107#if defined(MBEDTLS_PK_RSA_ALT_SUPPORT)
108/* Container for RSA-alt */
109typedef struct {
110 void *key;
111 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;
115#endif
116
117#if defined(MBEDTLS_RSA_C)
118extern const mbedtls_pk_info_t mbedtls_rsa_info;
119#endif
120
121#if defined(MBEDTLS_ECP_C)
122extern const mbedtls_pk_info_t mbedtls_eckey_info;
123extern const mbedtls_pk_info_t mbedtls_eckeydh_info;
124#endif
125
126#if defined(MBEDTLS_ECDSA_C)
127extern const mbedtls_pk_info_t mbedtls_ecdsa_info;
128#endif
129
130#if defined(MBEDTLS_PK_RSA_ALT_SUPPORT)
131extern const mbedtls_pk_info_t mbedtls_rsa_alt_info;
132#endif
133
134#if defined(MBEDTLS_USE_PSA_CRYPTO)
135extern const mbedtls_pk_info_t mbedtls_pk_opaque_info;
136#endif
137
138#endif /* MBEDTLS_PK_WRAP_H */
139