4 * \brief Public Key abstraction layer: wrapper functions
7 * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
8 * SPDX-License-Identifier: GPL-2.0
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 * This file is part of mbed TLS (https://tls.mbed.org)
27 #ifndef MBEDTLS_PK_WRAP_H
28 #define MBEDTLS_PK_WRAP_H
30 #if !defined(MBEDTLS_CONFIG_FILE)
33 #include MBEDTLS_CONFIG_FILE
38 struct mbedtls_pk_info_t
40 /** Public key type */
41 mbedtls_pk_type_t type
;
46 /** Get key size in bits */
47 size_t (*get_bitlen
)( const void * );
49 /** Tell if the context implements this type (e.g. ECKEY can do ECDSA) */
50 int (*can_do
)( mbedtls_pk_type_t type
);
52 /** Verify signature */
53 int (*verify_func
)( void *ctx
, mbedtls_md_type_t md_alg
,
54 const unsigned char *hash
, size_t hash_len
,
55 const unsigned char *sig
, size_t sig_len
);
58 int (*sign_func
)( void *ctx
, mbedtls_md_type_t md_alg
,
59 const unsigned char *hash
, size_t hash_len
,
60 unsigned char *sig
, size_t *sig_len
,
61 int (*f_rng
)(void *, unsigned char *, size_t),
64 /** Decrypt message */
65 int (*decrypt_func
)( void *ctx
, const unsigned char *input
, size_t ilen
,
66 unsigned char *output
, size_t *olen
, size_t osize
,
67 int (*f_rng
)(void *, unsigned char *, size_t),
70 /** Encrypt message */
71 int (*encrypt_func
)( void *ctx
, const unsigned char *input
, size_t ilen
,
72 unsigned char *output
, size_t *olen
, size_t osize
,
73 int (*f_rng
)(void *, unsigned char *, size_t),
76 /** Check public-private key pair */
77 int (*check_pair_func
)( const void *pub
, const void *prv
);
79 /** Allocate a new context */
80 void * (*ctx_alloc_func
)( void );
82 /** Free the given context */
83 void (*ctx_free_func
)( void *ctx
);
85 /** Interface with the debug module */
86 void (*debug_func
)( const void *ctx
, mbedtls_pk_debug_item
*items
);
89 #if defined(MBEDTLS_PK_RSA_ALT_SUPPORT)
90 /* Container for RSA-alt */
94 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
;
100 #if defined(MBEDTLS_RSA_C)
101 extern const mbedtls_pk_info_t mbedtls_rsa_info
;
104 #if defined(MBEDTLS_ECP_C)
105 extern const mbedtls_pk_info_t mbedtls_eckey_info
;
106 extern const mbedtls_pk_info_t mbedtls_eckeydh_info
;
109 #if defined(MBEDTLS_ECDSA_C)
110 extern const mbedtls_pk_info_t mbedtls_ecdsa_info
;
113 #if defined(MBEDTLS_PK_RSA_ALT_SUPPORT)
114 extern const mbedtls_pk_info_t mbedtls_rsa_alt_info
;
117 #endif /* MBEDTLS_PK_WRAP_H */