Exemple #1
0
/**
 * Implementation of hash function «ГОСТ Р 34.11—2012».
 * RFC: 6986 https://tools.ietf.org/html/rfc6986
 * GOST: http://protect.gost.ru/document.aspx?control=7&id=180209
 * 
 * @param hash Output buffer for 256/512-bit hash.
 * @param msg Entire message.
 * @param length Message length in bits.
 * @param is_512 true for 512-bit hash, false for 256-bit hash.
 * @return 0 — on success, 1 — on error.
 */
int streebog(WORD *hash, const unsigned char *msg, uint64_t length, bool is_512)
{
	WORD h[WORDS_IN_CHUNK];
	WORD N[WORDS_IN_CHUNK];
	WORD uint512[WORDS_IN_CHUNK]; /* 512-bit unsigned integer. Little endian. */
	WORD Sigma[WORDS_IN_CHUNK];
	WORD padding[WORDS_IN_CHUNK];
	WORD zero[WORDS_IN_CHUNK];
	WORD *m;
	uint64_t len = length;
	
	for(int i = 0; i < 12; ++i) init_chunk(C[i], C_STR[i]);
	
	chunk_set(N, 0);
	chunk_set(Sigma, 0);
	chunk_set(zero, 0);
	set_uint512(uint512, 512);
	
	m = (WORD *)msg;
	if(is_512) chunk_set(h, 0);
	else chunk_set(h, WADDING);
	
	/* stage 2 */
	while(len >= CHUNK_BITS)
	{
		gN(h, m, N);
		
		add512(N, uint512);
		add512(Sigma, m);
		len -= CHUNK_BITS;
		m += WORDS_IN_CHUNK;
	}
	/* stage 3 */
	/* 3.1. */
	pad(padding, msg + length / CHUNK_BITS * CHUNK_SIZE, len);
	/* 3.2. */	
	gN(h, padding, N);
	
	/* 3.3. */
	set_uint512(uint512, len);
	add512(N, uint512);
	/* 3.4. */
	add512(Sigma, padding);
	/* 3.5. */
	gN(h, N, zero);
	/* 3.6. */
	gN(h, Sigma, zero);
	/* 3.7. */
	chunk_cpy(hash, h, is_512);
	return 0;
}
double LCOBPMOcta1::MeasurePho(double TimeLocal, double TShiftEff)
{
	double TmpBeamExt, TmpBeamLoc;
	double TShiftDist;
	double  ResMes;
	LCVector n(MT);
	
	n = ( orb->position(iSC,TimeLocal) - orb->position(iSCLink, TimeLocal) ).unit(); 
	
	TShiftDist = TShiftEff - orb->Arm(iSCLink, iSC, TimeLocal);
	
	//if(TimeLocal>10.)
	//	Cout << Name << " : delay = " << TShiftDist << Endl;
	
	if(TypeOBPM == 0){
		//! *** Computing the GWs signal here is more precise but slower when the physical time step is small
		GWSignal = sGW(TimeLocal);
		//fCheck << TimeLocal << " " << GWSignal << Endl;
		//Cout << Name << " : t = " << TimeLocal << " GWSignal = " << GWSignal << Endl;
		
		/*! ** Compute the incoming beam path throught the distant optical bench and local optical bench :
		 *	\f$ b_{ext}(t_{USO}) = D_{IJ}(t_{USO}) (p_{I} + n_{IJ,x} a_{I,x} + n_{IJ,y} a_{I,y} + n_{IJ,z} a_{I,z})  - n_{IJ,x} a_{J,x} - n_{IJ,y} a_{J,y} - n_{IJ,z} a_{J,z} \f$ 
		 */
		TmpBeamExt = GWSignal ;
		TmpBeamExt += gN(5, TShiftDist );
		TmpBeamExt += n.x() * gN(6, TShiftDist );
		TmpBeamExt += n.y() * gN(7, TShiftDist );
		TmpBeamExt += n.z() * gN(8, TShiftDist );
		TmpBeamExt -= n.x() * gN(2, TShiftEff );
		TmpBeamExt -= n.y() * gN(3, TShiftEff );
		TmpBeamExt -= n.z() * gN(4, TShiftEff );
		
		/*! ** Compute the local beam path throught the optical bench :
		 * \f$ b_{loc}(t_{USO}) = b_{J}(t_{USO}) =  s_J^{SN}(t_{USO}) + p_J(t_{USO})  \f$
		 */
		//Cout << gFSN(TimeLocal) << Endl;
		TmpBeamLoc = gFSN(TimeLocal)*gN(0, TShiftEff) + gN(1, TShiftEff) 	;
		
	}
		
	//! ** Interference : \f$ s_i = b_{ext}(t_{USO}) - b_{loc}(t_{USO})  \f$
	ResMes = TmpBeamExt - TmpBeamLoc ;
	//fCheck << TimeLocal << " "  << ResMes << " " << TmpBeamExt << " " << TmpBeamLoc << Endl;
	
	return(ResMes);
}