PolarSSL v1.1.4
test_suite_rsa.c
Go to the documentation of this file.
00001 #include "fct.h"
00002 
00003 #include <polarssl/rsa.h>
00004 #include <polarssl/md2.h>
00005 #include <polarssl/md4.h>
00006 #include <polarssl/md5.h>
00007 #include <polarssl/sha1.h>
00008 #include <polarssl/sha2.h>
00009 #include <polarssl/sha4.h>
00010 #include <polarssl/entropy.h>
00011 #include <polarssl/ctr_drbg.h>
00012 
00013 #include <polarssl/config.h>
00014 
00015 #ifdef _MSC_VER
00016 #include <basetsd.h>
00017 typedef UINT32 uint32_t;
00018 #else
00019 #include <inttypes.h>
00020 #endif
00021 
00022 /*
00023  * 32-bit integer manipulation macros (big endian)
00024  */
00025 #ifndef GET_ULONG_BE
00026 #define GET_ULONG_BE(n,b,i)                             \
00027 {                                                       \
00028     (n) = ( (unsigned long) (b)[(i)    ] << 24 )        \
00029         | ( (unsigned long) (b)[(i) + 1] << 16 )        \
00030         | ( (unsigned long) (b)[(i) + 2] <<  8 )        \
00031         | ( (unsigned long) (b)[(i) + 3]       );       \
00032 }
00033 #endif
00034 
00035 #ifndef PUT_ULONG_BE
00036 #define PUT_ULONG_BE(n,b,i)                             \
00037 {                                                       \
00038     (b)[(i)    ] = (unsigned char) ( (n) >> 24 );       \
00039     (b)[(i) + 1] = (unsigned char) ( (n) >> 16 );       \
00040     (b)[(i) + 2] = (unsigned char) ( (n) >>  8 );       \
00041     (b)[(i) + 3] = (unsigned char) ( (n)       );       \
00042 }
00043 #endif
00044 
00045 int unhexify(unsigned char *obuf, const char *ibuf)
00046 {
00047     unsigned char c, c2;
00048     int len = strlen(ibuf) / 2;
00049     assert(!(strlen(ibuf) %1)); // must be even number of bytes
00050 
00051     while (*ibuf != 0)
00052     {
00053         c = *ibuf++;
00054         if( c >= '0' && c <= '9' )
00055             c -= '0';
00056         else if( c >= 'a' && c <= 'f' )
00057             c -= 'a' - 10;
00058         else if( c >= 'A' && c <= 'F' )
00059             c -= 'A' - 10;
00060         else
00061             assert( 0 );
00062 
00063         c2 = *ibuf++;
00064         if( c2 >= '0' && c2 <= '9' )
00065             c2 -= '0';
00066         else if( c2 >= 'a' && c2 <= 'f' )
00067             c2 -= 'a' - 10;
00068         else if( c2 >= 'A' && c2 <= 'F' )
00069             c2 -= 'A' - 10;
00070         else
00071             assert( 0 );
00072 
00073         *obuf++ = ( c << 4 ) | c2;
00074     }
00075 
00076     return len;
00077 }
00078 
00079 void hexify(unsigned char *obuf, const unsigned char *ibuf, int len)
00080 {
00081     unsigned char l, h;
00082 
00083     while (len != 0)
00084     {
00085         h = (*ibuf) / 16;
00086         l = (*ibuf) % 16;
00087 
00088         if( h < 10 )
00089             *obuf++ = '0' + h;
00090         else
00091             *obuf++ = 'a' + h - 10;
00092 
00093         if( l < 10 )
00094             *obuf++ = '0' + l;
00095         else
00096             *obuf++ = 'a' + l - 10;
00097 
00098         ++ibuf;
00099         len--;
00100     }
00101 }
00102 
00112 static int rnd_std_rand( void *rng_state, unsigned char *output, size_t len )
00113 {
00114     size_t i;
00115 
00116     if( rng_state != NULL )
00117         rng_state  = NULL;
00118 
00119     for( i = 0; i < len; ++i )
00120         output[i] = rand();
00121 
00122     return( 0 );
00123 }
00124 
00130 static int rnd_zero_rand( void *rng_state, unsigned char *output, size_t len )
00131 {
00132     if( rng_state != NULL )
00133         rng_state  = NULL;
00134 
00135     memset( output, 0, len );
00136 
00137     return( 0 );
00138 }
00139 
00140 typedef struct
00141 {
00142     unsigned char *buf;
00143     size_t length;
00144 } rnd_buf_info;
00145 
00157 static int rnd_buffer_rand( void *rng_state, unsigned char *output, size_t len )
00158 {
00159     rnd_buf_info *info = (rnd_buf_info *) rng_state;
00160     size_t use_len;
00161 
00162     if( rng_state == NULL )
00163         return( rnd_std_rand( NULL, output, len ) );
00164 
00165     use_len = len;
00166     if( len > info->length )
00167         use_len = info->length;
00168 
00169     if( use_len )
00170     {
00171         memcpy( output, info->buf, use_len );
00172         info->buf += use_len;
00173         info->length -= use_len;
00174     }
00175 
00176     if( len - use_len > 0 )
00177         return( rnd_std_rand( NULL, output + use_len, len - use_len ) );
00178 
00179     return( 0 );
00180 }
00181 
00189 typedef struct
00190 {
00191     uint32_t key[16];
00192     uint32_t v0, v1;
00193 } rnd_pseudo_info;
00194 
00203 static int rnd_pseudo_rand( void *rng_state, unsigned char *output, size_t len )
00204 {
00205     rnd_pseudo_info *info = (rnd_pseudo_info *) rng_state;
00206     uint32_t i, *k, sum, delta=0x9E3779B9;
00207     unsigned char result[4];
00208 
00209     if( rng_state == NULL )
00210         return( rnd_std_rand( NULL, output, len ) );
00211 
00212     k = info->key;
00213 
00214     while( len > 0 )
00215     {
00216         size_t use_len = ( len > 4 ) ? 4 : len;
00217         sum = 0;
00218 
00219         for( i = 0; i < 32; i++ )
00220         {
00221             info->v0 += (((info->v1 << 4) ^ (info->v1 >> 5)) + info->v1) ^ (sum + k[sum & 3]);
00222             sum += delta;
00223             info->v1 += (((info->v0 << 4) ^ (info->v0 >> 5)) + info->v0) ^ (sum + k[(sum>>11) & 3]);
00224         }
00225 
00226         PUT_ULONG_BE( info->v0, result, 0 );
00227         memcpy( output, result, use_len );
00228         len -= use_len;
00229     }
00230 
00231     return( 0 );
00232 }
00233 
00234 
00235 FCT_BGN()
00236 {
00237 #ifdef POLARSSL_RSA_C
00238 #ifdef POLARSSL_BIGNUM_C
00239 #ifdef POLARSSL_GENPRIME
00240 
00241 
00242     FCT_SUITE_BGN(test_suite_rsa)
00243     {
00244 #ifdef POLARSSL_SHA1_C
00245 
00246         FCT_TEST_BGN(rsa_pkcs1_verify_v15_cavs_1)
00247         {
00248             unsigned char message_str[1000];
00249             unsigned char hash_result[1000];
00250             unsigned char result_str[1000];
00251             rsa_context ctx;
00252             int msg_len;
00253         
00254             rsa_init( &ctx, RSA_PKCS_V15, 0 );
00255             memset( message_str, 0x00, 1000 );
00256             memset( hash_result, 0x00, 1000 );
00257             memset( result_str, 0x00, 1000 );
00258         
00259             ctx.len = 1024 / 8;
00260             fct_chk( mpi_read_string( &ctx.N, 16, "e28a13548525e5f36dccb24ecb7cc332cc689dfd64012604c9c7816d72a16c3f5fcdc0e86e7c03280b1c69b586ce0cd8aec722cc73a5d3b730310bf7dfebdc77ce5d94bbc369dc18a2f7b07bd505ab0f82224aef09fdc1e5063234255e0b3c40a52e9e8ae60898eb88a766bdd788fe9493d8fd86bcdd2884d5c06216c65469e5" ) == 0 );
00261             fct_chk( mpi_read_string( &ctx.E, 16, "3" ) == 0 );
00262         
00263             fct_chk( rsa_check_pubkey( &ctx ) == 0 );
00264         
00265             msg_len = unhexify( message_str, "d6248c3e96b1a7e5fea978870fcc4c9786b4e5156e16b7faef4557d667f730b8bc4c784ef00c624df5309513c3a5de8ca94c2152e0459618666d3148092562ebc256ffca45b27fd2d63c68bd5e0a0aefbe496e9e63838a361b1db6fc272464f191490bf9c029643c49d2d9cd08833b8a70b4b3431f56fb1eb55ccd39e77a9c92" );
00266             unhexify( result_str, "3203b7647fb7e345aa457681e5131777f1adc371f2fba8534928c4e52ef6206a856425d6269352ecbf64db2f6ad82397768cafdd8cd272e512d617ad67992226da6bc291c31404c17fd4b7e2beb20eff284a44f4d7af47fd6629e2c95809fa7f2241a04f70ac70d3271bb13258af1ed5c5988c95df7fa26603515791075feccd" );
00267         
00268             switch( SIG_RSA_SHA1 )
00269             {
00270         #ifdef POLARSSL_MD2_C
00271             case SIG_RSA_MD2:
00272                 md2( message_str, msg_len, hash_result );
00273                 break;
00274         #endif
00275         #ifdef POLARSSL_MD4_C
00276             case SIG_RSA_MD4:
00277                 md4( message_str, msg_len, hash_result );
00278                 break;
00279         #endif
00280         #ifdef POLARSSL_MD5_C
00281             case SIG_RSA_MD5:
00282                 md5( message_str, msg_len, hash_result );
00283                 break;
00284         #endif
00285         #ifdef POLARSSL_SHA1_C
00286             case SIG_RSA_SHA1:
00287                 sha1( message_str, msg_len, hash_result );
00288                 break;
00289         #endif
00290         #ifdef POLARSSL_SHA2_C
00291             case SIG_RSA_SHA224:
00292                 sha2( message_str, msg_len, hash_result, 1 );
00293                 break;
00294             case SIG_RSA_SHA256:
00295                 sha2( message_str, msg_len, hash_result, 0 );
00296                 break;
00297         #endif
00298         #ifdef POLARSSL_SHA4_C
00299             case SIG_RSA_SHA384:
00300                 sha4( message_str, msg_len, hash_result, 1 );
00301                 break;
00302             case SIG_RSA_SHA512:
00303                 sha4( message_str, msg_len, hash_result, 0 );
00304                 break;
00305         #endif
00306             }
00307         
00308             fct_chk( rsa_pkcs1_verify( &ctx, RSA_PUBLIC, SIG_RSA_SHA1, 0, hash_result, result_str ) == POLARSSL_ERR_RSA_VERIFY_FAILED );
00309         }
00310         FCT_TEST_END();
00311 #endif /* POLARSSL_SHA1_C */
00312 
00313 #ifdef POLARSSL_SHA1_C
00314 
00315         FCT_TEST_BGN(rsa_pkcs1_verify_v15_cavs_2)
00316         {
00317             unsigned char message_str[1000];
00318             unsigned char hash_result[1000];
00319             unsigned char result_str[1000];
00320             rsa_context ctx;
00321             int msg_len;
00322         
00323             rsa_init( &ctx, RSA_PKCS_V15, 0 );
00324             memset( message_str, 0x00, 1000 );
00325             memset( hash_result, 0x00, 1000 );
00326             memset( result_str, 0x00, 1000 );
00327         
00328             ctx.len = 1024 / 8;
00329             fct_chk( mpi_read_string( &ctx.N, 16, "e28a13548525e5f36dccb24ecb7cc332cc689dfd64012604c9c7816d72a16c3f5fcdc0e86e7c03280b1c69b586ce0cd8aec722cc73a5d3b730310bf7dfebdc77ce5d94bbc369dc18a2f7b07bd505ab0f82224aef09fdc1e5063234255e0b3c40a52e9e8ae60898eb88a766bdd788fe9493d8fd86bcdd2884d5c06216c65469e5" ) == 0 );
00330             fct_chk( mpi_read_string( &ctx.E, 16, "3" ) == 0 );
00331         
00332             fct_chk( rsa_check_pubkey( &ctx ) == 0 );
00333         
00334             msg_len = unhexify( message_str, "206ef4bf396c6087f8229ef196fd35f37ccb8de5efcdb238f20d556668f114257a11fbe038464a67830378e62ae9791453953dac1dbd7921837ba98e84e856eb80ed9487e656d0b20c28c8ba5e35db1abbed83ed1c7720a97701f709e3547a4bfcabca9c89c57ad15c3996577a0ae36d7c7b699035242f37954646c1cd5c08ac" );
00335             unhexify( result_str, "5abc01f5de25b70867ff0c24e222c61f53c88daf42586fddcd56f3c4588f074be3c328056c063388688b6385a8167957c6e5355a510e005b8a851d69c96b36ec6036644078210e5d7d326f96365ee0648882921492bc7b753eb9c26cdbab37555f210df2ca6fec1b25b463d38b81c0dcea202022b04af5da58aa03d77be949b7" );
00336         
00337             switch( SIG_RSA_SHA1 )
00338             {
00339         #ifdef POLARSSL_MD2_C
00340             case SIG_RSA_MD2:
00341                 md2( message_str, msg_len, hash_result );
00342                 break;
00343         #endif
00344         #ifdef POLARSSL_MD4_C
00345             case SIG_RSA_MD4:
00346                 md4( message_str, msg_len, hash_result );
00347                 break;
00348         #endif
00349         #ifdef POLARSSL_MD5_C
00350             case SIG_RSA_MD5:
00351                 md5( message_str, msg_len, hash_result );
00352                 break;
00353         #endif
00354         #ifdef POLARSSL_SHA1_C
00355             case SIG_RSA_SHA1:
00356                 sha1( message_str, msg_len, hash_result );
00357                 break;
00358         #endif
00359         #ifdef POLARSSL_SHA2_C
00360             case SIG_RSA_SHA224:
00361                 sha2( message_str, msg_len, hash_result, 1 );
00362                 break;
00363             case SIG_RSA_SHA256:
00364                 sha2( message_str, msg_len, hash_result, 0 );
00365                 break;
00366         #endif
00367         #ifdef POLARSSL_SHA4_C
00368             case SIG_RSA_SHA384:
00369                 sha4( message_str, msg_len, hash_result, 1 );
00370                 break;
00371             case SIG_RSA_SHA512:
00372                 sha4( message_str, msg_len, hash_result, 0 );
00373                 break;
00374         #endif
00375             }
00376         
00377             fct_chk( rsa_pkcs1_verify( &ctx, RSA_PUBLIC, SIG_RSA_SHA1, 0, hash_result, result_str ) == 0 );
00378         }
00379         FCT_TEST_END();
00380 #endif /* POLARSSL_SHA1_C */
00381 
00382 #ifdef POLARSSL_SHA1_C
00383 
00384         FCT_TEST_BGN(rsa_pkcs1_verify_v15_cavs_3)
00385         {
00386             unsigned char message_str[1000];
00387             unsigned char hash_result[1000];
00388             unsigned char result_str[1000];
00389             rsa_context ctx;
00390             int msg_len;
00391         
00392             rsa_init( &ctx, RSA_PKCS_V15, 0 );
00393             memset( message_str, 0x00, 1000 );
00394             memset( hash_result, 0x00, 1000 );
00395             memset( result_str, 0x00, 1000 );
00396         
00397             ctx.len = 1024 / 8;
00398             fct_chk( mpi_read_string( &ctx.N, 16, "e28a13548525e5f36dccb24ecb7cc332cc689dfd64012604c9c7816d72a16c3f5fcdc0e86e7c03280b1c69b586ce0cd8aec722cc73a5d3b730310bf7dfebdc77ce5d94bbc369dc18a2f7b07bd505ab0f82224aef09fdc1e5063234255e0b3c40a52e9e8ae60898eb88a766bdd788fe9493d8fd86bcdd2884d5c06216c65469e5" ) == 0 );
00399             fct_chk( mpi_read_string( &ctx.E, 16, "3" ) == 0 );
00400         
00401             fct_chk( rsa_check_pubkey( &ctx ) == 0 );
00402         
00403             msg_len = unhexify( message_str, "206ef4bf396c6087f8229ef196fd35f37ccb8de5efcdb238f20d556668f114257a11fbe038464a67830378e62ae9791453953dac1dbd7921837ba98e84e856eb80ed9487e656d0b20c28c8ba5e35db1abbed83ed1c7720a97701f709e3547a4bfcabca9c89c57ad15c3996577a0ae36d7c7b699035242f37954646c1cd5c08ac" );
00404             unhexify( result_str, "5abc01f5de25b70867ff0c24e222c61f53c88daf42586fddcd56f3c4588f074be3c328056c063388688b6385a8167957c6e5355a510e005b8a851d69c96b36ec6036644078210e5d7d326f96365ee0648882921492bc7b753eb9c26cdbab37555f210df2ca6fec1b25b463d38b81c0dcea202022b04af5da58aa03d77be949b7" );
00405         
00406             switch( SIG_RSA_SHA1 )
00407             {
00408         #ifdef POLARSSL_MD2_C
00409             case SIG_RSA_MD2:
00410                 md2( message_str, msg_len, hash_result );
00411                 break;
00412         #endif
00413         #ifdef POLARSSL_MD4_C
00414             case SIG_RSA_MD4:
00415                 md4( message_str, msg_len, hash_result );
00416                 break;
00417         #endif
00418         #ifdef POLARSSL_MD5_C
00419             case SIG_RSA_MD5:
00420                 md5( message_str, msg_len, hash_result );
00421                 break;
00422         #endif
00423         #ifdef POLARSSL_SHA1_C
00424             case SIG_RSA_SHA1:
00425                 sha1( message_str, msg_len, hash_result );
00426                 break;
00427         #endif
00428         #ifdef POLARSSL_SHA2_C
00429             case SIG_RSA_SHA224:
00430                 sha2( message_str, msg_len, hash_result, 1 );
00431                 break;
00432             case SIG_RSA_SHA256:
00433                 sha2( message_str, msg_len, hash_result, 0 );
00434                 break;
00435         #endif
00436         #ifdef POLARSSL_SHA4_C
00437             case SIG_RSA_SHA384:
00438                 sha4( message_str, msg_len, hash_result, 1 );
00439                 break;
00440             case SIG_RSA_SHA512:
00441                 sha4( message_str, msg_len, hash_result, 0 );
00442                 break;
00443         #endif
00444             }
00445         
00446             fct_chk( rsa_pkcs1_verify( &ctx, RSA_PUBLIC, SIG_RSA_SHA1, 0, hash_result, result_str ) == 0 );
00447         }
00448         FCT_TEST_END();
00449 #endif /* POLARSSL_SHA1_C */
00450 
00451 #ifdef POLARSSL_SHA2_C
00452 
00453         FCT_TEST_BGN(rsa_pkcs1_verify_v15_cavs_4)
00454         {
00455             unsigned char message_str[1000];
00456             unsigned char hash_result[1000];
00457             unsigned char result_str[1000];
00458             rsa_context ctx;
00459             int msg_len;
00460         
00461             rsa_init( &ctx, RSA_PKCS_V15, 0 );
00462             memset( message_str, 0x00, 1000 );
00463             memset( hash_result, 0x00, 1000 );
00464             memset( result_str, 0x00, 1000 );
00465         
00466             ctx.len = 1024 / 8;
00467             fct_chk( mpi_read_string( &ctx.N, 16, "e28a13548525e5f36dccb24ecb7cc332cc689dfd64012604c9c7816d72a16c3f5fcdc0e86e7c03280b1c69b586ce0cd8aec722cc73a5d3b730310bf7dfebdc77ce5d94bbc369dc18a2f7b07bd505ab0f82224aef09fdc1e5063234255e0b3c40a52e9e8ae60898eb88a766bdd788fe9493d8fd86bcdd2884d5c06216c65469e5" ) == 0 );
00468             fct_chk( mpi_read_string( &ctx.E, 16, "3" ) == 0 );
00469         
00470             fct_chk( rsa_check_pubkey( &ctx ) == 0 );
00471         
00472             msg_len = unhexify( message_str, "867ac26e11a13b7ac34a42a1e177648692861226effb55bb597fbde10f299bf7fffd6fc8ddb2a46a73b97b67387a461b23e1d65dc119366286979add615b926b9272832fc0c058b946fc752dcffceca12233f4c63f7897cbaa08aa7e07cf02b5e7e3e5ece252bf2fe61d163bce84c0e0368454a98e9fdebf6edbd70b290d549b" );
00473             unhexify( result_str, "3bb7b1c5f3391de4549e2e96fd33afa4d647dd90e321d9d576f3808e32213e948b697ef4fd2dd12923de6ec3ffd625078a57f86af38dc07052bb50547c616ed51fa1352b3ab66788408168d21263ef2d3388d567d2ce8cf674f45491ab2b0319d47be1266bda39e343b2a38ea2d6aaaee6c4465aee1d7bb33e93a1c40a8e3ae4" );
00474         
00475             switch( SIG_RSA_SHA224 )
00476             {
00477         #ifdef POLARSSL_MD2_C
00478             case SIG_RSA_MD2:
00479                 md2( message_str, msg_len, hash_result );
00480                 break;
00481         #endif
00482         #ifdef POLARSSL_MD4_C
00483             case SIG_RSA_MD4:
00484                 md4( message_str, msg_len, hash_result );
00485                 break;
00486         #endif
00487         #ifdef POLARSSL_MD5_C
00488             case SIG_RSA_MD5:
00489                 md5( message_str, msg_len, hash_result );
00490                 break;
00491         #endif
00492         #ifdef POLARSSL_SHA1_C
00493             case SIG_RSA_SHA1:
00494                 sha1( message_str, msg_len, hash_result );
00495                 break;
00496         #endif
00497         #ifdef POLARSSL_SHA2_C
00498             case SIG_RSA_SHA224:
00499                 sha2( message_str, msg_len, hash_result, 1 );
00500                 break;
00501             case SIG_RSA_SHA256:
00502                 sha2( message_str, msg_len, hash_result, 0 );
00503                 break;
00504         #endif
00505         #ifdef POLARSSL_SHA4_C
00506             case SIG_RSA_SHA384:
00507                 sha4( message_str, msg_len, hash_result, 1 );
00508                 break;
00509             case SIG_RSA_SHA512:
00510                 sha4( message_str, msg_len, hash_result, 0 );
00511                 break;
00512         #endif
00513             }
00514         
00515             fct_chk( rsa_pkcs1_verify( &ctx, RSA_PUBLIC, SIG_RSA_SHA224, 0, hash_result, result_str ) == 0 );
00516         }
00517         FCT_TEST_END();
00518 #endif /* POLARSSL_SHA2_C */
00519 
00520 #ifdef POLARSSL_SHA2_C
00521 
00522         FCT_TEST_BGN(rsa_pkcs1_verify_v15_cavs_5)
00523         {
00524             unsigned char message_str[1000];
00525             unsigned char hash_result[1000];
00526             unsigned char result_str[1000];
00527             rsa_context ctx;
00528             int msg_len;
00529         
00530             rsa_init( &ctx, RSA_PKCS_V15, 0 );
00531             memset( message_str, 0x00, 1000 );
00532             memset( hash_result, 0x00, 1000 );
00533             memset( result_str, 0x00, 1000 );
00534         
00535             ctx.len = 1024 / 8;
00536             fct_chk( mpi_read_string( &ctx.N, 16, "e28a13548525e5f36dccb24ecb7cc332cc689dfd64012604c9c7816d72a16c3f5fcdc0e86e7c03280b1c69b586ce0cd8aec722cc73a5d3b730310bf7dfebdc77ce5d94bbc369dc18a2f7b07bd505ab0f82224aef09fdc1e5063234255e0b3c40a52e9e8ae60898eb88a766bdd788fe9493d8fd86bcdd2884d5c06216c65469e5" ) == 0 );
00537             fct_chk( mpi_read_string( &ctx.E, 16, "3" ) == 0 );
00538         
00539             fct_chk( rsa_check_pubkey( &ctx ) == 0 );
00540         
00541             msg_len = unhexify( message_str, "cd810e97dc21095ea7a0238027a7bafd343e01444785ea9184a44a79f80438c41fc0b57aa95693407da38fe5ff0ec1398e03361e51a3dbe134b99cca2df0cef1c444ca54d2b7db2789455b6bb41918c24001fd82fc20ee089de3f34f053699c1c5f7954ce0aaabb9d26fce39d032894152229d98cf64ecafc7089530073c61d9" );
00542             unhexify( result_str, "7b5fba70ec5b521638f182bcab39cec30b76e7bc017bdbd1059658a9a1db0969ab482dce32f3e9865952f0a0de0978272c951e3c015328ea3758f47029a379ab4200550fba58f11d51264878406fc717d5f7b72b3582946f16a7e5314a220881fc820f7d29949710273421533d8ac0a449dc6d0fd1a21c22444edd1c0d5b44d3" );
00543         
00544             switch( SIG_RSA_SHA256 )
00545             {
00546         #ifdef POLARSSL_MD2_C
00547             case SIG_RSA_MD2:
00548                 md2( message_str, msg_len, hash_result );
00549                 break;
00550         #endif
00551         #ifdef POLARSSL_MD4_C
00552             case SIG_RSA_MD4:
00553                 md4( message_str, msg_len, hash_result );
00554                 break;
00555         #endif
00556         #ifdef POLARSSL_MD5_C
00557             case SIG_RSA_MD5:
00558                 md5( message_str, msg_len, hash_result );
00559                 break;
00560         #endif
00561         #ifdef POLARSSL_SHA1_C
00562             case SIG_RSA_SHA1:
00563                 sha1( message_str, msg_len, hash_result );
00564                 break;
00565         #endif
00566         #ifdef POLARSSL_SHA2_C
00567             case SIG_RSA_SHA224:
00568                 sha2( message_str, msg_len, hash_result, 1 );
00569                 break;
00570             case SIG_RSA_SHA256:
00571                 sha2( message_str, msg_len, hash_result, 0 );
00572                 break;
00573         #endif
00574         #ifdef POLARSSL_SHA4_C
00575             case SIG_RSA_SHA384:
00576                 sha4( message_str, msg_len, hash_result, 1 );
00577                 break;
00578             case SIG_RSA_SHA512:
00579                 sha4( message_str, msg_len, hash_result, 0 );
00580                 break;
00581         #endif
00582             }
00583         
00584             fct_chk( rsa_pkcs1_verify( &ctx, RSA_PUBLIC, SIG_RSA_SHA256, 0, hash_result, result_str ) == 0 );
00585         }
00586         FCT_TEST_END();
00587 #endif /* POLARSSL_SHA2_C */
00588 
00589 #ifdef POLARSSL_SHA4_C
00590 
00591         FCT_TEST_BGN(rsa_pkcs1_verify_v15_cavs_6)
00592         {
00593             unsigned char message_str[1000];
00594             unsigned char hash_result[1000];
00595             unsigned char result_str[1000];
00596             rsa_context ctx;
00597             int msg_len;
00598         
00599             rsa_init( &ctx, RSA_PKCS_V15, 0 );
00600             memset( message_str, 0x00, 1000 );
00601             memset( hash_result, 0x00, 1000 );
00602             memset( result_str, 0x00, 1000 );
00603         
00604             ctx.len = 1024 / 8;
00605             fct_chk( mpi_read_string( &ctx.N, 16, "e28a13548525e5f36dccb24ecb7cc332cc689dfd64012604c9c7816d72a16c3f5fcdc0e86e7c03280b1c69b586ce0cd8aec722cc73a5d3b730310bf7dfebdc77ce5d94bbc369dc18a2f7b07bd505ab0f82224aef09fdc1e5063234255e0b3c40a52e9e8ae60898eb88a766bdd788fe9493d8fd86bcdd2884d5c06216c65469e5" ) == 0 );
00606             fct_chk( mpi_read_string( &ctx.E, 16, "3" ) == 0 );
00607         
00608             fct_chk( rsa_check_pubkey( &ctx ) == 0 );
00609         
00610             msg_len = unhexify( message_str, "44637d3b8de525fd589237bc81229c8966d3af24540850c24036330db8007e6d19a19486018b2b02074da590aaba9d2c8848c0a2d1b6de4dfaf24025b6393df9228008f83f13cc76a67cfbed77a6e3429342824a0b6a9b8dd884094acc6a54bbc8c8829930c52fe39ce5e0dcd02d9553ef899d26eb6cae0940b63584e2daeb3b" );
00611             unhexify( result_str, "38fc4f6f0430bb3ea9f470a4c0f5cebdabac4dbeb3b9c99d4168e7b00f5eb294ec0ece1908eded1f3e14f1e69d10f9feb425bda0c998af945ef864298a60a675f0bb5c540a7be3f534d5faddff974eea8bffe182a44e2ee1f4f653e71967a11869ee1a850edb03cb44a340378cb7a1bc9616d3649b78002b390a05a7e54edec6" );
00612         
00613             switch( SIG_RSA_SHA384 )
00614             {
00615         #ifdef POLARSSL_MD2_C
00616             case SIG_RSA_MD2:
00617                 md2( message_str, msg_len, hash_result );
00618                 break;
00619         #endif
00620         #ifdef POLARSSL_MD4_C
00621             case SIG_RSA_MD4:
00622                 md4( message_str, msg_len, hash_result );
00623                 break;
00624         #endif
00625         #ifdef POLARSSL_MD5_C
00626             case SIG_RSA_MD5:
00627                 md5( message_str, msg_len, hash_result );
00628                 break;
00629         #endif
00630         #ifdef POLARSSL_SHA1_C
00631             case SIG_RSA_SHA1:
00632                 sha1( message_str, msg_len, hash_result );
00633                 break;
00634         #endif
00635         #ifdef POLARSSL_SHA2_C
00636             case SIG_RSA_SHA224:
00637                 sha2( message_str, msg_len, hash_result, 1 );
00638                 break;
00639             case SIG_RSA_SHA256:
00640                 sha2( message_str, msg_len, hash_result, 0 );
00641                 break;
00642         #endif
00643         #ifdef POLARSSL_SHA4_C
00644             case SIG_RSA_SHA384:
00645                 sha4( message_str, msg_len, hash_result, 1 );
00646                 break;
00647             case SIG_RSA_SHA512:
00648                 sha4( message_str, msg_len, hash_result, 0 );
00649                 break;
00650         #endif
00651             }
00652         
00653             fct_chk( rsa_pkcs1_verify( &ctx, RSA_PUBLIC, SIG_RSA_SHA384, 0, hash_result, result_str ) == 0 );
00654         }
00655         FCT_TEST_END();
00656 #endif /* POLARSSL_SHA4_C */
00657 
00658 #ifdef POLARSSL_SHA4_C
00659 
00660         FCT_TEST_BGN(rsa_pkcs1_verify_v15_cavs_7)
00661         {
00662             unsigned char message_str[1000];
00663             unsigned char hash_result[1000];
00664             unsigned char result_str[1000];
00665             rsa_context ctx;
00666             int msg_len;
00667         
00668             rsa_init( &ctx, RSA_PKCS_V15, 0 );
00669             memset( message_str, 0x00, 1000 );
00670             memset( hash_result, 0x00, 1000 );
00671             memset( result_str, 0x00, 1000 );
00672         
00673             ctx.len = 1024 / 8;
00674             fct_chk( mpi_read_string( &ctx.N, 16, "e28a13548525e5f36dccb24ecb7cc332cc689dfd64012604c9c7816d72a16c3f5fcdc0e86e7c03280b1c69b586ce0cd8aec722cc73a5d3b730310bf7dfebdc77ce5d94bbc369dc18a2f7b07bd505ab0f82224aef09fdc1e5063234255e0b3c40a52e9e8ae60898eb88a766bdd788fe9493d8fd86bcdd2884d5c06216c65469e5" ) == 0 );
00675             fct_chk( mpi_read_string( &ctx.E, 16, "3" ) == 0 );
00676         
00677             fct_chk( rsa_check_pubkey( &ctx ) == 0 );
00678         
00679             msg_len = unhexify( message_str, "d03f12276f6ba7545b8fce719471bd253791878809694e8754f3b389f26c9253a758ed28b4c62535a8d5702d7a778731d5759ff2b3b39b192db680e791632918b6093c0e8ca25c2bf756a07fde4144a37f769fe4054455a45cb8cefe4462e7a9a45ce71f2189b4fef01b47aee8585d44dc9d6fa627a3e5f08801871731f234cd" );
00680             unhexify( result_str, "d93a878c1ce86571590b0e43794b3edb23552797c4b8c9e3da4fe1cc4ac0566acd3b10541fe9a7a79f5ea4892d3069ca6903efb5c40c47eb8a9c781eb4249281d40c3d96aae16da1bb4daaece6a26eca5f41c062b4124a64fc9d340cba5ab0d1f5affff6515a87f0933774fd4322d2fa497cd6f708a429ca56dcb1fd3db623d0" );
00681         
00682             switch( SIG_RSA_SHA384 )
00683             {
00684         #ifdef POLARSSL_MD2_C
00685             case SIG_RSA_MD2:
00686                 md2( message_str, msg_len, hash_result );
00687                 break;
00688         #endif
00689         #ifdef POLARSSL_MD4_C
00690             case SIG_RSA_MD4:
00691                 md4( message_str, msg_len, hash_result );
00692                 break;
00693         #endif
00694         #ifdef POLARSSL_MD5_C
00695             case SIG_RSA_MD5:
00696                 md5( message_str, msg_len, hash_result );
00697                 break;
00698         #endif
00699         #ifdef POLARSSL_SHA1_C
00700             case SIG_RSA_SHA1:
00701                 sha1( message_str, msg_len, hash_result );
00702                 break;
00703         #endif
00704         #ifdef POLARSSL_SHA2_C
00705             case SIG_RSA_SHA224:
00706                 sha2( message_str, msg_len, hash_result, 1 );
00707                 break;
00708             case SIG_RSA_SHA256:
00709                 sha2( message_str, msg_len, hash_result, 0 );
00710                 break;
00711         #endif
00712         #ifdef POLARSSL_SHA4_C
00713             case SIG_RSA_SHA384:
00714                 sha4( message_str, msg_len, hash_result, 1 );
00715                 break;
00716             case SIG_RSA_SHA512:
00717                 sha4( message_str, msg_len, hash_result, 0 );
00718                 break;
00719         #endif
00720             }
00721         
00722             fct_chk( rsa_pkcs1_verify( &ctx, RSA_PUBLIC, SIG_RSA_SHA384, 0, hash_result, result_str ) == POLARSSL_ERR_RSA_INVALID_PADDING );
00723         }
00724         FCT_TEST_END();
00725 #endif /* POLARSSL_SHA4_C */
00726 
00727 #ifdef POLARSSL_SHA4_C
00728 
00729         FCT_TEST_BGN(rsa_pkcs1_verify_v15_cavs_8)
00730         {
00731             unsigned char message_str[1000];
00732             unsigned char hash_result[1000];
00733             unsigned char result_str[1000];
00734             rsa_context ctx;
00735             int msg_len;
00736         
00737             rsa_init( &ctx, RSA_PKCS_V15, 0 );
00738             memset( message_str, 0x00, 1000 );
00739             memset( hash_result, 0x00, 1000 );
00740             memset( result_str, 0x00, 1000 );
00741         
00742             ctx.len = 1024 / 8;
00743             fct_chk( mpi_read_string( &ctx.N, 16, "e28a13548525e5f36dccb24ecb7cc332cc689dfd64012604c9c7816d72a16c3f5fcdc0e86e7c03280b1c69b586ce0cd8aec722cc73a5d3b730310bf7dfebdc77ce5d94bbc369dc18a2f7b07bd505ab0f82224aef09fdc1e5063234255e0b3c40a52e9e8ae60898eb88a766bdd788fe9493d8fd86bcdd2884d5c06216c65469e5" ) == 0 );
00744             fct_chk( mpi_read_string( &ctx.E, 16, "3" ) == 0 );
00745         
00746             fct_chk( rsa_check_pubkey( &ctx ) == 0 );
00747         
00748             msg_len = unhexify( message_str, "b2f2e6e09fd19b0a8c06447554d6a236c69e2b334017488881d8c02ab81d74cae0c64efd50a374998eeec162651975e637cb2ba594250c750a4943253f1db0613e4ce1d50f8e3e968a2a83bd6cb97455ab2ccc77071076b3e211ffb251bd4c1a738b88b2021c61c727c074ce933c054acbcbf4f0c362ec09af38de191686aebe" );
00749             unhexify( result_str, "a853e67f928281d11506c9d39e5ea9b2d742782c663c37d0a7c9e9fe15379cde1e75d94adbfb1ca08691f320af4ff2b0a29a4d2ea10a20cb95d85f3dabac3d56cca9039c851d0181408c00b385fc82cafa4cfa7380d0c2c024fb83fec59d5ee591d63806dcb18b21ea440c3d3f12c1e7795eb15b7ce4c4b288d646cf1d34bdf1" );
00750         
00751             switch( SIG_RSA_SHA512 )
00752             {
00753         #ifdef POLARSSL_MD2_C
00754             case SIG_RSA_MD2:
00755                 md2( message_str, msg_len, hash_result );
00756                 break;
00757         #endif
00758         #ifdef POLARSSL_MD4_C
00759             case SIG_RSA_MD4:
00760                 md4( message_str, msg_len, hash_result );
00761                 break;
00762         #endif
00763         #ifdef POLARSSL_MD5_C
00764             case SIG_RSA_MD5:
00765                 md5( message_str, msg_len, hash_result );
00766                 break;
00767         #endif
00768         #ifdef POLARSSL_SHA1_C
00769             case SIG_RSA_SHA1:
00770                 sha1( message_str, msg_len, hash_result );
00771                 break;
00772         #endif
00773         #ifdef POLARSSL_SHA2_C
00774             case SIG_RSA_SHA224:
00775                 sha2( message_str, msg_len, hash_result, 1 );
00776                 break;
00777             case SIG_RSA_SHA256:
00778                 sha2( message_str, msg_len, hash_result, 0 );
00779                 break;
00780         #endif
00781         #ifdef POLARSSL_SHA4_C
00782             case SIG_RSA_SHA384:
00783                 sha4( message_str, msg_len, hash_result, 1 );
00784                 break;
00785             case SIG_RSA_SHA512:
00786                 sha4( message_str, msg_len, hash_result, 0 );
00787                 break;
00788         #endif
00789             }
00790         
00791             fct_chk( rsa_pkcs1_verify( &ctx, RSA_PUBLIC, SIG_RSA_SHA512, 0, hash_result, result_str ) == 0 );
00792         }
00793         FCT_TEST_END();
00794 #endif /* POLARSSL_SHA4_C */
00795 
00796 #ifdef POLARSSL_SHA1_C
00797 
00798         FCT_TEST_BGN(rsa_pkcs1_verify_v15_cavs_9)
00799         {
00800             unsigned char message_str[1000];
00801             unsigned char hash_result[1000];
00802             unsigned char result_str[1000];
00803             rsa_context ctx;
00804             int msg_len;
00805         
00806             rsa_init( &ctx, RSA_PKCS_V15, 0 );
00807             memset( message_str, 0x00, 1000 );
00808             memset( hash_result, 0x00, 1000 );
00809             memset( result_str, 0x00, 1000 );
00810         
00811             ctx.len = 1024 / 8;
00812             fct_chk( mpi_read_string( &ctx.N, 16, "e28a13548525e5f36dccb24ecb7cc332cc689dfd64012604c9c7816d72a16c3f5fcdc0e86e7c03280b1c69b586ce0cd8aec722cc73a5d3b730310bf7dfebdc77ce5d94bbc369dc18a2f7b07bd505ab0f82224aef09fdc1e5063234255e0b3c40a52e9e8ae60898eb88a766bdd788fe9493d8fd86bcdd2884d5c06216c65469e5" ) == 0 );
00813             fct_chk( mpi_read_string( &ctx.E, 16, "10001" ) == 0 );
00814         
00815             fct_chk( rsa_check_pubkey( &ctx ) == 0 );
00816         
00817             msg_len = unhexify( message_str, "647586ba587b09aa555d1b8da4cdf5c6e777e08859379ca45789019f2041e708d97c4408d4d6943b11dd7ebe05c6b48a9b5f1b0079452cc484579acfa66a34c0cf3f0e7339b2dbd5f1339ef7937a8261547705a846885c43d8ef139a9c83f5604ea52b231176a821fb48c45ed45226f31ba7e8a94a69f6c65c39b7278bf3f08f" );
00818             unhexify( result_str, "e27a90b644c3a11f234132d6727ada397774cd7fdf5eb0160a665ffccedabb8ae9e357966939a71c973e75e5ff771fb01a6483fcaf82f16dee65e6826121e2ae9c69d2c92387b33a641f397676776cde501e7314a9a4e76c0f4538edeea163e8de7bd21c93c298df748c6f5c26b7d03bfa3671f2a7488fe311309e8218a71171" );
00819         
00820             switch( SIG_RSA_SHA1 )
00821             {
00822         #ifdef POLARSSL_MD2_C
00823             case SIG_RSA_MD2:
00824                 md2( message_str, msg_len, hash_result );
00825                 break;
00826         #endif
00827         #ifdef POLARSSL_MD4_C
00828             case SIG_RSA_MD4:
00829                 md4( message_str, msg_len, hash_result );
00830                 break;
00831         #endif
00832         #ifdef POLARSSL_MD5_C
00833             case SIG_RSA_MD5:
00834                 md5( message_str, msg_len, hash_result );
00835                 break;
00836         #endif
00837         #ifdef POLARSSL_SHA1_C
00838             case SIG_RSA_SHA1:
00839                 sha1( message_str, msg_len, hash_result );
00840                 break;
00841         #endif
00842         #ifdef POLARSSL_SHA2_C
00843             case SIG_RSA_SHA224:
00844                 sha2( message_str, msg_len, hash_result, 1 );
00845                 break;
00846             case SIG_RSA_SHA256:
00847                 sha2( message_str, msg_len, hash_result, 0 );
00848                 break;
00849         #endif
00850         #ifdef POLARSSL_SHA4_C
00851             case SIG_RSA_SHA384:
00852                 sha4( message_str, msg_len, hash_result, 1 );
00853                 break;
00854             case SIG_RSA_SHA512:
00855                 sha4( message_str, msg_len, hash_result, 0 );
00856                 break;
00857         #endif
00858             }
00859         
00860             fct_chk( rsa_pkcs1_verify( &ctx, RSA_PUBLIC, SIG_RSA_SHA1, 0, hash_result, result_str ) == 0 );
00861         }
00862         FCT_TEST_END();
00863 #endif /* POLARSSL_SHA1_C */
00864 
00865 #ifdef POLARSSL_SHA1_C
00866 
00867         FCT_TEST_BGN(rsa_pkcs1_verify_v15_cavs_10)
00868         {
00869             unsigned char message_str[1000];
00870             unsigned char hash_result[1000];
00871             unsigned char result_str[1000];
00872             rsa_context ctx;
00873             int msg_len;
00874         
00875             rsa_init( &ctx, RSA_PKCS_V15, 0 );
00876             memset( message_str, 0x00, 1000 );
00877             memset( hash_result, 0x00, 1000 );
00878             memset( result_str, 0x00, 1000 );
00879         
00880             ctx.len = 1024 / 8;
00881             fct_chk( mpi_read_string( &ctx.N, 16, "e28a13548525e5f36dccb24ecb7cc332cc689dfd64012604c9c7816d72a16c3f5fcdc0e86e7c03280b1c69b586ce0cd8aec722cc73a5d3b730310bf7dfebdc77ce5d94bbc369dc18a2f7b07bd505ab0f82224aef09fdc1e5063234255e0b3c40a52e9e8ae60898eb88a766bdd788fe9493d8fd86bcdd2884d5c06216c65469e5" ) == 0 );
00882             fct_chk( mpi_read_string( &ctx.E, 16, "10001" ) == 0 );
00883         
00884             fct_chk( rsa_check_pubkey( &ctx ) == 0 );
00885         
00886             msg_len = unhexify( message_str, "55013a489e09b6553262aab59fb041b49437b86d52876f8e5d5e405b77ca0ff6ce8ea2dd75c7b3b411cf4445d56233c5b0ff0e58c49128d81b4fedd295e172d225c451e13defb34b87b7aea6d6f0d20f5c55feb71d2a789fa31f3d9ff47896adc16bec5ce0c9dda3fde190e08ca2451c01ff3091449887695f96dac97ad6a30e" );
00887             unhexify( result_str, "dd82b7be791c454fbbf6f1de47cbe585a687e4e8bbae0b6e2a77f8ca4efd06d71498f9a74b931bd59c377e71daf708a624c51303f377006c676487bad57f7067b09b7bb94a6189119ab8cf7321c321b2dc7df565bfbec833a28b86625fb5fd6a035d4ed79ff0f9aee9fa78935eec65069439ee449d7f5249cdae6fdd6d8c2a63" );
00888         
00889             switch( SIG_RSA_SHA1 )
00890             {
00891         #ifdef POLARSSL_MD2_C
00892             case SIG_RSA_MD2:
00893                 md2( message_str, msg_len, hash_result );
00894                 break;
00895         #endif
00896         #ifdef POLARSSL_MD4_C
00897             case SIG_RSA_MD4:
00898                 md4( message_str, msg_len, hash_result );
00899                 break;
00900         #endif
00901         #ifdef POLARSSL_MD5_C
00902             case SIG_RSA_MD5:
00903                 md5( message_str, msg_len, hash_result );
00904                 break;
00905         #endif
00906         #ifdef POLARSSL_SHA1_C
00907             case SIG_RSA_SHA1:
00908                 sha1( message_str, msg_len, hash_result );
00909                 break;
00910         #endif
00911         #ifdef POLARSSL_SHA2_C
00912             case SIG_RSA_SHA224:
00913                 sha2( message_str, msg_len, hash_result, 1 );
00914                 break;
00915             case SIG_RSA_SHA256:
00916                 sha2( message_str, msg_len, hash_result, 0 );
00917                 break;
00918         #endif
00919         #ifdef POLARSSL_SHA4_C
00920             case SIG_RSA_SHA384:
00921                 sha4( message_str, msg_len, hash_result, 1 );
00922                 break;
00923             case SIG_RSA_SHA512:
00924                 sha4( message_str, msg_len, hash_result, 0 );
00925                 break;
00926         #endif
00927             }
00928         
00929             fct_chk( rsa_pkcs1_verify( &ctx, RSA_PUBLIC, SIG_RSA_SHA1, 0, hash_result, result_str ) == POLARSSL_ERR_RSA_INVALID_PADDING );
00930         }
00931         FCT_TEST_END();
00932 #endif /* POLARSSL_SHA1_C */
00933 
00934 #ifdef POLARSSL_SHA2_C
00935 
00936         FCT_TEST_BGN(rsa_pkcs1_verify_v15_cavs_11)
00937         {
00938             unsigned char message_str[1000];
00939             unsigned char hash_result[1000];
00940             unsigned char result_str[1000];
00941             rsa_context ctx;
00942             int msg_len;
00943         
00944             rsa_init( &ctx, RSA_PKCS_V15, 0 );
00945             memset( message_str, 0x00, 1000 );
00946             memset( hash_result, 0x00, 1000 );
00947             memset( result_str, 0x00, 1000 );
00948         
00949             ctx.len = 1024 / 8;
00950             fct_chk( mpi_read_string( &ctx.N, 16, "e28a13548525e5f36dccb24ecb7cc332cc689dfd64012604c9c7816d72a16c3f5fcdc0e86e7c03280b1c69b586ce0cd8aec722cc73a5d3b730310bf7dfebdc77ce5d94bbc369dc18a2f7b07bd505ab0f82224aef09fdc1e5063234255e0b3c40a52e9e8ae60898eb88a766bdd788fe9493d8fd86bcdd2884d5c06216c65469e5" ) == 0 );
00951             fct_chk( mpi_read_string( &ctx.E, 16, "10001" ) == 0 );
00952         
00953             fct_chk( rsa_check_pubkey( &ctx ) == 0 );
00954         
00955             msg_len = unhexify( message_str, "f4a990b8d434a5914340c0ca3ca4e4a70856c55e13e938c1f854e91cdef54c6107d6d682a62e6c1ff12b1c6178ee0b26b5d8ae5ee4043db4151465727f313e9e174d7c6961abe9cb86a21367a89e41b47267ac5ef3a6eceaaca5b19ae756b3904b97ec35aeb404dc2a2d0da373ba709a678d2728e7d72daae68d335cbf6c957d" );
00956             unhexify( result_str, "d8ef7bdc0f111b1249d5ad6515b6fe37f2ff327f493832f1385c10e975c07b0266497716fcb84f5039cd60f5a050614fde27f354a6c45e8a7d74f9821e2f301500ac1953feafeb9d98cf88d2c928413f337813135c66abfc3dc7a4d80655d925bf96f21872ca2b3a2684b976ca768fe37feae20a69eeec3cc8f1de0db34b3462" );
00957         
00958             switch( SIG_RSA_SHA224 )
00959             {
00960         #ifdef POLARSSL_MD2_C
00961             case SIG_RSA_MD2:
00962                 md2( message_str, msg_len, hash_result );
00963                 break;
00964         #endif
00965         #ifdef POLARSSL_MD4_C
00966             case SIG_RSA_MD4:
00967                 md4( message_str, msg_len, hash_result );
00968                 break;
00969         #endif
00970         #ifdef POLARSSL_MD5_C
00971             case SIG_RSA_MD5:
00972                 md5( message_str, msg_len, hash_result );
00973                 break;
00974         #endif
00975         #ifdef POLARSSL_SHA1_C
00976             case SIG_RSA_SHA1:
00977                 sha1( message_str, msg_len, hash_result );
00978                 break;
00979         #endif
00980         #ifdef POLARSSL_SHA2_C
00981             case SIG_RSA_SHA224:
00982                 sha2( message_str, msg_len, hash_result, 1 );
00983                 break;
00984             case SIG_RSA_SHA256:
00985                 sha2( message_str, msg_len, hash_result, 0 );
00986                 break;
00987         #endif
00988         #ifdef POLARSSL_SHA4_C
00989             case SIG_RSA_SHA384:
00990                 sha4( message_str, msg_len, hash_result, 1 );
00991                 break;
00992             case SIG_RSA_SHA512:
00993                 sha4( message_str, msg_len, hash_result, 0 );
00994                 break;
00995         #endif
00996             }
00997         
00998             fct_chk( rsa_pkcs1_verify( &ctx, RSA_PUBLIC, SIG_RSA_SHA224, 0, hash_result, result_str ) == 0 );
00999         }
01000         FCT_TEST_END();
01001 #endif /* POLARSSL_SHA2_C */
01002 
01003 #ifdef POLARSSL_SHA2_C
01004 
01005         FCT_TEST_BGN(rsa_pkcs1_verify_v15_cavs_12)
01006         {
01007             unsigned char message_str[1000];
01008             unsigned char hash_result[1000];
01009             unsigned char result_str[1000];
01010             rsa_context ctx;
01011             int msg_len;
01012         
01013             rsa_init( &ctx, RSA_PKCS_V15, 0 );
01014             memset( message_str, 0x00, 1000 );
01015             memset( hash_result, 0x00, 1000 );
01016             memset( result_str, 0x00, 1000 );
01017         
01018             ctx.len = 1024 / 8;
01019             fct_chk( mpi_read_string( &ctx.N, 16, "e28a13548525e5f36dccb24ecb7cc332cc689dfd64012604c9c7816d72a16c3f5fcdc0e86e7c03280b1c69b586ce0cd8aec722cc73a5d3b730310bf7dfebdc77ce5d94bbc369dc18a2f7b07bd505ab0f82224aef09fdc1e5063234255e0b3c40a52e9e8ae60898eb88a766bdd788fe9493d8fd86bcdd2884d5c06216c65469e5" ) == 0 );
01020             fct_chk( mpi_read_string( &ctx.E, 16, "10001" ) == 0 );
01021         
01022             fct_chk( rsa_check_pubkey( &ctx ) == 0 );
01023         
01024             msg_len = unhexify( message_str, "c81f04c79982971fa176d64e8f7f8812f86a94c49e84672ff10996a2d6dfc444a884c7a87c4606a1aab22558894ee59b798b457827f5ee0b0cadcd94371902cc4ddaf97acefed641997717bcb3cc74cd440f0a31e20fb95812cecb740c36d6d1bf07e3641514cfa678aff2a39562ff4d60e02b17583a92bf0c56d66bde9e09f8" );
01025             unhexify( result_str, "52111f4798da3c11b3c74394358348ab0fc797bde99080f238d33a69b04b08ac2bd767b33872473943e23af27ca32fd568a43a8c7d6cc55b4fbb380212fdfcb60487e20694d4287e233efdf7b04737c0037a592d03077801828b051998c42b9f9e2420063331d5b2349918a64d8b65b21a2011ee7318fcef48aced95b8ddf501" );
01026         
01027             switch( SIG_RSA_SHA256 )
01028             {
01029         #ifdef POLARSSL_MD2_C
01030             case SIG_RSA_MD2:
01031                 md2( message_str, msg_len, hash_result );
01032                 break;
01033         #endif
01034         #ifdef POLARSSL_MD4_C
01035             case SIG_RSA_MD4:
01036                 md4( message_str, msg_len, hash_result );
01037                 break;
01038         #endif
01039         #ifdef POLARSSL_MD5_C
01040             case SIG_RSA_MD5:
01041                 md5( message_str, msg_len, hash_result );
01042                 break;
01043         #endif
01044         #ifdef POLARSSL_SHA1_C
01045             case SIG_RSA_SHA1:
01046                 sha1( message_str, msg_len, hash_result );
01047                 break;
01048         #endif
01049         #ifdef POLARSSL_SHA2_C
01050             case SIG_RSA_SHA224:
01051                 sha2( message_str, msg_len, hash_result, 1 );
01052                 break;
01053             case SIG_RSA_SHA256:
01054                 sha2( message_str, msg_len, hash_result, 0 );
01055                 break;
01056         #endif
01057         #ifdef POLARSSL_SHA4_C
01058             case SIG_RSA_SHA384:
01059                 sha4( message_str, msg_len, hash_result, 1 );
01060                 break;
01061             case SIG_RSA_SHA512:
01062                 sha4( message_str, msg_len, hash_result, 0 );
01063                 break;
01064         #endif
01065             }
01066         
01067             fct_chk( rsa_pkcs1_verify( &ctx, RSA_PUBLIC, SIG_RSA_SHA256, 0, hash_result, result_str ) == 0 );
01068         }
01069         FCT_TEST_END();
01070 #endif /* POLARSSL_SHA2_C */
01071 
01072 #ifdef POLARSSL_SHA4_C
01073 
01074         FCT_TEST_BGN(rsa_pkcs1_verify_v15_cavs_13)
01075         {
01076             unsigned char message_str[1000];
01077             unsigned char hash_result[1000];
01078             unsigned char result_str[1000];
01079             rsa_context ctx;
01080             int msg_len;
01081         
01082             rsa_init( &ctx, RSA_PKCS_V15, 0 );
01083             memset( message_str, 0x00, 1000 );
01084             memset( hash_result, 0x00, 1000 );
01085             memset( result_str, 0x00, 1000 );
01086         
01087             ctx.len = 1024 / 8;
01088             fct_chk( mpi_read_string( &ctx.N, 16, "e28a13548525e5f36dccb24ecb7cc332cc689dfd64012604c9c7816d72a16c3f5fcdc0e86e7c03280b1c69b586ce0cd8aec722cc73a5d3b730310bf7dfebdc77ce5d94bbc369dc18a2f7b07bd505ab0f82224aef09fdc1e5063234255e0b3c40a52e9e8ae60898eb88a766bdd788fe9493d8fd86bcdd2884d5c06216c65469e5" ) == 0 );
01089             fct_chk( mpi_read_string( &ctx.E, 16, "10001" ) == 0 );
01090         
01091             fct_chk( rsa_check_pubkey( &ctx ) == 0 );
01092         
01093             msg_len = unhexify( message_str, "a97824871770b79da979a111f6decfb1dd11bd946cfa800b008f0ad5aea5aa92e205d27a46c31d4fe6cb909091bd21f082fb75074000ee46c2f3e530d77b34c7c5d6f8453025950d3e0afae1f9752655f5bbea8432e9f1014357ff11b08076179a101e4f9d3f25bffb5e656bf6afe6c97d7aa4740b5d9224cde4dede035a7768" );
01094             unhexify( result_str, "d5dcd27c74e040ea86f106b63d3275fa7b7e98d2dd701f38ec15fc7301b72df127f6d3bd5571253a0b9e0e719d7d522893896941a1aeccc697912282b5308d829b91905b5dd7b7e1b8fe27e2bd4003b09dfe7fe295f8a43c076c0cb52f2aac067e87de7ffe3a275d21a870c3dfc9b1d06d7f018667de9eb187bdf53d282e5d8b" );
01095         
01096             switch( SIG_RSA_SHA384 )
01097             {
01098         #ifdef POLARSSL_MD2_C
01099             case SIG_RSA_MD2:
01100                 md2( message_str, msg_len, hash_result );
01101                 break;
01102         #endif
01103         #ifdef POLARSSL_MD4_C
01104             case SIG_RSA_MD4:
01105                 md4( message_str, msg_len, hash_result );
01106                 break;
01107         #endif
01108         #ifdef POLARSSL_MD5_C
01109             case SIG_RSA_MD5:
01110                 md5( message_str, msg_len, hash_result );
01111                 break;
01112         #endif
01113         #ifdef POLARSSL_SHA1_C
01114             case SIG_RSA_SHA1:
01115                 sha1( message_str, msg_len, hash_result );
01116                 break;
01117         #endif
01118         #ifdef POLARSSL_SHA2_C
01119             case SIG_RSA_SHA224:
01120                 sha2( message_str, msg_len, hash_result, 1 );
01121                 break;
01122             case SIG_RSA_SHA256:
01123                 sha2( message_str, msg_len, hash_result, 0 );
01124                 break;
01125         #endif
01126         #ifdef POLARSSL_SHA4_C
01127             case SIG_RSA_SHA384:
01128                 sha4( message_str, msg_len, hash_result, 1 );
01129                 break;
01130             case SIG_RSA_SHA512:
01131                 sha4( message_str, msg_len, hash_result, 0 );
01132                 break;
01133         #endif
01134             }
01135         
01136             fct_chk( rsa_pkcs1_verify( &ctx, RSA_PUBLIC, SIG_RSA_SHA384, 0, hash_result, result_str ) == 0 );
01137         }
01138         FCT_TEST_END();
01139 #endif /* POLARSSL_SHA4_C */
01140 
01141 #ifdef POLARSSL_SHA4_C
01142 
01143         FCT_TEST_BGN(rsa_pkcs1_verify_v15_cavs_14)
01144         {
01145             unsigned char message_str[1000];
01146             unsigned char hash_result[1000];
01147             unsigned char result_str[1000];
01148             rsa_context ctx;
01149             int msg_len;
01150         
01151             rsa_init( &ctx, RSA_PKCS_V15, 0 );
01152             memset( message_str, 0x00, 1000 );
01153             memset( hash_result, 0x00, 1000 );
01154             memset( result_str, 0x00, 1000 );
01155         
01156             ctx.len = 1024 / 8;
01157             fct_chk( mpi_read_string( &ctx.N, 16, "e28a13548525e5f36dccb24ecb7cc332cc689dfd64012604c9c7816d72a16c3f5fcdc0e86e7c03280b1c69b586ce0cd8aec722cc73a5d3b730310bf7dfebdc77ce5d94bbc369dc18a2f7b07bd505ab0f82224aef09fdc1e5063234255e0b3c40a52e9e8ae60898eb88a766bdd788fe9493d8fd86bcdd2884d5c06216c65469e5" ) == 0 );
01158             fct_chk( mpi_read_string( &ctx.E, 16, "10001" ) == 0 );
01159         
01160             fct_chk( rsa_check_pubkey( &ctx ) == 0 );
01161         
01162             msg_len = unhexify( message_str, "4ce61930c79dc017c2dea0c5085d73a3b0e4a6f341e9a5061a6658af11e5edf95bdad915ac3619969e39bee15788a8de667f92f4efc84f35082d52d562aa74e12cc7f22d3425b58f5056d74afcf162cd44e65b9ee510ff91af094c3d2d42c3b088536d62a98f1c689edcf3ea3fc228d711c109d76ae83d82d6a34dcfbad563cf" );
01163             unhexify( result_str, "27280b92eab5cbf0d787ff6fa6b0151d6610adfd25116113f2f186f3f8d39736d91ae510ec2bd96f2de135aefda79178138696dcc6d302e4a79ddabbe16e39ab96075776afce863e84a2e6013cb457e4047e22d43f67bf64ae5e1d844a7c12ac696efbb3cda7c0e0aca71f8a7ada9a0547bfaefe1ba2e04058c672c803720dd9" );
01164         
01165             switch( SIG_RSA_SHA512 )
01166             {
01167         #ifdef POLARSSL_MD2_C
01168             case SIG_RSA_MD2:
01169                 md2( message_str, msg_len, hash_result );
01170                 break;
01171         #endif
01172         #ifdef POLARSSL_MD4_C
01173             case SIG_RSA_MD4:
01174                 md4( message_str, msg_len, hash_result );
01175                 break;
01176         #endif
01177         #ifdef POLARSSL_MD5_C
01178             case SIG_RSA_MD5:
01179                 md5( message_str, msg_len, hash_result );
01180                 break;
01181         #endif
01182         #ifdef POLARSSL_SHA1_C
01183             case SIG_RSA_SHA1:
01184                 sha1( message_str, msg_len, hash_result );
01185                 break;
01186         #endif
01187         #ifdef POLARSSL_SHA2_C
01188             case SIG_RSA_SHA224:
01189                 sha2( message_str, msg_len, hash_result, 1 );
01190                 break;
01191             case SIG_RSA_SHA256:
01192                 sha2( message_str, msg_len, hash_result, 0 );
01193                 break;
01194         #endif
01195         #ifdef POLARSSL_SHA4_C
01196             case SIG_RSA_SHA384:
01197                 sha4( message_str, msg_len, hash_result, 1 );
01198                 break;
01199             case SIG_RSA_SHA512:
01200                 sha4( message_str, msg_len, hash_result, 0 );
01201                 break;
01202         #endif
01203             }
01204         
01205             fct_chk( rsa_pkcs1_verify( &ctx, RSA_PUBLIC, SIG_RSA_SHA512, 0, hash_result, result_str ) == 0 );
01206         }
01207         FCT_TEST_END();
01208 #endif /* POLARSSL_SHA4_C */
01209 
01210 #ifdef POLARSSL_SHA1_C
01211 
01212         FCT_TEST_BGN(rsa_pkcs1_verify_v15_cavs_15)
01213         {
01214             unsigned char message_str[1000];
01215             unsigned char hash_result[1000];
01216             unsigned char result_str[1000];
01217             rsa_context ctx;
01218             int msg_len;
01219         
01220             rsa_init( &ctx, RSA_PKCS_V15, 0 );
01221             memset( message_str, 0x00, 1000 );
01222             memset( hash_result, 0x00, 1000 );
01223             memset( result_str, 0x00, 1000 );
01224         
01225             ctx.len = 1536 / 8;
01226             fct_chk( mpi_read_string( &ctx.N, 16, "a59d9b7269b102b7be684ec5e28db79992e6d3231e77c90b78960c2638b35ef6dbdac1ac59e7249d96d426e7f99397eabc6b8903fe1942da580322b98bafacd81bb911c29666f83886a2a2864f3552044300e60cedd5a8c321c43e280413dc41673c39a11b98a885486f8187a70f270185c4c12bc48a1968305269776c070ef69d4913589a887c4d0f5e7dd58bd806d0d49a14a1762c38665cef4646ff13a0cd29c3a60460703c3d051d5b28c660bffb5f8bd43d495ffa64175f72b8abe5fddd" ) == 0 );
01227             fct_chk( mpi_read_string( &ctx.E, 16, "3" ) == 0 );
01228         
01229             fct_chk( rsa_check_pubkey( &ctx ) == 0 );
01230         
01231             msg_len = unhexify( message_str, "224ecd3b630581da948216366c741015a9723c5ea43de67e28454d0a846f54a6df167a25cc500cf21f729aaefed6a71a3bdba438e12e20ad0c48396afe38568b70a3187f26098d6ac649a7c7ea68ed52748e7125225102216236a28f67753b077cfd8d9198b86b0b331027cb59b24b85fd92896e8f2ff5a1d11872c2e6af6ae2" );
01232             unhexify( result_str, "1f7938b20a9cd8bb8ca26bad9e79ea92373174203f3ab212a06de34a9a3e14e102d19a8878c28a2fc8083a97c06b19c1ae62678289d5d071a904aed1d364655d9e2d16480a6fd18f4c8edf204844a34d573b1b988b82d495caefd9298c1635083e196a11f4a7df6a7e3cc4db7b9642e7682d22ec7038c3bad791e1365fe8836976092460e6df749dc032baf1e026684f55936beb9369845c53c3d217941c1f8d8f54a32333a4c049c3f2d527125778032f5d390040d1d4cce83dc353ce250152" );
01233         
01234             switch( SIG_RSA_SHA1 )
01235             {
01236         #ifdef POLARSSL_MD2_C
01237             case SIG_RSA_MD2:
01238                 md2( message_str, msg_len, hash_result );
01239                 break;
01240         #endif
01241         #ifdef POLARSSL_MD4_C
01242             case SIG_RSA_MD4:
01243                 md4( message_str, msg_len, hash_result );
01244                 break;
01245         #endif
01246         #ifdef POLARSSL_MD5_C
01247             case SIG_RSA_MD5:
01248                 md5( message_str, msg_len, hash_result );
01249                 break;
01250         #endif
01251         #ifdef POLARSSL_SHA1_C
01252             case SIG_RSA_SHA1:
01253                 sha1( message_str, msg_len, hash_result );
01254                 break;
01255         #endif
01256         #ifdef POLARSSL_SHA2_C
01257             case SIG_RSA_SHA224:
01258                 sha2( message_str, msg_len, hash_result, 1 );
01259                 break;
01260             case SIG_RSA_SHA256:
01261                 sha2( message_str, msg_len, hash_result, 0 );
01262                 break;
01263         #endif
01264         #ifdef POLARSSL_SHA4_C
01265             case SIG_RSA_SHA384:
01266                 sha4( message_str, msg_len, hash_result, 1 );
01267                 break;
01268             case SIG_RSA_SHA512:
01269                 sha4( message_str, msg_len, hash_result, 0 );
01270                 break;
01271         #endif
01272             }
01273         
01274             fct_chk( rsa_pkcs1_verify( &ctx, RSA_PUBLIC, SIG_RSA_SHA1, 0, hash_result, result_str ) == 0 );
01275         }
01276         FCT_TEST_END();
01277 #endif /* POLARSSL_SHA1_C */
01278 
01279 #ifdef POLARSSL_SHA2_C
01280 
01281         FCT_TEST_BGN(rsa_pkcs1_verify_v15_cavs_16)
01282         {
01283             unsigned char message_str[1000];
01284             unsigned char hash_result[1000];
01285             unsigned char result_str[1000];
01286             rsa_context ctx;
01287             int msg_len;
01288         
01289             rsa_init( &ctx, RSA_PKCS_V15, 0 );
01290             memset( message_str, 0x00, 1000 );
01291             memset( hash_result, 0x00, 1000 );
01292             memset( result_str, 0x00, 1000 );
01293         
01294             ctx.len = 1536 / 8;
01295             fct_chk( mpi_read_string( &ctx.N, 16, "a59d9b7269b102b7be684ec5e28db79992e6d3231e77c90b78960c2638b35ef6dbdac1ac59e7249d96d426e7f99397eabc6b8903fe1942da580322b98bafacd81bb911c29666f83886a2a2864f3552044300e60cedd5a8c321c43e280413dc41673c39a11b98a885486f8187a70f270185c4c12bc48a1968305269776c070ef69d4913589a887c4d0f5e7dd58bd806d0d49a14a1762c38665cef4646ff13a0cd29c3a60460703c3d051d5b28c660bffb5f8bd43d495ffa64175f72b8abe5fddd" ) == 0 );
01296             fct_chk( mpi_read_string( &ctx.E, 16, "3" ) == 0 );
01297         
01298             fct_chk( rsa_check_pubkey( &ctx ) == 0 );
01299         
01300             msg_len = unhexify( message_str, "6ecc722d233dad1aca45e6bc3e1a0b99fb1f89c0ec63bc657e6aaacbf931f267106cff42b712819f341b1ede798964a0b1a5032c198b391111e88d0d7303c02e23fa0137e74e604579a285b2dbc0a23aebdda65c371eb403125bd366e822e72dceffe0d55dfa3155c16283020dc9abb0d150da1aef251484aa49e49e00974dac" );
01301             unhexify( result_str, "339dce3a1937669d9fb14c4f652378861fd5adc4da88eaf833b16020b55a24ddc83b7ae3395a9a49b426bb9a4170cb765b02652faa9594b457aeefdae4f802e93d8e65c687ddc723701465a5ef19249ed5d2617b5121c58557b34eb99a663bbcf4453a6e1db5d88723de449fcf58ca8ef514daf08cfdc71be155bb3d0724df0c0a6fd5aa7737433cc376640b9b8b4c7ddd09776bae0245729cddb56e36f28edad6aecaed0821ec8d843a96348e722bf0a84cf060a793a2179f054138f907d0c3" );
01302         
01303             switch( SIG_RSA_SHA224 )
01304             {
01305         #ifdef POLARSSL_MD2_C
01306             case SIG_RSA_MD2:
01307                 md2( message_str, msg_len, hash_result );
01308                 break;
01309         #endif
01310         #ifdef POLARSSL_MD4_C
01311             case SIG_RSA_MD4:
01312                 md4( message_str, msg_len, hash_result );
01313                 break;
01314         #endif
01315         #ifdef POLARSSL_MD5_C
01316             case SIG_RSA_MD5:
01317                 md5( message_str, msg_len, hash_result );
01318                 break;
01319         #endif
01320         #ifdef POLARSSL_SHA1_C
01321             case SIG_RSA_SHA1:
01322                 sha1( message_str, msg_len, hash_result );
01323                 break;
01324         #endif
01325         #ifdef POLARSSL_SHA2_C
01326             case SIG_RSA_SHA224:
01327                 sha2( message_str, msg_len, hash_result, 1 );
01328                 break;
01329             case SIG_RSA_SHA256:
01330                 sha2( message_str, msg_len, hash_result, 0 );
01331                 break;
01332         #endif
01333         #ifdef POLARSSL_SHA4_C
01334             case SIG_RSA_SHA384:
01335                 sha4( message_str, msg_len, hash_result, 1 );
01336                 break;
01337             case SIG_RSA_SHA512:
01338                 sha4( message_str, msg_len, hash_result, 0 );
01339                 break;
01340         #endif
01341             }
01342         
01343             fct_chk( rsa_pkcs1_verify( &ctx, RSA_PUBLIC, SIG_RSA_SHA224, 0, hash_result, result_str ) == 0 );
01344         }
01345         FCT_TEST_END();
01346 #endif /* POLARSSL_SHA2_C */
01347 
01348 #ifdef POLARSSL_SHA2_C
01349 
01350         FCT_TEST_BGN(rsa_pkcs1_verify_v15_cavs_17)
01351         {
01352             unsigned char message_str[1000];
01353             unsigned char hash_result[1000];
01354             unsigned char result_str[1000];
01355             rsa_context ctx;
01356             int msg_len;
01357         
01358             rsa_init( &ctx, RSA_PKCS_V15, 0 );
01359             memset( message_str, 0x00, 1000 );
01360             memset( hash_result, 0x00, 1000 );
01361             memset( result_str, 0x00, 1000 );
01362         
01363             ctx.len = 1536 / 8;
01364             fct_chk( mpi_read_string( &ctx.N, 16, "a59d9b7269b102b7be684ec5e28db79992e6d3231e77c90b78960c2638b35ef6dbdac1ac59e7249d96d426e7f99397eabc6b8903fe1942da580322b98bafacd81bb911c29666f83886a2a2864f3552044300e60cedd5a8c321c43e280413dc41673c39a11b98a885486f8187a70f270185c4c12bc48a1968305269776c070ef69d4913589a887c4d0f5e7dd58bd806d0d49a14a1762c38665cef4646ff13a0cd29c3a60460703c3d051d5b28c660bffb5f8bd43d495ffa64175f72b8abe5fddd" ) == 0 );
01365             fct_chk( mpi_read_string( &ctx.E, 16, "3" ) == 0 );
01366         
01367             fct_chk( rsa_check_pubkey( &ctx ) == 0 );
01368         
01369             msg_len = unhexify( message_str, "72f0b1ae27e1f5e5bfa15ded204c2c54b47b2420750a3eb5471f9ff98b67c8b5f1a30d3f8d6448562e12ce4deb33a26cfeeae993d6be9e20679d8713c5216870f11276e5f22b0ead2821a7b4dee106fc1e19b13fc9fba5d6e73e4bd93b65a9881a43d5e97ebfb0b357d5d06b21ddbecdbb10626d7748bb9e6e07d49316bbf3c4" );
01370             unhexify( result_str, "8117a6897e14c183737661cf5741350a84ae00495cd9ee8fb033582e559f79701ab424706660515ee5821a69a6850647ec641676a625d1a3899932aaa52161fbc0c0a825db82fde0585b3c9b9c16de43e26da6a30fe5a601dae68bded1e29ec34557b5f6962efb10b9450d6f096655f68e8499cfa16a0adeb9075e7b91851fef84243132d08273d35d01ad89c17e1e6e4deaf1cb233050b275fa9d2cae57e9e1a0e23139267040aa39b6abd8f10fa1cec38ce2183573ddc11626fc262e1a0ced" );
01371         
01372             switch( SIG_RSA_SHA256 )
01373             {
01374         #ifdef POLARSSL_MD2_C
01375             case SIG_RSA_MD2:
01376                 md2( message_str, msg_len, hash_result );
01377                 break;
01378         #endif
01379         #ifdef POLARSSL_MD4_C
01380             case SIG_RSA_MD4:
01381                 md4( message_str, msg_len, hash_result );
01382                 break;
01383         #endif
01384         #ifdef POLARSSL_MD5_C
01385             case SIG_RSA_MD5:
01386                 md5( message_str, msg_len, hash_result );
01387                 break;
01388         #endif
01389         #ifdef POLARSSL_SHA1_C
01390             case SIG_RSA_SHA1:
01391                 sha1( message_str, msg_len, hash_result );
01392                 break;
01393         #endif
01394         #ifdef POLARSSL_SHA2_C
01395             case SIG_RSA_SHA224:
01396                 sha2( message_str, msg_len, hash_result, 1 );
01397                 break;
01398             case SIG_RSA_SHA256:
01399                 sha2( message_str, msg_len, hash_result, 0 );
01400                 break;
01401         #endif
01402         #ifdef POLARSSL_SHA4_C
01403             case SIG_RSA_SHA384:
01404                 sha4( message_str, msg_len, hash_result, 1 );
01405                 break;
01406             case SIG_RSA_SHA512:
01407                 sha4( message_str, msg_len, hash_result, 0 );
01408                 break;
01409         #endif
01410             }
01411         
01412             fct_chk( rsa_pkcs1_verify( &ctx, RSA_PUBLIC, SIG_RSA_SHA256, 0, hash_result, result_str ) == 0 );
01413         }
01414         FCT_TEST_END();
01415 #endif /* POLARSSL_SHA2_C */
01416 
01417 #ifdef POLARSSL_SHA4_C
01418 
01419         FCT_TEST_BGN(rsa_pkcs1_verify_v15_cavs_18)
01420         {
01421             unsigned char message_str[1000];
01422             unsigned char hash_result[1000];
01423             unsigned char result_str[1000];
01424             rsa_context ctx;
01425             int msg_len;
01426         
01427             rsa_init( &ctx, RSA_PKCS_V15, 0 );
01428             memset( message_str, 0x00, 1000 );
01429             memset( hash_result, 0x00, 1000 );
01430             memset( result_str, 0x00, 1000 );
01431         
01432             ctx.len = 1536 / 8;
01433             fct_chk( mpi_read_string( &ctx.N, 16, "a59d9b7269b102b7be684ec5e28db79992e6d3231e77c90b78960c2638b35ef6dbdac1ac59e7249d96d426e7f99397eabc6b8903fe1942da580322b98bafacd81bb911c29666f83886a2a2864f3552044300e60cedd5a8c321c43e280413dc41673c39a11b98a885486f8187a70f270185c4c12bc48a1968305269776c070ef69d4913589a887c4d0f5e7dd58bd806d0d49a14a1762c38665cef4646ff13a0cd29c3a60460703c3d051d5b28c660bffb5f8bd43d495ffa64175f72b8abe5fddd" ) == 0 );
01434             fct_chk( mpi_read_string( &ctx.E, 16, "3" ) == 0 );
01435         
01436             fct_chk( rsa_check_pubkey( &ctx ) == 0 );
01437         
01438             msg_len = unhexify( message_str, "f80c94a2b53736978adf041886ad97ab2aeb9e91c08bd4eeef6b2f2b8dd75a99b4506657188bbd7597bd5759121630627c8bf9cc30d90dd488c7a81cabab5350a62fa30abf5523f305b98f2c2c1743ec980cf26ab8219bfd9505b981ab1abbfef733b384519d5259fc5c14577cb6b88fa7f6f332ff6a65b23faecc24342c78e9" );
01439             unhexify( result_str, "6b49553ed964ae196a41ea281f4d2a250ce7d1e7434e45cf6a82f7bed17554f39c3f0241e0364702fcb87475eb0c0839ffd2180890fa05b4bbf31bbfa4bf5119dea0c9f88e1e9617fcdadabc6fa1945136cc66e039b905d78ed365c5806d38aec88b3edfb86c05ff446dbfd51d7cd75cbf8d3b85154c783765386f51637532221f52429db5612dcc034968bb8feab7dc6f5ed1f2feb557f6dd49c980296117be2c4195ec7b6101ea767df9d16a56fc9709b49308a54dab63dbc4d609f959ce17" );
01440         
01441             switch( SIG_RSA_SHA384 )
01442             {
01443         #ifdef POLARSSL_MD2_C
01444             case SIG_RSA_MD2:
01445                 md2( message_str, msg_len, hash_result );
01446                 break;
01447         #endif
01448         #ifdef POLARSSL_MD4_C
01449             case SIG_RSA_MD4:
01450                 md4( message_str, msg_len, hash_result );
01451                 break;
01452         #endif
01453         #ifdef POLARSSL_MD5_C
01454             case SIG_RSA_MD5:
01455                 md5( message_str, msg_len, hash_result );
01456                 break;
01457         #endif
01458         #ifdef POLARSSL_SHA1_C
01459             case SIG_RSA_SHA1:
01460                 sha1( message_str, msg_len, hash_result );
01461                 break;
01462         #endif
01463         #ifdef POLARSSL_SHA2_C
01464             case SIG_RSA_SHA224:
01465                 sha2( message_str, msg_len, hash_result, 1 );
01466                 break;
01467             case SIG_RSA_SHA256:
01468                 sha2( message_str, msg_len, hash_result, 0 );
01469                 break;
01470         #endif
01471         #ifdef POLARSSL_SHA4_C
01472             case SIG_RSA_SHA384:
01473                 sha4( message_str, msg_len, hash_result, 1 );
01474                 break;
01475             case SIG_RSA_SHA512:
01476                 sha4( message_str, msg_len, hash_result, 0 );
01477                 break;
01478         #endif
01479             }
01480         
01481             fct_chk( rsa_pkcs1_verify( &ctx, RSA_PUBLIC, SIG_RSA_SHA384, 0, hash_result, result_str ) == 0 );
01482         }
01483         FCT_TEST_END();
01484 #endif /* POLARSSL_SHA4_C */
01485 
01486 #ifdef POLARSSL_SHA4_C
01487 
01488         FCT_TEST_BGN(rsa_pkcs1_verify_v15_cavs_19)
01489         {
01490             unsigned char message_str[1000];
01491             unsigned char hash_result[1000];
01492             unsigned char result_str[1000];
01493             rsa_context ctx;
01494             int msg_len;
01495         
01496             rsa_init( &ctx, RSA_PKCS_V15, 0 );
01497             memset( message_str, 0x00, 1000 );
01498             memset( hash_result, 0x00, 1000 );
01499             memset( result_str, 0x00, 1000 );
01500         
01501             ctx.len = 1536 / 8;
01502             fct_chk( mpi_read_string( &ctx.N, 16, "a59d9b7269b102b7be684ec5e28db79992e6d3231e77c90b78960c2638b35ef6dbdac1ac59e7249d96d426e7f99397eabc6b8903fe1942da580322b98bafacd81bb911c29666f83886a2a2864f3552044300e60cedd5a8c321c43e280413dc41673c39a11b98a885486f8187a70f270185c4c12bc48a1968305269776c070ef69d4913589a887c4d0f5e7dd58bd806d0d49a14a1762c38665cef4646ff13a0cd29c3a60460703c3d051d5b28c660bffb5f8bd43d495ffa64175f72b8abe5fddd" ) == 0 );
01503             fct_chk( mpi_read_string( &ctx.E, 16, "3" ) == 0 );
01504         
01505             fct_chk( rsa_check_pubkey( &ctx ) == 0 );
01506         
01507             msg_len = unhexify( message_str, "4eb97094bb42aaa58b040bd06a8f324396b9eca9e39359b7039c4a010434ee131a53aebd9f7a55ae58ea7444fa1505a3ec524e054fd408513cddc1ee4c2f7fd95ec4a6f594be1ba39fa1aa933dc0a5dafff5ce44509577ebb3a3e8084c44010aa27321e5a3f646ade99175633b795c0f570b360eeebeefaef15788f80b5cbecd" );
01508             unhexify( result_str, "2b8b794a8621d492eec18a4efd239e0e077c89340a34b0fdbf467f2bf3112c7f33d00ee736f2988af8569c1a74891efbefa839e295fffdf4d908c1ede61a861a4d24b154a09d1b3f923fd2bb7906994cf82a97da285bf48e61f90cc3596f9350ab9b66a216ffca323195bb213f5a77fe8c697475595a1857dbee58128cbf1be7cb220229ce52766fefd88cc129ad5cbbdcd31fb4eede6c4fdd3193a9aaaa54362bcea4082981d9b7c40483814828f3297d95ad933c76f31c47e37a93ffaf0d4a" );
01509         
01510             switch( SIG_RSA_SHA512 )
01511             {
01512         #ifdef POLARSSL_MD2_C
01513             case SIG_RSA_MD2:
01514                 md2( message_str, msg_len, hash_result );
01515                 break;
01516         #endif
01517         #ifdef POLARSSL_MD4_C
01518             case SIG_RSA_MD4:
01519                 md4( message_str, msg_len, hash_result );
01520                 break;
01521         #endif
01522         #ifdef POLARSSL_MD5_C
01523             case SIG_RSA_MD5:
01524                 md5( message_str, msg_len, hash_result );
01525                 break;
01526         #endif
01527         #ifdef POLARSSL_SHA1_C
01528             case SIG_RSA_SHA1:
01529                 sha1( message_str, msg_len, hash_result );
01530                 break;
01531         #endif
01532         #ifdef POLARSSL_SHA2_C
01533             case SIG_RSA_SHA224:
01534                 sha2( message_str, msg_len, hash_result, 1 );
01535                 break;
01536             case SIG_RSA_SHA256:
01537                 sha2( message_str, msg_len, hash_result, 0 );
01538                 break;
01539         #endif
01540         #ifdef POLARSSL_SHA4_C
01541             case SIG_RSA_SHA384:
01542                 sha4( message_str, msg_len, hash_result, 1 );
01543                 break;
01544             case SIG_RSA_SHA512:
01545                 sha4( message_str, msg_len, hash_result, 0 );
01546                 break;
01547         #endif
01548             }
01549         
01550             fct_chk( rsa_pkcs1_verify( &ctx, RSA_PUBLIC, SIG_RSA_SHA512, 0, hash_result, result_str ) == 0 );
01551         }
01552         FCT_TEST_END();
01553 #endif /* POLARSSL_SHA4_C */
01554 
01555 #ifdef POLARSSL_SHA1_C
01556 
01557         FCT_TEST_BGN(rsa_pkcs1_verify_v15_cavs_20)
01558         {
01559             unsigned char message_str[1000];
01560             unsigned char hash_result[1000];
01561             unsigned char result_str[1000];
01562             rsa_context ctx;
01563             int msg_len;
01564         
01565             rsa_init( &ctx, RSA_PKCS_V15, 0 );
01566             memset( message_str, 0x00, 1000 );
01567             memset( hash_result, 0x00, 1000 );
01568             memset( result_str, 0x00, 1000 );
01569         
01570             ctx.len = 1536 / 8;
01571             fct_chk( mpi_read_string( &ctx.N, 16, "a59d9b7269b102b7be684ec5e28db79992e6d3231e77c90b78960c2638b35ef6dbdac1ac59e7249d96d426e7f99397eabc6b8903fe1942da580322b98bafacd81bb911c29666f83886a2a2864f3552044300e60cedd5a8c321c43e280413dc41673c39a11b98a885486f8187a70f270185c4c12bc48a1968305269776c070ef69d4913589a887c4d0f5e7dd58bd806d0d49a14a1762c38665cef4646ff13a0cd29c3a60460703c3d051d5b28c660bffb5f8bd43d495ffa64175f72b8abe5fddd" ) == 0 );
01572             fct_chk( mpi_read_string( &ctx.E, 16, "10001" ) == 0 );
01573         
01574             fct_chk( rsa_check_pubkey( &ctx ) == 0 );
01575         
01576             msg_len = unhexify( message_str, "a3edb0f52c6166d7b76e71634761f402337c3e9667549d00cd7877e6055396b35c54c4dffc4c987060178fc10b7e5e827a5c870057002ba6efd31fc4e63a429029be0d6b256b6b653775cb026322743f48e319d053c4aeac34077acb8e0c6c2ef375b2210f8788bd23d24eb0b614de41875b1c8ec56acf18825eaf826691be96" );
01577             unhexify( result_str, "180630d2f4dc91ddb1159978e278cda7ac4b178e82477f9770c4d2e1c5017d2f222348658044c1be4cda24ce3c9ba3d423536a39bf60324c1b30eabdad700b0982e58072f7e18216e7e4c07e17674ec3eabcfbafce317d2f539f129902d80031ca201a8b325629a96ca4a70b51294c2fddd1d0aca1537d7d8b780e1e62d34be2f98104d876a4990396c8628e6498d9651f468bdf1139664eabe9166efbe909bf87d7305d5f60f1acc3599ed339fcf4e009fbad4059af1a50264cb0a4ec1d23f3" );
01578         
01579             switch( SIG_RSA_SHA1 )
01580             {
01581         #ifdef POLARSSL_MD2_C
01582             case SIG_RSA_MD2:
01583                 md2( message_str, msg_len, hash_result );
01584                 break;
01585         #endif
01586         #ifdef POLARSSL_MD4_C
01587             case SIG_RSA_MD4:
01588                 md4( message_str, msg_len, hash_result );
01589                 break;
01590         #endif
01591         #ifdef POLARSSL_MD5_C
01592             case SIG_RSA_MD5:
01593                 md5( message_str, msg_len, hash_result );
01594                 break;
01595         #endif
01596         #ifdef POLARSSL_SHA1_C
01597             case SIG_RSA_SHA1:
01598                 sha1( message_str, msg_len, hash_result );
01599                 break;
01600         #endif
01601         #ifdef POLARSSL_SHA2_C
01602             case SIG_RSA_SHA224:
01603                 sha2( message_str, msg_len, hash_result, 1 );
01604                 break;
01605             case SIG_RSA_SHA256:
01606                 sha2( message_str, msg_len, hash_result, 0 );
01607                 break;
01608         #endif
01609         #ifdef POLARSSL_SHA4_C
01610             case SIG_RSA_SHA384:
01611                 sha4( message_str, msg_len, hash_result, 1 );
01612                 break;
01613             case SIG_RSA_SHA512:
01614                 sha4( message_str, msg_len, hash_result, 0 );
01615                 break;
01616         #endif
01617             }
01618         
01619             fct_chk( rsa_pkcs1_verify( &ctx, RSA_PUBLIC, SIG_RSA_SHA1, 0, hash_result, result_str ) == 0 );
01620         }
01621         FCT_TEST_END();
01622 #endif /* POLARSSL_SHA1_C */
01623 
01624 #ifdef POLARSSL_SHA1_C
01625 
01626         FCT_TEST_BGN(rsa_pkcs1_verify_v15_cavs_21)
01627         {
01628             unsigned char message_str[1000];
01629             unsigned char hash_result[1000];
01630             unsigned char result_str[1000];
01631             rsa_context ctx;
01632             int msg_len;
01633         
01634             rsa_init( &ctx, RSA_PKCS_V15, 0 );
01635             memset( message_str, 0x00, 1000 );
01636             memset( hash_result, 0x00, 1000 );
01637             memset( result_str, 0x00, 1000 );
01638         
01639             ctx.len = 1536 / 8;
01640             fct_chk( mpi_read_string( &ctx.N, 16, "a59d9b7269b102b7be684ec5e28db79992e6d3231e77c90b78960c2638b35ef6dbdac1ac59e7249d96d426e7f99397eabc6b8903fe1942da580322b98bafacd81bb911c29666f83886a2a2864f3552044300e60cedd5a8c321c43e280413dc41673c39a11b98a885486f8187a70f270185c4c12bc48a1968305269776c070ef69d4913589a887c4d0f5e7dd58bd806d0d49a14a1762c38665cef4646ff13a0cd29c3a60460703c3d051d5b28c660bffb5f8bd43d495ffa64175f72b8abe5fddd" ) == 0 );
01641             fct_chk( mpi_read_string( &ctx.E, 16, "10001" ) == 0 );
01642         
01643             fct_chk( rsa_check_pubkey( &ctx ) == 0 );
01644         
01645             msg_len = unhexify( message_str, "ac58fd024208d7f045d81a56cd55aad40ab86b0d216ab55136c7027aca23ea13480a52c0dacce0d98139b25965aa4ff76a41dd92037195d24bc0750d52cb3467b48b7b3e71d852c5f82bd9ee85a8388ead5cd8bc38c3d4792e8daa9734a137d31963e245ad3217fad235f7dfd5584de0fe91c4526568588e08b60bdf1badd99f" );
01646             unhexify( result_str, "a142b0d9456f8f4772675265a08613a66c416bd1ae712975c69d9ca5fb8c1be9c24359a04fd15460bf6136a8a11f13e3ce2de2171524f10cb715f0d71e3db15281ab99eadbe86cf8c5c518162c638ef27a4f7bfb4a1a3873f3c384a5b1c3b4966c837b9d8d192ac34e03943b7ae191355aa1ff3b9cd041bb2668f1f81cf0d015b3d3608cd9ac79398212c0f132f1bd45d47768b999fcf3c05fe2069593ceecedc851a7fc465abcfef0fabba9b9460153f6ba8723a5c6e766c83a446aef3ee327" );
01647         
01648             switch( SIG_RSA_SHA1 )
01649             {
01650         #ifdef POLARSSL_MD2_C
01651             case SIG_RSA_MD2:
01652                 md2( message_str, msg_len, hash_result );
01653                 break;
01654         #endif
01655         #ifdef POLARSSL_MD4_C
01656             case SIG_RSA_MD4:
01657                 md4( message_str, msg_len, hash_result );
01658                 break;
01659         #endif
01660         #ifdef POLARSSL_MD5_C
01661             case SIG_RSA_MD5:
01662                 md5( message_str, msg_len, hash_result );
01663                 break;
01664         #endif
01665         #ifdef POLARSSL_SHA1_C
01666             case SIG_RSA_SHA1:
01667                 sha1( message_str, msg_len, hash_result );
01668                 break;
01669         #endif
01670         #ifdef POLARSSL_SHA2_C
01671             case SIG_RSA_SHA224:
01672                 sha2( message_str, msg_len, hash_result, 1 );
01673                 break;
01674             case SIG_RSA_SHA256:
01675                 sha2( message_str, msg_len, hash_result, 0 );
01676                 break;
01677         #endif
01678         #ifdef POLARSSL_SHA4_C
01679             case SIG_RSA_SHA384:
01680                 sha4( message_str, msg_len, hash_result, 1 );
01681                 break;
01682             case SIG_RSA_SHA512:
01683                 sha4( message_str, msg_len, hash_result, 0 );
01684                 break;
01685         #endif
01686             }
01687         
01688             fct_chk( rsa_pkcs1_verify( &ctx, RSA_PUBLIC, SIG_RSA_SHA1, 0, hash_result, result_str ) == POLARSSL_ERR_RSA_INVALID_PADDING );
01689         }
01690         FCT_TEST_END();
01691 #endif /* POLARSSL_SHA1_C */
01692 
01693 #ifdef POLARSSL_SHA2_C
01694 
01695         FCT_TEST_BGN(rsa_pkcs1_verify_v15_cavs_22)
01696         {
01697             unsigned char message_str[1000];
01698             unsigned char hash_result[1000];
01699             unsigned char result_str[1000];
01700             rsa_context ctx;
01701             int msg_len;
01702         
01703             rsa_init( &ctx, RSA_PKCS_V15, 0 );
01704             memset( message_str, 0x00, 1000 );
01705             memset( hash_result, 0x00, 1000 );
01706             memset( result_str, 0x00, 1000 );
01707         
01708             ctx.len = 1536 / 8;
01709             fct_chk( mpi_read_string( &ctx.N, 16, "a59d9b7269b102b7be684ec5e28db79992e6d3231e77c90b78960c2638b35ef6dbdac1ac59e7249d96d426e7f99397eabc6b8903fe1942da580322b98bafacd81bb911c29666f83886a2a2864f3552044300e60cedd5a8c321c43e280413dc41673c39a11b98a885486f8187a70f270185c4c12bc48a1968305269776c070ef69d4913589a887c4d0f5e7dd58bd806d0d49a14a1762c38665cef4646ff13a0cd29c3a60460703c3d051d5b28c660bffb5f8bd43d495ffa64175f72b8abe5fddd" ) == 0 );
01710             fct_chk( mpi_read_string( &ctx.E, 16, "10001" ) == 0 );
01711         
01712             fct_chk( rsa_check_pubkey( &ctx ) == 0 );
01713         
01714             msg_len = unhexify( message_str, "027f767928a5821e2723d6f36c43e6b498b6f0b381852571794a096bd49f1c36a4d7bacec7ec402c24b970163169173bb930ec7fdc39bc9457dfc4ca051f5f28a64de1bbe007c22e8368ff9b117dbda17efd2fb73434bbbf5a4158df56813b8c904bb2e779de504dcd974a291568210d6f85810291606a1c0cd88d51ceadf98a" );
01715             unhexify( result_str, "0676e64daaa18f4af46e9dfbe234db389b8a527b0fe1db97eb7f404e3155226cba70d318800f83160fa1aa19916e5c09f079331079f18cb8ab1a4b884cb28501824974f683ed2b9babae9f8c15bea30802805c6b2152119764811bbf5f3994d2e97fa2fe8c5ab15a23c14d7ae56be00eaa8bc26678481ff5ba59b0acfb0e43341bff9fc638e5625480a73dbc5d8d13bd2b9e64037c6b79df0c60869980c6a22ec46f80fb859cb4ee5d2032ac1fe538cfd85c70a7f33b4af50a93395917c2cfb6" );
01716         
01717             switch( SIG_RSA_SHA224 )
01718             {
01719         #ifdef POLARSSL_MD2_C
01720             case SIG_RSA_MD2:
01721                 md2( message_str, msg_len, hash_result );
01722                 break;
01723         #endif
01724         #ifdef POLARSSL_MD4_C
01725             case SIG_RSA_MD4:
01726                 md4( message_str, msg_len, hash_result );
01727                 break;
01728         #endif
01729         #ifdef POLARSSL_MD5_C
01730             case SIG_RSA_MD5:
01731                 md5( message_str, msg_len, hash_result );
01732                 break;
01733         #endif
01734         #ifdef POLARSSL_SHA1_C
01735             case SIG_RSA_SHA1:
01736                 sha1( message_str, msg_len, hash_result );
01737                 break;
01738         #endif
01739         #ifdef POLARSSL_SHA2_C
01740             case SIG_RSA_SHA224:
01741                 sha2( message_str, msg_len, hash_result, 1 );
01742                 break;
01743             case SIG_RSA_SHA256:
01744                 sha2( message_str, msg_len, hash_result, 0 );
01745                 break;
01746         #endif
01747         #ifdef POLARSSL_SHA4_C
01748             case SIG_RSA_SHA384:
01749                 sha4( message_str, msg_len, hash_result, 1 );
01750                 break;
01751             case SIG_RSA_SHA512:
01752                 sha4( message_str, msg_len, hash_result, 0 );
01753                 break;
01754         #endif
01755             }
01756         
01757             fct_chk( rsa_pkcs1_verify( &ctx, RSA_PUBLIC, SIG_RSA_SHA224, 0, hash_result, result_str ) == POLARSSL_ERR_RSA_INVALID_PADDING );
01758         }
01759         FCT_TEST_END();
01760 #endif /* POLARSSL_SHA2_C */
01761 
01762 #ifdef POLARSSL_SHA2_C
01763 
01764         FCT_TEST_BGN(rsa_pkcs1_verify_v15_cavs_23)
01765         {
01766             unsigned char message_str[1000];
01767             unsigned char hash_result[1000];
01768             unsigned char result_str[1000];
01769             rsa_context ctx;
01770             int msg_len;
01771         
01772             rsa_init( &ctx, RSA_PKCS_V15, 0 );
01773             memset( message_str, 0x00, 1000 );
01774             memset( hash_result, 0x00, 1000 );
01775             memset( result_str, 0x00, 1000 );
01776         
01777             ctx.len = 1536 / 8;
01778             fct_chk( mpi_read_string( &ctx.N, 16, "a59d9b7269b102b7be684ec5e28db79992e6d3231e77c90b78960c2638b35ef6dbdac1ac59e7249d96d426e7f99397eabc6b8903fe1942da580322b98bafacd81bb911c29666f83886a2a2864f3552044300e60cedd5a8c321c43e280413dc41673c39a11b98a885486f8187a70f270185c4c12bc48a1968305269776c070ef69d4913589a887c4d0f5e7dd58bd806d0d49a14a1762c38665cef4646ff13a0cd29c3a60460703c3d051d5b28c660bffb5f8bd43d495ffa64175f72b8abe5fddd" ) == 0 );
01779             fct_chk( mpi_read_string( &ctx.E, 16, "10001" ) == 0 );
01780         
01781             fct_chk( rsa_check_pubkey( &ctx ) == 0 );
01782         
01783             msg_len = unhexify( message_str, "06dcd9d4c056b6a45b9ed2ae5f6c1cfa43aae06fe01ee098264aa7a80e901abbcf9a505e55f9a352ef0c078d48249b8298e57ea21bf0e423c3bf69002acfa541ca05007c704bc79cee7a80e1107c7b28d2b2aa6dd093b28efe9642519952a4a95ee49235f9924a0ac0aee5b2a1bce47459d70cd6e75074614199dca44561407c" );
01784             unhexify( result_str, "5e08f399258e6de075b67a0a6a822ceb21b1eb7a0342eca6a4295739f644547dee3456243cf32bd6ea6f357c88632508457130f3dae04f7806efaed43d1d501e16c961dfbd6c71a42b480e95c7027f8275063d05a9aac3eef0520867b9896ebe8ec358f7d121beb4e61ddfdc3dcd835dfe265f2ba68d300ef566ed1284f9f3d7b1af363ed47bfa2e5f0492925444df7e5fcb1e79e690c746117650b543a5e82c39553552f0f44e617b5cf773c533050f4129e893ac22af69b1eb9afb4b5ba5f5" );
01785         
01786             switch( SIG_RSA_SHA224 )
01787             {
01788         #ifdef POLARSSL_MD2_C
01789             case SIG_RSA_MD2:
01790                 md2( message_str, msg_len, hash_result );
01791                 break;
01792         #endif
01793         #ifdef POLARSSL_MD4_C
01794             case SIG_RSA_MD4:
01795                 md4( message_str, msg_len, hash_result );
01796                 break;
01797         #endif
01798         #ifdef POLARSSL_MD5_C
01799             case SIG_RSA_MD5:
01800                 md5( message_str, msg_len, hash_result );
01801                 break;
01802         #endif
01803         #ifdef POLARSSL_SHA1_C
01804             case SIG_RSA_SHA1:
01805                 sha1( message_str, msg_len, hash_result );
01806                 break;
01807         #endif
01808         #ifdef POLARSSL_SHA2_C
01809             case SIG_RSA_SHA224:
01810                 sha2( message_str, msg_len, hash_result, 1 );
01811                 break;
01812             case SIG_RSA_SHA256:
01813                 sha2( message_str, msg_len, hash_result, 0 );
01814                 break;
01815         #endif
01816         #ifdef POLARSSL_SHA4_C
01817             case SIG_RSA_SHA384:
01818                 sha4( message_str, msg_len, hash_result, 1 );
01819                 break;
01820             case SIG_RSA_SHA512:
01821                 sha4( message_str, msg_len, hash_result, 0 );
01822                 break;
01823         #endif
01824             }
01825         
01826             fct_chk( rsa_pkcs1_verify( &ctx, RSA_PUBLIC, SIG_RSA_SHA224, 0, hash_result, result_str ) == 0 );
01827         }
01828         FCT_TEST_END();
01829 #endif /* POLARSSL_SHA2_C */
01830 
01831 #ifdef POLARSSL_SHA2_C
01832 
01833         FCT_TEST_BGN(rsa_pkcs1_verify_v15_cavs_24)
01834         {
01835             unsigned char message_str[1000];
01836             unsigned char hash_result[1000];
01837             unsigned char result_str[1000];
01838             rsa_context ctx;
01839             int msg_len;
01840         
01841             rsa_init( &ctx, RSA_PKCS_V15, 0 );
01842             memset( message_str, 0x00, 1000 );
01843             memset( hash_result, 0x00, 1000 );
01844             memset( result_str, 0x00, 1000 );
01845         
01846             ctx.len = 1536 / 8;
01847             fct_chk( mpi_read_string( &ctx.N, 16, "a59d9b7269b102b7be684ec5e28db79992e6d3231e77c90b78960c2638b35ef6dbdac1ac59e7249d96d426e7f99397eabc6b8903fe1942da580322b98bafacd81bb911c29666f83886a2a2864f3552044300e60cedd5a8c321c43e280413dc41673c39a11b98a885486f8187a70f270185c4c12bc48a1968305269776c070ef69d4913589a887c4d0f5e7dd58bd806d0d49a14a1762c38665cef4646ff13a0cd29c3a60460703c3d051d5b28c660bffb5f8bd43d495ffa64175f72b8abe5fddd" ) == 0 );
01848             fct_chk( mpi_read_string( &ctx.E, 16, "10001" ) == 0 );
01849         
01850             fct_chk( rsa_check_pubkey( &ctx ) == 0 );
01851         
01852             msg_len = unhexify( message_str, "1240028c6d7ab3992ada0e5ca55ee4f3d62f8de575302d5861d73685423c2e6a6d6fb3be090fbc2a701821b6d8fd5e8233f794b6549cd0bb52b390ac31478307bffa91a9bd9c1bf93ffc846356fef008ebee4bb3ee148e0fb1893d188e4934d0d088a433d14a596c5f2e3e49648a22edc6bdbcc58dc1edbd440046b3a169ca2b" );
01853             unhexify( result_str, "a003ae9cf0704d58763b214f20446ecc4099c566f25384e28d0dd6540c58705fc8d0bfe1ceaa06096ed1e230146edb82056e39e6727abec09f25e44079b6ce1ca2c6a540dec7aa34444d7d435f41e5fca9b0bba62759ae2780638e5160e031bb60409c2e85674ac7a776b444b37b9d7f4dbaa557e88b8562a584f2dbe90729b241aede95dfcc7e05b10deef06255cb89f0e7ccff23354818756a1f8bb9f00fd18f6cd22ca1b4bfc38027562bb37562c77c7883b5d735170d75521195fd3f2bd3" );
01854         
01855             switch( SIG_RSA_SHA256 )
01856             {
01857         #ifdef POLARSSL_MD2_C
01858             case SIG_RSA_MD2:
01859                 md2( message_str, msg_len, hash_result );
01860                 break;
01861         #endif
01862         #ifdef POLARSSL_MD4_C
01863             case SIG_RSA_MD4:
01864                 md4( message_str, msg_len, hash_result );
01865                 break;
01866         #endif
01867         #ifdef POLARSSL_MD5_C
01868             case SIG_RSA_MD5:
01869                 md5( message_str, msg_len, hash_result );
01870                 break;
01871         #endif
01872         #ifdef POLARSSL_SHA1_C
01873             case SIG_RSA_SHA1:
01874                 sha1( message_str, msg_len, hash_result );
01875                 break;
01876         #endif
01877         #ifdef POLARSSL_SHA2_C
01878             case SIG_RSA_SHA224:
01879                 sha2( message_str, msg_len, hash_result, 1 );
01880                 break;
01881             case SIG_RSA_SHA256:
01882                 sha2( message_str, msg_len, hash_result, 0 );
01883                 break;
01884         #endif
01885         #ifdef POLARSSL_SHA4_C
01886             case SIG_RSA_SHA384:
01887                 sha4( message_str, msg_len, hash_result, 1 );
01888                 break;
01889             case SIG_RSA_SHA512:
01890                 sha4( message_str, msg_len, hash_result, 0 );
01891                 break;
01892         #endif
01893             }
01894         
01895             fct_chk( rsa_pkcs1_verify( &ctx, RSA_PUBLIC, SIG_RSA_SHA256, 0, hash_result, result_str ) == 0 );
01896         }
01897         FCT_TEST_END();
01898 #endif /* POLARSSL_SHA2_C */
01899 
01900 #ifdef POLARSSL_SHA4_C
01901 
01902         FCT_TEST_BGN(rsa_pkcs1_verify_v15_cavs_25)
01903         {
01904             unsigned char message_str[1000];
01905             unsigned char hash_result[1000];
01906             unsigned char result_str[1000];
01907             rsa_context ctx;
01908             int msg_len;
01909         
01910             rsa_init( &ctx, RSA_PKCS_V15, 0 );
01911             memset( message_str, 0x00, 1000 );
01912             memset( hash_result, 0x00, 1000 );
01913             memset( result_str, 0x00, 1000 );
01914         
01915             ctx.len = 1536 / 8;
01916             fct_chk( mpi_read_string( &ctx.N, 16, "a59d9b7269b102b7be684ec5e28db79992e6d3231e77c90b78960c2638b35ef6dbdac1ac59e7249d96d426e7f99397eabc6b8903fe1942da580322b98bafacd81bb911c29666f83886a2a2864f3552044300e60cedd5a8c321c43e280413dc41673c39a11b98a885486f8187a70f270185c4c12bc48a1968305269776c070ef69d4913589a887c4d0f5e7dd58bd806d0d49a14a1762c38665cef4646ff13a0cd29c3a60460703c3d051d5b28c660bffb5f8bd43d495ffa64175f72b8abe5fddd" ) == 0 );
01917             fct_chk( mpi_read_string( &ctx.E, 16, "10001" ) == 0 );
01918         
01919             fct_chk( rsa_check_pubkey( &ctx ) == 0 );
01920         
01921             msg_len = unhexify( message_str, "67922a8b9cbc95cf7c555ff2d73cfc62ee04c3f0df9bfc8f64293a58bd3bebd2eb212d711f94e35c729d0873d6b244914d21bd0e59b23089b38740e43f480e8f407d090ac93b08a57403968b55e78cfe31eee6e4ecbacf834168fe89b6b8454fce6e675e80f82b33e850ae3f3d24fd320335e37981fd000576941b4f08d4ba99" );
01922             unhexify( result_str, "2c6b301852cc55a993a933e2c080eb9dabfe19e9dc3571066caeabed1492d3501cd838de1c01784932df7a5ad5bbfb48c78f53a45f76e9812d046f23bd968495ef7e981e5add4acfc538fe33a5205de74bb37d3d9b6b87b2d174e85a73f216fd67d5738fc469dff7ea6b852e8dd08bc8df036597372d4d51185e6f47a45fbe1b9bdb06a4018783425ec95294de41f27235ad3b3263a890b8b62b17410a9bb08673393ff205a866ee2057e99c6517c6bbc84f8d87717b83d6f64de7ee215e1e8d" );
01923         
01924             switch( SIG_RSA_SHA384 )
01925             {
01926         #ifdef POLARSSL_MD2_C
01927             case SIG_RSA_MD2:
01928                 md2( message_str, msg_len, hash_result );
01929                 break;
01930         #endif
01931         #ifdef POLARSSL_MD4_C
01932             case SIG_RSA_MD4:
01933                 md4( message_str, msg_len, hash_result );
01934                 break;
01935         #endif
01936         #ifdef POLARSSL_MD5_C
01937             case SIG_RSA_MD5:
01938                 md5( message_str, msg_len, hash_result );
01939                 break;
01940         #endif
01941         #ifdef POLARSSL_SHA1_C
01942             case SIG_RSA_SHA1:
01943                 sha1( message_str, msg_len, hash_result );
01944                 break;
01945         #endif
01946         #ifdef POLARSSL_SHA2_C
01947             case SIG_RSA_SHA224:
01948                 sha2( message_str, msg_len, hash_result, 1 );
01949                 break;
01950             case SIG_RSA_SHA256:
01951                 sha2( message_str, msg_len, hash_result, 0 );
01952                 break;
01953         #endif
01954         #ifdef POLARSSL_SHA4_C
01955             case SIG_RSA_SHA384:
01956                 sha4( message_str, msg_len, hash_result, 1 );
01957                 break;
01958             case SIG_RSA_SHA512:
01959                 sha4( message_str, msg_len, hash_result, 0 );
01960                 break;
01961         #endif
01962             }
01963         
01964             fct_chk( rsa_pkcs1_verify( &ctx, RSA_PUBLIC, SIG_RSA_SHA384, 0, hash_result, result_str ) == 0 );
01965         }
01966         FCT_TEST_END();
01967 #endif /* POLARSSL_SHA4_C */
01968 
01969 #ifdef POLARSSL_SHA4_C
01970 
01971         FCT_TEST_BGN(rsa_pkcs1_verify_v15_cavs_26)
01972         {
01973             unsigned char message_str[1000];
01974             unsigned char hash_result[1000];
01975             unsigned char result_str[1000];
01976             rsa_context ctx;
01977             int msg_len;
01978         
01979             rsa_init( &ctx, RSA_PKCS_V15, 0 );
01980             memset( message_str, 0x00, 1000 );
01981             memset( hash_result, 0x00, 1000 );
01982             memset( result_str, 0x00, 1000 );
01983         
01984             ctx.len = 1536 / 8;
01985             fct_chk( mpi_read_string( &ctx.N, 16, "a59d9b7269b102b7be684ec5e28db79992e6d3231e77c90b78960c2638b35ef6dbdac1ac59e7249d96d426e7f99397eabc6b8903fe1942da580322b98bafacd81bb911c29666f83886a2a2864f3552044300e60cedd5a8c321c43e280413dc41673c39a11b98a885486f8187a70f270185c4c12bc48a1968305269776c070ef69d4913589a887c4d0f5e7dd58bd806d0d49a14a1762c38665cef4646ff13a0cd29c3a60460703c3d051d5b28c660bffb5f8bd43d495ffa64175f72b8abe5fddd" ) == 0 );
01986             fct_chk( mpi_read_string( &ctx.E, 16, "10001" ) == 0 );
01987         
01988             fct_chk( rsa_check_pubkey( &ctx ) == 0 );
01989         
01990             msg_len = unhexify( message_str, "1428b4a449698a994ef84c46a517c3aa6359c48e4264ef65f1f69d77ae26133e17edfc103de416fffb4f2bfe865b434544a418f6e2faca00a165d443f0663ff64080154614f7194057d8b5f1f33934cc9fc2314cf86d4fdad4892bf0d3058f7f37ebe98ef52bfb240b9ad369153afe081bbcf9d7ae43e8ba336b8ac57e8a6da0" );
01991             unhexify( result_str, "8e10a1ae470e6e57a8d234185f78fdb600cc636c41565a9f3694a84ae102f6251984f54d11a7785fdcfdfaf80a821e05d57ef6b8edc03d9076755779322fd53eb98c805da77dc9316744e393c2fecd291a7e6043b1ca89fd8248f661e1d53110211b91edb41b31e848cde1115d8afd9963ebcc36aff5a27085949f0781bc69167c140ecfe71c44aacaf4123e557eaf2b528c6d0ea875b4ceefa942fe338af8df10562c438af04cd7521da912b3e3899cef0d75722161be6abed5e4e9009dbf40" );
01992         
01993             switch( SIG_RSA_SHA512 )
01994             {
01995         #ifdef POLARSSL_MD2_C
01996             case SIG_RSA_MD2:
01997                 md2( message_str, msg_len, hash_result );
01998                 break;
01999         #endif
02000         #ifdef POLARSSL_MD4_C
02001             case SIG_RSA_MD4:
02002                 md4( message_str, msg_len, hash_result );
02003                 break;
02004         #endif
02005         #ifdef POLARSSL_MD5_C
02006             case SIG_RSA_MD5:
02007                 md5( message_str, msg_len, hash_result );
02008                 break;
02009         #endif
02010         #ifdef POLARSSL_SHA1_C
02011             case SIG_RSA_SHA1:
02012                 sha1( message_str, msg_len, hash_result );
02013                 break;
02014         #endif
02015         #ifdef POLARSSL_SHA2_C
02016             case SIG_RSA_SHA224:
02017                 sha2( message_str, msg_len, hash_result, 1 );
02018                 break;
02019             case SIG_RSA_SHA256:
02020                 sha2( message_str, msg_len, hash_result, 0 );
02021                 break;
02022         #endif
02023         #ifdef POLARSSL_SHA4_C
02024             case SIG_RSA_SHA384:
02025                 sha4( message_str, msg_len, hash_result, 1 );
02026                 break;
02027             case SIG_RSA_SHA512:
02028                 sha4( message_str, msg_len, hash_result, 0 );
02029                 break;
02030         #endif
02031             }
02032         
02033             fct_chk( rsa_pkcs1_verify( &ctx, RSA_PUBLIC, SIG_RSA_SHA512, 0, hash_result, result_str ) == 0 );
02034         }
02035         FCT_TEST_END();
02036 #endif /* POLARSSL_SHA4_C */
02037 
02038 #ifdef POLARSSL_SHA1_C
02039 
02040         FCT_TEST_BGN(rsa_pkcs1_verify_v15_cavs_27)
02041         {
02042             unsigned char message_str[1000];
02043             unsigned char hash_result[1000];
02044             unsigned char result_str[1000];
02045             rsa_context ctx;
02046             int msg_len;
02047         
02048             rsa_init( &ctx, RSA_PKCS_V15, 0 );
02049             memset( message_str, 0x00, 1000 );
02050             memset( hash_result, 0x00, 1000 );
02051             memset( result_str, 0x00, 1000 );
02052         
02053             ctx.len = 1536 / 8;
02054             fct_chk( mpi_read_string( &ctx.N, 16, "a59d9b7269b102b7be684ec5e28db79992e6d3231e77c90b78960c2638b35ef6dbdac1ac59e7249d96d426e7f99397eabc6b8903fe1942da580322b98bafacd81bb911c29666f83886a2a2864f3552044300e60cedd5a8c321c43e280413dc41673c39a11b98a885486f8187a70f270185c4c12bc48a1968305269776c070ef69d4913589a887c4d0f5e7dd58bd806d0d49a14a1762c38665cef4646ff13a0cd29c3a60460703c3d051d5b28c660bffb5f8bd43d495ffa64175f72b8abe5fddd" ) == 0 );
02055             fct_chk( mpi_read_string( &ctx.E, 16, "11" ) == 0 );
02056         
02057             fct_chk( rsa_check_pubkey( &ctx ) == 0 );
02058         
02059             msg_len = unhexify( message_str, "4871adc05f6b3ecf296680b0dd8d86715b0d5264c064008037dc410512520b5f193c8f4d21eb6c42e10d220c0275c9b3751f03a4096e2f0e3db9df8d52068c06a51589d23ca1361e9fe27691e95663301ec1407fbf73aee99cc92362eaf6994b95038396d815052a0aef6489bbb7bcb0fffdf13f0af9e7d9fd14f6ce00ab98f7" );
02060             unhexify( result_str, "180caf03781b391aacebe5b3f5e1d3b01c68a00df4ecfb6c4bf14217aed7cfca0adac099ec1d6e1f0b43b09b86788533fee6691d773807af0df6cc3bbdde3cf34bf5b848fa59c8bc10227cc3eba3452a85e0520fccdb2d8d32dd99672d302756a2d7f7f2693db3a48be17bd34d9d891f4ba44449c5bad1de91b788f524500a7703cccbaa77b9fe8791f5c8aa7b8f055336f28fcfc01733712e33cfb3d33fe71ddb9ced2a31931ec38007f5ad4a0d19acc428124b0e5ee6e0746fb33c1a4d90c8" );
02061         
02062             switch( SIG_RSA_SHA1 )
02063             {
02064         #ifdef POLARSSL_MD2_C
02065             case SIG_RSA_MD2:
02066                 md2( message_str, msg_len, hash_result );
02067                 break;
02068         #endif
02069         #ifdef POLARSSL_MD4_C
02070             case SIG_RSA_MD4:
02071                 md4( message_str, msg_len, hash_result );
02072                 break;
02073         #endif
02074         #ifdef POLARSSL_MD5_C
02075             case SIG_RSA_MD5:
02076                 md5( message_str, msg_len, hash_result );
02077                 break;
02078         #endif
02079         #ifdef POLARSSL_SHA1_C
02080             case SIG_RSA_SHA1:
02081                 sha1( message_str, msg_len, hash_result );
02082                 break;
02083         #endif
02084         #ifdef POLARSSL_SHA2_C
02085             case SIG_RSA_SHA224:
02086                 sha2( message_str, msg_len, hash_result, 1 );
02087                 break;
02088             case SIG_RSA_SHA256:
02089                 sha2( message_str, msg_len, hash_result, 0 );
02090                 break;
02091         #endif
02092         #ifdef POLARSSL_SHA4_C
02093             case SIG_RSA_SHA384:
02094                 sha4( message_str, msg_len, hash_result, 1 );
02095                 break;
02096             case SIG_RSA_SHA512:
02097                 sha4( message_str, msg_len, hash_result, 0 );
02098                 break;
02099         #endif
02100             }
02101         
02102             fct_chk( rsa_pkcs1_verify( &ctx, RSA_PUBLIC, SIG_RSA_SHA1, 0, hash_result, result_str ) == 0 );
02103         }
02104         FCT_TEST_END();
02105 #endif /* POLARSSL_SHA1_C */
02106 
02107 #ifdef POLARSSL_SHA2_C
02108 
02109         FCT_TEST_BGN(rsa_pkcs1_verify_v15_cavs_28)
02110         {
02111             unsigned char message_str[1000];
02112             unsigned char hash_result[1000];
02113             unsigned char result_str[1000];
02114             rsa_context ctx;
02115             int msg_len;
02116         
02117             rsa_init( &ctx, RSA_PKCS_V15, 0 );
02118             memset( message_str, 0x00, 1000 );
02119             memset( hash_result, 0x00, 1000 );
02120             memset( result_str, 0x00, 1000 );
02121         
02122             ctx.len = 1536 / 8;
02123             fct_chk( mpi_read_string( &ctx.N, 16, "a59d9b7269b102b7be684ec5e28db79992e6d3231e77c90b78960c2638b35ef6dbdac1ac59e7249d96d426e7f99397eabc6b8903fe1942da580322b98bafacd81bb911c29666f83886a2a2864f3552044300e60cedd5a8c321c43e280413dc41673c39a11b98a885486f8187a70f270185c4c12bc48a1968305269776c070ef69d4913589a887c4d0f5e7dd58bd806d0d49a14a1762c38665cef4646ff13a0cd29c3a60460703c3d051d5b28c660bffb5f8bd43d495ffa64175f72b8abe5fddd" ) == 0 );
02124             fct_chk( mpi_read_string( &ctx.E, 16, "11" ) == 0 );
02125         
02126             fct_chk( rsa_check_pubkey( &ctx ) == 0 );
02127         
02128             msg_len = unhexify( message_str, "3bba64de38438a71b95ab9c94539d5870c1fb08d7a9937600c00e9d063438edc97e625d0cd4b1eb00c31c9d94c7a0fe6d03160d1b6cbec5acdad16ada6ef253fee603df9faca8f98a477cc5456f3dfbf6414dbf19f3832e227ce291780188881e82e96a2e84744f12a34a9808a2daedc6fd00b345c6772bec26a095719451e6a" );
02129             unhexify( result_str, "8c846e75e32ce5f9964bdd8f6dcf1d2996a646b233bcf1bd6394e13e856691b89bedd18290a0f9f7c90dca307271b3108e795340490513b25e6789e93722c65ec064b4c43457295a31d1f07dd605e133fd6eaafc58cda132df2939f5f693e0205af34550afaa137f3e482885e50dfb48333a15c0821e7a19642acdddc6fea3c7487c691246a2b083dac439889d5ae741b7e08c47937530b4b069f1a260cd07fe4a0ddd530ab11534fb805e9b562118ee0e97932966008aadfc83f3b8a10de8ee" );
02130         
02131             switch( SIG_RSA_SHA224 )
02132             {
02133         #ifdef POLARSSL_MD2_C
02134             case SIG_RSA_MD2:
02135                 md2( message_str, msg_len, hash_result );
02136                 break;
02137         #endif
02138         #ifdef POLARSSL_MD4_C
02139             case SIG_RSA_MD4:
02140                 md4( message_str, msg_len, hash_result );
02141                 break;
02142         #endif
02143         #ifdef POLARSSL_MD5_C
02144             case SIG_RSA_MD5:
02145                 md5( message_str, msg_len, hash_result );
02146                 break;
02147         #endif
02148         #ifdef POLARSSL_SHA1_C
02149             case SIG_RSA_SHA1:
02150                 sha1( message_str, msg_len, hash_result );
02151                 break;
02152         #endif
02153         #ifdef POLARSSL_SHA2_C
02154             case SIG_RSA_SHA224:
02155                 sha2( message_str, msg_len, hash_result, 1 );
02156                 break;
02157             case SIG_RSA_SHA256:
02158                 sha2( message_str, msg_len, hash_result, 0 );
02159                 break;
02160         #endif
02161         #ifdef POLARSSL_SHA4_C
02162             case SIG_RSA_SHA384:
02163                 sha4( message_str, msg_len, hash_result, 1 );
02164                 break;
02165             case SIG_RSA_SHA512:
02166                 sha4( message_str, msg_len, hash_result, 0 );
02167                 break;
02168         #endif
02169             }
02170         
02171             fct_chk( rsa_pkcs1_verify( &ctx, RSA_PUBLIC, SIG_RSA_SHA224, 0, hash_result, result_str ) == 0 );
02172         }
02173         FCT_TEST_END();
02174 #endif /* POLARSSL_SHA2_C */
02175 
02176 #ifdef POLARSSL_SHA2_C
02177 
02178         FCT_TEST_BGN(rsa_pkcs1_verify_v15_cavs_29)
02179         {
02180             unsigned char message_str[1000];
02181             unsigned char hash_result[1000];
02182             unsigned char result_str[1000];
02183             rsa_context ctx;
02184             int msg_len;
02185         
02186             rsa_init( &ctx, RSA_PKCS_V15, 0 );
02187             memset( message_str, 0x00, 1000 );
02188             memset( hash_result, 0x00, 1000 );
02189             memset( result_str, 0x00, 1000 );
02190         
02191             ctx.len = 1536 / 8;
02192             fct_chk( mpi_read_string( &ctx.N, 16, "a59d9b7269b102b7be684ec5e28db79992e6d3231e77c90b78960c2638b35ef6dbdac1ac59e7249d96d426e7f99397eabc6b8903fe1942da580322b98bafacd81bb911c29666f83886a2a2864f3552044300e60cedd5a8c321c43e280413dc41673c39a11b98a885486f8187a70f270185c4c12bc48a1968305269776c070ef69d4913589a887c4d0f5e7dd58bd806d0d49a14a1762c38665cef4646ff13a0cd29c3a60460703c3d051d5b28c660bffb5f8bd43d495ffa64175f72b8abe5fddd" ) == 0 );
02193             fct_chk( mpi_read_string( &ctx.E, 16, "11" ) == 0 );
02194         
02195             fct_chk( rsa_check_pubkey( &ctx ) == 0 );
02196         
02197             msg_len = unhexify( message_str, "f7857ce04bf4292ea1755f9e587822372f4dcdf10bddfc0ff498a8af60ae94a0b482e873085c1cd52a5d181ce6b99a1f8520d74b947d65f3e7e358e8ddc4ac4ae465e39d408eee1f09865159733f83f553cd93cfde1c114fb3e32cf51cd418359016b3867df467b645d752808671a4609f3c49a67023c9ca617e6cffa544a10a" );
02198             unhexify( result_str, "9677300bbee003be3c445634f8ed5beb152b63f46f84cf5a8e721e0fafe8f3f7e99a6d50741f23f449d3026da3e8a7ac36be99ab44831803486ae552f7aa01f075287829b231d2d0840908e09081ae177ed888fe46a9d937a0871eb5d52ec541c8411c4cbf7efea6ca213b12cea513b0739eedca7c9473e10a7796936f4eaa0c5d3a9013ca5536781ac68eb2ca5779144de23da2e9875114aca885b3219dfc292d73940c5992ea3c4882889e7543430652860e441a01a45d9f4005a012421493" );
02199         
02200             switch( SIG_RSA_SHA256 )
02201             {
02202         #ifdef POLARSSL_MD2_C
02203             case SIG_RSA_MD2:
02204                 md2( message_str, msg_len, hash_result );
02205                 break;
02206         #endif
02207         #ifdef POLARSSL_MD4_C
02208             case SIG_RSA_MD4:
02209                 md4( message_str, msg_len, hash_result );
02210                 break;
02211         #endif
02212         #ifdef POLARSSL_MD5_C
02213             case SIG_RSA_MD5:
02214                 md5( message_str, msg_len, hash_result );
02215                 break;
02216         #endif
02217         #ifdef POLARSSL_SHA1_C
02218             case SIG_RSA_SHA1:
02219                 sha1( message_str, msg_len, hash_result );
02220                 break;
02221         #endif
02222         #ifdef POLARSSL_SHA2_C
02223             case SIG_RSA_SHA224:
02224                 sha2( message_str, msg_len, hash_result, 1 );
02225                 break;
02226             case SIG_RSA_SHA256:
02227                 sha2( message_str, msg_len, hash_result, 0 );
02228                 break;
02229         #endif
02230         #ifdef POLARSSL_SHA4_C
02231             case SIG_RSA_SHA384:
02232                 sha4( message_str, msg_len, hash_result, 1 );
02233                 break;
02234             case SIG_RSA_SHA512:
02235                 sha4( message_str, msg_len, hash_result, 0 );
02236                 break;
02237         #endif
02238             }
02239         
02240             fct_chk( rsa_pkcs1_verify( &ctx, RSA_PUBLIC, SIG_RSA_SHA256, 0, hash_result, result_str ) == 0 );
02241         }
02242         FCT_TEST_END();
02243 #endif /* POLARSSL_SHA2_C */
02244 
02245 #ifdef POLARSSL_SHA2_C
02246 
02247         FCT_TEST_BGN(rsa_pkcs1_verify_v15_cavs_30)
02248         {
02249             unsigned char message_str[1000];
02250             unsigned char hash_result[1000];
02251             unsigned char result_str[1000];
02252             rsa_context ctx;
02253             int msg_len;
02254         
02255             rsa_init( &ctx, RSA_PKCS_V15, 0 );
02256             memset( message_str, 0x00, 1000 );
02257             memset( hash_result, 0x00, 1000 );
02258             memset( result_str, 0x00, 1000 );
02259         
02260             ctx.len = 1536 / 8;
02261             fct_chk( mpi_read_string( &ctx.N, 16, "a59d9b7269b102b7be684ec5e28db79992e6d3231e77c90b78960c2638b35ef6dbdac1ac59e7249d96d426e7f99397eabc6b8903fe1942da580322b98bafacd81bb911c29666f83886a2a2864f3552044300e60cedd5a8c321c43e280413dc41673c39a11b98a885486f8187a70f270185c4c12bc48a1968305269776c070ef69d4913589a887c4d0f5e7dd58bd806d0d49a14a1762c38665cef4646ff13a0cd29c3a60460703c3d051d5b28c660bffb5f8bd43d495ffa64175f72b8abe5fddd" ) == 0 );
02262             fct_chk( mpi_read_string( &ctx.E, 16, "3" ) == 0 );
02263         
02264             fct_chk( rsa_check_pubkey( &ctx ) == 0 );
02265         
02266             msg_len = unhexify( message_str, "ca312774f2756ac2019f213a01a63c9a0b4a49ccafecf25e97a4c632668e3c77e664f4d7635241f25205e50c37061b02c546db8346fa597c3da8cfd44a827c5a4ff4ecfcd1797b39a1b215d9bbb93fdb6eb35bafbda427a5068888a6e19f86224b0897490491207e35ce39085668b10b4fb851b7dd9465c03869790ef38a61b5" );
02267             unhexify( result_str, "a202c33eb831b9d8e818b6c3bcdb42818e1d9c22a06ddd73a17a21e49d18cda44df349a066477cae068e1a5d2b518b0885e889ef796ca9e6f42a69ac755b8a6405fbaef93fe0130d98de35d689addfee3eecd26658903f774bda481c3f40ee0e9569a3c3e2da7ad576c7de82159d933e36fa29cfef99367005e34ab5082d80f48276d37dabc88dbb023bd01585329d2ccf417f78ec508aaa29751007d31f1669296b981d44c8fa99130c5df7a071725b496859314aaf9baf0ebc780355914249" );
02268         
02269             switch( SIG_RSA_SHA256 )
02270             {
02271         #ifdef POLARSSL_MD2_C
02272             case SIG_RSA_MD2:
02273                 md2( message_str, msg_len, hash_result );
02274                 break;
02275         #endif
02276         #ifdef POLARSSL_MD4_C
02277             case SIG_RSA_MD4:
02278                 md4( message_str, msg_len, hash_result );
02279                 break;
02280         #endif
02281         #ifdef POLARSSL_MD5_C
02282             case SIG_RSA_MD5:
02283                 md5( message_str, msg_len, hash_result );
02284                 break;
02285         #endif
02286         #ifdef POLARSSL_SHA1_C
02287             case SIG_RSA_SHA1:
02288                 sha1( message_str, msg_len, hash_result );
02289                 break;
02290         #endif
02291         #ifdef POLARSSL_SHA2_C
02292             case SIG_RSA_SHA224:
02293                 sha2( message_str, msg_len, hash_result, 1 );
02294                 break;
02295             case SIG_RSA_SHA256:
02296                 sha2( message_str, msg_len, hash_result, 0 );
02297                 break;
02298         #endif
02299         #ifdef POLARSSL_SHA4_C
02300             case SIG_RSA_SHA384:
02301                 sha4( message_str, msg_len, hash_result, 1 );
02302                 break;
02303             case SIG_RSA_SHA512:
02304                 sha4( message_str, msg_len, hash_result, 0 );
02305                 break;
02306         #endif
02307             }
02308         
02309             fct_chk( rsa_pkcs1_verify( &ctx, RSA_PUBLIC, SIG_RSA_SHA256, 0, hash_result, result_str ) == POLARSSL_ERR_RSA_INVALID_PADDING );
02310         }
02311         FCT_TEST_END();
02312 #endif /* POLARSSL_SHA2_C */
02313 
02314 #ifdef POLARSSL_SHA4_C
02315 
02316         FCT_TEST_BGN(rsa_pkcs1_verify_v15_cavs_31)
02317         {
02318             unsigned char message_str[1000];
02319             unsigned char hash_result[1000];
02320             unsigned char result_str[1000];
02321             rsa_context ctx;
02322             int msg_len;
02323         
02324             rsa_init( &ctx, RSA_PKCS_V15, 0 );
02325             memset( message_str, 0x00, 1000 );
02326             memset( hash_result, 0x00, 1000 );
02327             memset( result_str, 0x00, 1000 );
02328         
02329             ctx.len = 1536 / 8;
02330             fct_chk( mpi_read_string( &ctx.N, 16, "a59d9b7269b102b7be684ec5e28db79992e6d3231e77c90b78960c2638b35ef6dbdac1ac59e7249d96d426e7f99397eabc6b8903fe1942da580322b98bafacd81bb911c29666f83886a2a2864f3552044300e60cedd5a8c321c43e280413dc41673c39a11b98a885486f8187a70f270185c4c12bc48a1968305269776c070ef69d4913589a887c4d0f5e7dd58bd806d0d49a14a1762c38665cef4646ff13a0cd29c3a60460703c3d051d5b28c660bffb5f8bd43d495ffa64175f72b8abe5fddd" ) == 0 );
02331             fct_chk( mpi_read_string( &ctx.E, 16, "10001" ) == 0 );
02332         
02333             fct_chk( rsa_check_pubkey( &ctx ) == 0 );
02334         
02335             msg_len = unhexify( message_str, "2abe079077290ceb6c80ac5c61062ce8da814b1fb99a1a9fb2860ed900e6541856ec64bf19c0d9d1cc2280b7cc50af3e3d2ad8e044945d44761ca60891dd72bd6aa26a33274ffcf7ae7d661b5e651135fcff21aaf06b4a2db18fe5827e0243884f2841760b9f1c65fbda870f7f0cfbd6ff484f0825e688614928f2d12d1e7080" );
02336             unhexify( result_str, "402631f3cddfb02cc4d9cb58ef1ab6726bd787a50e12e98567c9702bfdf47af85904aec5a2f6c5df9a10f08f90f93728eb090ae2ac21ded9f38faecd8195f3eb3d4107521b1cee956e7a214245b038adae912fa35ec97cb3bdc41352e8aaff80173561284cb740f999a3cd6653a6c3d5a3f911a416f41e2155083982c99eb5998a0a74d77f1ae999d901ee24a7f2c424179a3f92b07dc0b3498c1884e60677bee0175e810b426c4ad008d2743cd19b00b33177bf8be3fed7f7406e1bce0c2ea3" );
02337         
02338             switch( SIG_RSA_SHA384 )
02339             {
02340         #ifdef POLARSSL_MD2_C
02341             case SIG_RSA_MD2:
02342                 md2( message_str, msg_len, hash_result );
02343                 break;
02344         #endif
02345         #ifdef POLARSSL_MD4_C
02346             case SIG_RSA_MD4:
02347                 md4( message_str, msg_len, hash_result );
02348                 break;
02349         #endif
02350         #ifdef POLARSSL_MD5_C
02351             case SIG_RSA_MD5:
02352                 md5( message_str, msg_len, hash_result );
02353                 break;
02354         #endif
02355         #ifdef POLARSSL_SHA1_C
02356             case SIG_RSA_SHA1:
02357                 sha1( message_str, msg_len, hash_result );
02358                 break;
02359         #endif
02360         #ifdef POLARSSL_SHA2_C
02361             case SIG_RSA_SHA224:
02362                 sha2( message_str, msg_len, hash_result, 1 );
02363                 break;
02364             case SIG_RSA_SHA256:
02365                 sha2( message_str, msg_len, hash_result, 0 );
02366                 break;
02367         #endif
02368         #ifdef POLARSSL_SHA4_C
02369             case SIG_RSA_SHA384:
02370                 sha4( message_str, msg_len, hash_result, 1 );
02371                 break;
02372             case SIG_RSA_SHA512:
02373                 sha4( message_str, msg_len, hash_result, 0 );
02374                 break;
02375         #endif
02376             }
02377         
02378             fct_chk( rsa_pkcs1_verify( &ctx, RSA_PUBLIC, SIG_RSA_SHA384, 0, hash_result, result_str ) == POLARSSL_ERR_RSA_INVALID_PADDING );
02379         }
02380         FCT_TEST_END();
02381 #endif /* POLARSSL_SHA4_C */
02382 
02383 #ifdef POLARSSL_SHA4_C
02384 
02385         FCT_TEST_BGN(rsa_pkcs1_verify_v15_cavs_32)
02386         {
02387             unsigned char message_str[1000];
02388             unsigned char hash_result[1000];
02389             unsigned char result_str[1000];
02390             rsa_context ctx;
02391             int msg_len;
02392         
02393             rsa_init( &ctx, RSA_PKCS_V15, 0 );
02394             memset( message_str, 0x00, 1000 );
02395             memset( hash_result, 0x00, 1000 );
02396             memset( result_str, 0x00, 1000 );
02397         
02398             ctx.len = 1536 / 8;
02399             fct_chk( mpi_read_string( &ctx.N, 16, "a59d9b7269b102b7be684ec5e28db79992e6d3231e77c90b78960c2638b35ef6dbdac1ac59e7249d96d426e7f99397eabc6b8903fe1942da580322b98bafacd81bb911c29666f83886a2a2864f3552044300e60cedd5a8c321c43e280413dc41673c39a11b98a885486f8187a70f270185c4c12bc48a1968305269776c070ef69d4913589a887c4d0f5e7dd58bd806d0d49a14a1762c38665cef4646ff13a0cd29c3a60460703c3d051d5b28c660bffb5f8bd43d495ffa64175f72b8abe5fddd" ) == 0 );
02400             fct_chk( mpi_read_string( &ctx.E, 16, "11" ) == 0 );
02401         
02402             fct_chk( rsa_check_pubkey( &ctx ) == 0 );
02403         
02404             msg_len = unhexify( message_str, "da9505809dc92cfd8e01a1857dde52df6677c40d98f4577c1659ca7d3e9f01f9a809065f51b54fe2f9723fe2c9d1eea7397f2d5531d1c51c6ea100b028596bf9f24dd90be14eab58f07b4f24a35b073aeb29ecde4a6f320237d7adbdc43d94f87e08866b95bbcac83dc7db3553a42400441f088e2bf6259539a2da8b5a74065f" );
02405             unhexify( result_str, "57edd0560df9840a25c28ff6d254e432395a5cd2d92248b3b44d7eab0fc65b3c4e545a916a8e90ce89745119db9ec9799aa8890f5250fb589cfc12dac1b6e406a39bc3b3663892da5354ba453cbd5e4c89bdce82d0ffe97052a03a5c3308819c1139ebc780c13cf6dc1477faf734abcb1db3fafaed6f22885c9c0222ff5deacb8cc6d027f2e959c3075011b382e88c4b27b83b4f2e6fda022e331c3602d19f5ac7bccfe95ea1e93d736dbd918ae5b1f468cd0b5b536a2f918d5e27a0757e75b7" );
02406         
02407             switch( SIG_RSA_SHA384 )
02408             {
02409         #ifdef POLARSSL_MD2_C
02410             case SIG_RSA_MD2:
02411                 md2( message_str, msg_len, hash_result );
02412                 break;
02413         #endif
02414         #ifdef POLARSSL_MD4_C
02415             case SIG_RSA_MD4:
02416                 md4( message_str, msg_len, hash_result );
02417                 break;
02418         #endif
02419         #ifdef POLARSSL_MD5_C
02420             case SIG_RSA_MD5:
02421                 md5( message_str, msg_len, hash_result );
02422                 break;
02423         #endif
02424         #ifdef POLARSSL_SHA1_C
02425             case SIG_RSA_SHA1:
02426                 sha1( message_str, msg_len, hash_result );
02427                 break;
02428         #endif
02429         #ifdef POLARSSL_SHA2_C
02430             case SIG_RSA_SHA224:
02431                 sha2( message_str, msg_len, hash_result, 1 );
02432                 break;
02433             case SIG_RSA_SHA256:
02434                 sha2( message_str, msg_len, hash_result, 0 );
02435                 break;
02436         #endif
02437         #ifdef POLARSSL_SHA4_C
02438             case SIG_RSA_SHA384:
02439                 sha4( message_str, msg_len, hash_result, 1 );
02440                 break;
02441             case SIG_RSA_SHA512:
02442                 sha4( message_str, msg_len, hash_result, 0 );
02443                 break;
02444         #endif
02445             }
02446         
02447             fct_chk( rsa_pkcs1_verify( &ctx, RSA_PUBLIC, SIG_RSA_SHA384, 0, hash_result, result_str ) == 0 );
02448         }
02449         FCT_TEST_END();
02450 #endif /* POLARSSL_SHA4_C */
02451 
02452 #ifdef POLARSSL_SHA4_C
02453 
02454         FCT_TEST_BGN(rsa_pkcs1_verify_v15_cavs_33)
02455         {
02456             unsigned char message_str[1000];
02457             unsigned char hash_result[1000];
02458             unsigned char result_str[1000];
02459             rsa_context ctx;
02460             int msg_len;
02461         
02462             rsa_init( &ctx, RSA_PKCS_V15, 0 );
02463             memset( message_str, 0x00, 1000 );
02464             memset( hash_result, 0x00, 1000 );
02465             memset( result_str, 0x00, 1000 );
02466         
02467             ctx.len = 1536 / 8;
02468             fct_chk( mpi_read_string( &ctx.N, 16, "a59d9b7269b102b7be684ec5e28db79992e6d3231e77c90b78960c2638b35ef6dbdac1ac59e7249d96d426e7f99397eabc6b8903fe1942da580322b98bafacd81bb911c29666f83886a2a2864f3552044300e60cedd5a8c321c43e280413dc41673c39a11b98a885486f8187a70f270185c4c12bc48a1968305269776c070ef69d4913589a887c4d0f5e7dd58bd806d0d49a14a1762c38665cef4646ff13a0cd29c3a60460703c3d051d5b28c660bffb5f8bd43d495ffa64175f72b8abe5fddd" ) == 0 );
02469             fct_chk( mpi_read_string( &ctx.E, 16, "11" ) == 0 );
02470         
02471             fct_chk( rsa_check_pubkey( &ctx ) == 0 );
02472         
02473             msg_len = unhexify( message_str, "d0cd038c65b3acca45822eaf91ea5176e82043268876dec0b62e2abd619023b7023abc67c6b823cfef5447b8772f985ff7910d6cc87e6c23688ac6de1fee40bbe2da1a92770de92adaa427ace02fee571a0a0176fceb0c8f3eb72dde839ab201395625f5c0db8641ce19d7711212dec61733262c6ce4476c025e67a3d5bc01f3" );
02474             unhexify( result_str, "2f30629c1117d013bb36e6099dee931dcaf0a1032b07ec23e2b262898a8945e569c9573d81e22bb0a5f8a28b0d7b8ff01367dd7f089c68ed1daa11cf53a96ee91b38e6b839b6e90bea34d14b78f5d2c7629b68c5b4f2ecfff66b483b2233cb14f95df533c867a2b610aebcdbb7ea3109aaf2f5762ab3edc2571deccc7da0c9a5b443ca2b924c0f18de7bbb736a08fed3916795018a436a3ae62c85d554a53a6d48623908e06e7d275f4251d3b3bd530bd11e155dcf2b5c2adf030cdf931ae749" );
02475         
02476             switch( SIG_RSA_SHA512 )
02477             {
02478         #ifdef POLARSSL_MD2_C
02479             case SIG_RSA_MD2:
02480                 md2( message_str, msg_len, hash_result );
02481                 break;
02482         #endif
02483         #ifdef POLARSSL_MD4_C
02484             case SIG_RSA_MD4:
02485                 md4( message_str, msg_len, hash_result );
02486                 break;
02487         #endif
02488         #ifdef POLARSSL_MD5_C
02489             case SIG_RSA_MD5:
02490                 md5( message_str, msg_len, hash_result );
02491                 break;
02492         #endif
02493         #ifdef POLARSSL_SHA1_C
02494             case SIG_RSA_SHA1:
02495                 sha1( message_str, msg_len, hash_result );
02496                 break;
02497         #endif
02498         #ifdef POLARSSL_SHA2_C
02499             case SIG_RSA_SHA224:
02500                 sha2( message_str, msg_len, hash_result, 1 );
02501                 break;
02502             case SIG_RSA_SHA256:
02503                 sha2( message_str, msg_len, hash_result, 0 );
02504                 break;
02505         #endif
02506         #ifdef POLARSSL_SHA4_C
02507             case SIG_RSA_SHA384:
02508                 sha4( message_str, msg_len, hash_result, 1 );
02509                 break;
02510             case SIG_RSA_SHA512:
02511                 sha4( message_str, msg_len, hash_result, 0 );
02512                 break;
02513         #endif
02514             }
02515         
02516             fct_chk( rsa_pkcs1_verify( &ctx, RSA_PUBLIC, SIG_RSA_SHA512, 0, hash_result, result_str ) == POLARSSL_ERR_RSA_INVALID_PADDING );
02517         }
02518         FCT_TEST_END();
02519 #endif /* POLARSSL_SHA4_C */
02520 
02521 #ifdef POLARSSL_SHA4_C
02522 
02523         FCT_TEST_BGN(rsa_pkcs1_verify_v15_cavs_34)
02524         {
02525             unsigned char message_str[1000];
02526             unsigned char hash_result[1000];
02527             unsigned char result_str[1000];
02528             rsa_context ctx;
02529             int msg_len;
02530         
02531             rsa_init( &ctx, RSA_PKCS_V15, 0 );
02532             memset( message_str, 0x00, 1000 );
02533             memset( hash_result, 0x00, 1000 );
02534             memset( result_str, 0x00, 1000 );
02535         
02536             ctx.len = 1536 / 8;
02537             fct_chk( mpi_read_string( &ctx.N, 16, "a59d9b7269b102b7be684ec5e28db79992e6d3231e77c90b78960c2638b35ef6dbdac1ac59e7249d96d426e7f99397eabc6b8903fe1942da580322b98bafacd81bb911c29666f83886a2a2864f3552044300e60cedd5a8c321c43e280413dc41673c39a11b98a885486f8187a70f270185c4c12bc48a1968305269776c070ef69d4913589a887c4d0f5e7dd58bd806d0d49a14a1762c38665cef4646ff13a0cd29c3a60460703c3d051d5b28c660bffb5f8bd43d495ffa64175f72b8abe5fddd" ) == 0 );
02538             fct_chk( mpi_read_string( &ctx.E, 16, "11" ) == 0 );
02539         
02540             fct_chk( rsa_check_pubkey( &ctx ) == 0 );
02541         
02542             msg_len = unhexify( message_str, "59779fd2a39e56640c4fc1e67b60aeffcecd78aed7ad2bdfa464e93d04198d48466b8da7445f25bfa19db2844edd5c8f539cf772cc132b483169d390db28a43bc4ee0f038f6568ffc87447746cb72fefac2d6d90ee3143a915ac4688028805905a68eb8f8a96674b093c495eddd8704461eaa2b345efbb2ad6930acd8023f870" );
02543             unhexify( result_str, "0b4d96f411c727a262d6d0ade34195b78603551061917d060f89add47b09dfe8715f4f9147d327dc25e91fe457e5d1a2f22cd8fe6fe8e29d2060658307c87a40640650fef3d4b289a6c3febc5a100b29a8b56623afb29fd3c13ea372bf3c638c1db25f8bd8c74c821beec7b5affcace1d05d056a6c2d3035926c7a268df4751a54bc20a6b8cfd729a7cba309ae817daccbef9950a482cf23950a8ca1d3a13ddb7d8d0f87ad5587d4d9ebe19fe93457597a7bdd056c2fd4cea7d31e4a0e595a7b" );
02544         
02545             switch( SIG_RSA_SHA512 )
02546             {
02547         #ifdef POLARSSL_MD2_C
02548             case SIG_RSA_MD2:
02549                 md2( message_str, msg_len, hash_result );
02550                 break;
02551         #endif
02552         #ifdef POLARSSL_MD4_C
02553             case SIG_RSA_MD4:
02554                 md4( message_str, msg_len, hash_result );
02555                 break;
02556         #endif
02557         #ifdef POLARSSL_MD5_C
02558             case SIG_RSA_MD5:
02559                 md5( message_str, msg_len, hash_result );
02560                 break;
02561         #endif
02562         #ifdef POLARSSL_SHA1_C
02563             case SIG_RSA_SHA1:
02564                 sha1( message_str, msg_len, hash_result );
02565                 break;
02566         #endif
02567         #ifdef POLARSSL_SHA2_C
02568             case SIG_RSA_SHA224:
02569                 sha2( message_str, msg_len, hash_result, 1 );
02570                 break;
02571             case SIG_RSA_SHA256:
02572                 sha2( message_str, msg_len, hash_result, 0 );
02573                 break;
02574         #endif
02575         #ifdef POLARSSL_SHA4_C
02576             case SIG_RSA_SHA384:
02577                 sha4( message_str, msg_len, hash_result, 1 );
02578                 break;
02579             case SIG_RSA_SHA512:
02580                 sha4( message_str, msg_len, hash_result, 0 );
02581                 break;
02582         #endif
02583             }
02584         
02585             fct_chk( rsa_pkcs1_verify( &ctx, RSA_PUBLIC, SIG_RSA_SHA512, 0, hash_result, result_str ) == 0 );
02586         }
02587         FCT_TEST_END();
02588 #endif /* POLARSSL_SHA4_C */
02589 
02590 #ifdef POLARSSL_SHA4_C
02591 
02592         FCT_TEST_BGN(rsa_pkcs1_sign_1_sha512_1536_bits_rsa)
02593         {
02594             unsigned char message_str[1000];
02595             unsigned char hash_result[1000];
02596             unsigned char output[1000];
02597             unsigned char output_str[1000];
02598             rsa_context ctx;
02599             mpi P1, Q1, H, G;
02600             int msg_len;
02601         
02602             mpi_init( &P1 ); mpi_init( &Q1 ); mpi_init( &H ); mpi_init( &G );
02603             rsa_init( &ctx, RSA_PKCS_V15, 0 );
02604         
02605             memset( message_str, 0x00, 1000 );
02606             memset( hash_result, 0x00, 1000 );
02607             memset( output, 0x00, 1000 );
02608             memset( output_str, 0x00, 1000 );
02609         
02610             ctx.len = 1536 / 8;
02611             fct_chk( mpi_read_string( &ctx.P, 16, "c8c67df894c882045ede26a9008ab09ea0672077d7bc71d412511cd93981ddde8f91b967da404056c39f105f7f239abdaff92923859920f6299e82b95bd5b8c959948f4a035cbd693ad83014294d349813d1ad57911a6355d0731fe3a034e9db" ) == 0 );
02612             fct_chk( mpi_read_string( &ctx.Q, 16, "f15147d0e7c04a1e3f37adde802cdc610999bf7ab0088434aaeda0c0ab3910b14d2ce56cb66bffd97552195fae8b061077e03920814d8b9cfb5a3958b3a82c2a7fc97e55db5978b47a922156eb8a3e55c06a54a45d1670abdfb995489c4d0051" ) == 0 );
02613             fct_chk( mpi_read_string( &ctx.N, 16, "bd429bb7c3b00bbea19ba664c0f8172d1a73c3cfa05e2ed656d570c1590918bb7e372ed25e2cd71395ba0a9b1a30f3ee012ffb0546cab8e3581fe3e23f44ab57a8aee9717e71a936a580fa8572d450fb00339a6f6704b717df0c149a465bab768c61500cd93b61113ff3e4389167f7b2c8e3c0da2d4765286bee555b0bcb4998f59b14fad03180a17c8b4f69bcd1234f4ae85950137665ac2ba80b55cc9b1aafb454b83771aa755acd2a00e93ddb65e696dbed8bdca69fb5e0c5c2097b9cfe4b" ) == 0 );
02614             fct_chk( mpi_read_string( &ctx.E, 16, "3" ) == 0 );
02615         
02616             fct_chk( mpi_sub_int( &P1, &ctx.P, 1 ) == 0 );
02617             fct_chk( mpi_sub_int( &Q1, &ctx.Q, 1 ) == 0 );
02618             fct_chk( mpi_mul_mpi( &H, &P1, &Q1 ) == 0 );
02619             fct_chk( mpi_gcd( &G, &ctx.E, &H  ) == 0 );
02620             fct_chk( mpi_inv_mod( &ctx.D , &ctx.E, &H  ) == 0 );
02621             fct_chk( mpi_mod_mpi( &ctx.DP, &ctx.D, &P1 ) == 0 );
02622             fct_chk( mpi_mod_mpi( &ctx.DQ, &ctx.D, &Q1 ) == 0 );
02623             fct_chk( mpi_inv_mod( &ctx.QP, &ctx.Q, &ctx.P ) == 0 );
02624         
02625             fct_chk( rsa_check_privkey( &ctx ) == 0 );
02626         
02627             msg_len = unhexify( message_str, "59779fd2a39e56640c4fc1e67b60aeffcecd78aed7ad2bdfa464e93d04198d48466b8da7445f25bfa19db2844edd5c8f539cf772cc132b483169d390db28a43bc4ee0f038f6568ffc87447746cb72fefac2d6d90ee3143a915ac4688028805905a68eb8f8a96674b093c495eddd8704461eaa2b345efbb2ad6930acd8023f870" );
02628         
02629             switch( SIG_RSA_SHA512 )
02630             {
02631         #ifdef POLARSSL_MD2_C
02632             case SIG_RSA_MD2:
02633                 md2( message_str, msg_len, hash_result );
02634                 break;
02635         #endif
02636         #ifdef POLARSSL_MD4_C
02637             case SIG_RSA_MD4:
02638                 md4( message_str, msg_len, hash_result );
02639                 break;
02640         #endif
02641         #ifdef POLARSSL_MD5_C
02642             case SIG_RSA_MD5:
02643                 md5( message_str, msg_len, hash_result );
02644                 break;
02645         #endif
02646         #ifdef POLARSSL_SHA1_C
02647             case SIG_RSA_SHA1:
02648                 sha1( message_str, msg_len, hash_result );
02649                 break;
02650         #endif
02651         #ifdef POLARSSL_SHA2_C
02652             case SIG_RSA_SHA224:
02653                 sha2( message_str, msg_len, hash_result, 1 );
02654                 break;
02655             case SIG_RSA_SHA256:
02656                 sha2( message_str, msg_len, hash_result, 0 );
02657                 break;
02658         #endif
02659         #ifdef POLARSSL_SHA4_C
02660             case SIG_RSA_SHA384:
02661                 sha4( message_str, msg_len, hash_result, 1 );
02662                 break;
02663             case SIG_RSA_SHA512:
02664                 sha4( message_str, msg_len, hash_result, 0 );
02665                 break;
02666         #endif
02667             }
02668         
02669             fct_chk( rsa_pkcs1_sign( &ctx, NULL, NULL, RSA_PRIVATE, SIG_RSA_SHA512, 0, hash_result, output ) == 0 );
02670             if( 0 == 0 )
02671             {
02672                 hexify( output_str, output, ctx.len );
02673         
02674                 fct_chk( strcasecmp( (char *) output_str, "93b6fa99485c116ca6efdd4202ea1cf49f4c6345fae692584413743ce5b65510e8e4690aee9a19ea1ff10d57f22aa3548d839f28a8525a34354e9e58e0f3947e056ce2554e21bf287e220b98db3b551258cd42b495e5d1a3bbc83c9d1a02f2a300ef6d866ea75108e44ebb3e16b47df2f6de28feb2be3874dbbf21599451082d86e9f2f462575a8185c69aa1f1fcb6a363c5d71aeba2103449eaf3845285291148d5f78d1646b8dc95cbcc4082f987d948b0e7d4e80b60595f8a7517584e1643" ) == 0 );
02675             }
02676         
02677             mpi_free( &P1 ); mpi_free( &Q1 ); mpi_free( &H ); mpi_free( &G );
02678         }
02679         FCT_TEST_END();
02680 #endif /* POLARSSL_SHA4_C */
02681 
02682 #ifdef POLARSSL_SHA4_C
02683 
02684         FCT_TEST_BGN(rsa_pkcs1_sign_1_verify)
02685         {
02686             unsigned char message_str[1000];
02687             unsigned char hash_result[1000];
02688             unsigned char result_str[1000];
02689             rsa_context ctx;
02690             int msg_len;
02691         
02692             rsa_init( &ctx, RSA_PKCS_V15, 0 );
02693             memset( message_str, 0x00, 1000 );
02694             memset( hash_result, 0x00, 1000 );
02695             memset( result_str, 0x00, 1000 );
02696         
02697             ctx.len = 1536 / 8;
02698             fct_chk( mpi_read_string( &ctx.N, 16, "bd429bb7c3b00bbea19ba664c0f8172d1a73c3cfa05e2ed656d570c1590918bb7e372ed25e2cd71395ba0a9b1a30f3ee012ffb0546cab8e3581fe3e23f44ab57a8aee9717e71a936a580fa8572d450fb00339a6f6704b717df0c149a465bab768c61500cd93b61113ff3e4389167f7b2c8e3c0da2d4765286bee555b0bcb4998f59b14fad03180a17c8b4f69bcd1234f4ae85950137665ac2ba80b55cc9b1aafb454b83771aa755acd2a00e93ddb65e696dbed8bdca69fb5e0c5c2097b9cfe4b" ) == 0 );
02699             fct_chk( mpi_read_string( &ctx.E, 16, "3" ) == 0 );
02700         
02701             fct_chk( rsa_check_pubkey( &ctx ) == 0 );
02702         
02703             msg_len = unhexify( message_str, "59779fd2a39e56640c4fc1e67b60aeffcecd78aed7ad2bdfa464e93d04198d48466b8da7445f25bfa19db2844edd5c8f539cf772cc132b483169d390db28a43bc4ee0f038f6568ffc87447746cb72fefac2d6d90ee3143a915ac4688028805905a68eb8f8a96674b093c495eddd8704461eaa2b345efbb2ad6930acd8023f870" );
02704             unhexify( result_str, "93b6fa99485c116ca6efdd4202ea1cf49f4c6345fae692584413743ce5b65510e8e4690aee9a19ea1ff10d57f22aa3548d839f28a8525a34354e9e58e0f3947e056ce2554e21bf287e220b98db3b551258cd42b495e5d1a3bbc83c9d1a02f2a300ef6d866ea75108e44ebb3e16b47df2f6de28feb2be3874dbbf21599451082d86e9f2f462575a8185c69aa1f1fcb6a363c5d71aeba2103449eaf3845285291148d5f78d1646b8dc95cbcc4082f987d948b0e7d4e80b60595f8a7517584e1643" );
02705         
02706             switch( SIG_RSA_SHA512 )
02707             {
02708         #ifdef POLARSSL_MD2_C
02709             case SIG_RSA_MD2:
02710                 md2( message_str, msg_len, hash_result );
02711                 break;
02712         #endif
02713         #ifdef POLARSSL_MD4_C
02714             case SIG_RSA_MD4:
02715                 md4( message_str, msg_len, hash_result );
02716                 break;
02717         #endif
02718         #ifdef POLARSSL_MD5_C
02719             case SIG_RSA_MD5:
02720                 md5( message_str, msg_len, hash_result );
02721                 break;
02722         #endif
02723         #ifdef POLARSSL_SHA1_C
02724             case SIG_RSA_SHA1:
02725                 sha1( message_str, msg_len, hash_result );
02726                 break;
02727         #endif
02728         #ifdef POLARSSL_SHA2_C
02729             case SIG_RSA_SHA224:
02730                 sha2( message_str, msg_len, hash_result, 1 );
02731                 break;
02732             case SIG_RSA_SHA256:
02733                 sha2( message_str, msg_len, hash_result, 0 );
02734                 break;
02735         #endif
02736         #ifdef POLARSSL_SHA4_C
02737             case SIG_RSA_SHA384:
02738                 sha4( message_str, msg_len, hash_result, 1 );
02739                 break;
02740             case SIG_RSA_SHA512:
02741                 sha4( message_str, msg_len, hash_result, 0 );
02742                 break;
02743         #endif
02744             }
02745         
02746             fct_chk( rsa_pkcs1_verify( &ctx, RSA_PUBLIC, SIG_RSA_SHA512, 0, hash_result, result_str ) == 0 );
02747         }
02748         FCT_TEST_END();
02749 #endif /* POLARSSL_SHA4_C */
02750 
02751 #ifdef POLARSSL_SHA2_C
02752 
02753         FCT_TEST_BGN(rsa_pkcs1_sign_2_sha256_2048_bits_rsa)
02754         {
02755             unsigned char message_str[1000];
02756             unsigned char hash_result[1000];
02757             unsigned char output[1000];
02758             unsigned char output_str[1000];
02759             rsa_context ctx;
02760             mpi P1, Q1, H, G;
02761             int msg_len;
02762         
02763             mpi_init( &P1 ); mpi_init( &Q1 ); mpi_init( &H ); mpi_init( &G );
02764             rsa_init( &ctx, RSA_PKCS_V15, 0 );
02765         
02766             memset( message_str, 0x00, 1000 );
02767             memset( hash_result, 0x00, 1000 );
02768             memset( output, 0x00, 1000 );
02769             memset( output_str, 0x00, 1000 );
02770         
02771             ctx.len = 2048 / 8;
02772             fct_chk( mpi_read_string( &ctx.P, 16, "e79a373182bfaa722eb035f772ad2a9464bd842de59432c18bbab3a7dfeae318c9b915ee487861ab665a40bd6cda560152578e8579016c929df99fea05b4d64efca1d543850bc8164b40d71ed7f3fa4105df0fb9b9ad2a18ce182c8a4f4f975bea9aa0b9a1438a27a28e97ac8330ef37383414d1bd64607d6979ac050424fd17" ) == 0 );
02773             fct_chk( mpi_read_string( &ctx.Q, 16, "c6749cbb0db8c5a177672d4728a8b22392b2fc4d3b8361d5c0d5055a1b4e46d821f757c24eef2a51c561941b93b3ace7340074c058c9bb48e7e7414f42c41da4cccb5c2ba91deb30c586b7fb18af12a52995592ad139d3be429add6547e044becedaf31fa3b39421e24ee034fbf367d11f6b8f88ee483d163b431e1654ad3e89" ) == 0 );
02774             fct_chk( mpi_read_string( &ctx.N, 16, "b38ac65c8141f7f5c96e14470e851936a67bf94cc6821a39ac12c05f7c0b06d9e6ddba2224703b02e25f31452f9c4a8417b62675fdc6df46b94813bc7b9769a892c482b830bfe0ad42e46668ace68903617faf6681f4babf1cc8e4b0420d3c7f61dc45434c6b54e2c3ee0fc07908509d79c9826e673bf8363255adb0add2401039a7bcd1b4ecf0fbe6ec8369d2da486eec59559dd1d54c9b24190965eafbdab203b35255765261cd0909acf93c3b8b8428cbb448de4715d1b813d0c94829c229543d391ce0adab5351f97a3810c1f73d7b1458b97daed4209c50e16d064d2d5bfda8c23893d755222793146d0a78c3d64f35549141486c3b0961a7b4c1a2034f" ) == 0 );
02775             fct_chk( mpi_read_string( &ctx.E, 16, "3" ) == 0 );
02776         
02777             fct_chk( mpi_sub_int( &P1, &ctx.P, 1 ) == 0 );
02778             fct_chk( mpi_sub_int( &Q1, &ctx.Q, 1 ) == 0 );
02779             fct_chk( mpi_mul_mpi( &H, &P1, &Q1 ) == 0 );
02780             fct_chk( mpi_gcd( &G, &ctx.E, &H  ) == 0 );
02781             fct_chk( mpi_inv_mod( &ctx.D , &ctx.E, &H  ) == 0 );
02782             fct_chk( mpi_mod_mpi( &ctx.DP, &ctx.D, &P1 ) == 0 );
02783             fct_chk( mpi_mod_mpi( &ctx.DQ, &ctx.D, &Q1 ) == 0 );
02784             fct_chk( mpi_inv_mod( &ctx.QP, &ctx.Q, &ctx.P ) == 0 );
02785         
02786             fct_chk( rsa_check_privkey( &ctx ) == 0 );
02787         
02788             msg_len = unhexify( message_str, "59779fd2a39e56640c4fc1e67b60aeffcecd78aed7ad2bdfa464e93d04198d48466b8da7445f25bfa19db2844edd5c8f539cf772cc132b483169d390db28a43bc4ee0f038f6568ffc87447746cb72fefac2d6d90ee3143a915ac4688028805905a68eb8f8a96674b093c495eddd8704461eaa2b345efbb2ad6930acd8023f870" );
02789         
02790             switch( SIG_RSA_SHA256 )
02791             {
02792         #ifdef POLARSSL_MD2_C
02793             case SIG_RSA_MD2:
02794                 md2( message_str, msg_len, hash_result );
02795                 break;
02796         #endif
02797         #ifdef POLARSSL_MD4_C
02798             case SIG_RSA_MD4:
02799                 md4( message_str, msg_len, hash_result );
02800                 break;
02801         #endif
02802         #ifdef POLARSSL_MD5_C
02803             case SIG_RSA_MD5:
02804                 md5( message_str, msg_len, hash_result );
02805                 break;
02806         #endif
02807         #ifdef POLARSSL_SHA1_C
02808             case SIG_RSA_SHA1:
02809                 sha1( message_str, msg_len, hash_result );
02810                 break;
02811         #endif
02812         #ifdef POLARSSL_SHA2_C
02813             case SIG_RSA_SHA224:
02814                 sha2( message_str, msg_len, hash_result, 1 );
02815                 break;
02816             case SIG_RSA_SHA256:
02817                 sha2( message_str, msg_len, hash_result, 0 );
02818                 break;
02819         #endif
02820         #ifdef POLARSSL_SHA4_C
02821             case SIG_RSA_SHA384:
02822                 sha4( message_str, msg_len, hash_result, 1 );
02823                 break;
02824             case SIG_RSA_SHA512:
02825                 sha4( message_str, msg_len, hash_result, 0 );
02826                 break;
02827         #endif
02828             }
02829         
02830             fct_chk( rsa_pkcs1_sign( &ctx, NULL, NULL, RSA_PRIVATE, SIG_RSA_SHA256, 0, hash_result, output ) == 0 );
02831             if( 0 == 0 )
02832             {
02833                 hexify( output_str, output, ctx.len );
02834         
02835                 fct_chk( strcasecmp( (char *) output_str, "5aee2b9dbc02a6a2d87ff64a64165dc0b9ce70c79bab2d287939e2601c3223e0493988d5468731ae4edc7d5f5d449335c204fdb0e192c1915c9d694d3a61c3be14df79c4b34d6ac73707829024d263c94f9107fa93f3783de3965522336e18d1e01a142b5103451bb97839eaf2f44703a63050a36b78aef4072ea1a8daaaf1a2918fc03ee957a9c09efdc7287bcb4d6aec4723290294b249b3e3dc63157b560ad9c867323a73ebeb360cc9e482111643b0d86c4e33dcf170155590f0eba7d170789e84de336b7fe2f6cf485ddca94607a4ff379fc49d375c730249dd1a210e7dccd762d1c23c7532e769c6aa88e38e8654ff90f7b34df4c07ba90e89099ec1ed" ) == 0 );
02836             }
02837         
02838             mpi_free( &P1 ); mpi_free( &Q1 ); mpi_free( &H ); mpi_free( &G );
02839         }
02840         FCT_TEST_END();
02841 #endif /* POLARSSL_SHA2_C */
02842 
02843 #ifdef POLARSSL_SHA2_C
02844 
02845         FCT_TEST_BGN(rsa_pkcs1_sign_2_verify)
02846         {
02847             unsigned char message_str[1000];
02848             unsigned char hash_result[1000];
02849             unsigned char result_str[1000];
02850             rsa_context ctx;
02851             int msg_len;
02852         
02853             rsa_init( &ctx, RSA_PKCS_V15, 0 );
02854             memset( message_str, 0x00, 1000 );
02855             memset( hash_result, 0x00, 1000 );
02856             memset( result_str, 0x00, 1000 );
02857         
02858             ctx.len = 2048 / 8;
02859             fct_chk( mpi_read_string( &ctx.N, 16, "b38ac65c8141f7f5c96e14470e851936a67bf94cc6821a39ac12c05f7c0b06d9e6ddba2224703b02e25f31452f9c4a8417b62675fdc6df46b94813bc7b9769a892c482b830bfe0ad42e46668ace68903617faf6681f4babf1cc8e4b0420d3c7f61dc45434c6b54e2c3ee0fc07908509d79c9826e673bf8363255adb0add2401039a7bcd1b4ecf0fbe6ec8369d2da486eec59559dd1d54c9b24190965eafbdab203b35255765261cd0909acf93c3b8b8428cbb448de4715d1b813d0c94829c229543d391ce0adab5351f97a3810c1f73d7b1458b97daed4209c50e16d064d2d5bfda8c23893d755222793146d0a78c3d64f35549141486c3b0961a7b4c1a2034f" ) == 0 );
02860             fct_chk( mpi_read_string( &ctx.E, 16, "3" ) == 0 );
02861         
02862             fct_chk( rsa_check_pubkey( &ctx ) == 0 );
02863         
02864             msg_len = unhexify( message_str, "59779fd2a39e56640c4fc1e67b60aeffcecd78aed7ad2bdfa464e93d04198d48466b8da7445f25bfa19db2844edd5c8f539cf772cc132b483169d390db28a43bc4ee0f038f6568ffc87447746cb72fefac2d6d90ee3143a915ac4688028805905a68eb8f8a96674b093c495eddd8704461eaa2b345efbb2ad6930acd8023f870" );
02865             unhexify( result_str, "5aee2b9dbc02a6a2d87ff64a64165dc0b9ce70c79bab2d287939e2601c3223e0493988d5468731ae4edc7d5f5d449335c204fdb0e192c1915c9d694d3a61c3be14df79c4b34d6ac73707829024d263c94f9107fa93f3783de3965522336e18d1e01a142b5103451bb97839eaf2f44703a63050a36b78aef4072ea1a8daaaf1a2918fc03ee957a9c09efdc7287bcb4d6aec4723290294b249b3e3dc63157b560ad9c867323a73ebeb360cc9e482111643b0d86c4e33dcf170155590f0eba7d170789e84de336b7fe2f6cf485ddca94607a4ff379fc49d375c730249dd1a210e7dccd762d1c23c7532e769c6aa88e38e8654ff90f7b34df4c07ba90e89099ec1ed" );
02866         
02867             switch( SIG_RSA_SHA256 )
02868             {
02869         #ifdef POLARSSL_MD2_C
02870             case SIG_RSA_MD2:
02871                 md2( message_str, msg_len, hash_result );
02872                 break;
02873         #endif
02874         #ifdef POLARSSL_MD4_C
02875             case SIG_RSA_MD4:
02876                 md4( message_str, msg_len, hash_result );
02877                 break;
02878         #endif
02879         #ifdef POLARSSL_MD5_C
02880             case SIG_RSA_MD5:
02881                 md5( message_str, msg_len, hash_result );
02882                 break;
02883         #endif
02884         #ifdef POLARSSL_SHA1_C
02885             case SIG_RSA_SHA1:
02886                 sha1( message_str, msg_len, hash_result );
02887                 break;
02888         #endif
02889         #ifdef POLARSSL_SHA2_C
02890             case SIG_RSA_SHA224:
02891                 sha2( message_str, msg_len, hash_result, 1 );
02892                 break;
02893             case SIG_RSA_SHA256:
02894                 sha2( message_str, msg_len, hash_result, 0 );
02895                 break;
02896         #endif
02897         #ifdef POLARSSL_SHA4_C
02898             case SIG_RSA_SHA384:
02899                 sha4( message_str, msg_len, hash_result, 1 );
02900                 break;
02901             case SIG_RSA_SHA512:
02902                 sha4( message_str, msg_len, hash_result, 0 );
02903                 break;
02904         #endif
02905             }
02906         
02907             fct_chk( rsa_pkcs1_verify( &ctx, RSA_PUBLIC, SIG_RSA_SHA256, 0, hash_result, result_str ) == 0 );
02908         }
02909         FCT_TEST_END();
02910 #endif /* POLARSSL_SHA2_C */
02911 
02912 #ifdef POLARSSL_SHA2_C
02913 
02914         FCT_TEST_BGN(rsa_pkcs1_sign_2_verify_fail)
02915         {
02916             unsigned char message_str[1000];
02917             unsigned char hash_result[1000];
02918             unsigned char result_str[1000];
02919             rsa_context ctx;
02920             int msg_len;
02921         
02922             rsa_init( &ctx, RSA_PKCS_V15, 0 );
02923             memset( message_str, 0x00, 1000 );
02924             memset( hash_result, 0x00, 1000 );
02925             memset( result_str, 0x00, 1000 );
02926         
02927             ctx.len = 2048 / 8;
02928             fct_chk( mpi_read_string( &ctx.N, 16, "b38ac65c8141f7f5c96e14470e851936a67bf94cc6821a39ac12c05f7c0b06d9e6ddba2224703b02e25f31452f9c4a8417b62675fdc6df46b94813bc7b9769a892c482b830bfe0ad42e46668ace68903617faf6681f4babf1cc8e4b0420d3c7f61dc45434c6b54e2c3ee0fc07908509d79c9826e673bf8363255adb0add2401039a7bcd1b4ecf0fbe6ec8369d2da486eec59559dd1d54c9b24190965eafbdab203b35255765261cd0909acf93c3b8b8428cbb448de4715d1b813d0c94829c229543d391ce0adab5351f97a3810c1f73d7b1458b97daed4209c50e16d064d2d5bfda8c23893d755222793146d0a78c3d64f35549141486c3b0961a7b4c1a2034f" ) == 0 );
02929             fct_chk( mpi_read_string( &ctx.E, 16, "3" ) == 0 );
02930         
02931             fct_chk( rsa_check_pubkey( &ctx ) == 0 );
02932         
02933             msg_len = unhexify( message_str, "59779fd2a39e56640c4fc1e67b60aeffcecd78aed7ad2bdfa464e93d04198d48466b8da7445f25bfa19db2844edd5c8f539cf772cc132b483169d390db28a43bc4ee0f038f6568ffc87447746cb72fefac2d6d90ee3143a915ac4688028805905a68eb8f8a96674b093c495eddd8704461eaa2b345efbb2ad6930acd8023f870" );
02934             unhexify( result_str, "5aee2b9dbc02a6a2d87ff64a64165dc0b9ce70c79bab2d287939e2601c3223e0493988d5468731ae4edc7d5f5d449335c204fdb0e192c1915c9d694d3a61c3be14df79c4b34d6ac73707829024d263c94f9107fa93f3783de3965522336e18d1e01a142b5103451bb97839eaf2f44703a63050a36b78aef4072ea1a8daaaf1a2918fc03ee957a9c09efdc6287bcb4d6aec4723290294b249b3e3dc63157b560ad9c867323a73ebeb360cc9e482111643b0d86c4e33dcf170155590f0eba7d170789e84de336b7fe2f6cf485ddca94607a4ff379fc49d375c730249dd1a210e7dccd763d1c23c7532e769c6aa88e38e8654ff90f7b34df4c07ba90e89099ec1ed" );
02935         
02936             switch( SIG_RSA_SHA256 )
02937             {
02938         #ifdef POLARSSL_MD2_C
02939             case SIG_RSA_MD2:
02940                 md2( message_str, msg_len, hash_result );
02941                 break;
02942         #endif
02943         #ifdef POLARSSL_MD4_C
02944             case SIG_RSA_MD4:
02945                 md4( message_str, msg_len, hash_result );
02946                 break;
02947         #endif
02948         #ifdef POLARSSL_MD5_C
02949             case SIG_RSA_MD5:
02950                 md5( message_str, msg_len, hash_result );
02951                 break;
02952         #endif
02953         #ifdef POLARSSL_SHA1_C
02954             case SIG_RSA_SHA1:
02955                 sha1( message_str, msg_len, hash_result );
02956                 break;
02957         #endif
02958         #ifdef POLARSSL_SHA2_C
02959             case SIG_RSA_SHA224:
02960                 sha2( message_str, msg_len, hash_result, 1 );
02961                 break;
02962             case SIG_RSA_SHA256:
02963                 sha2( message_str, msg_len, hash_result, 0 );
02964                 break;
02965         #endif
02966         #ifdef POLARSSL_SHA4_C
02967             case SIG_RSA_SHA384:
02968                 sha4( message_str, msg_len, hash_result, 1 );
02969                 break;
02970             case SIG_RSA_SHA512:
02971                 sha4( message_str, msg_len, hash_result, 0 );
02972                 break;
02973         #endif
02974             }
02975         
02976             fct_chk( rsa_pkcs1_verify( &ctx, RSA_PUBLIC, SIG_RSA_SHA256, 0, hash_result, result_str ) == POLARSSL_ERR_RSA_INVALID_PADDING );
02977         }
02978         FCT_TEST_END();
02979 #endif /* POLARSSL_SHA2_C */
02980 
02981 #ifdef POLARSSL_SHA2_C
02982 
02983         FCT_TEST_BGN(rsa_pkcs1_sign_3_sha224_2048_bits_rsa)
02984         {
02985             unsigned char message_str[1000];
02986             unsigned char hash_result[1000];
02987             unsigned char output[1000];
02988             unsigned char output_str[1000];
02989             rsa_context ctx;
02990             mpi P1, Q1, H, G;
02991             int msg_len;
02992         
02993             mpi_init( &P1 ); mpi_init( &Q1 ); mpi_init( &H ); mpi_init( &G );
02994             rsa_init( &ctx, RSA_PKCS_V15, 0 );
02995         
02996             memset( message_str, 0x00, 1000 );
02997             memset( hash_result, 0x00, 1000 );
02998             memset( output, 0x00, 1000 );
02999             memset( output_str, 0x00, 1000 );
03000         
03001             ctx.len = 2048 / 8;
03002             fct_chk( mpi_read_string( &ctx.P, 16, "e79a373182bfaa722eb035f772ad2a9464bd842de59432c18bbab3a7dfeae318c9b915ee487861ab665a40bd6cda560152578e8579016c929df99fea05b4d64efca1d543850bc8164b40d71ed7f3fa4105df0fb9b9ad2a18ce182c8a4f4f975bea9aa0b9a1438a27a28e97ac8330ef37383414d1bd64607d6979ac050424fd17" ) == 0 );
03003             fct_chk( mpi_read_string( &ctx.Q, 16, "c6749cbb0db8c5a177672d4728a8b22392b2fc4d3b8361d5c0d5055a1b4e46d821f757c24eef2a51c561941b93b3ace7340074c058c9bb48e7e7414f42c41da4cccb5c2ba91deb30c586b7fb18af12a52995592ad139d3be429add6547e044becedaf31fa3b39421e24ee034fbf367d11f6b8f88ee483d163b431e1654ad3e89" ) == 0 );
03004             fct_chk( mpi_read_string( &ctx.N, 16, "b38ac65c8141f7f5c96e14470e851936a67bf94cc6821a39ac12c05f7c0b06d9e6ddba2224703b02e25f31452f9c4a8417b62675fdc6df46b94813bc7b9769a892c482b830bfe0ad42e46668ace68903617faf6681f4babf1cc8e4b0420d3c7f61dc45434c6b54e2c3ee0fc07908509d79c9826e673bf8363255adb0add2401039a7bcd1b4ecf0fbe6ec8369d2da486eec59559dd1d54c9b24190965eafbdab203b35255765261cd0909acf93c3b8b8428cbb448de4715d1b813d0c94829c229543d391ce0adab5351f97a3810c1f73d7b1458b97daed4209c50e16d064d2d5bfda8c23893d755222793146d0a78c3d64f35549141486c3b0961a7b4c1a2034f" ) == 0 );
03005             fct_chk( mpi_read_string( &ctx.E, 16, "3" ) == 0 );
03006         
03007             fct_chk( mpi_sub_int( &P1, &ctx.P, 1 ) == 0 );
03008             fct_chk( mpi_sub_int( &Q1, &ctx.Q, 1 ) == 0 );
03009             fct_chk( mpi_mul_mpi( &H, &P1, &Q1 ) == 0 );
03010             fct_chk( mpi_gcd( &G, &ctx.E, &H  ) == 0 );
03011             fct_chk( mpi_inv_mod( &ctx.D , &ctx.E, &H  ) == 0 );
03012             fct_chk( mpi_mod_mpi( &ctx.DP, &ctx.D, &P1 ) == 0 );
03013             fct_chk( mpi_mod_mpi( &ctx.DQ, &ctx.D, &Q1 ) == 0 );
03014             fct_chk( mpi_inv_mod( &ctx.QP, &ctx.Q, &ctx.P ) == 0 );
03015         
03016             fct_chk( rsa_check_privkey( &ctx ) == 0 );
03017         
03018             msg_len = unhexify( message_str, "59779fd2a39e56640c4fc1e67b60aeffcecd78aed7ad2bdfa464e93d04198d48466b8da7445f25bfa19db2844edd5c8f539cf772cc132b483169d390db28a43bc4ee0f038f6568ffc87447746cb72fefac2d6d90ee3143a915ac4688028805905a68eb8f8a96674b093c495eddd8704461eaa2b345efbb2ad6930acd8023f870" );
03019         
03020             switch( SIG_RSA_SHA224 )
03021             {
03022         #ifdef POLARSSL_MD2_C
03023             case SIG_RSA_MD2:
03024                 md2( message_str, msg_len, hash_result );
03025                 break;
03026         #endif
03027         #ifdef POLARSSL_MD4_C
03028             case SIG_RSA_MD4:
03029                 md4( message_str, msg_len, hash_result );
03030                 break;
03031         #endif
03032         #ifdef POLARSSL_MD5_C
03033             case SIG_RSA_MD5:
03034                 md5( message_str, msg_len, hash_result );
03035                 break;
03036         #endif
03037         #ifdef POLARSSL_SHA1_C
03038             case SIG_RSA_SHA1:
03039                 sha1( message_str, msg_len, hash_result );
03040                 break;
03041         #endif
03042         #ifdef POLARSSL_SHA2_C
03043             case SIG_RSA_SHA224:
03044                 sha2( message_str, msg_len, hash_result, 1 );
03045                 break;
03046             case SIG_RSA_SHA256:
03047                 sha2( message_str, msg_len, hash_result, 0 );
03048                 break;
03049         #endif
03050         #ifdef POLARSSL_SHA4_C
03051             case SIG_RSA_SHA384:
03052                 sha4( message_str, msg_len, hash_result, 1 );
03053                 break;
03054             case SIG_RSA_SHA512:
03055                 sha4( message_str, msg_len, hash_result, 0 );
03056                 break;
03057         #endif
03058             }
03059         
03060             fct_chk( rsa_pkcs1_sign( &ctx, NULL, NULL, RSA_PRIVATE, SIG_RSA_SHA224, 0, hash_result, output ) == 0 );
03061             if( 0 == 0 )
03062             {
03063                 hexify( output_str, output, ctx.len );
03064         
03065                 fct_chk( strcasecmp( (char *) output_str, "9d768b8b31421f9d9ced890aafaf8b3468656419049ed268f6e1992066f45dc3e4cd349e8c5ed5a06e4ef5badaba064ba94907dfedf3d708becaf44ae9b27c3866d329311ba93e8ddc7fc284fba05d1bb84fb1e060a5b76b7fa515cfcd2c8144474623672703cac1e15ff4fdf8ef19d365c51ba86e60f4cbbcd07f956060625751bfbecc47945646459cadaddd900603a8149a93b31a6d432e1da1a67eb765f5b2f0bd1adb9af12d731c7b02931b42dbbfd8c7cecde76b817e96f664147a2c5091c6ce4dc562c5f57159d6f9dc9ba2daa212db56677839621bd4805dde62955fb2d0cc2c448109d10ecc6206ea81f0a02e1646471358f3ec146cd3c75f2d390b" ) == 0 );
03066             }
03067         
03068             mpi_free( &P1 ); mpi_free( &Q1 ); mpi_free( &H ); mpi_free( &G );
03069         }
03070         FCT_TEST_END();
03071 #endif /* POLARSSL_SHA2_C */
03072 
03073 #ifdef POLARSSL_SHA2_C
03074 
03075         FCT_TEST_BGN(rsa_pkcs1_sign_3_verify)
03076         {
03077             unsigned char message_str[1000];
03078             unsigned char hash_result[1000];
03079             unsigned char result_str[1000];
03080             rsa_context ctx;
03081             int msg_len;
03082         
03083             rsa_init( &ctx, RSA_PKCS_V15, 0 );
03084             memset( message_str, 0x00, 1000 );
03085             memset( hash_result, 0x00, 1000 );
03086             memset( result_str, 0x00, 1000 );
03087         
03088             ctx.len = 2048 / 8;
03089             fct_chk( mpi_read_string( &ctx.N, 16, "b38ac65c8141f7f5c96e14470e851936a67bf94cc6821a39ac12c05f7c0b06d9e6ddba2224703b02e25f31452f9c4a8417b62675fdc6df46b94813bc7b9769a892c482b830bfe0ad42e46668ace68903617faf6681f4babf1cc8e4b0420d3c7f61dc45434c6b54e2c3ee0fc07908509d79c9826e673bf8363255adb0add2401039a7bcd1b4ecf0fbe6ec8369d2da486eec59559dd1d54c9b24190965eafbdab203b35255765261cd0909acf93c3b8b8428cbb448de4715d1b813d0c94829c229543d391ce0adab5351f97a3810c1f73d7b1458b97daed4209c50e16d064d2d5bfda8c23893d755222793146d0a78c3d64f35549141486c3b0961a7b4c1a2034f" ) == 0 );
03090             fct_chk( mpi_read_string( &ctx.E, 16, "3" ) == 0 );
03091         
03092             fct_chk( rsa_check_pubkey( &ctx ) == 0 );
03093         
03094             msg_len = unhexify( message_str, "59779fd2a39e56640c4fc1e67b60aeffcecd78aed7ad2bdfa464e93d04198d48466b8da7445f25bfa19db2844edd5c8f539cf772cc132b483169d390db28a43bc4ee0f038f6568ffc87447746cb72fefac2d6d90ee3143a915ac4688028805905a68eb8f8a96674b093c495eddd8704461eaa2b345efbb2ad6930acd8023f870" );
03095             unhexify( result_str, "9d768b8b31421f9d9ced890aafaf8b3468656419049ed268f6e1992066f45dc3e4cd349e8c5ed5a06e4ef5badaba064ba94907dfedf3d708becaf44ae9b27c3866d329311ba93e8ddc7fc284fba05d1bb84fb1e060a5b76b7fa515cfcd2c8144474623672703cac1e15ff4fdf8ef19d365c51ba86e60f4cbbcd07f956060625751bfbecc47945646459cadaddd900603a8149a93b31a6d432e1da1a67eb765f5b2f0bd1adb9af12d731c7b02931b42dbbfd8c7cecde76b817e96f664147a2c5091c6ce4dc562c5f57159d6f9dc9ba2daa212db56677839621bd4805dde62955fb2d0cc2c448109d10ecc6206ea81f0a02e1646471358f3ec146cd3c75f2d390b" );
03096         
03097             switch( SIG_RSA_SHA224 )
03098             {
03099         #ifdef POLARSSL_MD2_C
03100             case SIG_RSA_MD2:
03101                 md2( message_str, msg_len, hash_result );
03102                 break;
03103         #endif
03104         #ifdef POLARSSL_MD4_C
03105             case SIG_RSA_MD4:
03106                 md4( message_str, msg_len, hash_result );
03107                 break;
03108         #endif
03109         #ifdef POLARSSL_MD5_C
03110             case SIG_RSA_MD5:
03111                 md5( message_str, msg_len, hash_result );
03112                 break;
03113         #endif
03114         #ifdef POLARSSL_SHA1_C
03115             case SIG_RSA_SHA1:
03116                 sha1( message_str, msg_len, hash_result );
03117                 break;
03118         #endif
03119         #ifdef POLARSSL_SHA2_C
03120             case SIG_RSA_SHA224:
03121                 sha2( message_str, msg_len, hash_result, 1 );
03122                 break;
03123             case SIG_RSA_SHA256:
03124                 sha2( message_str, msg_len, hash_result, 0 );
03125                 break;
03126         #endif
03127         #ifdef POLARSSL_SHA4_C
03128             case SIG_RSA_SHA384:
03129                 sha4( message_str, msg_len, hash_result, 1 );
03130                 break;
03131             case SIG_RSA_SHA512:
03132                 sha4( message_str, msg_len, hash_result, 0 );
03133                 break;
03134         #endif
03135             }
03136         
03137             fct_chk( rsa_pkcs1_verify( &ctx, RSA_PUBLIC, SIG_RSA_SHA224, 0, hash_result, result_str ) == 0 );
03138         }
03139         FCT_TEST_END();
03140 #endif /* POLARSSL_SHA2_C */
03141 
03142 #ifdef POLARSSL_SHA4_C
03143 
03144         FCT_TEST_BGN(rsa_pkcs1_sign_4_sha384_2048_bits_rsa)
03145         {
03146             unsigned char message_str[1000];
03147             unsigned char hash_result[1000];
03148             unsigned char output[1000];
03149             unsigned char output_str[1000];
03150             rsa_context ctx;
03151             mpi P1, Q1, H, G;
03152             int msg_len;
03153         
03154             mpi_init( &P1 ); mpi_init( &Q1 ); mpi_init( &H ); mpi_init( &G );
03155             rsa_init( &ctx, RSA_PKCS_V15, 0 );
03156         
03157             memset( message_str, 0x00, 1000 );
03158             memset( hash_result, 0x00, 1000 );
03159             memset( output, 0x00, 1000 );
03160             memset( output_str, 0x00, 1000 );
03161         
03162             ctx.len = 2048 / 8;
03163             fct_chk( mpi_read_string( &ctx.P, 16, "e79a373182bfaa722eb035f772ad2a9464bd842de59432c18bbab3a7dfeae318c9b915ee487861ab665a40bd6cda560152578e8579016c929df99fea05b4d64efca1d543850bc8164b40d71ed7f3fa4105df0fb9b9ad2a18ce182c8a4f4f975bea9aa0b9a1438a27a28e97ac8330ef37383414d1bd64607d6979ac050424fd17" ) == 0 );
03164             fct_chk( mpi_read_string( &ctx.Q, 16, "c6749cbb0db8c5a177672d4728a8b22392b2fc4d3b8361d5c0d5055a1b4e46d821f757c24eef2a51c561941b93b3ace7340074c058c9bb48e7e7414f42c41da4cccb5c2ba91deb30c586b7fb18af12a52995592ad139d3be429add6547e044becedaf31fa3b39421e24ee034fbf367d11f6b8f88ee483d163b431e1654ad3e89" ) == 0 );
03165             fct_chk( mpi_read_string( &ctx.N, 16, "b38ac65c8141f7f5c96e14470e851936a67bf94cc6821a39ac12c05f7c0b06d9e6ddba2224703b02e25f31452f9c4a8417b62675fdc6df46b94813bc7b9769a892c482b830bfe0ad42e46668ace68903617faf6681f4babf1cc8e4b0420d3c7f61dc45434c6b54e2c3ee0fc07908509d79c9826e673bf8363255adb0add2401039a7bcd1b4ecf0fbe6ec8369d2da486eec59559dd1d54c9b24190965eafbdab203b35255765261cd0909acf93c3b8b8428cbb448de4715d1b813d0c94829c229543d391ce0adab5351f97a3810c1f73d7b1458b97daed4209c50e16d064d2d5bfda8c23893d755222793146d0a78c3d64f35549141486c3b0961a7b4c1a2034f" ) == 0 );
03166             fct_chk( mpi_read_string( &ctx.E, 16, "3" ) == 0 );
03167         
03168             fct_chk( mpi_sub_int( &P1, &ctx.P, 1 ) == 0 );
03169             fct_chk( mpi_sub_int( &Q1, &ctx.Q, 1 ) == 0 );
03170             fct_chk( mpi_mul_mpi( &H, &P1, &Q1 ) == 0 );
03171             fct_chk( mpi_gcd( &G, &ctx.E, &H  ) == 0 );
03172             fct_chk( mpi_inv_mod( &ctx.D , &ctx.E, &H  ) == 0 );
03173             fct_chk( mpi_mod_mpi( &ctx.DP, &ctx.D, &P1 ) == 0 );
03174             fct_chk( mpi_mod_mpi( &ctx.DQ, &ctx.D, &Q1 ) == 0 );
03175             fct_chk( mpi_inv_mod( &ctx.QP, &ctx.Q, &ctx.P ) == 0 );
03176         
03177             fct_chk( rsa_check_privkey( &ctx ) == 0 );
03178         
03179             msg_len = unhexify( message_str, "59779fd2a39e56640c4fc1e67b60aeffcecd78aed7ad2bdfa464e93d04198d48466b8da7445f25bfa19db2844edd5c8f539cf772cc132b483169d390db28a43bc4ee0f038f6568ffc87447746cb72fefac2d6d90ee3143a915ac4688028805905a68eb8f8a96674b093c495eddd8704461eaa2b345efbb2ad6930acd8023f870" );
03180         
03181             switch( SIG_RSA_SHA384 )
03182             {
03183         #ifdef POLARSSL_MD2_C
03184             case SIG_RSA_MD2:
03185                 md2( message_str, msg_len, hash_result );
03186                 break;
03187         #endif
03188         #ifdef POLARSSL_MD4_C
03189             case SIG_RSA_MD4:
03190                 md4( message_str, msg_len, hash_result );
03191                 break;
03192         #endif
03193         #ifdef POLARSSL_MD5_C
03194             case SIG_RSA_MD5:
03195                 md5( message_str, msg_len, hash_result );
03196                 break;
03197         #endif
03198         #ifdef POLARSSL_SHA1_C
03199             case SIG_RSA_SHA1:
03200                 sha1( message_str, msg_len, hash_result );
03201                 break;
03202         #endif
03203         #ifdef POLARSSL_SHA2_C
03204             case SIG_RSA_SHA224:
03205                 sha2( message_str, msg_len, hash_result, 1 );
03206                 break;
03207             case SIG_RSA_SHA256:
03208                 sha2( message_str, msg_len, hash_result, 0 );
03209                 break;
03210         #endif
03211         #ifdef POLARSSL_SHA4_C
03212             case SIG_RSA_SHA384:
03213                 sha4( message_str, msg_len, hash_result, 1 );
03214                 break;
03215             case SIG_RSA_SHA512:
03216                 sha4( message_str, msg_len, hash_result, 0 );
03217                 break;
03218         #endif
03219             }
03220         
03221             fct_chk( rsa_pkcs1_sign( &ctx, NULL, NULL, RSA_PRIVATE, SIG_RSA_SHA384, 0, hash_result, output ) == 0 );
03222             if( 0 == 0 )
03223             {
03224                 hexify( output_str, output, ctx.len );
03225         
03226                 fct_chk( strcasecmp( (char *) output_str, "40dcc96822e5612eb33f1dca247a35109ba3845c7a3d556a60e656624bf1c103d94686ca7379e9e329ccd1b19b52bfd48b608df9f59a96a82d3feb0101096dbcb80e46da543b4c982ac6bb1717f24f9fe3f76b7154492b47525be1ddcaf4631d33481531be8f3e685837b40bdf4a02827d79f6a32374147174680f51c8e0d8eed9d5c445a563a7bce9ef4236e7cfdc12b2223ef457c3e8ccc6dd65cc23e977a1f03f5ef584feb9af00efc71a701f9d413b0290af17692cb821a1e863d5778e174b1130659f30583f434f09cb1212471a41dd65c102de64a194b6ae3e43cd75928049db78042c58e980aff3ea2774e42845bcf217410a118cf5deeaa64224dbc8" ) == 0 );
03227             }
03228         
03229             mpi_free( &P1 ); mpi_free( &Q1 ); mpi_free( &H ); mpi_free( &G );
03230         }
03231         FCT_TEST_END();
03232 #endif /* POLARSSL_SHA4_C */
03233 
03234 #ifdef POLARSSL_SHA4_C
03235 
03236         FCT_TEST_BGN(rsa_pkcs1_sign_4_verify)
03237         {
03238             unsigned char message_str[1000];
03239             unsigned char hash_result[1000];
03240             unsigned char result_str[1000];
03241             rsa_context ctx;
03242             int msg_len;
03243         
03244             rsa_init( &ctx, RSA_PKCS_V15, 0 );
03245             memset( message_str, 0x00, 1000 );
03246             memset( hash_result, 0x00, 1000 );
03247             memset( result_str, 0x00, 1000 );
03248         
03249             ctx.len = 2048 / 8;
03250             fct_chk( mpi_read_string( &ctx.N, 16, "b38ac65c8141f7f5c96e14470e851936a67bf94cc6821a39ac12c05f7c0b06d9e6ddba2224703b02e25f31452f9c4a8417b62675fdc6df46b94813bc7b9769a892c482b830bfe0ad42e46668ace68903617faf6681f4babf1cc8e4b0420d3c7f61dc45434c6b54e2c3ee0fc07908509d79c9826e673bf8363255adb0add2401039a7bcd1b4ecf0fbe6ec8369d2da486eec59559dd1d54c9b24190965eafbdab203b35255765261cd0909acf93c3b8b8428cbb448de4715d1b813d0c94829c229543d391ce0adab5351f97a3810c1f73d7b1458b97daed4209c50e16d064d2d5bfda8c23893d755222793146d0a78c3d64f35549141486c3b0961a7b4c1a2034f" ) == 0 );
03251             fct_chk( mpi_read_string( &ctx.E, 16, "3" ) == 0 );
03252         
03253             fct_chk( rsa_check_pubkey( &ctx ) == 0 );
03254         
03255             msg_len = unhexify( message_str, "59779fd2a39e56640c4fc1e67b60aeffcecd78aed7ad2bdfa464e93d04198d48466b8da7445f25bfa19db2844edd5c8f539cf772cc132b483169d390db28a43bc4ee0f038f6568ffc87447746cb72fefac2d6d90ee3143a915ac4688028805905a68eb8f8a96674b093c495eddd8704461eaa2b345efbb2ad6930acd8023f870" );
03256             unhexify( result_str, "40dcc96822e5612eb33f1dca247a35109ba3845c7a3d556a60e656624bf1c103d94686ca7379e9e329ccd1b19b52bfd48b608df9f59a96a82d3feb0101096dbcb80e46da543b4c982ac6bb1717f24f9fe3f76b7154492b47525be1ddcaf4631d33481531be8f3e685837b40bdf4a02827d79f6a32374147174680f51c8e0d8eed9d5c445a563a7bce9ef4236e7cfdc12b2223ef457c3e8ccc6dd65cc23e977a1f03f5ef584feb9af00efc71a701f9d413b0290af17692cb821a1e863d5778e174b1130659f30583f434f09cb1212471a41dd65c102de64a194b6ae3e43cd75928049db78042c58e980aff3ea2774e42845bcf217410a118cf5deeaa64224dbc8" );
03257         
03258             switch( SIG_RSA_SHA384 )
03259             {
03260         #ifdef POLARSSL_MD2_C
03261             case SIG_RSA_MD2:
03262                 md2( message_str, msg_len, hash_result );
03263                 break;
03264         #endif
03265         #ifdef POLARSSL_MD4_C
03266             case SIG_RSA_MD4:
03267                 md4( message_str, msg_len, hash_result );
03268                 break;
03269         #endif
03270         #ifdef POLARSSL_MD5_C
03271             case SIG_RSA_MD5:
03272                 md5( message_str, msg_len, hash_result );
03273                 break;
03274         #endif
03275         #ifdef POLARSSL_SHA1_C
03276             case SIG_RSA_SHA1:
03277                 sha1( message_str, msg_len, hash_result );
03278                 break;
03279         #endif
03280         #ifdef POLARSSL_SHA2_C
03281             case SIG_RSA_SHA224:
03282                 sha2( message_str, msg_len, hash_result, 1 );
03283                 break;
03284             case SIG_RSA_SHA256:
03285                 sha2( message_str, msg_len, hash_result, 0 );
03286                 break;
03287         #endif
03288         #ifdef POLARSSL_SHA4_C
03289             case SIG_RSA_SHA384:
03290                 sha4( message_str, msg_len, hash_result, 1 );
03291                 break;
03292             case SIG_RSA_SHA512:
03293                 sha4( message_str, msg_len, hash_result, 0 );
03294                 break;
03295         #endif
03296             }
03297         
03298             fct_chk( rsa_pkcs1_verify( &ctx, RSA_PUBLIC, SIG_RSA_SHA384, 0, hash_result, result_str ) == 0 );
03299         }
03300         FCT_TEST_END();
03301 #endif /* POLARSSL_SHA4_C */
03302 
03303 #ifdef POLARSSL_MD2_C
03304 
03305         FCT_TEST_BGN(rsa_pkcs1_sign_5_md2_2048_bits_rsa)
03306         {
03307             unsigned char message_str[1000];
03308             unsigned char hash_result[1000];
03309             unsigned char output[1000];
03310             unsigned char output_str[1000];
03311             rsa_context ctx;
03312             mpi P1, Q1, H, G;
03313             int msg_len;
03314         
03315             mpi_init( &P1 ); mpi_init( &Q1 ); mpi_init( &H ); mpi_init( &G );
03316             rsa_init( &ctx, RSA_PKCS_V15, 0 );
03317         
03318             memset( message_str, 0x00, 1000 );
03319             memset( hash_result, 0x00, 1000 );
03320             memset( output, 0x00, 1000 );
03321             memset( output_str, 0x00, 1000 );
03322         
03323             ctx.len = 2048 / 8;
03324             fct_chk( mpi_read_string( &ctx.P, 16, "e79a373182bfaa722eb035f772ad2a9464bd842de59432c18bbab3a7dfeae318c9b915ee487861ab665a40bd6cda560152578e8579016c929df99fea05b4d64efca1d543850bc8164b40d71ed7f3fa4105df0fb9b9ad2a18ce182c8a4f4f975bea9aa0b9a1438a27a28e97ac8330ef37383414d1bd64607d6979ac050424fd17" ) == 0 );
03325             fct_chk( mpi_read_string( &ctx.Q, 16, "c6749cbb0db8c5a177672d4728a8b22392b2fc4d3b8361d5c0d5055a1b4e46d821f757c24eef2a51c561941b93b3ace7340074c058c9bb48e7e7414f42c41da4cccb5c2ba91deb30c586b7fb18af12a52995592ad139d3be429add6547e044becedaf31fa3b39421e24ee034fbf367d11f6b8f88ee483d163b431e1654ad3e89" ) == 0 );
03326             fct_chk( mpi_read_string( &ctx.N, 16, "b38ac65c8141f7f5c96e14470e851936a67bf94cc6821a39ac12c05f7c0b06d9e6ddba2224703b02e25f31452f9c4a8417b62675fdc6df46b94813bc7b9769a892c482b830bfe0ad42e46668ace68903617faf6681f4babf1cc8e4b0420d3c7f61dc45434c6b54e2c3ee0fc07908509d79c9826e673bf8363255adb0add2401039a7bcd1b4ecf0fbe6ec8369d2da486eec59559dd1d54c9b24190965eafbdab203b35255765261cd0909acf93c3b8b8428cbb448de4715d1b813d0c94829c229543d391ce0adab5351f97a3810c1f73d7b1458b97daed4209c50e16d064d2d5bfda8c23893d755222793146d0a78c3d64f35549141486c3b0961a7b4c1a2034f" ) == 0 );
03327             fct_chk( mpi_read_string( &ctx.E, 16, "3" ) == 0 );
03328         
03329             fct_chk( mpi_sub_int( &P1, &ctx.P, 1 ) == 0 );
03330             fct_chk( mpi_sub_int( &Q1, &ctx.Q, 1 ) == 0 );
03331             fct_chk( mpi_mul_mpi( &H, &P1, &Q1 ) == 0 );
03332             fct_chk( mpi_gcd( &G, &ctx.E, &H  ) == 0 );
03333             fct_chk( mpi_inv_mod( &ctx.D , &ctx.E, &H  ) == 0 );
03334             fct_chk( mpi_mod_mpi( &ctx.DP, &ctx.D, &P1 ) == 0 );
03335             fct_chk( mpi_mod_mpi( &ctx.DQ, &ctx.D, &Q1 ) == 0 );
03336             fct_chk( mpi_inv_mod( &ctx.QP, &ctx.Q, &ctx.P ) == 0 );
03337         
03338             fct_chk( rsa_check_privkey( &ctx ) == 0 );
03339         
03340             msg_len = unhexify( message_str, "59779fd2a39e56640c4fc1e67b60aeffcecd78aed7ad2bdfa464e93d04198d48466b8da7445f25bfa19db2844edd5c8f539cf772cc132b483169d390db28a43bc4ee0f038f6568ffc87447746cb72fefac2d6d90ee3143a915ac4688028805905a68eb8f8a96674b093c495eddd8704461eaa2b345efbb2ad6930acd8023f870" );
03341         
03342             switch( SIG_RSA_MD2 )
03343             {
03344         #ifdef POLARSSL_MD2_C
03345             case SIG_RSA_MD2:
03346                 md2( message_str, msg_len, hash_result );
03347                 break;
03348         #endif
03349         #ifdef POLARSSL_MD4_C
03350             case SIG_RSA_MD4:
03351                 md4( message_str, msg_len, hash_result );
03352                 break;
03353         #endif
03354         #ifdef POLARSSL_MD5_C
03355             case SIG_RSA_MD5:
03356                 md5( message_str, msg_len, hash_result );
03357                 break;
03358         #endif
03359         #ifdef POLARSSL_SHA1_C
03360             case SIG_RSA_SHA1:
03361                 sha1( message_str, msg_len, hash_result );
03362                 break;
03363         #endif
03364         #ifdef POLARSSL_SHA2_C
03365             case SIG_RSA_SHA224:
03366                 sha2( message_str, msg_len, hash_result, 1 );
03367                 break;
03368             case SIG_RSA_SHA256:
03369                 sha2( message_str, msg_len, hash_result, 0 );
03370                 break;
03371         #endif
03372         #ifdef POLARSSL_SHA4_C
03373             case SIG_RSA_SHA384:
03374                 sha4( message_str, msg_len, hash_result, 1 );
03375                 break;
03376             case SIG_RSA_SHA512:
03377                 sha4( message_str, msg_len, hash_result, 0 );
03378                 break;
03379         #endif
03380             }
03381         
03382             fct_chk( rsa_pkcs1_sign( &ctx, NULL, NULL, RSA_PRIVATE, SIG_RSA_MD2, 0, hash_result, output ) == 0 );
03383             if( 0 == 0 )
03384             {
03385                 hexify( output_str, output, ctx.len );
03386         
03387                 fct_chk( strcasecmp( (char *) output_str, "6cbb0e4019d64dd5cd2d48fa43446e5cba1a7edbb79d91b199be75c7d3e7ae0820c44d3a120cd2910f73cbb315e15963a60ea7da3452015d9d6beb5ac998fddbd1fa3e5908abc9151f3ffb70365aaee6fb0cd440d3f5591868fc136fae38ac7bcdb3bde3c6a0362dd8b814f7edadd4a51b2edf2227a40d1e34c29f608add7746731425858eb93661c633b7a90942fca3cd594ab4ec170052d44105643518020782e76235def34d014135bad8daed590200482325c3416c3d66417e80d9f9c6322a54683638247b577445ecd0be2765ce96c4ee45213204026dfba24d5ee89e1ea75538ba39f7149a5ac0fc12d7c53cbc12481d4a8e2d410ec633d800ad4b4304" ) == 0 );
03388             }
03389         
03390             mpi_free( &P1 ); mpi_free( &Q1 ); mpi_free( &H ); mpi_free( &G );
03391         }
03392         FCT_TEST_END();
03393 #endif /* POLARSSL_MD2_C */
03394 
03395 #ifdef POLARSSL_MD2_C
03396 
03397         FCT_TEST_BGN(rsa_pkcs1_sign_5_verify)
03398         {
03399             unsigned char message_str[1000];
03400             unsigned char hash_result[1000];
03401             unsigned char result_str[1000];
03402             rsa_context ctx;
03403             int msg_len;
03404         
03405             rsa_init( &ctx, RSA_PKCS_V15, 0 );
03406             memset( message_str, 0x00, 1000 );
03407             memset( hash_result, 0x00, 1000 );
03408             memset( result_str, 0x00, 1000 );
03409         
03410             ctx.len = 2048 / 8;
03411             fct_chk( mpi_read_string( &ctx.N, 16, "b38ac65c8141f7f5c96e14470e851936a67bf94cc6821a39ac12c05f7c0b06d9e6ddba2224703b02e25f31452f9c4a8417b62675fdc6df46b94813bc7b9769a892c482b830bfe0ad42e46668ace68903617faf6681f4babf1cc8e4b0420d3c7f61dc45434c6b54e2c3ee0fc07908509d79c9826e673bf8363255adb0add2401039a7bcd1b4ecf0fbe6ec8369d2da486eec59559dd1d54c9b24190965eafbdab203b35255765261cd0909acf93c3b8b8428cbb448de4715d1b813d0c94829c229543d391ce0adab5351f97a3810c1f73d7b1458b97daed4209c50e16d064d2d5bfda8c23893d755222793146d0a78c3d64f35549141486c3b0961a7b4c1a2034f" ) == 0 );
03412             fct_chk( mpi_read_string( &ctx.E, 16, "3" ) == 0 );
03413         
03414             fct_chk( rsa_check_pubkey( &ctx ) == 0 );
03415         
03416             msg_len = unhexify( message_str, "59779fd2a39e56640c4fc1e67b60aeffcecd78aed7ad2bdfa464e93d04198d48466b8da7445f25bfa19db2844edd5c8f539cf772cc132b483169d390db28a43bc4ee0f038f6568ffc87447746cb72fefac2d6d90ee3143a915ac4688028805905a68eb8f8a96674b093c495eddd8704461eaa2b345efbb2ad6930acd8023f870" );
03417             unhexify( result_str, "6cbb0e4019d64dd5cd2d48fa43446e5cba1a7edbb79d91b199be75c7d3e7ae0820c44d3a120cd2910f73cbb315e15963a60ea7da3452015d9d6beb5ac998fddbd1fa3e5908abc9151f3ffb70365aaee6fb0cd440d3f5591868fc136fae38ac7bcdb3bde3c6a0362dd8b814f7edadd4a51b2edf2227a40d1e34c29f608add7746731425858eb93661c633b7a90942fca3cd594ab4ec170052d44105643518020782e76235def34d014135bad8daed590200482325c3416c3d66417e80d9f9c6322a54683638247b577445ecd0be2765ce96c4ee45213204026dfba24d5ee89e1ea75538ba39f7149a5ac0fc12d7c53cbc12481d4a8e2d410ec633d800ad4b4304" );
03418         
03419             switch( SIG_RSA_MD2 )
03420             {
03421         #ifdef POLARSSL_MD2_C
03422             case SIG_RSA_MD2:
03423                 md2( message_str, msg_len, hash_result );
03424                 break;
03425         #endif
03426         #ifdef POLARSSL_MD4_C
03427             case SIG_RSA_MD4:
03428                 md4( message_str, msg_len, hash_result );
03429                 break;
03430         #endif
03431         #ifdef POLARSSL_MD5_C
03432             case SIG_RSA_MD5:
03433                 md5( message_str, msg_len, hash_result );
03434                 break;
03435         #endif
03436         #ifdef POLARSSL_SHA1_C
03437             case SIG_RSA_SHA1:
03438                 sha1( message_str, msg_len, hash_result );
03439                 break;
03440         #endif
03441         #ifdef POLARSSL_SHA2_C
03442             case SIG_RSA_SHA224:
03443                 sha2( message_str, msg_len, hash_result, 1 );
03444                 break;
03445             case SIG_RSA_SHA256:
03446                 sha2( message_str, msg_len, hash_result, 0 );
03447                 break;
03448         #endif
03449         #ifdef POLARSSL_SHA4_C
03450             case SIG_RSA_SHA384:
03451                 sha4( message_str, msg_len, hash_result, 1 );
03452                 break;
03453             case SIG_RSA_SHA512:
03454                 sha4( message_str, msg_len, hash_result, 0 );
03455                 break;
03456         #endif
03457             }
03458         
03459             fct_chk( rsa_pkcs1_verify( &ctx, RSA_PUBLIC, SIG_RSA_MD2, 0, hash_result, result_str ) == 0 );
03460         }
03461         FCT_TEST_END();
03462 #endif /* POLARSSL_MD2_C */
03463 
03464 #ifdef POLARSSL_MD4_C
03465 
03466         FCT_TEST_BGN(rsa_pkcs1_sign_6_md4_2048_bits_rsa)
03467         {
03468             unsigned char message_str[1000];
03469             unsigned char hash_result[1000];
03470             unsigned char output[1000];
03471             unsigned char output_str[1000];
03472             rsa_context ctx;
03473             mpi P1, Q1, H, G;
03474             int msg_len;
03475         
03476             mpi_init( &P1 ); mpi_init( &Q1 ); mpi_init( &H ); mpi_init( &G );
03477             rsa_init( &ctx, RSA_PKCS_V15, 0 );
03478         
03479             memset( message_str, 0x00, 1000 );
03480             memset( hash_result, 0x00, 1000 );
03481             memset( output, 0x00, 1000 );
03482             memset( output_str, 0x00, 1000 );
03483         
03484             ctx.len = 2048 / 8;
03485             fct_chk( mpi_read_string( &ctx.P, 16, "e79a373182bfaa722eb035f772ad2a9464bd842de59432c18bbab3a7dfeae318c9b915ee487861ab665a40bd6cda560152578e8579016c929df99fea05b4d64efca1d543850bc8164b40d71ed7f3fa4105df0fb9b9ad2a18ce182c8a4f4f975bea9aa0b9a1438a27a28e97ac8330ef37383414d1bd64607d6979ac050424fd17" ) == 0 );
03486             fct_chk( mpi_read_string( &ctx.Q, 16, "c6749cbb0db8c5a177672d4728a8b22392b2fc4d3b8361d5c0d5055a1b4e46d821f757c24eef2a51c561941b93b3ace7340074c058c9bb48e7e7414f42c41da4cccb5c2ba91deb30c586b7fb18af12a52995592ad139d3be429add6547e044becedaf31fa3b39421e24ee034fbf367d11f6b8f88ee483d163b431e1654ad3e89" ) == 0 );
03487             fct_chk( mpi_read_string( &ctx.N, 16, "b38ac65c8141f7f5c96e14470e851936a67bf94cc6821a39ac12c05f7c0b06d9e6ddba2224703b02e25f31452f9c4a8417b62675fdc6df46b94813bc7b9769a892c482b830bfe0ad42e46668ace68903617faf6681f4babf1cc8e4b0420d3c7f61dc45434c6b54e2c3ee0fc07908509d79c9826e673bf8363255adb0add2401039a7bcd1b4ecf0fbe6ec8369d2da486eec59559dd1d54c9b24190965eafbdab203b35255765261cd0909acf93c3b8b8428cbb448de4715d1b813d0c94829c229543d391ce0adab5351f97a3810c1f73d7b1458b97daed4209c50e16d064d2d5bfda8c23893d755222793146d0a78c3d64f35549141486c3b0961a7b4c1a2034f" ) == 0 );
03488             fct_chk( mpi_read_string( &ctx.E, 16, "3" ) == 0 );
03489         
03490             fct_chk( mpi_sub_int( &P1, &ctx.P, 1 ) == 0 );
03491             fct_chk( mpi_sub_int( &Q1, &ctx.Q, 1 ) == 0 );
03492             fct_chk( mpi_mul_mpi( &H, &P1, &Q1 ) == 0 );
03493             fct_chk( mpi_gcd( &G, &ctx.E, &H  ) == 0 );
03494             fct_chk( mpi_inv_mod( &ctx.D , &ctx.E, &H  ) == 0 );
03495             fct_chk( mpi_mod_mpi( &ctx.DP, &ctx.D, &P1 ) == 0 );
03496             fct_chk( mpi_mod_mpi( &ctx.DQ, &ctx.D, &Q1 ) == 0 );
03497             fct_chk( mpi_inv_mod( &ctx.QP, &ctx.Q, &ctx.P ) == 0 );
03498         
03499             fct_chk( rsa_check_privkey( &ctx ) == 0 );
03500         
03501             msg_len = unhexify( message_str, "59779fd2a39e56640c4fc1e67b60aeffcecd78aed7ad2bdfa464e93d04198d48466b8da7445f25bfa19db2844edd5c8f539cf772cc132b483169d390db28a43bc4ee0f038f6568ffc87447746cb72fefac2d6d90ee3143a915ac4688028805905a68eb8f8a96674b093c495eddd8704461eaa2b345efbb2ad6930acd8023f870" );
03502         
03503             switch( SIG_RSA_MD4 )
03504             {
03505         #ifdef POLARSSL_MD2_C
03506             case SIG_RSA_MD2:
03507                 md2( message_str, msg_len, hash_result );
03508                 break;
03509         #endif
03510         #ifdef POLARSSL_MD4_C
03511             case SIG_RSA_MD4:
03512                 md4( message_str, msg_len, hash_result );
03513                 break;
03514         #endif
03515         #ifdef POLARSSL_MD5_C
03516             case SIG_RSA_MD5:
03517                 md5( message_str, msg_len, hash_result );
03518                 break;
03519         #endif
03520         #ifdef POLARSSL_SHA1_C
03521             case SIG_RSA_SHA1:
03522                 sha1( message_str, msg_len, hash_result );
03523                 break;
03524         #endif
03525         #ifdef POLARSSL_SHA2_C
03526             case SIG_RSA_SHA224:
03527                 sha2( message_str, msg_len, hash_result, 1 );
03528                 break;
03529             case SIG_RSA_SHA256:
03530                 sha2( message_str, msg_len, hash_result, 0 );
03531                 break;
03532         #endif
03533         #ifdef POLARSSL_SHA4_C
03534             case SIG_RSA_SHA384:
03535                 sha4( message_str, msg_len, hash_result, 1 );
03536                 break;
03537             case SIG_RSA_SHA512:
03538                 sha4( message_str, msg_len, hash_result, 0 );
03539                 break;
03540         #endif
03541             }
03542         
03543             fct_chk( rsa_pkcs1_sign( &ctx, NULL, NULL, RSA_PRIVATE, SIG_RSA_MD4, 0, hash_result, output ) == 0 );
03544             if( 0 == 0 )
03545             {
03546                 hexify( output_str, output, ctx.len );
03547         
03548                 fct_chk( strcasecmp( (char *) output_str, "b0e60dc4dfaf0f636a3a4414eae2d7bce7c3ce505a46e38f3f654d8769b31b7891ba18f89672fce204bbac6e3764355e65447c087994731cd44f086710e79e8c3ebc6e2cb61edc5d3e05848ab733d95efe2d0252a691e810c17fa57fd2dd296374c9ba17fea704685677f45d668a386c8ca433fbbb56d3bbfb43a489ed9518b1c9ab13ce497a1cec91467453bfe533145a31a095c2de541255141768ccc6fdff3fc790b5050f1122c93c3044a9346947e1b23e8125bf7edbf38c64a4286dfc1b829e983db3117959a2559a8ef97687ab673e231be213d88edc632637b58cdb2d69c51fbf6bf894cff319216718b1e696f75cd4366f53dc2e28b2a00017984207" ) == 0 );
03549             }
03550         
03551             mpi_free( &P1 ); mpi_free( &Q1 ); mpi_free( &H ); mpi_free( &G );
03552         }
03553         FCT_TEST_END();
03554 #endif /* POLARSSL_MD4_C */
03555 
03556 #ifdef POLARSSL_MD4_C
03557 
03558         FCT_TEST_BGN(rsa_pkcs1_sign_6_verify)
03559         {
03560             unsigned char message_str[1000];
03561             unsigned char hash_result[1000];
03562             unsigned char result_str[1000];
03563             rsa_context ctx;
03564             int msg_len;
03565         
03566             rsa_init( &ctx, RSA_PKCS_V15, 0 );
03567             memset( message_str, 0x00, 1000 );
03568             memset( hash_result, 0x00, 1000 );
03569             memset( result_str, 0x00, 1000 );
03570         
03571             ctx.len = 2048 / 8;
03572             fct_chk( mpi_read_string( &ctx.N, 16, "b38ac65c8141f7f5c96e14470e851936a67bf94cc6821a39ac12c05f7c0b06d9e6ddba2224703b02e25f31452f9c4a8417b62675fdc6df46b94813bc7b9769a892c482b830bfe0ad42e46668ace68903617faf6681f4babf1cc8e4b0420d3c7f61dc45434c6b54e2c3ee0fc07908509d79c9826e673bf8363255adb0add2401039a7bcd1b4ecf0fbe6ec8369d2da486eec59559dd1d54c9b24190965eafbdab203b35255765261cd0909acf93c3b8b8428cbb448de4715d1b813d0c94829c229543d391ce0adab5351f97a3810c1f73d7b1458b97daed4209c50e16d064d2d5bfda8c23893d755222793146d0a78c3d64f35549141486c3b0961a7b4c1a2034f" ) == 0 );
03573             fct_chk( mpi_read_string( &ctx.E, 16, "3" ) == 0 );
03574         
03575             fct_chk( rsa_check_pubkey( &ctx ) == 0 );
03576         
03577             msg_len = unhexify( message_str, "59779fd2a39e56640c4fc1e67b60aeffcecd78aed7ad2bdfa464e93d04198d48466b8da7445f25bfa19db2844edd5c8f539cf772cc132b483169d390db28a43bc4ee0f038f6568ffc87447746cb72fefac2d6d90ee3143a915ac4688028805905a68eb8f8a96674b093c495eddd8704461eaa2b345efbb2ad6930acd8023f870" );
03578             unhexify( result_str, "b0e60dc4dfaf0f636a3a4414eae2d7bce7c3ce505a46e38f3f654d8769b31b7891ba18f89672fce204bbac6e3764355e65447c087994731cd44f086710e79e8c3ebc6e2cb61edc5d3e05848ab733d95efe2d0252a691e810c17fa57fd2dd296374c9ba17fea704685677f45d668a386c8ca433fbbb56d3bbfb43a489ed9518b1c9ab13ce497a1cec91467453bfe533145a31a095c2de541255141768ccc6fdff3fc790b5050f1122c93c3044a9346947e1b23e8125bf7edbf38c64a4286dfc1b829e983db3117959a2559a8ef97687ab673e231be213d88edc632637b58cdb2d69c51fbf6bf894cff319216718b1e696f75cd4366f53dc2e28b2a00017984207" );
03579         
03580             switch( SIG_RSA_MD4 )
03581             {
03582         #ifdef POLARSSL_MD2_C
03583             case SIG_RSA_MD2:
03584                 md2( message_str, msg_len, hash_result );
03585                 break;
03586         #endif
03587         #ifdef POLARSSL_MD4_C
03588             case SIG_RSA_MD4:
03589                 md4( message_str, msg_len, hash_result );
03590                 break;
03591         #endif
03592         #ifdef POLARSSL_MD5_C
03593             case SIG_RSA_MD5:
03594                 md5( message_str, msg_len, hash_result );
03595                 break;
03596         #endif
03597         #ifdef POLARSSL_SHA1_C
03598             case SIG_RSA_SHA1:
03599                 sha1( message_str, msg_len, hash_result );
03600                 break;
03601         #endif
03602         #ifdef POLARSSL_SHA2_C
03603             case SIG_RSA_SHA224:
03604                 sha2( message_str, msg_len, hash_result, 1 );
03605                 break;
03606             case SIG_RSA_SHA256:
03607                 sha2( message_str, msg_len, hash_result, 0 );
03608                 break;
03609         #endif
03610         #ifdef POLARSSL_SHA4_C
03611             case SIG_RSA_SHA384:
03612                 sha4( message_str, msg_len, hash_result, 1 );
03613                 break;
03614             case SIG_RSA_SHA512:
03615                 sha4( message_str, msg_len, hash_result, 0 );
03616                 break;
03617         #endif
03618             }
03619         
03620             fct_chk( rsa_pkcs1_verify( &ctx, RSA_PUBLIC, SIG_RSA_MD4, 0, hash_result, result_str ) == 0 );
03621         }
03622         FCT_TEST_END();
03623 #endif /* POLARSSL_MD4_C */
03624 
03625 #ifdef POLARSSL_MD5_C
03626 
03627         FCT_TEST_BGN(rsa_pkcs1_sign_7_md5_2048_bits_rsa)
03628         {
03629             unsigned char message_str[1000];
03630             unsigned char hash_result[1000];
03631             unsigned char output[1000];
03632             unsigned char output_str[1000];
03633             rsa_context ctx;
03634             mpi P1, Q1, H, G;
03635             int msg_len;
03636         
03637             mpi_init( &P1 ); mpi_init( &Q1 ); mpi_init( &H ); mpi_init( &G );
03638             rsa_init( &ctx, RSA_PKCS_V15, 0 );
03639         
03640             memset( message_str, 0x00, 1000 );
03641             memset( hash_result, 0x00, 1000 );
03642             memset( output, 0x00, 1000 );
03643             memset( output_str, 0x00, 1000 );
03644         
03645             ctx.len = 2048 / 8;
03646             fct_chk( mpi_read_string( &ctx.P, 16, "e79a373182bfaa722eb035f772ad2a9464bd842de59432c18bbab3a7dfeae318c9b915ee487861ab665a40bd6cda560152578e8579016c929df99fea05b4d64efca1d543850bc8164b40d71ed7f3fa4105df0fb9b9ad2a18ce182c8a4f4f975bea9aa0b9a1438a27a28e97ac8330ef37383414d1bd64607d6979ac050424fd17" ) == 0 );
03647             fct_chk( mpi_read_string( &ctx.Q, 16, "c6749cbb0db8c5a177672d4728a8b22392b2fc4d3b8361d5c0d5055a1b4e46d821f757c24eef2a51c561941b93b3ace7340074c058c9bb48e7e7414f42c41da4cccb5c2ba91deb30c586b7fb18af12a52995592ad139d3be429add6547e044becedaf31fa3b39421e24ee034fbf367d11f6b8f88ee483d163b431e1654ad3e89" ) == 0 );
03648             fct_chk( mpi_read_string( &ctx.N, 16, "b38ac65c8141f7f5c96e14470e851936a67bf94cc6821a39ac12c05f7c0b06d9e6ddba2224703b02e25f31452f9c4a8417b62675fdc6df46b94813bc7b9769a892c482b830bfe0ad42e46668ace68903617faf6681f4babf1cc8e4b0420d3c7f61dc45434c6b54e2c3ee0fc07908509d79c9826e673bf8363255adb0add2401039a7bcd1b4ecf0fbe6ec8369d2da486eec59559dd1d54c9b24190965eafbdab203b35255765261cd0909acf93c3b8b8428cbb448de4715d1b813d0c94829c229543d391ce0adab5351f97a3810c1f73d7b1458b97daed4209c50e16d064d2d5bfda8c23893d755222793146d0a78c3d64f35549141486c3b0961a7b4c1a2034f" ) == 0 );
03649             fct_chk( mpi_read_string( &ctx.E, 16, "3" ) == 0 );
03650         
03651             fct_chk( mpi_sub_int( &P1, &ctx.P, 1 ) == 0 );
03652             fct_chk( mpi_sub_int( &Q1, &ctx.Q, 1 ) == 0 );
03653             fct_chk( mpi_mul_mpi( &H, &P1, &Q1 ) == 0 );
03654             fct_chk( mpi_gcd( &G, &ctx.E, &H  ) == 0 );
03655             fct_chk( mpi_inv_mod( &ctx.D , &ctx.E, &H  ) == 0 );
03656             fct_chk( mpi_mod_mpi( &ctx.DP, &ctx.D, &P1 ) == 0 );
03657             fct_chk( mpi_mod_mpi( &ctx.DQ, &ctx.D, &Q1 ) == 0 );
03658             fct_chk( mpi_inv_mod( &ctx.QP, &ctx.Q, &ctx.P ) == 0 );
03659         
03660             fct_chk( rsa_check_privkey( &ctx ) == 0 );
03661         
03662             msg_len = unhexify( message_str, "59779fd2a39e56640c4fc1e67b60aeffcecd78aed7ad2bdfa464e93d04198d48466b8da7445f25bfa19db2844edd5c8f539cf772cc132b483169d390db28a43bc4ee0f038f6568ffc87447746cb72fefac2d6d90ee3143a915ac4688028805905a68eb8f8a96674b093c495eddd8704461eaa2b345efbb2ad6930acd8023f870" );
03663         
03664             switch( SIG_RSA_MD5 )
03665             {
03666         #ifdef POLARSSL_MD2_C
03667             case SIG_RSA_MD2:
03668                 md2( message_str, msg_len, hash_result );
03669                 break;
03670         #endif
03671         #ifdef POLARSSL_MD4_C
03672             case SIG_RSA_MD4:
03673                 md4( message_str, msg_len, hash_result );
03674                 break;
03675         #endif
03676         #ifdef POLARSSL_MD5_C
03677             case SIG_RSA_MD5:
03678                 md5( message_str, msg_len, hash_result );
03679                 break;
03680         #endif
03681         #ifdef POLARSSL_SHA1_C
03682             case SIG_RSA_SHA1:
03683                 sha1( message_str, msg_len, hash_result );
03684                 break;
03685         #endif
03686         #ifdef POLARSSL_SHA2_C
03687             case SIG_RSA_SHA224:
03688                 sha2( message_str, msg_len, hash_result, 1 );
03689                 break;
03690             case SIG_RSA_SHA256:
03691                 sha2( message_str, msg_len, hash_result, 0 );
03692                 break;
03693         #endif
03694         #ifdef POLARSSL_SHA4_C
03695             case SIG_RSA_SHA384:
03696                 sha4( message_str, msg_len, hash_result, 1 );
03697                 break;
03698             case SIG_RSA_SHA512:
03699                 sha4( message_str, msg_len, hash_result, 0 );
03700                 break;
03701         #endif
03702             }
03703         
03704             fct_chk( rsa_pkcs1_sign( &ctx, NULL, NULL, RSA_PRIVATE, SIG_RSA_MD5, 0, hash_result, output ) == 0 );
03705             if( 0 == 0 )
03706             {
03707                 hexify( output_str, output, ctx.len );
03708         
03709                 fct_chk( strcasecmp( (char *) output_str, "3bcf673c3b27f6e2ece4bb97c7a37161e6c6ee7419ef366efc3cfee0f15f415ff6d9d4390937386c6fec1771acba73f24ec6b0469ea8b88083f0b4e1b6069d7bf286e67cf94182a548663137e82a6e09c35de2c27779da0503f1f5bedfebadf2a875f17763a0564df4a6d945a5a3e46bc90fb692af3a55106aafc6b577587456ff8d49cfd5c299d7a2b776dbe4c1ae777b0f64aa3bab27689af32d6cc76157c7dc6900a3469e18a7d9b6bfe4951d1105a08864575e4f4ec05b3e053f9b7a2d5653ae085e50a63380d6bdd6f58ab378d7e0a2be708c559849891317089ab04c82d8bc589ea088b90b11dea5cf85856ff7e609cc1adb1d403beead4c126ff29021" ) == 0 );
03710             }
03711         
03712             mpi_free( &P1 ); mpi_free( &Q1 ); mpi_free( &H ); mpi_free( &G );
03713         }
03714         FCT_TEST_END();
03715 #endif /* POLARSSL_MD5_C */
03716 
03717 #ifdef POLARSSL_MD5_C
03718 
03719         FCT_TEST_BGN(rsa_pkcs1_sign_7_verify)
03720         {
03721             unsigned char message_str[1000];
03722             unsigned char hash_result[1000];
03723             unsigned char result_str[1000];
03724             rsa_context ctx;
03725             int msg_len;
03726         
03727             rsa_init( &ctx, RSA_PKCS_V15, 0 );
03728             memset( message_str, 0x00, 1000 );
03729             memset( hash_result, 0x00, 1000 );
03730             memset( result_str, 0x00, 1000 );
03731         
03732             ctx.len = 2048 / 8;
03733             fct_chk( mpi_read_string( &ctx.N, 16, "b38ac65c8141f7f5c96e14470e851936a67bf94cc6821a39ac12c05f7c0b06d9e6ddba2224703b02e25f31452f9c4a8417b62675fdc6df46b94813bc7b9769a892c482b830bfe0ad42e46668ace68903617faf6681f4babf1cc8e4b0420d3c7f61dc45434c6b54e2c3ee0fc07908509d79c9826e673bf8363255adb0add2401039a7bcd1b4ecf0fbe6ec8369d2da486eec59559dd1d54c9b24190965eafbdab203b35255765261cd0909acf93c3b8b8428cbb448de4715d1b813d0c94829c229543d391ce0adab5351f97a3810c1f73d7b1458b97daed4209c50e16d064d2d5bfda8c23893d755222793146d0a78c3d64f35549141486c3b0961a7b4c1a2034f" ) == 0 );
03734             fct_chk( mpi_read_string( &ctx.E, 16, "3" ) == 0 );
03735         
03736             fct_chk( rsa_check_pubkey( &ctx ) == 0 );
03737         
03738             msg_len = unhexify( message_str, "59779fd2a39e56640c4fc1e67b60aeffcecd78aed7ad2bdfa464e93d04198d48466b8da7445f25bfa19db2844edd5c8f539cf772cc132b483169d390db28a43bc4ee0f038f6568ffc87447746cb72fefac2d6d90ee3143a915ac4688028805905a68eb8f8a96674b093c495eddd8704461eaa2b345efbb2ad6930acd8023f870" );
03739             unhexify( result_str, "3bcf673c3b27f6e2ece4bb97c7a37161e6c6ee7419ef366efc3cfee0f15f415ff6d9d4390937386c6fec1771acba73f24ec6b0469ea8b88083f0b4e1b6069d7bf286e67cf94182a548663137e82a6e09c35de2c27779da0503f1f5bedfebadf2a875f17763a0564df4a6d945a5a3e46bc90fb692af3a55106aafc6b577587456ff8d49cfd5c299d7a2b776dbe4c1ae777b0f64aa3bab27689af32d6cc76157c7dc6900a3469e18a7d9b6bfe4951d1105a08864575e4f4ec05b3e053f9b7a2d5653ae085e50a63380d6bdd6f58ab378d7e0a2be708c559849891317089ab04c82d8bc589ea088b90b11dea5cf85856ff7e609cc1adb1d403beead4c126ff29021" );
03740         
03741             switch( SIG_RSA_MD5 )
03742             {
03743         #ifdef POLARSSL_MD2_C
03744             case SIG_RSA_MD2:
03745                 md2( message_str, msg_len, hash_result );
03746                 break;
03747         #endif
03748         #ifdef POLARSSL_MD4_C
03749             case SIG_RSA_MD4:
03750                 md4( message_str, msg_len, hash_result );
03751                 break;
03752         #endif
03753         #ifdef POLARSSL_MD5_C
03754             case SIG_RSA_MD5:
03755                 md5( message_str, msg_len, hash_result );
03756                 break;
03757         #endif
03758         #ifdef POLARSSL_SHA1_C
03759             case SIG_RSA_SHA1:
03760                 sha1( message_str, msg_len, hash_result );
03761                 break;
03762         #endif
03763         #ifdef POLARSSL_SHA2_C
03764             case SIG_RSA_SHA224:
03765                 sha2( message_str, msg_len, hash_result, 1 );
03766                 break;
03767             case SIG_RSA_SHA256:
03768                 sha2( message_str, msg_len, hash_result, 0 );
03769                 break;
03770         #endif
03771         #ifdef POLARSSL_SHA4_C
03772             case SIG_RSA_SHA384:
03773                 sha4( message_str, msg_len, hash_result, 1 );
03774                 break;
03775             case SIG_RSA_SHA512:
03776                 sha4( message_str, msg_len, hash_result, 0 );
03777                 break;
03778         #endif
03779             }
03780         
03781             fct_chk( rsa_pkcs1_verify( &ctx, RSA_PUBLIC, SIG_RSA_MD5, 0, hash_result, result_str ) == 0 );
03782         }
03783         FCT_TEST_END();
03784 #endif /* POLARSSL_MD5_C */
03785 
03786 
03787         FCT_TEST_BGN(rsa_pkcs1_sign_8_raw_2048_bits_rsa)
03788         {
03789             unsigned char message_str[1000];
03790             unsigned char hash_result[1000];
03791             unsigned char output[1000];
03792             unsigned char output_str[1000];
03793             rsa_context ctx;
03794             mpi P1, Q1, H, G;
03795             int hash_len;
03796         
03797             mpi_init( &P1 ); mpi_init( &Q1 ); mpi_init( &H ); mpi_init( &G );
03798             rsa_init( &ctx, RSA_PKCS_V15, 0 );
03799         
03800             memset( message_str, 0x00, 1000 );
03801             memset( hash_result, 0x00, 1000 );
03802             memset( output, 0x00, 1000 );
03803             memset( output_str, 0x00, 1000 );
03804         
03805             ctx.len = 2048 / 8;
03806             fct_chk( mpi_read_string( &ctx.P, 16, "e79a373182bfaa722eb035f772ad2a9464bd842de59432c18bbab3a7dfeae318c9b915ee487861ab665a40bd6cda560152578e8579016c929df99fea05b4d64efca1d543850bc8164b40d71ed7f3fa4105df0fb9b9ad2a18ce182c8a4f4f975bea9aa0b9a1438a27a28e97ac8330ef37383414d1bd64607d6979ac050424fd17" ) == 0 );
03807             fct_chk( mpi_read_string( &ctx.Q, 16, "c6749cbb0db8c5a177672d4728a8b22392b2fc4d3b8361d5c0d5055a1b4e46d821f757c24eef2a51c561941b93b3ace7340074c058c9bb48e7e7414f42c41da4cccb5c2ba91deb30c586b7fb18af12a52995592ad139d3be429add6547e044becedaf31fa3b39421e24ee034fbf367d11f6b8f88ee483d163b431e1654ad3e89" ) == 0 );
03808             fct_chk( mpi_read_string( &ctx.N, 16, "b38ac65c8141f7f5c96e14470e851936a67bf94cc6821a39ac12c05f7c0b06d9e6ddba2224703b02e25f31452f9c4a8417b62675fdc6df46b94813bc7b9769a892c482b830bfe0ad42e46668ace68903617faf6681f4babf1cc8e4b0420d3c7f61dc45434c6b54e2c3ee0fc07908509d79c9826e673bf8363255adb0add2401039a7bcd1b4ecf0fbe6ec8369d2da486eec59559dd1d54c9b24190965eafbdab203b35255765261cd0909acf93c3b8b8428cbb448de4715d1b813d0c94829c229543d391ce0adab5351f97a3810c1f73d7b1458b97daed4209c50e16d064d2d5bfda8c23893d755222793146d0a78c3d64f35549141486c3b0961a7b4c1a2034f" ) == 0 );
03809             fct_chk( mpi_read_string( &ctx.E, 16, "3" ) == 0 );
03810         
03811             fct_chk( mpi_sub_int( &P1, &ctx.P, 1 ) == 0 );
03812             fct_chk( mpi_sub_int( &Q1, &ctx.Q, 1 ) == 0 );
03813             fct_chk( mpi_mul_mpi( &H, &P1, &Q1 ) == 0 );
03814             fct_chk( mpi_gcd( &G, &ctx.E, &H  ) == 0 );
03815             fct_chk( mpi_inv_mod( &ctx.D , &ctx.E, &H  ) == 0 );
03816             fct_chk( mpi_mod_mpi( &ctx.DP, &ctx.D, &P1 ) == 0 );
03817             fct_chk( mpi_mod_mpi( &ctx.DQ, &ctx.D, &Q1 ) == 0 );
03818             fct_chk( mpi_inv_mod( &ctx.QP, &ctx.Q, &ctx.P ) == 0 );
03819         
03820             fct_chk( rsa_check_privkey( &ctx ) == 0 );
03821         
03822             unhexify( message_str, "59779fd2a39e56640c4fc1e67b60aeffcecd78aed7ad2bdfa464e93d04198d48466b8da7445f25bfa19db2844edd5c8f539cf772cc132b483169d390db28a43bc4ee0f038f6568ffc87447746cb72fefac2d6d90ee3143a915ac4688028805905a68eb8f8a96674b093c495eddd8704461eaa2b345efbb2ad6930acd8023f870" );
03823             hash_len = unhexify( hash_result, "1234567890deadbeef" );
03824         
03825             fct_chk( rsa_pkcs1_sign( &ctx, NULL, NULL, RSA_PRIVATE, SIG_RSA_RAW, hash_len, hash_result, output ) == 0 );
03826         
03827             hexify( output_str, output, ctx.len );
03828         
03829             fct_chk( strcasecmp( (char *) output_str, "605baf947c0de49e4f6a0dfb94a43ae318d5df8ed20ba4ba5a37a73fb009c5c9e5cce8b70a25b1c7580f389f0d7092485cdfa02208b70d33482edf07a7eafebdc54862ca0e0396a5a7d09991b9753eb1ffb6091971bb5789c6b121abbcd0a3cbaa39969fa7c28146fce96c6d03272e3793e5be8f5abfa9afcbebb986d7b3050604a2af4d3a40fa6c003781a539a60259d1e84f13322da9e538a49c369b83e7286bf7d30b64bbb773506705da5d5d5483a563a1ffacc902fb75c9a751b1e83cdc7a6db0470056883f48b5a5446b43b1d180ea12ba11a6a8d93b3b32a30156b6084b7fb142998a2a0d28014b84098ece7d9d5e4d55cc342ca26f5a0167a679dec8" ) == 0 );
03830         
03831             mpi_free( &P1 ); mpi_free( &Q1 ); mpi_free( &H ); mpi_free( &G );
03832         }
03833         FCT_TEST_END();
03834 
03835 
03836         FCT_TEST_BGN(rsa_pkcs1_sign_8_verify)
03837         {
03838             unsigned char message_str[1000];
03839             unsigned char hash_result[1000];
03840             unsigned char result_str[1000];
03841             rsa_context ctx;
03842             size_t hash_len;
03843         
03844             rsa_init( &ctx, RSA_PKCS_V15, 0 );
03845             memset( message_str, 0x00, 1000 );
03846             memset( hash_result, 0x00, 1000 );
03847             memset( result_str, 0x00, 1000 );
03848         
03849             ctx.len = 2048 / 8;
03850             fct_chk( mpi_read_string( &ctx.N, 16, "b38ac65c8141f7f5c96e14470e851936a67bf94cc6821a39ac12c05f7c0b06d9e6ddba2224703b02e25f31452f9c4a8417b62675fdc6df46b94813bc7b9769a892c482b830bfe0ad42e46668ace68903617faf6681f4babf1cc8e4b0420d3c7f61dc45434c6b54e2c3ee0fc07908509d79c9826e673bf8363255adb0add2401039a7bcd1b4ecf0fbe6ec8369d2da486eec59559dd1d54c9b24190965eafbdab203b35255765261cd0909acf93c3b8b8428cbb448de4715d1b813d0c94829c229543d391ce0adab5351f97a3810c1f73d7b1458b97daed4209c50e16d064d2d5bfda8c23893d755222793146d0a78c3d64f35549141486c3b0961a7b4c1a2034f" ) == 0 );
03851             fct_chk( mpi_read_string( &ctx.E, 16, "3" ) == 0 );
03852         
03853             fct_chk( rsa_check_pubkey( &ctx ) == 0 );
03854         
03855             unhexify( message_str, "59779fd2a39e56640c4fc1e67b60aeffcecd78aed7ad2bdfa464e93d04198d48466b8da7445f25bfa19db2844edd5c8f539cf772cc132b483169d390db28a43bc4ee0f038f6568ffc87447746cb72fefac2d6d90ee3143a915ac4688028805905a68eb8f8a96674b093c495eddd8704461eaa2b345efbb2ad6930acd8023f870" );
03856             hash_len = unhexify( hash_result, "1234567890deadbeef" );
03857             unhexify( result_str, "605baf947c0de49e4f6a0dfb94a43ae318d5df8ed20ba4ba5a37a73fb009c5c9e5cce8b70a25b1c7580f389f0d7092485cdfa02208b70d33482edf07a7eafebdc54862ca0e0396a5a7d09991b9753eb1ffb6091971bb5789c6b121abbcd0a3cbaa39969fa7c28146fce96c6d03272e3793e5be8f5abfa9afcbebb986d7b3050604a2af4d3a40fa6c003781a539a60259d1e84f13322da9e538a49c369b83e7286bf7d30b64bbb773506705da5d5d5483a563a1ffacc902fb75c9a751b1e83cdc7a6db0470056883f48b5a5446b43b1d180ea12ba11a6a8d93b3b32a30156b6084b7fb142998a2a0d28014b84098ece7d9d5e4d55cc342ca26f5a0167a679dec8" );
03858         
03859             fct_chk( rsa_pkcs1_verify( &ctx, RSA_PUBLIC, SIG_RSA_RAW, hash_len, hash_result, result_str ) == 0 );
03860         }
03861         FCT_TEST_END();
03862 
03863 
03864         FCT_TEST_BGN(rsa_pkcs1_sign_8_verify_wrong_raw_hash)
03865         {
03866             unsigned char message_str[1000];
03867             unsigned char hash_result[1000];
03868             unsigned char result_str[1000];
03869             rsa_context ctx;
03870             size_t hash_len;
03871         
03872             rsa_init( &ctx, RSA_PKCS_V15, 0 );
03873             memset( message_str, 0x00, 1000 );
03874             memset( hash_result, 0x00, 1000 );
03875             memset( result_str, 0x00, 1000 );
03876         
03877             ctx.len = 2048 / 8;
03878             fct_chk( mpi_read_string( &ctx.N, 16, "b38ac65c8141f7f5c96e14470e851936a67bf94cc6821a39ac12c05f7c0b06d9e6ddba2224703b02e25f31452f9c4a8417b62675fdc6df46b94813bc7b9769a892c482b830bfe0ad42e46668ace68903617faf6681f4babf1cc8e4b0420d3c7f61dc45434c6b54e2c3ee0fc07908509d79c9826e673bf8363255adb0add2401039a7bcd1b4ecf0fbe6ec8369d2da486eec59559dd1d54c9b24190965eafbdab203b35255765261cd0909acf93c3b8b8428cbb448de4715d1b813d0c94829c229543d391ce0adab5351f97a3810c1f73d7b1458b97daed4209c50e16d064d2d5bfda8c23893d755222793146d0a78c3d64f35549141486c3b0961a7b4c1a2034f" ) == 0 );
03879             fct_chk( mpi_read_string( &ctx.E, 16, "3" ) == 0 );
03880         
03881             fct_chk( rsa_check_pubkey( &ctx ) == 0 );
03882         
03883             unhexify( message_str, "59779fd2a39e56640c4fc1e67b60aeffcecd78aed7ad2bdfa464e93d04198d48466b8da7445f25bfa19db2844edd5c8f539cf772cc132b483169d390db28a43bc4ee0f038f6568ffc87447746cb72fefac2d6d90ee3143a915ac4688028805905a68eb8f8a96674b093c495eddd8704461eaa2b345efbb2ad6930acd8023f870" );
03884             hash_len = unhexify( hash_result, "1234567890deadcafe" );
03885             unhexify( result_str, "605baf947c0de49e4f6a0dfb94a43ae318d5df8ed20ba4ba5a37a73fb009c5c9e5cce8b70a25b1c7580f389f0d7092485cdfa02208b70d33482edf07a7eafebdc54862ca0e0396a5a7d09991b9753eb1ffb6091971bb5789c6b121abbcd0a3cbaa39969fa7c28146fce96c6d03272e3793e5be8f5abfa9afcbebb986d7b3050604a2af4d3a40fa6c003781a539a60259d1e84f13322da9e538a49c369b83e7286bf7d30b64bbb773506705da5d5d5483a563a1ffacc902fb75c9a751b1e83cdc7a6db0470056883f48b5a5446b43b1d180ea12ba11a6a8d93b3b32a30156b6084b7fb142998a2a0d28014b84098ece7d9d5e4d55cc342ca26f5a0167a679dec8" );
03886         
03887             fct_chk( rsa_pkcs1_verify( &ctx, RSA_PUBLIC, SIG_RSA_RAW, hash_len, hash_result, result_str ) == POLARSSL_ERR_RSA_VERIFY_FAILED );
03888         }
03889         FCT_TEST_END();
03890 
03891 
03892         FCT_TEST_BGN(rsa_pkcs1_sign_9_invalid_digest_type)
03893         {
03894             unsigned char message_str[1000];
03895             unsigned char hash_result[1000];
03896             unsigned char output[1000];
03897             unsigned char output_str[1000];
03898             rsa_context ctx;
03899             mpi P1, Q1, H, G;
03900             int msg_len;
03901         
03902             mpi_init( &P1 ); mpi_init( &Q1 ); mpi_init( &H ); mpi_init( &G );
03903             rsa_init( &ctx, RSA_PKCS_V15, 0 );
03904         
03905             memset( message_str, 0x00, 1000 );
03906             memset( hash_result, 0x00, 1000 );
03907             memset( output, 0x00, 1000 );
03908             memset( output_str, 0x00, 1000 );
03909         
03910             ctx.len = 2048 / 8;
03911             fct_chk( mpi_read_string( &ctx.P, 16, "e79a373182bfaa722eb035f772ad2a9464bd842de59432c18bbab3a7dfeae318c9b915ee487861ab665a40bd6cda560152578e8579016c929df99fea05b4d64efca1d543850bc8164b40d71ed7f3fa4105df0fb9b9ad2a18ce182c8a4f4f975bea9aa0b9a1438a27a28e97ac8330ef37383414d1bd64607d6979ac050424fd17" ) == 0 );
03912             fct_chk( mpi_read_string( &ctx.Q, 16, "c6749cbb0db8c5a177672d4728a8b22392b2fc4d3b8361d5c0d5055a1b4e46d821f757c24eef2a51c561941b93b3ace7340074c058c9bb48e7e7414f42c41da4cccb5c2ba91deb30c586b7fb18af12a52995592ad139d3be429add6547e044becedaf31fa3b39421e24ee034fbf367d11f6b8f88ee483d163b431e1654ad3e89" ) == 0 );
03913             fct_chk( mpi_read_string( &ctx.N, 16, "b38ac65c8141f7f5c96e14470e851936a67bf94cc6821a39ac12c05f7c0b06d9e6ddba2224703b02e25f31452f9c4a8417b62675fdc6df46b94813bc7b9769a892c482b830bfe0ad42e46668ace68903617faf6681f4babf1cc8e4b0420d3c7f61dc45434c6b54e2c3ee0fc07908509d79c9826e673bf8363255adb0add2401039a7bcd1b4ecf0fbe6ec8369d2da486eec59559dd1d54c9b24190965eafbdab203b35255765261cd0909acf93c3b8b8428cbb448de4715d1b813d0c94829c229543d391ce0adab5351f97a3810c1f73d7b1458b97daed4209c50e16d064d2d5bfda8c23893d755222793146d0a78c3d64f35549141486c3b0961a7b4c1a2034f" ) == 0 );
03914             fct_chk( mpi_read_string( &ctx.E, 16, "3" ) == 0 );
03915         
03916             fct_chk( mpi_sub_int( &P1, &ctx.P, 1 ) == 0 );
03917             fct_chk( mpi_sub_int( &Q1, &ctx.Q, 1 ) == 0 );
03918             fct_chk( mpi_mul_mpi( &H, &P1, &Q1 ) == 0 );
03919             fct_chk( mpi_gcd( &G, &ctx.E, &H  ) == 0 );
03920             fct_chk( mpi_inv_mod( &ctx.D , &ctx.E, &H  ) == 0 );
03921             fct_chk( mpi_mod_mpi( &ctx.DP, &ctx.D, &P1 ) == 0 );
03922             fct_chk( mpi_mod_mpi( &ctx.DQ, &ctx.D, &Q1 ) == 0 );
03923             fct_chk( mpi_inv_mod( &ctx.QP, &ctx.Q, &ctx.P ) == 0 );
03924         
03925             fct_chk( rsa_check_privkey( &ctx ) == 0 );
03926         
03927             msg_len = unhexify( message_str, "59779fd2a39e56640c4fc1e67b60aeffcecd78aed7ad2bdfa464e93d04198d48466b8da7445f25bfa19db2844edd5c8f539cf772cc132b483169d390db28a43bc4ee0f038f6568ffc87447746cb72fefac2d6d90ee3143a915ac4688028805905a68eb8f8a96674b093c495eddd8704461eaa2b345efbb2ad6930acd8023f870" );
03928         
03929             switch( 1 )
03930             {
03931         #ifdef POLARSSL_MD2_C
03932             case SIG_RSA_MD2:
03933                 md2( message_str, msg_len, hash_result );
03934                 break;
03935         #endif
03936         #ifdef POLARSSL_MD4_C
03937             case SIG_RSA_MD4:
03938                 md4( message_str, msg_len, hash_result );
03939                 break;
03940         #endif
03941         #ifdef POLARSSL_MD5_C
03942             case SIG_RSA_MD5:
03943                 md5( message_str, msg_len, hash_result );
03944                 break;
03945         #endif
03946         #ifdef POLARSSL_SHA1_C
03947             case SIG_RSA_SHA1:
03948                 sha1( message_str, msg_len, hash_result );
03949                 break;
03950         #endif
03951         #ifdef POLARSSL_SHA2_C
03952             case SIG_RSA_SHA224:
03953                 sha2( message_str, msg_len, hash_result, 1 );
03954                 break;
03955             case SIG_RSA_SHA256:
03956                 sha2( message_str, msg_len, hash_result, 0 );
03957                 break;
03958         #endif
03959         #ifdef POLARSSL_SHA4_C
03960             case SIG_RSA_SHA384:
03961                 sha4( message_str, msg_len, hash_result, 1 );
03962                 break;
03963             case SIG_RSA_SHA512:
03964                 sha4( message_str, msg_len, hash_result, 0 );
03965                 break;
03966         #endif
03967             }
03968         
03969             fct_chk( rsa_pkcs1_sign( &ctx, NULL, NULL, RSA_PRIVATE, 1, 0, hash_result, output ) == POLARSSL_ERR_RSA_BAD_INPUT_DATA );
03970             if( POLARSSL_ERR_RSA_BAD_INPUT_DATA == 0 )
03971             {
03972                 hexify( output_str, output, ctx.len );
03973         
03974                 fct_chk( strcasecmp( (char *) output_str, "3bcf673c3b27f6e2ece4bb97c7a37161e6c6ee7419ef366efc3cfee0f15f415ff6d9d4390937386c6fec1771acba73f24ec6b0469ea8b88083f0b4e1b6069d7bf286e67cf94182a548663137e82a6e09c35de2c27779da0503f1f5bedfebadf2a875f17763a0564df4a6d945a5a3e46bc90fb692af3a55106aafc6b577587456ff8d49cfd5c299d7a2b776dbe4c1ae777b0f64aa3bab27689af32d6cc76157c7dc6900a3469e18a7d9b6bfe4951d1105a08864575e4f4ec05b3e053f9b7a2d5653ae085e50a63380d6bdd6f58ab378d7e0a2be708c559849891317089ab04c82d8bc589ea088b90b11dea5cf85856ff7e609cc1adb1d403beead4c126ff29021" ) == 0 );
03975             }
03976         
03977             mpi_free( &P1 ); mpi_free( &Q1 ); mpi_free( &H ); mpi_free( &G );
03978         }
03979         FCT_TEST_END();
03980 
03981 
03982         FCT_TEST_BGN(rsa_pkcs1_sign_9_verify_invalid_digest_type)
03983         {
03984             unsigned char message_str[1000];
03985             unsigned char hash_result[1000];
03986             unsigned char result_str[1000];
03987             rsa_context ctx;
03988             int msg_len;
03989         
03990             rsa_init( &ctx, RSA_PKCS_V15, 0 );
03991             memset( message_str, 0x00, 1000 );
03992             memset( hash_result, 0x00, 1000 );
03993             memset( result_str, 0x00, 1000 );
03994         
03995             ctx.len = 2048 / 8;
03996             fct_chk( mpi_read_string( &ctx.N, 16, "b38ac65c8141f7f5c96e14470e851936a67bf94cc6821a39ac12c05f7c0b06d9e6ddba2224703b02e25f31452f9c4a8417b62675fdc6df46b94813bc7b9769a892c482b830bfe0ad42e46668ace68903617faf6681f4babf1cc8e4b0420d3c7f61dc45434c6b54e2c3ee0fc07908509d79c9826e673bf8363255adb0add2401039a7bcd1b4ecf0fbe6ec8369d2da486eec59559dd1d54c9b24190965eafbdab203b35255765261cd0909acf93c3b8b8428cbb448de4715d1b813d0c94829c229543d391ce0adab5351f97a3810c1f73d7b1458b97daed4209c50e16d064d2d5bfda8c23893d755222793146d0a78c3d64f35549141486c3b0961a7b4c1a2034f" ) == 0 );
03997             fct_chk( mpi_read_string( &ctx.E, 16, "3" ) == 0 );
03998         
03999             fct_chk( rsa_check_pubkey( &ctx ) == 0 );
04000         
04001             msg_len = unhexify( message_str, "59779fd2a39e56640c4fc1e67b60aeffcecd78aed7ad2bdfa464e93d04198d48466b8da7445f25bfa19db2844edd5c8f539cf772cc132b483169d390db28a43bc4ee0f038f6568ffc87447746cb72fefac2d6d90ee3143a915ac4688028805905a68eb8f8a96674b093c495eddd8704461eaa2b345efbb2ad6930acd8023f870" );
04002             unhexify( result_str, "3bcf673c3b27f6e2ece4bb97c7a37161e6c6ee7419ef366efc3cfee0f15f415ff6d9d4390937386c6fec1771acba73f24ec6b0469ea8b88083f0b4e1b6069d7bf286e67cf94182a548663137e82a6e09c35de2c27779da0503f1f5bedfebadf2a875f17763a0564df4a6d945a5a3e46bc90fb692af3a55106aafc6b577587456ff8d49cfd5c299d7a2b776dbe4c1ae777b0f64aa3bab27689af32d6cc76157c7dc6900a3469e18a7d9b6bfe4951d1105a08864575e4f4ec05b3e053f9b7a2d5653ae085e50a63380d6bdd6f58ab378d7e0a2be708c559849891317089ab04c82d8bc589ea088b90b11dea5cf85856ff7e609cc1adb1d403beead4c126ff29021" );
04003         
04004             switch( 1 )
04005             {
04006         #ifdef POLARSSL_MD2_C
04007             case SIG_RSA_MD2:
04008                 md2( message_str, msg_len, hash_result );
04009                 break;
04010         #endif
04011         #ifdef POLARSSL_MD4_C
04012             case SIG_RSA_MD4:
04013                 md4( message_str, msg_len, hash_result );
04014                 break;
04015         #endif
04016         #ifdef POLARSSL_MD5_C
04017             case SIG_RSA_MD5:
04018                 md5( message_str, msg_len, hash_result );
04019                 break;
04020         #endif
04021         #ifdef POLARSSL_SHA1_C
04022             case SIG_RSA_SHA1:
04023                 sha1( message_str, msg_len, hash_result );
04024                 break;
04025         #endif
04026         #ifdef POLARSSL_SHA2_C
04027             case SIG_RSA_SHA224:
04028                 sha2( message_str, msg_len, hash_result, 1 );
04029                 break;
04030             case SIG_RSA_SHA256:
04031                 sha2( message_str, msg_len, hash_result, 0 );
04032                 break;
04033         #endif
04034         #ifdef POLARSSL_SHA4_C
04035             case SIG_RSA_SHA384:
04036                 sha4( message_str, msg_len, hash_result, 1 );
04037                 break;
04038             case SIG_RSA_SHA512:
04039                 sha4( message_str, msg_len, hash_result, 0 );
04040                 break;
04041         #endif
04042             }
04043         
04044             fct_chk( rsa_pkcs1_verify( &ctx, RSA_PUBLIC, 1, 0, hash_result, result_str ) == POLARSSL_ERR_RSA_INVALID_PADDING );
04045         }
04046         FCT_TEST_END();
04047 
04048 
04049         FCT_TEST_BGN(rsa_pkcs1_sign_8_invalid_padding_type)
04050         {
04051             unsigned char message_str[1000];
04052             unsigned char hash_result[1000];
04053             unsigned char output[1000];
04054             unsigned char output_str[1000];
04055             rsa_context ctx;
04056             mpi P1, Q1, H, G;
04057             int msg_len;
04058         
04059             mpi_init( &P1 ); mpi_init( &Q1 ); mpi_init( &H ); mpi_init( &G );
04060             rsa_init( &ctx, 2, 0 );
04061         
04062             memset( message_str, 0x00, 1000 );
04063             memset( hash_result, 0x00, 1000 );
04064             memset( output, 0x00, 1000 );
04065             memset( output_str, 0x00, 1000 );
04066         
04067             ctx.len = 2048 / 8;
04068             fct_chk( mpi_read_string( &ctx.P, 16, "e79a373182bfaa722eb035f772ad2a9464bd842de59432c18bbab3a7dfeae318c9b915ee487861ab665a40bd6cda560152578e8579016c929df99fea05b4d64efca1d543850bc8164b40d71ed7f3fa4105df0fb9b9ad2a18ce182c8a4f4f975bea9aa0b9a1438a27a28e97ac8330ef37383414d1bd64607d6979ac050424fd17" ) == 0 );
04069             fct_chk( mpi_read_string( &ctx.Q, 16, "c6749cbb0db8c5a177672d4728a8b22392b2fc4d3b8361d5c0d5055a1b4e46d821f757c24eef2a51c561941b93b3ace7340074c058c9bb48e7e7414f42c41da4cccb5c2ba91deb30c586b7fb18af12a52995592ad139d3be429add6547e044becedaf31fa3b39421e24ee034fbf367d11f6b8f88ee483d163b431e1654ad3e89" ) == 0 );
04070             fct_chk( mpi_read_string( &ctx.N, 16, "b38ac65c8141f7f5c96e14470e851936a67bf94cc6821a39ac12c05f7c0b06d9e6ddba2224703b02e25f31452f9c4a8417b62675fdc6df46b94813bc7b9769a892c482b830bfe0ad42e46668ace68903617faf6681f4babf1cc8e4b0420d3c7f61dc45434c6b54e2c3ee0fc07908509d79c9826e673bf8363255adb0add2401039a7bcd1b4ecf0fbe6ec8369d2da486eec59559dd1d54c9b24190965eafbdab203b35255765261cd0909acf93c3b8b8428cbb448de4715d1b813d0c94829c229543d391ce0adab5351f97a3810c1f73d7b1458b97daed4209c50e16d064d2d5bfda8c23893d755222793146d0a78c3d64f35549141486c3b0961a7b4c1a2034f" ) == 0 );
04071             fct_chk( mpi_read_string( &ctx.E, 16, "3" ) == 0 );
04072         
04073             fct_chk( mpi_sub_int( &P1, &ctx.P, 1 ) == 0 );
04074             fct_chk( mpi_sub_int( &Q1, &ctx.Q, 1 ) == 0 );
04075             fct_chk( mpi_mul_mpi( &H, &P1, &Q1 ) == 0 );
04076             fct_chk( mpi_gcd( &G, &ctx.E, &H  ) == 0 );
04077             fct_chk( mpi_inv_mod( &ctx.D , &ctx.E, &H  ) == 0 );
04078             fct_chk( mpi_mod_mpi( &ctx.DP, &ctx.D, &P1 ) == 0 );
04079             fct_chk( mpi_mod_mpi( &ctx.DQ, &ctx.D, &Q1 ) == 0 );
04080             fct_chk( mpi_inv_mod( &ctx.QP, &ctx.Q, &ctx.P ) == 0 );
04081         
04082             fct_chk( rsa_check_privkey( &ctx ) == 0 );
04083         
04084             msg_len = unhexify( message_str, "59779fd2a39e56640c4fc1e67b60aeffcecd78aed7ad2bdfa464e93d04198d48466b8da7445f25bfa19db2844edd5c8f539cf772cc132b483169d390db28a43bc4ee0f038f6568ffc87447746cb72fefac2d6d90ee3143a915ac4688028805905a68eb8f8a96674b093c495eddd8704461eaa2b345efbb2ad6930acd8023f870" );
04085         
04086             switch( SIG_RSA_MD5 )
04087             {
04088         #ifdef POLARSSL_MD2_C
04089             case SIG_RSA_MD2:
04090                 md2( message_str, msg_len, hash_result );
04091                 break;
04092         #endif
04093         #ifdef POLARSSL_MD4_C
04094             case SIG_RSA_MD4:
04095                 md4( message_str, msg_len, hash_result );
04096                 break;
04097         #endif
04098         #ifdef POLARSSL_MD5_C
04099             case SIG_RSA_MD5:
04100                 md5( message_str, msg_len, hash_result );
04101                 break;
04102         #endif
04103         #ifdef POLARSSL_SHA1_C
04104             case SIG_RSA_SHA1:
04105                 sha1( message_str, msg_len, hash_result );
04106                 break;
04107         #endif
04108         #ifdef POLARSSL_SHA2_C
04109             case SIG_RSA_SHA224:
04110                 sha2( message_str, msg_len, hash_result, 1 );
04111                 break;
04112             case SIG_RSA_SHA256:
04113                 sha2( message_str, msg_len, hash_result, 0 );
04114                 break;
04115         #endif
04116         #ifdef POLARSSL_SHA4_C
04117             case SIG_RSA_SHA384:
04118                 sha4( message_str, msg_len, hash_result, 1 );
04119                 break;
04120             case SIG_RSA_SHA512:
04121                 sha4( message_str, msg_len, hash_result, 0 );
04122                 break;
04123         #endif
04124             }
04125         
04126             fct_chk( rsa_pkcs1_sign( &ctx, NULL, NULL, RSA_PRIVATE, SIG_RSA_MD5, 0, hash_result, output ) == POLARSSL_ERR_RSA_INVALID_PADDING );
04127             if( POLARSSL_ERR_RSA_INVALID_PADDING == 0 )
04128             {
04129                 hexify( output_str, output, ctx.len );
04130         
04131                 fct_chk( strcasecmp( (char *) output_str, "3bcf673c3b27f6e2ece4bb97c7a37161e6c6ee7419ef366efc3cfee0f15f415ff6d9d4390937386c6fec1771acba73f24ec6b0469ea8b88083f0b4e1b6069d7bf286e67cf94182a548663137e82a6e09c35de2c27779da0503f1f5bedfebadf2a875f17763a0564df4a6d945a5a3e46bc90fb692af3a55106aafc6b577587456ff8d49cfd5c299d7a2b776dbe4c1ae777b0f64aa3bab27689af32d6cc76157c7dc6900a3469e18a7d9b6bfe4951d1105a08864575e4f4ec05b3e053f9b7a2d5653ae085e50a63380d6bdd6f58ab378d7e0a2be708c559849891317089ab04c82d8bc589ea088b90b11dea5cf85856ff7e609cc1adb1d403beead4c126ff29021" ) == 0 );
04132             }
04133         
04134             mpi_free( &P1 ); mpi_free( &Q1 ); mpi_free( &H ); mpi_free( &G );
04135         }
04136         FCT_TEST_END();
04137 
04138 
04139         FCT_TEST_BGN(rsa_pkcs1_sign_8_verify_invalid_padding_type)
04140         {
04141             unsigned char message_str[1000];
04142             unsigned char hash_result[1000];
04143             unsigned char result_str[1000];
04144             rsa_context ctx;
04145             int msg_len;
04146         
04147             rsa_init( &ctx, 1, 0 );
04148             memset( message_str, 0x00, 1000 );
04149             memset( hash_result, 0x00, 1000 );
04150             memset( result_str, 0x00, 1000 );
04151         
04152             ctx.len = 2048 / 8;
04153             fct_chk( mpi_read_string( &ctx.N, 16, "b38ac65c8141f7f5c96e14470e851936a67bf94cc6821a39ac12c05f7c0b06d9e6ddba2224703b02e25f31452f9c4a8417b62675fdc6df46b94813bc7b9769a892c482b830bfe0ad42e46668ace68903617faf6681f4babf1cc8e4b0420d3c7f61dc45434c6b54e2c3ee0fc07908509d79c9826e673bf8363255adb0add2401039a7bcd1b4ecf0fbe6ec8369d2da486eec59559dd1d54c9b24190965eafbdab203b35255765261cd0909acf93c3b8b8428cbb448de4715d1b813d0c94829c229543d391ce0adab5351f97a3810c1f73d7b1458b97daed4209c50e16d064d2d5bfda8c23893d755222793146d0a78c3d64f35549141486c3b0961a7b4c1a2034f" ) == 0 );
04154             fct_chk( mpi_read_string( &ctx.E, 16, "3" ) == 0 );
04155         
04156             fct_chk( rsa_check_pubkey( &ctx ) == 0 );
04157         
04158             msg_len = unhexify( message_str, "59779fd2a39e56640c4fc1e67b60aeffcecd78aed7ad2bdfa464e93d04198d48466b8da7445f25bfa19db2844edd5c8f539cf772cc132b483169d390db28a43bc4ee0f038f6568ffc87447746cb72fefac2d6d90ee3143a915ac4688028805905a68eb8f8a96674b093c495eddd8704461eaa2b345efbb2ad6930acd8023f870" );
04159             unhexify( result_str, "3bcf673c3b27f6e2ece4bb97c7a37161e6c6ee7419ef366efc3cfee0f15f415ff6d9d4390937386c6fec1771acba73f24ec6b0469ea8b88083f0b4e1b6069d7bf286e67cf94182a548663137e82a6e09c35de2c27779da0503f1f5bedfebadf2a875f17763a0564df4a6d945a5a3e46bc90fb692af3a55106aafc6b577587456ff8d49cfd5c299d7a2b776dbe4c1ae777b0f64aa3bab27689af32d6cc76157c7dc6900a3469e18a7d9b6bfe4951d1105a08864575e4f4ec05b3e053f9b7a2d5653ae085e50a63380d6bdd6f58ab378d7e0a2be708c559849891317089ab04c82d8bc589ea088b90b11dea5cf85856ff7e609cc1adb1d403beead4c126ff29021" );
04160         
04161             switch( SIG_RSA_MD5 )
04162             {
04163         #ifdef POLARSSL_MD2_C
04164             case SIG_RSA_MD2:
04165                 md2( message_str, msg_len, hash_result );
04166                 break;
04167         #endif
04168         #ifdef POLARSSL_MD4_C
04169             case SIG_RSA_MD4:
04170                 md4( message_str, msg_len, hash_result );
04171                 break;
04172         #endif
04173         #ifdef POLARSSL_MD5_C
04174             case SIG_RSA_MD5:
04175                 md5( message_str, msg_len, hash_result );
04176                 break;
04177         #endif
04178         #ifdef POLARSSL_SHA1_C
04179             case SIG_RSA_SHA1:
04180                 sha1( message_str, msg_len, hash_result );
04181                 break;
04182         #endif
04183         #ifdef POLARSSL_SHA2_C
04184             case SIG_RSA_SHA224:
04185                 sha2( message_str, msg_len, hash_result, 1 );
04186                 break;
04187             case SIG_RSA_SHA256:
04188                 sha2( message_str, msg_len, hash_result, 0 );
04189                 break;
04190         #endif
04191         #ifdef POLARSSL_SHA4_C
04192             case SIG_RSA_SHA384:
04193                 sha4( message_str, msg_len, hash_result, 1 );
04194                 break;
04195             case SIG_RSA_SHA512:
04196                 sha4( message_str, msg_len, hash_result, 0 );
04197                 break;
04198         #endif
04199             }
04200         
04201             fct_chk( rsa_pkcs1_verify( &ctx, RSA_PUBLIC, SIG_RSA_MD5, 0, hash_result, result_str ) == POLARSSL_ERR_RSA_INVALID_PADDING );
04202         }
04203         FCT_TEST_END();
04204 
04205 
04206         FCT_TEST_BGN(rsa_pkcs1_encrypt_1)
04207         {
04208             unsigned char message_str[1000];
04209             unsigned char output[1000];
04210             unsigned char output_str[1000];
04211             rsa_context ctx;
04212             size_t msg_len;
04213             rnd_pseudo_info rnd_info;
04214         
04215             memset( &rnd_info, 0, sizeof( rnd_pseudo_info ) );
04216         
04217             rsa_init( &ctx, RSA_PKCS_V15, 0 );
04218             memset( message_str, 0x00, 1000 );
04219             memset( output, 0x00, 1000 );
04220             memset( output_str, 0x00, 1000 );
04221         
04222             ctx.len = 2048 / 8;
04223             fct_chk( mpi_read_string( &ctx.N, 16, "b38ac65c8141f7f5c96e14470e851936a67bf94cc6821a39ac12c05f7c0b06d9e6ddba2224703b02e25f31452f9c4a8417b62675fdc6df46b94813bc7b9769a892c482b830bfe0ad42e46668ace68903617faf6681f4babf1cc8e4b0420d3c7f61dc45434c6b54e2c3ee0fc07908509d79c9826e673bf8363255adb0add2401039a7bcd1b4ecf0fbe6ec8369d2da486eec59559dd1d54c9b24190965eafbdab203b35255765261cd0909acf93c3b8b8428cbb448de4715d1b813d0c94829c229543d391ce0adab5351f97a3810c1f73d7b1458b97daed4209c50e16d064d2d5bfda8c23893d755222793146d0a78c3d64f35549141486c3b0961a7b4c1a2034f" ) == 0 );
04224             fct_chk( mpi_read_string( &ctx.E, 16, "3" ) == 0 );
04225         
04226             fct_chk( rsa_check_pubkey( &ctx ) == 0 );
04227         
04228             msg_len = unhexify( message_str, "4E636AF98E40F3ADCFCCB698F4E80B9F" );
04229         
04230             fct_chk( rsa_pkcs1_encrypt( &ctx, &rnd_pseudo_rand, &rnd_info, RSA_PUBLIC, msg_len, message_str, output ) == 0 );
04231             if( 0 == 0 )
04232             {
04233                 hexify( output_str, output, ctx.len );
04234         
04235                 fct_chk( strcasecmp( (char *) output_str, "b0c0b193ba4a5b4502bfacd1a9c2697da5510f3e3ab7274cf404418afd2c62c89b98d83bbc21c8c1bf1afe6d8bf40425e053e9c03e03a3be0edbe1eda073fade1cc286cc0305a493d98fe795634c3cad7feb513edb742d66d910c87d07f6b0055c3488bb262b5fd1ce8747af64801fb39d2d3a3e57086ffe55ab8d0a2ca86975629a0f85767a4990c532a7c2dab1647997ebb234d0b28a0008bfebfc905e7ba5b30b60566a5e0190417465efdbf549934b8f0c5c9f36b7c5b6373a47ae553ced0608a161b1b70dfa509375cf7a3598223a6d7b7a1d1a06ac74d345a9bb7c0e44c8388858a4f1d8115f2bd769ffa69020385fa286302c80e950f9e2751308666c" ) == 0 );
04236             }
04237         }
04238         FCT_TEST_END();
04239 
04240 
04241         FCT_TEST_BGN(rsa_pkcs1_decrypt_1_verify)
04242         {
04243             unsigned char message_str[1000];
04244             unsigned char output[1000];
04245             unsigned char output_str[1000];
04246             rsa_context ctx;
04247             mpi P1, Q1, H, G;
04248             size_t output_len;
04249         
04250             mpi_init( &P1 ); mpi_init( &Q1 ); mpi_init( &H ); mpi_init( &G );
04251             rsa_init( &ctx, RSA_PKCS_V15, 0 );
04252         
04253             memset( message_str, 0x00, 1000 );
04254             memset( output, 0x00, 1000 );
04255             memset( output_str, 0x00, 1000 );
04256         
04257             ctx.len = 2048 / 8;
04258             fct_chk( mpi_read_string( &ctx.P, 16, "e79a373182bfaa722eb035f772ad2a9464bd842de59432c18bbab3a7dfeae318c9b915ee487861ab665a40bd6cda560152578e8579016c929df99fea05b4d64efca1d543850bc8164b40d71ed7f3fa4105df0fb9b9ad2a18ce182c8a4f4f975bea9aa0b9a1438a27a28e97ac8330ef37383414d1bd64607d6979ac050424fd17" ) == 0 );
04259             fct_chk( mpi_read_string( &ctx.Q, 16, "c6749cbb0db8c5a177672d4728a8b22392b2fc4d3b8361d5c0d5055a1b4e46d821f757c24eef2a51c561941b93b3ace7340074c058c9bb48e7e7414f42c41da4cccb5c2ba91deb30c586b7fb18af12a52995592ad139d3be429add6547e044becedaf31fa3b39421e24ee034fbf367d11f6b8f88ee483d163b431e1654ad3e89" ) == 0 );
04260             fct_chk( mpi_read_string( &ctx.N, 16, "b38ac65c8141f7f5c96e14470e851936a67bf94cc6821a39ac12c05f7c0b06d9e6ddba2224703b02e25f31452f9c4a8417b62675fdc6df46b94813bc7b9769a892c482b830bfe0ad42e46668ace68903617faf6681f4babf1cc8e4b0420d3c7f61dc45434c6b54e2c3ee0fc07908509d79c9826e673bf8363255adb0add2401039a7bcd1b4ecf0fbe6ec8369d2da486eec59559dd1d54c9b24190965eafbdab203b35255765261cd0909acf93c3b8b8428cbb448de4715d1b813d0c94829c229543d391ce0adab5351f97a3810c1f73d7b1458b97daed4209c50e16d064d2d5bfda8c23893d755222793146d0a78c3d64f35549141486c3b0961a7b4c1a2034f" ) == 0 );
04261             fct_chk( mpi_read_string( &ctx.E, 16, "3" ) == 0 );
04262         
04263             fct_chk( mpi_sub_int( &P1, &ctx.P, 1 ) == 0 );
04264             fct_chk( mpi_sub_int( &Q1, &ctx.Q, 1 ) == 0 );
04265             fct_chk( mpi_mul_mpi( &H, &P1, &Q1 ) == 0 );
04266             fct_chk( mpi_gcd( &G, &ctx.E, &H  ) == 0 );
04267             fct_chk( mpi_inv_mod( &ctx.D , &ctx.E, &H  ) == 0 );
04268             fct_chk( mpi_mod_mpi( &ctx.DP, &ctx.D, &P1 ) == 0 );
04269             fct_chk( mpi_mod_mpi( &ctx.DQ, &ctx.D, &Q1 ) == 0 );
04270             fct_chk( mpi_inv_mod( &ctx.QP, &ctx.Q, &ctx.P ) == 0 );
04271         
04272             fct_chk( rsa_check_privkey( &ctx ) == 0 );
04273         
04274             unhexify( message_str, "a42eda41e56235e666e7faaa77100197f657288a1bf183e4820f0c37ce2c456b960278d6003e0bbcd4be4a969f8e8fd9231e1f492414f00ed09844994c86ec32db7cde3bec7f0c3dbf6ae55baeb2712fa609f5fc3207a824eb3dace31849cd6a6084318523912bccb84cf42e3c6d6d1685131d69bb545acec827d2b0dfdd5568b7dcc4f5a11d6916583fefa689d367f8c9e1d95dcd2240895a9470b0c1730f97cd6e8546860bd254801769f54be96e16362ddcbf34d56035028890199e0f48db38642cb66a4181e028a6443a404fea284ce02b4614b683367d40874e505611d23142d49f06feea831d52d347b13610b413c4efc43a6de9f0b08d2a951dc503b6" );
04275             output_len = 0;
04276         
04277             fct_chk( rsa_pkcs1_decrypt( &ctx, RSA_PRIVATE, &output_len, message_str, output, 1000 ) == 0 );
04278             if( 0 == 0 )
04279             {
04280                 hexify( output_str, output, ctx.len );
04281         
04282                 fct_chk( strncasecmp( (char *) output_str, "4E636AF98E40F3ADCFCCB698F4E80B9F", strlen( "4E636AF98E40F3ADCFCCB698F4E80B9F" ) ) == 0 );
04283             }
04284         
04285             mpi_free( &P1 ); mpi_free( &Q1 ); mpi_free( &H ); mpi_free( &G );
04286         }
04287         FCT_TEST_END();
04288 
04289 
04290         FCT_TEST_BGN(rsa_pkcs1_encrypt_2_data_too_large)
04291         {
04292             unsigned char message_str[1000];
04293             unsigned char output[1000];
04294             unsigned char output_str[1000];
04295             rsa_context ctx;
04296             size_t msg_len;
04297             rnd_pseudo_info rnd_info;
04298         
04299             memset( &rnd_info, 0, sizeof( rnd_pseudo_info ) );
04300         
04301             rsa_init( &ctx, RSA_PKCS_V15, 0 );
04302             memset( message_str, 0x00, 1000 );
04303             memset( output, 0x00, 1000 );
04304             memset( output_str, 0x00, 1000 );
04305         
04306             ctx.len = 2048 / 8;
04307             fct_chk( mpi_read_string( &ctx.N, 16, "b38ac65c8141f7f5c96e14470e851936a67bf94cc6821a39ac12c05f7c0b06d9e6ddba2224703b02e25f31452f9c4a8417b62675fdc6df46b94813bc7b9769a892c482b830bfe0ad42e46668ace68903617faf6681f4babf1cc8e4b0420d3c7f61dc45434c6b54e2c3ee0fc07908509d79c9826e673bf8363255adb0add2401039a7bcd1b4ecf0fbe6ec8369d2da486eec59559dd1d54c9b24190965eafbdab203b35255765261cd0909acf93c3b8b8428cbb448de4715d1b813d0c94829c229543d391ce0adab5351f97a3810c1f73d7b1458b97daed4209c50e16d064d2d5bfda8c23893d755222793146d0a78c3d64f35549141486c3b0961a7b4c1a2034f" ) == 0 );
04308             fct_chk( mpi_read_string( &ctx.E, 16, "3" ) == 0 );
04309         
04310             fct_chk( rsa_check_pubkey( &ctx ) == 0 );
04311         
04312             msg_len = unhexify( message_str, "b38ac65c8141f7f5c96e14470e851936a67bf94cc6821a39ac12c05f7c0b06d9e6ddba2224703b02e25f31452f9c4a8417b62675fdc6df46b94813bc7b9769a892c482b830bfe0ad42e46668ace68903617faf6681f4babf1cc8e4b0420d3c7f61dc45434c6b54e2c3ee0fc07908509d79c9826e673bf8363255adb0add2401039a7bcd1b4ecf0fbe6ec8369d2da486eec59559dd1d54c9b24190965eafbdab203b35255765261cd0909acf93c3b8b8428cbb448de4715d1b813d0c94829c229543d391ce0adab5351f97a3810c1f73d7b1458b97daed4209c50e16d064d2d5bfda8c23893d755222793146d0a78c3d64f35549141486c3b0961a7b4c1a2034f" );
04313         
04314             fct_chk( rsa_pkcs1_encrypt( &ctx, &rnd_pseudo_rand, &rnd_info, RSA_PUBLIC, msg_len, message_str, output ) == POLARSSL_ERR_RSA_BAD_INPUT_DATA );
04315             if( POLARSSL_ERR_RSA_BAD_INPUT_DATA == 0 )
04316             {
04317                 hexify( output_str, output, ctx.len );
04318         
04319                 fct_chk( strcasecmp( (char *) output_str, "a42eda41e56235e666e7faaa77100197f657288a1bf183e4820f0c37ce2c456b960278d6003e0bbcd4be4a969f8e8fd9231e1f492414f00ed09844994c86ec32db7cde3bec7f0c3dbf6ae55baeb2712fa609f5fc3207a824eb3dace31849cd6a6084318523912bccb84cf42e3c6d6d1685131d69bb545acec827d2b0dfdd5568b7dcc4f5a11d6916583fefa689d367f8c9e1d95dcd2240895a9470b0c1730f97cd6e8546860bd254801769f54be96e16362ddcbf34d56035028890199e0f48db38642cb66a4181e028a6443a404fea284ce02b4614b683367d40874e505611d23142d49f06feea831d52d347b13610b413c4efc43a6de9f0b08d2a951dc503b6" ) == 0 );
04320             }
04321         }
04322         FCT_TEST_END();
04323 
04324 
04325         FCT_TEST_BGN(rsa_pkcs1_decrypt_2_data_too_small)
04326         {
04327             unsigned char message_str[1000];
04328             unsigned char output[1000];
04329             unsigned char output_str[1000];
04330             rsa_context ctx;
04331             mpi P1, Q1, H, G;
04332             size_t output_len;
04333         
04334             mpi_init( &P1 ); mpi_init( &Q1 ); mpi_init( &H ); mpi_init( &G );
04335             rsa_init( &ctx, RSA_PKCS_V15, 0 );
04336         
04337             memset( message_str, 0x00, 1000 );
04338             memset( output, 0x00, 1000 );
04339             memset( output_str, 0x00, 1000 );
04340         
04341             ctx.len = 2048 / 8;
04342             fct_chk( mpi_read_string( &ctx.P, 16, "e79a373182bfaa722eb035f772ad2a9464bd842de59432c18bbab3a7dfeae318c9b915ee487861ab665a40bd6cda560152578e8579016c929df99fea05b4d64efca1d543850bc8164b40d71ed7f3fa4105df0fb9b9ad2a18ce182c8a4f4f975bea9aa0b9a1438a27a28e97ac8330ef37383414d1bd64607d6979ac050424fd17" ) == 0 );
04343             fct_chk( mpi_read_string( &ctx.Q, 16, "c6749cbb0db8c5a177672d4728a8b22392b2fc4d3b8361d5c0d5055a1b4e46d821f757c24eef2a51c561941b93b3ace7340074c058c9bb48e7e7414f42c41da4cccb5c2ba91deb30c586b7fb18af12a52995592ad139d3be429add6547e044becedaf31fa3b39421e24ee034fbf367d11f6b8f88ee483d163b431e1654ad3e89" ) == 0 );
04344             fct_chk( mpi_read_string( &ctx.N, 16, "b38ac65c8141f7f5c96e14470e851936a67bf94cc6821a39ac12c05f7c0b06d9e6ddba2224703b02e25f31452f9c4a8417b62675fdc6df46b94813bc7b9769a892c482b830bfe0ad42e46668ace68903617faf6681f4babf1cc8e4b0420d3c7f61dc45434c6b54e2c3ee0fc07908509d79c9826e673bf8363255adb0add2401039a7bcd1b4ecf0fbe6ec8369d2da486eec59559dd1d54c9b24190965eafbdab203b35255765261cd0909acf93c3b8b8428cbb448de4715d1b813d0c94829c229543d391ce0adab5351f97a3810c1f73d7b1458b97daed4209c50e16d064d2d5bfda8c23893d755222793146d0a78c3d64f35549141486c3b0961a7b4c1a2034f" ) == 0 );
04345             fct_chk( mpi_read_string( &ctx.E, 16, "3" ) == 0 );
04346         
04347             fct_chk( mpi_sub_int( &P1, &ctx.P, 1 ) == 0 );
04348             fct_chk( mpi_sub_int( &Q1, &ctx.Q, 1 ) == 0 );
04349             fct_chk( mpi_mul_mpi( &H, &P1, &Q1 ) == 0 );
04350             fct_chk( mpi_gcd( &G, &ctx.E, &H  ) == 0 );
04351             fct_chk( mpi_inv_mod( &ctx.D , &ctx.E, &H  ) == 0 );
04352             fct_chk( mpi_mod_mpi( &ctx.DP, &ctx.D, &P1 ) == 0 );
04353             fct_chk( mpi_mod_mpi( &ctx.DQ, &ctx.D, &Q1 ) == 0 );
04354             fct_chk( mpi_inv_mod( &ctx.QP, &ctx.Q, &ctx.P ) == 0 );
04355         
04356             fct_chk( rsa_check_privkey( &ctx ) == 0 );
04357         
04358             unhexify( message_str, "deadbeafcafedeadbeeffedcba9876" );
04359             output_len = 0;
04360         
04361             fct_chk( rsa_pkcs1_decrypt( &ctx, RSA_PRIVATE, &output_len, message_str, output, 1000 ) == POLARSSL_ERR_RSA_BAD_INPUT_DATA );
04362             if( POLARSSL_ERR_RSA_BAD_INPUT_DATA == 0 )
04363             {
04364                 hexify( output_str, output, ctx.len );
04365         
04366                 fct_chk( strncasecmp( (char *) output_str, "4E636AF98E40F3ADCFCCB698F4E80B9F", strlen( "4E636AF98E40F3ADCFCCB698F4E80B9F" ) ) == 0 );
04367             }
04368         
04369             mpi_free( &P1 ); mpi_free( &Q1 ); mpi_free( &H ); mpi_free( &G );
04370         }
04371         FCT_TEST_END();
04372 
04373 
04374         FCT_TEST_BGN(rsa_pkcs1_encrypt_3_invalid_padding_mode)
04375         {
04376             unsigned char message_str[1000];
04377             unsigned char output[1000];
04378             unsigned char output_str[1000];
04379             rsa_context ctx;
04380             size_t msg_len;
04381             rnd_pseudo_info rnd_info;
04382         
04383             memset( &rnd_info, 0, sizeof( rnd_pseudo_info ) );
04384         
04385             rsa_init( &ctx, 2, 0 );
04386             memset( message_str, 0x00, 1000 );
04387             memset( output, 0x00, 1000 );
04388             memset( output_str, 0x00, 1000 );
04389         
04390             ctx.len = 2048 / 8;
04391             fct_chk( mpi_read_string( &ctx.N, 16, "b38ac65c8141f7f5c96e14470e851936a67bf94cc6821a39ac12c05f7c0b06d9e6ddba2224703b02e25f31452f9c4a8417b62675fdc6df46b94813bc7b9769a892c482b830bfe0ad42e46668ace68903617faf6681f4babf1cc8e4b0420d3c7f61dc45434c6b54e2c3ee0fc07908509d79c9826e673bf8363255adb0add2401039a7bcd1b4ecf0fbe6ec8369d2da486eec59559dd1d54c9b24190965eafbdab203b35255765261cd0909acf93c3b8b8428cbb448de4715d1b813d0c94829c229543d391ce0adab5351f97a3810c1f73d7b1458b97daed4209c50e16d064d2d5bfda8c23893d755222793146d0a78c3d64f35549141486c3b0961a7b4c1a2034f" ) == 0 );
04392             fct_chk( mpi_read_string( &ctx.E, 16, "3" ) == 0 );
04393         
04394             fct_chk( rsa_check_pubkey( &ctx ) == 0 );
04395         
04396             msg_len = unhexify( message_str, "4E636AF98E40F3ADCFCCB698F4E80B9F" );
04397         
04398             fct_chk( rsa_pkcs1_encrypt( &ctx, &rnd_pseudo_rand, &rnd_info, RSA_PUBLIC, msg_len, message_str, output ) == POLARSSL_ERR_RSA_INVALID_PADDING );
04399             if( POLARSSL_ERR_RSA_INVALID_PADDING == 0 )
04400             {
04401                 hexify( output_str, output, ctx.len );
04402         
04403                 fct_chk( strcasecmp( (char *) output_str, "a42eda41e56235e666e7faaa77100197f657288a1bf183e4820f0c37ce2c456b960278d6003e0bbcd4be4a969f8e8fd9231e1f492414f00ed09844994c86ec32db7cde3bec7f0c3dbf6ae55baeb2712fa609f5fc3207a824eb3dace31849cd6a6084318523912bccb84cf42e3c6d6d1685131d69bb545acec827d2b0dfdd5568b7dcc4f5a11d6916583fefa689d367f8c9e1d95dcd2240895a9470b0c1730f97cd6e8546860bd254801769f54be96e16362ddcbf34d56035028890199e0f48db38642cb66a4181e028a6443a404fea284ce02b4614b683367d40874e505611d23142d49f06feea831d52d347b13610b413c4efc43a6de9f0b08d2a951dc503b6" ) == 0 );
04404             }
04405         }
04406         FCT_TEST_END();
04407 
04408 
04409         FCT_TEST_BGN(rsa_pkcs1_decrypt_3_invalid_padding_mode)
04410         {
04411             unsigned char message_str[1000];
04412             unsigned char output[1000];
04413             unsigned char output_str[1000];
04414             rsa_context ctx;
04415             mpi P1, Q1, H, G;
04416             size_t output_len;
04417         
04418             mpi_init( &P1 ); mpi_init( &Q1 ); mpi_init( &H ); mpi_init( &G );
04419             rsa_init( &ctx, 2, 0 );
04420         
04421             memset( message_str, 0x00, 1000 );
04422             memset( output, 0x00, 1000 );
04423             memset( output_str, 0x00, 1000 );
04424         
04425             ctx.len = 2048 / 8;
04426             fct_chk( mpi_read_string( &ctx.P, 16, "e79a373182bfaa722eb035f772ad2a9464bd842de59432c18bbab3a7dfeae318c9b915ee487861ab665a40bd6cda560152578e8579016c929df99fea05b4d64efca1d543850bc8164b40d71ed7f3fa4105df0fb9b9ad2a18ce182c8a4f4f975bea9aa0b9a1438a27a28e97ac8330ef37383414d1bd64607d6979ac050424fd17" ) == 0 );
04427             fct_chk( mpi_read_string( &ctx.Q, 16, "c6749cbb0db8c5a177672d4728a8b22392b2fc4d3b8361d5c0d5055a1b4e46d821f757c24eef2a51c561941b93b3ace7340074c058c9bb48e7e7414f42c41da4cccb5c2ba91deb30c586b7fb18af12a52995592ad139d3be429add6547e044becedaf31fa3b39421e24ee034fbf367d11f6b8f88ee483d163b431e1654ad3e89" ) == 0 );
04428             fct_chk( mpi_read_string( &ctx.N, 16, "b38ac65c8141f7f5c96e14470e851936a67bf94cc6821a39ac12c05f7c0b06d9e6ddba2224703b02e25f31452f9c4a8417b62675fdc6df46b94813bc7b9769a892c482b830bfe0ad42e46668ace68903617faf6681f4babf1cc8e4b0420d3c7f61dc45434c6b54e2c3ee0fc07908509d79c9826e673bf8363255adb0add2401039a7bcd1b4ecf0fbe6ec8369d2da486eec59559dd1d54c9b24190965eafbdab203b35255765261cd0909acf93c3b8b8428cbb448de4715d1b813d0c94829c229543d391ce0adab5351f97a3810c1f73d7b1458b97daed4209c50e16d064d2d5bfda8c23893d755222793146d0a78c3d64f35549141486c3b0961a7b4c1a2034f" ) == 0 );
04429             fct_chk( mpi_read_string( &ctx.E, 16, "3" ) == 0 );
04430         
04431             fct_chk( mpi_sub_int( &P1, &ctx.P, 1 ) == 0 );
04432             fct_chk( mpi_sub_int( &Q1, &ctx.Q, 1 ) == 0 );
04433             fct_chk( mpi_mul_mpi( &H, &P1, &Q1 ) == 0 );
04434             fct_chk( mpi_gcd( &G, &ctx.E, &H  ) == 0 );
04435             fct_chk( mpi_inv_mod( &ctx.D , &ctx.E, &H  ) == 0 );
04436             fct_chk( mpi_mod_mpi( &ctx.DP, &ctx.D, &P1 ) == 0 );
04437             fct_chk( mpi_mod_mpi( &ctx.DQ, &ctx.D, &Q1 ) == 0 );
04438             fct_chk( mpi_inv_mod( &ctx.QP, &ctx.Q, &ctx.P ) == 0 );
04439         
04440             fct_chk( rsa_check_privkey( &ctx ) == 0 );
04441         
04442             unhexify( message_str, "a42eda41e56235e666e7faaa77100197f657288a1bf183e4820f0c37ce2c456b960278d6003e0bbcd4be4a969f8e8fd9231e1f492414f00ed09844994c86ec32db7cde3bec7f0c3dbf6ae55baeb2712fa609f5fc3207a824eb3dace31849cd6a6084318523912bccb84cf42e3c6d6d1685131d69bb545acec827d2b0dfdd5568b7dcc4f5a11d6916583fefa689d367f8c9e1d95dcd2240895a9470b0c1730f97cd6e8546860bd254801769f54be96e16362ddcbf34d56035028890199e0f48db38642cb66a4181e028a6443a404fea284ce02b4614b683367d40874e505611d23142d49f06feea831d52d347b13610b413c4efc43a6de9f0b08d2a951dc503b6" );
04443             output_len = 0;
04444         
04445             fct_chk( rsa_pkcs1_decrypt( &ctx, RSA_PRIVATE, &output_len, message_str, output, 1000 ) == POLARSSL_ERR_RSA_INVALID_PADDING );
04446             if( POLARSSL_ERR_RSA_INVALID_PADDING == 0 )
04447             {
04448                 hexify( output_str, output, ctx.len );
04449         
04450                 fct_chk( strncasecmp( (char *) output_str, "4E636AF98E40F3ADCFCCB698F4E80B9F", strlen( "4E636AF98E40F3ADCFCCB698F4E80B9F" ) ) == 0 );
04451             }
04452         
04453             mpi_free( &P1 ); mpi_free( &Q1 ); mpi_free( &H ); mpi_free( &G );
04454         }
04455         FCT_TEST_END();
04456 
04457 
04458         FCT_TEST_BGN(rsa_pkcs1_decrypt_4_output_buffer_too_small)
04459         {
04460             unsigned char message_str[1000];
04461             unsigned char output[1000];
04462             unsigned char output_str[1000];
04463             rsa_context ctx;
04464             mpi P1, Q1, H, G;
04465             size_t output_len;
04466         
04467             mpi_init( &P1 ); mpi_init( &Q1 ); mpi_init( &H ); mpi_init( &G );
04468             rsa_init( &ctx, RSA_PKCS_V15, 0 );
04469         
04470             memset( message_str, 0x00, 1000 );
04471             memset( output, 0x00, 1000 );
04472             memset( output_str, 0x00, 1000 );
04473         
04474             ctx.len = 2048 / 8;
04475             fct_chk( mpi_read_string( &ctx.P, 16, "e79a373182bfaa722eb035f772ad2a9464bd842de59432c18bbab3a7dfeae318c9b915ee487861ab665a40bd6cda560152578e8579016c929df99fea05b4d64efca1d543850bc8164b40d71ed7f3fa4105df0fb9b9ad2a18ce182c8a4f4f975bea9aa0b9a1438a27a28e97ac8330ef37383414d1bd64607d6979ac050424fd17" ) == 0 );
04476             fct_chk( mpi_read_string( &ctx.Q, 16, "c6749cbb0db8c5a177672d4728a8b22392b2fc4d3b8361d5c0d5055a1b4e46d821f757c24eef2a51c561941b93b3ace7340074c058c9bb48e7e7414f42c41da4cccb5c2ba91deb30c586b7fb18af12a52995592ad139d3be429add6547e044becedaf31fa3b39421e24ee034fbf367d11f6b8f88ee483d163b431e1654ad3e89" ) == 0 );
04477             fct_chk( mpi_read_string( &ctx.N, 16, "b38ac65c8141f7f5c96e14470e851936a67bf94cc6821a39ac12c05f7c0b06d9e6ddba2224703b02e25f31452f9c4a8417b62675fdc6df46b94813bc7b9769a892c482b830bfe0ad42e46668ace68903617faf6681f4babf1cc8e4b0420d3c7f61dc45434c6b54e2c3ee0fc07908509d79c9826e673bf8363255adb0add2401039a7bcd1b4ecf0fbe6ec8369d2da486eec59559dd1d54c9b24190965eafbdab203b35255765261cd0909acf93c3b8b8428cbb448de4715d1b813d0c94829c229543d391ce0adab5351f97a3810c1f73d7b1458b97daed4209c50e16d064d2d5bfda8c23893d755222793146d0a78c3d64f35549141486c3b0961a7b4c1a2034f" ) == 0 );
04478             fct_chk( mpi_read_string( &ctx.E, 16, "3" ) == 0 );
04479         
04480             fct_chk( mpi_sub_int( &P1, &ctx.P, 1 ) == 0 );
04481             fct_chk( mpi_sub_int( &Q1, &ctx.Q, 1 ) == 0 );
04482             fct_chk( mpi_mul_mpi( &H, &P1, &Q1 ) == 0 );
04483             fct_chk( mpi_gcd( &G, &ctx.E, &H  ) == 0 );
04484             fct_chk( mpi_inv_mod( &ctx.D , &ctx.E, &H  ) == 0 );
04485             fct_chk( mpi_mod_mpi( &ctx.DP, &ctx.D, &P1 ) == 0 );
04486             fct_chk( mpi_mod_mpi( &ctx.DQ, &ctx.D, &Q1 ) == 0 );
04487             fct_chk( mpi_inv_mod( &ctx.QP, &ctx.Q, &ctx.P ) == 0 );
04488         
04489             fct_chk( rsa_check_privkey( &ctx ) == 0 );
04490         
04491             unhexify( message_str, "a42eda41e56235e666e7faaa77100197f657288a1bf183e4820f0c37ce2c456b960278d6003e0bbcd4be4a969f8e8fd9231e1f492414f00ed09844994c86ec32db7cde3bec7f0c3dbf6ae55baeb2712fa609f5fc3207a824eb3dace31849cd6a6084318523912bccb84cf42e3c6d6d1685131d69bb545acec827d2b0dfdd5568b7dcc4f5a11d6916583fefa689d367f8c9e1d95dcd2240895a9470b0c1730f97cd6e8546860bd254801769f54be96e16362ddcbf34d56035028890199e0f48db38642cb66a4181e028a6443a404fea284ce02b4614b683367d40874e505611d23142d49f06feea831d52d347b13610b413c4efc43a6de9f0b08d2a951dc503b6" );
04492             output_len = 0;
04493         
04494             fct_chk( rsa_pkcs1_decrypt( &ctx, RSA_PRIVATE, &output_len, message_str, output, 15 ) == POLARSSL_ERR_RSA_OUTPUT_TOO_LARGE );
04495             if( POLARSSL_ERR_RSA_OUTPUT_TOO_LARGE == 0 )
04496             {
04497                 hexify( output_str, output, ctx.len );
04498         
04499                 fct_chk( strncasecmp( (char *) output_str, "4E636AF98E40F3ADCFCCB698F4E80B9F", strlen( "4E636AF98E40F3ADCFCCB698F4E80B9F" ) ) == 0 );
04500             }
04501         
04502             mpi_free( &P1 ); mpi_free( &Q1 ); mpi_free( &H ); mpi_free( &G );
04503         }
04504         FCT_TEST_END();
04505 
04506 
04507         FCT_TEST_BGN(rsa_check_empty_private_key)
04508         {
04509             rsa_context ctx;
04510             memset( &ctx, 0x00, sizeof( rsa_context ) );
04511         
04512             fct_chk( rsa_check_privkey( &ctx ) == POLARSSL_ERR_RSA_KEY_CHECK_FAILED );
04513         }
04514         FCT_TEST_END();
04515 
04516 
04517         FCT_TEST_BGN(rsa_check_private_key_1_correct)
04518         {
04519             rsa_context ctx;
04520         
04521             rsa_init( &ctx, RSA_PKCS_V15, 0 );
04522         
04523             ctx.len = 2048 / 8;
04524             if( strlen( "e79a373182bfaa722eb035f772ad2a9464bd842de59432c18bbab3a7dfeae318c9b915ee487861ab665a40bd6cda560152578e8579016c929df99fea05b4d64efca1d543850bc8164b40d71ed7f3fa4105df0fb9b9ad2a18ce182c8a4f4f975bea9aa0b9a1438a27a28e97ac8330ef37383414d1bd64607d6979ac050424fd17" ) )
04525             {
04526                 fct_chk( mpi_read_string( &ctx.P, 16, "e79a373182bfaa722eb035f772ad2a9464bd842de59432c18bbab3a7dfeae318c9b915ee487861ab665a40bd6cda560152578e8579016c929df99fea05b4d64efca1d543850bc8164b40d71ed7f3fa4105df0fb9b9ad2a18ce182c8a4f4f975bea9aa0b9a1438a27a28e97ac8330ef37383414d1bd64607d6979ac050424fd17" ) == 0 );
04527             }
04528             if( strlen( "c6749cbb0db8c5a177672d4728a8b22392b2fc4d3b8361d5c0d5055a1b4e46d821f757c24eef2a51c561941b93b3ace7340074c058c9bb48e7e7414f42c41da4cccb5c2ba91deb30c586b7fb18af12a52995592ad139d3be429add6547e044becedaf31fa3b39421e24ee034fbf367d11f6b8f88ee483d163b431e1654ad3e89" ) )
04529             {
04530                 fct_chk( mpi_read_string( &ctx.Q, 16, "c6749cbb0db8c5a177672d4728a8b22392b2fc4d3b8361d5c0d5055a1b4e46d821f757c24eef2a51c561941b93b3ace7340074c058c9bb48e7e7414f42c41da4cccb5c2ba91deb30c586b7fb18af12a52995592ad139d3be429add6547e044becedaf31fa3b39421e24ee034fbf367d11f6b8f88ee483d163b431e1654ad3e89" ) == 0 );
04531             }
04532             if( strlen( "b38ac65c8141f7f5c96e14470e851936a67bf94cc6821a39ac12c05f7c0b06d9e6ddba2224703b02e25f31452f9c4a8417b62675fdc6df46b94813bc7b9769a892c482b830bfe0ad42e46668ace68903617faf6681f4babf1cc8e4b0420d3c7f61dc45434c6b54e2c3ee0fc07908509d79c9826e673bf8363255adb0add2401039a7bcd1b4ecf0fbe6ec8369d2da486eec59559dd1d54c9b24190965eafbdab203b35255765261cd0909acf93c3b8b8428cbb448de4715d1b813d0c94829c229543d391ce0adab5351f97a3810c1f73d7b1458b97daed4209c50e16d064d2d5bfda8c23893d755222793146d0a78c3d64f35549141486c3b0961a7b4c1a2034f" ) )
04533             {
04534                 fct_chk( mpi_read_string( &ctx.N, 16, "b38ac65c8141f7f5c96e14470e851936a67bf94cc6821a39ac12c05f7c0b06d9e6ddba2224703b02e25f31452f9c4a8417b62675fdc6df46b94813bc7b9769a892c482b830bfe0ad42e46668ace68903617faf6681f4babf1cc8e4b0420d3c7f61dc45434c6b54e2c3ee0fc07908509d79c9826e673bf8363255adb0add2401039a7bcd1b4ecf0fbe6ec8369d2da486eec59559dd1d54c9b24190965eafbdab203b35255765261cd0909acf93c3b8b8428cbb448de4715d1b813d0c94829c229543d391ce0adab5351f97a3810c1f73d7b1458b97daed4209c50e16d064d2d5bfda8c23893d755222793146d0a78c3d64f35549141486c3b0961a7b4c1a2034f" ) == 0 );
04535             }
04536             if( strlen( "3" ) )
04537             {
04538                 fct_chk( mpi_read_string( &ctx.E, 16, "3" ) == 0 );
04539             }
04540             if( strlen( "77B1D99300D6A54E864962DA09AE10CF19A7FB888456BC2672B72AEA52B204914493D16C184AD201EC3F762E1FBD8702BA796EF953D9EA2F26300D285264F11B0C8301D0207FEB1E2C984445C899B0ACEBAA74EF014DD1D4BDDB43202C08D2FF9692D8D788478DEC829EB52AFB5AE068FBDBAC499A27FACECC391E75C936D55F07BB45EE184DAB45808E15722502F279F89B38C1CB292557E5063597F52C75D61001EDC33F4739353E33E56AD273B067C1A2760208529EA421774A5FFFCB3423B1E0051E7702A55D80CBF2141569F18F87BFF538A1DA8EDBB2693A539F68E0D62D77743F89EACF3B1723BDB25CE2F333FA63CACF0E67DF1A431893BB9B352FCB" ) )
04541             {
04542                 fct_chk( mpi_read_string( &ctx.D, 16, "77B1D99300D6A54E864962DA09AE10CF19A7FB888456BC2672B72AEA52B204914493D16C184AD201EC3F762E1FBD8702BA796EF953D9EA2F26300D285264F11B0C8301D0207FEB1E2C984445C899B0ACEBAA74EF014DD1D4BDDB43202C08D2FF9692D8D788478DEC829EB52AFB5AE068FBDBAC499A27FACECC391E75C936D55F07BB45EE184DAB45808E15722502F279F89B38C1CB292557E5063597F52C75D61001EDC33F4739353E33E56AD273B067C1A2760208529EA421774A5FFFCB3423B1E0051E7702A55D80CBF2141569F18F87BFF538A1DA8EDBB2693A539F68E0D62D77743F89EACF3B1723BDB25CE2F333FA63CACF0E67DF1A431893BB9B352FCB" ) == 0 );
04543             }
04544         
04545             fct_chk( rsa_check_privkey( &ctx ) == 0 );
04546         }
04547         FCT_TEST_END();
04548 
04549 
04550         FCT_TEST_BGN(rsa_check_private_key_2_no_p)
04551         {
04552             rsa_context ctx;
04553         
04554             rsa_init( &ctx, RSA_PKCS_V15, 0 );
04555         
04556             ctx.len = 2048 / 8;
04557             if( strlen( "" ) )
04558             {
04559                 fct_chk( mpi_read_string( &ctx.P, 16, "" ) == 0 );
04560             }
04561             if( strlen( "c6749cbb0db8c5a177672d4728a8b22392b2fc4d3b8361d5c0d5055a1b4e46d821f757c24eef2a51c561941b93b3ace7340074c058c9bb48e7e7414f42c41da4cccb5c2ba91deb30c586b7fb18af12a52995592ad139d3be429add6547e044becedaf31fa3b39421e24ee034fbf367d11f6b8f88ee483d163b431e1654ad3e89" ) )
04562             {
04563                 fct_chk( mpi_read_string( &ctx.Q, 16, "c6749cbb0db8c5a177672d4728a8b22392b2fc4d3b8361d5c0d5055a1b4e46d821f757c24eef2a51c561941b93b3ace7340074c058c9bb48e7e7414f42c41da4cccb5c2ba91deb30c586b7fb18af12a52995592ad139d3be429add6547e044becedaf31fa3b39421e24ee034fbf367d11f6b8f88ee483d163b431e1654ad3e89" ) == 0 );
04564             }
04565             if( strlen( "b38ac65c8141f7f5c96e14470e851936a67bf94cc6821a39ac12c05f7c0b06d9e6ddba2224703b02e25f31452f9c4a8417b62675fdc6df46b94813bc7b9769a892c482b830bfe0ad42e46668ace68903617faf6681f4babf1cc8e4b0420d3c7f61dc45434c6b54e2c3ee0fc07908509d79c9826e673bf8363255adb0add2401039a7bcd1b4ecf0fbe6ec8369d2da486eec59559dd1d54c9b24190965eafbdab203b35255765261cd0909acf93c3b8b8428cbb448de4715d1b813d0c94829c229543d391ce0adab5351f97a3810c1f73d7b1458b97daed4209c50e16d064d2d5bfda8c23893d755222793146d0a78c3d64f35549141486c3b0961a7b4c1a2034f" ) )
04566             {
04567                 fct_chk( mpi_read_string( &ctx.N, 16, "b38ac65c8141f7f5c96e14470e851936a67bf94cc6821a39ac12c05f7c0b06d9e6ddba2224703b02e25f31452f9c4a8417b62675fdc6df46b94813bc7b9769a892c482b830bfe0ad42e46668ace68903617faf6681f4babf1cc8e4b0420d3c7f61dc45434c6b54e2c3ee0fc07908509d79c9826e673bf8363255adb0add2401039a7bcd1b4ecf0fbe6ec8369d2da486eec59559dd1d54c9b24190965eafbdab203b35255765261cd0909acf93c3b8b8428cbb448de4715d1b813d0c94829c229543d391ce0adab5351f97a3810c1f73d7b1458b97daed4209c50e16d064d2d5bfda8c23893d755222793146d0a78c3d64f35549141486c3b0961a7b4c1a2034f" ) == 0 );
04568             }
04569             if( strlen( "3" ) )
04570             {
04571                 fct_chk( mpi_read_string( &ctx.E, 16, "3" ) == 0 );
04572             }
04573             if( strlen( "77B1D99300D6A54E864962DA09AE10CF19A7FB888456BC2672B72AEA52B204914493D16C184AD201EC3F762E1FBD8702BA796EF953D9EA2F26300D285264F11B0C8301D0207FEB1E2C984445C899B0ACEBAA74EF014DD1D4BDDB43202C08D2FF9692D8D788478DEC829EB52AFB5AE068FBDBAC499A27FACECC391E75C936D55F07BB45EE184DAB45808E15722502F279F89B38C1CB292557E5063597F52C75D61001EDC33F4739353E33E56AD273B067C1A2760208529EA421774A5FFFCB3423B1E0051E7702A55D80CBF2141569F18F87BFF538A1DA8EDBB2693A539F68E0D62D77743F89EACF3B1723BDB25CE2F333FA63CACF0E67DF1A431893BB9B352FCB" ) )
04574             {
04575                 fct_chk( mpi_read_string( &ctx.D, 16, "77B1D99300D6A54E864962DA09AE10CF19A7FB888456BC2672B72AEA52B204914493D16C184AD201EC3F762E1FBD8702BA796EF953D9EA2F26300D285264F11B0C8301D0207FEB1E2C984445C899B0ACEBAA74EF014DD1D4BDDB43202C08D2FF9692D8D788478DEC829EB52AFB5AE068FBDBAC499A27FACECC391E75C936D55F07BB45EE184DAB45808E15722502F279F89B38C1CB292557E5063597F52C75D61001EDC33F4739353E33E56AD273B067C1A2760208529EA421774A5FFFCB3423B1E0051E7702A55D80CBF2141569F18F87BFF538A1DA8EDBB2693A539F68E0D62D77743F89EACF3B1723BDB25CE2F333FA63CACF0E67DF1A431893BB9B352FCB" ) == 0 );
04576             }
04577         
04578             fct_chk( rsa_check_privkey( &ctx ) == POLARSSL_ERR_RSA_KEY_CHECK_FAILED );
04579         }
04580         FCT_TEST_END();
04581 
04582 
04583         FCT_TEST_BGN(rsa_check_private_key_3_no_q)
04584         {
04585             rsa_context ctx;
04586         
04587             rsa_init( &ctx, RSA_PKCS_V15, 0 );
04588         
04589             ctx.len = 2048 / 8;
04590             if( strlen( "e79a373182bfaa722eb035f772ad2a9464bd842de59432c18bbab3a7dfeae318c9b915ee487861ab665a40bd6cda560152578e8579016c929df99fea05b4d64efca1d543850bc8164b40d71ed7f3fa4105df0fb9b9ad2a18ce182c8a4f4f975bea9aa0b9a1438a27a28e97ac8330ef37383414d1bd64607d6979ac050424fd17" ) )
04591             {
04592                 fct_chk( mpi_read_string( &ctx.P, 16, "e79a373182bfaa722eb035f772ad2a9464bd842de59432c18bbab3a7dfeae318c9b915ee487861ab665a40bd6cda560152578e8579016c929df99fea05b4d64efca1d543850bc8164b40d71ed7f3fa4105df0fb9b9ad2a18ce182c8a4f4f975bea9aa0b9a1438a27a28e97ac8330ef37383414d1bd64607d6979ac050424fd17" ) == 0 );
04593             }
04594             if( strlen( "" ) )
04595             {
04596                 fct_chk( mpi_read_string( &ctx.Q, 16, "" ) == 0 );
04597             }
04598             if( strlen( "b38ac65c8141f7f5c96e14470e851936a67bf94cc6821a39ac12c05f7c0b06d9e6ddba2224703b02e25f31452f9c4a8417b62675fdc6df46b94813bc7b9769a892c482b830bfe0ad42e46668ace68903617faf6681f4babf1cc8e4b0420d3c7f61dc45434c6b54e2c3ee0fc07908509d79c9826e673bf8363255adb0add2401039a7bcd1b4ecf0fbe6ec8369d2da486eec59559dd1d54c9b24190965eafbdab203b35255765261cd0909acf93c3b8b8428cbb448de4715d1b813d0c94829c229543d391ce0adab5351f97a3810c1f73d7b1458b97daed4209c50e16d064d2d5bfda8c23893d755222793146d0a78c3d64f35549141486c3b0961a7b4c1a2034f" ) )
04599             {
04600                 fct_chk( mpi_read_string( &ctx.N, 16, "b38ac65c8141f7f5c96e14470e851936a67bf94cc6821a39ac12c05f7c0b06d9e6ddba2224703b02e25f31452f9c4a8417b62675fdc6df46b94813bc7b9769a892c482b830bfe0ad42e46668ace68903617faf6681f4babf1cc8e4b0420d3c7f61dc45434c6b54e2c3ee0fc07908509d79c9826e673bf8363255adb0add2401039a7bcd1b4ecf0fbe6ec8369d2da486eec59559dd1d54c9b24190965eafbdab203b35255765261cd0909acf93c3b8b8428cbb448de4715d1b813d0c94829c229543d391ce0adab5351f97a3810c1f73d7b1458b97daed4209c50e16d064d2d5bfda8c23893d755222793146d0a78c3d64f35549141486c3b0961a7b4c1a2034f" ) == 0 );
04601             }
04602             if( strlen( "3" ) )
04603             {
04604                 fct_chk( mpi_read_string( &ctx.E, 16, "3" ) == 0 );
04605             }
04606             if( strlen( "77B1D99300D6A54E864962DA09AE10CF19A7FB888456BC2672B72AEA52B204914493D16C184AD201EC3F762E1FBD8702BA796EF953D9EA2F26300D285264F11B0C8301D0207FEB1E2C984445C899B0ACEBAA74EF014DD1D4BDDB43202C08D2FF9692D8D788478DEC829EB52AFB5AE068FBDBAC499A27FACECC391E75C936D55F07BB45EE184DAB45808E15722502F279F89B38C1CB292557E5063597F52C75D61001EDC33F4739353E33E56AD273B067C1A2760208529EA421774A5FFFCB3423B1E0051E7702A55D80CBF2141569F18F87BFF538A1DA8EDBB2693A539F68E0D62D77743F89EACF3B1723BDB25CE2F333FA63CACF0E67DF1A431893BB9B352FCB" ) )
04607             {
04608                 fct_chk( mpi_read_string( &ctx.D, 16, "77B1D99300D6A54E864962DA09AE10CF19A7FB888456BC2672B72AEA52B204914493D16C184AD201EC3F762E1FBD8702BA796EF953D9EA2F26300D285264F11B0C8301D0207FEB1E2C984445C899B0ACEBAA74EF014DD1D4BDDB43202C08D2FF9692D8D788478DEC829EB52AFB5AE068FBDBAC499A27FACECC391E75C936D55F07BB45EE184DAB45808E15722502F279F89B38C1CB292557E5063597F52C75D61001EDC33F4739353E33E56AD273B067C1A2760208529EA421774A5FFFCB3423B1E0051E7702A55D80CBF2141569F18F87BFF538A1DA8EDBB2693A539F68E0D62D77743F89EACF3B1723BDB25CE2F333FA63CACF0E67DF1A431893BB9B352FCB" ) == 0 );
04609             }
04610         
04611             fct_chk( rsa_check_privkey( &ctx ) == POLARSSL_ERR_RSA_KEY_CHECK_FAILED );
04612         }
04613         FCT_TEST_END();
04614 
04615 
04616         FCT_TEST_BGN(rsa_check_private_key_4_no_n)
04617         {
04618             rsa_context ctx;
04619         
04620             rsa_init( &ctx, RSA_PKCS_V15, 0 );
04621         
04622             ctx.len = 2048 / 8;
04623             if( strlen( "e79a373182bfaa722eb035f772ad2a9464bd842de59432c18bbab3a7dfeae318c9b915ee487861ab665a40bd6cda560152578e8579016c929df99fea05b4d64efca1d543850bc8164b40d71ed7f3fa4105df0fb9b9ad2a18ce182c8a4f4f975bea9aa0b9a1438a27a28e97ac8330ef37383414d1bd64607d6979ac050424fd17" ) )
04624             {
04625                 fct_chk( mpi_read_string( &ctx.P, 16, "e79a373182bfaa722eb035f772ad2a9464bd842de59432c18bbab3a7dfeae318c9b915ee487861ab665a40bd6cda560152578e8579016c929df99fea05b4d64efca1d543850bc8164b40d71ed7f3fa4105df0fb9b9ad2a18ce182c8a4f4f975bea9aa0b9a1438a27a28e97ac8330ef37383414d1bd64607d6979ac050424fd17" ) == 0 );
04626             }
04627             if( strlen( "c6749cbb0db8c5a177672d4728a8b22392b2fc4d3b8361d5c0d5055a1b4e46d821f757c24eef2a51c561941b93b3ace7340074c058c9bb48e7e7414f42c41da4cccb5c2ba91deb30c586b7fb18af12a52995592ad139d3be429add6547e044becedaf31fa3b39421e24ee034fbf367d11f6b8f88ee483d163b431e1654ad3e89" ) )
04628             {
04629                 fct_chk( mpi_read_string( &ctx.Q, 16, "c6749cbb0db8c5a177672d4728a8b22392b2fc4d3b8361d5c0d5055a1b4e46d821f757c24eef2a51c561941b93b3ace7340074c058c9bb48e7e7414f42c41da4cccb5c2ba91deb30c586b7fb18af12a52995592ad139d3be429add6547e044becedaf31fa3b39421e24ee034fbf367d11f6b8f88ee483d163b431e1654ad3e89" ) == 0 );
04630             }
04631             if( strlen( "" ) )
04632             {
04633                 fct_chk( mpi_read_string( &ctx.N, 16, "" ) == 0 );
04634             }
04635             if( strlen( "3" ) )
04636             {
04637                 fct_chk( mpi_read_string( &ctx.E, 16, "3" ) == 0 );
04638             }
04639             if( strlen( "77B1D99300D6A54E864962DA09AE10CF19A7FB888456BC2672B72AEA52B204914493D16C184AD201EC3F762E1FBD8702BA796EF953D9EA2F26300D285264F11B0C8301D0207FEB1E2C984445C899B0ACEBAA74EF014DD1D4BDDB43202C08D2FF9692D8D788478DEC829EB52AFB5AE068FBDBAC499A27FACECC391E75C936D55F07BB45EE184DAB45808E15722502F279F89B38C1CB292557E5063597F52C75D61001EDC33F4739353E33E56AD273B067C1A2760208529EA421774A5FFFCB3423B1E0051E7702A55D80CBF2141569F18F87BFF538A1DA8EDBB2693A539F68E0D62D77743F89EACF3B1723BDB25CE2F333FA63CACF0E67DF1A431893BB9B352FCB" ) )
04640             {
04641                 fct_chk( mpi_read_string( &ctx.D, 16, "77B1D99300D6A54E864962DA09AE10CF19A7FB888456BC2672B72AEA52B204914493D16C184AD201EC3F762E1FBD8702BA796EF953D9EA2F26300D285264F11B0C8301D0207FEB1E2C984445C899B0ACEBAA74EF014DD1D4BDDB43202C08D2FF9692D8D788478DEC829EB52AFB5AE068FBDBAC499A27FACECC391E75C936D55F07BB45EE184DAB45808E15722502F279F89B38C1CB292557E5063597F52C75D61001EDC33F4739353E33E56AD273B067C1A2760208529EA421774A5FFFCB3423B1E0051E7702A55D80CBF2141569F18F87BFF538A1DA8EDBB2693A539F68E0D62D77743F89EACF3B1723BDB25CE2F333FA63CACF0E67DF1A431893BB9B352FCB" ) == 0 );
04642             }
04643         
04644             fct_chk( rsa_check_privkey( &ctx ) == POLARSSL_ERR_RSA_KEY_CHECK_FAILED );
04645         }
04646         FCT_TEST_END();
04647 
04648 
04649         FCT_TEST_BGN(rsa_check_private_key_5_no_e)
04650         {
04651             rsa_context ctx;
04652         
04653             rsa_init( &ctx, RSA_PKCS_V15, 0 );
04654         
04655             ctx.len = 2048 / 8;
04656             if( strlen( "e79a373182bfaa722eb035f772ad2a9464bd842de59432c18bbab3a7dfeae318c9b915ee487861ab665a40bd6cda560152578e8579016c929df99fea05b4d64efca1d543850bc8164b40d71ed7f3fa4105df0fb9b9ad2a18ce182c8a4f4f975bea9aa0b9a1438a27a28e97ac8330ef37383414d1bd64607d6979ac050424fd17" ) )
04657             {
04658                 fct_chk( mpi_read_string( &ctx.P, 16, "e79a373182bfaa722eb035f772ad2a9464bd842de59432c18bbab3a7dfeae318c9b915ee487861ab665a40bd6cda560152578e8579016c929df99fea05b4d64efca1d543850bc8164b40d71ed7f3fa4105df0fb9b9ad2a18ce182c8a4f4f975bea9aa0b9a1438a27a28e97ac8330ef37383414d1bd64607d6979ac050424fd17" ) == 0 );
04659             }
04660             if( strlen( "c6749cbb0db8c5a177672d4728a8b22392b2fc4d3b8361d5c0d5055a1b4e46d821f757c24eef2a51c561941b93b3ace7340074c058c9bb48e7e7414f42c41da4cccb5c2ba91deb30c586b7fb18af12a52995592ad139d3be429add6547e044becedaf31fa3b39421e24ee034fbf367d11f6b8f88ee483d163b431e1654ad3e89" ) )
04661             {
04662                 fct_chk( mpi_read_string( &ctx.Q, 16, "c6749cbb0db8c5a177672d4728a8b22392b2fc4d3b8361d5c0d5055a1b4e46d821f757c24eef2a51c561941b93b3ace7340074c058c9bb48e7e7414f42c41da4cccb5c2ba91deb30c586b7fb18af12a52995592ad139d3be429add6547e044becedaf31fa3b39421e24ee034fbf367d11f6b8f88ee483d163b431e1654ad3e89" ) == 0 );
04663             }
04664             if( strlen( "b38ac65c8141f7f5c96e14470e851936a67bf94cc6821a39ac12c05f7c0b06d9e6ddba2224703b02e25f31452f9c4a8417b62675fdc6df46b94813bc7b9769a892c482b830bfe0ad42e46668ace68903617faf6681f4babf1cc8e4b0420d3c7f61dc45434c6b54e2c3ee0fc07908509d79c9826e673bf8363255adb0add2401039a7bcd1b4ecf0fbe6ec8369d2da486eec59559dd1d54c9b24190965eafbdab203b35255765261cd0909acf93c3b8b8428cbb448de4715d1b813d0c94829c229543d391ce0adab5351f97a3810c1f73d7b1458b97daed4209c50e16d064d2d5bfda8c23893d755222793146d0a78c3d64f35549141486c3b0961a7b4c1a2034f" ) )
04665             {
04666                 fct_chk( mpi_read_string( &ctx.N, 16, "b38ac65c8141f7f5c96e14470e851936a67bf94cc6821a39ac12c05f7c0b06d9e6ddba2224703b02e25f31452f9c4a8417b62675fdc6df46b94813bc7b9769a892c482b830bfe0ad42e46668ace68903617faf6681f4babf1cc8e4b0420d3c7f61dc45434c6b54e2c3ee0fc07908509d79c9826e673bf8363255adb0add2401039a7bcd1b4ecf0fbe6ec8369d2da486eec59559dd1d54c9b24190965eafbdab203b35255765261cd0909acf93c3b8b8428cbb448de4715d1b813d0c94829c229543d391ce0adab5351f97a3810c1f73d7b1458b97daed4209c50e16d064d2d5bfda8c23893d755222793146d0a78c3d64f35549141486c3b0961a7b4c1a2034f" ) == 0 );
04667             }
04668             if( strlen( "" ) )
04669             {
04670                 fct_chk( mpi_read_string( &ctx.E, 16, "" ) == 0 );
04671             }
04672             if( strlen( "77B1D99300D6A54E864962DA09AE10CF19A7FB888456BC2672B72AEA52B204914493D16C184AD201EC3F762E1FBD8702BA796EF953D9EA2F26300D285264F11B0C8301D0207FEB1E2C984445C899B0ACEBAA74EF014DD1D4BDDB43202C08D2FF9692D8D788478DEC829EB52AFB5AE068FBDBAC499A27FACECC391E75C936D55F07BB45EE184DAB45808E15722502F279F89B38C1CB292557E5063597F52C75D61001EDC33F4739353E33E56AD273B067C1A2760208529EA421774A5FFFCB3423B1E0051E7702A55D80CBF2141569F18F87BFF538A1DA8EDBB2693A539F68E0D62D77743F89EACF3B1723BDB25CE2F333FA63CACF0E67DF1A431893BB9B352FCB" ) )
04673             {
04674                 fct_chk( mpi_read_string( &ctx.D, 16, "77B1D99300D6A54E864962DA09AE10CF19A7FB888456BC2672B72AEA52B204914493D16C184AD201EC3F762E1FBD8702BA796EF953D9EA2F26300D285264F11B0C8301D0207FEB1E2C984445C899B0ACEBAA74EF014DD1D4BDDB43202C08D2FF9692D8D788478DEC829EB52AFB5AE068FBDBAC499A27FACECC391E75C936D55F07BB45EE184DAB45808E15722502F279F89B38C1CB292557E5063597F52C75D61001EDC33F4739353E33E56AD273B067C1A2760208529EA421774A5FFFCB3423B1E0051E7702A55D80CBF2141569F18F87BFF538A1DA8EDBB2693A539F68E0D62D77743F89EACF3B1723BDB25CE2F333FA63CACF0E67DF1A431893BB9B352FCB" ) == 0 );
04675             }
04676         
04677             fct_chk( rsa_check_privkey( &ctx ) == POLARSSL_ERR_RSA_KEY_CHECK_FAILED );
04678         }
04679         FCT_TEST_END();
04680 
04681 
04682         FCT_TEST_BGN(rsa_check_private_key_6_no_d)
04683         {
04684             rsa_context ctx;
04685         
04686             rsa_init( &ctx, RSA_PKCS_V15, 0 );
04687         
04688             ctx.len = 2048 / 8;
04689             if( strlen( "e79a373182bfaa722eb035f772ad2a9464bd842de59432c18bbab3a7dfeae318c9b915ee487861ab665a40bd6cda560152578e8579016c929df99fea05b4d64efca1d543850bc8164b40d71ed7f3fa4105df0fb9b9ad2a18ce182c8a4f4f975bea9aa0b9a1438a27a28e97ac8330ef37383414d1bd64607d6979ac050424fd17" ) )
04690             {
04691                 fct_chk( mpi_read_string( &ctx.P, 16, "e79a373182bfaa722eb035f772ad2a9464bd842de59432c18bbab3a7dfeae318c9b915ee487861ab665a40bd6cda560152578e8579016c929df99fea05b4d64efca1d543850bc8164b40d71ed7f3fa4105df0fb9b9ad2a18ce182c8a4f4f975bea9aa0b9a1438a27a28e97ac8330ef37383414d1bd64607d6979ac050424fd17" ) == 0 );
04692             }
04693             if( strlen( "c6749cbb0db8c5a177672d4728a8b22392b2fc4d3b8361d5c0d5055a1b4e46d821f757c24eef2a51c561941b93b3ace7340074c058c9bb48e7e7414f42c41da4cccb5c2ba91deb30c586b7fb18af12a52995592ad139d3be429add6547e044becedaf31fa3b39421e24ee034fbf367d11f6b8f88ee483d163b431e1654ad3e89" ) )
04694             {
04695                 fct_chk( mpi_read_string( &ctx.Q, 16, "c6749cbb0db8c5a177672d4728a8b22392b2fc4d3b8361d5c0d5055a1b4e46d821f757c24eef2a51c561941b93b3ace7340074c058c9bb48e7e7414f42c41da4cccb5c2ba91deb30c586b7fb18af12a52995592ad139d3be429add6547e044becedaf31fa3b39421e24ee034fbf367d11f6b8f88ee483d163b431e1654ad3e89" ) == 0 );
04696             }
04697             if( strlen( "b38ac65c8141f7f5c96e14470e851936a67bf94cc6821a39ac12c05f7c0b06d9e6ddba2224703b02e25f31452f9c4a8417b62675fdc6df46b94813bc7b9769a892c482b830bfe0ad42e46668ace68903617faf6681f4babf1cc8e4b0420d3c7f61dc45434c6b54e2c3ee0fc07908509d79c9826e673bf8363255adb0add2401039a7bcd1b4ecf0fbe6ec8369d2da486eec59559dd1d54c9b24190965eafbdab203b35255765261cd0909acf93c3b8b8428cbb448de4715d1b813d0c94829c229543d391ce0adab5351f97a3810c1f73d7b1458b97daed4209c50e16d064d2d5bfda8c23893d755222793146d0a78c3d64f35549141486c3b0961a7b4c1a2034f" ) )
04698             {
04699                 fct_chk( mpi_read_string( &ctx.N, 16, "b38ac65c8141f7f5c96e14470e851936a67bf94cc6821a39ac12c05f7c0b06d9e6ddba2224703b02e25f31452f9c4a8417b62675fdc6df46b94813bc7b9769a892c482b830bfe0ad42e46668ace68903617faf6681f4babf1cc8e4b0420d3c7f61dc45434c6b54e2c3ee0fc07908509d79c9826e673bf8363255adb0add2401039a7bcd1b4ecf0fbe6ec8369d2da486eec59559dd1d54c9b24190965eafbdab203b35255765261cd0909acf93c3b8b8428cbb448de4715d1b813d0c94829c229543d391ce0adab5351f97a3810c1f73d7b1458b97daed4209c50e16d064d2d5bfda8c23893d755222793146d0a78c3d64f35549141486c3b0961a7b4c1a2034f" ) == 0 );
04700             }
04701             if( strlen( "3" ) )
04702             {
04703                 fct_chk( mpi_read_string( &ctx.E, 16, "3" ) == 0 );
04704             }
04705             if( strlen( "" ) )
04706             {
04707                 fct_chk( mpi_read_string( &ctx.D, 16, "" ) == 0 );
04708             }
04709         
04710             fct_chk( rsa_check_privkey( &ctx ) == POLARSSL_ERR_RSA_KEY_CHECK_FAILED );
04711         }
04712         FCT_TEST_END();
04713 
04714 
04715         FCT_TEST_BGN(rsa_check_private_key_7_incorrect)
04716         {
04717             rsa_context ctx;
04718         
04719             rsa_init( &ctx, RSA_PKCS_V15, 0 );
04720         
04721             ctx.len = 2048 / 8;
04722             if( strlen( "e79a373182bfaa722eb035f772ad2a9464bd842de59432c18bbab3a7dfeae318c9b915ee487861ab665a40bd6cda560152578e8579016c929df99fea05b4d64efca1d543850bc8164b40d71ed7f3fa4105df0fb9b9ad2a18ce182c8a4f4f975bea9aa0b9a1438a27a28e97ac8330ef37383414d1bd64607d6979ac050424fd17" ) )
04723             {
04724                 fct_chk( mpi_read_string( &ctx.P, 16, "e79a373182bfaa722eb035f772ad2a9464bd842de59432c18bbab3a7dfeae318c9b915ee487861ab665a40bd6cda560152578e8579016c929df99fea05b4d64efca1d543850bc8164b40d71ed7f3fa4105df0fb9b9ad2a18ce182c8a4f4f975bea9aa0b9a1438a27a28e97ac8330ef37383414d1bd64607d6979ac050424fd17" ) == 0 );
04725             }
04726             if( strlen( "c6749cbb0db8c5a177672d4728a8b22392b2fc4d3b8361d5c0d5055a1b4e46d821f757c24eef2a51c561941b93b3ace7340074c058c9bb48e7e7414f42c41da4cccb5c2ba91deb30c586b7fb18af12a52995592ad139d3be429add6547e044becedaf31fa3b39421e24ee034fbf367d11f6b8f88ee483d163b431e1654ad3e89" ) )
04727             {
04728                 fct_chk( mpi_read_string( &ctx.Q, 16, "c6749cbb0db8c5a177672d4728a8b22392b2fc4d3b8361d5c0d5055a1b4e46d821f757c24eef2a51c561941b93b3ace7340074c058c9bb48e7e7414f42c41da4cccb5c2ba91deb30c586b7fb18af12a52995592ad139d3be429add6547e044becedaf31fa3b39421e24ee034fbf367d11f6b8f88ee483d163b431e1654ad3e89" ) == 0 );
04729             }
04730             if( strlen( "b38ac65c8141f7f5c96e14470e851936a67bf94cc6821a39ac12c05f7c0b06d9e6ddba2224703b02e25f31452f9c4a8417b62675fdc6df46b94813bc7b9769a892c482b830bfe0ad42e46668ace68903617faf6681f4babf1cc8e4b0420d3c7f61dc45434c6b54e2c3ee0fc07908509d79c9826e673bf8363255adb0add2401039a7bcd1b4ecf0fbe6ec8369d2da486eec59559dd1d54c9b24190965eafbdab203b35255765261cd0909acf93c3b8b8428cbb448de4715d1b813d0c94829c229543d391ce0adab5351f97a3810c1f73d7b1458b97daed4209c50e16d064d2d5bfda8c23893d755222793146d0a78c3d64f35549141486c3b0961a7b4c1a2034f" ) )
04731             {
04732                 fct_chk( mpi_read_string( &ctx.N, 16, "b38ac65c8141f7f5c96e14470e851936a67bf94cc6821a39ac12c05f7c0b06d9e6ddba2224703b02e25f31452f9c4a8417b62675fdc6df46b94813bc7b9769a892c482b830bfe0ad42e46668ace68903617faf6681f4babf1cc8e4b0420d3c7f61dc45434c6b54e2c3ee0fc07908509d79c9826e673bf8363255adb0add2401039a7bcd1b4ecf0fbe6ec8369d2da486eec59559dd1d54c9b24190965eafbdab203b35255765261cd0909acf93c3b8b8428cbb448de4715d1b813d0c94829c229543d391ce0adab5351f97a3810c1f73d7b1458b97daed4209c50e16d064d2d5bfda8c23893d755222793146d0a78c3d64f35549141486c3b0961a7b4c1a2034f" ) == 0 );
04733             }
04734             if( strlen( "3" ) )
04735             {
04736                 fct_chk( mpi_read_string( &ctx.E, 16, "3" ) == 0 );
04737             }
04738             if( strlen( "77B1D99300D6A54E864962DA09AE10CF19A7FB888456BC2672B72AEA52B204914493D16C184AD201EC3F762E1FBD8702BA796EF953D9EA2F26300D285264F11B0C8301D0207FEB1E2C984445C899B0ACEBAA74EF014DD1D4BDDB43202C08D2FF9692D8D788478DEC829EB52AFB5AE068FBDBAC499A27FACECC391E75C936D55F07BB45EE184DAB45808E15722502F279F89B38C1CB292557E5063597F52C75D61001EDC33F4739353E33E56AD273B067C1A2760208529EA421774A5FFFCB3423B1E0051E7702A55D80CBF2141569F18F87BFF538A1DA8EDBB2693A539F68E0D62D77743F89EACF3B1723BDB25CE2F333FA63CACF0E67DF1A431893BB9B352FCC" ) )
04739             {
04740                 fct_chk( mpi_read_string( &ctx.D, 16, "77B1D99300D6A54E864962DA09AE10CF19A7FB888456BC2672B72AEA52B204914493D16C184AD201EC3F762E1FBD8702BA796EF953D9EA2F26300D285264F11B0C8301D0207FEB1E2C984445C899B0ACEBAA74EF014DD1D4BDDB43202C08D2FF9692D8D788478DEC829EB52AFB5AE068FBDBAC499A27FACECC391E75C936D55F07BB45EE184DAB45808E15722502F279F89B38C1CB292557E5063597F52C75D61001EDC33F4739353E33E56AD273B067C1A2760208529EA421774A5FFFCB3423B1E0051E7702A55D80CBF2141569F18F87BFF538A1DA8EDBB2693A539F68E0D62D77743F89EACF3B1723BDB25CE2F333FA63CACF0E67DF1A431893BB9B352FCC" ) == 0 );
04741             }
04742         
04743             fct_chk( rsa_check_privkey( &ctx ) == POLARSSL_ERR_RSA_KEY_CHECK_FAILED );
04744         }
04745         FCT_TEST_END();
04746 
04747 
04748         FCT_TEST_BGN(rsa_check_public_key_1_correct)
04749         {
04750             rsa_context ctx;
04751         
04752             rsa_init( &ctx, RSA_PKCS_V15, 0 );
04753         
04754             if( strlen( "b38ac65c8141f7f5c96e14470e851936a67bf94cc6821a39ac12c05f7c0b06d9e6ddba2224703b02e25f31452f9c4a8417b62675fdc6df46b94813bc7b9769a892c482b830bfe0ad42e46668ace68903617faf6681f4babf1cc8e4b0420d3c7f61dc45434c6b54e2c3ee0fc07908509d79c9826e673bf8363255adb0add2401039a7bcd1b4ecf0fbe6ec8369d2da486eec59559dd1d54c9b24190965eafbdab203b35255765261cd0909acf93c3b8b8428cbb448de4715d1b813d0c94829c229543d391ce0adab5351f97a3810c1f73d7b1458b97daed4209c50e16d064d2d5bfda8c23893d755222793146d0a78c3d64f35549141486c3b0961a7b4c1a2034f" ) )
04755             {
04756                 fct_chk( mpi_read_string( &ctx.N, 16, "b38ac65c8141f7f5c96e14470e851936a67bf94cc6821a39ac12c05f7c0b06d9e6ddba2224703b02e25f31452f9c4a8417b62675fdc6df46b94813bc7b9769a892c482b830bfe0ad42e46668ace68903617faf6681f4babf1cc8e4b0420d3c7f61dc45434c6b54e2c3ee0fc07908509d79c9826e673bf8363255adb0add2401039a7bcd1b4ecf0fbe6ec8369d2da486eec59559dd1d54c9b24190965eafbdab203b35255765261cd0909acf93c3b8b8428cbb448de4715d1b813d0c94829c229543d391ce0adab5351f97a3810c1f73d7b1458b97daed4209c50e16d064d2d5bfda8c23893d755222793146d0a78c3d64f35549141486c3b0961a7b4c1a2034f" ) == 0 );
04757             }
04758             if( strlen( "3" ) )
04759             {
04760                 fct_chk( mpi_read_string( &ctx.E, 16, "3" ) == 0 );
04761             }
04762         
04763             fct_chk( rsa_check_pubkey( &ctx ) == 0 );
04764         }
04765         FCT_TEST_END();
04766 
04767 
04768         FCT_TEST_BGN(rsa_check_public_key_2_even_n)
04769         {
04770             rsa_context ctx;
04771         
04772             rsa_init( &ctx, RSA_PKCS_V15, 0 );
04773         
04774             if( strlen( "b38ac65c8141f7f5c96e14470e851936a67bf94cc6821a39ac12c05f7c0b06d9e6ddba2224703b02e25f31452f9c4a8417b62675fdc6df46b94813bc7b9769a892c482b830bfe0ad42e46668ace68903617faf6681f4babf1cc8e4b0420d3c7f61dc45434c6b54e2c3ee0fc07908509d79c9826e673bf8363255adb0add2401039a7bcd1b4ecf0fbe6ec8369d2da486eec59559dd1d54c9b24190965eafbdab203b35255765261cd0909acf93c3b8b8428cbb448de4715d1b813d0c94829c229543d391ce0adab5351f97a3810c1f73d7b1458b97daed4209c50e16d064d2d5bfda8c23893d755222793146d0a78c3d64f35549141486c3b0961a7b4c1a20340" ) )
04775             {
04776                 fct_chk( mpi_read_string( &ctx.N, 16, "b38ac65c8141f7f5c96e14470e851936a67bf94cc6821a39ac12c05f7c0b06d9e6ddba2224703b02e25f31452f9c4a8417b62675fdc6df46b94813bc7b9769a892c482b830bfe0ad42e46668ace68903617faf6681f4babf1cc8e4b0420d3c7f61dc45434c6b54e2c3ee0fc07908509d79c9826e673bf8363255adb0add2401039a7bcd1b4ecf0fbe6ec8369d2da486eec59559dd1d54c9b24190965eafbdab203b35255765261cd0909acf93c3b8b8428cbb448de4715d1b813d0c94829c229543d391ce0adab5351f97a3810c1f73d7b1458b97daed4209c50e16d064d2d5bfda8c23893d755222793146d0a78c3d64f35549141486c3b0961a7b4c1a20340" ) == 0 );
04777             }
04778             if( strlen( "3" ) )
04779             {
04780                 fct_chk( mpi_read_string( &ctx.E, 16, "3" ) == 0 );
04781             }
04782         
04783             fct_chk( rsa_check_pubkey( &ctx ) == POLARSSL_ERR_RSA_KEY_CHECK_FAILED );
04784         }
04785         FCT_TEST_END();
04786 
04787 
04788         FCT_TEST_BGN(rsa_check_public_key_3_even_e)
04789         {
04790             rsa_context ctx;
04791         
04792             rsa_init( &ctx, RSA_PKCS_V15, 0 );
04793         
04794             if( strlen( "b38ac65c8141f7f5c96e14470e851936a67bf94cc6821a39ac12c05f7c0b06d9e6ddba2224703b02e25f31452f9c4a8417b62675fdc6df46b94813bc7b9769a892c482b830bfe0ad42e46668ace68903617faf6681f4babf1cc8e4b0420d3c7f61dc45434c6b54e2c3ee0fc07908509d79c9826e673bf8363255adb0add2401039a7bcd1b4ecf0fbe6ec8369d2da486eec59559dd1d54c9b24190965eafbdab203b35255765261cd0909acf93c3b8b8428cbb448de4715d1b813d0c94829c229543d391ce0adab5351f97a3810c1f73d7b1458b97daed4209c50e16d064d2d5bfda8c23893d755222793146d0a78c3d64f35549141486c3b0961a7b4c1a20340" ) )
04795             {
04796                 fct_chk( mpi_read_string( &ctx.N, 16, "b38ac65c8141f7f5c96e14470e851936a67bf94cc6821a39ac12c05f7c0b06d9e6ddba2224703b02e25f31452f9c4a8417b62675fdc6df46b94813bc7b9769a892c482b830bfe0ad42e46668ace68903617faf6681f4babf1cc8e4b0420d3c7f61dc45434c6b54e2c3ee0fc07908509d79c9826e673bf8363255adb0add2401039a7bcd1b4ecf0fbe6ec8369d2da486eec59559dd1d54c9b24190965eafbdab203b35255765261cd0909acf93c3b8b8428cbb448de4715d1b813d0c94829c229543d391ce0adab5351f97a3810c1f73d7b1458b97daed4209c50e16d064d2d5bfda8c23893d755222793146d0a78c3d64f35549141486c3b0961a7b4c1a20340" ) == 0 );
04797             }
04798             if( strlen( "65536" ) )
04799             {
04800                 fct_chk( mpi_read_string( &ctx.E, 16, "65536" ) == 0 );
04801             }
04802         
04803             fct_chk( rsa_check_pubkey( &ctx ) == POLARSSL_ERR_RSA_KEY_CHECK_FAILED );
04804         }
04805         FCT_TEST_END();
04806 
04807 
04808         FCT_TEST_BGN(rsa_check_public_key_4_n_exactly_128_bits)
04809         {
04810             rsa_context ctx;
04811         
04812             rsa_init( &ctx, RSA_PKCS_V15, 0 );
04813         
04814             if( strlen( "fedcba9876543210deadbeefcafe4321" ) )
04815             {
04816                 fct_chk( mpi_read_string( &ctx.N, 16, "fedcba9876543210deadbeefcafe4321" ) == 0 );
04817             }
04818             if( strlen( "3" ) )
04819             {
04820                 fct_chk( mpi_read_string( &ctx.E, 16, "3" ) == 0 );
04821             }
04822         
04823             fct_chk( rsa_check_pubkey( &ctx ) == 0 );
04824         }
04825         FCT_TEST_END();
04826 
04827 
04828         FCT_TEST_BGN(rsa_check_public_key_5_n_smaller_than_128_bits)
04829         {
04830             rsa_context ctx;
04831         
04832             rsa_init( &ctx, RSA_PKCS_V15, 0 );
04833         
04834             if( strlen( "7edcba9876543210deadbeefcafe4321" ) )
04835             {
04836                 fct_chk( mpi_read_string( &ctx.N, 16, "7edcba9876543210deadbeefcafe4321" ) == 0 );
04837             }
04838             if( strlen( "3" ) )
04839             {
04840                 fct_chk( mpi_read_string( &ctx.E, 16, "3" ) == 0 );
04841             }
04842         
04843             fct_chk( rsa_check_pubkey( &ctx ) == POLARSSL_ERR_RSA_KEY_CHECK_FAILED );
04844         }
04845         FCT_TEST_END();
04846 
04847 
04848         FCT_TEST_BGN(rsa_check_public_key_6_n_exactly_4096_bits)
04849         {
04850             rsa_context ctx;
04851         
04852             rsa_init( &ctx, RSA_PKCS_V15, 0 );
04853         
04854             if( strlen( "00b38ac65c8141f7f5c96e14470e851936a67bf94cc6821a39ac12c05f7c0b06d9e6ddba2224703b02e25f31452f9c4a8417b62675fdc6df46b94813bc7b9769a892c482b830bfe0ad42e46668ace68903617faf6681f4babf1cc8e4b0420d3c7f61dc45434c6b54e2c3ee0fc07908509d79c9826e673bf8363255adb0add2401039a7bcd1b4ecf0fbe6ec8369d2da486eec59559dd1d54c9b24190965eafbdab203b35255765261cd0909acf93c3b8b8428cbb448de4715d1b813d0c94829c229543d391ce0adab5351f97a3810c1f73d7b1458b97daed4209c50e16d064d2d5bfda8c23893d755222793146d0a78c3d64f35549141486c3b0961a7b4c1a2034fb38ac65c8141f7f5c96e14470e851936a67bf94cc6821a39ac12c05f7c0b06d9e6ddba2224703b02e25f31452f9c4a8417b62675fdc6df46b94813bc7b9769a892c482b830bfe0ad42e46668ace68903617faf6681f4babf1cc8e4b0420d3c7f61dc45434c6b54e2c3ee0fc07908509d79c9826e673bf8363255adb0add2401039a7bcd1b4ecf0fbe6ec8369d2da486eec59559dd1d54c9b24190965eafbdab203b35255765261cd0909acf93c3b8b8428cbb448de4715d1b813d0c94829c229543d391ce0adab5351f97a3810c1f73d7b1458b97daed4209c50e16d064d2d5bfda8c23893d755222793146d0a78c3d64f35549141486c3b0961a7b4c1a2034f" ) )
04855             {
04856                 fct_chk( mpi_read_string( &ctx.N, 16, "00b38ac65c8141f7f5c96e14470e851936a67bf94cc6821a39ac12c05f7c0b06d9e6ddba2224703b02e25f31452f9c4a8417b62675fdc6df46b94813bc7b9769a892c482b830bfe0ad42e46668ace68903617faf6681f4babf1cc8e4b0420d3c7f61dc45434c6b54e2c3ee0fc07908509d79c9826e673bf8363255adb0add2401039a7bcd1b4ecf0fbe6ec8369d2da486eec59559dd1d54c9b24190965eafbdab203b35255765261cd0909acf93c3b8b8428cbb448de4715d1b813d0c94829c229543d391ce0adab5351f97a3810c1f73d7b1458b97daed4209c50e16d064d2d5bfda8c23893d755222793146d0a78c3d64f35549141486c3b0961a7b4c1a2034fb38ac65c8141f7f5c96e14470e851936a67bf94cc6821a39ac12c05f7c0b06d9e6ddba2224703b02e25f31452f9c4a8417b62675fdc6df46b94813bc7b9769a892c482b830bfe0ad42e46668ace68903617faf6681f4babf1cc8e4b0420d3c7f61dc45434c6b54e2c3ee0fc07908509d79c9826e673bf8363255adb0add2401039a7bcd1b4ecf0fbe6ec8369d2da486eec59559dd1d54c9b24190965eafbdab203b35255765261cd0909acf93c3b8b8428cbb448de4715d1b813d0c94829c229543d391ce0adab5351f97a3810c1f73d7b1458b97daed4209c50e16d064d2d5bfda8c23893d755222793146d0a78c3d64f35549141486c3b0961a7b4c1a2034f" ) == 0 );
04857             }
04858             if( strlen( "3" ) )
04859             {
04860                 fct_chk( mpi_read_string( &ctx.E, 16, "3" ) == 0 );
04861             }
04862         
04863             fct_chk( rsa_check_pubkey( &ctx ) == 0 );
04864         }
04865         FCT_TEST_END();
04866 
04867 
04868         FCT_TEST_BGN(rsa_check_public_key_7_n_larger_than_4096_bits)
04869         {
04870             rsa_context ctx;
04871         
04872             rsa_init( &ctx, RSA_PKCS_V15, 0 );
04873         
04874             if( strlen( "01b38ac65c8141f7f5c96e14470e851936a67bf94cc6821a39ac12c05f7c0b06d9e6ddba2224703b02e25f31452f9c4a8417b62675fdc6df46b94813bc7b9769a892c482b830bfe0ad42e46668ace68903617faf6681f4babf1cc8e4b0420d3c7f61dc45434c6b54e2c3ee0fc07908509d79c9826e673bf8363255adb0add2401039a7bcd1b4ecf0fbe6ec8369d2da486eec59559dd1d54c9b24190965eafbdab203b35255765261cd0909acf93c3b8b8428cbb448de4715d1b813d0c94829c229543d391ce0adab5351f97a3810c1f73d7b1458b97daed4209c50e16d064d2d5bfda8c23893d755222793146d0a78c3d64f35549141486c3b0961a7b4c1a2034fb38ac65c8141f7f5c96e14470e851936a67bf94cc6821a39ac12c05f7c0b06d9e6ddba2224703b02e25f31452f9c4a8417b62675fdc6df46b94813bc7b9769a892c482b830bfe0ad42e46668ace68903617faf6681f4babf1cc8e4b0420d3c7f61dc45434c6b54e2c3ee0fc07908509d79c9826e673bf8363255adb0add2401039a7bcd1b4ecf0fbe6ec8369d2da486eec59559dd1d54c9b24190965eafbdab203b35255765261cd0909acf93c3b8b8428cbb448de4715d1b813d0c94829c229543d391ce0adab5351f97a3810c1f73d7b1458b97daed4209c50e16d064d2d5bfda8c23893d755222793146d0a78c3d64f35549141486c3b0961a7b4c1a2034f" ) )
04875             {
04876                 fct_chk( mpi_read_string( &ctx.N, 16, "01b38ac65c8141f7f5c96e14470e851936a67bf94cc6821a39ac12c05f7c0b06d9e6ddba2224703b02e25f31452f9c4a8417b62675fdc6df46b94813bc7b9769a892c482b830bfe0ad42e46668ace68903617faf6681f4babf1cc8e4b0420d3c7f61dc45434c6b54e2c3ee0fc07908509d79c9826e673bf8363255adb0add2401039a7bcd1b4ecf0fbe6ec8369d2da486eec59559dd1d54c9b24190965eafbdab203b35255765261cd0909acf93c3b8b8428cbb448de4715d1b813d0c94829c229543d391ce0adab5351f97a3810c1f73d7b1458b97daed4209c50e16d064d2d5bfda8c23893d755222793146d0a78c3d64f35549141486c3b0961a7b4c1a2034fb38ac65c8141f7f5c96e14470e851936a67bf94cc6821a39ac12c05f7c0b06d9e6ddba2224703b02e25f31452f9c4a8417b62675fdc6df46b94813bc7b9769a892c482b830bfe0ad42e46668ace68903617faf6681f4babf1cc8e4b0420d3c7f61dc45434c6b54e2c3ee0fc07908509d79c9826e673bf8363255adb0add2401039a7bcd1b4ecf0fbe6ec8369d2da486eec59559dd1d54c9b24190965eafbdab203b35255765261cd0909acf93c3b8b8428cbb448de4715d1b813d0c94829c229543d391ce0adab5351f97a3810c1f73d7b1458b97daed4209c50e16d064d2d5bfda8c23893d755222793146d0a78c3d64f35549141486c3b0961a7b4c1a2034f" ) == 0 );
04877             }
04878             if( strlen( "3" ) )
04879             {
04880                 fct_chk( mpi_read_string( &ctx.E, 16, "3" ) == 0 );
04881             }
04882         
04883             fct_chk( rsa_check_pubkey( &ctx ) == POLARSSL_ERR_RSA_KEY_CHECK_FAILED );
04884         }
04885         FCT_TEST_END();
04886 
04887 
04888         FCT_TEST_BGN(rsa_check_public_key_8_e_exactly_2_bits)
04889         {
04890             rsa_context ctx;
04891         
04892             rsa_init( &ctx, RSA_PKCS_V15, 0 );
04893         
04894             if( strlen( "fedcba9876543210deadbeefcafe4321" ) )
04895             {
04896                 fct_chk( mpi_read_string( &ctx.N, 16, "fedcba9876543210deadbeefcafe4321" ) == 0 );
04897             }
04898             if( strlen( "3" ) )
04899             {
04900                 fct_chk( mpi_read_string( &ctx.E, 16, "3" ) == 0 );
04901             }
04902         
04903             fct_chk( rsa_check_pubkey( &ctx ) == 0 );
04904         }
04905         FCT_TEST_END();
04906 
04907 
04908         FCT_TEST_BGN(rsa_check_public_key_8_e_exactly_1_bits)
04909         {
04910             rsa_context ctx;
04911         
04912             rsa_init( &ctx, RSA_PKCS_V15, 0 );
04913         
04914             if( strlen( "fedcba9876543210deadbeefcafe4321" ) )
04915             {
04916                 fct_chk( mpi_read_string( &ctx.N, 16, "fedcba9876543210deadbeefcafe4321" ) == 0 );
04917             }
04918             if( strlen( "1" ) )
04919             {
04920                 fct_chk( mpi_read_string( &ctx.E, 16, "1" ) == 0 );
04921             }
04922         
04923             fct_chk( rsa_check_pubkey( &ctx ) == POLARSSL_ERR_RSA_KEY_CHECK_FAILED );
04924         }
04925         FCT_TEST_END();
04926 
04927 
04928         FCT_TEST_BGN(rsa_check_public_key_8_e_exactly_64_bits)
04929         {
04930             rsa_context ctx;
04931         
04932             rsa_init( &ctx, RSA_PKCS_V15, 0 );
04933         
04934             if( strlen( "fedcba9876543210deadbeefcafe4321" ) )
04935             {
04936                 fct_chk( mpi_read_string( &ctx.N, 16, "fedcba9876543210deadbeefcafe4321" ) == 0 );
04937             }
04938             if( strlen( "00fedcba9876543213" ) )
04939             {
04940                 fct_chk( mpi_read_string( &ctx.E, 16, "00fedcba9876543213" ) == 0 );
04941             }
04942         
04943             fct_chk( rsa_check_pubkey( &ctx ) == 0 );
04944         }
04945         FCT_TEST_END();
04946 
04947 
04948         FCT_TEST_BGN(rsa_check_public_key_8_e_larger_than_64_bits)
04949         {
04950             rsa_context ctx;
04951         
04952             rsa_init( &ctx, RSA_PKCS_V15, 0 );
04953         
04954             if( strlen( "fedcba9876543210deadbeefcafe4321" ) )
04955             {
04956                 fct_chk( mpi_read_string( &ctx.N, 16, "fedcba9876543210deadbeefcafe4321" ) == 0 );
04957             }
04958             if( strlen( "01fedcba9876543213" ) )
04959             {
04960                 fct_chk( mpi_read_string( &ctx.E, 16, "01fedcba9876543213" ) == 0 );
04961             }
04962         
04963             fct_chk( rsa_check_pubkey( &ctx ) == POLARSSL_ERR_RSA_KEY_CHECK_FAILED );
04964         }
04965         FCT_TEST_END();
04966 
04967 
04968         FCT_TEST_BGN(rsa_private_correct)
04969         {
04970             unsigned char message_str[1000];
04971             unsigned char output[1000];
04972             unsigned char output_str[1000];
04973             rsa_context ctx;
04974             mpi P1, Q1, H, G;
04975         
04976             mpi_init( &P1 ); mpi_init( &Q1 ); mpi_init( &H ); mpi_init( &G );
04977             rsa_init( &ctx, RSA_PKCS_V15, 0 );
04978         
04979             memset( message_str, 0x00, 1000 );
04980             memset( output, 0x00, 1000 );
04981             memset( output_str, 0x00, 1000 );
04982         
04983             ctx.len = 2048 / 8;
04984             fct_chk( mpi_read_string( &ctx.P, 16, "e79a373182bfaa722eb035f772ad2a9464bd842de59432c18bbab3a7dfeae318c9b915ee487861ab665a40bd6cda560152578e8579016c929df99fea05b4d64efca1d543850bc8164b40d71ed7f3fa4105df0fb9b9ad2a18ce182c8a4f4f975bea9aa0b9a1438a27a28e97ac8330ef37383414d1bd64607d6979ac050424fd17" ) == 0 );
04985             fct_chk( mpi_read_string( &ctx.Q, 16, "c6749cbb0db8c5a177672d4728a8b22392b2fc4d3b8361d5c0d5055a1b4e46d821f757c24eef2a51c561941b93b3ace7340074c058c9bb48e7e7414f42c41da4cccb5c2ba91deb30c586b7fb18af12a52995592ad139d3be429add6547e044becedaf31fa3b39421e24ee034fbf367d11f6b8f88ee483d163b431e1654ad3e89" ) == 0 );
04986             fct_chk( mpi_read_string( &ctx.N, 16, "b38ac65c8141f7f5c96e14470e851936a67bf94cc6821a39ac12c05f7c0b06d9e6ddba2224703b02e25f31452f9c4a8417b62675fdc6df46b94813bc7b9769a892c482b830bfe0ad42e46668ace68903617faf6681f4babf1cc8e4b0420d3c7f61dc45434c6b54e2c3ee0fc07908509d79c9826e673bf8363255adb0add2401039a7bcd1b4ecf0fbe6ec8369d2da486eec59559dd1d54c9b24190965eafbdab203b35255765261cd0909acf93c3b8b8428cbb448de4715d1b813d0c94829c229543d391ce0adab5351f97a3810c1f73d7b1458b97daed4209c50e16d064d2d5bfda8c23893d755222793146d0a78c3d64f35549141486c3b0961a7b4c1a2034f" ) == 0 );
04987             fct_chk( mpi_read_string( &ctx.E, 16, "3" ) == 0 );
04988         
04989             fct_chk( mpi_sub_int( &P1, &ctx.P, 1 ) == 0 );
04990             fct_chk( mpi_sub_int( &Q1, &ctx.Q, 1 ) == 0 );
04991             fct_chk( mpi_mul_mpi( &H, &P1, &Q1 ) == 0 );
04992             fct_chk( mpi_gcd( &G, &ctx.E, &H  ) == 0 );
04993             fct_chk( mpi_inv_mod( &ctx.D , &ctx.E, &H  ) == 0 );
04994             fct_chk( mpi_mod_mpi( &ctx.DP, &ctx.D, &P1 ) == 0 );
04995             fct_chk( mpi_mod_mpi( &ctx.DQ, &ctx.D, &Q1 ) == 0 );
04996             fct_chk( mpi_inv_mod( &ctx.QP, &ctx.Q, &ctx.P ) == 0 );
04997         
04998             fct_chk( rsa_check_privkey( &ctx ) == 0 );
04999         
05000             unhexify( message_str, "59779fd2a39e56640c4fc1e67b60aeffcecd78aed7ad2bdfa464e93d04198d48466b8da7445f25bfa19db2844edd5c8f539cf772cc132b483169d390db28a43bc4ee0f038f6568ffc87447746cb72fefac2d6d90ee3143a915ac4688028805905a68eb8f8a96674b093c495eddd8704461eaa2b345efbb2ad6930acd8023f870" );
05001         
05002             fct_chk( rsa_private( &ctx, message_str, output ) == 0 );
05003             if( 0 == 0 )
05004             {
05005                 hexify( output_str, output, ctx.len );
05006         
05007                 fct_chk( strcasecmp( (char *) output_str, "48ce62658d82be10737bd5d3579aed15bc82617e6758ba862eeb12d049d7bacaf2f62fce8bf6e980763d1951f7f0eae3a493df9890d249314b39d00d6ef791de0daebf2c50f46e54aeb63a89113defe85de6dbe77642aae9f2eceb420f3a47a56355396e728917f17876bb829fabcaeef8bf7ef6de2ff9e84e6108ea2e52bbb62b7b288efa0a3835175b8b08fac56f7396eceb1c692d419ecb79d80aef5bc08a75d89de9f2b2d411d881c0e3ffad24c311a19029d210d3d3534f1b626f982ea322b4d1cfba476860ef20d4f672f38c371084b5301b429b747ea051a619e4430e0dac33c12f9ee41ca4d81a4f6da3e495aa8524574bdc60d290dd1f7a62e90a67" ) == 0 );
05008             }
05009         
05010             mpi_free( &P1 ); mpi_free( &Q1 ); mpi_free( &H ); mpi_free( &G );
05011         }
05012         FCT_TEST_END();
05013 
05014 
05015         FCT_TEST_BGN(rsa_private_data_larger_than_n)
05016         {
05017             unsigned char message_str[1000];
05018             unsigned char output[1000];
05019             unsigned char output_str[1000];
05020             rsa_context ctx;
05021             mpi P1, Q1, H, G;
05022         
05023             mpi_init( &P1 ); mpi_init( &Q1 ); mpi_init( &H ); mpi_init( &G );
05024             rsa_init( &ctx, RSA_PKCS_V15, 0 );
05025         
05026             memset( message_str, 0x00, 1000 );
05027             memset( output, 0x00, 1000 );
05028             memset( output_str, 0x00, 1000 );
05029         
05030             ctx.len = 2048 / 8;
05031             fct_chk( mpi_read_string( &ctx.P, 16, "e79a373182bfaa722eb035f772ad2a9464bd842de59432c18bbab3a7dfeae318c9b915ee487861ab665a40bd6cda560152578e8579016c929df99fea05b4d64efca1d543850bc8164b40d71ed7f3fa4105df0fb9b9ad2a18ce182c8a4f4f975bea9aa0b9a1438a27a28e97ac8330ef37383414d1bd64607d6979ac050424fd17" ) == 0 );
05032             fct_chk( mpi_read_string( &ctx.Q, 16, "c6749cbb0db8c5a177672d4728a8b22392b2fc4d3b8361d5c0d5055a1b4e46d821f757c24eef2a51c561941b93b3ace7340074c058c9bb48e7e7414f42c41da4cccb5c2ba91deb30c586b7fb18af12a52995592ad139d3be429add6547e044becedaf31fa3b39421e24ee034fbf367d11f6b8f88ee483d163b431e1654ad3e89" ) == 0 );
05033             fct_chk( mpi_read_string( &ctx.N, 16, "b38ac65c8141f7f5c96e14470e851936a67bf94cc6821a39ac12c05f7c0b06d9e6ddba2224703b02e25f31452f9c4a8417b62675fdc6df46b94813bc7b9769a892c482b830bfe0ad42e46668ace68903617faf6681f4babf1cc8e4b0420d3c7f61dc45434c6b54e2c3ee0fc07908509d79c9826e673bf8363255adb0add2401039a7bcd1b4ecf0fbe6ec8369d2da486eec59559dd1d54c9b24190965eafbdab203b35255765261cd0909acf93c3b8b8428cbb448de4715d1b813d0c94829c229543d391ce0adab5351f97a3810c1f73d7b1458b97daed4209c50e16d064d2d5bfda8c23893d755222793146d0a78c3d64f35549141486c3b0961a7b4c1a2034f" ) == 0 );
05034             fct_chk( mpi_read_string( &ctx.E, 16, "3" ) == 0 );
05035         
05036             fct_chk( mpi_sub_int( &P1, &ctx.P, 1 ) == 0 );
05037             fct_chk( mpi_sub_int( &Q1, &ctx.Q, 1 ) == 0 );
05038             fct_chk( mpi_mul_mpi( &H, &P1, &Q1 ) == 0 );
05039             fct_chk( mpi_gcd( &G, &ctx.E, &H  ) == 0 );
05040             fct_chk( mpi_inv_mod( &ctx.D , &ctx.E, &H  ) == 0 );
05041             fct_chk( mpi_mod_mpi( &ctx.DP, &ctx.D, &P1 ) == 0 );
05042             fct_chk( mpi_mod_mpi( &ctx.DQ, &ctx.D, &Q1 ) == 0 );
05043             fct_chk( mpi_inv_mod( &ctx.QP, &ctx.Q, &ctx.P ) == 0 );
05044         
05045             fct_chk( rsa_check_privkey( &ctx ) == 0 );
05046         
05047             unhexify( message_str, "b38ac65c8141f7f5c96e14470e851936a67bf94cc6821a39ac12c05f7c0b06d9e6ddba2224703b02e25f31452f9c4a8417b62675fdc6df46b94813bc7b9769a892c482b830bfe0ad42e46668ace68903617faf6681f4babf1cc8e4b0420d3c7f61dc45434c6b54e2c3ee0fc07908509d79c9826e673bf8363255adb0add2401039a7bcd1b4ecf0fbe6ec8369d2da486eec59559dd1d54c9b24190965eafbdab203b35255765261cd0909acf93c3b8b8428cbb448de4715d1b813d0c94829c229543d391ce0adab5351f97a3810c1f73d7b1458b97daed4209c50e16d064d2d5bfda8c23893d755222793146d0a78c3d64f35549141486c3b0961a7b4c1a2034f" );
05048         
05049             fct_chk( rsa_private( &ctx, message_str, output ) == POLARSSL_ERR_RSA_BAD_INPUT_DATA );
05050             if( POLARSSL_ERR_RSA_BAD_INPUT_DATA == 0 )
05051             {
05052                 hexify( output_str, output, ctx.len );
05053         
05054                 fct_chk( strcasecmp( (char *) output_str, "605baf947c0de49e4f6a0dfb94a43ae318d5df8ed20ba4ba5a37a73fb009c5c9e5cce8b70a25b1c7580f389f0d7092485cdfa02208b70d33482edf07a7eafebdc54862ca0e0396a5a7d09991b9753eb1ffb6091971bb5789c6b121abbcd0a3cbaa39969fa7c28146fce96c6d03272e3793e5be8f5abfa9afcbebb986d7b3050604a2af4d3a40fa6c003781a539a60259d1e84f13322da9e538a49c369b83e7286bf7d30b64bbb773506705da5d5d5483a563a1ffacc902fb75c9a751b1e83cdc7a6db0470056883f48b5a5446b43b1d180ea12ba11a6a8d93b3b32a30156b6084b7fb142998a2a0d28014b84098ece7d9d5e4d55cc342ca26f5a0167a679dec8" ) == 0 );
05055             }
05056         
05057             mpi_free( &P1 ); mpi_free( &Q1 ); mpi_free( &H ); mpi_free( &G );
05058         }
05059         FCT_TEST_END();
05060 
05061 
05062         FCT_TEST_BGN(rsa_public_correct)
05063         {
05064             unsigned char message_str[1000];
05065             unsigned char output[1000];
05066             unsigned char output_str[1000];
05067             rsa_context ctx;
05068         
05069             rsa_init( &ctx, RSA_PKCS_V15, 0 );
05070             memset( message_str, 0x00, 1000 );
05071             memset( output, 0x00, 1000 );
05072             memset( output_str, 0x00, 1000 );
05073         
05074             ctx.len = 2048 / 8;
05075             fct_chk( mpi_read_string( &ctx.N, 16, "b38ac65c8141f7f5c96e14470e851936a67bf94cc6821a39ac12c05f7c0b06d9e6ddba2224703b02e25f31452f9c4a8417b62675fdc6df46b94813bc7b9769a892c482b830bfe0ad42e46668ace68903617faf6681f4babf1cc8e4b0420d3c7f61dc45434c6b54e2c3ee0fc07908509d79c9826e673bf8363255adb0add2401039a7bcd1b4ecf0fbe6ec8369d2da486eec59559dd1d54c9b24190965eafbdab203b35255765261cd0909acf93c3b8b8428cbb448de4715d1b813d0c94829c229543d391ce0adab5351f97a3810c1f73d7b1458b97daed4209c50e16d064d2d5bfda8c23893d755222793146d0a78c3d64f35549141486c3b0961a7b4c1a2034f" ) == 0 );
05076             fct_chk( mpi_read_string( &ctx.E, 16, "3" ) == 0 );
05077         
05078             fct_chk( rsa_check_pubkey( &ctx ) == 0 );
05079         
05080             unhexify( message_str, "59779fd2a39e56640c4fc1e67b60aeffcecd78aed7ad2bdfa464e93d04198d48466b8da7445f25bfa19db2844edd5c8f539cf772cc132b483169d390db28a43bc4ee0f038f6568ffc87447746cb72fefac2d6d90ee3143a915ac4688028805905a68eb8f8a96674b093c495eddd8704461eaa2b345efbb2ad6930acd8023f870" );
05081         
05082             fct_chk( rsa_public( &ctx, message_str, output ) == 0 );
05083             if( 0 == 0 )
05084             {
05085                 hexify( output_str, output, ctx.len );
05086         
05087                 fct_chk( strcasecmp( (char *) output_str, "1f5e927c13ff231090b0f18c8c3526428ed0f4a7561457ee5afe4d22d5d9220c34ef5b9a34d0c07f7248a1f3d57f95d10f7936b3063e40660b3a7ca3e73608b013f85a6e778ac7c60d576e9d9c0c5a79ad84ceea74e4722eb3553bdb0c2d7783dac050520cb27ca73478b509873cb0dcbd1d51dd8fccb96c29ad314f36d67cc57835d92d94defa0399feb095fd41b9f0b2be10f6041079ed4290040449f8a79aba50b0a1f8cf83c9fb8772b0686ec1b29cb1814bb06f9c024857db54d395a8da9a2c6f9f53b94bec612a0cb306a3eaa9fc80992e85d9d232e37a50cabe48c9343f039601ff7d95d60025e582aec475d031888310e8ec3833b394a5cf0599101e" ) == 0 );
05088             }
05089         }
05090         FCT_TEST_END();
05091 
05092 
05093         FCT_TEST_BGN(rsa_public_data_larger_than_n)
05094         {
05095             unsigned char message_str[1000];
05096             unsigned char output[1000];
05097             unsigned char output_str[1000];
05098             rsa_context ctx;
05099         
05100             rsa_init( &ctx, RSA_PKCS_V15, 0 );
05101             memset( message_str, 0x00, 1000 );
05102             memset( output, 0x00, 1000 );
05103             memset( output_str, 0x00, 1000 );
05104         
05105             ctx.len = 2048 / 8;
05106             fct_chk( mpi_read_string( &ctx.N, 16, "b38ac65c8141f7f5c96e14470e851936a67bf94cc6821a39ac12c05f7c0b06d9e6ddba2224703b02e25f31452f9c4a8417b62675fdc6df46b94813bc7b9769a892c482b830bfe0ad42e46668ace68903617faf6681f4babf1cc8e4b0420d3c7f61dc45434c6b54e2c3ee0fc07908509d79c9826e673bf8363255adb0add2401039a7bcd1b4ecf0fbe6ec8369d2da486eec59559dd1d54c9b24190965eafbdab203b35255765261cd0909acf93c3b8b8428cbb448de4715d1b813d0c94829c229543d391ce0adab5351f97a3810c1f73d7b1458b97daed4209c50e16d064d2d5bfda8c23893d755222793146d0a78c3d64f35549141486c3b0961a7b4c1a2034f" ) == 0 );
05107             fct_chk( mpi_read_string( &ctx.E, 16, "3" ) == 0 );
05108         
05109             fct_chk( rsa_check_pubkey( &ctx ) == 0 );
05110         
05111             unhexify( message_str, "b38ac65c8141f7f5c96e14470e851936a67bf94cc6821a39ac12c05f7c0b06d9e6ddba2224703b02e25f31452f9c4a8417b62675fdc6df46b94813bc7b9769a892c482b830bfe0ad42e46668ace68903617faf6681f4babf1cc8e4b0420d3c7f61dc45434c6b54e2c3ee0fc07908509d79c9826e673bf8363255adb0add2401039a7bcd1b4ecf0fbe6ec8369d2da486eec59559dd1d54c9b24190965eafbdab203b35255765261cd0909acf93c3b8b8428cbb448de4715d1b813d0c94829c229543d391ce0adab5351f97a3810c1f73d7b1458b97daed4209c50e16d064d2d5bfda8c23893d755222793146d0a78c3d64f35549141486c3b0961a7b4c1a2034f" );
05112         
05113             fct_chk( rsa_public( &ctx, message_str, output ) == POLARSSL_ERR_RSA_BAD_INPUT_DATA );
05114             if( POLARSSL_ERR_RSA_BAD_INPUT_DATA == 0 )
05115             {
05116                 hexify( output_str, output, ctx.len );
05117         
05118                 fct_chk( strcasecmp( (char *) output_str, "605baf947c0de49e4f6a0dfb94a43ae318d5df8ed20ba4ba5a37a73fb009c5c9e5cce8b70a25b1c7580f389f0d7092485cdfa02208b70d33482edf07a7eafebdc54862ca0e0396a5a7d09991b9753eb1ffb6091971bb5789c6b121abbcd0a3cbaa39969fa7c28146fce96c6d03272e3793e5be8f5abfa9afcbebb986d7b3050604a2af4d3a40fa6c003781a539a60259d1e84f13322da9e538a49c369b83e7286bf7d30b64bbb773506705da5d5d5483a563a1ffacc902fb75c9a751b1e83cdc7a6db0470056883f48b5a5446b43b1d180ea12ba11a6a8d93b3b32a30156b6084b7fb142998a2a0d28014b84098ece7d9d5e4d55cc342ca26f5a0167a679dec8" ) == 0 );
05119             }
05120         }
05121         FCT_TEST_END();
05122 
05123 #ifdef POLARSSL_ENTROPY_C
05124 #ifdef POLARSSL_CTR_DRBG_C
05125 
05126         FCT_TEST_BGN(rsa_generate_key)
05127         {
05128             rsa_context ctx;
05129             entropy_context entropy;
05130             ctr_drbg_context ctr_drbg;
05131             char *pers = "test_suite_rsa";
05132         
05133             entropy_init( &entropy );
05134             fct_chk( ctr_drbg_init( &ctr_drbg, entropy_func, &entropy,
05135                                         (unsigned char *) pers, strlen( pers ) ) == 0 );
05136         
05137             rsa_init( &ctx, 0, 0 );
05138         
05139             fct_chk( rsa_gen_key( &ctx, ctr_drbg_random, &ctr_drbg, 128, 3 ) == 0 );
05140             if( 0 == 0 )
05141             {
05142                 fct_chk( rsa_check_privkey( &ctx ) == 0 );
05143             }
05144         }
05145         FCT_TEST_END();
05146 #endif /* POLARSSL_ENTROPY_C */
05147 #endif /* POLARSSL_CTR_DRBG_C */
05148 
05149 #ifdef POLARSSL_ENTROPY_C
05150 #ifdef POLARSSL_CTR_DRBG_C
05151 
05152         FCT_TEST_BGN(rsa_generate_key_number_of_bits_too_small)
05153         {
05154             rsa_context ctx;
05155             entropy_context entropy;
05156             ctr_drbg_context ctr_drbg;
05157             char *pers = "test_suite_rsa";
05158         
05159             entropy_init( &entropy );
05160             fct_chk( ctr_drbg_init( &ctr_drbg, entropy_func, &entropy,
05161                                         (unsigned char *) pers, strlen( pers ) ) == 0 );
05162         
05163             rsa_init( &ctx, 0, 0 );
05164         
05165             fct_chk( rsa_gen_key( &ctx, ctr_drbg_random, &ctr_drbg, 127, 3 ) == POLARSSL_ERR_RSA_BAD_INPUT_DATA );
05166             if( POLARSSL_ERR_RSA_BAD_INPUT_DATA == 0 )
05167             {
05168                 fct_chk( rsa_check_privkey( &ctx ) == 0 );
05169             }
05170         }
05171         FCT_TEST_END();
05172 #endif /* POLARSSL_ENTROPY_C */
05173 #endif /* POLARSSL_CTR_DRBG_C */
05174 
05175 #ifdef POLARSSL_ENTROPY_C
05176 #ifdef POLARSSL_CTR_DRBG_C
05177 
05178         FCT_TEST_BGN(rsa_generate_key_exponent_too_small)
05179         {
05180             rsa_context ctx;
05181             entropy_context entropy;
05182             ctr_drbg_context ctr_drbg;
05183             char *pers = "test_suite_rsa";
05184         
05185             entropy_init( &entropy );
05186             fct_chk( ctr_drbg_init( &ctr_drbg, entropy_func, &entropy,
05187                                         (unsigned char *) pers, strlen( pers ) ) == 0 );
05188         
05189             rsa_init( &ctx, 0, 0 );
05190         
05191             fct_chk( rsa_gen_key( &ctx, ctr_drbg_random, &ctr_drbg, 128, 2 ) == POLARSSL_ERR_RSA_BAD_INPUT_DATA );
05192             if( POLARSSL_ERR_RSA_BAD_INPUT_DATA == 0 )
05193             {
05194                 fct_chk( rsa_check_privkey( &ctx ) == 0 );
05195             }
05196         }
05197         FCT_TEST_END();
05198 #endif /* POLARSSL_ENTROPY_C */
05199 #endif /* POLARSSL_CTR_DRBG_C */
05200 
05201 #ifdef POLARSSL_ENTROPY_C
05202 #ifdef POLARSSL_CTR_DRBG_C
05203 
05204         FCT_TEST_BGN(rsa_generate_key)
05205         {
05206             rsa_context ctx;
05207             entropy_context entropy;
05208             ctr_drbg_context ctr_drbg;
05209             char *pers = "test_suite_rsa";
05210         
05211             entropy_init( &entropy );
05212             fct_chk( ctr_drbg_init( &ctr_drbg, entropy_func, &entropy,
05213                                         (unsigned char *) pers, strlen( pers ) ) == 0 );
05214         
05215             rsa_init( &ctx, 0, 0 );
05216         
05217             fct_chk( rsa_gen_key( &ctx, ctr_drbg_random, &ctr_drbg, 1024, 3 ) == 0 );
05218             if( 0 == 0 )
05219             {
05220                 fct_chk( rsa_check_privkey( &ctx ) == 0 );
05221             }
05222         }
05223         FCT_TEST_END();
05224 #endif /* POLARSSL_ENTROPY_C */
05225 #endif /* POLARSSL_CTR_DRBG_C */
05226 
05227 
05228         FCT_TEST_BGN(rsa_pkcs1_encrypt_bad_rng)
05229         {
05230             unsigned char message_str[1000];
05231             unsigned char output[1000];
05232             unsigned char output_str[1000];
05233             rsa_context ctx;
05234             size_t msg_len;
05235         
05236             rsa_init( &ctx, RSA_PKCS_V15, 0 );
05237             memset( message_str, 0x00, 1000 );
05238             memset( output, 0x00, 1000 );
05239             memset( output_str, 0x00, 1000 );
05240         
05241             ctx.len = 2048 / 8;
05242             fct_chk( mpi_read_string( &ctx.N, 16, "b38ac65c8141f7f5c96e14470e851936a67bf94cc6821a39ac12c05f7c0b06d9e6ddba2224703b02e25f31452f9c4a8417b62675fdc6df46b94813bc7b9769a892c482b830bfe0ad42e46668ace68903617faf6681f4babf1cc8e4b0420d3c7f61dc45434c6b54e2c3ee0fc07908509d79c9826e673bf8363255adb0add2401039a7bcd1b4ecf0fbe6ec8369d2da486eec59559dd1d54c9b24190965eafbdab203b35255765261cd0909acf93c3b8b8428cbb448de4715d1b813d0c94829c229543d391ce0adab5351f97a3810c1f73d7b1458b97daed4209c50e16d064d2d5bfda8c23893d755222793146d0a78c3d64f35549141486c3b0961a7b4c1a2034f" ) == 0 );
05243             fct_chk( mpi_read_string( &ctx.E, 16, "3" ) == 0 );
05244         
05245             fct_chk( rsa_check_pubkey( &ctx ) == 0 );
05246         
05247             msg_len = unhexify( message_str, "4E636AF98E40F3ADCFCCB698F4E80B9F" );
05248         
05249             fct_chk( rsa_pkcs1_encrypt( &ctx, &rnd_zero_rand, NULL, RSA_PUBLIC, msg_len, message_str, output ) == POLARSSL_ERR_RSA_RNG_FAILED );
05250             if( POLARSSL_ERR_RSA_RNG_FAILED == 0 )
05251             {
05252                 hexify( output_str, output, ctx.len );
05253         
05254                 fct_chk( strcasecmp( (char *) output_str, "a42eda41e56235e666e7faaa77100197f657288a1bf183e4820f0c37ce2c456b960278d6003e0bbcd4be4a969f8e8fd9231e1f492414f00ed09844994c86ec32db7cde3bec7f0c3dbf6ae55baeb2712fa609f5fc3207a824eb3dace31849cd6a6084318523912bccb84cf42e3c6d6d1685131d69bb545acec827d2b0dfdd5568b7dcc4f5a11d6916583fefa689d367f8c9e1d95dcd2240895a9470b0c1730f97cd6e8546860bd254801769f54be96e16362ddcbf34d56035028890199e0f48db38642cb66a4181e028a6443a404fea284ce02b4614b683367d40874e505611d23142d49f06feea831d52d347b13610b413c4efc43a6de9f0b08d2a951dc503b6" ) == 0 );
05255             }
05256         }
05257         FCT_TEST_END();
05258 
05259 #ifdef POLARSSL_SELF_TEST
05260 
05261         FCT_TEST_BGN(rsa_selftest)
05262         {
05263             fct_chk( rsa_self_test( 0 ) == 0 );
05264         }
05265         FCT_TEST_END();
05266 #endif /* POLARSSL_SELF_TEST */
05267 
05268     }
05269     FCT_SUITE_END();
05270 
05271 #endif /* POLARSSL_RSA_C */
05272 #endif /* POLARSSL_BIGNUM_C */
05273 #endif /* POLARSSL_GENPRIME */
05274 
05275 }
05276 FCT_END();
05277