Exemplo n.º 1
0
void CTestPadPKCS7::TestPKCS7Padding(TInt aBlockSize)
	{
   	CPaddingPKCS7 *padding = CPaddingPKCS7::NewLC(aBlockSize);
	// Starts with zero input size(total block data is filled/padded with block size) 
	for (TInt i = 0 ; i <= aBlockSize; i++)
		{
		HBufC8 *padInData = HBufC8::NewLC(i);
		HBufC8 *padOutData = HBufC8::NewLC(i+(aBlockSize-i%aBlockSize));
		TPtr8 in(padInData->Des());
		TPtr8 out(padOutData->Des());

		GenerateInput(i, in);
		TRAPD(err, padding->PadL(in, out));
		
		TEST(err == KErrNone);
		
		TInt totalLength = out.Length();
		TUint paddingLength = aBlockSize - in.Length()%aBlockSize;
		// Test that the total length is a multiple of blockSize
		TEST((totalLength % aBlockSize) == 0);
      
		// Test that the padding bytes are equal in value to the paddingLength,
		// ie, if padding length is 5 the 5 last octets in the out array should be 0x05
		for (TInt j = paddingLength; j > 0 ; j--)
			{
			TEST(out[out.Length()-j] == paddingLength);
			}
      
		// Test that the data has not been corrupted
		TEST(in == out.Left(out.Length() - paddingLength));
		
		CleanupStack::PopAndDestroy(2, padInData); // padInData, padOutData
		}
	CleanupStack::PopAndDestroy(padding);
	}
Exemplo n.º 2
0
void CTestUnpadCorruptPKCS7::TestCorruptPKCS7Unpadding(TInt aBlockSize, TInt aTextSize, TUint8 aPaddingByte)
	{
 	CPaddingPKCS7 *padding = CPaddingPKCS7::NewLC(aBlockSize);
 	TInt paddingBytes = (aBlockSize - aTextSize % aBlockSize);
 	
	HBufC8 *padInData = HBufC8::NewLC(aTextSize + paddingBytes);
 	HBufC8 *padOutData = HBufC8::NewLC(aTextSize);
 	TPtr8 in(padInData->Des());
 	TPtr8 out(padOutData->Des());
 
 	GenerateInput(aTextSize, in);
 
 	in.SetLength(in.Length() + paddingBytes);
 	for (TInt j = 1; j <= paddingBytes; j++)
 		{
 		in[in.Length()-j] = (TUint8) aPaddingByte;
 		}
 
 	TRAPD(err, padding->UnPadL(in, out));
 	
 	if ( err == KErrInvalidPadding )
		{
  		INFO_PRINTF2(_L("The PKCS7 unpadding UnPadL method returned error is %d"), err);
  		TEST(err == KErrInvalidPadding);
  		SetTestStepResult(EPass);
  		}
	else if ( err == KErrNone )
		{
		TEST(err == KErrNone);
		}
	CleanupStack::PopAndDestroy(3, padding); // padding, padInData, padOutData
	}
Exemplo n.º 3
0
void CTestUnpadPKCS7::TestPKCS7Unpadding(TInt aBlockSize)
	{
	CPaddingPKCS7 *padding = CPaddingPKCS7::NewLC(aBlockSize);

	// Input must be < aBlockSize otherwise this wouldn't be 
	// a padded block
	for (TInt i = 0 ; i < aBlockSize; i++)
		{
		// Input to un-padding should always be an entire block
		// for correctly data.
		HBufC8 *padInData = HBufC8::NewLC(aBlockSize);
		HBufC8 *padOutData = HBufC8::NewLC(i);
		HBufC8 *padCompareData = HBufC8::NewLC(i);
		TPtr8 in(padInData->Des());
		TPtr8 out(padOutData->Des());
		TPtr8 comp(padCompareData->Des());

		GenerateInput(i, in);
		comp.Copy(in);		

		in.SetLength(aBlockSize);
		TInt paddingBytes = aBlockSize - (i % aBlockSize);
		for (TInt j = 1; j <= paddingBytes; j++)
			{
			in[in.Length()-j] = (TUint8)paddingBytes;
			}

		TRAPD(err, padding->UnPadL(in, out));
		if (err != KErrNone)
			{
			INFO_PRINTF3(_L("The Error returned for block size %d is %d"), aBlockSize,err);
			}
		TEST(err == KErrNone); // Verify UnPadL leave code 
		TEST(out == comp); // Verify  UnPadL output data with expected data
		CleanupStack::PopAndDestroy(3, padInData); // padInData, padOutData, padCompareData
		}
	CleanupStack::PopAndDestroy(padding);
	}
Exemplo n.º 4
0
uintptr_t CPROC GenerateApplicationStrokes( PTHREAD thread )
{
	int n;
	lprintf( "Short pause.." );
	if( CanSwipe() )
	{
		Sleep( 100 );
		lprintf( "generate percent" );
		GenerateInput( KEY_2, KEY_SHIFT );
		//GenerateInput( KEY_5, KEY_SHIFT );
		lprintf( "player name is : %s", ffl.player_name );
		if( ffl.player_name )
			for( n = 0; ffl.player_name[n]; n++ )
			{
				lprintf( "character is %c", ffl.player_name[n] );
				if( ffl.player_name[n] >= 'A' && ffl.player_name[n] <= 'Z' )
					GenerateInput( ffl.player_name[n], KEY_SHIFT );
				else if( ffl.player_name[n] >= 'a' && ffl.player_name[n] <= 'z' )
					GenerateInput( ffl.player_name[n] - ( 'a' - 'A' ), 0 );
				else
					GenerateInput( ffl.player_name[n], 0 );
			}
		lprintf( "generate caret" );
		GenerateInput( KEY_6, KEY_SHIFT );
		if( ffl.player_id )
			for( n = 0; ffl.player_id[n]; n++ )
			{
				lprintf( "character is %c", ffl.player_id[n] );
				GenerateInput( ffl.player_id[n], 0 );
			}
		//GenerateInput( KEY_SLASH, KEY_SHIFT );
		GenerateInput( KEY_3, KEY_SHIFT );
	}
	ffl.in_replay = 0;
	ffl.value_collect_index = 0;
	ffl.card_collected = 0;
	return 0;
}
Exemplo n.º 5
0
int main(int argc, char *argv[]){

	pthread_t tid[MAX_THREADS];  
	pthread_attr_t attr[MAX_THREADS];
	int indexes[MAX_THREADS][3];
	int i, indexForZero, arraySize, min;

	// Code for parsing and checking command-line arguments
	if(argc != 4){
		fprintf(stderr, "Invalid number of arguments!\n");
		exit(-1);
	}
	if((arraySize = atoi(argv[1])) <= 0 || arraySize > MAX_SIZE){
		fprintf(stderr, "Invalid Array Size\n");
		exit(-1);				
	}
	gThreadCount = atoi(argv[2]);				
	if(gThreadCount > MAX_THREADS || gThreadCount <=0){
		fprintf(stderr, "Invalid Thread Count\n");
		exit(-1);				
	}
	indexForZero = atoi(argv[3]);
	if(indexForZero < -1 || indexForZero >= arraySize){
		fprintf(stderr, "Invalid index for zero!\n");
		exit(-1);
	}

    GenerateInput(arraySize, indexForZero);

    CalculateIndexes(arraySize, gThreadCount, indexes); 

	// Code for the sequential part
	SetTime();
	min = SqFindMin(arraySize);
	printf("Sequential search completed in %ld ms. Min = %d\n", GetTime(), min);
	
	// Threaded with parent waiting for all child threads
	SetTime();

	// Write your code here
	// Initialize threads, create threads, and then let the parent wait for all threads using pthread_join
	// The thread start function is ThFindMin
	// Don't forget to properly initialize shared variables 
	for(i = 0; i < gThreadCount; i++){
		pthread_attr_init(&attr[i]);
		if(pthread_create(&tid[i], &attr[i], ThFindMin, &indexes[i])) {
			fprintf(stderr, "Error creating thread\n");
			return 1;

		}
	}

	for(i = 0; i < gThreadCount; i++){
		if(pthread_join(tid[i], NULL)) {
			fprintf(stderr, "Error joining thread\n");
			return 1;
		}
	}

    min = SearchThreadMin();
	printf("Threaded FindMin with parent waiting for all children completed in %ld ms. Min = %d\n", GetTime(), min);

	// Multi-threaded with busy waiting (parent continually checking on child threads)  
	SetTime();

	// Write your code here
	// Initialize threads, create threads, and then make the parent continually check on all child threads
	// The thread start function is ThFindMin
	// Don't forget to properly initialize shared variables 
	for(i = 0; i < gThreadCount; i++){
		pthread_attr_init(&attr[i]);
		if(pthread_create(&tid[i], &attr[i], ThFindMin, &indexes[i])) {
			fprintf(stderr, "Error creating thread\n");
			return 1;

		}
	}

	int j;
	for(j = 0; j < gThreadCount; j++){
		gThreadDone[j] = false;
	}
	while(1){
		bool thrdsComplete = true;
		for(j = 0; j < gThreadCount; j++){
			thrdsComplete = thrdsComplete && gThreadDone[j];
		}
		if(thrdsComplete){
			break;
		}
	}
	
	
    min = SearchThreadMin();
	printf("Threaded FindMin with parent continually checking on children completed in %ld ms. Min = %d\n", GetTime(), min);
	

	// Multi-threaded with semaphores  
	SetTime();

    // Write your code here
	// Initialize threads, create threads, and then make the parent wait on the "completed" semaphore 
	// The thread start function is ThFindMinWithSemaphore
	// Don't forget to properly initialize shared variables and semaphores using sem_init 
	sem_init(&completed,0,1);
	sem_init(&mutex,0,1);

	sem_wait(&completed);
	for(i = 0; i < gThreadCount; i++){
		pthread_attr_init(&attr[i]);
		if(pthread_create(&tid[i], &attr[i], ThFindMinWithSemaphore, &indexes[i])) {
			fprintf(stderr, "Error creating thread\n");
			//return 1;

		}
	}
	sem_wait(&completed);

	min = SearchThreadMin();
	printf("Threaded FindMin with parent waiting on a semaphore completed in %ld ms. Min = %d\n", GetTime(), min);
}
Exemplo n.º 6
0
void CTestPaddingCorruptPKCS7::TestCorruptPKCS7padding(TInt aBlockSize, TInt aTextSize)
	{
	CPaddingPKCS7 *padding = CPaddingPKCS7::NewLC(aBlockSize);

	TInt paddingBytes = 0;
	//Divide by 0 is undefined.
	if(aBlockSize != 0)
		{
		paddingBytes = aBlockSize - (aTextSize % aBlockSize);
		}
		
 	HBufC8 *padOutData = HBufC8::NewLC(aTextSize + paddingBytes);
 	HBufC8 *padInData = HBufC8::NewLC(aTextSize);
 	TPtr8 in(padInData->Des());
 	TPtr8 out(padOutData->Des());
 
 	GenerateInput(aTextSize, in);
 	TRAPD(err, padding->PadL(in, out));

	INFO_PRINTF2(_L("The PKCS7 padding PadL method returned error is %d"), err);
	
	//check expected result
	TPtrC expectedContent;
 	if (GetStringFromConfig(ConfigSection(), _L("case"), expectedContent))
 		{
 		if(expectedContent.Compare(_L("InvalidPadding")) ==0)
 			{
 			TEST(err == KErrInvalidPadding);
 			}
 		else if(expectedContent.Compare(_L("Valid")) ==0)
 			{
 			TEST(err == KErrNone);
 			}
 		else if(expectedContent.Compare(_L("CorruptBlockSize")) ==0)
 			{
 			TEST(err == KErrArgument);
 			}
 		}
 	
 	//skip the checking on padded data if padding is unsuccessful(no padding is done), 
 	//otherwise the erroneous operation on output descriptor will panic.
 	if(err != KErrNone)
 		{
 		CleanupStack::PopAndDestroy(3, padding);
 		return;
 		}
	
	TInt totalLength = out.Length();
	TInt inLength = in.Length();
	
	TUint paddingLength = 0;
	//Divide by 0 is undefined.
	if(aBlockSize != 0)
		{
		paddingLength = aBlockSize - inLength%aBlockSize;
		// Test that the total length is a multiple of blockSize
		TEST((totalLength % aBlockSize) == 0);
		}			
	
 	// Test that the padding bytes are equal in value to the paddingLength,
	// ie, if padding length is 5 the 5 last octets in the out array should be 0x05
	for (TInt j = paddingLength; j > 0 ; j--)
		{
		TEST(out[out.Length()-j] == paddingLength);
		}

	
 	
 	// Test that the data has not been corrupted
	TEST(in == out.Left(out.Length() - paddingLength));
 	
 	CleanupStack::PopAndDestroy(3, padding); // padInData, padOutData, padCompareData, padding
	}