kal_bool che_sw_rsa(STCHE* che_context, CHE_ACTION act, kal_uint8* data_src, kal_uint8* data_dst, kal_int32 length, kal_bool last_block){ rsa_context rsa; memset( &rsa, 0, sizeof( rsa ) ); rsa.len = length; mpi_read( &rsa.N , che_context->modulusN, 16, che_context->modulusNLen ); mpi_read( &rsa.E , che_context->pubExp, 16, che_context->pubExpLen ); mpi_read( &rsa.D , che_context->privExpD, 16, che_context->privExpDLen ); mpi_read( &rsa.P , che_context->primeP, 16, che_context->primePLen ); mpi_read( &rsa.Q , che_context->primeQ, 16,che_context->primeQLen ); mpi_read( &rsa.DP, che_context->dModPm1, 16,che_context->dModPm1Len ); mpi_read( &rsa.DQ, che_context->dModQm1, 16,che_context->dModQm1Len ); mpi_read( &rsa.QP, che_context->qInvModP, 16,che_context->qInvModPLen ); if( rsa_check_pubkey( &rsa ) != 0 || rsa_check_privkey( &rsa ) != 0 ){ ASSERT(0); } switch (act){ case RSA_PUBLIC_ENC: if( rsa_public_encrypt( &rsa, data_src, length, data_dst, length ) != 0 ){ ASSERT(0); } break; case RSA_PUBLIC_DEC: if( rsa_public_decrypt( &rsa, data_src, length, data_dst, length ) != 0 ){ ASSERT(0); } break; case RSA_PRIVATE_ENC: if( rsa_private_encrypt( &rsa, data_src, length, data_dst, length ) != 0 ){ ASSERT(0); } break; case RSA_PRIVATE_DEC: if( rsa_private_decrypt( &rsa, data_src, length, data_dst, length ) != 0 ){ ASSERT(0); } break; default: return KAL_FALSE; } return KAL_TRUE; }
/*---< main() >-------------------------------------------------------------*/ int main(int argc, char **argv) { int opt; extern char *optarg; extern int optind; int i, j; int isInFileBinary, isOutFileBinary, do_pnetcdf; int is_output_timing, is_print_usage, verbose; int numClusters, numCoords, numObjs, totalNumObjs; int *membership; /* [numObjs] */ char *filename; // TODO >> modified by VL: new variable representing the centers file name char *centers_filename; // TODO << end of the modification char *var_name; float **objects; /* [numObjs][numCoords] data objects */ float **clusters; /* [numClusters][numCoords] cluster center */ float threshold; double timing, io_timing, clustering_timing; int rank, nproc, mpi_namelen; char mpi_name[MPI_MAX_PROCESSOR_NAME]; MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &nproc); MPI_Get_processor_name(mpi_name,&mpi_namelen); /* some default values */ _debug = 0; verbose = 1; threshold = 0.001; numClusters = 0; isInFileBinary = 0; isOutFileBinary = 0; is_output_timing = 0; is_print_usage = 0; filename = NULL; // TODO >> modified by VL: initialization of the new variable centers_filename = NULL; // TODO << end of the modification do_pnetcdf = 0; var_name = NULL; // TODO >> modified by VL: added the letter z while ( (opt=getopt(argc,argv,"i:z:n:t:v:c:abdorhq"))!= EOF) { // TODO << end of the modification switch (opt) { case 'i': filename=optarg; break; // TODO >> modified by VL: initialize centers filename case 'z': centers_filename=optarg; break; // TODO << end of the modification case 'b': isInFileBinary = 1; break; case 'r': isOutFileBinary = 1; break; case 't': threshold=atof(optarg); break; case 'n': numClusters = atoi(optarg); break; case 'o': is_output_timing = 1; break; case 'c': do_pnetcdf = 1; var_name = optarg; break; case 'q': verbose = 0; break; case 'd': _debug = 1; break; case 'h': default: is_print_usage = 1; break; } } if (filename == 0 || numClusters <= 1 || is_print_usage == 1 || (do_pnetcdf && var_name == NULL)) { if (rank == 0) usage(argv[0], threshold); MPI_Finalize(); exit(1); } if (_debug) printf("Proc %d of %d running on %s\n", rank, nproc, mpi_name); #ifndef _PNETCDF_BUILT if (do_pnetcdf) { if (rank == 0) printf("Error: PnetCDF feature is not built\n"); MPI_Finalize(); exit(1); } #endif MPI_Barrier(MPI_COMM_WORLD); io_timing = MPI_Wtime(); /* read data points from file ------------------------------------------*/ #ifdef _PNETCDF_BUILT if (do_pnetcdf) objects = pnetcdf_read(filename, var_name, &numObjs, &numCoords, MPI_COMM_WORLD); else #endif objects = mpi_read(isInFileBinary, filename, &numObjs, &numCoords, MPI_COMM_WORLD); if (_debug) { /* print the first 4 objects' coordinates */ int num = (numObjs < 4) ? numObjs : 4; for (i=0; i<num; i++) { char strline[1024], strfloat[16]; sprintf(strline,"%d: objects[%d]= ",rank,i); for (j=0; j<numCoords; j++) { sprintf(strfloat,"%10f",objects[i][j]); strcat(strline, strfloat); } strcat(strline, "\n"); printf("%s",strline); } } timing = MPI_Wtime(); io_timing = timing - io_timing; clustering_timing = timing; /* allocate a 2D space for clusters[] (coordinates of cluster centers) this array should be the same across all processes */ clusters = (float**) malloc(numClusters * sizeof(float*)); assert(clusters != NULL); clusters[0] = (float*) malloc(numClusters * numCoords * sizeof(float)); assert(clusters[0] != NULL); for (i=1; i<numClusters; i++) clusters[i] = clusters[i-1] + numCoords; MPI_Allreduce(&numObjs, &totalNumObjs, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD); /* checking if numObjs < nproc is done in the I/O routine */ // TODO >> modified by VL: initialize variable "clusters" // possibly load the centers from a file if (centers_filename != NULL) { int num_centers, num_coords; clusters = file_read(0, centers_filename, &num_centers, &num_coords); // no control over the numbers of centers and coordinates } // otherwise, pick the first numClusters elements of objects[] as initial cluster centers else // TODO << end of the modification /* pick first numClusters elements in feature[] as initial cluster centers*/ if (rank == 0) { if (numObjs < numClusters) { /* read the first numClusters data points from file */ read_n_objects(isInFileBinary, filename, numClusters, numCoords, clusters); } else { /* copy the first numClusters elements in feature[] */ for (i=0; i<numClusters; i++) for (j=0; j<numCoords; j++) clusters[i][j] = objects[i][j]; } } MPI_Bcast(clusters[0], numClusters*numCoords, MPI_FLOAT, 0, MPI_COMM_WORLD); /* membership: the cluster id for each data object */ membership = (int*) malloc(numObjs * sizeof(int)); assert(membership != NULL); /* start the core computation -------------------------------------------*/ mpi_kmeans(objects, numCoords, numObjs, numClusters, threshold, membership, clusters, MPI_COMM_WORLD); free(objects[0]); free(objects); timing = MPI_Wtime(); clustering_timing = timing - clustering_timing; /* output: the coordinates of the cluster centres ----------------------*/ #ifdef _PNETCDF_BUILT if (do_pnetcdf) pnetcdf_write(filename, 1, numClusters, numObjs, numCoords, clusters, membership, totalNumObjs, MPI_COMM_WORLD, verbose); else #endif mpi_write(isOutFileBinary, filename, numClusters, numObjs, numCoords, clusters, membership, totalNumObjs, MPI_COMM_WORLD, verbose); free(membership); free(clusters[0]); free(clusters); /*---- output performance numbers ---------------------------------------*/ if (is_output_timing) { double max_io_timing, max_clustering_timing; io_timing += MPI_Wtime() - timing; /* get the max timing measured among all processes */ MPI_Reduce(&io_timing, &max_io_timing, 1, MPI_DOUBLE, MPI_MAX, 0, MPI_COMM_WORLD); MPI_Reduce(&clustering_timing, &max_clustering_timing, 1, MPI_DOUBLE, MPI_MAX, 0, MPI_COMM_WORLD); if (rank == 0) { printf("\nPerforming **** Simple Kmeans (MPI) ****\n"); printf("Num of processes = %d\n", nproc); printf("Input file: %s\n", filename); // TODO >> modified by VL: display centers filename if(centers_filename!=NULL) printf("Centers file: %s\n", centers_filename); // TODO << end of the modifications printf("numObjs = %d\n", totalNumObjs); printf("numCoords = %d\n", numCoords); printf("numClusters = %d\n", numClusters); printf("threshold = %.4f\n", threshold); printf("I/O time = %10.4f sec\n", max_io_timing); printf("Computation timing = %10.4f sec\n", max_clustering_timing); } } MPI_Finalize(); return(0); }
int main(int argc, char **argv) { int opt; extern char *optarg; extern int optind; int i, j; int isInFileBinary, isOutFileBinary; int is_output_timing, is_print_usage; int numClusters, numCoords, numObjs, totalNumObjs; int *membership; /* [numObjs] */ char *filename; float **objects; /* [numObjs][numCoords] data objects */ float **clusters; /* [numClusters][numCoords] cluster center */ float threshold; double timing, io_timing, clustering_timing; int rank, nproc, mpi_namelen; char mpi_name[MPI_MAX_PROCESSOR_NAME]; MPI_Status status; MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &nproc); MPI_Get_processor_name(mpi_name,&mpi_namelen); /* some default values */ _debug = 0; threshold = 0.001; numClusters = 0; isInFileBinary = 0; isOutFileBinary = 0; is_output_timing = 0; is_print_usage = 0; filename = NULL; while ( (opt=getopt(argc,argv,"p:i:n:t:abdorh"))!= EOF) { switch (opt) { case 'i': filename=optarg; break; case 'b': isInFileBinary = 1; break; case 'r': isOutFileBinary = 1; break; case 't': threshold=atof(optarg); break; case 'n': numClusters = atoi(optarg); break; case 'o': is_output_timing = 1; break; case 'd': _debug = 1; break; case 'h': is_print_usage = 1; break; default: is_print_usage = 1; break; } } if (filename == 0 || numClusters <= 1 || is_print_usage == 1) { if (rank == 0) usage(argv[0], threshold); MPI_Finalize(); exit(1); } if (_debug) printf("Proc %d of %d running on %s\n", rank, nproc, mpi_name); MPI_Barrier(MPI_COMM_WORLD); io_timing = MPI_Wtime(); /* read data points from file ------------------------------------------*/ objects = mpi_read(filename, &numObjs, &numCoords, MPI_COMM_WORLD); if (_debug) { /* print the first 4 objects' coordinates */ int num = (numObjs < 4) ? numObjs : 4; for (i=0; i<num; i++) { char strline[1024], strfloat[16]; sprintf(strline,"%d: objects[%d]= ",rank,i); for (j=0; j<numCoords; j++) { sprintf(strfloat,"%10f",objects[i][j]); strcat(strline, strfloat); } strcat(strline, "\n"); printf("%s",strline); } } timing = MPI_Wtime(); io_timing = timing - io_timing; clustering_timing = timing; /* allocate a 2D space for clusters[] (coordinates of cluster centers) this array should be the same across all processes */ clusters = (float**) malloc(numClusters * sizeof(float*)); assert(clusters != NULL); clusters[0] = (float*) malloc(numClusters * numCoords * sizeof(float)); assert(clusters[0] != NULL); for (i=1; i<numClusters; i++) clusters[i] = clusters[i-1] + numCoords; MPI_Allreduce(&numObjs, &totalNumObjs, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD); /* pick first numClusters elements in feature[] as initial cluster centers*/ if (rank == 0) { for (i=0; i<numClusters; i++) for (j=0; j<numCoords; j++) clusters[i][j] = objects[i][j]; } MPI_Bcast(clusters[0], numClusters*numCoords, MPI_FLOAT, 0, MPI_COMM_WORLD); /* membership: the cluster id for each data object */ membership = (int*) malloc(numObjs * sizeof(int)); assert(membership != NULL); /* start the core computation -------------------------------------------*/ mpi_kmeans(objects, numCoords, numObjs, numClusters, threshold, membership, clusters, MPI_COMM_WORLD); free(objects[0]); free(objects); timing = MPI_Wtime(); clustering_timing = timing - clustering_timing; /* output: the coordinates of the cluster centres ----------------------*/ mpi_write(filename, numClusters, numObjs, numCoords, clusters, membership, totalNumObjs, MPI_COMM_WORLD); free(membership); free(clusters[0]); free(clusters); /*---- output performance numbers ---------------------------------------*/ if (is_output_timing) { double max_io_timing, max_clustering_timing; io_timing += MPI_Wtime() - timing; /* get the max timing measured among all processes */ MPI_Reduce(&io_timing, &max_io_timing, 1, MPI_DOUBLE, MPI_MAX, 0, MPI_COMM_WORLD); MPI_Reduce(&clustering_timing, &max_clustering_timing, 1, MPI_DOUBLE, MPI_MAX, 0, MPI_COMM_WORLD); if (rank == 0) { printf("\nPerforming **** Simple Kmeans (MPI) ****\n"); printf("Num of processes = %d\n", nproc); printf("Input file: %s\n", filename); printf("numObjs = %d\n", totalNumObjs); printf("numCoords = %d\n", numCoords); printf("numClusters = %d\n", numClusters); printf("threshold = %.4f\n", threshold); printf("I/O time = %10.4f sec\n", max_io_timing); printf("Computation timing = %10.4f sec\n", max_clustering_timing); } } MPI_Finalize(); return(0); }
/* * Checkup routine */ int main ( void ) { int len; rsa_context rsa; unsigned char md5sum[16]; unsigned char rsa_plaintext[PTLEN]; unsigned char rsa_decrypted[PTLEN]; unsigned char rsa_ciphertext[CTLEN]; memset( &rsa, 0, sizeof( rsa ) ); rsa.len = 128; mpi_read( &rsa.N , "9292758453063D803DD603D5E777D788" \ "8ED1D5BF35786190FA2F23EBC0848AEA" \ "DDA92CA6C3D80B32C4D109BE0F36D6AE" \ "7130B9CED7ACDF54CFC7555AC14EEBAB" \ "93A89813FBF3C4F8066D2D800F7C38A8" \ "1AE31942917403FF4946B0A83D3D3E05" \ "EE57C6F5F5606FB5D4BC6CD34EE0801A" \ "5E94BB77B07507233A0BC7BAC8F90F79", 16 ); mpi_read( &rsa.E , "10001", 16 ); mpi_read( &rsa.D , "24BF6185468786FDD303083D25E64EFC" \ "66CA472BC44D253102F8B4A9D3BFA750" \ "91386C0077937FE33FA3252D28855837" \ "AE1B484A8A9A45F7EE8C0C634F99E8CD" \ "DF79C5CE07EE72C7F123142198164234" \ "CABB724CF78B8173B9F880FC86322407" \ "AF1FEDFDDE2BEB674CA15F3E81A1521E" \ "071513A1E85B5DFA031F21ECAE91A34D", 16 ); mpi_read( &rsa.P , "C36D0EB7FCD285223CFB5AABA5BDA3D8" \ "2C01CAD19EA484A87EA4377637E75500" \ "FCB2005C5C7DD6EC4AC023CDA285D796" \ "C3D9E75E1EFC42488BB4F1D13AC30A57", 16 ); mpi_read( &rsa.Q , "C000DF51A7C77AE8D7C7370C1FF55B69" \ "E211C2B9E5DB1ED0BF61D0D9899620F4" \ "910E4168387E3C30AA1E00C339A79508" \ "8452DD96A9A5EA5D9DCA68DA636032AF", 16 ); mpi_read( &rsa.DP, "C1ACF567564274FB07A0BBAD5D26E298" \ "3C94D22288ACD763FD8E5600ED4A702D" \ "F84198A5F06C2E72236AE490C93F07F8" \ "3CC559CD27BC2D1CA488811730BB5725", 16 ); mpi_read( &rsa.DQ, "4959CBF6F8FEF750AEE6977C155579C7" \ "D8AAEA56749EA28623272E4F7D0592AF" \ "7C1F1313CAC9471B5C523BFE592F517B" \ "407A1BD76C164B93DA2D32A383E58357", 16 ); mpi_read( &rsa.QP, "9AE7FBC99546432DF71896FC239EADAE" \ "F38D18D2B2F0E2DD275AA977E2BF4411" \ "F5A3B2A5D33605AEBBCCBA7FEB9F2D2F" \ "A74206CEC169D74BF5A8C50D6F48EA08", 16 ); printf( " RSA key validation: " ); if( rsa_check_pubkey( &rsa ) != 0 || rsa_check_privkey( &rsa ) != 0 ) { printf( "failed\n" ); return( 1 ); } printf( "passed\n PKCS#1 encryption : " ); memcpy( rsa_plaintext, "\xAA\xBB\xCC\x03\x02\x01\x00\xFF\xFF\xFF\xFF\xFF" \ "\x11\x22\x33\x0A\x0B\x0C\xCC\xDD\xDD\xDD\xDD\xDD", PTLEN ); len = CTLEN; if( rsa_pkcs1_encrypt( &rsa, rsa_plaintext, PTLEN, rsa_ciphertext, &len ) != 0 ) { printf( "failed\n" ); return( 1 ); } printf( "passed\n PKCS#1 decryption : " ); len = sizeof( rsa_decrypted ); if( rsa_pkcs1_decrypt( &rsa, rsa_ciphertext, CTLEN, rsa_decrypted, &len ) != 0 || memcmp( rsa_decrypted, rsa_plaintext, len ) != 0 ) { printf( "failed\n" ); return( 1 ); } printf( "passed\n" ); #if 0 md5_csum( rsa_plaintext, PTLEN, md5sum ); if( rsa_pkcs1_sign( &rsa, RSA_MD5, md5sum, 16, rsa_ciphertext, CTLEN ) != 0 ) { printf( "failed\n" ); return( 1 ); } printf( "passed\n PKCS#1 sig. verify: " ); if( rsa_pkcs1_verify( &rsa, RSA_MD5, md5sum, 16, rsa_ciphertext, CTLEN ) != 0 ) { printf( "failed\n" ); return( 1 ); } printf( "passed\n\n" ); #endif rsa_free( &rsa ); return( 0 ); }
/* * Checkup routine */ int rsa_self_test( void ) { int len; rsa_context rsa; uchar md5sum[16]; uchar decrypted[PTLEN]; uchar ciphertext[CTLEN]; memset( &rsa, 0, sizeof( rsa ) ); rsa.len = 128; #if 0 mpi_read( &rsa.N , "9292758453063D803DD603D5E777D788" \ "8ED1D5BF35786190FA2F23EBC0848AEA" \ "DDA92CA6C3D80B32C4D109BE0F36D6AE" \ "7130B9CED7ACDF54CFC7555AC14EEBAB" \ "93A89813FBF3C4F8066D2D800F7C38A8" \ "1AE31942917403FF4946B0A83D3D3E05" \ "EE57C6F5F5606FB5D4BC6CD34EE0801A" \ "5E94BB77B07507233A0BC7BAC8F90F79", 16 ); mpi_read( &rsa.E , "10001", 16 ); mpi_read( &rsa.D , "24BF6185468786FDD303083D25E64EFC" \ "66CA472BC44D253102F8B4A9D3BFA750" \ "91386C0077937FE33FA3252D28855837" \ "AE1B484A8A9A45F7EE8C0C634F99E8CD" \ "DF79C5CE07EE72C7F123142198164234" \ "CABB724CF78B8173B9F880FC86322407" \ "AF1FEDFDDE2BEB674CA15F3E81A1521E" \ "071513A1E85B5DFA031F21ECAE91A34D", 16 ); mpi_read( &rsa.P , "C36D0EB7FCD285223CFB5AABA5BDA3D8" \ "2C01CAD19EA484A87EA4377637E75500" \ "FCB2005C5C7DD6EC4AC023CDA285D796" \ "C3D9E75E1EFC42488BB4F1D13AC30A57", 16 ); mpi_read( &rsa.Q , "C000DF51A7C77AE8D7C7370C1FF55B69" \ "E211C2B9E5DB1ED0BF61D0D9899620F4" \ "910E4168387E3C30AA1E00C339A79508" \ "8452DD96A9A5EA5D9DCA68DA636032AF", 16 ); mpi_read( &rsa.DP, "C1ACF567564274FB07A0BBAD5D26E298" \ "3C94D22288ACD763FD8E5600ED4A702D" \ "F84198A5F06C2E72236AE490C93F07F8" \ "3CC559CD27BC2D1CA488811730BB5725", 16 ); mpi_read( &rsa.DQ, "4959CBF6F8FEF750AEE6977C155579C7" \ "D8AAEA56749EA28623272E4F7D0592AF" \ "7C1F1313CAC9471B5C523BFE592F517B" \ "407A1BD76C164B93DA2D32A383E58357", 16 ); mpi_read( &rsa.QP, "9AE7FBC99546432DF71896FC239EADAE" \ "F38D18D2B2F0E2DD275AA977E2BF4411" \ "F5A3B2A5D33605AEBBCCBA7FEB9F2D2F" \ "A74206CEC169D74BF5A8C50D6F48EA08", 16 ); #else mpi_read( &rsa.N , "EEF43DF231F4FEFDA3FF0576F864912B" \ "F5D51D627C5911F4794F54C8BE178C66" \ "FD9C447BE512735818E93CF88AB1696C" \ "1C634A898DBFCE384F74CD347B715419" \ "EAE05016842B752F127CC224535C4708" \ "8DE7566D50F0CFC013B2592BAB1E042A" \ "76239E5262D931B84BDAB640028AFE7C" \ "39E2B75A353EABF827854EE249C6EA45", 16 ); mpi_read( &rsa.E , "010001", 16 ); mpi_read( &rsa.D , "B6F6044861BFF94E34379BF3901550A2" \ "9C44658F772EABF4C8BDD9692B43D499" \ "372E63B189A02AF91579E0D95D38A243" \ "C928AD75CD3743AB120B98E3CA70E7B6" \ "C5B3C1EA2065EF5A6347F80B247044D4" \ "775C4379C2286F8724E0DFE859F808E8" \ "BFBE3D257EF84E3A455C5BC452F5600E" \ "5CDD62818D7E937C7D4C9819C1FAF331", 16 ); mpi_read( &rsa.P , "FBD24AF8F6132E9E1D07B73CFD6D0ECE" \ "6E49DD602EF0F4D6FE6DF66493F016EA" \ "C19FF290749194145C3229D0CC57B31F" \ "199AE2819572271CFE40279063B5BEAB", 16 ); mpi_read( &rsa.Q , "F2EB4A3E41438F2690EC2DED0198E4BD" \ "7ABA01D374A27C92BDAEA3803FF8584C" \ "2B923C95868B4C53DCEEA3A750D7B702" \ "748522C8BF781CCED4E76B52A9DD3ACF", 16 ); mpi_read( &rsa.DP, "3947752C39F4D506BBFDB44D582BC551" \ "693EBDEF11DE5722CC0EC11BD196ABEF" \ "CC0910C890EB482E756627A2C9C82D03" \ "26F4D70EB8AA9580FFC821F7B2E6752F", 16 ); mpi_read( &rsa.DQ, "5A71D28DC55CF322A7D8D7ECA3A89A9A" \ "15E4C5A3468CED16F1BAE133721DF43A" \ "400ACDB5DA8768DEDCA69996455A5BD0" \ "7533D0D4AFBD77F4667ED78DCAA30D2F", 16 ); mpi_read( &rsa.QP, "81267EDB140CE8F07CA92F508FEA134B" \ "23C871D428C6EF870F08FFF2AD46D210" \ "8FCD67E28FF95E8E332B5EEE16EB8784" \ "AB3D1E59B078CB93EF5C6E0F12419439", 16 ); #endif printf( " RSA key validation: " ); if( rsa_check_pubkey( &rsa ) != 0 || rsa_check_privkey( &rsa ) != 0 ) { printf( "failed\n" ); return( 1 ); } printf( "passed\n PKCS#1 encryption : " ); if( rsa_pkcs1_encrypt( &rsa, plaintext, PTLEN, ciphertext, CTLEN ) != 0 ) { printf( "failed\n" ); return( 1 ); } printf( "passed\n PKCS#1 decryption : " ); len = sizeof( decrypted ); if( rsa_pkcs1_decrypt( &rsa, ciphertext, CTLEN, decrypted, &len ) != 0 || memcmp( decrypted, plaintext, len ) != 0 ) { printf( "failed\n" ); return( 1 ); } printf( "passed\n PKCS#1 data sign : " ); md5_csum( plaintext, PTLEN, md5sum ); if( rsa_pkcs1_sign( &rsa, RSA_MD5, md5sum, 16, ciphertext, CTLEN ) != 0 ) { printf( "failed\n" ); return( 1 ); } printf( "passed\n PKCS#1 sig. verify: " ); if( rsa_pkcs1_verify( &rsa, RSA_MD5, md5sum, 16, ciphertext, CTLEN ) != 0 ) { printf( "failed\n" ); return( 1 ); } printf( "passed\n\n" ); rsa_free( &rsa ); return( 0 ); }