示例#1
0
文件: uva-12144.cpp 项目: c-a/Impa
int main() {
  while (true) {
    int N, M;
    scanf("%d %d", &N, &M);
    if (N == 0 && M == 0)
      break;

    int S, D;
    scanf("%d %d", &S, &D);

    Graph<int> G(N);
    for (int m = 0; m < M; ++m) {
      int u, v, p;
      scanf("%d %d %d", &u, &v, &p);
      G.add_edge(u, v, p);
    }

    Dijkstra<int> di(G, S);
    std::set<int> short_edges;
    for (const auto& e : di.get_shortest_edges(D))
      short_edges.insert(e.index);

    Graph<int> G2(N);
    for (int u = 0; u < N; ++u) {
      for (const auto& e : G.adj(u)) {
        if (short_edges.find(e.index) == short_edges.end())
          G2.add_edge(e.from, e.to, e.cost);
      }
    }

    Dijkstra<int> di2(G2, S);
    int res = di2.has_path(D) ? di2.get_cost(D) : -1;
    printf("%d\n", res);
  }
}
示例#2
0
DifferenceGraph<GraphT> updatedVoronoiDiagram(const GraphT& G, const Vector2 sites[], index_t l)
{
	//埋め込まれた部分グラフを除去したグラフを構築し、新たなボロノイ図 Phi_3 を得る
	InducedSubgraph<GraphT> T1 = embedRegion(G, sites, l);

	//BUG! boundaryHalfedgeのbisector/Circumcenterがおかしい(頂点座標が全て原点になっている)
	DifferenceGraph<GraphT> G2(G, std::move(T1));
	return std::move(G2);
}
示例#3
0
int main(int argc, char** argv) {
	Giornale G1(12.50, "Titolo1", false);
	Giornale G2(1.50, "Titolo2", true);
	Giornale G3(2.00, "Titolo3", false);
	Rivista R4(22.70, "Titolo4", false, "Editore4", "Periodo4");
	Rivista R5(11.50, "Titolo5", true, "Editore5", "Periodo5");
	Rivista R6(6.00, "Titolo6", false,  "Editore6", "Periodo6");
	Quotidiano Q7(6.35, "Titolo7", false, "Direttore7", true);
	Quotidiano Q8(9.99, "Titolo8", true, "Direttore8", false);
	Quotidiano Q9(5, "Titolo9", false, "Direttore9", true);
	
	cout<<"Polimorfismo:\n";
	Giornale * vett[9];
	vett[0] = &G1;
	vett[1] = &G2;
	vett[2] = &G3;
	vett[3] = &R4;
	vett[4] = &R5;
	vett[5] = &R6;
	vett[6] = &Q7;
	vett[7] = &Q8;
	vett[8] = &Q9;
	
	for(int i=0; i<9; i++) {
		cout << *vett[i] << "\n\n";
	}
	
	cout<<"\n\nPila:\n";
	Pila P;
	for(int i=0; i<9; i++) {
		P.push(vett[i]);
	}
	cout<<P;
	
	ofstream file;
	file.open("./test.txt", ios::out);
	if(!file) {
		cout<<"Errore apertura file.";
	} else {
		file << P;
	}
	file.close();
	
	Rivista R10(1.00, "Titolo10", false,  "Editore10", "Periodo10");
	Quotidiano Q11(1.35, "Titolo11", false, "Direttore11", true);
	
	P.push(&R10);
	
	cout<<"\n\nEccezione:\n";
	try {
		P.push(&Q11);
	} catch(SpaceOverflow e) {
		cout<<e.errorLog();
	}
	return 0;
}
示例#4
0
void 
CAST5decrypt(const PGPUInt8 *in, PGPUInt8 *out, const PGPUInt32 *xkey)
{
	PGPUInt32 l, r, t;

	r = (PGPUInt32) in[0]<<24 | (PGPUInt32) in[1]<<16 | 
		(PGPUInt32) in[2]<<8 | in[3];

	l = (PGPUInt32) in[4]<<24 | (PGPUInt32) in[5]<<16 | 
		(PGPUInt32) in[6]<<8 | in[7];

	t = F1(l, xkey, 15); r ^= G1(t);
	t = F3(r, xkey, 14); l ^= G3(t);
	t = F2(l, xkey, 13); r ^= G2(t);
	t = F1(r, xkey, 12); l ^= G1(t);
	// Start here if only doing 12 rounds
	t = F3(l, xkey, 11); r ^= G3(t);
	t = F2(r, xkey, 10); l ^= G2(t);
	t = F1(l, xkey,  9); r ^= G1(t);
	t = F3(r, xkey,  8); l ^= G3(t);
	t = F2(l, xkey,  7); r ^= G2(t);
	t = F1(r, xkey,  6); l ^= G1(t);
	t = F3(l, xkey,  5); r ^= G3(t);
	t = F2(r, xkey,  4); l ^= G2(t);
	t = F1(l, xkey,  3); r ^= G1(t);
	t = F3(r, xkey,  2); l ^= G3(t);
	t = F2(l, xkey,  1); r ^= G2(t);
	t = F1(r, xkey,  0); l ^= G1(t);

	out[0]	= (PGPUInt8) B0(l);
	out[1]	= (PGPUInt8) B1(l);
	out[2]	= (PGPUInt8) B2(l);
	out[3]	= (PGPUInt8) B3(l);
	out[4]	= (PGPUInt8) B0(r);
	out[5]	= (PGPUInt8) B1(r);
	out[6]	= (PGPUInt8) B2(r);
	out[7]	= (PGPUInt8) B3(r);
}
示例#5
0
bool test(accelerator_view &rv)
{
    const int size = 100;

    vector<int> A(size);
    vector<s> G1(size);
    vector<int> G2(size);
    vector<double> G3(size);

    for(int i = 0; i < size; i++)
    {
        A[i] = INIT_VALUE;
        G1[i].i = 2;
        G1[i].d = 2;
        G1[i].ul = 2;
        G1[i].f = 2;
    }

    extent<1> e(size);

    array<int, 1> aA(e, A.begin(), rv);
    array<s, 1> aG1(e, G1.begin(), rv);
    array<int, 1> aG2(e, G2.begin(), rv);
    array<double, 1> aG3(e, G3.begin(), rv);

    parallel_for_each(aA.get_extent(), [&](index<1>idx) __GPU
    {
        s o;

        o.i = 2;
        o.d = 2;
        o.ul = 2;
        o.f = 2;

        const s o2 = o;

        const s* ps = 0;
        ps = &o2;

        if (!Equal(ps->i, 2) || !Equal(ps->d, (double)2) || !Equal(ps->ul, (unsigned long)2) || !Equal(ps->f, (float)2))
            aA[idx] = 1;

        const int i1 = 1;
        const int *pi1 = &i1;
        const double d1 = 1;
        const double *pd1 = &d1;

        if (!Equal(*pi1, (int)1) || !Equal(*pd1, (double)1))
            aA[idx] = 1;
    });
示例#6
0
/*
 * Encrypt the 8 bytes at *in into the 8 bytes at *out using the expanded
 * key schedule from *xkey.
 */
static void
CAST5encrypt(PGPByte const *in, PGPByte *out, PGPUInt32 const *xkey)
{
	PGPUInt32 l, r, t;

	l = (PGPUInt32)
		in[0]<<24 | (PGPUInt32)in[1]<<16 | (PGPUInt32)in[2]<<8 | in[3];
	r = (PGPUInt32)
		in[4]<<24 | (PGPUInt32)in[5]<<16 | (PGPUInt32)in[6]<<8 | in[7];

	t = F1(r, xkey,  0); l ^= G1(t);
	t = F2(l, xkey,  1); r ^= G2(t);
	t = F3(r, xkey,  2); l ^= G3(t);
	t = F1(l, xkey,  3); r ^= G1(t);
	t = F2(r, xkey,  4); l ^= G2(t);
	t = F3(l, xkey,  5); r ^= G3(t);
	t = F1(r, xkey,  6); l ^= G1(t);
	t = F2(l, xkey,  7); r ^= G2(t);
	t = F3(r, xkey,  8); l ^= G3(t);
	t = F1(l, xkey,  9); r ^= G1(t);
	t = F2(r, xkey, 10); l ^= G2(t);
	t = F3(l, xkey, 11); r ^= G3(t);
	/* Stop here if only doing 12 rounds */
	t = F1(r, xkey, 12); l ^= G1(t);
	t = F2(l, xkey, 13); r ^= G2(t);
	t = F3(r, xkey, 14); l ^= G3(t);
	t = F1(l, xkey, 15); r ^= G1(t);

	out[0] = B0(r);
	out[1] = B1(r);
	out[2] = B2(r);
	out[3] = B3(r);
	out[4] = B0(l);
	out[5] = B1(l);
	out[6] = B2(l);
	out[7] = B3(l);
}
示例#7
0
PetscReal ct_function(PetscReal theta_local, void * int_params)
{
	struct int_params * iparams = (struct int_params *)int_params;
	h_params hparams;	
	PetscReal result;
	PetscReal mu1,mu2,th1,x1,x2,k1,k2,aa;
	PetscReal mf2;
	PetscReal denom;
	PetscReal p_b3;

	mu1 = iparams->mu1;
	th1 = theta_local;
	mu2 = iparams->mu2;
	mf2 = iparams->mf*iparams->mf;
	p_b3=iparams->p_bohr[0]*iparams->p_bohr[0]*iparams->p_bohr[0]*8.0;//Should this be /8 or times 8?

	result = 0.0;
	
	x1 = (1.0 + mu1*th1/sqrt(mf2 + mu1*mu1))/2.0;	
	k1 = mu1*sqrt(1.0-th1*th1);
	x2 = iparams->x2;	
	k2 = iparams->k2;
	if (( std::fabs(x1-x2) >= 1e-8 || std::fabs(k1-k2) >= 1e-8 ) )
	{
	        aa = (x1-x2)*(x1-x2)*mf2/2.0*(1.0/(1.0-x2)/(1.0-x1)+1.0/x1/x2) + k1*k1 + k2*k2+ (x1-x2)/2.0*(k1*k1*(1.0/(1.0-x1)-1.0/x1)-k2*k2*(1.0/(1.0-x2)-1.0/x2));
        	denom = aa*aa-4.0*k1*k1*k2*k2;
	
		if( denom > 0.0 )
		{
			hparams.flag_asy=iparams->flag_asy;
			hparams.flag_perm=0;
			hparams.x1=x1;
			hparams.k1=k1;
			hparams.x2=x2;
			hparams.k2=k2;
			hparams.Jz=iparams->Jzc;
			hparams.m1=iparams->mf;
			hparams.m2=iparams->mf;
			hparams.A  = 1.0/sqrt(denom);
       			hparams.B  = (1.0-aa*hparams.A)/2.0;

			if (iparams->index_s==0 || iparams->index_s==3)   result = G1(&hparams);
			else		       result = G2(&hparams);
			result *= 2.0*mu1*mu1*x1*(1.0-x1)/sqrt(mf2 + mu1*mu1)/sqrt(mf2 + mu1*mu1)/sqrt(mf2 + mu1*mu1)*(1.0+mu2*mu2*mu2/p_b3)/(1.0+mu1*mu1*mu1/p_b3)/M_PI;
		}
	}
	return result;
}
示例#8
0
文件: test.cpp 项目: 8l/kalmar
bool test(accelerator_view &rv)
{
    int data[] = {0, 0, 0, 0};
    vector<int> Flags(data, data + sizeof(data) / sizeof(int));
    extent<1> eflags(sizeof(data) / sizeof(int));
    array<int, 1> aFlag(eflags, Flags.begin(), rv);

    const int size = 100;

    vector<int> A(size);
    vector<c> G(size);
    vector<c> G2(size);

    for(int i = 0; i < size; i++)
    {
        A[i] = INIT_VALUE;
        G[i].i = G[i].d = G[i].ui = G[i].f = i;
        G2[i].i = G2[i].d = G2[i].ui = G2[i].f = i;
    }

    extent<1> e(size);
    extent<2> eG(10, 10);

    array<int, 1> aA(e, A.begin(), rv);
    array<c, 2> aG(eG, G.begin(), rv);
    array<c, 2> aG2(eG, G2.begin(), rv);

    parallel_for_each(aA.get_extent(), [&](index<1>idx) __GPU
    {
        c *p = NULL;

        if (aFlag[0] == 0)
            p = &aG[0][0];
        else
            p = &aG2[0][0];

        double di = 0;
        for (int i = 0; i < 100; i++)
        {
            if (!Equal((*p).i, (int)i) || !Equal((*p).d, di) || !Equal((*p).ui, (unsigned __int32)i) || !Equal((*p).f, (float)i))
            {
                aA[idx] = 1;
            }
            p++;
            di++;
        }
    });
示例#9
0
int main()
{
    std_setup();
    
    ml_random rng;
    
    
    
    {
		// output analytic solution
		
        grid2D<double, double > F1( 500, -10.0, 10.0, 500, -10.0, 10.0 );
        grid2D<double, double > F2( F1 );
        grid2D<double, double > G1( F1 );
        grid2D<double, double > G2( F1 );
        
        F1 = V_1;
        F2 = V_2;
        
        laplacian_2d_hdaf Del2;
        Del2.init( F1.n1, F1.n2, F1.b1-F1.a1, F1.b2-F1.a2, 24, 24, .5, .5 );
        
        Del2.execute( F1.array, G1.array );
        Del2.execute( F2.array, G2.array );
        
        
        plotGrid2D_1( F1,  "/workspace/output/scratch/F1.png", color_map_green );
        plotGrid2D_1( F2,  "/workspace/output/scratch/F2.png", color_map_green );
        plotGrid2D_1( G1,  "/workspace/output/scratch/G1.png", color_map_error );
        plotGrid2D_1( G2,  "/workspace/output/scratch/G2.png", color_map_error );
	}
    
    
    
    
    
    
    std_exit();
}
示例#10
0
		G("Lineage 2", l2, GAME_Lineage2),
#endif
#if LOCO
		G("Land of Chaos Online (LOCO)", loco, GAME_Loco),
#endif
#if BATTLE_TERR
		G("Battle Territory Online", bterr, GAME_BattleTerr),
#endif
#if SWRC
		G("Star Wars: Republic Commando", swrc, GAME_RepCommando),
#endif
#if XIII
		G("XIII", xiii, GAME_XIII),
#endif
#if UNREAL25
		G2("UE2Runtime"),
#	if TRIBES3
		G("Tribes: Vengeance", t3, GAME_Tribes3),
#	endif
#	if SWAT4
		G("SWAT 4", swat4, GAME_Swat4),
#	endif
#	if BIOSHOCK
		G("Bioshock, Bioshock 2", bio, GAME_Bioshock),
#	endif
#	if RAGNAROK2
		G("Ragnarok Online 2", rag2, GAME_Ragnarok2),
#	endif
#	if EXTEEL
		G("Exteel", extl, GAME_Exteel),
#	endif
示例#11
0
文件: luit.c 项目: aosm/X11
static int
parseOptions(int argc, char **argv)
{
    int i = 1;
    while(i < argc) {
        if(argv[i][0] != '-' && argv[i][0] != '+') {
            break;
        } else if(!strcmp(argv[i], "--")) {
            i++;
            break;
        } else if(!strcmp(argv[i], "-v")) {
            verbose++;
            i++;
        } else if(!strcmp(argv[i], "-h")) {
            help();
            exit(0);
        } else if(!strcmp(argv[i], "-list")) {
            reportCharsets();
            exit(0);
        } else if(!strcmp(argv[i], "+oss")) {
            outputState->outputFlags &= ~OF_SS;
            i++;
        } else if(!strcmp(argv[i], "+ols")) {
            outputState->outputFlags &= ~OF_LS;
            i++;
        } else if(!strcmp(argv[i], "+osl")) {
            outputState->outputFlags &= ~OF_SELECT;
            i++;
        } else if(!strcmp(argv[i], "+ot")) {
            outputState->outputFlags = OF_PASSTHRU;
            i++;
        } else if(!strcmp(argv[i], "-k7")) {
            inputState->inputFlags &= ~IF_EIGHTBIT;
            i++;
        } else if(!strcmp(argv[i], "+kss")) {
            inputState->inputFlags &= ~IF_SS;
            i++;
        } else if(!strcmp(argv[1], "+kssgr")) {
            inputState->inputFlags &= ~IF_SSGR;
            i++;
        } else if(!strcmp(argv[i], "-kls")) {
            inputState->inputFlags |= IF_LS;
            i++;
        } else if(!strcmp(argv[i], "-g0")) {
            if(i + 1 >= argc)
                FatalError("-g0 requires an argument\n");
            G0(outputState) = getCharsetByName(argv[i + 1]);
            i += 2;
        } else if(!strcmp(argv[i], "-g1")) {
            if(i + 1 >= argc)
                FatalError("-g1 requires an argument\n");
            G1(outputState) = getCharsetByName(argv[i + 1]);
            i += 2;
        } else if(!strcmp(argv[i], "-g2")) {
            if(i + 1 >= argc)
                FatalError("-g2 requires an argument\n");
            G2(outputState) = getCharsetByName(argv[i + 1]);
            i += 2;
        } else if(!strcmp(argv[i], "-g3")) {
            if(i + 1 >= argc)
                FatalError("-g3 requires an argument\n");
            G3(outputState) = getCharsetByName(argv[i + 1]);

            i += 2;
        } else if(!strcmp(argv[i], "-gl")) {
            int j;
            if(i + 1 >= argc)
                FatalError("-gl requires an argument\n");
            if(strlen(argv[i + 1]) != 2 ||
               argv[i + 1][0] != 'g')
                j = -1;
            else 
                j = argv[i + 1][1] - '0';
            if(j < 0 || j > 3)
                FatalError("The argument of -gl "
                           "should be one of g0 through g3,\n"
                           "not %s\n", argv[i + 1]);
            else
                outputState->glp = &outputState->g[j];
            i += 2;
        } else if(!strcmp(argv[i], "-gr")) {
            int j;
            if(i + 1 >= argc)
                FatalError("-gr requires an argument\n");
            if(strlen(argv[i + 1]) != 2 ||
               argv[i + 1][0] != 'g')
                j = -1;
            else 
                j = argv[i + 1][1] - '0';
            if(j < 0 || j > 3)
                FatalError("The argument of -gl "
                           "should be one of g0 through g3,\n"
                           "not %s\n", argv[i + 1]);
            else
                outputState->grp = &outputState->g[j];
            i += 2;
        } else if(!strcmp(argv[i], "-kg0")) {
            if(i + 1 >= argc)
                FatalError("-kg0 requires an argument\n");
            G0(inputState) = getCharsetByName(argv[i + 1]);
            i += 2;
        } else if(!strcmp(argv[i], "-kg1")) {
            if(i + 1 >= argc)
                FatalError("-kg1 requires an argument\n");
            G1(inputState) = getCharsetByName(argv[i + 1]);
            i += 2;
        } else if(!strcmp(argv[i], "-kg2")) {
            if(i + 1 >= argc)
                FatalError("-kg2 requires an argument\n");
            G2(inputState) = getCharsetByName(argv[i + 1]);
            i += 2;
        } else if(!strcmp(argv[i], "-kg3")) {
            if(i + 1 >= argc)
                FatalError("-kg3 requires an argument\n");
            G3(inputState) = getCharsetByName(argv[i + 1]);

            i += 2;
        } else if(!strcmp(argv[i], "-kgl")) {
            int j;
            if(i + 1 >= argc)
                FatalError("-kgl requires an argument\n");
            if(strlen(argv[i + 1]) != 2 ||
               argv[i + 1][0] != 'g')
                j = -1;
            else 
                j = argv[i + 1][1] - '0';
            if(j < 0 || j > 3)
                FatalError("The argument of -kgl "
                           "should be one of g0 through g3,\n"
                           "not %s\n", argv[i + 1]);
            else
                inputState->glp = &inputState->g[j];
            i += 2;
        } else if(!strcmp(argv[i], "-kgr")) {
            int j;
            if(i + 1 >= argc)
                FatalError("-kgl requires an argument\n");
            if(strlen(argv[i + 1]) != 2 ||
               argv[i + 1][0] != 'g')
                j = -1;
            else 
                j = argv[i + 1][1] - '0';
            if(j < 0 || j > 3)
                FatalError("The argument of -kgl "
                           "should be one of g0 through g3,\n"
                           "not %s\n", argv[i + 1]);
            else
                inputState->grp = &inputState->g[j];
            i += 2;
        } else if(!strcmp(argv[i], "-argv0")) {
            if(i + 1 >= argc)
                FatalError("-argv0 requires an argument\n");
            child_argv0 = argv[i + 1];
            i += 2;
        } else if(!strcmp(argv[i], "-x")) {
            exitOnChild = 1;
            i++;
        } else if(!strcmp(argv[i], "-c")) {
            converter = 1;
            i++;
        } else if(!strcmp(argv[i], "-ilog")) {
            if(i + 1 >= argc)
                FatalError("-ilog requires an argument\n");
            ilog = open(argv[i + 1], O_WRONLY | O_CREAT | O_TRUNC, 0777);
            if(ilog < 0) {
                perror("Couldn't open input log");
                exit(1);
            }
            i += 2;
        } else if(!strcmp(argv[i], "-olog")) {
            if(i + 1 >= argc)
                FatalError("-olog requires an argument\n");
            olog = open(argv[i + 1], O_WRONLY | O_CREAT | O_TRUNC, 0777);
            if(olog < 0) {
                perror("Couldn't open output log");
                exit(1);
            }
            i += 2;
        } else if(!strcmp(argv[i], "-encoding")) {
            int rc;
            if(i + 1 >= argc)
                FatalError("-encoding requires an argument\n");
            rc = initIso2022(NULL, argv[i + 1], outputState);
            if(rc < 0)
                FatalError("Couldn't init output state\n");
            i += 2;
        } else {
            FatalError("Unknown option %s\n", argv[i]);
        }
    }
    return i;
}
示例#12
0
  void SurfaceVectorGradient<EvalT, Traits>::
  evaluateFields(typename Traits::EvalData workset)
  {
    for (std::size_t cell=0; cell < workset.numCells; ++cell) {
      for (std::size_t pt=0; pt < numQPs; ++pt) {
        Intrepid::Vector<ScalarT> g_0(3, &currentBasis(cell, pt, 0, 0));
        Intrepid::Vector<ScalarT> g_1(3, &currentBasis(cell, pt, 1, 0));
        Intrepid::Vector<ScalarT> g_2(3, &currentBasis(cell, pt, 2, 0));
        Intrepid::Vector<ScalarT> G_2(3, &refNormal(cell, pt, 0));
        Intrepid::Vector<ScalarT> d(3, &jump(cell, pt, 0));
        Intrepid::Vector<ScalarT> G0(3, &refDualBasis(cell, pt, 0, 0));
        Intrepid::Vector<ScalarT> G1(3, &refDualBasis(cell, pt, 1, 0));
        Intrepid::Vector<ScalarT> G2(3, &refDualBasis(cell, pt, 2, 0));

        Intrepid::Tensor<ScalarT>
        Fpar(Intrepid::bun(g_0, G0) +
            Intrepid::bun(g_1, G1) +
            Intrepid::bun(g_2, G2));
        // for Jay: bun()
        Intrepid::Tensor<ScalarT> Fper((1 / thickness) * Intrepid::bun(d, G_2));

        Intrepid::Tensor<ScalarT> F = Fpar + Fper;

        defGrad(cell, pt, 0, 0) = F(0, 0);
        defGrad(cell, pt, 0, 1) = F(0, 1);
        defGrad(cell, pt, 0, 2) = F(0, 2);
        defGrad(cell, pt, 1, 0) = F(1, 0);
        defGrad(cell, pt, 1, 1) = F(1, 1);
        defGrad(cell, pt, 1, 2) = F(1, 2);
        defGrad(cell, pt, 2, 0) = F(2, 0);
        defGrad(cell, pt, 2, 1) = F(2, 1);
        defGrad(cell, pt, 2, 2) = F(2, 2);

        J(cell,pt) = Intrepid::det(F);
      }
    }

    if (weightedAverage)
    {
      ScalarT Jbar, wJbar, vol;
      for (std::size_t cell=0; cell < workset.numCells; ++cell)
      {
        Jbar = 0.0;
        vol = 0.0;
        for (std::size_t qp=0; qp < numQPs; ++qp)
        {
          Jbar += weights(cell,qp) * std::log( J(cell,qp) );
          vol  += weights(cell,qp);
        }
        Jbar /= vol;

        // Jbar = std::exp(Jbar);
        for (std::size_t qp=0; qp < numQPs; ++qp)
        {
          for (std::size_t i=0; i < numDims; ++i)
          {
            for (std::size_t j=0; j < numDims; ++j)
            {
              wJbar = std::exp( (1-alpha) * Jbar + alpha * std::log( J(cell,qp) ) );
              defGrad(cell,qp,i,j) *= std::pow( wJbar / J(cell,qp) ,1./3. );
            }
          }
          J(cell,qp) = wJbar;
        }
      }
    }

  }
示例#13
0
文件: portable.c 项目: abhijaju/raaz
void raazHashBlake256PortableCompress(Hash hash, Salt salt, uint64_t counter, int nblocks, Block *mesg)
{

    Word t0,t1;  /* Counter variables */

    /* Message variables */
    Word m0;    
    Word m1;
    Word m2;
    Word m3;
    Word m4;    
    Word m5;
    Word m6;
    Word m7;
    Word m8;
    Word m9;
    Word m10;
    Word m11;
    Word m12;
    Word m13;
    Word m14;
    Word m15;
    
    /* State variables - stored in registers so as to make the code faster */
    register Word v0;
    register Word v1;
    register Word v2;
    register Word v3;
    register Word v4;
    register Word v5;
    register Word v6;
    register Word v7;
    register Word v8;
    register Word v9;
    register Word v10;
    register Word v11;
    register Word v12;
    register Word v13;
    register Word v14;
    register Word v15;


    while(nblocks > 0)
    {
        /* Incrementing counter by message bits */
        counter = counter + 512;  
    
        t0 = (Word)counter;                    
        t1 = (Word)(counter >> 32);
                
        /* Initialization of the state consisting of 16 words */                
        v0 = hash[0];
        v1 = hash[1];
        v2 = hash[2];
        v3 = hash[3];
        v4 = hash[4];
        v5 = hash[5];
        v6 = hash[6];
        v7 = hash[7];
        v8 = salt[0] ^ c0;
        v9 = salt[1] ^ c1;
        v10 = salt[2] ^ c2; 
        v11 = salt[3] ^ c3;
        v12 = t0 ^ c4; 
        v13 = t0 ^ c5; 
        v14 = t1 ^ c6; 
        v15 = t1 ^ c7;

        /* Loading the message into 16 words */     
        m0 = raazLoad32BE((Word *)mesg,0);
        m1 = raazLoad32BE((Word *)mesg,1);
        m2 = raazLoad32BE((Word *)mesg,2);
        m3 = raazLoad32BE((Word *)mesg,3);
        m4 = raazLoad32BE((Word *)mesg,4);
        m5 = raazLoad32BE((Word *)mesg,5);
        m6 = raazLoad32BE((Word *)mesg,6);
        m7 = raazLoad32BE((Word *)mesg,7);
        m8 = raazLoad32BE((Word *)mesg,8);
        m9 = raazLoad32BE((Word *)mesg,9);
        m10 = raazLoad32BE((Word *)mesg,10); 
        m11 = raazLoad32BE((Word *)mesg,11); 
        m12 = raazLoad32BE((Word *)mesg,12); 
        m13 = raazLoad32BE((Word *)mesg,13); 
        m14 = raazLoad32BE((Word *)mesg,14); 
        m15 = raazLoad32BE((Word *)mesg,15);
        
        /* End of reading the message block */


        /*
        Loop unrollings are being done after every round so as to improve the 
        performance. 
        */

        /* Round 1 */
        /* Column Steps 0-3 */
        G0( m0, m1, c0, c1 );
        G1( m2, m3, c2, c3 );
        G2( m4, m5, c4, c5 );
        G3( m6, m7, c6, c7 );

        /* Diagonal-Step 4-7 */  
        G4( m8 , m9 , c8 , c9  );
        G5( m10, m11, c10, c11 );
        G6( m12, m13, c12, c13 );
        G7( m14, m15, c14, c15 );


        /* Round 2 */
        /* Column Step 0-3 */
        G0( m14, m10, c14, c10 );
        G1( m4 , m8 , c4 , c8  );
        G2( m9 , m15, c9 , c15 );
        G3( m13, m6 , c13, c6  );

        /* Diagonal Step 4-7 */
        G4( m1 , m12, c1 , c12 );
        G5( m0 , m2 , c0 , c2  );
        G6( m11, m7 , c11, c7  );
        G7( m5 , m3 , c5 , c3  );


        /* Round 3 */
        /* Column Step 0-3 */
        G0( m11, m8 , c11, c8  );
        G1( m12, m0 , c12, c0  );
        G2( m5 , m2 , c5 , c2  );
        G3( m15, m13, c15, c13 );

        /* Diagonal Step 4-7 */
        G4( m10, m14, c10, c14 );
        G5( m3 , m6 , c3 , c6  );
        G6( m7 , m1 , c7 , c1  );
        G7( m9 , m4 , c9 , c4  );


        /* Round 4 */
        /* Column Step 0-3 */
        G0( m7 , m9 , c7 , c9  );
        G1( m3 , m1 , c3 , c1  );
        G2( m13, m12, c13, c12 );
        G3( m11, m14, c11, c14 );

        /* Diagonal Step 4-7 */
        G4( m2 , m6 , c2 , c6  );
        G5( m5 , m10, c5 , c10 );
        G6( m4 , m0 , c4 , c0  );
        G7( m15, m8 , c15, c8  );


        /* Round 5 */
        /* Column Step 0-3 */
        G0( m9 , m0 , c9 , c0  );
        G1( m5 , m7 , c5 , c7  );
        G2( m2 , m4 , c2 , c4  );
        G3( m10, m15, c10, c15 );

        /* Diagonal Step 4-7 */
        G4( m14, m1 , c14, c1  );
        G5( m11, m12, c11, c12 );
        G6( m6 , m8 , c6 , c8  );
        G7( m3 , m13, c3 , c13 );


        /* Round 6 */
        /* Column Step 0-3 */
        G0( m2, m12, c2, c12 );
        G1( m6, m10, c6, c10 );
        G2( m0, m11, c0, c11 );
        G3( m8, m3 , c8, c3  );

        /* Diagonal Step 4-7 */
        G4( m4 , m13, c4 , c13 );
        G5( m7 , m5 , c7 , c5  );
        G6( m15, m14, c15, c14 );
        G7( m1 , m9 , c1 , c9  );


        /* Round 7 */
        /* Column Step 0-3 */
        G0( m12, m5 , c12, c5 );
        G1( m1 , m15, c1 , c15 );
        G2( m14, m13, c14, c13 );
        G3( m4 , m10, c4 , c10 );

        /* Diagonal Step 4-7 */
        G4( m0, m7 , c0, c7  );
        G5( m6, m3 , c6, c3  );
        G6( m9, m2 , c9, c2  ); 
        G7( m8, m11, c8, c11 );


        /* Round 8 */
        /* Column Step 0-3 */
        G0( m13, m11, c13, c11 );
        G1( m7 , m14, c7 , c14 );
        G2( m12, m1 , c12, c1  );
        G3( m3 , m9 , c3 , c9  );

        /* Diagonal Step 4-7 */
        G4( m5 , m0 , c5 , c0  );
        G5( m15, m4 , c15, c4  );
        G6( m8 , m6 , c8 , c6  );
        G7( m2 , m10, c2 , c10 );


        /* Round 9 */
        /* Column Step 0-3 */
        G0( m6 , m15, c6 , c15 );
        G1( m14, m9 , c14, c9  );
        G2( m11, m3 , c11, c3  );
        G3( m0 , m8 , c0 , c8  );

        /* Diagonal Step 4-7 */
        G4( m12, m2, c12, c2 );
        G5( m13, m7, c13, c7 );
        G6( m1 , m4, c1 , c4 );
        G7( m10, m5, c10, c5 );


        /* Round 10 */
        /* Column Step 0-3 */
        G0( m10, m2, c10, c2 );
        G1( m8 , m4, c8 , c4 );
        G2( m7 , m6, c7 , c6 );
        G3( m1 , m5, c1 , c5 );

        /* Diagonal Step 4-7 */
        G4( m15, m11, c15, c11 );
        G5( m9 , m14, c9 , c14 );
        G6( m3 , m12, c3 , c12 );
        G7( m13, m0 , c13, c0  );


        /* Round 11 */
        /* Column Steps 0-3 */
        G0( m0, m1, c0, c1 );
        G1( m2, m3, c2, c3 );
        G2( m4, m5, c4, c5 );
        G3( m6, m7, c6, c7 );

        /* Diagonal-Step 4-7 */  
        G4( m8 , m9 , c8 , c9  );
        G5( m10, m11, c10, c11 );
        G6( m12, m13, c12, c13 );
        G7( m14, m15, c14, c15 );
        

        /* Round 12 */
        /* Column Step 0-3 */
        G0( m14, m10, c14, c10 );
        G1( m4 , m8 , c4 , c8  );
        G2( m9 , m15, c9 , c15 );
        G3( m13, m6 , c13, c6  );

        /* Diagonal Step 4-7 */
        G4( m1 , m12, c1 , c12 );
        G5( m0 , m2 , c0 , c2  );
        G6( m11, m7 , c11, c7  );
        G7( m5 , m3 , c5 , c3  );


        /* Round 13 */
        /* Column Step 0-3 */
        G0( m11, m8 , c11, c8  );
        G1( m12, m0 , c12, c0  );
        G2( m5 , m2 , c5 , c2  );
        G3( m15, m13, c15, c13 );
  
        /* Diagonal Step 4-7 */
        G4( m10, m14, c10, c14 );
        G5( m3 , m6 , c3 , c6  );
        G6( m7 , m1 , c7 , c1  );
        G7( m9 , m4 , c9 , c4  );


        /* Round 14 */
        /* Column Step 0-3 */
        G0( m7 , m9 , c7 , c9  );
        G1( m3 , m1 , c3 , c1  );
        G2( m13, m12, c13, c12 );
        G3( m11, m14, c11, c14 );

        /* Diagonal Step 4-7 */
        G4( m2 , m6 , c2 , c6  );
        G5( m5 , m10, c5 , c10 );
        G6( m4 , m0 , c4 , c0  );
        G7( m15, m8 , c15, c8  );



        /* Updation of hash variables with the new chain value */
        hash[0] = hash[0] ^ salt[0] ^ v0 ^ v8;
        hash[1] = hash[1] ^ salt[1] ^ v1 ^ v9;
        hash[2] = hash[2] ^ salt[2] ^ v2 ^ v10;
        hash[3] = hash[3] ^ salt[3] ^ v3 ^ v11;
        hash[4] = hash[4] ^ salt[0] ^ v4 ^ v12;     
        hash[5] = hash[5] ^ salt[1] ^ v5 ^ v13;     
        hash[6] = hash[6] ^ salt[2] ^ v6 ^ v14; 
        hash[7] = hash[7] ^ salt[3] ^ v7 ^ v15;     
        
        ++mesg; /* Incrementing to the next block */
        --nblocks;
    }   
}