Beispiel #1
0
void TLSHash::Add(TFltV Datum) {
  int Id = DataV.Len();
  DataV.Add(Datum);

  for (int i=0; i<Bands; i++) {
    TInt Sig = ComputeSignature(Datum, i);
    THash<TInt, TIntV> &SigBucketVH = SigBucketVHV[i];

    int KeyId = SigBucketVH.AddKey(Sig);
    SigBucketVH[KeyId].Add(Id);
  }
}
Beispiel #2
0
void TLSHash::AddV(TVec<TFltV> NewV) {
  int StartId = DataV.Len();
  DataV.AddV(NewV);

  #pragma omp parallel for num_threads(4) schedule(dynamic)
  for (int i=0; i<Bands; i++) {
    THash<TInt, TIntV> &SigBucketVH = SigBucketVHV[i];
    for (int j=0; j<NewV.Len(); j++) {
      int KeyId = SigBucketVH.AddKey(ComputeSignature(NewV[j], i));
      SigBucketVH[KeyId].Add(StartId+j);
    }
  }
}
int WXBizMsgCrypt::ValidateSignature(const std::string &sMsgSignature, const std::string &sTimeStamp, 
    const std::string &sNonce, const std::string & sEncryptMsg)
{
    std::string sSignature;
    if(0 != ComputeSignature(m_sToken, sTimeStamp, sNonce, sEncryptMsg, sSignature))
    {
        return -1;
    }
    
    if( sMsgSignature != sSignature)
    {
        return -1;
    }
    
    return 0;
}
int WXBizMsgCrypt::EncryptMsg(const std::string &sReplyMsg,
                const std::string &sTimeStamp,
                const std::string &sNonce,
                std::string &sEncryptMsg)
{
    if(0 == sReplyMsg.size())
    {
        return WXBizMsgCrypt_ParseXml_Error;
    }

    //1.add rand str ,len, appid
    std::string sNeedEncrypt;
    GenNeedEncryptData(sReplyMsg,sNeedEncrypt);
    
    //2. AES Encrypt
    std::string sAesData;
    std::string sAesKey;
    if(0 != GenAesKeyFromEncodingKey(m_sEncodingAESKey,sAesKey)) 
    {
        return WXBizMsgCrypt_IllegalAesKey;
    }
    if(0 != AES_CBCEncrypt(sNeedEncrypt, sAesKey, &sAesData))
    {
        return WXBizMsgCrypt_EncryptAES_Error;
    }    

    //3. base64Encode
    std::string sBase64Data;
    if( 0!= EncodeBase64(sAesData,sBase64Data) )
    {
        return WXBizMsgCrypt_EncodeBase64_Error;
    }
    
    //4. compute signature
    std::string sSignature;
    if(0!=ComputeSignature(m_sToken, sTimeStamp, sNonce, sBase64Data, sSignature))
    {
        return WXBizMsgCrypt_ComputeSignature_Error;
    }
    
    //5. Gen xml
    if(0 != GenReturnXml(sBase64Data, sSignature, sTimeStamp, sNonce, sEncryptMsg) )
    {
        return WXBizMsgCrypt_GenReturnXml_Error ;
    }
    return WXBizMsgCrypt_OK;
}
Beispiel #5
0
TVec<TFltV> TLSHash::GetCandidates(TFltV Datum) {
  THashSet<TInt> CandidateIds;
  for (int i=0; i<Bands; i++) {
    TInt Sig = ComputeSignature(Datum, i);
    THash<TInt, TIntV>& SigBucketVH = SigBucketVHV[i];

    if (!SigBucketVH.IsKey(Sig)) {
      continue;
    }
    CandidateIds.AddKeyV(SigBucketVH.GetDat(Sig));
  }

  TVec<TFltV> Candidates;
  int Ind = CandidateIds.FFirstKeyId();
  while(CandidateIds.FNextKeyId(Ind)) {
    int Id = CandidateIds[Ind];
    Candidates.Add(DataV[Id]);
  }
  return Candidates;
}
const std::string ParserFlowStep::GetSignature() const
{
   return ComputeSignature(parser_step_type, file_name);
}
Beispiel #7
0
int32_t BucketElimination::Bucket::ComputeFirstVariableDistribution(ARE_Function_TableType *dist)
{
	int32_t i, j, k, ret = 0 ;

	MBEworkspace *bews = dynamic_cast<MBEworkspace*>(_Workspace) ;
	if (NULL == bews) 
		return ERRORCODE_generic ;
	ARE::ARP *problem = bews->Problem() ;
	if (NULL == problem) 
		return ERRORCODE_generic ;
	ARE_Function_TableType nv = bews->FnCombinationNeutralValue() ;
	int32_t w = Width() ;
	if (w < 0) {
		ComputeSignature() ;
		w = Width() ;
		if (w < 0) 
			return 0 ; // should not happen; means bucket has no functions/variables.
		}
	const int32_t *signature = Signature() ;
	const int32_t nOF = nOriginalFunctions() ;
	const int32_t nAF = nAugmentedFunctions() ;
	const int32_t nIF = nIntermediateFunctions() ;
	int32_t nFunctions_OA = nOF + nAF ;
	int32_t nTotalFunctions = nOF + nAF + nIF ;
	if (w < 0 || nTotalFunctions < 1) {
		return 0 ;
		}

	if (w > MAX_NUM_VARIABLES_PER_BUCKET) 
		return ERRORCODE_too_many_variables ;
	if (nTotalFunctions > MAX_NUM_FUNCTIONS_PER_BUCKET) 
		return ERRORCODE_too_many_functions ;

	int32_t values[MAX_NUM_VARIABLES_PER_BUCKET] ; // this is the current value combination of the arguments of this function (table block).
	ARE::Function *flist[MAX_NUM_FUNCTIONS_PER_BUCKET] ; // this is a list of input functions

	ARE_Function_TableType const_factor = bews->FnCombinationNeutralValue() ;
	int32_t nFNs = 0 ;
	for (j = 0 ; j < nOF ; j++) {
		ARE::Function *f = OriginalFunction(j) ;
		if (NULL == f) continue ;
		if (0 == f->N()) bews->ApplyFnCombinationOperator(const_factor, f->ConstValue()) ;
		else { flist[nFNs++] = f ; f->ComputeArgumentsPermutationList(w, signature) ; }
		}
	for (; j < nTotalFunctions ; j++) {
		ARE::Function *f = AugmentedFunction(j - nOF) ;
		if (NULL == f) continue ;
		if (0 == f->N()) bews->ApplyFnCombinationOperator(const_factor, f->ConstValue()) ;
		else { flist[nFNs++] = f ; f->ComputeArgumentsPermutationList(w, signature) ; }
		}
	for (; j < nTotalFunctions ; j++) {
		ARE::Function *f = IntermediateFunction(j - nFunctions_OA) ;
		if (NULL == f) continue ;
		if (0 == f->N()) bews->ApplyFnCombinationOperator(const_factor, f->ConstValue()) ;
		else { flist[nFNs++] = f ; f->ComputeArgumentsPermutationList(w, signature) ; }
		}

	INT64 ElimSize = 1 ;
	for (j = 1 ; j < w ; j++) 
		ElimSize *= problem->K(signature[j]) ;

	for (j = 0 ; j < w ; j++) 
		values[j] = 0 ;
	int32_t v0 = _Vars[0] ;
	for (i = 0 ; i < problem->K(v0) ; i++) {
		ARE_Function_TableType V = bews->VarEliminationDefaultValue() ;
		for (INT64 ElimIDX = 0 ; ElimIDX < ElimSize ; ElimIDX++) {
			ARE_Function_TableType value = nv ;
			for (j = 0 ; j < nFNs ; j++) { // note : it should be that 0 != flist[j]->N(). note : it is assumed that flist[j] has 1 block. note : it is assumed that order of flist[j] arguments is the same as signature.
				INT64 adr = flist[j]->ComputeFnTableAdr_wrtLocalPermutation(w, values, problem->K()) ;
				bews->ApplyFnCombinationOperator(value, flist[j]->TableEntry(adr)) ;
				}
			bews->ApplyVarEliminationOperator(V, value) ;
			// go to next argument value combination
			ARE::EnumerateNextArgumentsValueCombination(w-1, signature+1, values+1, problem->K()) ;
			}
		bews->ApplyFnCombinationOperator(V, const_factor) ;
		dist[i] = V ;
		values[0]++ ;
		}
done :
	return ret ;
}
Beispiel #8
0
int32_t BucketElimination::Bucket::ComputeOutputFunctionWithScopeWithoutTable(int32_t * & TempSpaceForArglist, int32_t TempSpaceForArglistSize, ARE::Function * & FN, int32_t & max_var)
{
	max_var = -1 ;
	if (NULL != FN) {
		FN->Destroy() ;
		FN->SetIDX(-(_V+1)) ;
		}
	if (NULL == _Workspace) 
		return 1 ;

	if (_Width < 0) {
		int32_t res = ComputeSignature() ;
		if (0 != res) {
//			if (createdFN && NULL != FN) 
//				{ delete FN ; FN = NULL ; }
			return 1 ;
			}
		}
	if (_Width <= 0) 
		return 0 ; // bucket has no variables; that should not happen
	// if _Width - _nVars <= 0, then all variables are eliminated; output is a const fn.

	bool createdFN = false ;
	if (NULL == FN) {
		FN = new ARE::Function(_Workspace, NULL != _Workspace ? _Workspace->Problem() : NULL, -(_V+1)) ;
		if (NULL == FN) 
			return 1 ;
		FN->SetOriginatingBucket(this) ;
		createdFN = true ;
		}

	// check memory is ok for sorting
	if (TempSpaceForArglistSize < _Width) {
		if (NULL != TempSpaceForArglist) 
			{ delete [] TempSpaceForArglist ; TempSpaceForArglist = NULL ; TempSpaceForArglistSize = 0 ; }
		TempSpaceForArglist = new int32_t[_Width] ;
		if (NULL == TempSpaceForArglist) 
			return 1 ;
		TempSpaceForArglistSize = _Width ;
		}

	// construct args list; find max argument.
	const int32_t *varpos = _Workspace->VarPos() ;
	int32_t nArgs = 0 ;
	for (int32_t i = 0 ; i < _Width ; i++) {
		int32_t v = _Signature[i], j ;
		for (j = 0 ; j < _nVars ; j++) 
			{ if (v == _Vars[j]) break ; }
		if (j < _nVars) 
			continue ;
		TempSpaceForArglist[nArgs++] = v ;
		if (max_var < 0) 
			max_var = v ;
		else if (varpos[max_var] < varpos[v]) 
			max_var = v ;
		}

	// set up fn; nArgs should be _Width - _nVars
	FN->SetArguments(nArgs, TempSpaceForArglist) ;

	return 0 ;
}
const std::string FunctionFrontendFlowStep::GetSignature() const
{
   return ComputeSignature(frontend_flow_step_type, function_id);
}