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 | 342cecf | 2019-09-19 10:45:14 +0200 | [diff] [blame] | 53 | #define MBEDTLS_PK_INFO_ECKEY_TYPE MBEDTLS_PK_ECKEY |
| 54 | #define MBEDTLS_PK_INFO_ECKEY_NAME "EC" |
| 55 | #define MBEDTLS_PK_INFO_ECKEY_GET_BITLEN uecc_eckey_get_bitlen |
| 56 | #define MBEDTLS_PK_INFO_ECKEY_CAN_DO uecc_eckey_can_do |
| 57 | #define MBEDTLS_PK_INFO_ECKEY_VERIFY_FUNC uecc_eckey_verify_wrap |
| 58 | #define MBEDTLS_PK_INFO_ECKEY_SIGN_FUNC uecc_eckey_sign_wrap |
| 59 | #define MBEDTLS_PK_INFO_ECKEY_DECRYPT_FUNC NULL |
Manuel Pégourié-Gonnard | 08620cb | 2019-09-19 10:45:14 +0200 | [diff] [blame] | 60 | #define MBEDTLS_PK_INFO_ECKEY_DECRYPT_OMIT 1 |
Manuel Pégourié-Gonnard | 342cecf | 2019-09-19 10:45:14 +0200 | [diff] [blame] | 61 | #define MBEDTLS_PK_INFO_ECKEY_ENCRYPT_FUNC NULL |
Manuel Pégourié-Gonnard | 08620cb | 2019-09-19 10:45:14 +0200 | [diff] [blame] | 62 | #define MBEDTLS_PK_INFO_ECKEY_ENCRYPT_OMIT 1 |
Manuel Pégourié-Gonnard | 342cecf | 2019-09-19 10:45:14 +0200 | [diff] [blame] | 63 | #define MBEDTLS_PK_INFO_ECKEY_CHECK_PAIR_FUNC uecc_eckey_check_pair |
| 64 | #define MBEDTLS_PK_INFO_ECKEY_CTX_ALLOC_FUNC uecc_eckey_alloc_wrap |
| 65 | #define MBEDTLS_PK_INFO_ECKEY_CTX_FREE_FUNC uecc_eckey_free_wrap |
| 66 | #define MBEDTLS_PK_INFO_ECKEY_DEBUG_FUNC NULL |
Manuel Pégourié-Gonnard | 08620cb | 2019-09-19 10:45:14 +0200 | [diff] [blame] | 67 | #define MBEDTLS_PK_INFO_ECKEY_DEBUG_OMIT 1 |
Manuel Pégourié-Gonnard | 342cecf | 2019-09-19 10:45:14 +0200 | [diff] [blame] | 68 | #endif /* MBEDTLS_USE_TINYCRYPT */ |
| 69 | |
| 70 | /* |
| 71 | * Helper macros to extract fields from PK types |
| 72 | */ |
| 73 | #define MBEDTLS_PK_INFO_TYPE_T( PK ) PK ## _TYPE |
| 74 | #define MBEDTLS_PK_INFO_NAME_T( PK ) PK ## _NAME |
| 75 | #define MBEDTLS_PK_INFO_GET_BITLEN_T( PK ) PK ## _GET_BITLEN |
| 76 | #define MBEDTLS_PK_INFO_CAN_DO_T( PK ) PK ## _CAN_DO |
| 77 | #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] | 78 | #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] | 79 | #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] | 80 | #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] | 81 | #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] | 82 | #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] | 83 | #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] | 84 | #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] | 85 | #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] | 86 | #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] | 87 | #define MBEDTLS_PK_INFO_CTX_ALLOC_FUNC_T( PK ) PK ## _CTX_ALLOC_FUNC |
| 88 | #define MBEDTLS_PK_INFO_CTX_FREE_FUNC_T( PK ) PK ## _CTX_FREE_FUNC |
| 89 | #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] | 90 | #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] | 91 | |
| 92 | /* Wrappers around MBEDTLS_PK_INFO_{FIELD}_T() which makes sure that |
| 93 | * the argument is macro-expanded before concatenated with the |
| 94 | * field name. This allows to call these macros as |
| 95 | * MBEDTLS_PK_INFO_{FIELD}( MBEDTLS_PK_SINGLE_TYPE ). |
| 96 | * where MBEDTLS_PK_SINGLE_TYPE expands to MBEDTLS_PK_INFO_{TYPE}. */ |
| 97 | #define MBEDTLS_PK_INFO_TYPE( PK ) MBEDTLS_PK_INFO_TYPE_T( PK ) |
| 98 | #define MBEDTLS_PK_INFO_NAME( PK ) MBEDTLS_PK_INFO_NAME_T( PK ) |
| 99 | #define MBEDTLS_PK_INFO_GET_BITLEN( PK ) MBEDTLS_PK_INFO_GET_BITLEN_T( PK ) |
| 100 | #define MBEDTLS_PK_INFO_CAN_DO( PK ) MBEDTLS_PK_INFO_CAN_DO_T( PK ) |
| 101 | #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] | 102 | #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] | 103 | #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] | 104 | #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] | 105 | #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] | 106 | #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] | 107 | #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] | 108 | #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] | 109 | #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] | 110 | #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] | 111 | #define MBEDTLS_PK_INFO_CTX_ALLOC_FUNC( PK ) MBEDTLS_PK_INFO_CTX_ALLOC_FUNC_T( PK ) |
| 112 | #define MBEDTLS_PK_INFO_CTX_FREE_FUNC( PK ) MBEDTLS_PK_INFO_CTX_FREE_FUNC_T( PK ) |
| 113 | #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] | 114 | #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] | 115 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 116 | struct mbedtls_pk_info_t |
Manuel Pégourié-Gonnard | c89d6cf | 2015-03-31 14:43:19 +0200 | [diff] [blame] | 117 | { |
| 118 | /** Public key type */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 119 | mbedtls_pk_type_t type; |
Manuel Pégourié-Gonnard | c89d6cf | 2015-03-31 14:43:19 +0200 | [diff] [blame] | 120 | |
| 121 | /** Type name */ |
| 122 | const char *name; |
| 123 | |
Manuel Pégourié-Gonnard | 57d96cd | 2019-09-19 10:45:14 +0200 | [diff] [blame] | 124 | /** Get key size in bits (must be valid)*/ |
Manuel Pégourié-Gonnard | 39a48f4 | 2015-06-18 16:06:55 +0200 | [diff] [blame] | 125 | size_t (*get_bitlen)( const void * ); |
Manuel Pégourié-Gonnard | c89d6cf | 2015-03-31 14:43:19 +0200 | [diff] [blame] | 126 | |
Manuel Pégourié-Gonnard | 57d96cd | 2019-09-19 10:45:14 +0200 | [diff] [blame] | 127 | /** Tell if the context implements this type (e.g. ECKEY can do ECDSA) |
| 128 | * (must be valid) */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 129 | int (*can_do)( mbedtls_pk_type_t type ); |
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 | /** Verify signature (may be NULL) */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 132 | 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] | 133 | const unsigned char *hash, size_t hash_len, |
| 134 | const unsigned char *sig, size_t sig_len ); |
| 135 | |
Manuel Pégourié-Gonnard | 57d96cd | 2019-09-19 10:45:14 +0200 | [diff] [blame] | 136 | /** Make signature (may be NULL)*/ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 137 | 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] | 138 | const unsigned char *hash, size_t hash_len, |
| 139 | unsigned char *sig, size_t *sig_len, |
| 140 | int (*f_rng)(void *, unsigned char *, size_t), |
| 141 | void *p_rng ); |
| 142 | |
Manuel Pégourié-Gonnard | aaa9814 | 2017-08-18 17:30:37 +0200 | [diff] [blame] | 143 | #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE) |
Manuel Pégourié-Gonnard | 57d96cd | 2019-09-19 10:45:14 +0200 | [diff] [blame] | 144 | /** Verify signature (restartable) (may be NULL) */ |
Manuel Pégourié-Gonnard | 1f59606 | 2017-05-09 10:42:40 +0200 | [diff] [blame] | 145 | int (*verify_rs_func)( void *ctx, mbedtls_md_type_t md_alg, |
| 146 | const unsigned char *hash, size_t hash_len, |
| 147 | const unsigned char *sig, size_t sig_len, |
| 148 | void *rs_ctx ); |
| 149 | |
Manuel Pégourié-Gonnard | 57d96cd | 2019-09-19 10:45:14 +0200 | [diff] [blame] | 150 | /** Make signature (restartable) (may be NULL) */ |
Manuel Pégourié-Gonnard | 1f59606 | 2017-05-09 10:42:40 +0200 | [diff] [blame] | 151 | int (*sign_rs_func)( void *ctx, mbedtls_md_type_t md_alg, |
| 152 | const unsigned char *hash, size_t hash_len, |
| 153 | unsigned char *sig, size_t *sig_len, |
| 154 | int (*f_rng)(void *, unsigned char *, size_t), |
| 155 | void *p_rng, void *rs_ctx ); |
Manuel Pégourié-Gonnard | aaa9814 | 2017-08-18 17:30:37 +0200 | [diff] [blame] | 156 | #endif /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */ |
Manuel Pégourié-Gonnard | 1f59606 | 2017-05-09 10:42:40 +0200 | [diff] [blame] | 157 | |
Manuel Pégourié-Gonnard | 57d96cd | 2019-09-19 10:45:14 +0200 | [diff] [blame] | 158 | /** Decrypt message (may be NULL) */ |
Manuel Pégourié-Gonnard | c89d6cf | 2015-03-31 14:43:19 +0200 | [diff] [blame] | 159 | int (*decrypt_func)( void *ctx, const unsigned char *input, size_t ilen, |
| 160 | unsigned char *output, size_t *olen, size_t osize, |
| 161 | int (*f_rng)(void *, unsigned char *, size_t), |
| 162 | void *p_rng ); |
| 163 | |
Manuel Pégourié-Gonnard | 57d96cd | 2019-09-19 10:45:14 +0200 | [diff] [blame] | 164 | /** Encrypt message (may be NULL ) */ |
Manuel Pégourié-Gonnard | c89d6cf | 2015-03-31 14:43:19 +0200 | [diff] [blame] | 165 | int (*encrypt_func)( void *ctx, const unsigned char *input, size_t ilen, |
| 166 | unsigned char *output, size_t *olen, size_t osize, |
| 167 | int (*f_rng)(void *, unsigned char *, size_t), |
| 168 | void *p_rng ); |
| 169 | |
Manuel Pégourié-Gonnard | 57d96cd | 2019-09-19 10:45:14 +0200 | [diff] [blame] | 170 | /** Check public-private key pair (may be NULL) */ |
Manuel Pégourié-Gonnard | c89d6cf | 2015-03-31 14:43:19 +0200 | [diff] [blame] | 171 | int (*check_pair_func)( const void *pub, const void *prv ); |
| 172 | |
Manuel Pégourié-Gonnard | 57d96cd | 2019-09-19 10:45:14 +0200 | [diff] [blame] | 173 | /** Allocate a new context (must be valid) */ |
Manuel Pégourié-Gonnard | c89d6cf | 2015-03-31 14:43:19 +0200 | [diff] [blame] | 174 | void * (*ctx_alloc_func)( void ); |
| 175 | |
Manuel Pégourié-Gonnard | 57d96cd | 2019-09-19 10:45:14 +0200 | [diff] [blame] | 176 | /** Free the given context (must be valid) */ |
Manuel Pégourié-Gonnard | c89d6cf | 2015-03-31 14:43:19 +0200 | [diff] [blame] | 177 | void (*ctx_free_func)( void *ctx ); |
| 178 | |
Manuel Pégourié-Gonnard | aaa9814 | 2017-08-18 17:30:37 +0200 | [diff] [blame] | 179 | #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE) |
Manuel Pégourié-Gonnard | 57d96cd | 2019-09-19 10:45:14 +0200 | [diff] [blame] | 180 | /** Allocate the restart context (may be NULL)*/ |
Manuel Pégourié-Gonnard | 0bbc66c | 2017-08-18 16:22:06 +0200 | [diff] [blame] | 181 | void * (*rs_alloc_func)( void ); |
| 182 | |
Manuel Pégourié-Gonnard | 57d96cd | 2019-09-19 10:45:14 +0200 | [diff] [blame] | 183 | /** Free the restart context (may be NULL) */ |
Manuel Pégourié-Gonnard | 0bbc66c | 2017-08-18 16:22:06 +0200 | [diff] [blame] | 184 | void (*rs_free_func)( void *rs_ctx ); |
Manuel Pégourié-Gonnard | aaa9814 | 2017-08-18 17:30:37 +0200 | [diff] [blame] | 185 | #endif /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */ |
Manuel Pégourié-Gonnard | 0bbc66c | 2017-08-18 16:22:06 +0200 | [diff] [blame] | 186 | |
Manuel Pégourié-Gonnard | 57d96cd | 2019-09-19 10:45:14 +0200 | [diff] [blame] | 187 | /** Interface with the debug module (may be NULL) */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 188 | 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] | 189 | |
| 190 | }; |
Manuel Pégourié-Gonnard | 342cecf | 2019-09-19 10:45:14 +0200 | [diff] [blame] | 191 | |
| 192 | /** |
| 193 | * \brief This macro builds an instance of ::mbedtls_pk_info_t |
| 194 | * from an \c MBEDTLS_PK_INFO_{TYPE} identifier. |
| 195 | */ |
| 196 | #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE) |
| 197 | #define MBEDTLS_PK_INFO( PK ) \ |
| 198 | { \ |
| 199 | MBEDTLS_PK_INFO_TYPE( PK ), \ |
| 200 | MBEDTLS_PK_INFO_NAME( PK ), \ |
| 201 | MBEDTLS_PK_INFO_GET_BITLEN( PK ), \ |
| 202 | MBEDTLS_PK_INFO_CAN_DO( PK ), \ |
| 203 | MBEDTLS_PK_INFO_VERIFY_FUNC( PK ), \ |
| 204 | MBEDTLS_PK_INFO_SIGN_FUNC( PK ), \ |
| 205 | NULL, \ |
| 206 | NULL, \ |
| 207 | MBEDTLS_PK_INFO_DECRYPT_FUNC( PK ), \ |
| 208 | MBEDTLS_PK_INFO_ENCRYPT_FUNC( PK ), \ |
| 209 | MBEDTLS_PK_INFO_CHECK_PAIR_FUNC( PK ), \ |
| 210 | MBEDTLS_PK_INFO_CTX_ALLOC_FUNC( PK ), \ |
| 211 | MBEDTLS_PK_INFO_CTX_FREE_FUNC( PK ), \ |
| 212 | NULL, \ |
| 213 | NULL, \ |
| 214 | MBEDTLS_PK_INFO_DEBUG_FUNC( PK ), \ |
| 215 | } |
| 216 | #else /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */ |
| 217 | #define MBEDTLS_PK_INFO( PK ) \ |
| 218 | { \ |
| 219 | MBEDTLS_PK_INFO_TYPE( PK ), \ |
| 220 | MBEDTLS_PK_INFO_NAME( PK ), \ |
| 221 | MBEDTLS_PK_INFO_GET_BITLEN( PK ), \ |
| 222 | MBEDTLS_PK_INFO_CAN_DO( PK ), \ |
| 223 | MBEDTLS_PK_INFO_VERIFY_FUNC( PK ), \ |
| 224 | MBEDTLS_PK_INFO_SIGN_FUNC( PK ), \ |
| 225 | MBEDTLS_PK_INFO_DECRYPT_FUNC( PK ), \ |
| 226 | MBEDTLS_PK_INFO_ENCRYPT_FUNC( PK ), \ |
| 227 | MBEDTLS_PK_INFO_CHECK_PAIR_FUNC( PK ), \ |
| 228 | MBEDTLS_PK_INFO_CTX_ALLOC_FUNC( PK ), \ |
| 229 | MBEDTLS_PK_INFO_CTX_FREE_FUNC( PK ), \ |
| 230 | MBEDTLS_PK_INFO_DEBUG_FUNC( PK ), \ |
| 231 | } |
| 232 | #endif /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */ |
| 233 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 234 | #if defined(MBEDTLS_PK_RSA_ALT_SUPPORT) |
Manuel Pégourié-Gonnard | 12c1ff0 | 2013-08-21 12:28:31 +0200 | [diff] [blame] | 235 | /* Container for RSA-alt */ |
| 236 | typedef struct |
| 237 | { |
| 238 | void *key; |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 239 | mbedtls_pk_rsa_alt_decrypt_func decrypt_func; |
| 240 | mbedtls_pk_rsa_alt_sign_func sign_func; |
| 241 | mbedtls_pk_rsa_alt_key_len_func key_len_func; |
| 242 | } mbedtls_rsa_alt_context; |
Manuel Pégourié-Gonnard | 348bcb3 | 2015-03-31 14:01:33 +0200 | [diff] [blame] | 243 | #endif |
Manuel Pégourié-Gonnard | 12c1ff0 | 2013-08-21 12:28:31 +0200 | [diff] [blame] | 244 | |
Manuel Pégourié-Gonnard | f8b7c7f | 2019-09-19 10:45:14 +0200 | [diff] [blame^] | 245 | #if !defined(MBEDTLS_PK_SINGLE_TYPE) |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 246 | #if defined(MBEDTLS_RSA_C) |
| 247 | extern const mbedtls_pk_info_t mbedtls_rsa_info; |
Manuel Pégourié-Gonnard | d73b3c1 | 2013-08-12 17:06:05 +0200 | [diff] [blame] | 248 | #endif |
| 249 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 250 | #if defined(MBEDTLS_ECP_C) |
| 251 | extern const mbedtls_pk_info_t mbedtls_eckey_info; |
| 252 | extern const mbedtls_pk_info_t mbedtls_eckeydh_info; |
Manuel Pégourié-Gonnard | d73b3c1 | 2013-08-12 17:06:05 +0200 | [diff] [blame] | 253 | #endif |
| 254 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 255 | #if defined(MBEDTLS_ECDSA_C) |
| 256 | extern const mbedtls_pk_info_t mbedtls_ecdsa_info; |
Manuel Pégourié-Gonnard | d73b3c1 | 2013-08-12 17:06:05 +0200 | [diff] [blame] | 257 | #endif |
| 258 | |
Jarno Lamsa | 42b83db | 2019-04-16 16:48:22 +0300 | [diff] [blame] | 259 | #if defined(MBEDTLS_USE_TINYCRYPT) |
Hanno Becker | adf11e1 | 2019-08-21 13:03:44 +0100 | [diff] [blame] | 260 | extern const mbedtls_pk_info_t mbedtls_uecc_eckey_info; |
Jarno Lamsa | 42b83db | 2019-04-16 16:48:22 +0300 | [diff] [blame] | 261 | #endif |
| 262 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 263 | #if defined(MBEDTLS_PK_RSA_ALT_SUPPORT) |
| 264 | extern const mbedtls_pk_info_t mbedtls_rsa_alt_info; |
Manuel Pégourié-Gonnard | 348bcb3 | 2015-03-31 14:01:33 +0200 | [diff] [blame] | 265 | #endif |
Manuel Pégourié-Gonnard | f8b7c7f | 2019-09-19 10:45:14 +0200 | [diff] [blame^] | 266 | #endif /* MBEDTLS_PK_SINGLE_TYPE */ |
Manuel Pégourié-Gonnard | 12c1ff0 | 2013-08-21 12:28:31 +0200 | [diff] [blame] | 267 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 268 | #endif /* MBEDTLS_PK_WRAP_H */ |