Exemple #1
0
uvar32_64 CMarkStyle::GetPos () {
	for (CHash<CMarkStyle*,CMarkStyle>* p = theApp.MarkStyles.m_pHashHead; p; p = p->GetNext ())
		if (p->m_hData == this)
			if (theApp.MarkStyles.m_nActive == p->GetPos ())
				return (p->GetPos ());
	return (uvar32_64(-1));
}
Exemple #2
0
uvar32_64 CVariable::GetPos () {
	m_pTesla->Variables.m_pHashHead = m_pTesla->Variables.m_pHashHead->GetHead ();
	for (CHash<CVariable*,CVariable>* p = m_pTesla->Variables.m_pHashHead; p; p = p->GetNext ())
		if (p->m_hData == this)
			return (p->GetPos ());
	return (-1);
}
Exemple #3
0
svar32_64 CImage::GetPos () {
	m_pDoc->Images.m_pHashHead = m_pDoc->Images.m_pHashHead->GetHead ();
	for (CHash<CImage*,CImage>* p = m_pDoc->Images.m_pHashHead; p; p = p->GetNext ())
		if (p->m_hData == this)
			return (p->GetPos ());
	return (-1);
}
uvar32_64 CDiasAPIDensScales::Insert (uvar32_64 pos, CDensScale& scale) {
	if ((pos = NameLookup (scale.m_strName)) != uvar32_64(-1))
		return ((uvar32_64)-1);
	CHash<CDensScale*,CDensScale>* p = new CHash<CDensScale*,CDensScale>(&scale);
	m_pHashHead->GetAt(pos)->InsertAfter (p);
	m_pHashHead = m_pHashHead->GetHead ();
	return ((uvar32_64)(p->GetPos ()));
}
Exemple #5
0
void CM_ShutdownShaderProperties(void)
{
	if(cmShaderTable.count())
	{
//		Com_Printf("Shutting down cmShaderTable .....\n");
		cmShaderTable.clear();
	}
}
Exemple #6
0
void CBNFParser::DeleteRules()
{
	if (!m_pRootRule)
		return;
	CHash<CRule const *> hashRules;
	m_pRootRule->AddToHash(hashRules);
	hashRules.DeleteAll();
	m_pRootRule = 0;
}
Exemple #7
0
void CBNFParser::CNonTerminal::AddToHash(CHash<CRule const *> &hashRules) const
{
	CHash<CRule const *>::TIter it = hashRules.Find(this);
	if (!it) {
		hashRules.Add(this);
		for (int i = 0; i < MAX_CHILD_RULES && m_pChildren[i]; ++i)
			m_pChildren[i]->AddToHash(hashRules);
	}
}
Exemple #8
0
static long Hash(tHashAlgo hashAlgo, const CByteArray & oData)
{
	CHash oHash;
	CByteArray oHashData = oHash.Hash(hashAlgo, oData);

	printf("Hash: %s\n", oHashData.ToString(true, false).c_str());
	WriteFile("", "hash.bin", oHashData);

	return 0;
}
uvar32_64 CDiasAPIDensScales::Add (CDensScale& scale) {
	int pos;
	if ((pos = NameLookup (scale.m_strName)) != uvar32_64(-1))
		return ((uvar32_64)-1);
	CHash<CDensScale*,CDensScale>* p = new CHash<CDensScale*,CDensScale>(&scale);
	if (!m_pHashHead)
		m_pHashHead = p;
	else
		m_pHashHead->GetTail()->InsertAfter (p);
	return ((uvar32_64)(p->GetPos()));
	
}
UINT CEightPuzzleGame::GetSlove ()
{
	int nCurValue = this->ConvertMetrixToInt ( this->bBegMetrix ) ;
	int nEndValue = this->ConvertMetrixToInt ( this->bEndMetrix ) ;

	vector<ITEM> Queue ;				// 广搜的辅助队列
	CHash Hash ;						// Hash表,用于保存状态
	Queue.clear () ;			
	Queue.push_back ( ITEM(-1,nCurValue) ) ;
	Hash.AddValue ( nCurValue ) ;

	int nCurIndex = 0, nTotalIndex = 1 ;
	while ( nCurIndex < nTotalIndex )
	{
		if ( nCurIndex == 200000 )
			return 0 ;

		nCurValue = Queue[nCurIndex].nValue ;
		for ( int i = 0; i < 4; i++ )		// 枚举4个方向
		{
			this->ConvertIntToCurMetrix ( nCurValue ) ;
			if ( this->SingleMove ( i ) == FALSE )
				continue ;
			int nValue = this->ConvertMetrixToInt ( this->bCurMetrix ) ;
			// 如果这个状态首次出现,则添加辅助队列并保存到hash表
			if ( Hash.IsValueExist ( nValue ) == FALSE )
			{
				nTotalIndex ++ ;
				Hash.AddValue ( nValue ) ;
				Queue.push_back ( ITEM(nCurIndex,nValue) ) ;
				// 达到目标状态时,提取路径,注意路径为倒序
				if ( nValue == nEndValue )
				{
					this->PathList.clear () ;
					this->PathList.push_back ( nValue ) ;

					int nIndex = nCurIndex, nStep = 0 ;
					while ( TRUE )
					{
						nStep ++ ;
						this->PathList.push_back ( Queue[nIndex].nValue ) ;
						if ( ( nIndex = Queue[nIndex].nIndex ) == -1 )
							break ;
					}
					return nStep ;
				}
			}
		}
		nCurIndex++ ;
	}

	return 0 ;
}
Exemple #11
0
CDiasAPIChnlRange& CDiasAPIChannels::operator() (aImAPIRngType type) {
	m_rngInt.Reset ();
	CHash<CChannel*, CChannel>* p;
	switch (type) {
		case aimAll:
			for (p = m_pHashHead ; p ; p = p->GetNext ())
				m_rngInt.Include (p);
			break;
		case aimVisible:
			// #### TODO: Place code here
			break;
		default:
			throw (CaImAPIException (0));
	}
	return (m_rngInt);
}
Exemple #12
0
CCMShader *CM_GetShaderInfo( const char *name )
{
	CCMShader	*out;
	const char	*def;

	out = cmShaderTable[name];
	if(out)
	{
		return(out);
	}

	// Create a new CCMShader class
	out = (CCMShader *)Hunk_Alloc( sizeof( CCMShader ), h_high );
	// Set defaults
	Q_strncpyz(out->shader, name, MAX_QPATH);
	out->contentFlags = CONTENTS_SOLID | CONTENTS_OPAQUE;

	// Parse in any text if it exists
	def = CM_GetShaderText(name);
	if(def)
	{
		CM_ParseShader(out, &def);
	}

	cmShaderTable.insert(out);
	return(out);
}
Exemple #13
0
CByteArray CPkiCard::Sign(const tPrivKey & key, const tPin & Pin,
    unsigned long algo, CHash & oHash)
{
	CByteArray oHashResult = oHash.GetHash();

	return Sign(key, Pin, algo, oHashResult);
}
Exemple #14
0
void CM_FreeShaderText(void)
{
	shaderTextTable.clear();
	if(shaderText)
	{
		Z_Free(shaderText);
		shaderText = NULL;
	}
}
Exemple #15
0
	//拷贝oSrc中的元素进来。
	inline void Insert(const CHash<TKey, TData, TGetKey, TCompareKey, THashArithmetic> &oSrc)
	{
		if(this == &oSrc)
		{
			if(!m_bUnique)
			{
				uint32 i;
				CHash<TKey, TData, TGetKey, TCompareKey, THashArithmetic> o(oSrc);
				for(i=0; i<m_nBucketSize; ++i)
					m_pBuckets[i].Append(NULL, o.m_pBuckets[i]);
			}
		}
		else
		{
			CHashIterator oIt=oSrc.First(), oEnd=oSrc.End();
			for(; !oSrc.IteratorEqual(oIt, oEnd);  oIt=oSrc.GetNext(oIt))
				Insert(oSrc.GetItem(oIt));
		}
	}
Exemple #16
0
void CM_FreeShaderText(void)
{
	shaderTextTable.clear();
	// We NEVER free the shadertext anymore!
//	if(shaderText)
//	{
//		Z_Free(shaderText);
//		shaderText = NULL;
//	}
}
Exemple #17
0
static long SignVerify(CReader & oReader, tPrivKey & key,
	const CByteArray & oCertData, unsigned long ulSignAlgo)
{
	CByteArray oData(1000);
	for (int i = 0; i < 300; i++)
		oData.Append((unsigned char) rand());

	long lHashAlgo = sign2hashAlgo(ulSignAlgo);

	if (lHashAlgo != -1)
	{
		CByteArray oSignature;
	
		CHash oHash;
		oHash.Init((tHashAlgo) lHashAlgo);
		oHash.Update(oData);

		if (ulSignAlgo == SIGN_ALGO_RSA_PKCS)
		{
			// To test SIGN_ALGO_RSA_PKCS, we take as input the SHA1 AID
			// plus the SHA1 hash of oData. This way, we can use OpenSSL's
			// SHA1 signature verification in VerifySignature().
			const unsigned char SHA1_AID[] = {0x30, 0x21, 0x30, 0x09,
				0x06, 0x05, 0x2b, 0x0e, 0x03, 0x02, 0x1a, 0x05, 0x00,0x04, 0x14};
			CByteArray oTobeSigned(SHA1_AID, sizeof(SHA1_AID));
			oTobeSigned.Append(oHash.GetHash());
			oSignature = oReader.Sign(key, ulSignAlgo, oTobeSigned);
		}
		else
			oSignature = oReader.Sign(key, ulSignAlgo, oHash);

		bool bVerified = VerifySignature(oData, oSignature, oCertData, ulSignAlgo);

		return bVerified ? 0 : 1;
	}
	else
	{
		printf("      Signature algo %s can't be tested yet\n", SignAlgo2String(ulSignAlgo));
		return 0;
	}
}
Exemple #18
0
static CByteArray HashAndSign(CReader & oReader, const tPrivKey & key,
	unsigned long signAlgo, const CByteArray & oData)
{
	tHashAlgo hashAlgo;
	if (signAlgo == SIGN_ALGO_MD5_RSA_PKCS)
		hashAlgo = ALGO_MD5;
	else if (signAlgo == SIGN_ALGO_SHA1_RSA_PKCS)
		hashAlgo = ALGO_SHA1;
	else if (signAlgo == SIGN_ALGO_SHA256_RSA_PKCS)
		hashAlgo = ALGO_SHA256;
	else
	{
		printf("Unsupport signature algorithm %d, can't sign\n", signAlgo);
		return CByteArray();
	}

	CHash oHash;
	oHash.Init(hashAlgo);
	oHash.Update(oData);

	return oReader.Sign(key, signAlgo, oHash);
}
Exemple #19
0
ENDI * GetEndiInfo(EUI64 * pId)
{
    ENDI   *pEndi;
    int         nIndex;

    nIndex = g_EndListHash.Find(pId, sizeof(EUI64));
    if (nIndex == -1)
    {
        pEndi = (ENDI *) MALLOC(sizeof(ENDI));
        memset(pEndi, 0, sizeof(ENDI));
        memcpy(&pEndi->id, pId, sizeof(EUI64));
        pEndi->stream.pszBuffer = (char *)MALLOC(1024);
        memset(pEndi->stream.pszBuffer, 0, 1024);

        pEndi->position = (int)g_EndiList.AddTail(pEndi);

        g_EndListHash.Update(pId, sizeof(EUI64), pEndi->position);

        return pEndi;
    }

    pEndi = g_EndiList.Get((POSITION)nIndex);
    return pEndi;
}
void CM_LoadShaderText(qboolean forceReload)
{
	if(forceReload)
	{
		CM_FreeShaderText();
	}
	if(shaderText)
	{
		return;
	}
	Com_Printf("Loading shader text .....\n");
	CM_LoadShaderFiles();
	CM_CreateShaderTextHash();

	Com_Printf("..... %d shader definitions loaded\n", shaderTextTable.count());
}
Exemple #21
0
CByteArray CReader::Sign(const tPrivKey & key, unsigned long algo,
    CHash & oHash)
{
    if (m_poCard == NULL)
        throw CMWEXCEPTION(EIDMW_ERR_NO_CARD);

	unsigned long ulSupportedAlgos = m_poCard->GetSupportedAlgorithms();
	if ((algo & ulSupportedAlgos & SIGN_ALGO_MD5_RSA_PKCS) ||
		(algo & ulSupportedAlgos & SIGN_ALGO_SHA1_RSA_PKCS) ||
		(algo & ulSupportedAlgos & SIGN_ALGO_SHA256_RSA_PKCS) ||
		(algo & ulSupportedAlgos & SIGN_ALGO_SHA384_RSA_PKCS) ||
		(algo & ulSupportedAlgos & SIGN_ALGO_SHA512_RSA_PKCS) ||
		(algo & ulSupportedAlgos & SIGN_ALGO_RIPEMD160_RSA_PKCS))
	{
	    return m_poCard->Sign(key, GetPinByID(key.ulAuthID), algo, oHash);
	}
	else
	{
		CByteArray oHashResult = oHash.GetHash();
		return Sign(key, algo, oHashResult);
	}
}
Exemple #22
0
void CM_SetupShaderProperties(void)
{
	int			i;
	const char	*def;
	CCMShader	*shader;

	// Add all basic shaders to the cmShaderTable
	for(i = 0; i < cmg.numShaders; i++)
	{
		cmShaderTable.insert(CM_GetShaderInfo(i));
	}
	// Go through and parse evaluate shader names to shadernums
	for(i = 0; i < cmg.numShaders; i++)
	{
		shader = CM_GetShaderInfo(i);
		def = CM_GetShaderText(shader->shader);
		if(def)
		{
			CM_ParseShader(shader, &def);
		}
	}
}
Exemple #23
0
/*
====================
CM_CreateShaderTextHash
=====================
*/
void CM_CreateShaderTextHash(void)
{
	const char			*p;
	qboolean			hasNewLines;
	char				*token;
	CCMShaderText		*shader;

	p = shaderText;
	// look for label
	while (p) 
	{
		p = SkipWhitespace(p, &hasNewLines);
		token = COM_ParseExt( &p, qtrue );
		if ( !token[0] ) 
		{
			break;
		}
		shader = new CCMShaderText(token, p);
		shaderTextTable.insert(shader);

		SkipBracedSection(&p);
	}
}
Exemple #24
0
//rwwFIXMEFIXME: Called at RE_BeginRegistration because Hunk_Clear
//destroys the memory cmShaderTable is on. This is a temp solution
//I guess.
void ShaderTableCleanup()
{
	cmShaderTable.clear();
}
Exemple #25
0
void CMarkStyle::Activate () {
	for (CHash<CMarkStyle*,CMarkStyle>* p = theApp.MarkStyles.m_pHashHead; p; p = p->GetNext ())
		if (p->m_hData == this)
			theApp.MarkStyles.m_nActive = p->GetPos ();
	theApp.Update (UPDHA_MARKSTYLE);
}
Exemple #26
0
void CGeomScale::Activate () {
	for (CHash<CGeomScale*,CGeomScale>* p = theApp.GeomScales.m_pHashHead; p; p = p->GetNext ())
		if (p->m_hData == this)
			theApp.GeomScales.m_nActive = p->GetPos ();
	theApp.Update (UPDHA_GEOMSCALE);
}
TVerdict CHmacSetOperationModeCheckingStep::doTestStepL()
	{
	if (TestStepResult()==EPass)
		{
		
		//Assume faliure, unless all is successful
		SetTestStepResult(EFail);
		
		INFO_PRINTF1(_L("*** Hmac - Set Operation Mode Checking ***"));
		INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells());
		
		TVariantPtrC algorithmUid;
		TVariantPtrC operationModeUid;
		TVariantPtrC secondOperationModeUid;
		TPtrC sourcePath;
		TPtrC expectedHash;
		TPtrC expectedHmac;
		TPtrC encryptKey;
		TVariantPtrC keyType;
		
		//Extract the Test Case ID parameter from the specified INI file
		if(!GetStringFromConfig(ConfigSection(),KConfigAlgorithmUid,algorithmUid) ||
			!GetStringFromConfig(ConfigSection(),KConfigOperationMode,operationModeUid) ||
			!GetStringFromConfig(ConfigSection(),KConfigSecondOperationMode,secondOperationModeUid) ||
			!GetStringFromConfig(ConfigSection(),KConfigSourcePath,sourcePath) ||
			!GetStringFromConfig(ConfigSection(),KConfigExHashHmacValue,expectedHash) ||
			!GetStringFromConfig(ConfigSection(),KConfigExSecondHashHmacValue,expectedHmac) ||
			!GetStringFromConfig(ConfigSection(),KConfigEncryptKey,encryptKey) ||
			!GetStringFromConfig(ConfigSection(),KConfigEncryptKeyType,keyType))
			{
			ERR_PRINTF1(_L("** Error: Failed to Load Configuration Parameters **"));
			SetTestStepResult(EFail);
			}
		else
			{	
			RFs fsSession;
				
			//Create a connection to the file server	
			User::LeaveIfError(fsSession.Connect());
						
			RFile sourceFile;
	    	CleanupClosePushL(sourceFile);
	    			
	    	//Open the specified source file		
	    	User::LeaveIfError(sourceFile.Open(fsSession,sourcePath, EFileRead));
	    					
			TInt sourceLength = 0;
			User::LeaveIfError(sourceFile.Size(sourceLength));
						
			//Create a heap based descriptor to store the data
			HBufC8* sourceData = HBufC8::NewL(sourceLength);						
			CleanupStack::PushL(sourceData);
			TPtr8 sourcePtr = sourceData->Des();
						
			sourceFile.Read(sourcePtr);
							
			if(sourcePtr.Length() != sourceLength)
				{
				ERR_PRINTF1(_L("*** Error: Reading Source File ***"));
				SetTestStepResult(EFail);	
				}
			else
				{
				//Create a pointer for the Hash + Key (Hmac) Implementation Object
				CHash* hashHmacImpl = NULL;
				
				//Convert encryption key to an 8 Bit Descriptor
				HBufC8* keyStr = HBufC8::NewLC(encryptKey.Length());
				TPtr8 keyStrPtr = keyStr->Des();
				
				keyStrPtr.Copy(encryptKey);
				
				//Create an new CryptoParams object to encapsulate the invalid key type and key string
				CCryptoParams* keyParams = CCryptoParams::NewL();
				CleanupStack::PushL(keyParams);
				keyParams->AddL(*keyStr,keyType);
				
				//Create a valid CKey Object
				TKeyProperty keyProperty;
				CKey* key = CKey::NewL(keyProperty,*keyParams);
				CleanupStack::PushL(key);
				
				//Construct an initial hash object with NO key, Catching any possible Leaves			
				TRAPD(err,CHashFactory::CreateHashL(
									hashHmacImpl,
									algorithmUid,
									operationModeUid,
									NULL,
									NULL));
									
										
				if(hashHmacImpl && (err == KErrNone))
					{
					
					//Push the Implementation Object onto the Cleanup Stack
					CleanupStack::PushL(hashHmacImpl);
					
					//Create a NULL TCharacteristics pointer
					const TCharacteristics* charsPtrA(NULL);
					
					//Retrieve the characteristics for the hash implementation object
					TRAP_LOG(err, hashHmacImpl->GetCharacteristicsL(charsPtrA));
					
					//Static cast the characteristics to type THashCharacteristics
					const THashCharacteristics* hashCharsPtrA = static_cast<const THashCharacteristics*>(charsPtrA);
					
					//The hash output size is returned in Bits, divide by 8 to get the Byte size
					TInt hashSize = hashCharsPtrA->iOutputSize/8;
					
					//Retrieve the final 8bit hash value and convert to 16bit												
					HBufC* hashDataA = HBufC::NewLC(hashSize);
					TPtr hashPtrA = hashDataA->Des();
					
					hashPtrA.Copy(hashHmacImpl->Hash(*sourceData));
					
					//Take the 16bit descriptor and convert the string to hexadecimal
					TVariantPtrC convertHash;
					convertHash.Set(hashPtrA);
					
					HBufC* resultA = convertHash.HexStringLC();							
						
					INFO_PRINTF2(_L("*** Hashed Data: %S ***"),&*resultA);
					INFO_PRINTF2(_L("*** Expected Hash: %S ***"),&expectedHash);
					
					if(*resultA == expectedHash)
						{
						INFO_PRINTF1(_L("*** PRIMARY HASH VALID - STAGE 1 PASS ***"));
						
						//Set the valid key within the Hmac Implementation Object
						TRAP(err,hashHmacImpl->SetKeyL(*key));
						
						if(err!=KErrNone)
							{
							ERR_PRINTF2(_L("*** ERROR %d: Setting Key ***"),err);
							User::Leave(err);	
							}
						else
							{
							INFO_PRINTF1(_L("*** HMAC KEY SET ***"));	
							}
										
						//Set the Operation Mode of the Hmac Implementation Object
						hashHmacImpl->SetOperationModeL(secondOperationModeUid);
						
						if(err!=KErrNone)
							{
							ERR_PRINTF3(_L("*** ERROR %d: Setting Operation Mode %S ***"),err,&secondOperationModeUid);	
							User::Leave(err);
							}
						else
							{
							INFO_PRINTF2(_L("*** OPERATION MODE SET : %S ***"),&secondOperationModeUid);	
							}
						
						//Create a NULL TCharacteristics pointer
						const TCharacteristics* charsPtrB(NULL);
					
						//Retrieve the characteristics for the hash implementation object
						TRAP_LOG(err, hashHmacImpl->GetCharacteristicsL(charsPtrB));
					
						//Static cast the characteristics to type THashCharacteristics
						const THashCharacteristics* hashCharsPtrB = static_cast<const THashCharacteristics*>(charsPtrB);
						
						//The hash output size is returned in Bits, divide by 8 to get the Byte size
						hashSize = hashCharsPtrB->iOutputSize/8;
						
						//Retrieve the final 8bit hash value and convert to 16bit												
						HBufC* hashDataB = HBufC::NewLC(hashSize);
						TPtr hashPtrB = hashDataB->Des();
						
						hashPtrB.Copy(hashHmacImpl->Hash(*sourceData));
						
						//Take the 16bit descriptor and convert the string to hexadecimal
						convertHash.Set(hashPtrB);
						HBufC* resultB = convertHash.HexStringLC();						
						
						INFO_PRINTF2(_L("*** Hashed Data: %S ***"),&*resultB);
						INFO_PRINTF2(_L("*** Expected Hash: %S ***"),&expectedHmac);
						
						if(*resultB == expectedHmac)
							{
							INFO_PRINTF1(_L("*** SECONDARY HASH VALID - STAGE 2 PASS ***"));
							
							//Set the Operation Mode of the Hmac Implementation Object
							TRAP(err,hashHmacImpl->SetOperationModeL(operationModeUid));
							
							if(err!=KErrNone)
								{
								ERR_PRINTF3(_L("*** ERROR %d: Setting Operation Mode %S ***"),err,&operationModeUid);	
								User::Leave(err);
								}
							else
								{
								INFO_PRINTF2(_L("*** OPERATION MODE SET : %S ***"),&operationModeUid);	
								}
								
							//Create a NULL TCharacteristics pointer
							const TCharacteristics* charsPtrC(NULL);
						
							//Retrieve the characteristics for the hash implementation object
							TRAP_LOG(err, hashHmacImpl->GetCharacteristicsL(charsPtrC));
						
							//Static cast the characteristics to type THashCharacteristics
							const THashCharacteristics* hashCharsPtrC = static_cast<const THashCharacteristics*>(charsPtrC);
							
							//The hash output size is returned in Bits, divide by 8 to get the Byte size
							hashSize = hashCharsPtrC->iOutputSize/8;
							
							//Retrieve the final 8bit hash value and convert to 16bit												
							HBufC* hashDataC = HBufC::NewLC(hashSize);
							TPtr hashPtrC = hashDataC->Des();
							
							hashPtrC.Copy(hashHmacImpl->Hash(*sourceData));
							
							//Take the 16bit descriptor and convert the string to hexadecimal
							convertHash.Set(hashPtrC);
							HBufC* resultC = convertHash.HexStringLC();							
							
							INFO_PRINTF2(_L("*** Hashed Data: %S ***"),&*resultC);
							INFO_PRINTF2(_L("*** Expected Hash: %S ***"),&expectedHash);
									
							if(*resultC == expectedHash)
								{
								INFO_PRINTF1(_L("*** FINAL HASH VALID - STAGE 3 PASS ***"));
								INFO_PRINTF1(_L("*** Hmac - Set Operation Mode Checking : PASS ***"));
								SetTestStepResult(EPass);
								}
							else
								{
								ERR_PRINTF1(_L("*** STAGE 3 FAIL: Hash and Expected Value Mismatch ***"));
								SetTestStepResult(EFail);	
								}
								
							CleanupStack::PopAndDestroy(resultC);
							CleanupStack::PopAndDestroy(hashDataC);
							}
						else
							{
							ERR_PRINTF1(_L("*** STAGE 2 FAIL: Hash and Expected Value Mismatch ***"));
							SetTestStepResult(EFail);	
							}
							
						CleanupStack::PopAndDestroy(resultB);
						CleanupStack::PopAndDestroy(hashDataB);	
						}
					else
						{
						ERR_PRINTF1(_L("*** STAGE 1 FAIL: Hash and Expected Value Match ***"));
						SetTestStepResult(EFail);	
						}
						
					CleanupStack::PopAndDestroy(resultA);
					CleanupStack::PopAndDestroy(hashDataA);
					CleanupStack::PopAndDestroy(hashHmacImpl);										
					}
				else if(err==KErrNotSupported)
					{
					if((((TUid)operationModeUid != KHashModeUid) && ((TUid)operationModeUid != KHmacModeUid)) ||
						((TUid)algorithmUid != KMd2Uid) && (TUid)algorithmUid != KMd5Uid && (TUid)algorithmUid != KSha1Uid && (TUid)algorithmUid != KMd4Uid && (TUid)algorithmUid != KSha224Uid && (TUid)algorithmUid != KSha256Uid && (TUid)algorithmUid != KSha384Uid && (TUid)algorithmUid != KSha512Uid)
						{
						ERR_PRINTF2(_L("*** Object Load Failure - Invalid Operation Mode : %d ***"), err);
						User::Leave(err);	
						}
					else
						{
						SetTestStepResult(EFail);	
						}
					}
				else
					{
					ERR_PRINTF2(_L("*** Hash/Hmac Facotry Object Load Failure : %d ***"), err);
					User::Leave(err);	
					}
					
				CleanupStack::PopAndDestroy(key);
				CleanupStack::PopAndDestroy(keyParams);
				CleanupStack::PopAndDestroy(keyStr);
				}
							
			CleanupStack::PopAndDestroy(sourceData);
								
			//Cleanup the Source RFile	
			CleanupStack::PopAndDestroy();	
						
			fsSession.Close();	
			}
			
		}
		else
		{
			SetTestStepResult(EFail);	
		}		
		
	INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells());	
	
	return TestStepResult();
	}
Exemple #28
0
void CDensScale::Activate () {
	for (CHash<CDensScale*,CDensScale>* p = theApp.DensScales.m_pHashHead; p; p = p->GetNext ())
		if (p->m_hData == this)
			theApp.DensScales.m_nActive = p->GetPos ();
	theApp.Update (UPDHA_DENSSCALE);
}
Exemple #29
0
/*-----------------------------------------------CIRexxApp::addRecordsToIndex-+
|                                                                             |
+----------------------------------------------------------------------------*/
void CIRexxApp::addRecordsToIndex(CArray<ScriptRecord *> & records, CDatabase * db, UInt16 cat, char * dbi)
{
   UInt16 index = 0;
   UInt32 rowId;
   MemHandle hMem;
   Int16 recordPosition = 0;
   CHash<unsigned int, Int16> recordPositionBySegmentId;
   ScriptRecord * scriptRecord;

   if (db == 0) { return; }
   while ((hMem = db->QueryNextInCategory(index, cat))) {
      db->GetRecordUniqueID(index, rowId);
      UInt32 size = MemHandleSize(hMem);
      const char * pMem = (char *)MemHandleLock(hMem);
      /*
      | FORMAT:
      | %6s #segment.<no>#\ndate() time() <id>\nTitle: <tit>\nCategory: <cat>
      */
      char * scanner;
      if (                    // if it's segmented, combine the segments
         (scanner = StrStr(pMem, "#segment.")) &&
         (scanner = StrChr(scanner + 1, '#'))
      ) {
         char segmentNoAsString[5];
         memcpy(segmentNoAsString, scanner - 4, 4);
         segmentNoAsString[4] = '\0';
         int segmentNo = StrAToI(segmentNoAsString);
         ++scanner;
         int peditHeaderSize = size - (scanner - pMem);
         if (peditHeaderSize > ScriptRecord::MAX_PEDITHEADERLEN) {
            peditHeaderSize = ScriptRecord::MAX_PEDITHEADERLEN;
         }
         RexxString header(scanner, peditHeaderSize);
         RexxString segmentIdAsString;
         segmentIdAsString.wordAt(header, 3);
         unsigned int segmentId = hex2uint(
            (char const *)segmentIdAsString, segmentIdAsString.length()
         );
         int titWordNo = RexxString("Title:").wordpos(header, 1);
         int catWordNo = RexxString("Category:").wordpos(header, 1);
         RexxString title;
         title.subword(header, titWordNo + 1, catWordNo - (titWordNo + 1));
         // create the script record
         Int16 * psegmentedRecordPosition = (Int16 *)recordPositionBySegmentId.Lookup(segmentId);
         // if this segment has already been encountered, then create a chain of segments
         if (psegmentedRecordPosition) {
            ScriptRecord * sr = records[*psegmentedRecordPosition];
            sr->m_indexes.Insert(sr->m_indexes.GetCount(), index);
            sr->m_segments.Insert(sr->m_segments.GetCount(), segmentNo);
         // otherwise just add it
         }else {
            scriptRecord = new ScriptRecord(db, dbi, title, index, segmentNo);
            recordPositionBySegmentId.SetAt(segmentId, recordPosition);
            records.Insert(recordPosition++, scriptRecord);
         }
      }else { // otherwise just add it
         unsigned int i;
         for (i=0; pMem[i] && pMem[i] != linefeedChr && i < ScriptRecord::MAX_TITLELEN; ++i) {
            ;
         }
         char * t = new char[i + 1];
         memcpy(t, pMem, i);
         t[i] = '\0';
         RexxString title(t);
         scriptRecord = new ScriptRecord(db, dbi, title, index);
         delete [] t;
         records.Insert(recordPosition++, scriptRecord);
      }
      MemHandleUnlock(hMem);
      ++index;
   }
}
TVerdict CHashIncrementalHashWithCopyStep::doTestStepL()
	{
	if (TestStepResult()==EPass)
		{
		
		//Assume faliure, unless all is successful
		SetTestStepResult(EFail);
		
		INFO_PRINTF1(_L("*** Hash - Incremental Hash with Copy ***"));
		INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells());
		
		TVariantPtrC algorithmUid;
		TVariantPtrC operationModeUid;
		TPtrC sourcePath;
		TPtrC expectedHash;
		
		//Extract the Test Case ID parameter from the specified INI file
		if(!GetStringFromConfig(ConfigSection(),KConfigAlgorithmUid,algorithmUid) ||
			!GetStringFromConfig(ConfigSection(),KConfigOperationMode,operationModeUid) ||
			!GetStringFromConfig(ConfigSection(),KConfigSourcePath,sourcePath) ||
			!GetStringFromConfig(ConfigSection(),KConfigExHashHmacValue,expectedHash))
			{
			ERR_PRINTF1(_L("** Error: Failed to Load Configuration Parameters **"));
			SetTestStepResult(EFail);
			}
		else
			{
			//Create a pointer for the Hash Implementation Object
			CHash* hashImpl = NULL;
			
			//Retrieve a Hash Factory Object					
			TRAPD(err,CHashFactory::CreateHashL(hashImpl,
												algorithmUid,
												operationModeUid,
												NULL,
												NULL));  				
	
			if(hashImpl && (err == KErrNone))
				{
				
				//Push the Hash Implementation Object onto the Cleanup Stack
				CleanupStack::PushL(hashImpl);
				
				RFs fsSession;
				
				//Create a connection to the file server	
				err = fsSession.Connect();
					
				if(err != KErrNone)
					{
					ERR_PRINTF2(_L("*** Error: File Server Connection - %d ***"), err);
					SetTestStepResult(EFail);
					}	
				else
					{
					RFile sourceFile;
					CleanupClosePushL(sourceFile);
	    			
	    			//Open the specified source file		
	    			err = sourceFile.Open(fsSession,sourcePath, EFileRead);
	    					
	    			if(err != KErrNone)
						{
						ERR_PRINTF2(_L("*** Error: Opening Source File - %d ***"), err);
						SetTestStepResult(EFail);
						}
					else
						{
						
						TInt sourceLength = 0;
						TInt readPosition = 0;
						TInt readIncrement = 0;
						TBool hashComplete = EFalse;
						TBool hashCopied = EFalse;
						TPtrC8 hashStr;
						
						CHash* hashCopyImpl = NULL;
						
						User::LeaveIfError(sourceFile.Size(sourceLength));
						
						//Divide the total size of the source file up into individual equal sized blocks to read
						//over several increments
						readIncrement = sourceLength/KDataReadBlocks;
						
						do 
							{							
							//Create a heap based descriptor to store the data
							HBufC8* sourceData = HBufC8::NewL(readIncrement);
							CleanupStack::PushL(sourceData);
							TPtr8 sourcePtr = sourceData->Des();
							
							//Read in a block of data from the source file from the current position
							err = sourceFile.Read(readPosition,sourcePtr,readIncrement);
							
							//Update the read position by adding the number of bytes read
							readPosition += readIncrement;
							
							if(readPosition == readIncrement)
								{
								//Read in the first block from the data file into the Hash implementation object
								hashImpl->Hash(*sourceData);
								INFO_PRINTF2(_L("Intial Hash - Bytes Read: %d"), readPosition);
								}
							else if(readPosition >= sourceLength)
								{
								//Reading in the final block, constructs the complete hash value and returns it within a TPtrC8
								hashStr.Set(hashCopyImpl->Final(*sourceData));
								
								//Sets the Complete Flag to ETrue in order to drop out of the loop
								hashComplete = ETrue;
								
								TInt totalRead = (readPosition - readIncrement) + (*sourceData).Length();
								INFO_PRINTF2(_L("Final Hash - Bytes Read: %d"),totalRead);
								}
							//If the read position is half the source length and the implementation
							//object hasn't already been copied
							else if((readPosition >= sourceLength/2) && (hashCopied == EFalse))
								{
								//Update the hash message before copying
								hashImpl->Update(*sourceData);
								
								INFO_PRINTF1(_L("Copying Hash Object..."));
								
								//Create a Copy of the existing Hash Object and all internal state of the message digest
								hashCopyImpl = hashImpl->CopyL();
								
								hashCopied = ETrue;
								
								INFO_PRINTF2(_L("*** HASH COPY - Bytes Read: %d ***"), readPosition);
								}
							else
								{
								//Update the message data within the Hash object with the new block
								if(hashCopied == EFalse)
									{
									hashImpl->Update(*sourceData);
									INFO_PRINTF2(_L("Hash Update - Bytes Read: %d"), readPosition);		
									}
								else
									{
									hashCopyImpl->Update(*sourceData);
									INFO_PRINTF2(_L("Hash Update (Copy) - Bytes Read: %d"), readPosition);		
									}
								}
							
							CleanupStack::PopAndDestroy(sourceData);
							
								
							}while(hashComplete == EFalse);
						
						//Create a NULL TCharacteristics pointer
						const TCharacteristics* charsPtr(NULL);
						
						//Retrieve the characteristics for the hash implementation object
						TRAP_LOG(err, hashImpl->GetCharacteristicsL(charsPtr));
						
						//Static cast the characteristics to type THashCharacteristics
						const THashCharacteristics* hashCharsPtr = static_cast<const THashCharacteristics*>(charsPtr);
						
						//The hash output size is returned in Bits, divide by 8 to get the Byte size
						TInt hashSize = hashCharsPtr->iOutputSize/8;
						
						//Retrieve the final 8bit hash value and convert to 16bit												
						HBufC* hashData = HBufC::NewLC(hashSize);
						TPtr hashPtr = hashData->Des();
						
						//Copy the hashed content into the heap based descriptor
						hashPtr.Copy(hashStr);
						
					 	//Take the 16bit descriptor and convert the string to hexadecimal
						TVariantPtrC convertHash;
						convertHash.Set(hashPtr);
						HBufC* hashResult = convertHash.HexStringLC();
						
						INFO_PRINTF2(_L("*** Hashed Data: %S ***"),&*hashResult);
						INFO_PRINTF2(_L("*** Expected Hash: %S ***"),&expectedHash);
						
						//If the returned hash value matches the expected hash, Pass the test		
						if(*hashResult == expectedHash)
							{
							INFO_PRINTF1(_L("*** Hash - Incremental Hash with Copy : PASS ***"));
							SetTestStepResult(EPass);	
							}
						else
							{
							ERR_PRINTF2(_L("*** FAIL: Hashed and Expected Value Mismatch  ***"), err);
							SetTestStepResult(EFail);	
							}
								
						CleanupStack::PopAndDestroy(hashResult);
						CleanupStack::PopAndDestroy(hashData);						
						
						delete hashCopyImpl;
						}
					
					//Cleanup the Source RFile	
					CleanupStack::PopAndDestroy();	
					}

				fsSession.Close();	
				
				CleanupStack::PopAndDestroy(hashImpl);
				}
			else
				{
				ERR_PRINTF2(_L("*** FAIL: Failed to Create Hash Object - %d ***"), err);
				SetTestStepResult(EFail);	
				}
			}
			
		}
		
	INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells());
	return TestStepResult();
	}