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 | /* |
Bence Szépkúti | 1e14827 | 2020-08-07 13:07:28 +0200 | [diff] [blame] | 7 | * Copyright The Mbed TLS Contributors |
Dave Rodgman | 7ff7965 | 2023-11-03 12:04:52 +0000 | [diff] [blame] | 8 | * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later |
Manuel Pégourié-Gonnard | d73b3c1 | 2013-08-12 17:06:05 +0200 | [diff] [blame] | 9 | */ |
| 10 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 11 | #ifndef MBEDTLS_PK_WRAP_H |
| 12 | #define MBEDTLS_PK_WRAP_H |
Manuel Pégourié-Gonnard | d73b3c1 | 2013-08-12 17:06:05 +0200 | [diff] [blame] | 13 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 14 | #if !defined(MBEDTLS_CONFIG_FILE) |
Jaeden Amero | c49fbbf | 2019-07-04 20:01:14 +0100 | [diff] [blame] | 15 | #include "mbedtls/config.h" |
Manuel Pégourié-Gonnard | cef4ad2 | 2014-04-29 12:39:06 +0200 | [diff] [blame] | 16 | #else |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 17 | #include MBEDTLS_CONFIG_FILE |
Manuel Pégourié-Gonnard | cef4ad2 | 2014-04-29 12:39:06 +0200 | [diff] [blame] | 18 | #endif |
Manuel Pégourié-Gonnard | d73b3c1 | 2013-08-12 17:06:05 +0200 | [diff] [blame] | 19 | |
Jaeden Amero | c49fbbf | 2019-07-04 20:01:14 +0100 | [diff] [blame] | 20 | #include "mbedtls/pk.h" |
Manuel Pégourié-Gonnard | d73b3c1 | 2013-08-12 17:06:05 +0200 | [diff] [blame] | 21 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 22 | struct mbedtls_pk_info_t { |
Manuel Pégourié-Gonnard | c89d6cf | 2015-03-31 14:43:19 +0200 | [diff] [blame] | 23 | /** Public key type */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 24 | mbedtls_pk_type_t type; |
Manuel Pégourié-Gonnard | c89d6cf | 2015-03-31 14:43:19 +0200 | [diff] [blame] | 25 | |
| 26 | /** Type name */ |
| 27 | const char *name; |
| 28 | |
| 29 | /** Get key size in bits */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 30 | size_t (*get_bitlen)(const void *); |
Manuel Pégourié-Gonnard | c89d6cf | 2015-03-31 14:43:19 +0200 | [diff] [blame] | 31 | |
| 32 | /** Tell if the context implements this type (e.g. ECKEY can do ECDSA) */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 33 | int (*can_do)(mbedtls_pk_type_t type); |
Manuel Pégourié-Gonnard | c89d6cf | 2015-03-31 14:43:19 +0200 | [diff] [blame] | 34 | |
| 35 | /** Verify signature */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 36 | int (*verify_func)(void *ctx, mbedtls_md_type_t md_alg, |
| 37 | const unsigned char *hash, size_t hash_len, |
| 38 | const unsigned char *sig, size_t sig_len); |
Manuel Pégourié-Gonnard | c89d6cf | 2015-03-31 14:43:19 +0200 | [diff] [blame] | 39 | |
| 40 | /** Make signature */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 41 | int (*sign_func)(void *ctx, mbedtls_md_type_t md_alg, |
| 42 | const unsigned char *hash, size_t hash_len, |
| 43 | unsigned char *sig, size_t *sig_len, |
| 44 | int (*f_rng)(void *, unsigned char *, size_t), |
| 45 | void *p_rng); |
Manuel Pégourié-Gonnard | c89d6cf | 2015-03-31 14:43:19 +0200 | [diff] [blame] | 46 | |
Manuel Pégourié-Gonnard | aaa9814 | 2017-08-18 17:30:37 +0200 | [diff] [blame] | 47 | #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE) |
Manuel Pégourié-Gonnard | 1f59606 | 2017-05-09 10:42:40 +0200 | [diff] [blame] | 48 | /** Verify signature (restartable) */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 49 | int (*verify_rs_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 | void *rs_ctx); |
Manuel Pégourié-Gonnard | 1f59606 | 2017-05-09 10:42:40 +0200 | [diff] [blame] | 53 | |
| 54 | /** Make signature (restartable) */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 55 | int (*sign_rs_func)(void *ctx, mbedtls_md_type_t md_alg, |
| 56 | const unsigned char *hash, size_t hash_len, |
| 57 | unsigned char *sig, size_t *sig_len, |
| 58 | int (*f_rng)(void *, unsigned char *, size_t), |
| 59 | void *p_rng, void *rs_ctx); |
Manuel Pégourié-Gonnard | aaa9814 | 2017-08-18 17:30:37 +0200 | [diff] [blame] | 60 | #endif /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */ |
Manuel Pégourié-Gonnard | 1f59606 | 2017-05-09 10:42:40 +0200 | [diff] [blame] | 61 | |
Manuel Pégourié-Gonnard | c89d6cf | 2015-03-31 14:43:19 +0200 | [diff] [blame] | 62 | /** Decrypt message */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 63 | int (*decrypt_func)(void *ctx, const unsigned char *input, size_t ilen, |
| 64 | unsigned char *output, size_t *olen, size_t osize, |
| 65 | int (*f_rng)(void *, unsigned char *, size_t), |
| 66 | void *p_rng); |
Manuel Pégourié-Gonnard | c89d6cf | 2015-03-31 14:43:19 +0200 | [diff] [blame] | 67 | |
| 68 | /** Encrypt message */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 69 | int (*encrypt_func)(void *ctx, const unsigned char *input, size_t ilen, |
| 70 | unsigned char *output, size_t *olen, size_t osize, |
| 71 | int (*f_rng)(void *, unsigned char *, size_t), |
| 72 | void *p_rng); |
Manuel Pégourié-Gonnard | c89d6cf | 2015-03-31 14:43:19 +0200 | [diff] [blame] | 73 | |
| 74 | /** Check public-private key pair */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 75 | int (*check_pair_func)(const void *pub, const void *prv); |
Manuel Pégourié-Gonnard | c89d6cf | 2015-03-31 14:43:19 +0200 | [diff] [blame] | 76 | |
| 77 | /** Allocate a new context */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 78 | void * (*ctx_alloc_func)(void); |
Manuel Pégourié-Gonnard | c89d6cf | 2015-03-31 14:43:19 +0200 | [diff] [blame] | 79 | |
| 80 | /** Free the given context */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 81 | void (*ctx_free_func)(void *ctx); |
Manuel Pégourié-Gonnard | c89d6cf | 2015-03-31 14:43:19 +0200 | [diff] [blame] | 82 | |
Manuel Pégourié-Gonnard | aaa9814 | 2017-08-18 17:30:37 +0200 | [diff] [blame] | 83 | #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE) |
Manuel Pégourié-Gonnard | 0bbc66c | 2017-08-18 16:22:06 +0200 | [diff] [blame] | 84 | /** Allocate the restart context */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 85 | void *(*rs_alloc_func)(void); |
Manuel Pégourié-Gonnard | 0bbc66c | 2017-08-18 16:22:06 +0200 | [diff] [blame] | 86 | |
| 87 | /** Free the restart context */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 88 | void (*rs_free_func)(void *rs_ctx); |
Manuel Pégourié-Gonnard | aaa9814 | 2017-08-18 17:30:37 +0200 | [diff] [blame] | 89 | #endif /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */ |
Manuel Pégourié-Gonnard | 0bbc66c | 2017-08-18 16:22:06 +0200 | [diff] [blame] | 90 | |
Manuel Pégourié-Gonnard | c89d6cf | 2015-03-31 14:43:19 +0200 | [diff] [blame] | 91 | /** Interface with the debug module */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 92 | 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] | 93 | |
| 94 | }; |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 95 | #if defined(MBEDTLS_PK_RSA_ALT_SUPPORT) |
Manuel Pégourié-Gonnard | 12c1ff0 | 2013-08-21 12:28:31 +0200 | [diff] [blame] | 96 | /* Container for RSA-alt */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 97 | typedef struct { |
Manuel Pégourié-Gonnard | 12c1ff0 | 2013-08-21 12:28:31 +0200 | [diff] [blame] | 98 | void *key; |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 99 | mbedtls_pk_rsa_alt_decrypt_func decrypt_func; |
| 100 | mbedtls_pk_rsa_alt_sign_func sign_func; |
| 101 | mbedtls_pk_rsa_alt_key_len_func key_len_func; |
| 102 | } mbedtls_rsa_alt_context; |
Manuel Pégourié-Gonnard | 348bcb3 | 2015-03-31 14:01:33 +0200 | [diff] [blame] | 103 | #endif |
Manuel Pégourié-Gonnard | 12c1ff0 | 2013-08-21 12:28:31 +0200 | [diff] [blame] | 104 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 105 | #if defined(MBEDTLS_RSA_C) |
| 106 | extern const mbedtls_pk_info_t mbedtls_rsa_info; |
Manuel Pégourié-Gonnard | d73b3c1 | 2013-08-12 17:06:05 +0200 | [diff] [blame] | 107 | #endif |
| 108 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 109 | #if defined(MBEDTLS_ECP_C) |
| 110 | extern const mbedtls_pk_info_t mbedtls_eckey_info; |
| 111 | extern const mbedtls_pk_info_t mbedtls_eckeydh_info; |
Manuel Pégourié-Gonnard | d73b3c1 | 2013-08-12 17:06:05 +0200 | [diff] [blame] | 112 | #endif |
| 113 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 114 | #if defined(MBEDTLS_ECDSA_C) |
| 115 | extern const mbedtls_pk_info_t mbedtls_ecdsa_info; |
Manuel Pégourié-Gonnard | d73b3c1 | 2013-08-12 17:06:05 +0200 | [diff] [blame] | 116 | #endif |
| 117 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 118 | #if defined(MBEDTLS_PK_RSA_ALT_SUPPORT) |
| 119 | extern const mbedtls_pk_info_t mbedtls_rsa_alt_info; |
Manuel Pégourié-Gonnard | 348bcb3 | 2015-03-31 14:01:33 +0200 | [diff] [blame] | 120 | #endif |
Manuel Pégourié-Gonnard | 12c1ff0 | 2013-08-21 12:28:31 +0200 | [diff] [blame] | 121 | |
Manuel Pégourié-Gonnard | 1ecf92c3 | 2018-10-22 12:11:15 +0200 | [diff] [blame] | 122 | #if defined(MBEDTLS_USE_PSA_CRYPTO) |
Manuel Pégourié-Gonnard | 276cb64 | 2018-11-06 09:34:30 +0100 | [diff] [blame] | 123 | extern const mbedtls_pk_info_t mbedtls_pk_opaque_info; |
Manuel Pégourié-Gonnard | 1ecf92c3 | 2018-10-22 12:11:15 +0200 | [diff] [blame] | 124 | #endif |
| 125 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 126 | #endif /* MBEDTLS_PK_WRAP_H */ |