1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/ssl/tsrc/crypto_test/src/crypto_testBlocks.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,630 @@
1.4 +/*
1.5 +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
1.6 +
1.7 +* Redistribution and use in source and binary forms, with or without
1.8 +* modification, are permitted provided that the following conditions are met:
1.9 +
1.10 +* Redistributions of source code must retain the above copyright notice, this
1.11 +* list of conditions and the following disclaimer.
1.12 +* Redistributions in binary form must reproduce the above copyright notice,
1.13 +* this list of conditions and the following disclaimer in the documentation
1.14 +* and/or other materials provided with the distribution.
1.15 +* Neither the name of Nokia Corporation nor the names of its contributors
1.16 +* may be used to endorse or promote products derived from this software
1.17 +* without specific prior written permission.
1.18 +
1.19 +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
1.20 +* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1.21 +* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
1.22 +* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
1.23 +* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1.24 +* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
1.25 +* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
1.26 +* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
1.27 +* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
1.28 +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1.29 +*
1.30 +* Description: ?Description
1.31 +*
1.32 +*/
1.33 +
1.34 +
1.35 +
1.36 +// INCLUDE FILES
1.37 +#include <e32svr.h>
1.38 +#include <StifParser.h>
1.39 +#include <Stiftestinterface.h>
1.40 +#include "crypto_test.h"
1.41 +#include "tcrypto_test.h"
1.42 +#include <stdio.h>
1.43 +#include <string.h>
1.44 +#include <stdlib.h>
1.45 +#include <errno.h>
1.46 +// EXTERNAL DATA STRUCTURES
1.47 +//extern ?external_data;
1.48 +
1.49 +// EXTERNAL FUNCTION PROTOTYPES
1.50 +//extern ?external_function( ?arg_type,?arg_type );
1.51 +
1.52 +// CONSTANTS
1.53 +//const ?type ?constant_var = ?constant;
1.54 +
1.55 +// MACROS
1.56 +//#define ?macro ?macro_def
1.57 +
1.58 +// LOCAL CONSTANTS AND MACROS
1.59 +//const ?type ?constant_var = ?constant;
1.60 +//#define ?macro_name ?macro_def
1.61 +
1.62 +// MODULE DATA STRUCTURES
1.63 +//enum ?declaration
1.64 +//typedef ?declaration
1.65 +
1.66 +// LOCAL FUNCTION PROTOTYPES
1.67 +//?type ?function_name( ?arg_type, ?arg_type );
1.68 +
1.69 +// FORWARD DECLARATIONS
1.70 +//class ?FORWARD_CLASSNAME;
1.71 +
1.72 +// ============================= LOCAL FUNCTIONS ===============================
1.73 +
1.74 +// -----------------------------------------------------------------------------
1.75 +// ?function_name ?description.
1.76 +// ?description
1.77 +// Returns: ?value_1: ?description
1.78 +// ?value_n: ?description_line1
1.79 +// ?description_line2
1.80 +// -----------------------------------------------------------------------------
1.81 +//
1.82 +/*
1.83 +?type ?function_name(
1.84 + ?arg_type arg, // ?description
1.85 + ?arg_type arg) // ?description
1.86 + {
1.87 +
1.88 + ?code // ?comment
1.89 +
1.90 + // ?comment
1.91 + ?code
1.92 + }
1.93 +*/
1.94 +
1.95 +// ============================ MEMBER FUNCTIONS ===============================
1.96 +
1.97 +// -----------------------------------------------------------------------------
1.98 +// Ccrypto_test::Delete
1.99 +// Delete here all resources allocated and opened from test methods.
1.100 +// Called from destructor.
1.101 +// -----------------------------------------------------------------------------
1.102 +//
1.103 +void Ccrypto_test::Delete()
1.104 + {
1.105 +
1.106 + }
1.107 +
1.108 +// -----------------------------------------------------------------------------
1.109 +// Ccrypto_test::RunMethodL
1.110 +// Run specified method. Contains also table of test mothods and their names.
1.111 +// -----------------------------------------------------------------------------
1.112 +//
1.113 +TInt Ccrypto_test::RunMethodL(
1.114 + CStifItemParser& aItem )
1.115 + {
1.116 +
1.117 + static TStifFunctionInfo const KFunctions[] =
1.118 + {
1.119 + // Copy this line for every implemented function.
1.120 + // First string is the function name used in TestScripter script file.
1.121 + // Second is the actual implementation member function.
1.122 + ENTRY( "BNTest", Ccrypto_test::BnTest ),
1.123 + ENTRY( "DESTest", Ccrypto_test::DesTest ),
1.124 + ENTRY( "DHTest", Ccrypto_test::DhTest ),
1.125 + ENTRY( "DSATest", Ccrypto_test::DsaTest ),
1.126 + ENTRY( "ENGINETest", Ccrypto_test::EngineTest ),
1.127 + ENTRY( "EVPTest", Ccrypto_test::EvpTest ),
1.128 + ENTRY( "EXPTest", Ccrypto_test::ExpTest ),
1.129 + ENTRY( "HMACTest", Ccrypto_test::HmacTest ),
1.130 + ENTRY( "MD2Test", Ccrypto_test::Md2Test ),
1.131 + ENTRY( "MD5Test", Ccrypto_test::Md5Test ),
1.132 + ENTRY( "RANDTest", Ccrypto_test::RandTest ),
1.133 + ENTRY( "RC2Test", Ccrypto_test::Rc2Test ),
1.134 + ENTRY( "RC4Test", Ccrypto_test::Rc4Test ),
1.135 + ENTRY( "RSATest", Ccrypto_test::RsaTest ),
1.136 + ENTRY( "SHATest", Ccrypto_test::ShaTest ),
1.137 + ENTRY( "SHA1Test", Ccrypto_test::Sha1Test ),
1.138 + ENTRY( "SHA256Test", Ccrypto_test::Sha256Test ),
1.139 + ENTRY( "SHA512Test", Ccrypto_test::Sha512Test ),
1.140 +
1.141 + };
1.142 +
1.143 + const TInt count = sizeof( KFunctions ) /
1.144 + sizeof( TStifFunctionInfo );
1.145 +
1.146 + return RunInternalL( KFunctions, count, aItem );
1.147 +
1.148 + }
1.149 +
1.150 +#ifdef __cplusplus
1.151 +extern "C"
1.152 +{
1.153 +#endif
1.154 +
1.155 +FILE *fp_stdout=NULL;
1.156 +FILE *fp_stderr=NULL;
1.157 +
1.158 +#ifdef __cplusplus
1.159 +}
1.160 +#endif
1.161 +int cryptotest_init(char *mod)
1.162 +{
1.163 + char str[200];
1.164 + int len=0;
1.165 + if(!mod)
1.166 + return 1;
1.167 + len=strlen(LOG_STDOUT);
1.168 + strcpy(str,LOG_STDOUT);
1.169 + strcat(str,"_");
1.170 + strcat(str,mod);
1.171 + len+=strlen(mod);
1.172 + str[len+1]='\0';
1.173 + fp_stdout = fopen(str,"a+b");
1.174 + if(!fp_stdout)
1.175 + return 1;
1.176 + fp_stderr=fp_stdout;
1.177 + return 0;
1.178 +}
1.179 +
1.180 +void cryptotest_deinit(void)
1.181 +{
1.182 + fclose(fp_stdout);
1.183 + fp_stderr=NULL;
1.184 + fp_stdout=NULL;
1.185 +}
1.186 +char ** MakeArgs(CStifItemParser& aItem,int * argc)
1.187 +{
1.188 + char *ini_cmd[256];
1.189 + char **cmd_line;
1.190 +
1.191 + TInt len=0;
1.192 + TPtrC string;
1.193 + TBuf8<50> buf1;
1.194 + char* argument;
1.195 + int cnt=0;
1.196 + int i;
1.197 +
1.198 + //parse through the parameters of cfg to find the number and strings of cmd line
1.199 +
1.200 + while(aItem.GetNextString(string)!=-1)
1.201 + {
1.202 + buf1.Copy(string);
1.203 + argument=(char *)buf1.Ptr();
1.204 + len=buf1.Length();
1.205 + argument[len]='\0';
1.206 +
1.207 + ini_cmd[cnt]=(char *)malloc(sizeof(char)*len+1);
1.208 + if(ini_cmd[cnt]==NULL)
1.209 + {
1.210 + for(i=0;i<cnt;i++)
1.211 + {
1.212 + if(ini_cmd[i])
1.213 + free(ini_cmd[i]);
1.214 + }
1.215 + return NULL;
1.216 + }
1.217 + strcpy(ini_cmd[cnt],(const char *)argument);
1.218 +
1.219 + cnt++;
1.220 + }
1.221 +
1.222 + //allocate memory for the command line ragged array
1.223 +
1.224 + cmd_line=(char **)malloc(cnt*sizeof(char *));
1.225 + if(cmd_line==NULL)
1.226 + {
1.227 + for(i=0;i<cnt;i++)
1.228 + {
1.229 + if(ini_cmd[i])
1.230 + free(ini_cmd[i]);
1.231 + }
1.232 + return NULL;
1.233 + }
1.234 +
1.235 + //initialize the array
1.236 +
1.237 + for(i=0;i<cnt;i++) cmd_line[i]=ini_cmd[i];
1.238 +
1.239 + //initialize argc
1.240 +
1.241 + *argc=cnt;
1.242 +
1.243 + return cmd_line;
1.244 +
1.245 +}
1.246 +//-----------------------------------------------------------------------------
1.247 +//function function for destroying argv
1.248 +//-----------------------------------------------------------------------------
1.249 +void DeleteArgs(char ** cmd_line,int argc)
1.250 +{
1.251 + int i;
1.252 + for(i=0;i<argc;i++) free(cmd_line[i]);
1.253 +
1.254 + free(cmd_line);
1.255 +}
1.256 +
1.257 +
1.258 +// -----------------------------------------------------------------------------
1.259 +// Ccrypto_test::ExampleL
1.260 +// Example test method function.
1.261 +// (other items were commented in a header).
1.262 +// -----------------------------------------------------------------------------
1.263 +//
1.264 +
1.265 +
1.266 +TInt Ccrypto_test::BnTest( CStifItemParser&/* aItem*/ )
1.267 + {
1.268 + TInt ret=1;
1.269 +
1.270 +
1.271 + if(!cryptotest_init("bn"))
1.272 + {
1.273 + ret = bn_main(0,NULL);
1.274 + cryptotest_deinit();
1.275 +
1.276 + }
1.277 + if(ret==1&&errno==ENOMEM)
1.278 + {
1.279 + return KErrNoMemory;
1.280 + }
1.281 + return ret;
1.282 +
1.283 + }
1.284 +
1.285 +
1.286 +
1.287 +TInt Ccrypto_test::DesTest( CStifItemParser&/* aItem*/ )
1.288 + {
1.289 + TInt ret=1;
1.290 +
1.291 +
1.292 + if(!cryptotest_init("des"))
1.293 + {
1.294 + ret = des_main(0,NULL);
1.295 + cryptotest_deinit();
1.296 +
1.297 + }
1.298 + if(ret==1&&errno==ENOMEM)
1.299 + {
1.300 + return KErrNoMemory;
1.301 + }
1.302 + return ret;
1.303 +
1.304 + return ret;
1.305 +
1.306 + }
1.307 +
1.308 +
1.309 +TInt Ccrypto_test::DhTest( CStifItemParser&/* aItem*/ )
1.310 + {
1.311 + TInt ret=1;
1.312 +
1.313 +
1.314 + if(!cryptotest_init("dh"))
1.315 + {
1.316 + ret = dh_main(0,NULL);
1.317 + cryptotest_deinit();
1.318 + }
1.319 + if(ret==1&&errno==ENOMEM)
1.320 + {
1.321 + return KErrNoMemory;
1.322 + }
1.323 + return ret;
1.324 +
1.325 + }
1.326 +
1.327 +TInt Ccrypto_test::DsaTest( CStifItemParser&/* aItem*/ )
1.328 + {
1.329 + TInt ret=1;
1.330 + if(!cryptotest_init("dsa"))
1.331 + {
1.332 + ret = dsa_main(0,NULL);
1.333 + cryptotest_deinit();
1.334 +
1.335 + }
1.336 + if(ret==1&&errno==ENOMEM)
1.337 + {
1.338 + return KErrNoMemory;
1.339 + }
1.340 + return ret;
1.341 +
1.342 +
1.343 + }
1.344 +
1.345 +
1.346 +TInt Ccrypto_test::EngineTest( CStifItemParser&/* aItem*/ )
1.347 + {
1.348 + TInt ret=1;
1.349 +
1.350 + if(!cryptotest_init("eng"))
1.351 + {
1.352 + ret = engine_main(0,NULL);
1.353 + cryptotest_deinit();
1.354 +
1.355 + }
1.356 + if(ret==1&&errno==ENOMEM)
1.357 + {
1.358 + return KErrNoMemory;
1.359 + }
1.360 + return ret;
1.361 +
1.362 + }
1.363 +
1.364 +TInt Ccrypto_test::EvpTest( CStifItemParser& aItem )
1.365 + {
1.366 + TInt ret=1;
1.367 + int argc=0;
1.368 + char** argv=NULL;
1.369 +
1.370 + argv = MakeArgs(aItem,&argc);
1.371 + if(!argv)
1.372 + {
1.373 + return KErrNoMemory;
1.374 + }
1.375 + if(!cryptotest_init("evp"))
1.376 + {
1.377 + ret = evp_main(argc,argv);
1.378 + cryptotest_deinit();
1.379 +
1.380 + }
1.381 + DeleteArgs(argv,argc);
1.382 + if(ret==1&&errno==ENOMEM)
1.383 + {
1.384 + return KErrNoMemory;
1.385 + }
1.386 + return ret;
1.387 + }
1.388 +
1.389 +
1.390 +
1.391 +TInt Ccrypto_test::ExpTest( CStifItemParser& /*aItem */)
1.392 + {
1.393 + TInt ret=1;
1.394 +
1.395 + if(!cryptotest_init("exp"))
1.396 + {
1.397 + ret = exp_main(0,NULL);
1.398 + cryptotest_deinit();
1.399 +
1.400 + }
1.401 + if(ret==1&&errno==ENOMEM)
1.402 + {
1.403 + return KErrNoMemory;
1.404 + }
1.405 + return ret;
1.406 +
1.407 + }
1.408 +TInt Ccrypto_test::HmacTest( CStifItemParser& /*aItem */)
1.409 + {
1.410 + TInt ret=1;
1.411 +
1.412 + if(!cryptotest_init("hmac"))
1.413 + {
1.414 + ret = hmac_main(0,NULL);
1.415 + cryptotest_deinit();
1.416 +
1.417 + }
1.418 + if(ret==1&&errno==ENOMEM)
1.419 + {
1.420 + return KErrNoMemory;
1.421 + }
1.422 + return ret;
1.423 +
1.424 + }
1.425 +
1.426 +
1.427 +TInt Ccrypto_test::Md2Test( CStifItemParser& /*aItem */)
1.428 + {
1.429 + TInt ret=1;
1.430 +
1.431 + if(!cryptotest_init("md2"))
1.432 + {
1.433 + ret = md2_main(0,NULL);
1.434 + cryptotest_deinit();
1.435 +
1.436 + }
1.437 + if(ret==1&&errno==ENOMEM)
1.438 + {
1.439 + return KErrNoMemory;
1.440 + }
1.441 + return ret;
1.442 +
1.443 + }
1.444 +TInt Ccrypto_test::Md5Test( CStifItemParser& /*aItem */)
1.445 + {
1.446 + TInt ret=1;
1.447 +
1.448 + if(!cryptotest_init("md5"))
1.449 + {
1.450 + ret = md5_main(0,NULL);
1.451 + cryptotest_deinit();
1.452 +
1.453 + }
1.454 + if(ret==1&&errno==ENOMEM)
1.455 + {
1.456 + return KErrNoMemory;
1.457 + }
1.458 + return ret;
1.459 +
1.460 + }
1.461 +TInt Ccrypto_test::RandTest( CStifItemParser& /*aItem */)
1.462 + {
1.463 + TInt ret=1;
1.464 +
1.465 + if(!cryptotest_init("rand"))
1.466 + {
1.467 + ret = rand_main(0,NULL);
1.468 + cryptotest_deinit();
1.469 +
1.470 + }
1.471 + if(ret==1&&errno==ENOMEM)
1.472 + {
1.473 + return KErrNoMemory;
1.474 + }
1.475 + return ret;
1.476 +
1.477 + }
1.478 +
1.479 +
1.480 +TInt Ccrypto_test::Rc2Test( CStifItemParser& /*aItem */)
1.481 + {
1.482 + TInt ret=1;
1.483 +
1.484 + if(!cryptotest_init("rc2"))
1.485 + {
1.486 + ret = rc2_main(0,NULL);
1.487 + cryptotest_deinit();
1.488 +
1.489 + }
1.490 +
1.491 + if(ret==1&&errno==ENOMEM)
1.492 + {
1.493 + return KErrNoMemory;
1.494 + }
1.495 + return ret;
1.496 +
1.497 + }
1.498 +
1.499 +TInt Ccrypto_test::Rc4Test( CStifItemParser& /*aItem */)
1.500 + {
1.501 + TInt ret=1;
1.502 +
1.503 + if(!cryptotest_init("rc4"))
1.504 + {
1.505 + ret = rc4_main(0,NULL);
1.506 + cryptotest_deinit();
1.507 +
1.508 + }
1.509 +
1.510 + if(ret==1&&errno==ENOMEM)
1.511 + {
1.512 + return KErrNoMemory;
1.513 + }
1.514 + return ret;
1.515 +
1.516 + }
1.517 +
1.518 +TInt Ccrypto_test::RsaTest( CStifItemParser& /*aItem */)
1.519 + {
1.520 + TInt ret=1;
1.521 +
1.522 + if(!cryptotest_init("rsa"))
1.523 + {
1.524 + ret = rsa_main(0,NULL);
1.525 + cryptotest_deinit();
1.526 +
1.527 + }
1.528 +
1.529 + if(ret==1&&errno==ENOMEM)
1.530 + {
1.531 + return KErrNoMemory;
1.532 + }
1.533 + return ret;
1.534 +
1.535 + }
1.536 +
1.537 +TInt Ccrypto_test::ShaTest( CStifItemParser& /*aItem */)
1.538 + {
1.539 + TInt ret=1;
1.540 +
1.541 + if(!cryptotest_init("sha"))
1.542 + {
1.543 + ret = sha_main(0,NULL);
1.544 + cryptotest_deinit();
1.545 +
1.546 + }
1.547 +
1.548 + if(ret==1&&errno==ENOMEM)
1.549 + {
1.550 + return KErrNoMemory;
1.551 + }
1.552 + return ret;
1.553 +
1.554 + }
1.555 +
1.556 +TInt Ccrypto_test::Sha1Test( CStifItemParser& /*aItem */)
1.557 + {
1.558 + TInt ret=1;
1.559 +
1.560 + if(!cryptotest_init("sha1"))
1.561 + {
1.562 + ret = sha1_main(0,NULL);
1.563 + cryptotest_deinit();
1.564 +
1.565 + }
1.566 +
1.567 + if(ret==1&&errno==ENOMEM)
1.568 + {
1.569 + return KErrNoMemory;
1.570 + }
1.571 + return ret;
1.572 +
1.573 + }
1.574 +
1.575 +TInt Ccrypto_test::Sha256Test( CStifItemParser& /*aItem */)
1.576 + {
1.577 + TInt ret=1;
1.578 +
1.579 + if(!cryptotest_init("sha256"))
1.580 + {
1.581 + ret = sha256_main(0,NULL);
1.582 + cryptotest_deinit();
1.583 +
1.584 + }
1.585 +
1.586 + if(ret==1&&errno==ENOMEM)
1.587 + {
1.588 + return KErrNoMemory;
1.589 + }
1.590 + return ret;
1.591 +
1.592 + }
1.593 +
1.594 +TInt Ccrypto_test::Sha512Test( CStifItemParser& /*aItem */)
1.595 + {
1.596 + TInt ret=1;
1.597 +
1.598 + if(!cryptotest_init("sha512"))
1.599 + {
1.600 + ret = sha512_main(0,NULL);
1.601 + cryptotest_deinit();
1.602 +
1.603 + }
1.604 +
1.605 + if(ret==1&&errno==ENOMEM)
1.606 + {
1.607 + return KErrNoMemory;
1.608 + }
1.609 + return ret;
1.610 +
1.611 + }
1.612 +
1.613 +
1.614 +// -----------------------------------------------------------------------------
1.615 +// Ccrypto_test::?member_function
1.616 +// ?implementation_description
1.617 +// (other items were commented in a header).
1.618 +// -----------------------------------------------------------------------------
1.619 +//
1.620 +/*
1.621 +TInt Ccrypto_test::?member_function(
1.622 + CItemParser& aItem )
1.623 + {
1.624 +
1.625 + ?code
1.626 +
1.627 + }
1.628 +*/
1.629 +
1.630 +// ========================== OTHER EXPORTED FUNCTIONS =========================
1.631 +// None
1.632 +
1.633 +// End of File