Paul Bakker | e6ee41f | 2012-05-19 08:43:48 +0000 | [diff] [blame] | 1 | /* |
Manuel Pégourié-Gonnard | 9169921 | 2015-01-22 16:26:39 +0000 | [diff] [blame] | 2 | * Test application that shows some mbed TLS and OpenSSL compatibility |
Paul Bakker | e6ee41f | 2012-05-19 08:43:48 +0000 | [diff] [blame] | 3 | * |
Manuel Pégourié-Gonnard | a658a40 | 2015-01-23 09:45:19 +0000 | [diff] [blame] | 4 | * Copyright (C) 2011-2012 ARM Limited, All Rights Reserved |
Paul Bakker | e6ee41f | 2012-05-19 08:43:48 +0000 | [diff] [blame] | 5 | * |
Manuel Pégourié-Gonnard | 860b516 | 2015-01-28 17:12:07 +0000 | [diff] [blame^] | 6 | * This file is part of mbed TLS (https://polarssl.org) |
Paul Bakker | e6ee41f | 2012-05-19 08:43:48 +0000 | [diff] [blame] | 7 | * |
Paul Bakker | e6ee41f | 2012-05-19 08:43:48 +0000 | [diff] [blame] | 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License along |
| 19 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 20 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 21 | */ |
| 22 | |
Manuel Pégourié-Gonnard | cef4ad2 | 2014-04-29 12:39:06 +0200 | [diff] [blame] | 23 | #if !defined(POLARSSL_CONFIG_FILE) |
Manuel Pégourié-Gonnard | abd6e02 | 2013-09-20 13:30:43 +0200 | [diff] [blame] | 24 | #include "polarssl/config.h" |
Manuel Pégourié-Gonnard | cef4ad2 | 2014-04-29 12:39:06 +0200 | [diff] [blame] | 25 | #else |
| 26 | #include POLARSSL_CONFIG_FILE |
| 27 | #endif |
Paul Bakker | e6ee41f | 2012-05-19 08:43:48 +0000 | [diff] [blame] | 28 | |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 29 | #if defined(POLARSSL_PLATFORM_C) |
| 30 | #include "polarssl/platform.h" |
| 31 | #else |
| 32 | #define polarssl_printf printf |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 33 | #endif |
| 34 | |
Paul Bakker | e6ee41f | 2012-05-19 08:43:48 +0000 | [diff] [blame] | 35 | #include <string.h> |
| 36 | #include <stdio.h> |
| 37 | #include <stdlib.h> |
| 38 | #include <unistd.h> |
| 39 | #include <sys/stat.h> |
| 40 | |
| 41 | #include <openssl/rsa.h> |
Paul Bakker | 5eb264c | 2014-01-23 15:43:07 +0100 | [diff] [blame] | 42 | #ifndef OPENSSL_NO_ENGINE |
Paul Bakker | e6ee41f | 2012-05-19 08:43:48 +0000 | [diff] [blame] | 43 | #include <openssl/engine.h> |
Paul Bakker | 5eb264c | 2014-01-23 15:43:07 +0100 | [diff] [blame] | 44 | #endif |
Paul Bakker | e6ee41f | 2012-05-19 08:43:48 +0000 | [diff] [blame] | 45 | #include <openssl/pem.h> |
| 46 | #include <openssl/bio.h> |
| 47 | |
Paul Bakker | 36713e8 | 2013-09-17 13:25:29 +0200 | [diff] [blame] | 48 | #include "polarssl/pk.h" |
Paul Bakker | e6ee41f | 2012-05-19 08:43:48 +0000 | [diff] [blame] | 49 | #include "polarssl/x509.h" |
Paul Bakker | e6ee41f | 2012-05-19 08:43:48 +0000 | [diff] [blame] | 50 | #include "polarssl/entropy.h" |
| 51 | #include "polarssl/ctr_drbg.h" |
| 52 | |
Paul Bakker | ed27a04 | 2013-04-18 22:46:23 +0200 | [diff] [blame] | 53 | #if !defined(POLARSSL_BIGNUM_C) || !defined(POLARSSL_RSA_C) || \ |
Paul Bakker | 36713e8 | 2013-09-17 13:25:29 +0200 | [diff] [blame] | 54 | !defined(POLARSSL_PK_PARSE_C) || !defined(POLARSSL_FS_IO) |
Paul Bakker | ed27a04 | 2013-04-18 22:46:23 +0200 | [diff] [blame] | 55 | int main( int argc, char *argv[] ) |
| 56 | { |
| 57 | ((void) argc); |
| 58 | ((void) argv); |
| 59 | |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 60 | polarssl_printf("POLARSSL_BIGNUM_C and/or POLARSSL_RSA_C and/or " |
Paul Bakker | 36713e8 | 2013-09-17 13:25:29 +0200 | [diff] [blame] | 61 | "POLARSSL_PK_PARSE_C and/or POLARSSL_FS_IO not defined.\n"); |
Paul Bakker | ed27a04 | 2013-04-18 22:46:23 +0200 | [diff] [blame] | 62 | return( 0 ); |
| 63 | } |
| 64 | #else |
Paul Bakker | e6ee41f | 2012-05-19 08:43:48 +0000 | [diff] [blame] | 65 | int main( int argc, char *argv[] ) |
| 66 | { |
| 67 | int ret; |
| 68 | FILE *key_file; |
| 69 | size_t olen; |
Paul Bakker | 36713e8 | 2013-09-17 13:25:29 +0200 | [diff] [blame] | 70 | pk_context p_pk; |
| 71 | rsa_context *p_rsa; |
Paul Bakker | e6ee41f | 2012-05-19 08:43:48 +0000 | [diff] [blame] | 72 | RSA *o_rsa; |
| 73 | entropy_context entropy; |
| 74 | ctr_drbg_context ctr_drbg; |
| 75 | unsigned char input[1024]; |
| 76 | unsigned char p_pub_encrypted[512]; |
| 77 | unsigned char o_pub_encrypted[512]; |
| 78 | unsigned char p_pub_decrypted[512]; |
| 79 | unsigned char o_pub_decrypted[512]; |
| 80 | unsigned char p_priv_encrypted[512]; |
| 81 | unsigned char o_priv_encrypted[512]; |
| 82 | unsigned char p_priv_decrypted[512]; |
| 83 | unsigned char o_priv_decrypted[512]; |
Paul Bakker | ef3f8c7 | 2013-06-24 13:01:08 +0200 | [diff] [blame] | 84 | const char *pers = "o_p_test_example"; |
Paul Bakker | e6ee41f | 2012-05-19 08:43:48 +0000 | [diff] [blame] | 85 | |
| 86 | entropy_init( &entropy ); |
| 87 | if( ( ret = ctr_drbg_init( &ctr_drbg, entropy_func, &entropy, |
Paul Bakker | ef3f8c7 | 2013-06-24 13:01:08 +0200 | [diff] [blame] | 88 | (const unsigned char *) pers, |
| 89 | strlen( pers ) ) ) != 0 ) |
Paul Bakker | e6ee41f | 2012-05-19 08:43:48 +0000 | [diff] [blame] | 90 | { |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 91 | polarssl_printf( " failed\n ! ctr_drbg_init returned %d\n", ret ); |
Paul Bakker | e6ee41f | 2012-05-19 08:43:48 +0000 | [diff] [blame] | 92 | goto exit; |
| 93 | } |
| 94 | ERR_load_crypto_strings(); |
| 95 | |
| 96 | ret = 1; |
| 97 | |
| 98 | if( argc != 3 ) |
| 99 | { |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 100 | polarssl_printf( "usage: o_p_test <keyfile with private_key> <string of max 100 characters>\n" ); |
Paul Bakker | e6ee41f | 2012-05-19 08:43:48 +0000 | [diff] [blame] | 101 | |
| 102 | #ifdef WIN32 |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 103 | polarssl_printf( "\n" ); |
Paul Bakker | e6ee41f | 2012-05-19 08:43:48 +0000 | [diff] [blame] | 104 | #endif |
| 105 | |
| 106 | goto exit; |
| 107 | } |
| 108 | |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 109 | polarssl_printf( " . Reading private key from %s into mbed TLS ...", argv[1] ); |
Paul Bakker | e6ee41f | 2012-05-19 08:43:48 +0000 | [diff] [blame] | 110 | fflush( stdout ); |
| 111 | |
Paul Bakker | 36713e8 | 2013-09-17 13:25:29 +0200 | [diff] [blame] | 112 | pk_init( &p_pk ); |
| 113 | if( pk_parse_keyfile( &p_pk, argv[1], NULL ) != 0 ) |
Paul Bakker | e6ee41f | 2012-05-19 08:43:48 +0000 | [diff] [blame] | 114 | { |
| 115 | ret = 1; |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 116 | polarssl_printf( " failed\n ! Could not load key.\n\n" ); |
Paul Bakker | e6ee41f | 2012-05-19 08:43:48 +0000 | [diff] [blame] | 117 | goto exit; |
| 118 | } |
| 119 | |
Paul Bakker | 36713e8 | 2013-09-17 13:25:29 +0200 | [diff] [blame] | 120 | if( !pk_can_do( &p_pk, POLARSSL_PK_RSA ) ) |
| 121 | { |
| 122 | ret = 1; |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 123 | polarssl_printf( " failed\n ! Key is not an RSA key\n" ); |
Paul Bakker | 36713e8 | 2013-09-17 13:25:29 +0200 | [diff] [blame] | 124 | goto exit; |
| 125 | } |
| 126 | |
| 127 | p_rsa = pk_rsa( p_pk ); |
| 128 | |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 129 | polarssl_printf( " passed\n"); |
Paul Bakker | e6ee41f | 2012-05-19 08:43:48 +0000 | [diff] [blame] | 130 | |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 131 | polarssl_printf( " . Reading private key from %s into OpenSSL ...", argv[1] ); |
Paul Bakker | e6ee41f | 2012-05-19 08:43:48 +0000 | [diff] [blame] | 132 | fflush( stdout ); |
| 133 | |
| 134 | key_file = fopen( argv[1], "r" ); |
| 135 | o_rsa = PEM_read_RSAPrivateKey(key_file, 0, 0, 0); |
| 136 | fclose(key_file); |
| 137 | if( o_rsa == NULL ) |
| 138 | { |
| 139 | ret = 1; |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 140 | polarssl_printf( " failed\n ! Could not load key.\n\n" ); |
Paul Bakker | e6ee41f | 2012-05-19 08:43:48 +0000 | [diff] [blame] | 141 | goto exit; |
| 142 | } |
| 143 | |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 144 | polarssl_printf( " passed\n"); |
| 145 | polarssl_printf( "\n" ); |
Paul Bakker | e6ee41f | 2012-05-19 08:43:48 +0000 | [diff] [blame] | 146 | |
| 147 | if( strlen( argv[1] ) > 100 ) |
| 148 | { |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 149 | polarssl_printf( " Input data larger than 100 characters.\n\n" ); |
Paul Bakker | e6ee41f | 2012-05-19 08:43:48 +0000 | [diff] [blame] | 150 | goto exit; |
| 151 | } |
| 152 | |
| 153 | memcpy( input, argv[2], strlen( argv[2] ) ); |
| 154 | |
| 155 | /* |
| 156 | * Calculate the RSA encryption with public key. |
| 157 | */ |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 158 | polarssl_printf( " . Generating the RSA encrypted value with mbed TLS (RSA_PUBLIC) ..." ); |
Paul Bakker | e6ee41f | 2012-05-19 08:43:48 +0000 | [diff] [blame] | 159 | fflush( stdout ); |
| 160 | |
Paul Bakker | 36713e8 | 2013-09-17 13:25:29 +0200 | [diff] [blame] | 161 | if( ( ret = rsa_pkcs1_encrypt( p_rsa, ctr_drbg_random, &ctr_drbg, RSA_PUBLIC, strlen( argv[2] ), input, p_pub_encrypted ) ) != 0 ) |
Paul Bakker | e6ee41f | 2012-05-19 08:43:48 +0000 | [diff] [blame] | 162 | { |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 163 | polarssl_printf( " failed\n ! rsa_pkcs1_encrypt returned %d\n\n", ret ); |
Paul Bakker | e6ee41f | 2012-05-19 08:43:48 +0000 | [diff] [blame] | 164 | goto exit; |
| 165 | } |
| 166 | else |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 167 | polarssl_printf( " passed\n"); |
Paul Bakker | e6ee41f | 2012-05-19 08:43:48 +0000 | [diff] [blame] | 168 | |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 169 | polarssl_printf( " . Generating the RSA encrypted value with OpenSSL (PUBLIC) ..." ); |
Paul Bakker | e6ee41f | 2012-05-19 08:43:48 +0000 | [diff] [blame] | 170 | fflush( stdout ); |
| 171 | |
Paul Bakker | 36713e8 | 2013-09-17 13:25:29 +0200 | [diff] [blame] | 172 | if( ( ret = RSA_public_encrypt( strlen( argv[2] ), input, o_pub_encrypted, o_rsa, RSA_PKCS1_PADDING ) ) == -1 ) |
Paul Bakker | e6ee41f | 2012-05-19 08:43:48 +0000 | [diff] [blame] | 173 | { |
| 174 | unsigned long code = ERR_get_error(); |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 175 | polarssl_printf( " failed\n ! RSA_public_encrypt returned %d %s\n\n", ret, ERR_error_string( code, NULL ) ); |
Paul Bakker | e6ee41f | 2012-05-19 08:43:48 +0000 | [diff] [blame] | 176 | goto exit; |
| 177 | } |
| 178 | else |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 179 | polarssl_printf( " passed\n"); |
Paul Bakker | e6ee41f | 2012-05-19 08:43:48 +0000 | [diff] [blame] | 180 | |
| 181 | /* |
| 182 | * Calculate the RSA encryption with private key. |
| 183 | */ |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 184 | polarssl_printf( " . Generating the RSA encrypted value with mbed TLS (RSA_PRIVATE) ..." ); |
Paul Bakker | e6ee41f | 2012-05-19 08:43:48 +0000 | [diff] [blame] | 185 | fflush( stdout ); |
| 186 | |
Paul Bakker | 36713e8 | 2013-09-17 13:25:29 +0200 | [diff] [blame] | 187 | if( ( ret = rsa_pkcs1_encrypt( p_rsa, ctr_drbg_random, &ctr_drbg, RSA_PRIVATE, strlen( argv[2] ), input, p_priv_encrypted ) ) != 0 ) |
Paul Bakker | e6ee41f | 2012-05-19 08:43:48 +0000 | [diff] [blame] | 188 | { |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 189 | polarssl_printf( " failed\n ! rsa_pkcs1_encrypt returned %d\n\n", ret ); |
Paul Bakker | e6ee41f | 2012-05-19 08:43:48 +0000 | [diff] [blame] | 190 | goto exit; |
| 191 | } |
| 192 | else |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 193 | polarssl_printf( " passed\n"); |
Paul Bakker | e6ee41f | 2012-05-19 08:43:48 +0000 | [diff] [blame] | 194 | |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 195 | polarssl_printf( " . Generating the RSA encrypted value with OpenSSL (PRIVATE) ..." ); |
Paul Bakker | e6ee41f | 2012-05-19 08:43:48 +0000 | [diff] [blame] | 196 | fflush( stdout ); |
| 197 | |
Paul Bakker | 36713e8 | 2013-09-17 13:25:29 +0200 | [diff] [blame] | 198 | if( ( ret = RSA_private_encrypt( strlen( argv[2] ), input, o_priv_encrypted, o_rsa, RSA_PKCS1_PADDING ) ) == -1 ) |
Paul Bakker | e6ee41f | 2012-05-19 08:43:48 +0000 | [diff] [blame] | 199 | { |
| 200 | unsigned long code = ERR_get_error(); |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 201 | polarssl_printf( " failed\n ! RSA_private_encrypt returned %d %s\n\n", ret, ERR_error_string( code, NULL ) ); |
Paul Bakker | e6ee41f | 2012-05-19 08:43:48 +0000 | [diff] [blame] | 202 | goto exit; |
| 203 | } |
| 204 | else |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 205 | polarssl_printf( " passed\n"); |
Paul Bakker | e6ee41f | 2012-05-19 08:43:48 +0000 | [diff] [blame] | 206 | |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 207 | polarssl_printf( "\n" ); |
Paul Bakker | e6ee41f | 2012-05-19 08:43:48 +0000 | [diff] [blame] | 208 | |
| 209 | /* |
| 210 | * Calculate the RSA decryption with private key. |
| 211 | */ |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 212 | polarssl_printf( " . Generating the RSA decrypted value for OpenSSL (PUBLIC) with mbed TLS (PRIVATE) ..." ); |
Paul Bakker | e6ee41f | 2012-05-19 08:43:48 +0000 | [diff] [blame] | 213 | fflush( stdout ); |
| 214 | |
Paul Bakker | 36713e8 | 2013-09-17 13:25:29 +0200 | [diff] [blame] | 215 | if( ( ret = rsa_pkcs1_decrypt( p_rsa, ctr_drbg_random, &ctr_drbg, RSA_PRIVATE, &olen, o_pub_encrypted, p_pub_decrypted, 1024 ) ) != 0 ) |
Paul Bakker | e6ee41f | 2012-05-19 08:43:48 +0000 | [diff] [blame] | 216 | { |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 217 | polarssl_printf( " failed\n ! rsa_pkcs1_decrypt returned %d\n\n", ret ); |
Paul Bakker | e6ee41f | 2012-05-19 08:43:48 +0000 | [diff] [blame] | 218 | } |
| 219 | else |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 220 | polarssl_printf( " passed\n"); |
Paul Bakker | e6ee41f | 2012-05-19 08:43:48 +0000 | [diff] [blame] | 221 | |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 222 | polarssl_printf( " . Generating the RSA decrypted value for mbed TLS (PUBLIC) with OpenSSL (PRIVATE) ..." ); |
Paul Bakker | e6ee41f | 2012-05-19 08:43:48 +0000 | [diff] [blame] | 223 | fflush( stdout ); |
| 224 | |
Paul Bakker | 36713e8 | 2013-09-17 13:25:29 +0200 | [diff] [blame] | 225 | if( ( ret = RSA_private_decrypt( p_rsa->len, p_pub_encrypted, o_pub_decrypted, o_rsa, RSA_PKCS1_PADDING ) ) == -1 ) |
Paul Bakker | e6ee41f | 2012-05-19 08:43:48 +0000 | [diff] [blame] | 226 | { |
| 227 | unsigned long code = ERR_get_error(); |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 228 | polarssl_printf( " failed\n ! RSA_private_decrypt returned %d %s\n\n", ret, ERR_error_string( code, NULL ) ); |
Paul Bakker | e6ee41f | 2012-05-19 08:43:48 +0000 | [diff] [blame] | 229 | } |
| 230 | else |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 231 | polarssl_printf( " passed\n"); |
Paul Bakker | e6ee41f | 2012-05-19 08:43:48 +0000 | [diff] [blame] | 232 | |
| 233 | /* |
| 234 | * Calculate the RSA decryption with public key. |
| 235 | */ |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 236 | polarssl_printf( " . Generating the RSA decrypted value for OpenSSL (PRIVATE) with mbed TLS (PUBLIC) ..." ); |
Paul Bakker | e6ee41f | 2012-05-19 08:43:48 +0000 | [diff] [blame] | 237 | fflush( stdout ); |
| 238 | |
Paul Bakker | 36713e8 | 2013-09-17 13:25:29 +0200 | [diff] [blame] | 239 | if( ( ret = rsa_pkcs1_decrypt( p_rsa, NULL, NULL, RSA_PUBLIC, &olen, o_priv_encrypted, p_priv_decrypted, 1024 ) ) != 0 ) |
Paul Bakker | e6ee41f | 2012-05-19 08:43:48 +0000 | [diff] [blame] | 240 | { |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 241 | polarssl_printf( " failed\n ! rsa_pkcs1_decrypt returned %d\n\n", ret ); |
Paul Bakker | e6ee41f | 2012-05-19 08:43:48 +0000 | [diff] [blame] | 242 | } |
| 243 | else |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 244 | polarssl_printf( " passed\n"); |
Paul Bakker | e6ee41f | 2012-05-19 08:43:48 +0000 | [diff] [blame] | 245 | |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 246 | polarssl_printf( " . Generating the RSA decrypted value for mbed TLS (PRIVATE) with OpenSSL (PUBLIC) ..." ); |
Paul Bakker | e6ee41f | 2012-05-19 08:43:48 +0000 | [diff] [blame] | 247 | fflush( stdout ); |
| 248 | |
Paul Bakker | 36713e8 | 2013-09-17 13:25:29 +0200 | [diff] [blame] | 249 | if( ( ret = RSA_public_decrypt( p_rsa->len, p_priv_encrypted, o_priv_decrypted, o_rsa, RSA_PKCS1_PADDING ) ) == -1 ) |
Paul Bakker | e6ee41f | 2012-05-19 08:43:48 +0000 | [diff] [blame] | 250 | { |
| 251 | unsigned long code = ERR_get_error(); |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 252 | polarssl_printf( " failed\n ! RSA_public_decrypt returned %d %s\n\n", ret, ERR_error_string( code, NULL ) ); |
Paul Bakker | e6ee41f | 2012-05-19 08:43:48 +0000 | [diff] [blame] | 253 | } |
| 254 | else |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 255 | polarssl_printf( " passed\n"); |
Paul Bakker | e6ee41f | 2012-05-19 08:43:48 +0000 | [diff] [blame] | 256 | |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 257 | polarssl_printf( "\n" ); |
| 258 | polarssl_printf( "String value (OpenSSL Public Encrypt, mbed TLS Private Decrypt): '%s'\n", p_pub_decrypted ); |
| 259 | polarssl_printf( "String value (mbed TLS Public Encrypt, OpenSSL Private Decrypt): '%s'\n", o_pub_decrypted ); |
| 260 | polarssl_printf( "String value (OpenSSL Private Encrypt, mbed TLS Public Decrypt): '%s'\n", p_priv_decrypted ); |
| 261 | polarssl_printf( "String value (mbed TLS Private Encrypt, OpenSSL Public Decrypt): '%s'\n", o_priv_decrypted ); |
Paul Bakker | e6ee41f | 2012-05-19 08:43:48 +0000 | [diff] [blame] | 262 | |
| 263 | exit: |
Paul Bakker | a317a98 | 2014-06-18 16:44:11 +0200 | [diff] [blame] | 264 | ctr_drbg_free( &ctr_drbg ); |
Paul Bakker | 1ffefac | 2013-09-28 15:23:03 +0200 | [diff] [blame] | 265 | entropy_free( &entropy ); |
Paul Bakker | e6ee41f | 2012-05-19 08:43:48 +0000 | [diff] [blame] | 266 | |
| 267 | #ifdef WIN32 |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 268 | polarssl_printf( " + Press Enter to exit this program.\n" ); |
Paul Bakker | e6ee41f | 2012-05-19 08:43:48 +0000 | [diff] [blame] | 269 | fflush( stdout ); getchar(); |
| 270 | #endif |
| 271 | |
| 272 | return( ret ); |
| 273 | } |
Paul Bakker | ed27a04 | 2013-04-18 22:46:23 +0200 | [diff] [blame] | 274 | #endif /* POLARSSL_BIGNUM_C && POLARSSL_RSA_C && |
Paul Bakker | 36713e8 | 2013-09-17 13:25:29 +0200 | [diff] [blame] | 275 | POLARSSL_PK_PARSE_C && POLARSSL_FS_IO */ |