Manuel Pégourié-Gonnard | d73b3c1 | 2013-08-12 17:06:05 +0200 | [diff] [blame] | 1 | /** |
Darryl Green | a40a101 | 2018-01-05 15:33:17 +0000 | [diff] [blame] | 2 | * \file pk_internal.h |
Manuel Pégourié-Gonnard | d73b3c1 | 2013-08-12 17:06:05 +0200 | [diff] [blame] | 3 | * |
| 4 | * \brief Public Key abstraction layer: wrapper functions |
Darryl Green | a40a101 | 2018-01-05 15:33:17 +0000 | [diff] [blame] | 5 | */ |
| 6 | /* |
Manuel Pégourié-Gonnard | 6fb8187 | 2015-07-27 11:11:48 +0200 | [diff] [blame] | 7 | * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved |
Manuel Pégourié-Gonnard | 37ff140 | 2015-09-04 14:21:07 +0200 | [diff] [blame] | 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. |
Manuel Pégourié-Gonnard | d73b3c1 | 2013-08-12 17:06:05 +0200 | [diff] [blame] | 21 | * |
Manuel Pégourié-Gonnard | fe44643 | 2015-03-06 13:17:10 +0000 | [diff] [blame] | 22 | * This file is part of mbed TLS (https://tls.mbed.org) |
Manuel Pégourié-Gonnard | d73b3c1 | 2013-08-12 17:06:05 +0200 | [diff] [blame] | 23 | */ |
| 24 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 25 | #ifndef MBEDTLS_PK_WRAP_H |
| 26 | #define MBEDTLS_PK_WRAP_H |
Manuel Pégourié-Gonnard | d73b3c1 | 2013-08-12 17:06:05 +0200 | [diff] [blame] | 27 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 28 | #if !defined(MBEDTLS_CONFIG_FILE) |
Manuel Pégourié-Gonnard | d73b3c1 | 2013-08-12 17:06:05 +0200 | [diff] [blame] | 29 | #include "config.h" |
Manuel Pégourié-Gonnard | cef4ad2 | 2014-04-29 12:39:06 +0200 | [diff] [blame] | 30 | #else |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 31 | #include MBEDTLS_CONFIG_FILE |
Manuel Pégourié-Gonnard | cef4ad2 | 2014-04-29 12:39:06 +0200 | [diff] [blame] | 32 | #endif |
Manuel Pégourié-Gonnard | d73b3c1 | 2013-08-12 17:06:05 +0200 | [diff] [blame] | 33 | |
| 34 | #include "pk.h" |
| 35 | |
Manuel Pégourié-Gonnard | 342cecf | 2019-09-19 10:45:14 +0200 | [diff] [blame] | 36 | /* |
| 37 | * PK information macro definitions |
| 38 | */ |
| 39 | |
| 40 | /* |
| 41 | * Each PK type that can be used with MBEDTLS_PK_SINGLE_TYPE needs to have |
| 42 | * the following MBEDTLS_PK_INFO_{FIELD} definitions, plus a dummy one for the |
| 43 | * base name. For now, only ECKEY with MBEDTLS_USE_TINYCRYPT is defined. |
Manuel Pégourié-Gonnard | 08620cb | 2019-09-19 10:45:14 +0200 | [diff] [blame] | 44 | * |
| 45 | * For optional functions that are omitted, we need both the _FUNC field |
| 46 | * defined to NULL, and an extra macro _OMIT defined to 1. |
Manuel Pégourié-Gonnard | 342cecf | 2019-09-19 10:45:14 +0200 | [diff] [blame] | 47 | */ |
| 48 | |
| 49 | #if defined(MBEDTLS_USE_TINYCRYPT) |
Manuel Pégourié-Gonnard | 1c1cc0d | 2019-09-19 10:45:14 +0200 | [diff] [blame] | 50 | /* Dummy definition to keep check-names.sh happy - don't uncomment */ |
| 51 | //#define MBEDTLS_PK_INFO_ECKEY |
| 52 | |
Manuel Pégourié-Gonnard | a77e9b5 | 2019-09-19 10:45:14 +0200 | [diff] [blame^] | 53 | #define MBEDTLS_PK_INFO_ECKEY_CONTEXT mbedtls_uecc_keypair |
Manuel Pégourié-Gonnard | 342cecf | 2019-09-19 10:45:14 +0200 | [diff] [blame] | 54 | #define MBEDTLS_PK_INFO_ECKEY_TYPE MBEDTLS_PK_ECKEY |
| 55 | #define MBEDTLS_PK_INFO_ECKEY_NAME "EC" |
| 56 | #define MBEDTLS_PK_INFO_ECKEY_GET_BITLEN uecc_eckey_get_bitlen |
| 57 | #define MBEDTLS_PK_INFO_ECKEY_CAN_DO uecc_eckey_can_do |
| 58 | #define MBEDTLS_PK_INFO_ECKEY_VERIFY_FUNC uecc_eckey_verify_wrap |
| 59 | #define MBEDTLS_PK_INFO_ECKEY_SIGN_FUNC uecc_eckey_sign_wrap |
| 60 | #define MBEDTLS_PK_INFO_ECKEY_DECRYPT_FUNC NULL |
Manuel Pégourié-Gonnard | 08620cb | 2019-09-19 10:45:14 +0200 | [diff] [blame] | 61 | #define MBEDTLS_PK_INFO_ECKEY_DECRYPT_OMIT 1 |
Manuel Pégourié-Gonnard | 342cecf | 2019-09-19 10:45:14 +0200 | [diff] [blame] | 62 | #define MBEDTLS_PK_INFO_ECKEY_ENCRYPT_FUNC NULL |
Manuel Pégourié-Gonnard | 08620cb | 2019-09-19 10:45:14 +0200 | [diff] [blame] | 63 | #define MBEDTLS_PK_INFO_ECKEY_ENCRYPT_OMIT 1 |
Manuel Pégourié-Gonnard | 342cecf | 2019-09-19 10:45:14 +0200 | [diff] [blame] | 64 | #define MBEDTLS_PK_INFO_ECKEY_CHECK_PAIR_FUNC uecc_eckey_check_pair |
| 65 | #define MBEDTLS_PK_INFO_ECKEY_CTX_ALLOC_FUNC uecc_eckey_alloc_wrap |
| 66 | #define MBEDTLS_PK_INFO_ECKEY_CTX_FREE_FUNC uecc_eckey_free_wrap |
| 67 | #define MBEDTLS_PK_INFO_ECKEY_DEBUG_FUNC NULL |
Manuel Pégourié-Gonnard | 08620cb | 2019-09-19 10:45:14 +0200 | [diff] [blame] | 68 | #define MBEDTLS_PK_INFO_ECKEY_DEBUG_OMIT 1 |
Manuel Pégourié-Gonnard | 342cecf | 2019-09-19 10:45:14 +0200 | [diff] [blame] | 69 | #endif /* MBEDTLS_USE_TINYCRYPT */ |
| 70 | |
| 71 | /* |
| 72 | * Helper macros to extract fields from PK types |
| 73 | */ |
Manuel Pégourié-Gonnard | a77e9b5 | 2019-09-19 10:45:14 +0200 | [diff] [blame^] | 74 | #define MBEDTLS_PK_INFO_CONTEXT_T( PK ) PK ## _CONTEXT |
Manuel Pégourié-Gonnard | 342cecf | 2019-09-19 10:45:14 +0200 | [diff] [blame] | 75 | #define MBEDTLS_PK_INFO_TYPE_T( PK ) PK ## _TYPE |
| 76 | #define MBEDTLS_PK_INFO_NAME_T( PK ) PK ## _NAME |
| 77 | #define MBEDTLS_PK_INFO_GET_BITLEN_T( PK ) PK ## _GET_BITLEN |
| 78 | #define MBEDTLS_PK_INFO_CAN_DO_T( PK ) PK ## _CAN_DO |
| 79 | #define MBEDTLS_PK_INFO_VERIFY_FUNC_T( PK ) PK ## _VERIFY_FUNC |
Manuel Pégourié-Gonnard | 08620cb | 2019-09-19 10:45:14 +0200 | [diff] [blame] | 80 | #define MBEDTLS_PK_INFO_VERIFY_OMIT_T( PK ) PK ## _VERIFY_OMIT |
Manuel Pégourié-Gonnard | 342cecf | 2019-09-19 10:45:14 +0200 | [diff] [blame] | 81 | #define MBEDTLS_PK_INFO_SIGN_FUNC_T( PK ) PK ## _SIGN_FUNC |
Manuel Pégourié-Gonnard | 08620cb | 2019-09-19 10:45:14 +0200 | [diff] [blame] | 82 | #define MBEDTLS_PK_INFO_SIGN_OMIT_T( PK ) PK ## _SIGN_OMIT |
Manuel Pégourié-Gonnard | 342cecf | 2019-09-19 10:45:14 +0200 | [diff] [blame] | 83 | #define MBEDTLS_PK_INFO_DECRYPT_FUNC_T( PK ) PK ## _DECRYPT_FUNC |
Manuel Pégourié-Gonnard | 08620cb | 2019-09-19 10:45:14 +0200 | [diff] [blame] | 84 | #define MBEDTLS_PK_INFO_DECRYPT_OMIT_T( PK ) PK ## _DECRYPT_OMIT |
Manuel Pégourié-Gonnard | 342cecf | 2019-09-19 10:45:14 +0200 | [diff] [blame] | 85 | #define MBEDTLS_PK_INFO_ENCRYPT_FUNC_T( PK ) PK ## _ENCRYPT_FUNC |
Manuel Pégourié-Gonnard | 08620cb | 2019-09-19 10:45:14 +0200 | [diff] [blame] | 86 | #define MBEDTLS_PK_INFO_ENCRYPT_OMIT_T( PK ) PK ## _ENCRYPT_OMIT |
Manuel Pégourié-Gonnard | 342cecf | 2019-09-19 10:45:14 +0200 | [diff] [blame] | 87 | #define MBEDTLS_PK_INFO_CHECK_PAIR_FUNC_T( PK ) PK ## _CHECK_PAIR_FUNC |
Manuel Pégourié-Gonnard | 08620cb | 2019-09-19 10:45:14 +0200 | [diff] [blame] | 88 | #define MBEDTLS_PK_INFO_CHECK_PAIR_OMIT_T( PK ) PK ## _CHECK_PAIR_OMIT |
Manuel Pégourié-Gonnard | 342cecf | 2019-09-19 10:45:14 +0200 | [diff] [blame] | 89 | #define MBEDTLS_PK_INFO_CTX_ALLOC_FUNC_T( PK ) PK ## _CTX_ALLOC_FUNC |
| 90 | #define MBEDTLS_PK_INFO_CTX_FREE_FUNC_T( PK ) PK ## _CTX_FREE_FUNC |
| 91 | #define MBEDTLS_PK_INFO_DEBUG_FUNC_T( PK ) PK ## _DEBUG_FUNC |
Manuel Pégourié-Gonnard | 08620cb | 2019-09-19 10:45:14 +0200 | [diff] [blame] | 92 | #define MBEDTLS_PK_INFO_DEBUG_OMIT_T( PK ) PK ## _DEBUG_OMIT |
Manuel Pégourié-Gonnard | 342cecf | 2019-09-19 10:45:14 +0200 | [diff] [blame] | 93 | |
| 94 | /* Wrappers around MBEDTLS_PK_INFO_{FIELD}_T() which makes sure that |
| 95 | * the argument is macro-expanded before concatenated with the |
| 96 | * field name. This allows to call these macros as |
| 97 | * MBEDTLS_PK_INFO_{FIELD}( MBEDTLS_PK_SINGLE_TYPE ). |
| 98 | * where MBEDTLS_PK_SINGLE_TYPE expands to MBEDTLS_PK_INFO_{TYPE}. */ |
Manuel Pégourié-Gonnard | a77e9b5 | 2019-09-19 10:45:14 +0200 | [diff] [blame^] | 99 | #define MBEDTLS_PK_INFO_CONTEXT( PK ) MBEDTLS_PK_INFO_CONTEXT_T( PK ) |
Manuel Pégourié-Gonnard | 342cecf | 2019-09-19 10:45:14 +0200 | [diff] [blame] | 100 | #define MBEDTLS_PK_INFO_TYPE( PK ) MBEDTLS_PK_INFO_TYPE_T( PK ) |
| 101 | #define MBEDTLS_PK_INFO_NAME( PK ) MBEDTLS_PK_INFO_NAME_T( PK ) |
| 102 | #define MBEDTLS_PK_INFO_GET_BITLEN( PK ) MBEDTLS_PK_INFO_GET_BITLEN_T( PK ) |
| 103 | #define MBEDTLS_PK_INFO_CAN_DO( PK ) MBEDTLS_PK_INFO_CAN_DO_T( PK ) |
| 104 | #define MBEDTLS_PK_INFO_VERIFY_FUNC( PK ) MBEDTLS_PK_INFO_VERIFY_FUNC_T( PK ) |
Manuel Pégourié-Gonnard | 08620cb | 2019-09-19 10:45:14 +0200 | [diff] [blame] | 105 | #define MBEDTLS_PK_INFO_VERIFY_OMIT( PK ) MBEDTLS_PK_INFO_VERIFY_OMIT_T( PK ) |
Manuel Pégourié-Gonnard | 342cecf | 2019-09-19 10:45:14 +0200 | [diff] [blame] | 106 | #define MBEDTLS_PK_INFO_SIGN_FUNC( PK ) MBEDTLS_PK_INFO_SIGN_FUNC_T( PK ) |
Manuel Pégourié-Gonnard | 08620cb | 2019-09-19 10:45:14 +0200 | [diff] [blame] | 107 | #define MBEDTLS_PK_INFO_SIGN_OMIT( PK ) MBEDTLS_PK_INFO_SIGN_OMIT_T( PK ) |
Manuel Pégourié-Gonnard | 342cecf | 2019-09-19 10:45:14 +0200 | [diff] [blame] | 108 | #define MBEDTLS_PK_INFO_DECRYPT_FUNC( PK ) MBEDTLS_PK_INFO_DECRYPT_FUNC_T( PK ) |
Manuel Pégourié-Gonnard | 08620cb | 2019-09-19 10:45:14 +0200 | [diff] [blame] | 109 | #define MBEDTLS_PK_INFO_DECRYPT_OMIT( PK ) MBEDTLS_PK_INFO_DECRYPT_OMIT_T( PK ) |
Manuel Pégourié-Gonnard | 342cecf | 2019-09-19 10:45:14 +0200 | [diff] [blame] | 110 | #define MBEDTLS_PK_INFO_ENCRYPT_FUNC( PK ) MBEDTLS_PK_INFO_ENCRYPT_FUNC_T( PK ) |
Manuel Pégourié-Gonnard | 08620cb | 2019-09-19 10:45:14 +0200 | [diff] [blame] | 111 | #define MBEDTLS_PK_INFO_ENCRYPT_OMIT( PK ) MBEDTLS_PK_INFO_ENCRYPT_OMIT_T( PK ) |
Manuel Pégourié-Gonnard | 342cecf | 2019-09-19 10:45:14 +0200 | [diff] [blame] | 112 | #define MBEDTLS_PK_INFO_CHECK_PAIR_FUNC( PK ) MBEDTLS_PK_INFO_CHECK_PAIR_FUNC_T( PK ) |
Manuel Pégourié-Gonnard | 08620cb | 2019-09-19 10:45:14 +0200 | [diff] [blame] | 113 | #define MBEDTLS_PK_INFO_CHECK_PAIR_OMIT( PK ) MBEDTLS_PK_INFO_CHECK_PAIR_OMIT_T( PK ) |
Manuel Pégourié-Gonnard | 342cecf | 2019-09-19 10:45:14 +0200 | [diff] [blame] | 114 | #define MBEDTLS_PK_INFO_CTX_ALLOC_FUNC( PK ) MBEDTLS_PK_INFO_CTX_ALLOC_FUNC_T( PK ) |
| 115 | #define MBEDTLS_PK_INFO_CTX_FREE_FUNC( PK ) MBEDTLS_PK_INFO_CTX_FREE_FUNC_T( PK ) |
| 116 | #define MBEDTLS_PK_INFO_DEBUG_FUNC( PK ) MBEDTLS_PK_INFO_DEBUG_FUNC_T( PK ) |
Manuel Pégourié-Gonnard | 08620cb | 2019-09-19 10:45:14 +0200 | [diff] [blame] | 117 | #define MBEDTLS_PK_INFO_DEBUG_OMIT( PK ) MBEDTLS_PK_INFO_DEBUG_OMIT_T( PK ) |
Manuel Pégourié-Gonnard | 342cecf | 2019-09-19 10:45:14 +0200 | [diff] [blame] | 118 | |
Manuel Pégourié-Gonnard | a77e9b5 | 2019-09-19 10:45:14 +0200 | [diff] [blame^] | 119 | #if !defined(MBEDTLS_PK_SINGLE_TYPE) |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 120 | struct mbedtls_pk_info_t |
Manuel Pégourié-Gonnard | c89d6cf | 2015-03-31 14:43:19 +0200 | [diff] [blame] | 121 | { |
| 122 | /** Public key type */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 123 | mbedtls_pk_type_t type; |
Manuel Pégourié-Gonnard | c89d6cf | 2015-03-31 14:43:19 +0200 | [diff] [blame] | 124 | |
| 125 | /** Type name */ |
| 126 | const char *name; |
| 127 | |
Manuel Pégourié-Gonnard | 57d96cd | 2019-09-19 10:45:14 +0200 | [diff] [blame] | 128 | /** Get key size in bits (must be valid)*/ |
Manuel Pégourié-Gonnard | 39a48f4 | 2015-06-18 16:06:55 +0200 | [diff] [blame] | 129 | size_t (*get_bitlen)( const void * ); |
Manuel Pégourié-Gonnard | c89d6cf | 2015-03-31 14:43:19 +0200 | [diff] [blame] | 130 | |
Manuel Pégourié-Gonnard | 57d96cd | 2019-09-19 10:45:14 +0200 | [diff] [blame] | 131 | /** Tell if the context implements this type (e.g. ECKEY can do ECDSA) |
| 132 | * (must be valid) */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 133 | int (*can_do)( mbedtls_pk_type_t type ); |
Manuel Pégourié-Gonnard | c89d6cf | 2015-03-31 14:43:19 +0200 | [diff] [blame] | 134 | |
Manuel Pégourié-Gonnard | 57d96cd | 2019-09-19 10:45:14 +0200 | [diff] [blame] | 135 | /** Verify signature (may be NULL) */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 136 | int (*verify_func)( void *ctx, mbedtls_md_type_t md_alg, |
Manuel Pégourié-Gonnard | c89d6cf | 2015-03-31 14:43:19 +0200 | [diff] [blame] | 137 | const unsigned char *hash, size_t hash_len, |
| 138 | const unsigned char *sig, size_t sig_len ); |
| 139 | |
Manuel Pégourié-Gonnard | 57d96cd | 2019-09-19 10:45:14 +0200 | [diff] [blame] | 140 | /** Make signature (may be NULL)*/ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 141 | int (*sign_func)( void *ctx, mbedtls_md_type_t md_alg, |
Manuel Pégourié-Gonnard | c89d6cf | 2015-03-31 14:43:19 +0200 | [diff] [blame] | 142 | const unsigned char *hash, size_t hash_len, |
| 143 | unsigned char *sig, size_t *sig_len, |
| 144 | int (*f_rng)(void *, unsigned char *, size_t), |
| 145 | void *p_rng ); |
| 146 | |
Manuel Pégourié-Gonnard | aaa9814 | 2017-08-18 17:30:37 +0200 | [diff] [blame] | 147 | #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE) |
Manuel Pégourié-Gonnard | 57d96cd | 2019-09-19 10:45:14 +0200 | [diff] [blame] | 148 | /** Verify signature (restartable) (may be NULL) */ |
Manuel Pégourié-Gonnard | 1f59606 | 2017-05-09 10:42:40 +0200 | [diff] [blame] | 149 | int (*verify_rs_func)( void *ctx, mbedtls_md_type_t md_alg, |
| 150 | const unsigned char *hash, size_t hash_len, |
| 151 | const unsigned char *sig, size_t sig_len, |
| 152 | void *rs_ctx ); |
| 153 | |
Manuel Pégourié-Gonnard | 57d96cd | 2019-09-19 10:45:14 +0200 | [diff] [blame] | 154 | /** Make signature (restartable) (may be NULL) */ |
Manuel Pégourié-Gonnard | 1f59606 | 2017-05-09 10:42:40 +0200 | [diff] [blame] | 155 | int (*sign_rs_func)( void *ctx, mbedtls_md_type_t md_alg, |
| 156 | const unsigned char *hash, size_t hash_len, |
| 157 | unsigned char *sig, size_t *sig_len, |
| 158 | int (*f_rng)(void *, unsigned char *, size_t), |
| 159 | void *p_rng, void *rs_ctx ); |
Manuel Pégourié-Gonnard | aaa9814 | 2017-08-18 17:30:37 +0200 | [diff] [blame] | 160 | #endif /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */ |
Manuel Pégourié-Gonnard | 1f59606 | 2017-05-09 10:42:40 +0200 | [diff] [blame] | 161 | |
Manuel Pégourié-Gonnard | 57d96cd | 2019-09-19 10:45:14 +0200 | [diff] [blame] | 162 | /** Decrypt message (may be NULL) */ |
Manuel Pégourié-Gonnard | c89d6cf | 2015-03-31 14:43:19 +0200 | [diff] [blame] | 163 | int (*decrypt_func)( void *ctx, const unsigned char *input, size_t ilen, |
| 164 | unsigned char *output, size_t *olen, size_t osize, |
| 165 | int (*f_rng)(void *, unsigned char *, size_t), |
| 166 | void *p_rng ); |
| 167 | |
Manuel Pégourié-Gonnard | 57d96cd | 2019-09-19 10:45:14 +0200 | [diff] [blame] | 168 | /** Encrypt message (may be NULL ) */ |
Manuel Pégourié-Gonnard | c89d6cf | 2015-03-31 14:43:19 +0200 | [diff] [blame] | 169 | int (*encrypt_func)( void *ctx, const unsigned char *input, size_t ilen, |
| 170 | unsigned char *output, size_t *olen, size_t osize, |
| 171 | int (*f_rng)(void *, unsigned char *, size_t), |
| 172 | void *p_rng ); |
| 173 | |
Manuel Pégourié-Gonnard | 57d96cd | 2019-09-19 10:45:14 +0200 | [diff] [blame] | 174 | /** Check public-private key pair (may be NULL) */ |
Manuel Pégourié-Gonnard | c89d6cf | 2015-03-31 14:43:19 +0200 | [diff] [blame] | 175 | int (*check_pair_func)( const void *pub, const void *prv ); |
| 176 | |
Manuel Pégourié-Gonnard | 57d96cd | 2019-09-19 10:45:14 +0200 | [diff] [blame] | 177 | /** Allocate a new context (must be valid) */ |
Manuel Pégourié-Gonnard | c89d6cf | 2015-03-31 14:43:19 +0200 | [diff] [blame] | 178 | void * (*ctx_alloc_func)( void ); |
| 179 | |
Manuel Pégourié-Gonnard | 57d96cd | 2019-09-19 10:45:14 +0200 | [diff] [blame] | 180 | /** Free the given context (must be valid) */ |
Manuel Pégourié-Gonnard | c89d6cf | 2015-03-31 14:43:19 +0200 | [diff] [blame] | 181 | void (*ctx_free_func)( void *ctx ); |
| 182 | |
Manuel Pégourié-Gonnard | aaa9814 | 2017-08-18 17:30:37 +0200 | [diff] [blame] | 183 | #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE) |
Manuel Pégourié-Gonnard | 57d96cd | 2019-09-19 10:45:14 +0200 | [diff] [blame] | 184 | /** Allocate the restart context (may be NULL)*/ |
Manuel Pégourié-Gonnard | 0bbc66c | 2017-08-18 16:22:06 +0200 | [diff] [blame] | 185 | void * (*rs_alloc_func)( void ); |
| 186 | |
Manuel Pégourié-Gonnard | 57d96cd | 2019-09-19 10:45:14 +0200 | [diff] [blame] | 187 | /** Free the restart context (may be NULL) */ |
Manuel Pégourié-Gonnard | 0bbc66c | 2017-08-18 16:22:06 +0200 | [diff] [blame] | 188 | void (*rs_free_func)( void *rs_ctx ); |
Manuel Pégourié-Gonnard | aaa9814 | 2017-08-18 17:30:37 +0200 | [diff] [blame] | 189 | #endif /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */ |
Manuel Pégourié-Gonnard | 0bbc66c | 2017-08-18 16:22:06 +0200 | [diff] [blame] | 190 | |
Manuel Pégourié-Gonnard | 57d96cd | 2019-09-19 10:45:14 +0200 | [diff] [blame] | 191 | /** Interface with the debug module (may be NULL) */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 192 | void (*debug_func)( const void *ctx, mbedtls_pk_debug_item *items ); |
Manuel Pégourié-Gonnard | c89d6cf | 2015-03-31 14:43:19 +0200 | [diff] [blame] | 193 | |
| 194 | }; |
Manuel Pégourié-Gonnard | 342cecf | 2019-09-19 10:45:14 +0200 | [diff] [blame] | 195 | |
| 196 | /** |
| 197 | * \brief This macro builds an instance of ::mbedtls_pk_info_t |
| 198 | * from an \c MBEDTLS_PK_INFO_{TYPE} identifier. |
| 199 | */ |
| 200 | #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE) |
| 201 | #define MBEDTLS_PK_INFO( PK ) \ |
| 202 | { \ |
| 203 | MBEDTLS_PK_INFO_TYPE( PK ), \ |
| 204 | MBEDTLS_PK_INFO_NAME( PK ), \ |
| 205 | MBEDTLS_PK_INFO_GET_BITLEN( PK ), \ |
| 206 | MBEDTLS_PK_INFO_CAN_DO( PK ), \ |
| 207 | MBEDTLS_PK_INFO_VERIFY_FUNC( PK ), \ |
| 208 | MBEDTLS_PK_INFO_SIGN_FUNC( PK ), \ |
| 209 | NULL, \ |
| 210 | NULL, \ |
| 211 | MBEDTLS_PK_INFO_DECRYPT_FUNC( PK ), \ |
| 212 | MBEDTLS_PK_INFO_ENCRYPT_FUNC( PK ), \ |
| 213 | MBEDTLS_PK_INFO_CHECK_PAIR_FUNC( PK ), \ |
| 214 | MBEDTLS_PK_INFO_CTX_ALLOC_FUNC( PK ), \ |
| 215 | MBEDTLS_PK_INFO_CTX_FREE_FUNC( PK ), \ |
| 216 | NULL, \ |
| 217 | NULL, \ |
| 218 | MBEDTLS_PK_INFO_DEBUG_FUNC( PK ), \ |
| 219 | } |
| 220 | #else /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */ |
| 221 | #define MBEDTLS_PK_INFO( PK ) \ |
| 222 | { \ |
| 223 | MBEDTLS_PK_INFO_TYPE( PK ), \ |
| 224 | MBEDTLS_PK_INFO_NAME( PK ), \ |
| 225 | MBEDTLS_PK_INFO_GET_BITLEN( PK ), \ |
| 226 | MBEDTLS_PK_INFO_CAN_DO( PK ), \ |
| 227 | MBEDTLS_PK_INFO_VERIFY_FUNC( PK ), \ |
| 228 | MBEDTLS_PK_INFO_SIGN_FUNC( PK ), \ |
| 229 | MBEDTLS_PK_INFO_DECRYPT_FUNC( PK ), \ |
| 230 | MBEDTLS_PK_INFO_ENCRYPT_FUNC( PK ), \ |
| 231 | MBEDTLS_PK_INFO_CHECK_PAIR_FUNC( PK ), \ |
| 232 | MBEDTLS_PK_INFO_CTX_ALLOC_FUNC( PK ), \ |
| 233 | MBEDTLS_PK_INFO_CTX_FREE_FUNC( PK ), \ |
| 234 | MBEDTLS_PK_INFO_DEBUG_FUNC( PK ), \ |
| 235 | } |
| 236 | #endif /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */ |
Manuel Pégourié-Gonnard | a77e9b5 | 2019-09-19 10:45:14 +0200 | [diff] [blame^] | 237 | #endif /* MBEDTLS_PK_SINGLE_TYPE */ |
Manuel Pégourié-Gonnard | 342cecf | 2019-09-19 10:45:14 +0200 | [diff] [blame] | 238 | |
Manuel Pégourié-Gonnard | 4223ce4 | 2019-09-19 10:45:14 +0200 | [diff] [blame] | 239 | /* |
| 240 | * Macros to access pk_info |
| 241 | */ |
Manuel Pégourié-Gonnard | 073c1e1 | 2019-09-19 10:45:14 +0200 | [diff] [blame] | 242 | #if defined(MBEDTLS_PK_SINGLE_TYPE) |
| 243 | #define MBEDTLS_PK_CTX_INFO( ctx ) MBEDTLS_PK_UNIQUE_VALID_HANDLE |
| 244 | #else |
Manuel Pégourié-Gonnard | 4223ce4 | 2019-09-19 10:45:14 +0200 | [diff] [blame] | 245 | #define MBEDTLS_PK_CTX_INFO( ctx ) ( (ctx)->pk_info ) |
Manuel Pégourié-Gonnard | 073c1e1 | 2019-09-19 10:45:14 +0200 | [diff] [blame] | 246 | #endif |
Manuel Pégourié-Gonnard | 4223ce4 | 2019-09-19 10:45:14 +0200 | [diff] [blame] | 247 | #define MBEDTLS_PK_CTX_IS_VALID( ctx ) \ |
| 248 | ( MBEDTLS_PK_CTX_INFO( (ctx) ) != MBEDTLS_PK_INVALID_HANDLE ) |
| 249 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 250 | #if defined(MBEDTLS_PK_RSA_ALT_SUPPORT) |
Manuel Pégourié-Gonnard | 12c1ff0 | 2013-08-21 12:28:31 +0200 | [diff] [blame] | 251 | /* Container for RSA-alt */ |
| 252 | typedef struct |
| 253 | { |
| 254 | void *key; |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 255 | mbedtls_pk_rsa_alt_decrypt_func decrypt_func; |
| 256 | mbedtls_pk_rsa_alt_sign_func sign_func; |
| 257 | mbedtls_pk_rsa_alt_key_len_func key_len_func; |
| 258 | } mbedtls_rsa_alt_context; |
Manuel Pégourié-Gonnard | 348bcb3 | 2015-03-31 14:01:33 +0200 | [diff] [blame] | 259 | #endif |
Manuel Pégourié-Gonnard | 12c1ff0 | 2013-08-21 12:28:31 +0200 | [diff] [blame] | 260 | |
Manuel Pégourié-Gonnard | f8b7c7f | 2019-09-19 10:45:14 +0200 | [diff] [blame] | 261 | #if !defined(MBEDTLS_PK_SINGLE_TYPE) |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 262 | #if defined(MBEDTLS_RSA_C) |
| 263 | extern const mbedtls_pk_info_t mbedtls_rsa_info; |
Manuel Pégourié-Gonnard | d73b3c1 | 2013-08-12 17:06:05 +0200 | [diff] [blame] | 264 | #endif |
| 265 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 266 | #if defined(MBEDTLS_ECP_C) |
| 267 | extern const mbedtls_pk_info_t mbedtls_eckey_info; |
| 268 | extern const mbedtls_pk_info_t mbedtls_eckeydh_info; |
Manuel Pégourié-Gonnard | d73b3c1 | 2013-08-12 17:06:05 +0200 | [diff] [blame] | 269 | #endif |
| 270 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 271 | #if defined(MBEDTLS_ECDSA_C) |
| 272 | extern const mbedtls_pk_info_t mbedtls_ecdsa_info; |
Manuel Pégourié-Gonnard | d73b3c1 | 2013-08-12 17:06:05 +0200 | [diff] [blame] | 273 | #endif |
| 274 | |
Jarno Lamsa | 42b83db | 2019-04-16 16:48:22 +0300 | [diff] [blame] | 275 | #if defined(MBEDTLS_USE_TINYCRYPT) |
Hanno Becker | adf11e1 | 2019-08-21 13:03:44 +0100 | [diff] [blame] | 276 | extern const mbedtls_pk_info_t mbedtls_uecc_eckey_info; |
Jarno Lamsa | 42b83db | 2019-04-16 16:48:22 +0300 | [diff] [blame] | 277 | #endif |
| 278 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 279 | #if defined(MBEDTLS_PK_RSA_ALT_SUPPORT) |
| 280 | extern const mbedtls_pk_info_t mbedtls_rsa_alt_info; |
Manuel Pégourié-Gonnard | 348bcb3 | 2015-03-31 14:01:33 +0200 | [diff] [blame] | 281 | #endif |
Manuel Pégourié-Gonnard | f8b7c7f | 2019-09-19 10:45:14 +0200 | [diff] [blame] | 282 | #endif /* MBEDTLS_PK_SINGLE_TYPE */ |
Manuel Pégourié-Gonnard | 12c1ff0 | 2013-08-21 12:28:31 +0200 | [diff] [blame] | 283 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 284 | #endif /* MBEDTLS_PK_WRAP_H */ |