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 | |
Jarno Lamsa | 42b83db | 2019-04-16 16:48:22 +0300 | [diff] [blame] | 36 | #if defined(MBEDTLS_USE_TINYCRYPT) |
Hanno Becker | 496b83f | 2019-08-20 13:33:49 +0100 | [diff] [blame] | 37 | #include "tinycrypt/ecc.h" |
| 38 | #include "tinycrypt/ecc_dsa.h" |
Jarno Lamsa | 42b83db | 2019-04-16 16:48:22 +0300 | [diff] [blame] | 39 | #include "mbedtls/asn1.h" |
| 40 | #include "mbedtls/asn1write.h" |
| 41 | #else |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 42 | #if defined(MBEDTLS_ECP_C) |
Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 43 | #include "mbedtls/ecp.h" |
Manuel Pégourié-Gonnard | d73b3c1 | 2013-08-12 17:06:05 +0200 | [diff] [blame] | 44 | #endif |
| 45 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 46 | #if defined(MBEDTLS_ECDSA_C) |
Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 47 | #include "mbedtls/ecdsa.h" |
Manuel Pégourié-Gonnard | d73b3c1 | 2013-08-12 17:06:05 +0200 | [diff] [blame] | 48 | #endif |
Jarno Lamsa | 42b83db | 2019-04-16 16:48:22 +0300 | [diff] [blame] | 49 | #endif /* MBEDTLS_USE_TINYCRYPT */ |
Manuel Pégourié-Gonnard | d73b3c1 | 2013-08-12 17:06:05 +0200 | [diff] [blame] | 50 | |
Andres Amaya Garcia | e32df08 | 2017-10-25 09:37:04 +0100 | [diff] [blame] | 51 | #if defined(MBEDTLS_PK_RSA_ALT_SUPPORT) |
Andres Amaya Garcia | 1f6301b | 2018-04-17 09:51:09 -0500 | [diff] [blame] | 52 | #include "mbedtls/platform_util.h" |
Andres Amaya Garcia | e32df08 | 2017-10-25 09:37:04 +0100 | [diff] [blame] | 53 | #endif |
| 54 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 55 | #if defined(MBEDTLS_PLATFORM_C) |
Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 56 | #include "mbedtls/platform.h" |
Manuel Pégourié-Gonnard | 765db07 | 2013-08-14 15:00:27 +0200 | [diff] [blame] | 57 | #else |
| 58 | #include <stdlib.h> |
Manuel Pégourié-Gonnard | 7551cb9 | 2015-05-26 16:04:06 +0200 | [diff] [blame] | 59 | #define mbedtls_calloc calloc |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 60 | #define mbedtls_free free |
Manuel Pégourié-Gonnard | 765db07 | 2013-08-14 15:00:27 +0200 | [diff] [blame] | 61 | #endif |
| 62 | |
Andres AG | 7284987 | 2017-01-19 11:24:33 +0000 | [diff] [blame] | 63 | #include <limits.h> |
Andres Amaya Garcia | 7c02c50 | 2017-08-04 13:32:15 +0100 | [diff] [blame] | 64 | #include <stdint.h> |
Paul Bakker | 3461772 | 2014-06-13 17:20:13 +0200 | [diff] [blame] | 65 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 66 | #if defined(MBEDTLS_RSA_C) |
| 67 | static int rsa_can_do( mbedtls_pk_type_t type ) |
Manuel Pégourié-Gonnard | f18c3e0 | 2013-08-12 18:41:18 +0200 | [diff] [blame] | 68 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 69 | return( type == MBEDTLS_PK_RSA || |
| 70 | type == MBEDTLS_PK_RSASSA_PSS ); |
Manuel Pégourié-Gonnard | f18c3e0 | 2013-08-12 18:41:18 +0200 | [diff] [blame] | 71 | } |
| 72 | |
Manuel Pégourié-Gonnard | 39a48f4 | 2015-06-18 16:06:55 +0200 | [diff] [blame] | 73 | static size_t rsa_get_bitlen( const void *ctx ) |
Manuel Pégourié-Gonnard | f8c948a | 2013-08-12 19:45:32 +0200 | [diff] [blame] | 74 | { |
Hanno Becker | 6a1e7e5 | 2017-08-22 13:55:00 +0100 | [diff] [blame] | 75 | const mbedtls_rsa_context * rsa = (const mbedtls_rsa_context *) ctx; |
| 76 | return( 8 * mbedtls_rsa_get_len( rsa ) ); |
Manuel Pégourié-Gonnard | f8c948a | 2013-08-12 19:45:32 +0200 | [diff] [blame] | 77 | } |
| 78 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 79 | 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] | 80 | const unsigned char *hash, size_t hash_len, |
Manuel Pégourié-Gonnard | d73b3c1 | 2013-08-12 17:06:05 +0200 | [diff] [blame] | 81 | const unsigned char *sig, size_t sig_len ) |
| 82 | { |
Manuel Pégourié-Gonnard | 2abed84 | 2014-04-08 12:40:15 +0200 | [diff] [blame] | 83 | int ret; |
Hanno Becker | 6a1e7e5 | 2017-08-22 13:55:00 +0100 | [diff] [blame] | 84 | mbedtls_rsa_context * rsa = (mbedtls_rsa_context *) ctx; |
| 85 | size_t rsa_len = mbedtls_rsa_get_len( rsa ); |
Manuel Pégourié-Gonnard | 2abed84 | 2014-04-08 12:40:15 +0200 | [diff] [blame] | 86 | |
Andres Amaya Garcia | 7c02c50 | 2017-08-04 13:32:15 +0100 | [diff] [blame] | 87 | #if SIZE_MAX > UINT_MAX |
Andres AG | 7284987 | 2017-01-19 11:24:33 +0000 | [diff] [blame] | 88 | if( md_alg == MBEDTLS_MD_NONE && UINT_MAX < hash_len ) |
| 89 | return( MBEDTLS_ERR_PK_BAD_INPUT_DATA ); |
Andres Amaya Garcia | 7c02c50 | 2017-08-04 13:32:15 +0100 | [diff] [blame] | 90 | #endif /* SIZE_MAX > UINT_MAX */ |
Andres AG | 7284987 | 2017-01-19 11:24:33 +0000 | [diff] [blame] | 91 | |
Hanno Becker | 6a1e7e5 | 2017-08-22 13:55:00 +0100 | [diff] [blame] | 92 | if( sig_len < rsa_len ) |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 93 | return( MBEDTLS_ERR_RSA_VERIFY_FAILED ); |
Manuel Pégourié-Gonnard | d73b3c1 | 2013-08-12 17:06:05 +0200 | [diff] [blame] | 94 | |
Hanno Becker | 6a1e7e5 | 2017-08-22 13:55:00 +0100 | [diff] [blame] | 95 | if( ( ret = mbedtls_rsa_pkcs1_verify( rsa, NULL, NULL, |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 96 | MBEDTLS_RSA_PUBLIC, md_alg, |
Manuel Pégourié-Gonnard | 2abed84 | 2014-04-08 12:40:15 +0200 | [diff] [blame] | 97 | (unsigned int) hash_len, hash, sig ) ) != 0 ) |
| 98 | return( ret ); |
| 99 | |
Gilles Peskine | 5114d3e | 2018-03-30 07:12:15 +0200 | [diff] [blame] | 100 | /* The buffer contains a valid signature followed by extra data. |
| 101 | * We have a special error code for that so that so that callers can |
| 102 | * use mbedtls_pk_verify() to check "Does the buffer start with a |
| 103 | * valid signature?" and not just "Does the buffer contain a valid |
| 104 | * signature?". */ |
Hanno Becker | 6a1e7e5 | 2017-08-22 13:55:00 +0100 | [diff] [blame] | 105 | if( sig_len > rsa_len ) |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 106 | return( MBEDTLS_ERR_PK_SIG_LEN_MISMATCH ); |
Manuel Pégourié-Gonnard | 2abed84 | 2014-04-08 12:40:15 +0200 | [diff] [blame] | 107 | |
| 108 | return( 0 ); |
Manuel Pégourié-Gonnard | d73b3c1 | 2013-08-12 17:06:05 +0200 | [diff] [blame] | 109 | } |
| 110 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 111 | 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] | 112 | const unsigned char *hash, size_t hash_len, |
| 113 | unsigned char *sig, size_t *sig_len, |
| 114 | int (*f_rng)(void *, unsigned char *, size_t), void *p_rng ) |
| 115 | { |
Hanno Becker | 6a1e7e5 | 2017-08-22 13:55:00 +0100 | [diff] [blame] | 116 | mbedtls_rsa_context * rsa = (mbedtls_rsa_context *) ctx; |
| 117 | |
Andres Amaya Garcia | 7c02c50 | 2017-08-04 13:32:15 +0100 | [diff] [blame] | 118 | #if SIZE_MAX > UINT_MAX |
Andres AG | 7284987 | 2017-01-19 11:24:33 +0000 | [diff] [blame] | 119 | if( md_alg == MBEDTLS_MD_NONE && UINT_MAX < hash_len ) |
| 120 | return( MBEDTLS_ERR_PK_BAD_INPUT_DATA ); |
Andres Amaya Garcia | 7c02c50 | 2017-08-04 13:32:15 +0100 | [diff] [blame] | 121 | #endif /* SIZE_MAX > UINT_MAX */ |
Andres AG | 7284987 | 2017-01-19 11:24:33 +0000 | [diff] [blame] | 122 | |
Hanno Becker | 6a1e7e5 | 2017-08-22 13:55:00 +0100 | [diff] [blame] | 123 | *sig_len = mbedtls_rsa_get_len( rsa ); |
Manuel Pégourié-Gonnard | 8df2769 | 2013-08-21 10:34:38 +0200 | [diff] [blame] | 124 | |
Hanno Becker | 6a1e7e5 | 2017-08-22 13:55:00 +0100 | [diff] [blame] | 125 | 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] | 126 | md_alg, (unsigned int) hash_len, hash, sig ) ); |
Manuel Pégourié-Gonnard | 8df2769 | 2013-08-21 10:34:38 +0200 | [diff] [blame] | 127 | } |
| 128 | |
Manuel Pégourié-Gonnard | a2d3f22 | 2013-08-21 11:51:08 +0200 | [diff] [blame] | 129 | static int rsa_decrypt_wrap( void *ctx, |
| 130 | const unsigned char *input, size_t ilen, |
| 131 | unsigned char *output, size_t *olen, size_t osize, |
| 132 | int (*f_rng)(void *, unsigned char *, size_t), void *p_rng ) |
| 133 | { |
Hanno Becker | 6a1e7e5 | 2017-08-22 13:55:00 +0100 | [diff] [blame] | 134 | mbedtls_rsa_context * rsa = (mbedtls_rsa_context *) ctx; |
| 135 | |
| 136 | if( ilen != mbedtls_rsa_get_len( rsa ) ) |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 137 | return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA ); |
Manuel Pégourié-Gonnard | a2d3f22 | 2013-08-21 11:51:08 +0200 | [diff] [blame] | 138 | |
Hanno Becker | 6a1e7e5 | 2017-08-22 13:55:00 +0100 | [diff] [blame] | 139 | return( mbedtls_rsa_pkcs1_decrypt( rsa, f_rng, p_rng, |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 140 | MBEDTLS_RSA_PRIVATE, olen, input, output, osize ) ); |
Manuel Pégourié-Gonnard | a2d3f22 | 2013-08-21 11:51:08 +0200 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | static int rsa_encrypt_wrap( void *ctx, |
| 144 | const unsigned char *input, size_t ilen, |
| 145 | unsigned char *output, size_t *olen, size_t osize, |
| 146 | int (*f_rng)(void *, unsigned char *, size_t), void *p_rng ) |
| 147 | { |
Hanno Becker | 6a1e7e5 | 2017-08-22 13:55:00 +0100 | [diff] [blame] | 148 | mbedtls_rsa_context * rsa = (mbedtls_rsa_context *) ctx; |
| 149 | *olen = mbedtls_rsa_get_len( rsa ); |
Manuel Pégourié-Gonnard | a2d3f22 | 2013-08-21 11:51:08 +0200 | [diff] [blame] | 150 | |
Manuel Pégourié-Gonnard | a1efcb0 | 2014-11-08 17:08:08 +0100 | [diff] [blame] | 151 | if( *olen > osize ) |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 152 | return( MBEDTLS_ERR_RSA_OUTPUT_TOO_LARGE ); |
Manuel Pégourié-Gonnard | a1efcb0 | 2014-11-08 17:08:08 +0100 | [diff] [blame] | 153 | |
Hanno Becker | 6a1e7e5 | 2017-08-22 13:55:00 +0100 | [diff] [blame] | 154 | return( mbedtls_rsa_pkcs1_encrypt( rsa, f_rng, p_rng, MBEDTLS_RSA_PUBLIC, |
| 155 | ilen, input, output ) ); |
Manuel Pégourié-Gonnard | a2d3f22 | 2013-08-21 11:51:08 +0200 | [diff] [blame] | 156 | } |
| 157 | |
Manuel Pégourié-Gonnard | 70bdadf | 2014-11-06 16:51:20 +0100 | [diff] [blame] | 158 | static int rsa_check_pair_wrap( const void *pub, const void *prv ) |
| 159 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 160 | return( mbedtls_rsa_check_pub_priv( (const mbedtls_rsa_context *) pub, |
| 161 | (const mbedtls_rsa_context *) prv ) ); |
Manuel Pégourié-Gonnard | 70bdadf | 2014-11-06 16:51:20 +0100 | [diff] [blame] | 162 | } |
| 163 | |
Manuel Pégourié-Gonnard | 765db07 | 2013-08-14 15:00:27 +0200 | [diff] [blame] | 164 | static void *rsa_alloc_wrap( void ) |
| 165 | { |
Manuel Pégourié-Gonnard | 7551cb9 | 2015-05-26 16:04:06 +0200 | [diff] [blame] | 166 | void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_rsa_context ) ); |
Manuel Pégourié-Gonnard | 765db07 | 2013-08-14 15:00:27 +0200 | [diff] [blame] | 167 | |
| 168 | if( ctx != NULL ) |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 169 | mbedtls_rsa_init( (mbedtls_rsa_context *) ctx, 0, 0 ); |
Manuel Pégourié-Gonnard | 765db07 | 2013-08-14 15:00:27 +0200 | [diff] [blame] | 170 | |
Paul Bakker | d8bb826 | 2014-06-17 14:06:49 +0200 | [diff] [blame] | 171 | return( ctx ); |
Manuel Pégourié-Gonnard | 765db07 | 2013-08-14 15:00:27 +0200 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | static void rsa_free_wrap( void *ctx ) |
| 175 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 176 | mbedtls_rsa_free( (mbedtls_rsa_context *) ctx ); |
| 177 | mbedtls_free( ctx ); |
Manuel Pégourié-Gonnard | 765db07 | 2013-08-14 15:00:27 +0200 | [diff] [blame] | 178 | } |
| 179 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 180 | 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] | 181 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 182 | items->type = MBEDTLS_PK_DEBUG_MPI; |
Manuel Pégourié-Gonnard | c6ac887 | 2013-08-14 18:04:18 +0200 | [diff] [blame] | 183 | items->name = "rsa.N"; |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 184 | items->value = &( ((mbedtls_rsa_context *) ctx)->N ); |
Manuel Pégourié-Gonnard | c6ac887 | 2013-08-14 18:04:18 +0200 | [diff] [blame] | 185 | |
| 186 | items++; |
| 187 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 188 | items->type = MBEDTLS_PK_DEBUG_MPI; |
Manuel Pégourié-Gonnard | c6ac887 | 2013-08-14 18:04:18 +0200 | [diff] [blame] | 189 | items->name = "rsa.E"; |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 190 | items->value = &( ((mbedtls_rsa_context *) ctx)->E ); |
Manuel Pégourié-Gonnard | c6ac887 | 2013-08-14 18:04:18 +0200 | [diff] [blame] | 191 | } |
| 192 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 193 | const mbedtls_pk_info_t mbedtls_rsa_info = { |
| 194 | MBEDTLS_PK_RSA, |
Manuel Pégourié-Gonnard | f8c948a | 2013-08-12 19:45:32 +0200 | [diff] [blame] | 195 | "RSA", |
Manuel Pégourié-Gonnard | 39a48f4 | 2015-06-18 16:06:55 +0200 | [diff] [blame] | 196 | rsa_get_bitlen, |
Manuel Pégourié-Gonnard | f18c3e0 | 2013-08-12 18:41:18 +0200 | [diff] [blame] | 197 | rsa_can_do, |
Manuel Pégourié-Gonnard | d73b3c1 | 2013-08-12 17:06:05 +0200 | [diff] [blame] | 198 | rsa_verify_wrap, |
Manuel Pégourié-Gonnard | 8df2769 | 2013-08-21 10:34:38 +0200 | [diff] [blame] | 199 | rsa_sign_wrap, |
Manuel Pégourié-Gonnard | aaa9814 | 2017-08-18 17:30:37 +0200 | [diff] [blame] | 200 | #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE) |
Manuel Pégourié-Gonnard | 1f59606 | 2017-05-09 10:42:40 +0200 | [diff] [blame] | 201 | NULL, |
| 202 | NULL, |
| 203 | #endif |
Manuel Pégourié-Gonnard | a2d3f22 | 2013-08-21 11:51:08 +0200 | [diff] [blame] | 204 | rsa_decrypt_wrap, |
| 205 | rsa_encrypt_wrap, |
Manuel Pégourié-Gonnard | 70bdadf | 2014-11-06 16:51:20 +0100 | [diff] [blame] | 206 | rsa_check_pair_wrap, |
Manuel Pégourié-Gonnard | 765db07 | 2013-08-14 15:00:27 +0200 | [diff] [blame] | 207 | rsa_alloc_wrap, |
| 208 | rsa_free_wrap, |
Manuel Pégourié-Gonnard | aaa9814 | 2017-08-18 17:30:37 +0200 | [diff] [blame] | 209 | #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE) |
Manuel Pégourié-Gonnard | 0bbc66c | 2017-08-18 16:22:06 +0200 | [diff] [blame] | 210 | NULL, |
| 211 | NULL, |
| 212 | #endif |
Manuel Pégourié-Gonnard | c6ac887 | 2013-08-14 18:04:18 +0200 | [diff] [blame] | 213 | rsa_debug, |
Manuel Pégourié-Gonnard | d73b3c1 | 2013-08-12 17:06:05 +0200 | [diff] [blame] | 214 | }; |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 215 | #endif /* MBEDTLS_RSA_C */ |
Manuel Pégourié-Gonnard | d73b3c1 | 2013-08-12 17:06:05 +0200 | [diff] [blame] | 216 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 217 | #if defined(MBEDTLS_ECP_C) |
Manuel Pégourié-Gonnard | 835eb59 | 2013-08-12 18:51:26 +0200 | [diff] [blame] | 218 | /* |
| 219 | * Generic EC key |
| 220 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 221 | static int eckey_can_do( mbedtls_pk_type_t type ) |
Manuel Pégourié-Gonnard | f18c3e0 | 2013-08-12 18:41:18 +0200 | [diff] [blame] | 222 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 223 | return( type == MBEDTLS_PK_ECKEY || |
| 224 | type == MBEDTLS_PK_ECKEY_DH || |
| 225 | type == MBEDTLS_PK_ECDSA ); |
Manuel Pégourié-Gonnard | f18c3e0 | 2013-08-12 18:41:18 +0200 | [diff] [blame] | 226 | } |
| 227 | |
Manuel Pégourié-Gonnard | 39a48f4 | 2015-06-18 16:06:55 +0200 | [diff] [blame] | 228 | static size_t eckey_get_bitlen( const void *ctx ) |
Manuel Pégourié-Gonnard | f8c948a | 2013-08-12 19:45:32 +0200 | [diff] [blame] | 229 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 230 | return( ((mbedtls_ecp_keypair *) ctx)->grp.pbits ); |
Manuel Pégourié-Gonnard | f8c948a | 2013-08-12 19:45:32 +0200 | [diff] [blame] | 231 | } |
| 232 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 233 | #if defined(MBEDTLS_ECDSA_C) |
Manuel Pégourié-Gonnard | 8df2769 | 2013-08-21 10:34:38 +0200 | [diff] [blame] | 234 | /* Forward declarations */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 235 | 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] | 236 | const unsigned char *hash, size_t hash_len, |
Manuel Pégourié-Gonnard | 09162dd | 2013-08-14 18:16:50 +0200 | [diff] [blame] | 237 | const unsigned char *sig, size_t sig_len ); |
Manuel Pégourié-Gonnard | 09162dd | 2013-08-14 18:16:50 +0200 | [diff] [blame] | 238 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 239 | 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] | 240 | const unsigned char *hash, size_t hash_len, |
| 241 | unsigned char *sig, size_t *sig_len, |
| 242 | int (*f_rng)(void *, unsigned char *, size_t), void *p_rng ); |
| 243 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 244 | 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] | 245 | const unsigned char *hash, size_t hash_len, |
Manuel Pégourié-Gonnard | d73b3c1 | 2013-08-12 17:06:05 +0200 | [diff] [blame] | 246 | const unsigned char *sig, size_t sig_len ) |
| 247 | { |
Manuel Pégourié-Gonnard | d73b3c1 | 2013-08-12 17:06:05 +0200 | [diff] [blame] | 248 | int ret; |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 249 | mbedtls_ecdsa_context ecdsa; |
Manuel Pégourié-Gonnard | d73b3c1 | 2013-08-12 17:06:05 +0200 | [diff] [blame] | 250 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 251 | mbedtls_ecdsa_init( &ecdsa ); |
Manuel Pégourié-Gonnard | d73b3c1 | 2013-08-12 17:06:05 +0200 | [diff] [blame] | 252 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 253 | if( ( ret = mbedtls_ecdsa_from_keypair( &ecdsa, ctx ) ) == 0 ) |
Manuel Pégourié-Gonnard | 583b608 | 2013-08-20 16:58:13 +0200 | [diff] [blame] | 254 | 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] | 255 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 256 | mbedtls_ecdsa_free( &ecdsa ); |
Manuel Pégourié-Gonnard | d73b3c1 | 2013-08-12 17:06:05 +0200 | [diff] [blame] | 257 | |
| 258 | return( ret ); |
Manuel Pégourié-Gonnard | d73b3c1 | 2013-08-12 17:06:05 +0200 | [diff] [blame] | 259 | } |
Manuel Pégourié-Gonnard | 8df2769 | 2013-08-21 10:34:38 +0200 | [diff] [blame] | 260 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 261 | 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] | 262 | const unsigned char *hash, size_t hash_len, |
| 263 | unsigned char *sig, size_t *sig_len, |
| 264 | int (*f_rng)(void *, unsigned char *, size_t), void *p_rng ) |
| 265 | { |
| 266 | int ret; |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 267 | mbedtls_ecdsa_context ecdsa; |
Manuel Pégourié-Gonnard | 8df2769 | 2013-08-21 10:34:38 +0200 | [diff] [blame] | 268 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 269 | mbedtls_ecdsa_init( &ecdsa ); |
Manuel Pégourié-Gonnard | 8df2769 | 2013-08-21 10:34:38 +0200 | [diff] [blame] | 270 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 271 | if( ( ret = mbedtls_ecdsa_from_keypair( &ecdsa, ctx ) ) == 0 ) |
Manuel Pégourié-Gonnard | 8df2769 | 2013-08-21 10:34:38 +0200 | [diff] [blame] | 272 | ret = ecdsa_sign_wrap( &ecdsa, md_alg, hash, hash_len, sig, sig_len, |
| 273 | f_rng, p_rng ); |
| 274 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 275 | mbedtls_ecdsa_free( &ecdsa ); |
Manuel Pégourié-Gonnard | 8df2769 | 2013-08-21 10:34:38 +0200 | [diff] [blame] | 276 | |
| 277 | return( ret ); |
| 278 | } |
| 279 | |
Manuel Pégourié-Gonnard | 1f59606 | 2017-05-09 10:42:40 +0200 | [diff] [blame] | 280 | #if defined(MBEDTLS_ECP_RESTARTABLE) |
| 281 | /* Forward declarations */ |
| 282 | static int ecdsa_verify_rs_wrap( void *ctx, mbedtls_md_type_t md_alg, |
| 283 | const unsigned char *hash, size_t hash_len, |
| 284 | const unsigned char *sig, size_t sig_len, |
| 285 | void *rs_ctx ); |
| 286 | |
| 287 | static int ecdsa_sign_rs_wrap( void *ctx, mbedtls_md_type_t md_alg, |
| 288 | const unsigned char *hash, size_t hash_len, |
| 289 | unsigned char *sig, size_t *sig_len, |
| 290 | int (*f_rng)(void *, unsigned char *, size_t), void *p_rng, |
| 291 | void *rs_ctx ); |
| 292 | |
Manuel Pégourié-Gonnard | fe68770 | 2017-08-18 17:04:07 +0200 | [diff] [blame] | 293 | /* |
| 294 | * Restart context for ECDSA operations with ECKEY context |
| 295 | * |
| 296 | * We need to store an actual ECDSA context, as we need to pass the same to |
| 297 | * the underlying ecdsa function, so we can't create it on the fly every time. |
| 298 | */ |
| 299 | typedef struct |
| 300 | { |
| 301 | mbedtls_ecdsa_restart_ctx ecdsa_rs; |
| 302 | mbedtls_ecdsa_context ecdsa_ctx; |
| 303 | } eckey_restart_ctx; |
| 304 | |
| 305 | static void *eckey_rs_alloc( void ) |
| 306 | { |
| 307 | eckey_restart_ctx *rs_ctx; |
| 308 | |
| 309 | void *ctx = mbedtls_calloc( 1, sizeof( eckey_restart_ctx ) ); |
| 310 | |
| 311 | if( ctx != NULL ) |
| 312 | { |
| 313 | rs_ctx = ctx; |
| 314 | mbedtls_ecdsa_restart_init( &rs_ctx->ecdsa_rs ); |
| 315 | mbedtls_ecdsa_init( &rs_ctx->ecdsa_ctx ); |
| 316 | } |
| 317 | |
| 318 | return( ctx ); |
| 319 | } |
| 320 | |
| 321 | static void eckey_rs_free( void *ctx ) |
| 322 | { |
| 323 | eckey_restart_ctx *rs_ctx; |
| 324 | |
| 325 | if( ctx == NULL) |
| 326 | return; |
| 327 | |
| 328 | rs_ctx = ctx; |
| 329 | mbedtls_ecdsa_restart_free( &rs_ctx->ecdsa_rs ); |
| 330 | mbedtls_ecdsa_free( &rs_ctx->ecdsa_ctx ); |
| 331 | |
| 332 | mbedtls_free( ctx ); |
| 333 | } |
| 334 | |
Manuel Pégourié-Gonnard | 1f59606 | 2017-05-09 10:42:40 +0200 | [diff] [blame] | 335 | static int eckey_verify_rs_wrap( void *ctx, mbedtls_md_type_t md_alg, |
| 336 | const unsigned char *hash, size_t hash_len, |
| 337 | const unsigned char *sig, size_t sig_len, |
Manuel Pégourié-Gonnard | fe68770 | 2017-08-18 17:04:07 +0200 | [diff] [blame] | 338 | void *rs_ctx ) |
Manuel Pégourié-Gonnard | 1f59606 | 2017-05-09 10:42:40 +0200 | [diff] [blame] | 339 | { |
| 340 | int ret; |
Manuel Pégourié-Gonnard | fe68770 | 2017-08-18 17:04:07 +0200 | [diff] [blame] | 341 | eckey_restart_ctx *rs = rs_ctx; |
Manuel Pégourié-Gonnard | 1f59606 | 2017-05-09 10:42:40 +0200 | [diff] [blame] | 342 | |
Manuel Pégourié-Gonnard | fe68770 | 2017-08-18 17:04:07 +0200 | [diff] [blame] | 343 | /* Should never happen */ |
| 344 | if( rs == NULL ) |
| 345 | return( MBEDTLS_ERR_PK_BAD_INPUT_DATA ); |
Manuel Pégourié-Gonnard | 1f59606 | 2017-05-09 10:42:40 +0200 | [diff] [blame] | 346 | |
Manuel Pégourié-Gonnard | ee68cff | 2018-10-15 15:27:49 +0200 | [diff] [blame] | 347 | /* 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] | 348 | if( rs->ecdsa_ctx.grp.pbits == 0 ) |
| 349 | 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] | 350 | |
Manuel Pégourié-Gonnard | fe68770 | 2017-08-18 17:04:07 +0200 | [diff] [blame] | 351 | MBEDTLS_MPI_CHK( ecdsa_verify_rs_wrap( &rs->ecdsa_ctx, |
| 352 | md_alg, hash, hash_len, |
| 353 | sig, sig_len, &rs->ecdsa_rs ) ); |
Manuel Pégourié-Gonnard | 1f59606 | 2017-05-09 10:42:40 +0200 | [diff] [blame] | 354 | |
| 355 | cleanup: |
Manuel Pégourié-Gonnard | 1f59606 | 2017-05-09 10:42:40 +0200 | [diff] [blame] | 356 | return( ret ); |
| 357 | } |
| 358 | |
| 359 | static int eckey_sign_rs_wrap( void *ctx, mbedtls_md_type_t md_alg, |
| 360 | const unsigned char *hash, size_t hash_len, |
| 361 | unsigned char *sig, size_t *sig_len, |
| 362 | 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] | 363 | void *rs_ctx ) |
Manuel Pégourié-Gonnard | 1f59606 | 2017-05-09 10:42:40 +0200 | [diff] [blame] | 364 | { |
| 365 | int ret; |
Manuel Pégourié-Gonnard | fe68770 | 2017-08-18 17:04:07 +0200 | [diff] [blame] | 366 | eckey_restart_ctx *rs = rs_ctx; |
Manuel Pégourié-Gonnard | 1f59606 | 2017-05-09 10:42:40 +0200 | [diff] [blame] | 367 | |
Manuel Pégourié-Gonnard | fe68770 | 2017-08-18 17:04:07 +0200 | [diff] [blame] | 368 | /* Should never happen */ |
| 369 | if( rs == NULL ) |
| 370 | return( MBEDTLS_ERR_PK_BAD_INPUT_DATA ); |
Manuel Pégourié-Gonnard | 1f59606 | 2017-05-09 10:42:40 +0200 | [diff] [blame] | 371 | |
Manuel Pégourié-Gonnard | ee68cff | 2018-10-15 15:27:49 +0200 | [diff] [blame] | 372 | /* 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] | 373 | if( rs->ecdsa_ctx.grp.pbits == 0 ) |
| 374 | 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] | 375 | |
Manuel Pégourié-Gonnard | fe68770 | 2017-08-18 17:04:07 +0200 | [diff] [blame] | 376 | MBEDTLS_MPI_CHK( ecdsa_sign_rs_wrap( &rs->ecdsa_ctx, md_alg, |
| 377 | hash, hash_len, sig, sig_len, |
| 378 | f_rng, p_rng, &rs->ecdsa_rs ) ); |
Manuel Pégourié-Gonnard | 1f59606 | 2017-05-09 10:42:40 +0200 | [diff] [blame] | 379 | |
| 380 | cleanup: |
Manuel Pégourié-Gonnard | 1f59606 | 2017-05-09 10:42:40 +0200 | [diff] [blame] | 381 | return( ret ); |
| 382 | } |
| 383 | #endif /* MBEDTLS_ECP_RESTARTABLE */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 384 | #endif /* MBEDTLS_ECDSA_C */ |
Manuel Pégourié-Gonnard | d73b3c1 | 2013-08-12 17:06:05 +0200 | [diff] [blame] | 385 | |
Manuel Pégourié-Gonnard | 70bdadf | 2014-11-06 16:51:20 +0100 | [diff] [blame] | 386 | static int eckey_check_pair( const void *pub, const void *prv ) |
| 387 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 388 | return( mbedtls_ecp_check_pub_priv( (const mbedtls_ecp_keypair *) pub, |
| 389 | (const mbedtls_ecp_keypair *) prv ) ); |
Manuel Pégourié-Gonnard | 70bdadf | 2014-11-06 16:51:20 +0100 | [diff] [blame] | 390 | } |
| 391 | |
Manuel Pégourié-Gonnard | 765db07 | 2013-08-14 15:00:27 +0200 | [diff] [blame] | 392 | static void *eckey_alloc_wrap( void ) |
| 393 | { |
Manuel Pégourié-Gonnard | 7551cb9 | 2015-05-26 16:04:06 +0200 | [diff] [blame] | 394 | void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_ecp_keypair ) ); |
Manuel Pégourié-Gonnard | 765db07 | 2013-08-14 15:00:27 +0200 | [diff] [blame] | 395 | |
| 396 | if( ctx != NULL ) |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 397 | mbedtls_ecp_keypair_init( ctx ); |
Manuel Pégourié-Gonnard | 765db07 | 2013-08-14 15:00:27 +0200 | [diff] [blame] | 398 | |
| 399 | return( ctx ); |
| 400 | } |
| 401 | |
| 402 | static void eckey_free_wrap( void *ctx ) |
| 403 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 404 | mbedtls_ecp_keypair_free( (mbedtls_ecp_keypair *) ctx ); |
| 405 | mbedtls_free( ctx ); |
Manuel Pégourié-Gonnard | 765db07 | 2013-08-14 15:00:27 +0200 | [diff] [blame] | 406 | } |
| 407 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 408 | 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] | 409 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 410 | items->type = MBEDTLS_PK_DEBUG_ECP; |
Manuel Pégourié-Gonnard | c6ac887 | 2013-08-14 18:04:18 +0200 | [diff] [blame] | 411 | items->name = "eckey.Q"; |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 412 | items->value = &( ((mbedtls_ecp_keypair *) ctx)->Q ); |
Manuel Pégourié-Gonnard | c6ac887 | 2013-08-14 18:04:18 +0200 | [diff] [blame] | 413 | } |
| 414 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 415 | const mbedtls_pk_info_t mbedtls_eckey_info = { |
| 416 | MBEDTLS_PK_ECKEY, |
Manuel Pégourié-Gonnard | f8c948a | 2013-08-12 19:45:32 +0200 | [diff] [blame] | 417 | "EC", |
Manuel Pégourié-Gonnard | 39a48f4 | 2015-06-18 16:06:55 +0200 | [diff] [blame] | 418 | eckey_get_bitlen, |
Manuel Pégourié-Gonnard | f18c3e0 | 2013-08-12 18:41:18 +0200 | [diff] [blame] | 419 | eckey_can_do, |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 420 | #if defined(MBEDTLS_ECDSA_C) |
Manuel Pégourié-Gonnard | d73b3c1 | 2013-08-12 17:06:05 +0200 | [diff] [blame] | 421 | eckey_verify_wrap, |
Manuel Pégourié-Gonnard | 8df2769 | 2013-08-21 10:34:38 +0200 | [diff] [blame] | 422 | eckey_sign_wrap, |
Manuel Pégourié-Gonnard | 1f59606 | 2017-05-09 10:42:40 +0200 | [diff] [blame] | 423 | #if defined(MBEDTLS_ECP_RESTARTABLE) |
| 424 | eckey_verify_rs_wrap, |
| 425 | eckey_sign_rs_wrap, |
| 426 | #endif |
| 427 | #else /* MBEDTLS_ECDSA_C */ |
| 428 | NULL, |
| 429 | NULL, |
Manuel Pégourié-Gonnard | 1f59606 | 2017-05-09 10:42:40 +0200 | [diff] [blame] | 430 | #endif /* MBEDTLS_ECDSA_C */ |
Manuel Pégourié-Gonnard | a2d3f22 | 2013-08-21 11:51:08 +0200 | [diff] [blame] | 431 | NULL, |
| 432 | NULL, |
Manuel Pégourié-Gonnard | 70bdadf | 2014-11-06 16:51:20 +0100 | [diff] [blame] | 433 | eckey_check_pair, |
Manuel Pégourié-Gonnard | 765db07 | 2013-08-14 15:00:27 +0200 | [diff] [blame] | 434 | eckey_alloc_wrap, |
| 435 | eckey_free_wrap, |
Manuel Pégourié-Gonnard | aaa9814 | 2017-08-18 17:30:37 +0200 | [diff] [blame] | 436 | #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE) |
Manuel Pégourié-Gonnard | 0bbc66c | 2017-08-18 16:22:06 +0200 | [diff] [blame] | 437 | eckey_rs_alloc, |
| 438 | eckey_rs_free, |
| 439 | #endif |
Manuel Pégourié-Gonnard | c6ac887 | 2013-08-14 18:04:18 +0200 | [diff] [blame] | 440 | eckey_debug, |
Manuel Pégourié-Gonnard | d73b3c1 | 2013-08-12 17:06:05 +0200 | [diff] [blame] | 441 | }; |
Manuel Pégourié-Gonnard | 835eb59 | 2013-08-12 18:51:26 +0200 | [diff] [blame] | 442 | |
| 443 | /* |
Paul Bakker | 75342a6 | 2014-04-08 17:35:40 +0200 | [diff] [blame] | 444 | * EC key restricted to ECDH |
Manuel Pégourié-Gonnard | 835eb59 | 2013-08-12 18:51:26 +0200 | [diff] [blame] | 445 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 446 | static int eckeydh_can_do( mbedtls_pk_type_t type ) |
Manuel Pégourié-Gonnard | 835eb59 | 2013-08-12 18:51:26 +0200 | [diff] [blame] | 447 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 448 | return( type == MBEDTLS_PK_ECKEY || |
| 449 | type == MBEDTLS_PK_ECKEY_DH ); |
Manuel Pégourié-Gonnard | 835eb59 | 2013-08-12 18:51:26 +0200 | [diff] [blame] | 450 | } |
| 451 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 452 | const mbedtls_pk_info_t mbedtls_eckeydh_info = { |
| 453 | MBEDTLS_PK_ECKEY_DH, |
Manuel Pégourié-Gonnard | f8c948a | 2013-08-12 19:45:32 +0200 | [diff] [blame] | 454 | "EC_DH", |
Manuel Pégourié-Gonnard | 39a48f4 | 2015-06-18 16:06:55 +0200 | [diff] [blame] | 455 | eckey_get_bitlen, /* Same underlying key structure */ |
Manuel Pégourié-Gonnard | 835eb59 | 2013-08-12 18:51:26 +0200 | [diff] [blame] | 456 | eckeydh_can_do, |
Manuel Pégourié-Gonnard | fff80f8 | 2013-08-17 15:20:06 +0200 | [diff] [blame] | 457 | NULL, |
Manuel Pégourié-Gonnard | 8df2769 | 2013-08-21 10:34:38 +0200 | [diff] [blame] | 458 | NULL, |
Manuel Pégourié-Gonnard | aaa9814 | 2017-08-18 17:30:37 +0200 | [diff] [blame] | 459 | #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE) |
Manuel Pégourié-Gonnard | 1f59606 | 2017-05-09 10:42:40 +0200 | [diff] [blame] | 460 | NULL, |
| 461 | NULL, |
| 462 | #endif |
Manuel Pégourié-Gonnard | a2d3f22 | 2013-08-21 11:51:08 +0200 | [diff] [blame] | 463 | NULL, |
| 464 | NULL, |
Manuel Pégourié-Gonnard | 70bdadf | 2014-11-06 16:51:20 +0100 | [diff] [blame] | 465 | eckey_check_pair, |
Manuel Pégourié-Gonnard | 765db07 | 2013-08-14 15:00:27 +0200 | [diff] [blame] | 466 | eckey_alloc_wrap, /* Same underlying key structure */ |
| 467 | eckey_free_wrap, /* Same underlying key structure */ |
Manuel Pégourié-Gonnard | aaa9814 | 2017-08-18 17:30:37 +0200 | [diff] [blame] | 468 | #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE) |
Manuel Pégourié-Gonnard | 0bbc66c | 2017-08-18 16:22:06 +0200 | [diff] [blame] | 469 | NULL, |
| 470 | NULL, |
| 471 | #endif |
Manuel Pégourié-Gonnard | 09162dd | 2013-08-14 18:16:50 +0200 | [diff] [blame] | 472 | eckey_debug, /* Same underlying key structure */ |
Manuel Pégourié-Gonnard | 835eb59 | 2013-08-12 18:51:26 +0200 | [diff] [blame] | 473 | }; |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 474 | #endif /* MBEDTLS_ECP_C */ |
Manuel Pégourié-Gonnard | 09162dd | 2013-08-14 18:16:50 +0200 | [diff] [blame] | 475 | |
Jarno Lamsa | 42b83db | 2019-04-16 16:48:22 +0300 | [diff] [blame] | 476 | #if defined(MBEDTLS_USE_TINYCRYPT) |
| 477 | static int extract_ecdsa_sig_int( unsigned char **from, const unsigned char *end, |
| 478 | unsigned char *to, size_t to_len ) |
| 479 | { |
| 480 | int ret; |
| 481 | size_t unpadded_len, padding_len; |
| 482 | |
| 483 | if( ( ret = mbedtls_asn1_get_tag( from, end, &unpadded_len, |
| 484 | MBEDTLS_ASN1_INTEGER ) ) != 0 ) |
| 485 | { |
| 486 | return( ret ); |
| 487 | } |
| 488 | |
| 489 | while( unpadded_len > 0 && **from == 0x00 ) |
| 490 | { |
| 491 | ( *from )++; |
| 492 | unpadded_len--; |
| 493 | } |
| 494 | |
| 495 | if( unpadded_len > to_len || unpadded_len == 0 ) |
| 496 | return( MBEDTLS_ERR_ASN1_LENGTH_MISMATCH ); |
| 497 | |
| 498 | padding_len = to_len - unpadded_len; |
| 499 | memset( to, 0x00, padding_len ); |
| 500 | memcpy( to + padding_len, *from, unpadded_len ); |
| 501 | ( *from ) += unpadded_len; |
| 502 | |
| 503 | return( 0 ); |
| 504 | } |
| 505 | |
| 506 | /* |
| 507 | * Convert a signature from an ASN.1 sequence of two integers |
| 508 | * to a raw {r,s} buffer. Note: the provided sig buffer must be at least |
| 509 | * twice as big as int_size. |
| 510 | */ |
| 511 | static int extract_ecdsa_sig( unsigned char **p, const unsigned char *end, |
| 512 | unsigned char *sig, size_t int_size ) |
| 513 | { |
| 514 | int ret; |
| 515 | size_t tmp_size; |
| 516 | |
| 517 | if( ( ret = mbedtls_asn1_get_tag( p, end, &tmp_size, |
| 518 | MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 ) |
| 519 | return( ret ); |
| 520 | |
| 521 | /* Extract r */ |
| 522 | if( ( ret = extract_ecdsa_sig_int( p, end, sig, int_size ) ) != 0 ) |
| 523 | return( ret ); |
| 524 | /* Extract s */ |
| 525 | if( ( ret = extract_ecdsa_sig_int( p, end, sig + int_size, int_size ) ) != 0 ) |
| 526 | return( ret ); |
| 527 | |
| 528 | return( 0 ); |
| 529 | } |
| 530 | |
Hanno Becker | adf11e1 | 2019-08-21 13:03:44 +0100 | [diff] [blame] | 531 | static size_t uecc_eckey_get_bitlen( const void *ctx ) |
Jarno Lamsa | 42b83db | 2019-04-16 16:48:22 +0300 | [diff] [blame] | 532 | { |
| 533 | (void) ctx; |
Hanno Becker | 9a62f2d | 2019-08-20 14:57:37 +0100 | [diff] [blame] | 534 | return( (size_t) ( NUM_ECC_BYTES * 8 ) ); |
Jarno Lamsa | 42b83db | 2019-04-16 16:48:22 +0300 | [diff] [blame] | 535 | } |
| 536 | |
Hanno Becker | adf11e1 | 2019-08-21 13:03:44 +0100 | [diff] [blame] | 537 | static int uecc_eckey_can_do( mbedtls_pk_type_t type ) |
Jarno Lamsa | 42b83db | 2019-04-16 16:48:22 +0300 | [diff] [blame] | 538 | { |
Hanno Becker | adf11e1 | 2019-08-21 13:03:44 +0100 | [diff] [blame] | 539 | return( type == MBEDTLS_PK_ECDSA || |
| 540 | type == MBEDTLS_PK_ECKEY ); |
Jarno Lamsa | 42b83db | 2019-04-16 16:48:22 +0300 | [diff] [blame] | 541 | } |
| 542 | |
Hanno Becker | adf11e1 | 2019-08-21 13:03:44 +0100 | [diff] [blame] | 543 | static int uecc_eckey_verify_wrap( void *ctx, mbedtls_md_type_t md_alg, |
Jarno Lamsa | 42b83db | 2019-04-16 16:48:22 +0300 | [diff] [blame] | 544 | const unsigned char *hash, size_t hash_len, |
| 545 | const unsigned char *sig, size_t sig_len ) |
| 546 | { |
| 547 | int ret; |
| 548 | uint8_t signature[2*NUM_ECC_BYTES]; |
| 549 | unsigned char *p; |
| 550 | const struct uECC_Curve_t * uecc_curve = uECC_secp256r1(); |
Hanno Becker | 8ea3545 | 2019-08-20 15:39:13 +0100 | [diff] [blame^] | 551 | const mbedtls_uecc_keypair *keypair = (const mbedtls_uecc_keypair *) ctx; |
Jarno Lamsa | 42b83db | 2019-04-16 16:48:22 +0300 | [diff] [blame] | 552 | |
| 553 | ((void) md_alg); |
| 554 | p = (unsigned char*) sig; |
| 555 | |
Hanno Becker | ad353f2 | 2019-08-20 13:04:30 +0100 | [diff] [blame] | 556 | ret = extract_ecdsa_sig( &p, sig + sig_len, signature, NUM_ECC_BYTES ); |
| 557 | if( ret != 0 ) |
Jarno Lamsa | 42b83db | 2019-04-16 16:48:22 +0300 | [diff] [blame] | 558 | return( ret ); |
| 559 | |
Hanno Becker | 8ea3545 | 2019-08-20 15:39:13 +0100 | [diff] [blame^] | 560 | ret = uECC_verify( keypair->public_key, hash, |
Hanno Becker | ad353f2 | 2019-08-20 13:04:30 +0100 | [diff] [blame] | 561 | (unsigned) hash_len, signature, uecc_curve ); |
Hanno Becker | 8ea3545 | 2019-08-20 15:39:13 +0100 | [diff] [blame^] | 562 | if( ret == 0 ) |
| 563 | return( MBEDTLS_ERR_PK_HW_ACCEL_FAILED ); |
Jarno Lamsa | 42b83db | 2019-04-16 16:48:22 +0300 | [diff] [blame] | 564 | |
Hanno Becker | 8ea3545 | 2019-08-20 15:39:13 +0100 | [diff] [blame^] | 565 | return( 0 ); |
Jarno Lamsa | 42b83db | 2019-04-16 16:48:22 +0300 | [diff] [blame] | 566 | } |
| 567 | |
| 568 | /* |
| 569 | * Simultaneously convert and move raw MPI from the beginning of a buffer |
| 570 | * to an ASN.1 MPI at the end of the buffer. |
| 571 | * See also mbedtls_asn1_write_mpi(). |
| 572 | * |
| 573 | * p: pointer to the end of the output buffer |
| 574 | * start: start of the output buffer, and also of the mpi to write at the end |
| 575 | * n_len: length of the mpi to read from start |
| 576 | */ |
| 577 | static int asn1_write_mpibuf( unsigned char **p, unsigned char *start, |
| 578 | size_t n_len ) |
| 579 | { |
| 580 | int ret; |
| 581 | size_t len = 0; |
| 582 | |
| 583 | if( (size_t)( *p - start ) < n_len ) |
| 584 | return( MBEDTLS_ERR_ASN1_BUF_TOO_SMALL ); |
| 585 | |
| 586 | len = n_len; |
| 587 | *p -= len; |
| 588 | memmove( *p, start, len ); |
| 589 | |
| 590 | /* ASN.1 DER encoding requires minimal length, so skip leading 0s. |
| 591 | * Neither r nor s should be 0, but as a failsafe measure, still detect |
Hanno Becker | e8f1448 | 2019-08-20 13:28:59 +0100 | [diff] [blame] | 592 | * that rather than overflowing the buffer in case of an error. */ |
Jarno Lamsa | 42b83db | 2019-04-16 16:48:22 +0300 | [diff] [blame] | 593 | while( len > 0 && **p == 0x00 ) |
| 594 | { |
| 595 | ++(*p); |
| 596 | --len; |
| 597 | } |
| 598 | |
| 599 | /* this is only reached if the signature was invalid */ |
| 600 | if( len == 0 ) |
| 601 | return( MBEDTLS_ERR_PK_HW_ACCEL_FAILED ); |
| 602 | |
| 603 | /* if the msb is 1, ASN.1 requires that we prepend a 0. |
| 604 | * Neither r nor s can be 0, so we can assume len > 0 at all times. */ |
| 605 | if( **p & 0x80 ) |
| 606 | { |
| 607 | if( *p - start < 1 ) |
| 608 | return( MBEDTLS_ERR_ASN1_BUF_TOO_SMALL ); |
| 609 | |
| 610 | *--(*p) = 0x00; |
| 611 | len += 1; |
| 612 | } |
| 613 | |
| 614 | MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_len( p, start, len ) ); |
| 615 | MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_tag( p, start, |
| 616 | MBEDTLS_ASN1_INTEGER ) ); |
| 617 | |
| 618 | return( (int) len ); |
| 619 | } |
| 620 | |
Jarno Lamsa | ad78931 | 2019-04-23 09:15:54 +0300 | [diff] [blame] | 621 | /* Transcode signature from uECC format to ASN.1 sequence. |
Jarno Lamsa | 42b83db | 2019-04-16 16:48:22 +0300 | [diff] [blame] | 622 | * See ecdsa_signature_to_asn1 in ecdsa.c, but with byte buffers instead of |
| 623 | * MPIs, and in-place. |
| 624 | * |
| 625 | * [in/out] sig: the signature pre- and post-transcoding |
| 626 | * [in/out] sig_len: signature length pre- and post-transcoding |
| 627 | * [int] buf_len: the available size the in/out buffer |
| 628 | */ |
Hanno Becker | e8f1448 | 2019-08-20 13:28:59 +0100 | [diff] [blame] | 629 | static int pk_ecdsa_sig_asn1_from_uecc( unsigned char *sig, size_t *sig_len, |
| 630 | size_t buf_len ) |
Jarno Lamsa | 42b83db | 2019-04-16 16:48:22 +0300 | [diff] [blame] | 631 | { |
| 632 | int ret; |
| 633 | size_t len = 0; |
| 634 | const size_t rs_len = *sig_len / 2; |
| 635 | unsigned char *p = sig + buf_len; |
| 636 | |
| 637 | MBEDTLS_ASN1_CHK_ADD( len, asn1_write_mpibuf( &p, sig + rs_len, rs_len ) ); |
| 638 | MBEDTLS_ASN1_CHK_ADD( len, asn1_write_mpibuf( &p, sig, rs_len ) ); |
| 639 | |
| 640 | MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_len( &p, sig, len ) ); |
| 641 | MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_tag( &p, sig, |
| 642 | MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ); |
| 643 | |
| 644 | memmove( sig, p, len ); |
| 645 | *sig_len = len; |
| 646 | |
| 647 | return( 0 ); |
| 648 | } |
| 649 | |
Hanno Becker | adf11e1 | 2019-08-21 13:03:44 +0100 | [diff] [blame] | 650 | static int uecc_eckey_sign_wrap( void *ctx, mbedtls_md_type_t md_alg, |
Jarno Lamsa | 42b83db | 2019-04-16 16:48:22 +0300 | [diff] [blame] | 651 | const unsigned char *hash, size_t hash_len, |
| 652 | unsigned char *sig, size_t *sig_len, |
| 653 | int (*f_rng)(void *, unsigned char *, size_t), void *p_rng ) |
| 654 | { |
Jarno Lamsa | ad78931 | 2019-04-23 09:15:54 +0300 | [diff] [blame] | 655 | const mbedtls_uecc_keypair *keypair = (const mbedtls_uecc_keypair *) ctx; |
| 656 | const struct uECC_Curve_t * uecc_curve = uECC_secp256r1(); |
Hanno Becker | 9c7a359 | 2019-08-20 15:37:17 +0100 | [diff] [blame] | 657 | |
| 658 | /* |
| 659 | * RFC-4492 page 20: |
| 660 | * |
| 661 | * Ecdsa-Sig-Value ::= SEQUENCE { |
| 662 | * r INTEGER, |
| 663 | * s INTEGER |
| 664 | * } |
| 665 | * |
| 666 | * Size is at most |
| 667 | * 1 (tag) + 1 (len) + 1 (initial 0) + NUM_ECC_BYTES for each of r and s, |
| 668 | * twice that + 1 (tag) + 2 (len) for the sequence |
| 669 | * (assuming NUM_ECC_BYTES is less than 126 for r and s, |
| 670 | * and less than 124 (total len <= 255) for the sequence) |
| 671 | */ |
| 672 | const size_t max_secp256r1_ecdsa_sig_len = 3 + 2 * ( 3 + NUM_ECC_BYTES ); |
| 673 | |
| 674 | uECC_sign( keypair->private_key, hash, hash_len, sig, uecc_curve ); |
| 675 | *sig_len = 2 * NUM_ECC_BYTES; |
Jarno Lamsa | ad78931 | 2019-04-23 09:15:54 +0300 | [diff] [blame] | 676 | |
| 677 | /* uECC owns its rng function pointer */ |
Jarno Lamsa | 42b83db | 2019-04-16 16:48:22 +0300 | [diff] [blame] | 678 | (void) f_rng; |
| 679 | (void) p_rng; |
Jarno Lamsa | ad78931 | 2019-04-23 09:15:54 +0300 | [diff] [blame] | 680 | (void) md_alg; |
Jarno Lamsa | 42b83db | 2019-04-16 16:48:22 +0300 | [diff] [blame] | 681 | |
Hanno Becker | 9c7a359 | 2019-08-20 15:37:17 +0100 | [diff] [blame] | 682 | return( pk_ecdsa_sig_asn1_from_uecc( sig, sig_len, max_secp256r1_ecdsa_sig_len ) ); |
Jarno Lamsa | 42b83db | 2019-04-16 16:48:22 +0300 | [diff] [blame] | 683 | } |
| 684 | |
Hanno Becker | adf11e1 | 2019-08-21 13:03:44 +0100 | [diff] [blame] | 685 | static void *uecc_eckey_alloc_wrap( void ) |
Jarno Lamsa | 42b83db | 2019-04-16 16:48:22 +0300 | [diff] [blame] | 686 | { |
| 687 | /*void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_ecdsa_context ) ); |
| 688 | |
| 689 | if( ctx != NULL ) |
| 690 | mbedtls_ecdsa_init( (mbedtls_ecdsa_context *) ctx ); |
| 691 | |
| 692 | return( ctx );*/ |
| 693 | return NULL; |
| 694 | } |
| 695 | |
Hanno Becker | adf11e1 | 2019-08-21 13:03:44 +0100 | [diff] [blame] | 696 | static void uecc_eckey_free_wrap( void *ctx ) |
Jarno Lamsa | 42b83db | 2019-04-16 16:48:22 +0300 | [diff] [blame] | 697 | { |
| 698 | (void) ctx; |
| 699 | /*mbedtls_ecdsa_free( (mbedtls_ecdsa_context *) ctx ); |
| 700 | mbedtls_free( ctx );*/ |
| 701 | } |
| 702 | |
Hanno Becker | adf11e1 | 2019-08-21 13:03:44 +0100 | [diff] [blame] | 703 | const mbedtls_pk_info_t mbedtls_uecc_eckey_info = { |
| 704 | MBEDTLS_PK_ECKEY, |
| 705 | "EC", |
| 706 | uecc_eckey_get_bitlen, |
| 707 | uecc_eckey_can_do, |
| 708 | uecc_eckey_verify_wrap, |
| 709 | uecc_eckey_sign_wrap, |
Jarno Lamsa | 42b83db | 2019-04-16 16:48:22 +0300 | [diff] [blame] | 710 | NULL, |
| 711 | NULL, |
| 712 | NULL, |
Hanno Becker | adf11e1 | 2019-08-21 13:03:44 +0100 | [diff] [blame] | 713 | uecc_eckey_alloc_wrap, |
| 714 | uecc_eckey_free_wrap, |
Jarno Lamsa | 42b83db | 2019-04-16 16:48:22 +0300 | [diff] [blame] | 715 | NULL, |
| 716 | }; |
| 717 | #else |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 718 | #if defined(MBEDTLS_ECDSA_C) |
| 719 | static int ecdsa_can_do( mbedtls_pk_type_t type ) |
Manuel Pégourié-Gonnard | 09162dd | 2013-08-14 18:16:50 +0200 | [diff] [blame] | 720 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 721 | return( type == MBEDTLS_PK_ECDSA ); |
Manuel Pégourié-Gonnard | 09162dd | 2013-08-14 18:16:50 +0200 | [diff] [blame] | 722 | } |
| 723 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 724 | 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] | 725 | const unsigned char *hash, size_t hash_len, |
Manuel Pégourié-Gonnard | 09162dd | 2013-08-14 18:16:50 +0200 | [diff] [blame] | 726 | const unsigned char *sig, size_t sig_len ) |
| 727 | { |
Manuel Pégourié-Gonnard | 2abed84 | 2014-04-08 12:40:15 +0200 | [diff] [blame] | 728 | int ret; |
Manuel Pégourié-Gonnard | f73da02 | 2013-08-17 14:36:32 +0200 | [diff] [blame] | 729 | ((void) md_alg); |
| 730 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 731 | ret = mbedtls_ecdsa_read_signature( (mbedtls_ecdsa_context *) ctx, |
Manuel Pégourié-Gonnard | 2abed84 | 2014-04-08 12:40:15 +0200 | [diff] [blame] | 732 | hash, hash_len, sig, sig_len ); |
| 733 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 734 | if( ret == MBEDTLS_ERR_ECP_SIG_LEN_MISMATCH ) |
| 735 | return( MBEDTLS_ERR_PK_SIG_LEN_MISMATCH ); |
Manuel Pégourié-Gonnard | 2abed84 | 2014-04-08 12:40:15 +0200 | [diff] [blame] | 736 | |
| 737 | return( ret ); |
Manuel Pégourié-Gonnard | 09162dd | 2013-08-14 18:16:50 +0200 | [diff] [blame] | 738 | } |
| 739 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 740 | 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] | 741 | const unsigned char *hash, size_t hash_len, |
| 742 | unsigned char *sig, size_t *sig_len, |
| 743 | int (*f_rng)(void *, unsigned char *, size_t), void *p_rng ) |
| 744 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 745 | return( mbedtls_ecdsa_write_signature( (mbedtls_ecdsa_context *) ctx, |
Manuel Pégourié-Gonnard | dfdcac9 | 2015-03-31 11:41:42 +0200 | [diff] [blame] | 746 | 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] | 747 | } |
| 748 | |
Manuel Pégourié-Gonnard | 1f59606 | 2017-05-09 10:42:40 +0200 | [diff] [blame] | 749 | #if defined(MBEDTLS_ECP_RESTARTABLE) |
| 750 | static int ecdsa_verify_rs_wrap( void *ctx, mbedtls_md_type_t md_alg, |
| 751 | const unsigned char *hash, size_t hash_len, |
| 752 | const unsigned char *sig, size_t sig_len, |
| 753 | void *rs_ctx ) |
| 754 | { |
| 755 | int ret; |
| 756 | ((void) md_alg); |
| 757 | |
| 758 | ret = mbedtls_ecdsa_read_signature_restartable( |
| 759 | (mbedtls_ecdsa_context *) ctx, |
| 760 | hash, hash_len, sig, sig_len, |
| 761 | (mbedtls_ecdsa_restart_ctx *) rs_ctx ); |
| 762 | |
| 763 | if( ret == MBEDTLS_ERR_ECP_SIG_LEN_MISMATCH ) |
| 764 | return( MBEDTLS_ERR_PK_SIG_LEN_MISMATCH ); |
| 765 | |
| 766 | return( ret ); |
| 767 | } |
| 768 | |
| 769 | static int ecdsa_sign_rs_wrap( void *ctx, mbedtls_md_type_t md_alg, |
| 770 | const unsigned char *hash, size_t hash_len, |
| 771 | unsigned char *sig, size_t *sig_len, |
| 772 | int (*f_rng)(void *, unsigned char *, size_t), void *p_rng, |
| 773 | void *rs_ctx ) |
| 774 | { |
| 775 | return( mbedtls_ecdsa_write_signature_restartable( |
| 776 | (mbedtls_ecdsa_context *) ctx, |
| 777 | md_alg, hash, hash_len, sig, sig_len, f_rng, p_rng, |
| 778 | (mbedtls_ecdsa_restart_ctx *) rs_ctx ) ); |
| 779 | |
| 780 | } |
| 781 | #endif /* MBEDTLS_ECP_RESTARTABLE */ |
| 782 | |
Manuel Pégourié-Gonnard | 09162dd | 2013-08-14 18:16:50 +0200 | [diff] [blame] | 783 | static void *ecdsa_alloc_wrap( void ) |
| 784 | { |
Manuel Pégourié-Gonnard | 7551cb9 | 2015-05-26 16:04:06 +0200 | [diff] [blame] | 785 | void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_ecdsa_context ) ); |
Manuel Pégourié-Gonnard | 09162dd | 2013-08-14 18:16:50 +0200 | [diff] [blame] | 786 | |
| 787 | if( ctx != NULL ) |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 788 | mbedtls_ecdsa_init( (mbedtls_ecdsa_context *) ctx ); |
Manuel Pégourié-Gonnard | 09162dd | 2013-08-14 18:16:50 +0200 | [diff] [blame] | 789 | |
| 790 | return( ctx ); |
| 791 | } |
| 792 | |
| 793 | static void ecdsa_free_wrap( void *ctx ) |
| 794 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 795 | mbedtls_ecdsa_free( (mbedtls_ecdsa_context *) ctx ); |
| 796 | mbedtls_free( ctx ); |
Manuel Pégourié-Gonnard | 09162dd | 2013-08-14 18:16:50 +0200 | [diff] [blame] | 797 | } |
| 798 | |
Manuel Pégourié-Gonnard | fe68770 | 2017-08-18 17:04:07 +0200 | [diff] [blame] | 799 | #if defined(MBEDTLS_ECP_RESTARTABLE) |
| 800 | static void *ecdsa_rs_alloc( void ) |
| 801 | { |
| 802 | void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_ecdsa_restart_ctx ) ); |
| 803 | |
| 804 | if( ctx != NULL ) |
| 805 | mbedtls_ecdsa_restart_init( ctx ); |
| 806 | |
| 807 | return( ctx ); |
| 808 | } |
| 809 | |
| 810 | static void ecdsa_rs_free( void *ctx ) |
| 811 | { |
| 812 | mbedtls_ecdsa_restart_free( ctx ); |
| 813 | mbedtls_free( ctx ); |
| 814 | } |
| 815 | #endif /* MBEDTLS_ECP_RESTARTABLE */ |
| 816 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 817 | const mbedtls_pk_info_t mbedtls_ecdsa_info = { |
| 818 | MBEDTLS_PK_ECDSA, |
Manuel Pégourié-Gonnard | 09162dd | 2013-08-14 18:16:50 +0200 | [diff] [blame] | 819 | "ECDSA", |
Manuel Pégourié-Gonnard | 39a48f4 | 2015-06-18 16:06:55 +0200 | [diff] [blame] | 820 | eckey_get_bitlen, /* Compatible key structures */ |
Manuel Pégourié-Gonnard | 09162dd | 2013-08-14 18:16:50 +0200 | [diff] [blame] | 821 | ecdsa_can_do, |
| 822 | ecdsa_verify_wrap, |
Manuel Pégourié-Gonnard | 8df2769 | 2013-08-21 10:34:38 +0200 | [diff] [blame] | 823 | ecdsa_sign_wrap, |
Manuel Pégourié-Gonnard | 1f59606 | 2017-05-09 10:42:40 +0200 | [diff] [blame] | 824 | #if defined(MBEDTLS_ECP_RESTARTABLE) |
| 825 | ecdsa_verify_rs_wrap, |
| 826 | ecdsa_sign_rs_wrap, |
| 827 | #endif |
Manuel Pégourié-Gonnard | a2d3f22 | 2013-08-21 11:51:08 +0200 | [diff] [blame] | 828 | NULL, |
| 829 | NULL, |
Manuel Pégourié-Gonnard | 70bdadf | 2014-11-06 16:51:20 +0100 | [diff] [blame] | 830 | eckey_check_pair, /* Compatible key structures */ |
Manuel Pégourié-Gonnard | 09162dd | 2013-08-14 18:16:50 +0200 | [diff] [blame] | 831 | ecdsa_alloc_wrap, |
| 832 | ecdsa_free_wrap, |
Manuel Pégourié-Gonnard | 0bbc66c | 2017-08-18 16:22:06 +0200 | [diff] [blame] | 833 | #if defined(MBEDTLS_ECP_RESTARTABLE) |
Manuel Pégourié-Gonnard | fe68770 | 2017-08-18 17:04:07 +0200 | [diff] [blame] | 834 | ecdsa_rs_alloc, |
| 835 | ecdsa_rs_free, |
Manuel Pégourié-Gonnard | 0bbc66c | 2017-08-18 16:22:06 +0200 | [diff] [blame] | 836 | #endif |
Manuel Pégourié-Gonnard | 09162dd | 2013-08-14 18:16:50 +0200 | [diff] [blame] | 837 | eckey_debug, /* Compatible key structures */ |
| 838 | }; |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 839 | #endif /* MBEDTLS_ECDSA_C */ |
Jarno Lamsa | 42b83db | 2019-04-16 16:48:22 +0300 | [diff] [blame] | 840 | #endif /* MBEDTLS_USE_TINYCRYPT */ |
Manuel Pégourié-Gonnard | 12c1ff0 | 2013-08-21 12:28:31 +0200 | [diff] [blame] | 841 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 842 | #if defined(MBEDTLS_PK_RSA_ALT_SUPPORT) |
Manuel Pégourié-Gonnard | 12c1ff0 | 2013-08-21 12:28:31 +0200 | [diff] [blame] | 843 | /* |
| 844 | * Support for alternative RSA-private implementations |
| 845 | */ |
| 846 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 847 | 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] | 848 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 849 | return( type == MBEDTLS_PK_RSA ); |
Manuel Pégourié-Gonnard | 20422e9 | 2014-06-05 13:41:44 +0200 | [diff] [blame] | 850 | } |
| 851 | |
Manuel Pégourié-Gonnard | 39a48f4 | 2015-06-18 16:06:55 +0200 | [diff] [blame] | 852 | static size_t rsa_alt_get_bitlen( const void *ctx ) |
Manuel Pégourié-Gonnard | 12c1ff0 | 2013-08-21 12:28:31 +0200 | [diff] [blame] | 853 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 854 | 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] | 855 | |
Manuel Pégourié-Gonnard | 0148875 | 2014-04-03 22:09:18 +0200 | [diff] [blame] | 856 | return( 8 * rsa_alt->key_len_func( rsa_alt->key ) ); |
Manuel Pégourié-Gonnard | 12c1ff0 | 2013-08-21 12:28:31 +0200 | [diff] [blame] | 857 | } |
| 858 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 859 | 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] | 860 | const unsigned char *hash, size_t hash_len, |
| 861 | unsigned char *sig, size_t *sig_len, |
| 862 | int (*f_rng)(void *, unsigned char *, size_t), void *p_rng ) |
| 863 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 864 | 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] | 865 | |
Andres Amaya Garcia | 7c02c50 | 2017-08-04 13:32:15 +0100 | [diff] [blame] | 866 | #if SIZE_MAX > UINT_MAX |
Andres AG | 7284987 | 2017-01-19 11:24:33 +0000 | [diff] [blame] | 867 | if( UINT_MAX < hash_len ) |
| 868 | return( MBEDTLS_ERR_PK_BAD_INPUT_DATA ); |
Andres Amaya Garcia | 7c02c50 | 2017-08-04 13:32:15 +0100 | [diff] [blame] | 869 | #endif /* SIZE_MAX > UINT_MAX */ |
Andres AG | 7284987 | 2017-01-19 11:24:33 +0000 | [diff] [blame] | 870 | |
Manuel Pégourié-Gonnard | 12c1ff0 | 2013-08-21 12:28:31 +0200 | [diff] [blame] | 871 | *sig_len = rsa_alt->key_len_func( rsa_alt->key ); |
| 872 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 873 | 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] | 874 | md_alg, (unsigned int) hash_len, hash, sig ) ); |
Manuel Pégourié-Gonnard | 12c1ff0 | 2013-08-21 12:28:31 +0200 | [diff] [blame] | 875 | } |
| 876 | |
| 877 | static int rsa_alt_decrypt_wrap( void *ctx, |
| 878 | const unsigned char *input, size_t ilen, |
| 879 | unsigned char *output, size_t *olen, size_t osize, |
| 880 | int (*f_rng)(void *, unsigned char *, size_t), void *p_rng ) |
| 881 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 882 | 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] | 883 | |
| 884 | ((void) f_rng); |
| 885 | ((void) p_rng); |
| 886 | |
| 887 | if( ilen != rsa_alt->key_len_func( rsa_alt->key ) ) |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 888 | return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA ); |
Manuel Pégourié-Gonnard | 12c1ff0 | 2013-08-21 12:28:31 +0200 | [diff] [blame] | 889 | |
| 890 | return( rsa_alt->decrypt_func( rsa_alt->key, |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 891 | MBEDTLS_RSA_PRIVATE, olen, input, output, osize ) ); |
Manuel Pégourié-Gonnard | 12c1ff0 | 2013-08-21 12:28:31 +0200 | [diff] [blame] | 892 | } |
| 893 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 894 | #if defined(MBEDTLS_RSA_C) |
Manuel Pégourié-Gonnard | a1efcb0 | 2014-11-08 17:08:08 +0100 | [diff] [blame] | 895 | static int rsa_alt_check_pair( const void *pub, const void *prv ) |
| 896 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 897 | unsigned char sig[MBEDTLS_MPI_MAX_SIZE]; |
Manuel Pégourié-Gonnard | a1efcb0 | 2014-11-08 17:08:08 +0100 | [diff] [blame] | 898 | unsigned char hash[32]; |
| 899 | size_t sig_len = 0; |
| 900 | int ret; |
| 901 | |
Manuel Pégourié-Gonnard | 39a48f4 | 2015-06-18 16:06:55 +0200 | [diff] [blame] | 902 | if( rsa_alt_get_bitlen( prv ) != rsa_get_bitlen( pub ) ) |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 903 | return( MBEDTLS_ERR_RSA_KEY_CHECK_FAILED ); |
Manuel Pégourié-Gonnard | a1efcb0 | 2014-11-08 17:08:08 +0100 | [diff] [blame] | 904 | |
| 905 | memset( hash, 0x2a, sizeof( hash ) ); |
| 906 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 907 | 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] | 908 | hash, sizeof( hash ), |
| 909 | sig, &sig_len, NULL, NULL ) ) != 0 ) |
| 910 | { |
| 911 | return( ret ); |
| 912 | } |
| 913 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 914 | if( rsa_verify_wrap( (void *) pub, MBEDTLS_MD_NONE, |
Manuel Pégourié-Gonnard | a1efcb0 | 2014-11-08 17:08:08 +0100 | [diff] [blame] | 915 | hash, sizeof( hash ), sig, sig_len ) != 0 ) |
| 916 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 917 | return( MBEDTLS_ERR_RSA_KEY_CHECK_FAILED ); |
Manuel Pégourié-Gonnard | a1efcb0 | 2014-11-08 17:08:08 +0100 | [diff] [blame] | 918 | } |
| 919 | |
| 920 | return( 0 ); |
| 921 | } |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 922 | #endif /* MBEDTLS_RSA_C */ |
Manuel Pégourié-Gonnard | a1efcb0 | 2014-11-08 17:08:08 +0100 | [diff] [blame] | 923 | |
Manuel Pégourié-Gonnard | 12c1ff0 | 2013-08-21 12:28:31 +0200 | [diff] [blame] | 924 | static void *rsa_alt_alloc_wrap( void ) |
| 925 | { |
Manuel Pégourié-Gonnard | 7551cb9 | 2015-05-26 16:04:06 +0200 | [diff] [blame] | 926 | void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_rsa_alt_context ) ); |
Manuel Pégourié-Gonnard | 12c1ff0 | 2013-08-21 12:28:31 +0200 | [diff] [blame] | 927 | |
| 928 | if( ctx != NULL ) |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 929 | memset( ctx, 0, sizeof( mbedtls_rsa_alt_context ) ); |
Manuel Pégourié-Gonnard | 12c1ff0 | 2013-08-21 12:28:31 +0200 | [diff] [blame] | 930 | |
Paul Bakker | d8bb826 | 2014-06-17 14:06:49 +0200 | [diff] [blame] | 931 | return( ctx ); |
Manuel Pégourié-Gonnard | 12c1ff0 | 2013-08-21 12:28:31 +0200 | [diff] [blame] | 932 | } |
| 933 | |
| 934 | static void rsa_alt_free_wrap( void *ctx ) |
| 935 | { |
Andres Amaya Garcia | 1f6301b | 2018-04-17 09:51:09 -0500 | [diff] [blame] | 936 | mbedtls_platform_zeroize( ctx, sizeof( mbedtls_rsa_alt_context ) ); |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 937 | mbedtls_free( ctx ); |
Manuel Pégourié-Gonnard | 12c1ff0 | 2013-08-21 12:28:31 +0200 | [diff] [blame] | 938 | } |
| 939 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 940 | const mbedtls_pk_info_t mbedtls_rsa_alt_info = { |
| 941 | MBEDTLS_PK_RSA_ALT, |
Manuel Pégourié-Gonnard | 12c1ff0 | 2013-08-21 12:28:31 +0200 | [diff] [blame] | 942 | "RSA-alt", |
Manuel Pégourié-Gonnard | 39a48f4 | 2015-06-18 16:06:55 +0200 | [diff] [blame] | 943 | rsa_alt_get_bitlen, |
Manuel Pégourié-Gonnard | 20422e9 | 2014-06-05 13:41:44 +0200 | [diff] [blame] | 944 | rsa_alt_can_do, |
Manuel Pégourié-Gonnard | 12c1ff0 | 2013-08-21 12:28:31 +0200 | [diff] [blame] | 945 | NULL, |
| 946 | rsa_alt_sign_wrap, |
Manuel Pégourié-Gonnard | aaa9814 | 2017-08-18 17:30:37 +0200 | [diff] [blame] | 947 | #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE) |
Manuel Pégourié-Gonnard | 1f59606 | 2017-05-09 10:42:40 +0200 | [diff] [blame] | 948 | NULL, |
| 949 | NULL, |
| 950 | #endif |
Manuel Pégourié-Gonnard | 12c1ff0 | 2013-08-21 12:28:31 +0200 | [diff] [blame] | 951 | rsa_alt_decrypt_wrap, |
| 952 | NULL, |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 953 | #if defined(MBEDTLS_RSA_C) |
Manuel Pégourié-Gonnard | a1efcb0 | 2014-11-08 17:08:08 +0100 | [diff] [blame] | 954 | rsa_alt_check_pair, |
Manuel Pégourié-Gonnard | 7c13d69 | 2014-11-12 00:01:34 +0100 | [diff] [blame] | 955 | #else |
| 956 | NULL, |
| 957 | #endif |
Manuel Pégourié-Gonnard | 12c1ff0 | 2013-08-21 12:28:31 +0200 | [diff] [blame] | 958 | rsa_alt_alloc_wrap, |
| 959 | rsa_alt_free_wrap, |
Manuel Pégourié-Gonnard | aaa9814 | 2017-08-18 17:30:37 +0200 | [diff] [blame] | 960 | #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE) |
Manuel Pégourié-Gonnard | 0bbc66c | 2017-08-18 16:22:06 +0200 | [diff] [blame] | 961 | NULL, |
| 962 | NULL, |
| 963 | #endif |
Manuel Pégourié-Gonnard | 12c1ff0 | 2013-08-21 12:28:31 +0200 | [diff] [blame] | 964 | NULL, |
| 965 | }; |
Manuel Pégourié-Gonnard | c40b4c3 | 2013-08-22 13:29:31 +0200 | [diff] [blame] | 966 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 967 | #endif /* MBEDTLS_PK_RSA_ALT_SUPPORT */ |
Manuel Pégourié-Gonnard | 348bcb3 | 2015-03-31 14:01:33 +0200 | [diff] [blame] | 968 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 969 | #endif /* MBEDTLS_PK_C */ |