text
[RRG-proxmark3.git] / common / mbedtls / pk_internal.h
blob7c13c8020723b2c51265bc58214d86e997ac02f0
1 /**
2 * \file pk_internal.h
4 * \brief Public Key abstraction layer: wrapper functions
5 */
6 /*
7 * Copyright The Mbed TLS Contributors
8 * SPDX-License-Identifier: Apache-2.0
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
14 * http://www.apache.org/licenses/LICENSE-2.0
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.
23 #ifndef MBEDTLS_PK_WRAP_H
24 #define MBEDTLS_PK_WRAP_H
26 #if !defined(MBEDTLS_CONFIG_FILE)
27 #include "mbedtls/config.h"
28 #else
29 #include MBEDTLS_CONFIG_FILE
30 #endif
32 #include "mbedtls/pk.h"
34 struct mbedtls_pk_info_t {
35 /** Public key type */
36 mbedtls_pk_type_t type;
38 /** Type name */
39 const char *name;
41 /** Get key size in bits */
42 size_t (*get_bitlen)(const void *);
44 /** Tell if the context implements this type (e.g. ECKEY can do ECDSA) */
45 int (*can_do)(mbedtls_pk_type_t type);
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);
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);
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);
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 */
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);
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);
86 /** Check public-private key pair */
87 int (*check_pair_func)(const void *pub, const void *prv);
89 /** Allocate a new context */
90 void *(*ctx_alloc_func)(void);
92 /** Free the given context */
93 void (*ctx_free_func)(void *ctx);
95 #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
96 /** Allocate the restart context */
97 void *(*rs_alloc_func)(void);
99 /** Free the restart context */
100 void (*rs_free_func)(void *rs_ctx);
101 #endif /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */
103 /** Interface with the debug module */
104 void (*debug_func)(const void *ctx, mbedtls_pk_debug_item *items);
107 #if defined(MBEDTLS_PK_RSA_ALT_SUPPORT)
108 /* Container for RSA-alt */
109 typedef 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
117 #if defined(MBEDTLS_RSA_C)
118 extern const mbedtls_pk_info_t mbedtls_rsa_info;
119 #endif
121 #if defined(MBEDTLS_ECP_C)
122 extern const mbedtls_pk_info_t mbedtls_eckey_info;
123 extern const mbedtls_pk_info_t mbedtls_eckeydh_info;
124 #endif
126 #if defined(MBEDTLS_ECDSA_C)
127 extern const mbedtls_pk_info_t mbedtls_ecdsa_info;
128 #endif
130 #if defined(MBEDTLS_PK_RSA_ALT_SUPPORT)
131 extern const mbedtls_pk_info_t mbedtls_rsa_alt_info;
132 #endif
134 #if defined(MBEDTLS_USE_PSA_CRYPTO)
135 extern const mbedtls_pk_info_t mbedtls_pk_opaque_info;
136 #endif
138 #endif /* MBEDTLS_PK_WRAP_H */