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