Manuel Pégourié-Gonnard | d73b3c1 | 2013-08-12 17:06:05 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Public Key abstraction layer: wrapper functions |
| 3 | * |
Manuel Pégourié-Gonnard | 6fb8187 | 2015-07-27 11:11:48 +0200 | [diff] [blame] | 4 | * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved |
Manuel Pégourié-Gonnard | 37ff140 | 2015-09-04 14:21:07 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: Apache-2.0 |
| 6 | * |
| 7 | * Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 8 | * not use this file except in compliance with the License. |
| 9 | * You may obtain a copy of the License at |
| 10 | * |
| 11 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | * |
| 13 | * Unless required by applicable law or agreed to in writing, software |
| 14 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 15 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | * See the License for the specific language governing permissions and |
| 17 | * limitations under the License. |
Manuel Pégourié-Gonnard | d73b3c1 | 2013-08-12 17:06:05 +0200 | [diff] [blame] | 18 | * |
Manuel Pégourié-Gonnard | fe44643 | 2015-03-06 13:17:10 +0000 | [diff] [blame] | 19 | * 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] | 20 | */ |
| 21 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 22 | #if !defined(MBEDTLS_CONFIG_FILE) |
Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 23 | #include "mbedtls/config.h" |
Manuel Pégourié-Gonnard | cef4ad2 | 2014-04-29 12:39:06 +0200 | [diff] [blame] | 24 | #else |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 25 | #include MBEDTLS_CONFIG_FILE |
Manuel Pégourié-Gonnard | cef4ad2 | 2014-04-29 12:39:06 +0200 | [diff] [blame] | 26 | #endif |
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_PK_C) |
Manuel Pégourié-Gonnard | 50518f4 | 2015-05-26 11:04:15 +0200 | [diff] [blame] | 29 | #include "mbedtls/pk_internal.h" |
Manuel Pégourié-Gonnard | d73b3c1 | 2013-08-12 17:06:05 +0200 | [diff] [blame] | 30 | |
Manuel Pégourié-Gonnard | e511ffc | 2013-08-22 17:33:21 +0200 | [diff] [blame] | 31 | /* Even if RSA not activated, for the sake of RSA-alt */ |
Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 32 | #include "mbedtls/rsa.h" |
Manuel Pégourié-Gonnard | d73b3c1 | 2013-08-12 17:06:05 +0200 | [diff] [blame] | 33 | |
Rich Evans | 00ab470 | 2015-02-06 13:43:58 +0000 | [diff] [blame] | 34 | #include <string.h> |
| 35 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 36 | #if defined(MBEDTLS_ECP_C) |
Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 37 | #include "mbedtls/ecp.h" |
Manuel Pégourié-Gonnard | d73b3c1 | 2013-08-12 17:06:05 +0200 | [diff] [blame] | 38 | #endif |
| 39 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 40 | #if defined(MBEDTLS_ECDSA_C) |
Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 41 | #include "mbedtls/ecdsa.h" |
Manuel Pégourié-Gonnard | d73b3c1 | 2013-08-12 17:06:05 +0200 | [diff] [blame] | 42 | #endif |
| 43 | |
Andres Amaya Garcia | e32df08 | 2017-10-25 09:37:04 +0100 | [diff] [blame] | 44 | #if defined(MBEDTLS_PK_RSA_ALT_SUPPORT) |
Andres Amaya Garcia | 1f6301b | 2018-04-17 09:51:09 -0500 | [diff] [blame] | 45 | #include "mbedtls/platform_util.h" |
Andres Amaya Garcia | e32df08 | 2017-10-25 09:37:04 +0100 | [diff] [blame] | 46 | #endif |
| 47 | |
Andrzej Kurek | 8b036a6 | 2018-10-31 05:16:46 -0400 | [diff] [blame] | 48 | #if defined(MBEDTLS_USE_PSA_CRYPTO) |
| 49 | #include "psa/crypto.h" |
| 50 | #include "mbedtls/x509.h" |
| 51 | #include "mbedtls/asn1.h" |
| 52 | #endif |
| 53 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 54 | #if defined(MBEDTLS_PLATFORM_C) |
Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 55 | #include "mbedtls/platform.h" |
Manuel Pégourié-Gonnard | 765db07 | 2013-08-14 15:00:27 +0200 | [diff] [blame] | 56 | #else |
| 57 | #include <stdlib.h> |
Manuel Pégourié-Gonnard | 7551cb9 | 2015-05-26 16:04:06 +0200 | [diff] [blame] | 58 | #define mbedtls_calloc calloc |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 59 | #define mbedtls_free free |
Manuel Pégourié-Gonnard | 765db07 | 2013-08-14 15:00:27 +0200 | [diff] [blame] | 60 | #endif |
| 61 | |
Andres AG | 7284987 | 2017-01-19 11:24:33 +0000 | [diff] [blame] | 62 | #include <limits.h> |
Andres Amaya Garcia | 7c02c50 | 2017-08-04 13:32:15 +0100 | [diff] [blame] | 63 | #include <stdint.h> |
Paul Bakker | 3461772 | 2014-06-13 17:20:13 +0200 | [diff] [blame] | 64 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 65 | #if defined(MBEDTLS_RSA_C) |
| 66 | static int rsa_can_do( mbedtls_pk_type_t type ) |
Manuel Pégourié-Gonnard | f18c3e0 | 2013-08-12 18:41:18 +0200 | [diff] [blame] | 67 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 68 | return( type == MBEDTLS_PK_RSA || |
| 69 | type == MBEDTLS_PK_RSASSA_PSS ); |
Manuel Pégourié-Gonnard | f18c3e0 | 2013-08-12 18:41:18 +0200 | [diff] [blame] | 70 | } |
| 71 | |
Manuel Pégourié-Gonnard | 39a48f4 | 2015-06-18 16:06:55 +0200 | [diff] [blame] | 72 | static size_t rsa_get_bitlen( const void *ctx ) |
Manuel Pégourié-Gonnard | f8c948a | 2013-08-12 19:45:32 +0200 | [diff] [blame] | 73 | { |
Hanno Becker | 6a1e7e5 | 2017-08-22 13:55:00 +0100 | [diff] [blame] | 74 | const mbedtls_rsa_context * rsa = (const mbedtls_rsa_context *) ctx; |
| 75 | return( 8 * mbedtls_rsa_get_len( rsa ) ); |
Manuel Pégourié-Gonnard | f8c948a | 2013-08-12 19:45:32 +0200 | [diff] [blame] | 76 | } |
| 77 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 78 | static int rsa_verify_wrap( void *ctx, mbedtls_md_type_t md_alg, |
Manuel Pégourié-Gonnard | f73da02 | 2013-08-17 14:36:32 +0200 | [diff] [blame] | 79 | const unsigned char *hash, size_t hash_len, |
Manuel Pégourié-Gonnard | d73b3c1 | 2013-08-12 17:06:05 +0200 | [diff] [blame] | 80 | const unsigned char *sig, size_t sig_len ) |
| 81 | { |
Manuel Pégourié-Gonnard | 2abed84 | 2014-04-08 12:40:15 +0200 | [diff] [blame] | 82 | int ret; |
Hanno Becker | 6a1e7e5 | 2017-08-22 13:55:00 +0100 | [diff] [blame] | 83 | mbedtls_rsa_context * rsa = (mbedtls_rsa_context *) ctx; |
| 84 | size_t rsa_len = mbedtls_rsa_get_len( rsa ); |
Manuel Pégourié-Gonnard | 2abed84 | 2014-04-08 12:40:15 +0200 | [diff] [blame] | 85 | |
Andres Amaya Garcia | 7c02c50 | 2017-08-04 13:32:15 +0100 | [diff] [blame] | 86 | #if SIZE_MAX > UINT_MAX |
Andres AG | 7284987 | 2017-01-19 11:24:33 +0000 | [diff] [blame] | 87 | if( md_alg == MBEDTLS_MD_NONE && UINT_MAX < hash_len ) |
| 88 | return( MBEDTLS_ERR_PK_BAD_INPUT_DATA ); |
Andres Amaya Garcia | 7c02c50 | 2017-08-04 13:32:15 +0100 | [diff] [blame] | 89 | #endif /* SIZE_MAX > UINT_MAX */ |
Andres AG | 7284987 | 2017-01-19 11:24:33 +0000 | [diff] [blame] | 90 | |
Hanno Becker | 6a1e7e5 | 2017-08-22 13:55:00 +0100 | [diff] [blame] | 91 | if( sig_len < rsa_len ) |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 92 | return( MBEDTLS_ERR_RSA_VERIFY_FAILED ); |
Manuel Pégourié-Gonnard | d73b3c1 | 2013-08-12 17:06:05 +0200 | [diff] [blame] | 93 | |
Hanno Becker | 6a1e7e5 | 2017-08-22 13:55:00 +0100 | [diff] [blame] | 94 | if( ( ret = mbedtls_rsa_pkcs1_verify( rsa, NULL, NULL, |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 95 | MBEDTLS_RSA_PUBLIC, md_alg, |
Manuel Pégourié-Gonnard | 2abed84 | 2014-04-08 12:40:15 +0200 | [diff] [blame] | 96 | (unsigned int) hash_len, hash, sig ) ) != 0 ) |
| 97 | return( ret ); |
| 98 | |
Gilles Peskine | 5114d3e | 2018-03-30 07:12:15 +0200 | [diff] [blame] | 99 | /* The buffer contains a valid signature followed by extra data. |
| 100 | * We have a special error code for that so that so that callers can |
| 101 | * use mbedtls_pk_verify() to check "Does the buffer start with a |
| 102 | * valid signature?" and not just "Does the buffer contain a valid |
| 103 | * signature?". */ |
Hanno Becker | 6a1e7e5 | 2017-08-22 13:55:00 +0100 | [diff] [blame] | 104 | if( sig_len > rsa_len ) |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 105 | return( MBEDTLS_ERR_PK_SIG_LEN_MISMATCH ); |
Manuel Pégourié-Gonnard | 2abed84 | 2014-04-08 12:40:15 +0200 | [diff] [blame] | 106 | |
| 107 | return( 0 ); |
Manuel Pégourié-Gonnard | d73b3c1 | 2013-08-12 17:06:05 +0200 | [diff] [blame] | 108 | } |
| 109 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 110 | static int rsa_sign_wrap( void *ctx, mbedtls_md_type_t md_alg, |
Manuel Pégourié-Gonnard | 8df2769 | 2013-08-21 10:34:38 +0200 | [diff] [blame] | 111 | const unsigned char *hash, size_t hash_len, |
| 112 | unsigned char *sig, size_t *sig_len, |
| 113 | int (*f_rng)(void *, unsigned char *, size_t), void *p_rng ) |
| 114 | { |
Hanno Becker | 6a1e7e5 | 2017-08-22 13:55:00 +0100 | [diff] [blame] | 115 | mbedtls_rsa_context * rsa = (mbedtls_rsa_context *) ctx; |
| 116 | |
Andres Amaya Garcia | 7c02c50 | 2017-08-04 13:32:15 +0100 | [diff] [blame] | 117 | #if SIZE_MAX > UINT_MAX |
Andres AG | 7284987 | 2017-01-19 11:24:33 +0000 | [diff] [blame] | 118 | if( md_alg == MBEDTLS_MD_NONE && UINT_MAX < hash_len ) |
| 119 | return( MBEDTLS_ERR_PK_BAD_INPUT_DATA ); |
Andres Amaya Garcia | 7c02c50 | 2017-08-04 13:32:15 +0100 | [diff] [blame] | 120 | #endif /* SIZE_MAX > UINT_MAX */ |
Andres AG | 7284987 | 2017-01-19 11:24:33 +0000 | [diff] [blame] | 121 | |
Hanno Becker | 6a1e7e5 | 2017-08-22 13:55:00 +0100 | [diff] [blame] | 122 | *sig_len = mbedtls_rsa_get_len( rsa ); |
Manuel Pégourié-Gonnard | 8df2769 | 2013-08-21 10:34:38 +0200 | [diff] [blame] | 123 | |
Hanno Becker | 6a1e7e5 | 2017-08-22 13:55:00 +0100 | [diff] [blame] | 124 | return( mbedtls_rsa_pkcs1_sign( rsa, f_rng, p_rng, MBEDTLS_RSA_PRIVATE, |
Paul Bakker | b9cfaa0 | 2013-10-11 18:58:55 +0200 | [diff] [blame] | 125 | md_alg, (unsigned int) hash_len, hash, sig ) ); |
Manuel Pégourié-Gonnard | 8df2769 | 2013-08-21 10:34:38 +0200 | [diff] [blame] | 126 | } |
| 127 | |
Manuel Pégourié-Gonnard | a2d3f22 | 2013-08-21 11:51:08 +0200 | [diff] [blame] | 128 | static int rsa_decrypt_wrap( void *ctx, |
| 129 | const unsigned char *input, size_t ilen, |
| 130 | unsigned char *output, size_t *olen, size_t osize, |
| 131 | int (*f_rng)(void *, unsigned char *, size_t), void *p_rng ) |
| 132 | { |
Hanno Becker | 6a1e7e5 | 2017-08-22 13:55:00 +0100 | [diff] [blame] | 133 | mbedtls_rsa_context * rsa = (mbedtls_rsa_context *) ctx; |
| 134 | |
| 135 | if( ilen != mbedtls_rsa_get_len( rsa ) ) |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 136 | return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA ); |
Manuel Pégourié-Gonnard | a2d3f22 | 2013-08-21 11:51:08 +0200 | [diff] [blame] | 137 | |
Hanno Becker | 6a1e7e5 | 2017-08-22 13:55:00 +0100 | [diff] [blame] | 138 | return( mbedtls_rsa_pkcs1_decrypt( rsa, f_rng, p_rng, |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 139 | MBEDTLS_RSA_PRIVATE, olen, input, output, osize ) ); |
Manuel Pégourié-Gonnard | a2d3f22 | 2013-08-21 11:51:08 +0200 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | static int rsa_encrypt_wrap( void *ctx, |
| 143 | const unsigned char *input, size_t ilen, |
| 144 | unsigned char *output, size_t *olen, size_t osize, |
| 145 | int (*f_rng)(void *, unsigned char *, size_t), void *p_rng ) |
| 146 | { |
Hanno Becker | 6a1e7e5 | 2017-08-22 13:55:00 +0100 | [diff] [blame] | 147 | mbedtls_rsa_context * rsa = (mbedtls_rsa_context *) ctx; |
| 148 | *olen = mbedtls_rsa_get_len( rsa ); |
Manuel Pégourié-Gonnard | a2d3f22 | 2013-08-21 11:51:08 +0200 | [diff] [blame] | 149 | |
Manuel Pégourié-Gonnard | a1efcb0 | 2014-11-08 17:08:08 +0100 | [diff] [blame] | 150 | if( *olen > osize ) |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 151 | return( MBEDTLS_ERR_RSA_OUTPUT_TOO_LARGE ); |
Manuel Pégourié-Gonnard | a1efcb0 | 2014-11-08 17:08:08 +0100 | [diff] [blame] | 152 | |
Hanno Becker | 6a1e7e5 | 2017-08-22 13:55:00 +0100 | [diff] [blame] | 153 | return( mbedtls_rsa_pkcs1_encrypt( rsa, f_rng, p_rng, MBEDTLS_RSA_PUBLIC, |
| 154 | ilen, input, output ) ); |
Manuel Pégourié-Gonnard | a2d3f22 | 2013-08-21 11:51:08 +0200 | [diff] [blame] | 155 | } |
| 156 | |
Manuel Pégourié-Gonnard | 70bdadf | 2014-11-06 16:51:20 +0100 | [diff] [blame] | 157 | static int rsa_check_pair_wrap( const void *pub, const void *prv ) |
| 158 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 159 | return( mbedtls_rsa_check_pub_priv( (const mbedtls_rsa_context *) pub, |
| 160 | (const mbedtls_rsa_context *) prv ) ); |
Manuel Pégourié-Gonnard | 70bdadf | 2014-11-06 16:51:20 +0100 | [diff] [blame] | 161 | } |
| 162 | |
Manuel Pégourié-Gonnard | 765db07 | 2013-08-14 15:00:27 +0200 | [diff] [blame] | 163 | static void *rsa_alloc_wrap( void ) |
| 164 | { |
Manuel Pégourié-Gonnard | 7551cb9 | 2015-05-26 16:04:06 +0200 | [diff] [blame] | 165 | void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_rsa_context ) ); |
Manuel Pégourié-Gonnard | 765db07 | 2013-08-14 15:00:27 +0200 | [diff] [blame] | 166 | |
| 167 | if( ctx != NULL ) |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 168 | mbedtls_rsa_init( (mbedtls_rsa_context *) ctx, 0, 0 ); |
Manuel Pégourié-Gonnard | 765db07 | 2013-08-14 15:00:27 +0200 | [diff] [blame] | 169 | |
Paul Bakker | d8bb826 | 2014-06-17 14:06:49 +0200 | [diff] [blame] | 170 | return( ctx ); |
Manuel Pégourié-Gonnard | 765db07 | 2013-08-14 15:00:27 +0200 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | static void rsa_free_wrap( void *ctx ) |
| 174 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 175 | mbedtls_rsa_free( (mbedtls_rsa_context *) ctx ); |
| 176 | mbedtls_free( ctx ); |
Manuel Pégourié-Gonnard | 765db07 | 2013-08-14 15:00:27 +0200 | [diff] [blame] | 177 | } |
| 178 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 179 | static void rsa_debug( const void *ctx, mbedtls_pk_debug_item *items ) |
Manuel Pégourié-Gonnard | c6ac887 | 2013-08-14 18:04:18 +0200 | [diff] [blame] | 180 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 181 | items->type = MBEDTLS_PK_DEBUG_MPI; |
Manuel Pégourié-Gonnard | c6ac887 | 2013-08-14 18:04:18 +0200 | [diff] [blame] | 182 | items->name = "rsa.N"; |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 183 | items->value = &( ((mbedtls_rsa_context *) ctx)->N ); |
Manuel Pégourié-Gonnard | c6ac887 | 2013-08-14 18:04:18 +0200 | [diff] [blame] | 184 | |
| 185 | items++; |
| 186 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 187 | items->type = MBEDTLS_PK_DEBUG_MPI; |
Manuel Pégourié-Gonnard | c6ac887 | 2013-08-14 18:04:18 +0200 | [diff] [blame] | 188 | items->name = "rsa.E"; |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 189 | items->value = &( ((mbedtls_rsa_context *) ctx)->E ); |
Manuel Pégourié-Gonnard | c6ac887 | 2013-08-14 18:04:18 +0200 | [diff] [blame] | 190 | } |
| 191 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 192 | const mbedtls_pk_info_t mbedtls_rsa_info = { |
| 193 | MBEDTLS_PK_RSA, |
Manuel Pégourié-Gonnard | f8c948a | 2013-08-12 19:45:32 +0200 | [diff] [blame] | 194 | "RSA", |
Manuel Pégourié-Gonnard | 39a48f4 | 2015-06-18 16:06:55 +0200 | [diff] [blame] | 195 | rsa_get_bitlen, |
Manuel Pégourié-Gonnard | f18c3e0 | 2013-08-12 18:41:18 +0200 | [diff] [blame] | 196 | rsa_can_do, |
Manuel Pégourié-Gonnard | d73b3c1 | 2013-08-12 17:06:05 +0200 | [diff] [blame] | 197 | rsa_verify_wrap, |
Manuel Pégourié-Gonnard | 8df2769 | 2013-08-21 10:34:38 +0200 | [diff] [blame] | 198 | rsa_sign_wrap, |
Manuel Pégourié-Gonnard | aaa9814 | 2017-08-18 17:30:37 +0200 | [diff] [blame] | 199 | #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE) |
Manuel Pégourié-Gonnard | 1f59606 | 2017-05-09 10:42:40 +0200 | [diff] [blame] | 200 | NULL, |
| 201 | NULL, |
| 202 | #endif |
Manuel Pégourié-Gonnard | a2d3f22 | 2013-08-21 11:51:08 +0200 | [diff] [blame] | 203 | rsa_decrypt_wrap, |
| 204 | rsa_encrypt_wrap, |
Manuel Pégourié-Gonnard | 70bdadf | 2014-11-06 16:51:20 +0100 | [diff] [blame] | 205 | rsa_check_pair_wrap, |
Manuel Pégourié-Gonnard | 765db07 | 2013-08-14 15:00:27 +0200 | [diff] [blame] | 206 | rsa_alloc_wrap, |
| 207 | rsa_free_wrap, |
Manuel Pégourié-Gonnard | aaa9814 | 2017-08-18 17:30:37 +0200 | [diff] [blame] | 208 | #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE) |
Manuel Pégourié-Gonnard | 0bbc66c | 2017-08-18 16:22:06 +0200 | [diff] [blame] | 209 | NULL, |
| 210 | NULL, |
| 211 | #endif |
Manuel Pégourié-Gonnard | c6ac887 | 2013-08-14 18:04:18 +0200 | [diff] [blame] | 212 | rsa_debug, |
Manuel Pégourié-Gonnard | d73b3c1 | 2013-08-12 17:06:05 +0200 | [diff] [blame] | 213 | }; |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 214 | #endif /* MBEDTLS_RSA_C */ |
Manuel Pégourié-Gonnard | d73b3c1 | 2013-08-12 17:06:05 +0200 | [diff] [blame] | 215 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 216 | #if defined(MBEDTLS_ECP_C) |
Manuel Pégourié-Gonnard | 835eb59 | 2013-08-12 18:51:26 +0200 | [diff] [blame] | 217 | /* |
| 218 | * Generic EC key |
| 219 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 220 | static int eckey_can_do( mbedtls_pk_type_t type ) |
Manuel Pégourié-Gonnard | f18c3e0 | 2013-08-12 18:41:18 +0200 | [diff] [blame] | 221 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 222 | return( type == MBEDTLS_PK_ECKEY || |
| 223 | type == MBEDTLS_PK_ECKEY_DH || |
| 224 | type == MBEDTLS_PK_ECDSA ); |
Manuel Pégourié-Gonnard | f18c3e0 | 2013-08-12 18:41:18 +0200 | [diff] [blame] | 225 | } |
| 226 | |
Manuel Pégourié-Gonnard | 39a48f4 | 2015-06-18 16:06:55 +0200 | [diff] [blame] | 227 | static size_t eckey_get_bitlen( const void *ctx ) |
Manuel Pégourié-Gonnard | f8c948a | 2013-08-12 19:45:32 +0200 | [diff] [blame] | 228 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 229 | return( ((mbedtls_ecp_keypair *) ctx)->grp.pbits ); |
Manuel Pégourié-Gonnard | f8c948a | 2013-08-12 19:45:32 +0200 | [diff] [blame] | 230 | } |
| 231 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 232 | #if defined(MBEDTLS_ECDSA_C) |
Manuel Pégourié-Gonnard | 8df2769 | 2013-08-21 10:34:38 +0200 | [diff] [blame] | 233 | /* Forward declarations */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 234 | static int ecdsa_verify_wrap( void *ctx, mbedtls_md_type_t md_alg, |
Manuel Pégourié-Gonnard | f73da02 | 2013-08-17 14:36:32 +0200 | [diff] [blame] | 235 | const unsigned char *hash, size_t hash_len, |
Manuel Pégourié-Gonnard | 09162dd | 2013-08-14 18:16:50 +0200 | [diff] [blame] | 236 | const unsigned char *sig, size_t sig_len ); |
Manuel Pégourié-Gonnard | 09162dd | 2013-08-14 18:16:50 +0200 | [diff] [blame] | 237 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 238 | static int ecdsa_sign_wrap( void *ctx, mbedtls_md_type_t md_alg, |
Manuel Pégourié-Gonnard | 8df2769 | 2013-08-21 10:34:38 +0200 | [diff] [blame] | 239 | const unsigned char *hash, size_t hash_len, |
| 240 | unsigned char *sig, size_t *sig_len, |
| 241 | int (*f_rng)(void *, unsigned char *, size_t), void *p_rng ); |
| 242 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 243 | static int eckey_verify_wrap( void *ctx, mbedtls_md_type_t md_alg, |
Manuel Pégourié-Gonnard | f73da02 | 2013-08-17 14:36:32 +0200 | [diff] [blame] | 244 | const unsigned char *hash, size_t hash_len, |
Manuel Pégourié-Gonnard | d73b3c1 | 2013-08-12 17:06:05 +0200 | [diff] [blame] | 245 | const unsigned char *sig, size_t sig_len ) |
| 246 | { |
Manuel Pégourié-Gonnard | d73b3c1 | 2013-08-12 17:06:05 +0200 | [diff] [blame] | 247 | int ret; |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 248 | mbedtls_ecdsa_context ecdsa; |
Manuel Pégourié-Gonnard | d73b3c1 | 2013-08-12 17:06:05 +0200 | [diff] [blame] | 249 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 250 | mbedtls_ecdsa_init( &ecdsa ); |
Manuel Pégourié-Gonnard | d73b3c1 | 2013-08-12 17:06:05 +0200 | [diff] [blame] | 251 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 252 | if( ( ret = mbedtls_ecdsa_from_keypair( &ecdsa, ctx ) ) == 0 ) |
Manuel Pégourié-Gonnard | 583b608 | 2013-08-20 16:58:13 +0200 | [diff] [blame] | 253 | ret = ecdsa_verify_wrap( &ecdsa, md_alg, hash, hash_len, sig, sig_len ); |
Manuel Pégourié-Gonnard | d73b3c1 | 2013-08-12 17:06:05 +0200 | [diff] [blame] | 254 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 255 | mbedtls_ecdsa_free( &ecdsa ); |
Manuel Pégourié-Gonnard | d73b3c1 | 2013-08-12 17:06:05 +0200 | [diff] [blame] | 256 | |
| 257 | return( ret ); |
Manuel Pégourié-Gonnard | d73b3c1 | 2013-08-12 17:06:05 +0200 | [diff] [blame] | 258 | } |
Manuel Pégourié-Gonnard | 8df2769 | 2013-08-21 10:34:38 +0200 | [diff] [blame] | 259 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 260 | static int eckey_sign_wrap( void *ctx, mbedtls_md_type_t md_alg, |
Manuel Pégourié-Gonnard | 8df2769 | 2013-08-21 10:34:38 +0200 | [diff] [blame] | 261 | const unsigned char *hash, size_t hash_len, |
| 262 | unsigned char *sig, size_t *sig_len, |
| 263 | int (*f_rng)(void *, unsigned char *, size_t), void *p_rng ) |
| 264 | { |
| 265 | int ret; |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 266 | mbedtls_ecdsa_context ecdsa; |
Manuel Pégourié-Gonnard | 8df2769 | 2013-08-21 10:34:38 +0200 | [diff] [blame] | 267 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 268 | mbedtls_ecdsa_init( &ecdsa ); |
Manuel Pégourié-Gonnard | 8df2769 | 2013-08-21 10:34:38 +0200 | [diff] [blame] | 269 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 270 | if( ( ret = mbedtls_ecdsa_from_keypair( &ecdsa, ctx ) ) == 0 ) |
Manuel Pégourié-Gonnard | 8df2769 | 2013-08-21 10:34:38 +0200 | [diff] [blame] | 271 | ret = ecdsa_sign_wrap( &ecdsa, md_alg, hash, hash_len, sig, sig_len, |
| 272 | f_rng, p_rng ); |
| 273 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 274 | mbedtls_ecdsa_free( &ecdsa ); |
Manuel Pégourié-Gonnard | 8df2769 | 2013-08-21 10:34:38 +0200 | [diff] [blame] | 275 | |
| 276 | return( ret ); |
| 277 | } |
| 278 | |
Manuel Pégourié-Gonnard | 1f59606 | 2017-05-09 10:42:40 +0200 | [diff] [blame] | 279 | #if defined(MBEDTLS_ECP_RESTARTABLE) |
| 280 | /* Forward declarations */ |
| 281 | static int ecdsa_verify_rs_wrap( void *ctx, mbedtls_md_type_t md_alg, |
| 282 | const unsigned char *hash, size_t hash_len, |
| 283 | const unsigned char *sig, size_t sig_len, |
| 284 | void *rs_ctx ); |
| 285 | |
| 286 | static int ecdsa_sign_rs_wrap( void *ctx, mbedtls_md_type_t md_alg, |
| 287 | const unsigned char *hash, size_t hash_len, |
| 288 | unsigned char *sig, size_t *sig_len, |
| 289 | int (*f_rng)(void *, unsigned char *, size_t), void *p_rng, |
| 290 | void *rs_ctx ); |
| 291 | |
Manuel Pégourié-Gonnard | fe68770 | 2017-08-18 17:04:07 +0200 | [diff] [blame] | 292 | /* |
| 293 | * Restart context for ECDSA operations with ECKEY context |
| 294 | * |
| 295 | * We need to store an actual ECDSA context, as we need to pass the same to |
| 296 | * the underlying ecdsa function, so we can't create it on the fly every time. |
| 297 | */ |
| 298 | typedef struct |
| 299 | { |
| 300 | mbedtls_ecdsa_restart_ctx ecdsa_rs; |
| 301 | mbedtls_ecdsa_context ecdsa_ctx; |
| 302 | } eckey_restart_ctx; |
| 303 | |
| 304 | static void *eckey_rs_alloc( void ) |
| 305 | { |
| 306 | eckey_restart_ctx *rs_ctx; |
| 307 | |
| 308 | void *ctx = mbedtls_calloc( 1, sizeof( eckey_restart_ctx ) ); |
| 309 | |
| 310 | if( ctx != NULL ) |
| 311 | { |
| 312 | rs_ctx = ctx; |
| 313 | mbedtls_ecdsa_restart_init( &rs_ctx->ecdsa_rs ); |
| 314 | mbedtls_ecdsa_init( &rs_ctx->ecdsa_ctx ); |
| 315 | } |
| 316 | |
| 317 | return( ctx ); |
| 318 | } |
| 319 | |
| 320 | static void eckey_rs_free( void *ctx ) |
| 321 | { |
| 322 | eckey_restart_ctx *rs_ctx; |
| 323 | |
| 324 | if( ctx == NULL) |
| 325 | return; |
| 326 | |
| 327 | rs_ctx = ctx; |
| 328 | mbedtls_ecdsa_restart_free( &rs_ctx->ecdsa_rs ); |
| 329 | mbedtls_ecdsa_free( &rs_ctx->ecdsa_ctx ); |
| 330 | |
| 331 | mbedtls_free( ctx ); |
| 332 | } |
| 333 | |
Manuel Pégourié-Gonnard | 1f59606 | 2017-05-09 10:42:40 +0200 | [diff] [blame] | 334 | static int eckey_verify_rs_wrap( void *ctx, mbedtls_md_type_t md_alg, |
| 335 | const unsigned char *hash, size_t hash_len, |
| 336 | const unsigned char *sig, size_t sig_len, |
Manuel Pégourié-Gonnard | fe68770 | 2017-08-18 17:04:07 +0200 | [diff] [blame] | 337 | void *rs_ctx ) |
Manuel Pégourié-Gonnard | 1f59606 | 2017-05-09 10:42:40 +0200 | [diff] [blame] | 338 | { |
| 339 | int ret; |
Manuel Pégourié-Gonnard | fe68770 | 2017-08-18 17:04:07 +0200 | [diff] [blame] | 340 | eckey_restart_ctx *rs = rs_ctx; |
Manuel Pégourié-Gonnard | 1f59606 | 2017-05-09 10:42:40 +0200 | [diff] [blame] | 341 | |
Manuel Pégourié-Gonnard | fe68770 | 2017-08-18 17:04:07 +0200 | [diff] [blame] | 342 | /* Should never happen */ |
| 343 | if( rs == NULL ) |
| 344 | return( MBEDTLS_ERR_PK_BAD_INPUT_DATA ); |
Manuel Pégourié-Gonnard | 1f59606 | 2017-05-09 10:42:40 +0200 | [diff] [blame] | 345 | |
Manuel Pégourié-Gonnard | ee68cff | 2018-10-15 15:27:49 +0200 | [diff] [blame] | 346 | /* set up our own sub-context if needed (that is, on first run) */ |
Manuel Pégourié-Gonnard | fe68770 | 2017-08-18 17:04:07 +0200 | [diff] [blame] | 347 | if( rs->ecdsa_ctx.grp.pbits == 0 ) |
| 348 | MBEDTLS_MPI_CHK( mbedtls_ecdsa_from_keypair( &rs->ecdsa_ctx, ctx ) ); |
Manuel Pégourié-Gonnard | 1f59606 | 2017-05-09 10:42:40 +0200 | [diff] [blame] | 349 | |
Manuel Pégourié-Gonnard | fe68770 | 2017-08-18 17:04:07 +0200 | [diff] [blame] | 350 | MBEDTLS_MPI_CHK( ecdsa_verify_rs_wrap( &rs->ecdsa_ctx, |
| 351 | md_alg, hash, hash_len, |
| 352 | sig, sig_len, &rs->ecdsa_rs ) ); |
Manuel Pégourié-Gonnard | 1f59606 | 2017-05-09 10:42:40 +0200 | [diff] [blame] | 353 | |
| 354 | cleanup: |
Manuel Pégourié-Gonnard | 1f59606 | 2017-05-09 10:42:40 +0200 | [diff] [blame] | 355 | return( ret ); |
| 356 | } |
| 357 | |
| 358 | static int eckey_sign_rs_wrap( void *ctx, mbedtls_md_type_t md_alg, |
| 359 | const unsigned char *hash, size_t hash_len, |
| 360 | unsigned char *sig, size_t *sig_len, |
| 361 | int (*f_rng)(void *, unsigned char *, size_t), void *p_rng, |
Manuel Pégourié-Gonnard | fe68770 | 2017-08-18 17:04:07 +0200 | [diff] [blame] | 362 | void *rs_ctx ) |
Manuel Pégourié-Gonnard | 1f59606 | 2017-05-09 10:42:40 +0200 | [diff] [blame] | 363 | { |
| 364 | int ret; |
Manuel Pégourié-Gonnard | fe68770 | 2017-08-18 17:04:07 +0200 | [diff] [blame] | 365 | eckey_restart_ctx *rs = rs_ctx; |
Manuel Pégourié-Gonnard | 1f59606 | 2017-05-09 10:42:40 +0200 | [diff] [blame] | 366 | |
Manuel Pégourié-Gonnard | fe68770 | 2017-08-18 17:04:07 +0200 | [diff] [blame] | 367 | /* Should never happen */ |
| 368 | if( rs == NULL ) |
| 369 | return( MBEDTLS_ERR_PK_BAD_INPUT_DATA ); |
Manuel Pégourié-Gonnard | 1f59606 | 2017-05-09 10:42:40 +0200 | [diff] [blame] | 370 | |
Manuel Pégourié-Gonnard | ee68cff | 2018-10-15 15:27:49 +0200 | [diff] [blame] | 371 | /* set up our own sub-context if needed (that is, on first run) */ |
Manuel Pégourié-Gonnard | fe68770 | 2017-08-18 17:04:07 +0200 | [diff] [blame] | 372 | if( rs->ecdsa_ctx.grp.pbits == 0 ) |
| 373 | MBEDTLS_MPI_CHK( mbedtls_ecdsa_from_keypair( &rs->ecdsa_ctx, ctx ) ); |
Manuel Pégourié-Gonnard | 1f59606 | 2017-05-09 10:42:40 +0200 | [diff] [blame] | 374 | |
Manuel Pégourié-Gonnard | fe68770 | 2017-08-18 17:04:07 +0200 | [diff] [blame] | 375 | MBEDTLS_MPI_CHK( ecdsa_sign_rs_wrap( &rs->ecdsa_ctx, md_alg, |
| 376 | hash, hash_len, sig, sig_len, |
| 377 | f_rng, p_rng, &rs->ecdsa_rs ) ); |
Manuel Pégourié-Gonnard | 1f59606 | 2017-05-09 10:42:40 +0200 | [diff] [blame] | 378 | |
| 379 | cleanup: |
Manuel Pégourié-Gonnard | 1f59606 | 2017-05-09 10:42:40 +0200 | [diff] [blame] | 380 | return( ret ); |
| 381 | } |
| 382 | #endif /* MBEDTLS_ECP_RESTARTABLE */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 383 | #endif /* MBEDTLS_ECDSA_C */ |
Manuel Pégourié-Gonnard | d73b3c1 | 2013-08-12 17:06:05 +0200 | [diff] [blame] | 384 | |
Manuel Pégourié-Gonnard | 70bdadf | 2014-11-06 16:51:20 +0100 | [diff] [blame] | 385 | static int eckey_check_pair( const void *pub, const void *prv ) |
| 386 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 387 | return( mbedtls_ecp_check_pub_priv( (const mbedtls_ecp_keypair *) pub, |
| 388 | (const mbedtls_ecp_keypair *) prv ) ); |
Manuel Pégourié-Gonnard | 70bdadf | 2014-11-06 16:51:20 +0100 | [diff] [blame] | 389 | } |
| 390 | |
Manuel Pégourié-Gonnard | 765db07 | 2013-08-14 15:00:27 +0200 | [diff] [blame] | 391 | static void *eckey_alloc_wrap( void ) |
| 392 | { |
Manuel Pégourié-Gonnard | 7551cb9 | 2015-05-26 16:04:06 +0200 | [diff] [blame] | 393 | void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_ecp_keypair ) ); |
Manuel Pégourié-Gonnard | 765db07 | 2013-08-14 15:00:27 +0200 | [diff] [blame] | 394 | |
| 395 | if( ctx != NULL ) |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 396 | mbedtls_ecp_keypair_init( ctx ); |
Manuel Pégourié-Gonnard | 765db07 | 2013-08-14 15:00:27 +0200 | [diff] [blame] | 397 | |
| 398 | return( ctx ); |
| 399 | } |
| 400 | |
| 401 | static void eckey_free_wrap( void *ctx ) |
| 402 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 403 | mbedtls_ecp_keypair_free( (mbedtls_ecp_keypair *) ctx ); |
| 404 | mbedtls_free( ctx ); |
Manuel Pégourié-Gonnard | 765db07 | 2013-08-14 15:00:27 +0200 | [diff] [blame] | 405 | } |
| 406 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 407 | static void eckey_debug( const void *ctx, mbedtls_pk_debug_item *items ) |
Manuel Pégourié-Gonnard | c6ac887 | 2013-08-14 18:04:18 +0200 | [diff] [blame] | 408 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 409 | items->type = MBEDTLS_PK_DEBUG_ECP; |
Manuel Pégourié-Gonnard | c6ac887 | 2013-08-14 18:04:18 +0200 | [diff] [blame] | 410 | items->name = "eckey.Q"; |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 411 | items->value = &( ((mbedtls_ecp_keypair *) ctx)->Q ); |
Manuel Pégourié-Gonnard | c6ac887 | 2013-08-14 18:04:18 +0200 | [diff] [blame] | 412 | } |
| 413 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 414 | const mbedtls_pk_info_t mbedtls_eckey_info = { |
| 415 | MBEDTLS_PK_ECKEY, |
Manuel Pégourié-Gonnard | f8c948a | 2013-08-12 19:45:32 +0200 | [diff] [blame] | 416 | "EC", |
Manuel Pégourié-Gonnard | 39a48f4 | 2015-06-18 16:06:55 +0200 | [diff] [blame] | 417 | eckey_get_bitlen, |
Manuel Pégourié-Gonnard | f18c3e0 | 2013-08-12 18:41:18 +0200 | [diff] [blame] | 418 | eckey_can_do, |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 419 | #if defined(MBEDTLS_ECDSA_C) |
Manuel Pégourié-Gonnard | d73b3c1 | 2013-08-12 17:06:05 +0200 | [diff] [blame] | 420 | eckey_verify_wrap, |
Manuel Pégourié-Gonnard | 8df2769 | 2013-08-21 10:34:38 +0200 | [diff] [blame] | 421 | eckey_sign_wrap, |
Manuel Pégourié-Gonnard | 1f59606 | 2017-05-09 10:42:40 +0200 | [diff] [blame] | 422 | #if defined(MBEDTLS_ECP_RESTARTABLE) |
| 423 | eckey_verify_rs_wrap, |
| 424 | eckey_sign_rs_wrap, |
| 425 | #endif |
| 426 | #else /* MBEDTLS_ECDSA_C */ |
| 427 | NULL, |
| 428 | NULL, |
Manuel Pégourié-Gonnard | 1f59606 | 2017-05-09 10:42:40 +0200 | [diff] [blame] | 429 | #endif /* MBEDTLS_ECDSA_C */ |
Manuel Pégourié-Gonnard | a2d3f22 | 2013-08-21 11:51:08 +0200 | [diff] [blame] | 430 | NULL, |
| 431 | NULL, |
Manuel Pégourié-Gonnard | 70bdadf | 2014-11-06 16:51:20 +0100 | [diff] [blame] | 432 | eckey_check_pair, |
Manuel Pégourié-Gonnard | 765db07 | 2013-08-14 15:00:27 +0200 | [diff] [blame] | 433 | eckey_alloc_wrap, |
| 434 | eckey_free_wrap, |
Manuel Pégourié-Gonnard | aaa9814 | 2017-08-18 17:30:37 +0200 | [diff] [blame] | 435 | #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE) |
Manuel Pégourié-Gonnard | 0bbc66c | 2017-08-18 16:22:06 +0200 | [diff] [blame] | 436 | eckey_rs_alloc, |
| 437 | eckey_rs_free, |
| 438 | #endif |
Manuel Pégourié-Gonnard | c6ac887 | 2013-08-14 18:04:18 +0200 | [diff] [blame] | 439 | eckey_debug, |
Manuel Pégourié-Gonnard | d73b3c1 | 2013-08-12 17:06:05 +0200 | [diff] [blame] | 440 | }; |
Manuel Pégourié-Gonnard | 835eb59 | 2013-08-12 18:51:26 +0200 | [diff] [blame] | 441 | |
| 442 | /* |
Paul Bakker | 75342a6 | 2014-04-08 17:35:40 +0200 | [diff] [blame] | 443 | * EC key restricted to ECDH |
Manuel Pégourié-Gonnard | 835eb59 | 2013-08-12 18:51:26 +0200 | [diff] [blame] | 444 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 445 | static int eckeydh_can_do( mbedtls_pk_type_t type ) |
Manuel Pégourié-Gonnard | 835eb59 | 2013-08-12 18:51:26 +0200 | [diff] [blame] | 446 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 447 | return( type == MBEDTLS_PK_ECKEY || |
| 448 | type == MBEDTLS_PK_ECKEY_DH ); |
Manuel Pégourié-Gonnard | 835eb59 | 2013-08-12 18:51:26 +0200 | [diff] [blame] | 449 | } |
| 450 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 451 | const mbedtls_pk_info_t mbedtls_eckeydh_info = { |
| 452 | MBEDTLS_PK_ECKEY_DH, |
Manuel Pégourié-Gonnard | f8c948a | 2013-08-12 19:45:32 +0200 | [diff] [blame] | 453 | "EC_DH", |
Manuel Pégourié-Gonnard | 39a48f4 | 2015-06-18 16:06:55 +0200 | [diff] [blame] | 454 | eckey_get_bitlen, /* Same underlying key structure */ |
Manuel Pégourié-Gonnard | 835eb59 | 2013-08-12 18:51:26 +0200 | [diff] [blame] | 455 | eckeydh_can_do, |
Manuel Pégourié-Gonnard | fff80f8 | 2013-08-17 15:20:06 +0200 | [diff] [blame] | 456 | NULL, |
Manuel Pégourié-Gonnard | 8df2769 | 2013-08-21 10:34:38 +0200 | [diff] [blame] | 457 | NULL, |
Manuel Pégourié-Gonnard | aaa9814 | 2017-08-18 17:30:37 +0200 | [diff] [blame] | 458 | #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE) |
Manuel Pégourié-Gonnard | 1f59606 | 2017-05-09 10:42:40 +0200 | [diff] [blame] | 459 | NULL, |
| 460 | NULL, |
| 461 | #endif |
Manuel Pégourié-Gonnard | a2d3f22 | 2013-08-21 11:51:08 +0200 | [diff] [blame] | 462 | NULL, |
| 463 | NULL, |
Manuel Pégourié-Gonnard | 70bdadf | 2014-11-06 16:51:20 +0100 | [diff] [blame] | 464 | eckey_check_pair, |
Manuel Pégourié-Gonnard | 765db07 | 2013-08-14 15:00:27 +0200 | [diff] [blame] | 465 | eckey_alloc_wrap, /* Same underlying key structure */ |
| 466 | eckey_free_wrap, /* Same underlying key structure */ |
Manuel Pégourié-Gonnard | aaa9814 | 2017-08-18 17:30:37 +0200 | [diff] [blame] | 467 | #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE) |
Manuel Pégourié-Gonnard | 0bbc66c | 2017-08-18 16:22:06 +0200 | [diff] [blame] | 468 | NULL, |
| 469 | NULL, |
| 470 | #endif |
Manuel Pégourié-Gonnard | 09162dd | 2013-08-14 18:16:50 +0200 | [diff] [blame] | 471 | eckey_debug, /* Same underlying key structure */ |
Manuel Pégourié-Gonnard | 835eb59 | 2013-08-12 18:51:26 +0200 | [diff] [blame] | 472 | }; |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 473 | #endif /* MBEDTLS_ECP_C */ |
Manuel Pégourié-Gonnard | 09162dd | 2013-08-14 18:16:50 +0200 | [diff] [blame] | 474 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 475 | #if defined(MBEDTLS_ECDSA_C) |
| 476 | static int ecdsa_can_do( mbedtls_pk_type_t type ) |
Manuel Pégourié-Gonnard | 09162dd | 2013-08-14 18:16:50 +0200 | [diff] [blame] | 477 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 478 | return( type == MBEDTLS_PK_ECDSA ); |
Manuel Pégourié-Gonnard | 09162dd | 2013-08-14 18:16:50 +0200 | [diff] [blame] | 479 | } |
| 480 | |
Andrzej Kurek | 8b036a6 | 2018-10-31 05:16:46 -0400 | [diff] [blame] | 481 | #if defined(MBEDTLS_USE_PSA_CRYPTO) |
| 482 | static psa_status_t mbedtls_psa_get_free_key_slot( psa_key_slot_t *key ) |
| 483 | { |
| 484 | for( psa_key_slot_t slot = 1; slot <= 32; slot++ ) |
| 485 | { |
| 486 | if( psa_get_key_information( slot, NULL, NULL ) == PSA_ERROR_EMPTY_SLOT ) |
| 487 | { |
| 488 | *key = slot; |
| 489 | return( PSA_SUCCESS ); |
| 490 | } |
| 491 | } |
| 492 | return( PSA_ERROR_INSUFFICIENT_MEMORY ); |
| 493 | } |
| 494 | |
| 495 | static psa_algorithm_t translate_md_to_psa( mbedtls_md_type_t md_alg ) |
| 496 | { |
| 497 | switch( md_alg ) |
| 498 | { |
| 499 | #if defined(MBEDTLS_MD2_C) |
| 500 | case MBEDTLS_MD_MD2: |
| 501 | return( PSA_ALG_MD2 ); |
| 502 | #endif |
| 503 | #if defined(MBEDTLS_MD4_C) |
| 504 | case MBEDTLS_MD_MD4: |
| 505 | return( PSA_ALG_MD4 ); |
| 506 | #endif |
| 507 | #if defined(MBEDTLS_MD5_C) |
| 508 | case MBEDTLS_MD_MD5: |
| 509 | return( PSA_ALG_MD5 ); |
| 510 | #endif |
| 511 | #if defined(MBEDTLS_SHA1_C) |
| 512 | case MBEDTLS_MD_SHA1: |
| 513 | return( PSA_ALG_SHA_1 ); |
| 514 | #endif |
| 515 | #if defined(MBEDTLS_SHA256_C) |
| 516 | case MBEDTLS_MD_SHA224: |
| 517 | return( PSA_ALG_SHA_224 ); |
| 518 | case MBEDTLS_MD_SHA256: |
| 519 | return( PSA_ALG_SHA_256 ); |
| 520 | #endif |
| 521 | #if defined(MBEDTLS_SHA512_C) |
| 522 | case MBEDTLS_MD_SHA384: |
| 523 | return( PSA_ALG_SHA_384 ); |
| 524 | case MBEDTLS_MD_SHA512: |
| 525 | return( PSA_ALG_SHA_512 ); |
| 526 | #endif |
| 527 | #if defined(MBEDTLS_RIPEMD160_C) |
| 528 | case MBEDTLS_MD_RIPEMD160: |
| 529 | return( PSA_ALG_RIPEMD160 ); |
| 530 | #endif |
| 531 | case MBEDTLS_MD_NONE: // Intentional fallthrough |
| 532 | default: |
| 533 | return( 0 ); |
| 534 | } |
| 535 | } |
| 536 | |
| 537 | /* |
| 538 | * Convert a signature from an ASN.1 sequence of two integers |
| 539 | * to a raw {r,s} buffer. Note: upon a successful call, the caller |
| 540 | * takes ownership of the sig->p buffer. |
| 541 | */ |
| 542 | static int extract_ecdsa_sig( unsigned char **p, const unsigned char *end, |
| 543 | mbedtls_asn1_buf *sig ) |
| 544 | { |
Andrzej Kurek | 3f864c2 | 2018-11-07 09:30:50 -0500 | [diff] [blame^] | 545 | int ret, tag_type; |
| 546 | size_t len_signature, len_partial; |
| 547 | |
Andrzej Kurek | 8b036a6 | 2018-10-31 05:16:46 -0400 | [diff] [blame] | 548 | if( ( end - *p ) < 1 ) |
Andrzej Kurek | 6376d63 | 2018-11-06 08:50:04 -0500 | [diff] [blame] | 549 | { |
Andrzej Kurek | 8b036a6 | 2018-10-31 05:16:46 -0400 | [diff] [blame] | 550 | return( MBEDTLS_ERR_X509_INVALID_SIGNATURE + |
Andrzej Kurek | 6376d63 | 2018-11-06 08:50:04 -0500 | [diff] [blame] | 551 | MBEDTLS_ERR_ASN1_OUT_OF_DATA ); |
| 552 | } |
Andrzej Kurek | 8b036a6 | 2018-10-31 05:16:46 -0400 | [diff] [blame] | 553 | tag_type = **p; |
| 554 | |
Andrzej Kurek | 6376d63 | 2018-11-06 08:50:04 -0500 | [diff] [blame] | 555 | if( ( ret = mbedtls_asn1_get_tag( p, end, &len_partial, |
| 556 | MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 ) |
| 557 | { |
Andrzej Kurek | 8b036a6 | 2018-10-31 05:16:46 -0400 | [diff] [blame] | 558 | return( MBEDTLS_ERR_X509_INVALID_SIGNATURE + ret ); |
| 559 | } |
| 560 | |
| 561 | if( ( ret = mbedtls_asn1_get_tag( p, end, &len_partial, MBEDTLS_ASN1_INTEGER ) ) |
| 562 | != 0 ) |
| 563 | return( ret ); |
| 564 | |
Andrzej Kurek | 6376d63 | 2018-11-06 08:50:04 -0500 | [diff] [blame] | 565 | if( **p == '\0' ) |
| 566 | { |
Andrzej Kurek | 8b036a6 | 2018-10-31 05:16:46 -0400 | [diff] [blame] | 567 | ( *p )++; |
| 568 | len_partial--; |
| 569 | } |
| 570 | |
| 571 | sig->p = mbedtls_calloc( 2, len_partial ); |
Andrzej Kurek | 6376d63 | 2018-11-06 08:50:04 -0500 | [diff] [blame] | 572 | if( sig->p == NULL ) |
Andrzej Kurek | 8b036a6 | 2018-10-31 05:16:46 -0400 | [diff] [blame] | 573 | return( MBEDTLS_ERR_ASN1_ALLOC_FAILED ); |
Andrzej Kurek | 8b036a6 | 2018-10-31 05:16:46 -0400 | [diff] [blame] | 574 | |
| 575 | memcpy( sig->p, *p, len_partial ); |
| 576 | len_signature = len_partial; |
| 577 | ( *p ) += len_partial; |
Andrzej Kurek | ea84233 | 2018-11-07 03:19:08 -0500 | [diff] [blame] | 578 | if( ( ret = mbedtls_asn1_get_tag( p, end, &len_partial, |
| 579 | MBEDTLS_ASN1_INTEGER ) ) != 0 ) |
Andrzej Kurek | 8b036a6 | 2018-10-31 05:16:46 -0400 | [diff] [blame] | 580 | { |
| 581 | mbedtls_free( sig->p ); |
Andrzej Kurek | ea84233 | 2018-11-07 03:19:08 -0500 | [diff] [blame] | 582 | sig->p = NULL; |
Andrzej Kurek | 8b036a6 | 2018-10-31 05:16:46 -0400 | [diff] [blame] | 583 | return( ret ); |
| 584 | } |
| 585 | |
Andrzej Kurek | 6376d63 | 2018-11-06 08:50:04 -0500 | [diff] [blame] | 586 | if( **p == '\0' ) |
| 587 | { |
Andrzej Kurek | 8b036a6 | 2018-10-31 05:16:46 -0400 | [diff] [blame] | 588 | ( *p )++; |
| 589 | len_partial--; |
| 590 | } |
| 591 | |
Andrzej Kurek | 3f864c2 | 2018-11-07 09:30:50 -0500 | [diff] [blame^] | 592 | // Check if both parts are of the same size |
| 593 | if( len_partial != len_signature ) |
| 594 | return( MBEDTLS_ERR_X509_INVALID_SIGNATURE ); |
| 595 | |
Andrzej Kurek | 8b036a6 | 2018-10-31 05:16:46 -0400 | [diff] [blame] | 596 | memcpy( sig->p + len_partial, *p, len_partial ); |
| 597 | len_signature += len_partial; |
| 598 | sig->tag = tag_type; |
| 599 | sig->len = len_signature; |
| 600 | ( *p ) += len_partial; |
| 601 | return( 0 ); |
| 602 | } |
| 603 | |
| 604 | static psa_ecc_curve_t mbedtls_ecc_group_to_psa( mbedtls_ecp_group_id grpid ) |
| 605 | { |
| 606 | switch( grpid ) |
| 607 | { |
| 608 | #if defined(MBEDTLS_ECP_DP_SECP192R1_ENABLED) |
| 609 | case MBEDTLS_ECP_DP_SECP192R1: |
| 610 | return( PSA_ECC_CURVE_SECP192R1 ); |
| 611 | #endif |
| 612 | #if defined(MBEDTLS_ECP_DP_SECP224R1_ENABLED) |
| 613 | case MBEDTLS_ECP_DP_SECP224R1: |
| 614 | return( PSA_ECC_CURVE_SECP224R1 ); |
| 615 | #endif |
| 616 | #if defined(MBEDTLS_ECP_DP_SECP256R1_ENABLED) |
| 617 | case MBEDTLS_ECP_DP_SECP256R1: |
| 618 | return( PSA_ECC_CURVE_SECP256R1 ); |
| 619 | #endif |
| 620 | #if defined(MBEDTLS_ECP_DP_SECP384R1_ENABLED) |
| 621 | case MBEDTLS_ECP_DP_SECP384R1: |
| 622 | return( PSA_ECC_CURVE_SECP384R1 ); |
| 623 | #endif |
| 624 | #if defined(MBEDTLS_ECP_DP_SECP521R1_ENABLED) |
| 625 | case MBEDTLS_ECP_DP_SECP521R1: |
| 626 | return( PSA_ECC_CURVE_SECP521R1 ); |
| 627 | #endif |
| 628 | #if defined(MBEDTLS_ECP_DP_BP256R1_ENABLED) |
| 629 | case MBEDTLS_ECP_DP_BP256R1: |
| 630 | return( PSA_ECC_CURVE_BRAINPOOL_P256R1 ); |
| 631 | #endif |
| 632 | #if defined(MBEDTLS_ECP_DP_BP384R1_ENABLED) |
| 633 | case MBEDTLS_ECP_DP_BP384R1: |
| 634 | return( PSA_ECC_CURVE_BRAINPOOL_P384R1 ); |
| 635 | #endif |
| 636 | #if defined(MBEDTLS_ECP_DP_BP512R1_ENABLED) |
| 637 | case MBEDTLS_ECP_DP_BP512R1: |
| 638 | return( PSA_ECC_CURVE_BRAINPOOL_P512R1 ); |
| 639 | #endif |
| 640 | #if defined(MBEDTLS_ECP_DP_CURVE25519_ENABLED) |
| 641 | case MBEDTLS_ECP_DP_CURVE25519: |
| 642 | return( PSA_ECC_CURVE_CURVE25519 ); |
| 643 | #endif |
| 644 | #if defined(MBEDTLS_ECP_DP_SECP192K1_ENABLED) |
| 645 | case MBEDTLS_ECP_DP_SECP192K1: |
| 646 | return( PSA_ECC_CURVE_SECP192K1 ); |
| 647 | #endif |
| 648 | #if defined(MBEDTLS_ECP_DP_SECP224K1_ENABLED) |
| 649 | case MBEDTLS_ECP_DP_SECP224K1: |
| 650 | return( PSA_ECC_CURVE_SECP224K1 ); |
| 651 | #endif |
| 652 | #if defined(MBEDTLS_ECP_DP_SECP256K1_ENABLED) |
| 653 | case MBEDTLS_ECP_DP_SECP256K1: |
| 654 | return( PSA_ECC_CURVE_SECP256K1 ); |
| 655 | #endif |
| 656 | #if defined(MBEDTLS_ECP_DP_CURVE448_ENABLED) |
| 657 | case MBEDTLS_ECP_DP_CURVE448: |
| 658 | return( PSA_ECC_CURVE_CURVE448 ); |
| 659 | #endif |
| 660 | default: |
| 661 | return( 0 ); |
| 662 | } |
| 663 | } |
| 664 | |
| 665 | static int ecdsa_verify_wrap( void *ctx, mbedtls_md_type_t md_alg, |
| 666 | const unsigned char *hash, size_t hash_len, |
| 667 | const unsigned char *sig, size_t sig_len ) |
| 668 | { |
| 669 | int ret; |
| 670 | psa_key_slot_t key_slot; |
| 671 | psa_key_policy_t policy; |
| 672 | psa_key_type_t psa_type; |
| 673 | mbedtls_pk_context key; |
| 674 | mbedtls_asn1_buf signature; |
| 675 | int key_len; |
Andrzej Kurek | 6376d63 | 2018-11-06 08:50:04 -0500 | [diff] [blame] | 676 | const int buf_len = 30 + 2 * MBEDTLS_ECP_MAX_BYTES; // Equivalent of ECP_PUB_DER_MAX_BYTES |
| 677 | unsigned char buf[buf_len]; |
| 678 | unsigned char *p = (unsigned char*) sig; |
Andrzej Kurek | 8b036a6 | 2018-10-31 05:16:46 -0400 | [diff] [blame] | 679 | mbedtls_pk_info_t pk_info = mbedtls_eckey_info; |
| 680 | psa_algorithm_t psa_sig_md = PSA_ALG_ECDSA( translate_md_to_psa( md_alg ) ); |
| 681 | psa_ecc_curve_t curve = mbedtls_ecc_group_to_psa ( ( (mbedtls_ecdsa_context *) ctx )->grp.id ); |
Andrzej Kurek | 8b036a6 | 2018-10-31 05:16:46 -0400 | [diff] [blame] | 682 | |
Andrzej Kurek | b3d1b12 | 2018-11-07 08:18:52 -0500 | [diff] [blame] | 683 | if( curve == 0 ) |
| 684 | return( MBEDTLS_ERR_PK_BAD_INPUT_DATA ); |
| 685 | |
Andrzej Kurek | 8b036a6 | 2018-10-31 05:16:46 -0400 | [diff] [blame] | 686 | memset( &signature, 0, sizeof( mbedtls_asn1_buf ) ); |
Andrzej Kurek | 8b036a6 | 2018-10-31 05:16:46 -0400 | [diff] [blame] | 687 | key.pk_info = &pk_info; |
| 688 | key.pk_ctx = ctx; |
| 689 | psa_crypto_init(); |
| 690 | |
| 691 | psa_type = PSA_KEY_TYPE_ECC_PUBLIC_KEY( curve ); |
| 692 | |
| 693 | if( extract_ecdsa_sig( &p, p + sig_len, &signature ) != 0 ) |
Andrzej Kurek | ea84233 | 2018-11-07 03:19:08 -0500 | [diff] [blame] | 694 | return( MBEDTLS_ERR_PK_BAD_INPUT_DATA ); |
Andrzej Kurek | 8b036a6 | 2018-10-31 05:16:46 -0400 | [diff] [blame] | 695 | |
Andrzej Kurek | 6376d63 | 2018-11-06 08:50:04 -0500 | [diff] [blame] | 696 | key_len = mbedtls_pk_write_pubkey_der( &key, buf, buf_len ); |
Andrzej Kurek | 8b036a6 | 2018-10-31 05:16:46 -0400 | [diff] [blame] | 697 | if( key_len <= 0 ) |
| 698 | { |
| 699 | ret = MBEDTLS_ERR_PK_BAD_INPUT_DATA; |
| 700 | goto cleanup; |
| 701 | } |
| 702 | |
| 703 | if( mbedtls_psa_get_free_key_slot( &key_slot ) != PSA_SUCCESS ) |
| 704 | { |
| 705 | ret = MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE; |
| 706 | goto cleanup; |
| 707 | } |
| 708 | psa_key_policy_init( &policy ); |
| 709 | psa_key_policy_set_usage( &policy, PSA_KEY_USAGE_VERIFY, psa_sig_md ); |
| 710 | if( psa_set_key_policy( key_slot, &policy ) != PSA_SUCCESS ) |
| 711 | { |
| 712 | ret = MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE; |
| 713 | goto cleanup; |
| 714 | } |
| 715 | |
Andrzej Kurek | 6376d63 | 2018-11-06 08:50:04 -0500 | [diff] [blame] | 716 | if( psa_import_key( key_slot, psa_type, buf+buf_len-key_len, key_len ) |
Andrzej Kurek | 8b036a6 | 2018-10-31 05:16:46 -0400 | [diff] [blame] | 717 | != PSA_SUCCESS ) |
| 718 | { |
| 719 | ret = MBEDTLS_ERR_PK_BAD_INPUT_DATA; |
| 720 | goto cleanup; |
| 721 | } |
| 722 | |
| 723 | if( psa_asymmetric_verify( key_slot, psa_sig_md, |
| 724 | hash, hash_len, |
| 725 | signature.p, signature.len ) |
| 726 | != PSA_SUCCESS ) |
| 727 | { |
| 728 | psa_destroy_key( key_slot ); |
| 729 | ret = MBEDTLS_ERR_ECP_VERIFY_FAILED; |
| 730 | goto cleanup; |
| 731 | } |
| 732 | ret = 0; |
| 733 | psa_destroy_key( key_slot ); |
| 734 | |
| 735 | cleanup: |
| 736 | mbedtls_free( signature.p ); |
| 737 | return( ret ); |
| 738 | } |
| 739 | #else /* MBEDTLS_USE_PSA_CRYPTO */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 740 | static int ecdsa_verify_wrap( void *ctx, mbedtls_md_type_t md_alg, |
Manuel Pégourié-Gonnard | f73da02 | 2013-08-17 14:36:32 +0200 | [diff] [blame] | 741 | const unsigned char *hash, size_t hash_len, |
Manuel Pégourié-Gonnard | 09162dd | 2013-08-14 18:16:50 +0200 | [diff] [blame] | 742 | const unsigned char *sig, size_t sig_len ) |
| 743 | { |
Manuel Pégourié-Gonnard | 2abed84 | 2014-04-08 12:40:15 +0200 | [diff] [blame] | 744 | int ret; |
Manuel Pégourié-Gonnard | f73da02 | 2013-08-17 14:36:32 +0200 | [diff] [blame] | 745 | ((void) md_alg); |
| 746 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 747 | ret = mbedtls_ecdsa_read_signature( (mbedtls_ecdsa_context *) ctx, |
Manuel Pégourié-Gonnard | 2abed84 | 2014-04-08 12:40:15 +0200 | [diff] [blame] | 748 | hash, hash_len, sig, sig_len ); |
| 749 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 750 | if( ret == MBEDTLS_ERR_ECP_SIG_LEN_MISMATCH ) |
| 751 | return( MBEDTLS_ERR_PK_SIG_LEN_MISMATCH ); |
Manuel Pégourié-Gonnard | 2abed84 | 2014-04-08 12:40:15 +0200 | [diff] [blame] | 752 | |
| 753 | return( ret ); |
Manuel Pégourié-Gonnard | 09162dd | 2013-08-14 18:16:50 +0200 | [diff] [blame] | 754 | } |
Andrzej Kurek | 8b036a6 | 2018-10-31 05:16:46 -0400 | [diff] [blame] | 755 | #endif /* MBEDTLS_USE_PSA_CRYPTO */ |
Manuel Pégourié-Gonnard | 09162dd | 2013-08-14 18:16:50 +0200 | [diff] [blame] | 756 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 757 | static int ecdsa_sign_wrap( void *ctx, mbedtls_md_type_t md_alg, |
Manuel Pégourié-Gonnard | 8df2769 | 2013-08-21 10:34:38 +0200 | [diff] [blame] | 758 | const unsigned char *hash, size_t hash_len, |
| 759 | unsigned char *sig, size_t *sig_len, |
| 760 | int (*f_rng)(void *, unsigned char *, size_t), void *p_rng ) |
| 761 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 762 | return( mbedtls_ecdsa_write_signature( (mbedtls_ecdsa_context *) ctx, |
Manuel Pégourié-Gonnard | dfdcac9 | 2015-03-31 11:41:42 +0200 | [diff] [blame] | 763 | md_alg, hash, hash_len, sig, sig_len, f_rng, p_rng ) ); |
Manuel Pégourié-Gonnard | 8df2769 | 2013-08-21 10:34:38 +0200 | [diff] [blame] | 764 | } |
| 765 | |
Manuel Pégourié-Gonnard | 1f59606 | 2017-05-09 10:42:40 +0200 | [diff] [blame] | 766 | #if defined(MBEDTLS_ECP_RESTARTABLE) |
| 767 | static int ecdsa_verify_rs_wrap( void *ctx, mbedtls_md_type_t md_alg, |
| 768 | const unsigned char *hash, size_t hash_len, |
| 769 | const unsigned char *sig, size_t sig_len, |
| 770 | void *rs_ctx ) |
| 771 | { |
| 772 | int ret; |
| 773 | ((void) md_alg); |
| 774 | |
| 775 | ret = mbedtls_ecdsa_read_signature_restartable( |
| 776 | (mbedtls_ecdsa_context *) ctx, |
| 777 | hash, hash_len, sig, sig_len, |
| 778 | (mbedtls_ecdsa_restart_ctx *) rs_ctx ); |
| 779 | |
| 780 | if( ret == MBEDTLS_ERR_ECP_SIG_LEN_MISMATCH ) |
| 781 | return( MBEDTLS_ERR_PK_SIG_LEN_MISMATCH ); |
| 782 | |
| 783 | return( ret ); |
| 784 | } |
| 785 | |
| 786 | static int ecdsa_sign_rs_wrap( void *ctx, mbedtls_md_type_t md_alg, |
| 787 | const unsigned char *hash, size_t hash_len, |
| 788 | unsigned char *sig, size_t *sig_len, |
| 789 | int (*f_rng)(void *, unsigned char *, size_t), void *p_rng, |
| 790 | void *rs_ctx ) |
| 791 | { |
| 792 | return( mbedtls_ecdsa_write_signature_restartable( |
| 793 | (mbedtls_ecdsa_context *) ctx, |
| 794 | md_alg, hash, hash_len, sig, sig_len, f_rng, p_rng, |
| 795 | (mbedtls_ecdsa_restart_ctx *) rs_ctx ) ); |
| 796 | |
| 797 | } |
| 798 | #endif /* MBEDTLS_ECP_RESTARTABLE */ |
| 799 | |
Manuel Pégourié-Gonnard | 09162dd | 2013-08-14 18:16:50 +0200 | [diff] [blame] | 800 | static void *ecdsa_alloc_wrap( void ) |
| 801 | { |
Manuel Pégourié-Gonnard | 7551cb9 | 2015-05-26 16:04:06 +0200 | [diff] [blame] | 802 | void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_ecdsa_context ) ); |
Manuel Pégourié-Gonnard | 09162dd | 2013-08-14 18:16:50 +0200 | [diff] [blame] | 803 | |
| 804 | if( ctx != NULL ) |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 805 | mbedtls_ecdsa_init( (mbedtls_ecdsa_context *) ctx ); |
Manuel Pégourié-Gonnard | 09162dd | 2013-08-14 18:16:50 +0200 | [diff] [blame] | 806 | |
| 807 | return( ctx ); |
| 808 | } |
| 809 | |
| 810 | static void ecdsa_free_wrap( void *ctx ) |
| 811 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 812 | mbedtls_ecdsa_free( (mbedtls_ecdsa_context *) ctx ); |
| 813 | mbedtls_free( ctx ); |
Manuel Pégourié-Gonnard | 09162dd | 2013-08-14 18:16:50 +0200 | [diff] [blame] | 814 | } |
| 815 | |
Manuel Pégourié-Gonnard | fe68770 | 2017-08-18 17:04:07 +0200 | [diff] [blame] | 816 | #if defined(MBEDTLS_ECP_RESTARTABLE) |
| 817 | static void *ecdsa_rs_alloc( void ) |
| 818 | { |
| 819 | void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_ecdsa_restart_ctx ) ); |
| 820 | |
| 821 | if( ctx != NULL ) |
| 822 | mbedtls_ecdsa_restart_init( ctx ); |
| 823 | |
| 824 | return( ctx ); |
| 825 | } |
| 826 | |
| 827 | static void ecdsa_rs_free( void *ctx ) |
| 828 | { |
| 829 | mbedtls_ecdsa_restart_free( ctx ); |
| 830 | mbedtls_free( ctx ); |
| 831 | } |
| 832 | #endif /* MBEDTLS_ECP_RESTARTABLE */ |
| 833 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 834 | const mbedtls_pk_info_t mbedtls_ecdsa_info = { |
| 835 | MBEDTLS_PK_ECDSA, |
Manuel Pégourié-Gonnard | 09162dd | 2013-08-14 18:16:50 +0200 | [diff] [blame] | 836 | "ECDSA", |
Manuel Pégourié-Gonnard | 39a48f4 | 2015-06-18 16:06:55 +0200 | [diff] [blame] | 837 | eckey_get_bitlen, /* Compatible key structures */ |
Manuel Pégourié-Gonnard | 09162dd | 2013-08-14 18:16:50 +0200 | [diff] [blame] | 838 | ecdsa_can_do, |
| 839 | ecdsa_verify_wrap, |
Manuel Pégourié-Gonnard | 8df2769 | 2013-08-21 10:34:38 +0200 | [diff] [blame] | 840 | ecdsa_sign_wrap, |
Manuel Pégourié-Gonnard | 1f59606 | 2017-05-09 10:42:40 +0200 | [diff] [blame] | 841 | #if defined(MBEDTLS_ECP_RESTARTABLE) |
| 842 | ecdsa_verify_rs_wrap, |
| 843 | ecdsa_sign_rs_wrap, |
| 844 | #endif |
Manuel Pégourié-Gonnard | a2d3f22 | 2013-08-21 11:51:08 +0200 | [diff] [blame] | 845 | NULL, |
| 846 | NULL, |
Manuel Pégourié-Gonnard | 70bdadf | 2014-11-06 16:51:20 +0100 | [diff] [blame] | 847 | eckey_check_pair, /* Compatible key structures */ |
Manuel Pégourié-Gonnard | 09162dd | 2013-08-14 18:16:50 +0200 | [diff] [blame] | 848 | ecdsa_alloc_wrap, |
| 849 | ecdsa_free_wrap, |
Manuel Pégourié-Gonnard | 0bbc66c | 2017-08-18 16:22:06 +0200 | [diff] [blame] | 850 | #if defined(MBEDTLS_ECP_RESTARTABLE) |
Manuel Pégourié-Gonnard | fe68770 | 2017-08-18 17:04:07 +0200 | [diff] [blame] | 851 | ecdsa_rs_alloc, |
| 852 | ecdsa_rs_free, |
Manuel Pégourié-Gonnard | 0bbc66c | 2017-08-18 16:22:06 +0200 | [diff] [blame] | 853 | #endif |
Manuel Pégourié-Gonnard | 09162dd | 2013-08-14 18:16:50 +0200 | [diff] [blame] | 854 | eckey_debug, /* Compatible key structures */ |
| 855 | }; |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 856 | #endif /* MBEDTLS_ECDSA_C */ |
Manuel Pégourié-Gonnard | 12c1ff0 | 2013-08-21 12:28:31 +0200 | [diff] [blame] | 857 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 858 | #if defined(MBEDTLS_PK_RSA_ALT_SUPPORT) |
Manuel Pégourié-Gonnard | 12c1ff0 | 2013-08-21 12:28:31 +0200 | [diff] [blame] | 859 | /* |
| 860 | * Support for alternative RSA-private implementations |
| 861 | */ |
| 862 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 863 | static int rsa_alt_can_do( mbedtls_pk_type_t type ) |
Manuel Pégourié-Gonnard | 20422e9 | 2014-06-05 13:41:44 +0200 | [diff] [blame] | 864 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 865 | return( type == MBEDTLS_PK_RSA ); |
Manuel Pégourié-Gonnard | 20422e9 | 2014-06-05 13:41:44 +0200 | [diff] [blame] | 866 | } |
| 867 | |
Manuel Pégourié-Gonnard | 39a48f4 | 2015-06-18 16:06:55 +0200 | [diff] [blame] | 868 | static size_t rsa_alt_get_bitlen( const void *ctx ) |
Manuel Pégourié-Gonnard | 12c1ff0 | 2013-08-21 12:28:31 +0200 | [diff] [blame] | 869 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 870 | const mbedtls_rsa_alt_context *rsa_alt = (const mbedtls_rsa_alt_context *) ctx; |
Manuel Pégourié-Gonnard | 12c1ff0 | 2013-08-21 12:28:31 +0200 | [diff] [blame] | 871 | |
Manuel Pégourié-Gonnard | 0148875 | 2014-04-03 22:09:18 +0200 | [diff] [blame] | 872 | return( 8 * rsa_alt->key_len_func( rsa_alt->key ) ); |
Manuel Pégourié-Gonnard | 12c1ff0 | 2013-08-21 12:28:31 +0200 | [diff] [blame] | 873 | } |
| 874 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 875 | static int rsa_alt_sign_wrap( void *ctx, mbedtls_md_type_t md_alg, |
Manuel Pégourié-Gonnard | 12c1ff0 | 2013-08-21 12:28:31 +0200 | [diff] [blame] | 876 | const unsigned char *hash, size_t hash_len, |
| 877 | unsigned char *sig, size_t *sig_len, |
| 878 | int (*f_rng)(void *, unsigned char *, size_t), void *p_rng ) |
| 879 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 880 | mbedtls_rsa_alt_context *rsa_alt = (mbedtls_rsa_alt_context *) ctx; |
Manuel Pégourié-Gonnard | 12c1ff0 | 2013-08-21 12:28:31 +0200 | [diff] [blame] | 881 | |
Andres Amaya Garcia | 7c02c50 | 2017-08-04 13:32:15 +0100 | [diff] [blame] | 882 | #if SIZE_MAX > UINT_MAX |
Andres AG | 7284987 | 2017-01-19 11:24:33 +0000 | [diff] [blame] | 883 | if( UINT_MAX < hash_len ) |
| 884 | return( MBEDTLS_ERR_PK_BAD_INPUT_DATA ); |
Andres Amaya Garcia | 7c02c50 | 2017-08-04 13:32:15 +0100 | [diff] [blame] | 885 | #endif /* SIZE_MAX > UINT_MAX */ |
Andres AG | 7284987 | 2017-01-19 11:24:33 +0000 | [diff] [blame] | 886 | |
Manuel Pégourié-Gonnard | 12c1ff0 | 2013-08-21 12:28:31 +0200 | [diff] [blame] | 887 | *sig_len = rsa_alt->key_len_func( rsa_alt->key ); |
| 888 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 889 | return( rsa_alt->sign_func( rsa_alt->key, f_rng, p_rng, MBEDTLS_RSA_PRIVATE, |
Paul Bakker | b9cfaa0 | 2013-10-11 18:58:55 +0200 | [diff] [blame] | 890 | md_alg, (unsigned int) hash_len, hash, sig ) ); |
Manuel Pégourié-Gonnard | 12c1ff0 | 2013-08-21 12:28:31 +0200 | [diff] [blame] | 891 | } |
| 892 | |
| 893 | static int rsa_alt_decrypt_wrap( void *ctx, |
| 894 | const unsigned char *input, size_t ilen, |
| 895 | unsigned char *output, size_t *olen, size_t osize, |
| 896 | int (*f_rng)(void *, unsigned char *, size_t), void *p_rng ) |
| 897 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 898 | mbedtls_rsa_alt_context *rsa_alt = (mbedtls_rsa_alt_context *) ctx; |
Manuel Pégourié-Gonnard | 12c1ff0 | 2013-08-21 12:28:31 +0200 | [diff] [blame] | 899 | |
| 900 | ((void) f_rng); |
| 901 | ((void) p_rng); |
| 902 | |
| 903 | if( ilen != rsa_alt->key_len_func( rsa_alt->key ) ) |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 904 | return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA ); |
Manuel Pégourié-Gonnard | 12c1ff0 | 2013-08-21 12:28:31 +0200 | [diff] [blame] | 905 | |
| 906 | return( rsa_alt->decrypt_func( rsa_alt->key, |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 907 | MBEDTLS_RSA_PRIVATE, olen, input, output, osize ) ); |
Manuel Pégourié-Gonnard | 12c1ff0 | 2013-08-21 12:28:31 +0200 | [diff] [blame] | 908 | } |
| 909 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 910 | #if defined(MBEDTLS_RSA_C) |
Manuel Pégourié-Gonnard | a1efcb0 | 2014-11-08 17:08:08 +0100 | [diff] [blame] | 911 | static int rsa_alt_check_pair( const void *pub, const void *prv ) |
| 912 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 913 | unsigned char sig[MBEDTLS_MPI_MAX_SIZE]; |
Manuel Pégourié-Gonnard | a1efcb0 | 2014-11-08 17:08:08 +0100 | [diff] [blame] | 914 | unsigned char hash[32]; |
| 915 | size_t sig_len = 0; |
| 916 | int ret; |
| 917 | |
Manuel Pégourié-Gonnard | 39a48f4 | 2015-06-18 16:06:55 +0200 | [diff] [blame] | 918 | if( rsa_alt_get_bitlen( prv ) != rsa_get_bitlen( pub ) ) |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 919 | return( MBEDTLS_ERR_RSA_KEY_CHECK_FAILED ); |
Manuel Pégourié-Gonnard | a1efcb0 | 2014-11-08 17:08:08 +0100 | [diff] [blame] | 920 | |
| 921 | memset( hash, 0x2a, sizeof( hash ) ); |
| 922 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 923 | if( ( ret = rsa_alt_sign_wrap( (void *) prv, MBEDTLS_MD_NONE, |
Manuel Pégourié-Gonnard | a1efcb0 | 2014-11-08 17:08:08 +0100 | [diff] [blame] | 924 | hash, sizeof( hash ), |
| 925 | sig, &sig_len, NULL, NULL ) ) != 0 ) |
| 926 | { |
| 927 | return( ret ); |
| 928 | } |
| 929 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 930 | if( rsa_verify_wrap( (void *) pub, MBEDTLS_MD_NONE, |
Manuel Pégourié-Gonnard | a1efcb0 | 2014-11-08 17:08:08 +0100 | [diff] [blame] | 931 | hash, sizeof( hash ), sig, sig_len ) != 0 ) |
| 932 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 933 | return( MBEDTLS_ERR_RSA_KEY_CHECK_FAILED ); |
Manuel Pégourié-Gonnard | a1efcb0 | 2014-11-08 17:08:08 +0100 | [diff] [blame] | 934 | } |
| 935 | |
| 936 | return( 0 ); |
| 937 | } |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 938 | #endif /* MBEDTLS_RSA_C */ |
Manuel Pégourié-Gonnard | a1efcb0 | 2014-11-08 17:08:08 +0100 | [diff] [blame] | 939 | |
Manuel Pégourié-Gonnard | 12c1ff0 | 2013-08-21 12:28:31 +0200 | [diff] [blame] | 940 | static void *rsa_alt_alloc_wrap( void ) |
| 941 | { |
Manuel Pégourié-Gonnard | 7551cb9 | 2015-05-26 16:04:06 +0200 | [diff] [blame] | 942 | void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_rsa_alt_context ) ); |
Manuel Pégourié-Gonnard | 12c1ff0 | 2013-08-21 12:28:31 +0200 | [diff] [blame] | 943 | |
| 944 | if( ctx != NULL ) |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 945 | memset( ctx, 0, sizeof( mbedtls_rsa_alt_context ) ); |
Manuel Pégourié-Gonnard | 12c1ff0 | 2013-08-21 12:28:31 +0200 | [diff] [blame] | 946 | |
Paul Bakker | d8bb826 | 2014-06-17 14:06:49 +0200 | [diff] [blame] | 947 | return( ctx ); |
Manuel Pégourié-Gonnard | 12c1ff0 | 2013-08-21 12:28:31 +0200 | [diff] [blame] | 948 | } |
| 949 | |
| 950 | static void rsa_alt_free_wrap( void *ctx ) |
| 951 | { |
Andres Amaya Garcia | 1f6301b | 2018-04-17 09:51:09 -0500 | [diff] [blame] | 952 | mbedtls_platform_zeroize( ctx, sizeof( mbedtls_rsa_alt_context ) ); |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 953 | mbedtls_free( ctx ); |
Manuel Pégourié-Gonnard | 12c1ff0 | 2013-08-21 12:28:31 +0200 | [diff] [blame] | 954 | } |
| 955 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 956 | const mbedtls_pk_info_t mbedtls_rsa_alt_info = { |
| 957 | MBEDTLS_PK_RSA_ALT, |
Manuel Pégourié-Gonnard | 12c1ff0 | 2013-08-21 12:28:31 +0200 | [diff] [blame] | 958 | "RSA-alt", |
Manuel Pégourié-Gonnard | 39a48f4 | 2015-06-18 16:06:55 +0200 | [diff] [blame] | 959 | rsa_alt_get_bitlen, |
Manuel Pégourié-Gonnard | 20422e9 | 2014-06-05 13:41:44 +0200 | [diff] [blame] | 960 | rsa_alt_can_do, |
Manuel Pégourié-Gonnard | 12c1ff0 | 2013-08-21 12:28:31 +0200 | [diff] [blame] | 961 | NULL, |
| 962 | rsa_alt_sign_wrap, |
Manuel Pégourié-Gonnard | aaa9814 | 2017-08-18 17:30:37 +0200 | [diff] [blame] | 963 | #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE) |
Manuel Pégourié-Gonnard | 1f59606 | 2017-05-09 10:42:40 +0200 | [diff] [blame] | 964 | NULL, |
| 965 | NULL, |
| 966 | #endif |
Manuel Pégourié-Gonnard | 12c1ff0 | 2013-08-21 12:28:31 +0200 | [diff] [blame] | 967 | rsa_alt_decrypt_wrap, |
| 968 | NULL, |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 969 | #if defined(MBEDTLS_RSA_C) |
Manuel Pégourié-Gonnard | a1efcb0 | 2014-11-08 17:08:08 +0100 | [diff] [blame] | 970 | rsa_alt_check_pair, |
Manuel Pégourié-Gonnard | 7c13d69 | 2014-11-12 00:01:34 +0100 | [diff] [blame] | 971 | #else |
| 972 | NULL, |
| 973 | #endif |
Manuel Pégourié-Gonnard | 12c1ff0 | 2013-08-21 12:28:31 +0200 | [diff] [blame] | 974 | rsa_alt_alloc_wrap, |
| 975 | rsa_alt_free_wrap, |
Manuel Pégourié-Gonnard | aaa9814 | 2017-08-18 17:30:37 +0200 | [diff] [blame] | 976 | #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE) |
Manuel Pégourié-Gonnard | 0bbc66c | 2017-08-18 16:22:06 +0200 | [diff] [blame] | 977 | NULL, |
| 978 | NULL, |
| 979 | #endif |
Manuel Pégourié-Gonnard | 12c1ff0 | 2013-08-21 12:28:31 +0200 | [diff] [blame] | 980 | NULL, |
| 981 | }; |
Manuel Pégourié-Gonnard | c40b4c3 | 2013-08-22 13:29:31 +0200 | [diff] [blame] | 982 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 983 | #endif /* MBEDTLS_PK_RSA_ALT_SUPPORT */ |
Manuel Pégourié-Gonnard | 348bcb3 | 2015-03-31 14:01:33 +0200 | [diff] [blame] | 984 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 985 | #endif /* MBEDTLS_PK_C */ |