4 * \brief Public Key abstraction layer: wrapper functions
6 * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
7 * SPDX-License-Identifier: Apache-2.0
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 * This file is part of mbed TLS (https://tls.mbed.org)
24 #ifndef MBEDTLS_PK_WRAP_H
25 #define MBEDTLS_PK_WRAP_H
27 #if !defined(MBEDTLS_CONFIG_FILE)
30 #include MBEDTLS_CONFIG_FILE
35 struct mbedtls_pk_info_t
37 /** Public key type */
38 mbedtls_pk_type_t type;
43 /** Get key size in bits */
44 size_t (*get_bitlen)( const void * );
46 /** Tell if the context implements this type (e.g. ECKEY can do ECDSA) */
47 int (*can_do)( mbedtls_pk_type_t type );
49 /** Verify signature */
50 int (*verify_func)( void *ctx, mbedtls_md_type_t md_alg,
51 const unsigned char *hash, size_t hash_len,
52 const unsigned char *sig, size_t sig_len );
55 int (*sign_func)( void *ctx, mbedtls_md_type_t md_alg,
56 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),
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),
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),
73 /** Check public-private key pair */
74 int (*check_pair_func)( const void *pub, const void *prv );
76 /** Allocate a new context */
77 void * (*ctx_alloc_func)( void );
79 /** Free the given context */
80 void (*ctx_free_func)( void *ctx );
82 /** Interface with the debug module */
83 void (*debug_func)( const void *ctx, mbedtls_pk_debug_item *items );
86 #if defined(MBEDTLS_PK_RSA_ALT_SUPPORT)
87 /* Container for RSA-alt */
91 mbedtls_pk_rsa_alt_decrypt_func decrypt_func;
92 mbedtls_pk_rsa_alt_sign_func sign_func;
93 mbedtls_pk_rsa_alt_key_len_func key_len_func;
94 } mbedtls_rsa_alt_context;
97 #if defined(MBEDTLS_RSA_C)
98 extern const mbedtls_pk_info_t mbedtls_rsa_info;
101 #if defined(MBEDTLS_ECP_C)
102 extern const mbedtls_pk_info_t mbedtls_eckey_info;
103 extern const mbedtls_pk_info_t mbedtls_eckeydh_info;
106 #if defined(MBEDTLS_ECDSA_C)
107 extern const mbedtls_pk_info_t mbedtls_ecdsa_info;
110 #if defined(MBEDTLS_PK_RSA_ALT_SUPPORT)
111 extern const mbedtls_pk_info_t mbedtls_rsa_alt_info;
114 #endif /* MBEDTLS_PK_WRAP_H */