4 * \brief Public Key abstraction layer: wrapper functions
6 * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
7 * SPDX-License-Identifier: GPL-2.0
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 * This file is part of mbed TLS (https://tls.mbed.org)
26 #ifndef MBEDTLS_PK_WRAP_H
27 #define MBEDTLS_PK_WRAP_H
29 #if !defined(MBEDTLS_CONFIG_FILE)
32 #include MBEDTLS_CONFIG_FILE
37 struct mbedtls_pk_info_t
39 /** Public key type */
40 mbedtls_pk_type_t type
;
45 /** Get key size in bits */
46 size_t (*get_bitlen
)( const void * );
48 /** Tell if the context implements this type (e.g. ECKEY can do ECDSA) */
49 int (*can_do
)( mbedtls_pk_type_t type
);
51 /** Verify signature */
52 int (*verify_func
)( void *ctx
, mbedtls_md_type_t md_alg
,
53 const unsigned char *hash
, size_t hash_len
,
54 const unsigned char *sig
, size_t sig_len
);
57 int (*sign_func
)( void *ctx
, mbedtls_md_type_t md_alg
,
58 const unsigned char *hash
, size_t hash_len
,
59 unsigned char *sig
, size_t *sig_len
,
60 int (*f_rng
)(void *, unsigned char *, size_t),
63 /** Decrypt message */
64 int (*decrypt_func
)( void *ctx
, const unsigned char *input
, size_t ilen
,
65 unsigned char *output
, size_t *olen
, size_t osize
,
66 int (*f_rng
)(void *, unsigned char *, size_t),
69 /** Encrypt message */
70 int (*encrypt_func
)( void *ctx
, const unsigned char *input
, size_t ilen
,
71 unsigned char *output
, size_t *olen
, size_t osize
,
72 int (*f_rng
)(void *, unsigned char *, size_t),
75 /** Check public-private key pair */
76 int (*check_pair_func
)( const void *pub
, const void *prv
);
78 /** Allocate a new context */
79 void * (*ctx_alloc_func
)( void );
81 /** Free the given context */
82 void (*ctx_free_func
)( void *ctx
);
84 /** Interface with the debug module */
85 void (*debug_func
)( const void *ctx
, mbedtls_pk_debug_item
*items
);
88 #if defined(MBEDTLS_PK_RSA_ALT_SUPPORT)
89 /* Container for RSA-alt */
93 mbedtls_pk_rsa_alt_decrypt_func decrypt_func
;
94 mbedtls_pk_rsa_alt_sign_func sign_func
;
95 mbedtls_pk_rsa_alt_key_len_func key_len_func
;
96 } mbedtls_rsa_alt_context
;
99 #if defined(MBEDTLS_RSA_C)
100 extern const mbedtls_pk_info_t mbedtls_rsa_info
;
103 #if defined(MBEDTLS_ECP_C)
104 extern const mbedtls_pk_info_t mbedtls_eckey_info
;
105 extern const mbedtls_pk_info_t mbedtls_eckeydh_info
;
108 #if defined(MBEDTLS_ECDSA_C)
109 extern const mbedtls_pk_info_t mbedtls_ecdsa_info
;
112 #if defined(MBEDTLS_PK_RSA_ALT_SUPPORT)
113 extern const mbedtls_pk_info_t mbedtls_rsa_alt_info
;
116 #endif /* MBEDTLS_PK_WRAP_H */