Beispiel #1
0
void
transform(
    std::uint32_t digest[], std::uint32_t block[BLOCK_INTS])
{
    std::uint32_t a = digest[0];
    std::uint32_t b = digest[1];
    std::uint32_t c = digest[2];
    std::uint32_t d = digest[3];
    std::uint32_t e = digest[4];

    R0(block, a, b, c, d, e,  0);
    R0(block, e, a, b, c, d,  1);
    R0(block, d, e, a, b, c,  2);
    R0(block, c, d, e, a, b,  3);
    R0(block, b, c, d, e, a,  4);
    R0(block, a, b, c, d, e,  5);
    R0(block, e, a, b, c, d,  6);
    R0(block, d, e, a, b, c,  7);
    R0(block, c, d, e, a, b,  8);
    R0(block, b, c, d, e, a,  9);
    R0(block, a, b, c, d, e, 10);
    R0(block, e, a, b, c, d, 11);
    R0(block, d, e, a, b, c, 12);
    R0(block, c, d, e, a, b, 13);
    R0(block, b, c, d, e, a, 14);
    R0(block, a, b, c, d, e, 15);
    R1(block, e, a, b, c, d,  0);
    R1(block, d, e, a, b, c,  1);
    R1(block, c, d, e, a, b,  2);
    R1(block, b, c, d, e, a,  3);
    R2(block, a, b, c, d, e,  4);
    R2(block, e, a, b, c, d,  5);
    R2(block, d, e, a, b, c,  6);
    R2(block, c, d, e, a, b,  7);
    R2(block, b, c, d, e, a,  8);
    R2(block, a, b, c, d, e,  9);
    R2(block, e, a, b, c, d, 10);
    R2(block, d, e, a, b, c, 11);
    R2(block, c, d, e, a, b, 12);
    R2(block, b, c, d, e, a, 13);
    R2(block, a, b, c, d, e, 14);
    R2(block, e, a, b, c, d, 15);
    R2(block, d, e, a, b, c,  0);
    R2(block, c, d, e, a, b,  1);
    R2(block, b, c, d, e, a,  2);
    R2(block, a, b, c, d, e,  3);
    R2(block, e, a, b, c, d,  4);
    R2(block, d, e, a, b, c,  5);
    R2(block, c, d, e, a, b,  6);
    R2(block, b, c, d, e, a,  7);
    R3(block, a, b, c, d, e,  8);
    R3(block, e, a, b, c, d,  9);
    R3(block, d, e, a, b, c, 10);
    R3(block, c, d, e, a, b, 11);
    R3(block, b, c, d, e, a, 12);
    R3(block, a, b, c, d, e, 13);
    R3(block, e, a, b, c, d, 14);
    R3(block, d, e, a, b, c, 15);
    R3(block, c, d, e, a, b,  0);
    R3(block, b, c, d, e, a,  1);
    R3(block, a, b, c, d, e,  2);
    R3(block, e, a, b, c, d,  3);
    R3(block, d, e, a, b, c,  4);
    R3(block, c, d, e, a, b,  5);
    R3(block, b, c, d, e, a,  6);
    R3(block, a, b, c, d, e,  7);
    R3(block, e, a, b, c, d,  8);
    R3(block, d, e, a, b, c,  9);
    R3(block, c, d, e, a, b, 10);
    R3(block, b, c, d, e, a, 11);
    R4(block, a, b, c, d, e, 12);
    R4(block, e, a, b, c, d, 13);
    R4(block, d, e, a, b, c, 14);
    R4(block, c, d, e, a, b, 15);
    R4(block, b, c, d, e, a,  0);
    R4(block, a, b, c, d, e,  1);
    R4(block, e, a, b, c, d,  2);
    R4(block, d, e, a, b, c,  3);
    R4(block, c, d, e, a, b,  4);
    R4(block, b, c, d, e, a,  5);
    R4(block, a, b, c, d, e,  6);
    R4(block, e, a, b, c, d,  7);
    R4(block, d, e, a, b, c,  8);
    R4(block, c, d, e, a, b,  9);
    R4(block, b, c, d, e, a, 10);
    R4(block, a, b, c, d, e, 11);
    R4(block, e, a, b, c, d, 12);
    R4(block, d, e, a, b, c, 13);
    R4(block, c, d, e, a, b, 14);
    R4(block, b, c, d, e, a, 15);

    digest[0] += a;
    digest[1] += b;
    digest[2] += c;
    digest[3] += d;
    digest[4] += e;
}
Beispiel #2
0
Pix3D render(Pixel3DSet & objectIn, int volumeWidth, float focalDistance)
{
	unsigned int S = 640 * 480; //image sizes for Pix3D are 640x480
	float volW = (float)volumeWidth; //floating point version of volume width
	float hvw = volW * 0.5f; //half the volume width

	//init buffers for the Pix3D data
	bool * vd = new bool[S];
	R3 * points = new R3[S];
	Vec3b * colors = new Vec3b[S];
	float * depths = new float[S];
	//initialize values depth map
	for(int i = 0; i < S; i++)
	{
		depths[i] = FLT_MAX;
		vd[i] = false;
	}

	//camera focal ranges in angles
	//angle-y = 60.0f, angle-x = 45.0f
	float angleY = 60.0f, angleX = 40.0f;
	//half versions
	float hay = angleY * 0.5f;
	float hax = angleX * 0.5f;

	int hw = 640 / 2;
	int hh = 480 / 2;

	
	R3 cameraLocation(hvw, hvw, -focalDistance); //the location of the camera

	

	//define the projection plane dimensions
	float planeWidth = tan(hay * ll_R3_C::ll_R3_deg2rad) * focalDistance * 2.0f;
	float planeHeight = tan(hax * ll_R3_C::ll_R3_deg2rad) * focalDistance * 2.0f;
	float hpw = planeWidth * 0.5f;
	float hph = planeHeight * 0.5f;

	
	//define the top left corner of the projection plane
	R3 planeTopLeft = R3(hvw - hpw, hvw + hph, 0.0f);
	R3 planeBottomRight = planeTopLeft + R3(planeWidth, -planeHeight, 0.0f);
	
	for(int i = 0; i < objectIn.size(); i++)
	{
		//project onto projection plane
		R3 ray = (objectIn[i] - cameraLocation).unit();
		ray *= focalDistance / ray.z;
		//check if it is within the bounds
		int x = round((ray.x - planeTopLeft.x) / planeWidth * 640.0f) + hw;
		int y = round((planeTopLeft.y - ray.y) / planeHeight * 480.0f) - hh;
		if(x>=0 && y>=0 && x<640 && y<480)
		{
			int index = y*640 + x;
			//compute the depth
			float depth = ray.dist(cameraLocation);
			//update point if necessary
			if(depth < depths[index])
			{
				depths[index] = depth;
				vd[index] = true;
				colors[index] = objectIn.colors[i];
				points[index] = objectIn[i];
			}
			
		}
	}
	

	Pix3D ret(S, points, colors, vd);
	delete [] points;
	delete [] colors;
	delete [] vd;
	delete [] depths;
	
	return ret;
}
Beispiel #3
0
void md5_block_data_order(MD5_CTX *ctx, const void *data_, size_t num)
{
    const uint8_t *data = data_;
    uint32_t A, B, C, D, l;
    uint32_t XX0, XX1, XX2, XX3, XX4, XX5, XX6, XX7,
        XX8, XX9, XX10, XX11, XX12, XX13, XX14, XX15;
#define X(i) XX##i

    A = ctx->A;
    B = ctx->B;
    C = ctx->C;
    D = ctx->D;

    for (; num--;) {
        HOST_c2l(data, l);
        X(0) = l;
        HOST_c2l(data, l);
        X(1) = l;
        /* Round 0 */
        R0(A, B, C, D, X(0), 7, 0xd76aa478L);
        HOST_c2l(data, l);
        X(2) = l;
        R0(D, A, B, C, X(1), 12, 0xe8c7b756L);
        HOST_c2l(data, l);
        X(3) = l;
        R0(C, D, A, B, X(2), 17, 0x242070dbL);
        HOST_c2l(data, l);
        X(4) = l;
        R0(B, C, D, A, X(3), 22, 0xc1bdceeeL);
        HOST_c2l(data, l);
        X(5) = l;
        R0(A, B, C, D, X(4), 7, 0xf57c0fafL);
        HOST_c2l(data, l);
        X(6) = l;
        R0(D, A, B, C, X(5), 12, 0x4787c62aL);
        HOST_c2l(data, l);
        X(7) = l;
        R0(C, D, A, B, X(6), 17, 0xa8304613L);
        HOST_c2l(data, l);
        X(8) = l;
        R0(B, C, D, A, X(7), 22, 0xfd469501L);
        HOST_c2l(data, l);
        X(9) = l;
        R0(A, B, C, D, X(8), 7, 0x698098d8L);
        HOST_c2l(data, l);
        X(10) = l;
        R0(D, A, B, C, X(9), 12, 0x8b44f7afL);
        HOST_c2l(data, l);
        X(11) = l;
        R0(C, D, A, B, X(10), 17, 0xffff5bb1L);
        HOST_c2l(data, l);
        X(12) = l;
        R0(B, C, D, A, X(11), 22, 0x895cd7beL);
        HOST_c2l(data, l);
        X(13) = l;
        R0(A, B, C, D, X(12), 7, 0x6b901122L);
        HOST_c2l(data, l);
        X(14) = l;
        R0(D, A, B, C, X(13), 12, 0xfd987193L);
        HOST_c2l(data, l);
        X(15) = l;
        R0(C, D, A, B, X(14), 17, 0xa679438eL);
        R0(B, C, D, A, X(15), 22, 0x49b40821L);
        /* Round 1 */
        R1(A, B, C, D, X(1), 5, 0xf61e2562L);
        R1(D, A, B, C, X(6), 9, 0xc040b340L);
        R1(C, D, A, B, X(11), 14, 0x265e5a51L);
        R1(B, C, D, A, X(0), 20, 0xe9b6c7aaL);
        R1(A, B, C, D, X(5), 5, 0xd62f105dL);
        R1(D, A, B, C, X(10), 9, 0x02441453L);
        R1(C, D, A, B, X(15), 14, 0xd8a1e681L);
        R1(B, C, D, A, X(4), 20, 0xe7d3fbc8L);
        R1(A, B, C, D, X(9), 5, 0x21e1cde6L);
        R1(D, A, B, C, X(14), 9, 0xc33707d6L);
        R1(C, D, A, B, X(3), 14, 0xf4d50d87L);
        R1(B, C, D, A, X(8), 20, 0x455a14edL);
        R1(A, B, C, D, X(13), 5, 0xa9e3e905L);
        R1(D, A, B, C, X(2), 9, 0xfcefa3f8L);
        R1(C, D, A, B, X(7), 14, 0x676f02d9L);
        R1(B, C, D, A, X(12), 20, 0x8d2a4c8aL);
        /* Round 2 */
        R2(A, B, C, D, X(5), 4, 0xfffa3942L);
        R2(D, A, B, C, X(8), 11, 0x8771f681L);
        R2(C, D, A, B, X(11), 16, 0x6d9d6122L);
        R2(B, C, D, A, X(14), 23, 0xfde5380cL);
        R2(A, B, C, D, X(1), 4, 0xa4beea44L);
        R2(D, A, B, C, X(4), 11, 0x4bdecfa9L);
        R2(C, D, A, B, X(7), 16, 0xf6bb4b60L);
        R2(B, C, D, A, X(10), 23, 0xbebfbc70L);
        R2(A, B, C, D, X(13), 4, 0x289b7ec6L);
        R2(D, A, B, C, X(0), 11, 0xeaa127faL);
        R2(C, D, A, B, X(3), 16, 0xd4ef3085L);
        R2(B, C, D, A, X(6), 23, 0x04881d05L);
        R2(A, B, C, D, X(9), 4, 0xd9d4d039L);
        R2(D, A, B, C, X(12), 11, 0xe6db99e5L);
        R2(C, D, A, B, X(15), 16, 0x1fa27cf8L);
        R2(B, C, D, A, X(2), 23, 0xc4ac5665L);
        /* Round 3 */
        R3(A, B, C, D, X(0), 6, 0xf4292244L);
        R3(D, A, B, C, X(7), 10, 0x432aff97L);
        R3(C, D, A, B, X(14), 15, 0xab9423a7L);
        R3(B, C, D, A, X(5), 21, 0xfc93a039L);
        R3(A, B, C, D, X(12), 6, 0x655b59c3L);
        R3(D, A, B, C, X(3), 10, 0x8f0ccc92L);
        R3(C, D, A, B, X(10), 15, 0xffeff47dL);
        R3(B, C, D, A, X(1), 21, 0x85845dd1L);
        R3(A, B, C, D, X(8), 6, 0x6fa87e4fL);
        R3(D, A, B, C, X(15), 10, 0xfe2ce6e0L);
        R3(C, D, A, B, X(6), 15, 0xa3014314L);
        R3(B, C, D, A, X(13), 21, 0x4e0811a1L);
        R3(A, B, C, D, X(4), 6, 0xf7537e82L);
        R3(D, A, B, C, X(11), 10, 0xbd3af235L);
        R3(C, D, A, B, X(2), 15, 0x2ad7d2bbL);
        R3(B, C, D, A, X(9), 21, 0xeb86d391L);

        A = ctx->A += A;
        B = ctx->B += B;
        C = ctx->C += C;
        D = ctx->D += D;
    }
}
Beispiel #4
0
/* Hash a single 512-bit block. This is the core of the algorithm. */
static void SHATransform(ULONG State[5], UCHAR Buffer[64])
{
   ULONG a, b, c, d, e;
   ULONG *Block;

   Block = (ULONG*)Buffer;

   /* Copy Context->State[] to working variables */
   a = State[0];
   b = State[1];
   c = State[2];
   d = State[3];
   e = State[4];

   /* 4 rounds of 20 operations each. Loop unrolled. */
   R0(a,b,c,d,e, 0); R0(e,a,b,c,d, 1); R0(d,e,a,b,c, 2); R0(c,d,e,a,b, 3);
   R0(b,c,d,e,a, 4); R0(a,b,c,d,e, 5); R0(e,a,b,c,d, 6); R0(d,e,a,b,c, 7);
   R0(c,d,e,a,b, 8); R0(b,c,d,e,a, 9); R0(a,b,c,d,e,10); R0(e,a,b,c,d,11);
   R0(d,e,a,b,c,12); R0(c,d,e,a,b,13); R0(b,c,d,e,a,14); R0(a,b,c,d,e,15);
   R1(e,a,b,c,d,16); R1(d,e,a,b,c,17); R1(c,d,e,a,b,18); R1(b,c,d,e,a,19);
   R2(a,b,c,d,e,20); R2(e,a,b,c,d,21); R2(d,e,a,b,c,22); R2(c,d,e,a,b,23);
   R2(b,c,d,e,a,24); R2(a,b,c,d,e,25); R2(e,a,b,c,d,26); R2(d,e,a,b,c,27);
   R2(c,d,e,a,b,28); R2(b,c,d,e,a,29); R2(a,b,c,d,e,30); R2(e,a,b,c,d,31);
   R2(d,e,a,b,c,32); R2(c,d,e,a,b,33); R2(b,c,d,e,a,34); R2(a,b,c,d,e,35);
   R2(e,a,b,c,d,36); R2(d,e,a,b,c,37); R2(c,d,e,a,b,38); R2(b,c,d,e,a,39);
   R3(a,b,c,d,e,40); R3(e,a,b,c,d,41); R3(d,e,a,b,c,42); R3(c,d,e,a,b,43);
   R3(b,c,d,e,a,44); R3(a,b,c,d,e,45); R3(e,a,b,c,d,46); R3(d,e,a,b,c,47);
   R3(c,d,e,a,b,48); R3(b,c,d,e,a,49); R3(a,b,c,d,e,50); R3(e,a,b,c,d,51);
   R3(d,e,a,b,c,52); R3(c,d,e,a,b,53); R3(b,c,d,e,a,54); R3(a,b,c,d,e,55);
   R3(e,a,b,c,d,56); R3(d,e,a,b,c,57); R3(c,d,e,a,b,58); R3(b,c,d,e,a,59);
   R4(a,b,c,d,e,60); R4(e,a,b,c,d,61); R4(d,e,a,b,c,62); R4(c,d,e,a,b,63);
   R4(b,c,d,e,a,64); R4(a,b,c,d,e,65); R4(e,a,b,c,d,66); R4(d,e,a,b,c,67);
   R4(c,d,e,a,b,68); R4(b,c,d,e,a,69); R4(a,b,c,d,e,70); R4(e,a,b,c,d,71);
   R4(d,e,a,b,c,72); R4(c,d,e,a,b,73); R4(b,c,d,e,a,74); R4(a,b,c,d,e,75);
   R4(e,a,b,c,d,76); R4(d,e,a,b,c,77); R4(c,d,e,a,b,78); R4(b,c,d,e,a,79);

   /* Add the working variables back into Context->State[] */
   State[0] += a;
   State[1] += b;
   State[2] += c;
   State[3] += d;
   State[4] += e;

   /* Wipe variables */
   a = b = c = d = e = 0;
}
Beispiel #5
0
Pix3D render(SIObj & objectIn, int volumeWidth, float focalDistance)
{
	unsigned int S = 640 * 480; //image sizes for Pix3D are 640x480
	float volW = (float)volumeWidth; //floating point version of volume width
	float hvw = volW * 0.5f; //half the volume width

	R3 lightPosition = R3(-1000.0f, 1000.0f, -1000.0f);
	float ambientLight = 100.0f;


	//init buffers for the Pix3D data
	bool * vd = new bool[S];
	R3 * points = new R3[S];
	Vec3b * colors = new Vec3b[S];

	//camera focal ranges in angles
	//angle-y = 60.0f, angle-x = 45.0f
	float angleY = 60.0f, angleX = 40.0f;
	//half versions
	float hay = angleY * 0.5f;
	float hax = angleX * 0.5f;

	

	
	R3 cameraLocation(hvw, hvw, -focalDistance); //the location of the camera

	//define the projection plane dimensions
	float planeWidth = tan(hay * ll_R3_C::ll_R3_deg2rad) * focalDistance * 2.0f;
	float planeHeight = tan(hax * ll_R3_C::ll_R3_deg2rad) * focalDistance * 2.0f;
	float hpw = planeWidth * 0.5f;
	float hph = planeHeight * 0.5f;

	
	//define the top left corner of the projection plane
	R3 planeTopLeft = R3(hvw - hpw, hvw + hph, 0.0f);
	

	float rayXInc = planeWidth / 640.0f;
	float rayYInc = -planeHeight / 480.0f;
	

	//pre-compute some data used for ray-tracing
	//tris : the triangles
	//normals : the normal vectors for the triangles
	//c2ps : the vector from the camera to the center of the triangles
	//radiuses : the radius' of the bounding spheres for each triangle
	vector<SI_FullTriangle> tris; vector<R3> normals, C2Ps;
	vector<float> radiuses;
	R3 camera_direction(0.0f, 0.0f, -1.0f);

	for (int i = 0; i < objectIn._triangles.size(); i++) //for each triangle
	{
		SI_FullTriangle triangle = objectIn.getTriangle(i);
		R3 normal = triangle.normal();
		float angle = acos(normal * camera_direction) * ll_R3_C::ll_R3_rad2deg;
		if (abs(angle) <= 90.0f) //perform back-face culling
		{
			R3 center = (triangle.a + triangle.b + triangle.c) * (1.0f / 3.0f);
			float radius = R3(center.dist(triangle.a), center.dist(triangle.b), center.dist(triangle.c)).max();
			tris.push_back(triangle);
			normals.push_back(normal);
			C2Ps.push_back(center - cameraLocation);
			radiuses.push_back(radius);
		}
	}
		
	bool found = false, hit = false;
	R3 ray, ip;
	float d = 0.0f, bestDistance;
	R3 intersectionPoint, normal;
	int __index = 0;

	R3 q = planeTopLeft;

	for (int y = 0; y < 480; y++, q.y += rayYInc)
	{
		q.x = planeTopLeft.x;
		for (int x = 0; x < 640; x++, __index++, q.x += rayXInc)
		{
			ray = (q - cameraLocation).unit();
			found = false;
			bestDistance = FLT_MAX;
			for (int j = 0; j < tris.size(); j++)
			{
				hit = false;

				//check if ray intersects bounding sphere
				//C2P is the vector from the camera to the center
				R3 C2P = C2Ps[j];
				R3 projectedPoint = C2P.project(ray);
				if (projectedPoint.dist(C2P) > radiuses[j]) continue;

				SI_FullTriangle T = tris[j];
				d = T.RayIntersectsTriangle(cameraLocation, ray, normals[j], ip, hit);
				if (hit)
				{
					if (d < bestDistance)
					{
						bestDistance = d;
						intersectionPoint = ip;
						normal = normals[j];
					}
					found = true;
				}
			}
			if (found)
			{
				points[__index] = intersectionPoint;
				R3 lightNormal = (lightPosition - intersectionPoint).unit();
				float angle = abs(acos(normal * lightNormal) * ll_R3_C::ll_R3_rad2deg);
				float _color = ambientLight;
				if (angle <= 90.0f)
				{
					float diffuse = 180.0f - angle;
					_color += diffuse / 180.0f * 150.0f;
				}
				_color = _color > 255.0f ? 255.0f : _color;
				colors[__index] = Vec3b((unsigned char)_color, (unsigned char)_color, (unsigned char)_color);
				
			}
			vd[__index] = found;
			
		}
	}
	Pix3D ret(S, points, colors, vd);
	delete [] points;
	delete [] colors;
	delete [] vd;
	
	return ret;
}
Beispiel #6
0
void SHA1Transform(uint32 state[5], const unsigned char buffer[SHA1_BLOCK_LENGTH])
{
uint32 a, b, c, d, e;
typedef union {
    unsigned char c[64];
    uint32 l[16];
} CHAR64LONG16;
CHAR64LONG16 block[1];  /* use array to appear as a pointer */
    memcpy(block, buffer, SHA1_BLOCK_LENGTH);

    /* Copy context->state[] to working vars */
    a = state[0];
    b = state[1];
    c = state[2];
    d = state[3];
    e = state[4];

    /* 4 rounds of 20 operations each. Loop unrolled. */
    R0(a,b,c,d,e, 0); R0(e,a,b,c,d, 1); R0(d,e,a,b,c, 2); R0(c,d,e,a,b, 3);
    R0(b,c,d,e,a, 4); R0(a,b,c,d,e, 5); R0(e,a,b,c,d, 6); R0(d,e,a,b,c, 7);
    R0(c,d,e,a,b, 8); R0(b,c,d,e,a, 9); R0(a,b,c,d,e,10); R0(e,a,b,c,d,11);
    R0(d,e,a,b,c,12); R0(c,d,e,a,b,13); R0(b,c,d,e,a,14); R0(a,b,c,d,e,15);
    R1(e,a,b,c,d,16); R1(d,e,a,b,c,17); R1(c,d,e,a,b,18); R1(b,c,d,e,a,19);
    R2(a,b,c,d,e,20); R2(e,a,b,c,d,21); R2(d,e,a,b,c,22); R2(c,d,e,a,b,23);
    R2(b,c,d,e,a,24); R2(a,b,c,d,e,25); R2(e,a,b,c,d,26); R2(d,e,a,b,c,27);
    R2(c,d,e,a,b,28); R2(b,c,d,e,a,29); R2(a,b,c,d,e,30); R2(e,a,b,c,d,31);
    R2(d,e,a,b,c,32); R2(c,d,e,a,b,33); R2(b,c,d,e,a,34); R2(a,b,c,d,e,35);
    R2(e,a,b,c,d,36); R2(d,e,a,b,c,37); R2(c,d,e,a,b,38); R2(b,c,d,e,a,39);
    R3(a,b,c,d,e,40); R3(e,a,b,c,d,41); R3(d,e,a,b,c,42); R3(c,d,e,a,b,43);
    R3(b,c,d,e,a,44); R3(a,b,c,d,e,45); R3(e,a,b,c,d,46); R3(d,e,a,b,c,47);
    R3(c,d,e,a,b,48); R3(b,c,d,e,a,49); R3(a,b,c,d,e,50); R3(e,a,b,c,d,51);
    R3(d,e,a,b,c,52); R3(c,d,e,a,b,53); R3(b,c,d,e,a,54); R3(a,b,c,d,e,55);
    R3(e,a,b,c,d,56); R3(d,e,a,b,c,57); R3(c,d,e,a,b,58); R3(b,c,d,e,a,59);
    R4(a,b,c,d,e,60); R4(e,a,b,c,d,61); R4(d,e,a,b,c,62); R4(c,d,e,a,b,63);
    R4(b,c,d,e,a,64); R4(a,b,c,d,e,65); R4(e,a,b,c,d,66); R4(d,e,a,b,c,67);
    R4(c,d,e,a,b,68); R4(b,c,d,e,a,69); R4(a,b,c,d,e,70); R4(e,a,b,c,d,71);
    R4(d,e,a,b,c,72); R4(c,d,e,a,b,73); R4(b,c,d,e,a,74); R4(a,b,c,d,e,75);
    R4(e,a,b,c,d,76); R4(d,e,a,b,c,77); R4(c,d,e,a,b,78); R4(b,c,d,e,a,79);
    /* Add the working vars back into context.state[] */
    state[0] += a;
    state[1] += b;
    state[2] += c;
    state[3] += d;
    state[4] += e;
    /* Wipe variables */
    a = b = c = d = e = 0;
#ifdef SHA1HANDSOFF
    memset(block, '\0', sizeof(block));
#endif
}
Beispiel #7
0
static void Transform(Sha* sha)
{
    word32 W[SHA_BLOCK_SIZE / sizeof(word32)];

    /* Copy context->state[] to working vars */ 
    word32 a = sha->digest[0];
    word32 b = sha->digest[1];
    word32 c = sha->digest[2];
    word32 d = sha->digest[3];
    word32 e = sha->digest[4];

#ifdef USE_SLOW_SHA
    word32 t, i;

    for (i = 0; i < 16; i++) {
        R0(a, b, c, d, e, i);
        t = e; e = d; d = c; c = b; b = a; a = t;
    }

    for (; i < 20; i++) {
        R1(a, b, c, d, e, i);
        t = e; e = d; d = c; c = b; b = a; a = t;
    }

    for (; i < 40; i++) {
        R2(a, b, c, d, e, i);
        t = e; e = d; d = c; c = b; b = a; a = t;
    }

    for (; i < 60; i++) {
        R3(a, b, c, d, e, i);
        t = e; e = d; d = c; c = b; b = a; a = t;
    }

    for (; i < 80; i++) {
        R4(a, b, c, d, e, i);
        t = e; e = d; d = c; c = b; b = a; a = t;
    }
#else
    /* nearly 1 K bigger in code size but 25% faster  */
    /* 4 rounds of 20 operations each. Loop unrolled. */
    R0(a,b,c,d,e, 0); R0(e,a,b,c,d, 1); R0(d,e,a,b,c, 2); R0(c,d,e,a,b, 3);
    R0(b,c,d,e,a, 4); R0(a,b,c,d,e, 5); R0(e,a,b,c,d, 6); R0(d,e,a,b,c, 7);
    R0(c,d,e,a,b, 8); R0(b,c,d,e,a, 9); R0(a,b,c,d,e,10); R0(e,a,b,c,d,11);
    R0(d,e,a,b,c,12); R0(c,d,e,a,b,13); R0(b,c,d,e,a,14); R0(a,b,c,d,e,15);

    R1(e,a,b,c,d,16); R1(d,e,a,b,c,17); R1(c,d,e,a,b,18); R1(b,c,d,e,a,19);

    R2(a,b,c,d,e,20); R2(e,a,b,c,d,21); R2(d,e,a,b,c,22); R2(c,d,e,a,b,23);
    R2(b,c,d,e,a,24); R2(a,b,c,d,e,25); R2(e,a,b,c,d,26); R2(d,e,a,b,c,27);
    R2(c,d,e,a,b,28); R2(b,c,d,e,a,29); R2(a,b,c,d,e,30); R2(e,a,b,c,d,31);
    R2(d,e,a,b,c,32); R2(c,d,e,a,b,33); R2(b,c,d,e,a,34); R2(a,b,c,d,e,35);
    R2(e,a,b,c,d,36); R2(d,e,a,b,c,37); R2(c,d,e,a,b,38); R2(b,c,d,e,a,39);

    R3(a,b,c,d,e,40); R3(e,a,b,c,d,41); R3(d,e,a,b,c,42); R3(c,d,e,a,b,43);
    R3(b,c,d,e,a,44); R3(a,b,c,d,e,45); R3(e,a,b,c,d,46); R3(d,e,a,b,c,47);
    R3(c,d,e,a,b,48); R3(b,c,d,e,a,49); R3(a,b,c,d,e,50); R3(e,a,b,c,d,51);
    R3(d,e,a,b,c,52); R3(c,d,e,a,b,53); R3(b,c,d,e,a,54); R3(a,b,c,d,e,55);
    R3(e,a,b,c,d,56); R3(d,e,a,b,c,57); R3(c,d,e,a,b,58); R3(b,c,d,e,a,59);

    R4(a,b,c,d,e,60); R4(e,a,b,c,d,61); R4(d,e,a,b,c,62); R4(c,d,e,a,b,63);
    R4(b,c,d,e,a,64); R4(a,b,c,d,e,65); R4(e,a,b,c,d,66); R4(d,e,a,b,c,67);
    R4(c,d,e,a,b,68); R4(b,c,d,e,a,69); R4(a,b,c,d,e,70); R4(e,a,b,c,d,71);
    R4(d,e,a,b,c,72); R4(c,d,e,a,b,73); R4(b,c,d,e,a,74); R4(a,b,c,d,e,75);
    R4(e,a,b,c,d,76); R4(d,e,a,b,c,77); R4(c,d,e,a,b,78); R4(b,c,d,e,a,79);
#endif

    /* Add the working vars back into digest state[] */
    sha->digest[0] += a;
    sha->digest[1] += b;
    sha->digest[2] += c;
    sha->digest[3] += d;
    sha->digest[4] += e;
}
Beispiel #8
0
void MD5MAC::Transform (word32 *digest, const word32 *X, const word32 *key)
{
// #define	F(x,y,z)	((x & y)  |  (~x & z))
#define F(x,y,z)    (z ^ (x & (y^z)))
// #define	G(x,y,z)	((x & z)  |  (y & ~z))
#define G(x,y,z)    (y ^ (z & (x^y)))
#define	H(x,y,z)	(x ^ y ^ z)
#define	I(x,y,z)	(y  ^  (x | ~z))

#define R0(a,b,c,d,k,s,t) { \
	a+=(k+t+ F((b),(c),(d)) + key[0]); \
	a = rotlFixed(word32(a), (unsigned int)(s)); \
	a+=b; };\

#define R1(a,b,c,d,k,s,t) { \
	a+=(k+t+ G((b),(c),(d)) + key[1]); \
	a = rotlFixed(word32(a), (unsigned int)(s)); \
	a+=b; };

#define R2(a,b,c,d,k,s,t) { \
	a+=(k+t+ H((b),(c),(d)) + key[2]); \
	a = rotlFixed(word32(a), (unsigned int)(s)); \
	a+=b; };

#define R3(a,b,c,d,k,s,t) { \
	a+=(k+t+ I((b),(c),(d)) + key[3]); \
	a = rotlFixed(word32(a), (unsigned int)(s)); \
	a+=b; };

	register unsigned long A,B,C,D;

	A=digest[0];
	B=digest[1];
	C=digest[2];
	D=digest[3];

	/* Round 0 */
	R0(A,B,C,D,X[ 0], 7,0xd76aa478);
	R0(D,A,B,C,X[ 1],12,0xe8c7b756);
	R0(C,D,A,B,X[ 2],17,0x242070db);
	R0(B,C,D,A,X[ 3],22,0xc1bdceee);
	R0(A,B,C,D,X[ 4], 7,0xf57c0faf);
	R0(D,A,B,C,X[ 5],12,0x4787c62a);
	R0(C,D,A,B,X[ 6],17,0xa8304613);
	R0(B,C,D,A,X[ 7],22,0xfd469501);
	R0(A,B,C,D,X[ 8], 7,0x698098d8);
	R0(D,A,B,C,X[ 9],12,0x8b44f7af);
	R0(C,D,A,B,X[10],17,0xffff5bb1);
	R0(B,C,D,A,X[11],22,0x895cd7be);
	R0(A,B,C,D,X[12], 7,0x6b901122);
	R0(D,A,B,C,X[13],12,0xfd987193);
	R0(C,D,A,B,X[14],17,0xa679438e);
	R0(B,C,D,A,X[15],22,0x49b40821);
	/* Round 1 */
	R1(A,B,C,D,X[ 1], 5,0xf61e2562);
	R1(D,A,B,C,X[ 6], 9,0xc040b340);
	R1(C,D,A,B,X[11],14,0x265e5a51);
	R1(B,C,D,A,X[ 0],20,0xe9b6c7aa);
	R1(A,B,C,D,X[ 5], 5,0xd62f105d);
	R1(D,A,B,C,X[10], 9,0x02441453);
	R1(C,D,A,B,X[15],14,0xd8a1e681);
	R1(B,C,D,A,X[ 4],20,0xe7d3fbc8);
	R1(A,B,C,D,X[ 9], 5,0x21e1cde6);
	R1(D,A,B,C,X[14], 9,0xc33707d6);
	R1(C,D,A,B,X[ 3],14,0xf4d50d87);
	R1(B,C,D,A,X[ 8],20,0x455a14ed);
	R1(A,B,C,D,X[13], 5,0xa9e3e905);
	R1(D,A,B,C,X[ 2], 9,0xfcefa3f8);
	R1(C,D,A,B,X[ 7],14,0x676f02d9);
	R1(B,C,D,A,X[12],20,0x8d2a4c8a);
	/* Round 2 */
	R2(A,B,C,D,X[ 5], 4,0xfffa3942);
	R2(D,A,B,C,X[ 8],11,0x8771f681);
	R2(C,D,A,B,X[11],16,0x6d9d6122);
	R2(B,C,D,A,X[14],23,0xfde5380c);
	R2(A,B,C,D,X[ 1], 4,0xa4beea44);
	R2(D,A,B,C,X[ 4],11,0x4bdecfa9);
	R2(C,D,A,B,X[ 7],16,0xf6bb4b60);
	R2(B,C,D,A,X[10],23,0xbebfbc70);
	R2(A,B,C,D,X[13], 4,0x289b7ec6);
	R2(D,A,B,C,X[ 0],11,0xeaa127fa);
	R2(C,D,A,B,X[ 3],16,0xd4ef3085);
	R2(B,C,D,A,X[ 6],23,0x04881d05);
	R2(A,B,C,D,X[ 9], 4,0xd9d4d039);
	R2(D,A,B,C,X[12],11,0xe6db99e5);
	R2(C,D,A,B,X[15],16,0x1fa27cf8);
	R2(B,C,D,A,X[ 2],23,0xc4ac5665);
	/* Round 3 */
	R3(A,B,C,D,X[ 0], 6,0xf4292244);
	R3(D,A,B,C,X[ 7],10,0x432aff97);
	R3(C,D,A,B,X[14],15,0xab9423a7);
	R3(B,C,D,A,X[ 5],21,0xfc93a039);
	R3(A,B,C,D,X[12], 6,0x655b59c3);
	R3(D,A,B,C,X[ 3],10,0x8f0ccc92);
	R3(C,D,A,B,X[10],15,0xffeff47d);
	R3(B,C,D,A,X[ 1],21,0x85845dd1);
	R3(A,B,C,D,X[ 8], 6,0x6fa87e4f);
	R3(D,A,B,C,X[15],10,0xfe2ce6e0);
	R3(C,D,A,B,X[ 6],15,0xa3014314);
	R3(B,C,D,A,X[13],21,0x4e0811a1);
	R3(A,B,C,D,X[ 4], 6,0xf7537e82);
	R3(D,A,B,C,X[11],10,0xbd3af235);
	R3(C,D,A,B,X[ 2],15,0x2ad7d2bb);
	R3(B,C,D,A,X[ 9],21,0xeb86d391);

	digest[0]+=A;
	digest[1]+=B;
	digest[2]+=C;
	digest[3]+=D;
}
int main(int argc,char **argv){

// Print GPU properties
//print_properties();

// Files to print the result after the last time step
FILE *rho_file;
FILE *E_file;
rho_file = fopen("rho_final.txt", "w");
E_file = fopen("E_final.txt", "w");

// Construct initial condition for problem
ICsinus Config(-1.0, 1.0, -1.0, 1.0); 
//ICsquare Config(0.5,0.5,gasGam);

// Set initial values for Configuration 1
/*
Config.set_rho(rhoConfig19);
Config.set_pressure(pressureConfig19);
Config.set_u(uConfig19);
Config.set_v(vConfig19);
*/

// Determining global border based on left over tiles (a little hack)
int globalPadding;
globalPadding = (nx+2*border+16)/16;
globalPadding = 16*globalPadding - (nx+2*border);
//printf("Globalpad: %i\n", globalPadding);

// Change border to add padding
//border = border + globalPadding/2;

// Initiate the matrices for the unknowns in the Euler equations
cpu_ptr_2D rho(nx, ny, border,1);
cpu_ptr_2D E(nx, ny, border,1);
cpu_ptr_2D rho_u(nx, ny, border,1);
cpu_ptr_2D rho_v(nx, ny, border,1);
cpu_ptr_2D zeros(nx, ny, border,1);

// Set initial condition
Config.setIC(rho, rho_u, rho_v, E);

double timeStart = get_wall_time();

// Test 
cpu_ptr_2D rho_dummy(nx, ny, border);
cpu_ptr_2D E_dummy(nx, ny, border);

/*
rho_dummy.xmin = -1.0;
rho_dummy.ymin = -1.0;
E_dummy.xmin = -1.0;
E_dummy.ymin = -1.0;
*/

// Set block and grid sizes
dim3 gridBC = dim3(1, 1, 1);
dim3 blockBC = dim3(BLOCKDIM_BC,1,1);

dim3 gridBlockFlux;
dim3 threadBlockFlux;

dim3 gridBlockRK;
dim3 threadBlockRK;

computeGridBlock(gridBlockFlux, threadBlockFlux, nx + 2*border, ny + 2*border, INNERTILEDIM_X, INNERTILEDIM_Y, BLOCKDIM_X, BLOCKDIM_Y);

computeGridBlock(gridBlockRK, threadBlockRK, nx + 2*border, ny + 2*border, BLOCKDIM_X_RK, BLOCKDIM_Y_RK, BLOCKDIM_X_RK, BLOCKDIM_Y_RK);

int nElements = gridBlockFlux.x*gridBlockFlux.y;

// Allocate memory for the GPU pointers
gpu_ptr_1D L_device(nElements);
gpu_ptr_1D dt_device(1);

gpu_ptr_2D rho_device(nx, ny, border);
gpu_ptr_2D E_device(nx, ny, border);
gpu_ptr_2D rho_u_device(nx, ny, border);
gpu_ptr_2D rho_v_device(nx, ny, border); 

gpu_ptr_2D R0(nx, ny, border);
gpu_ptr_2D R1(nx, ny, border);
gpu_ptr_2D R2(nx, ny, border);
gpu_ptr_2D R3(nx, ny, border);

gpu_ptr_2D Q0(nx, ny, border);
gpu_ptr_2D Q1(nx, ny, border);
gpu_ptr_2D Q2(nx, ny, border);
gpu_ptr_2D Q3(nx, ny, border);

// Allocate pinned memory on host
init_allocate();

// Set BC arguments
set_bc_args(BCArgs[0], rho_device.getRawPtr(), rho_u_device.getRawPtr(), rho_v_device.getRawPtr(), E_device.getRawPtr(), nx+2*border, ny+2*border, border);
set_bc_args(BCArgs[1], Q0.getRawPtr(), Q1.getRawPtr(), Q2.getRawPtr(), Q3.getRawPtr(), nx+2*border, ny+2*border, border);
set_bc_args(BCArgs[2], rho_device.getRawPtr(), rho_u_device.getRawPtr(), rho_v_device.getRawPtr(), E_device.getRawPtr(), nx+2*border, ny+2*border, border);

// Set FLUX arguments
set_flux_args(fluxArgs[0], L_device.getRawPtr(), rho_device.getRawPtr(), rho_u_device.getRawPtr(), rho_v_device.getRawPtr(), E_device.getRawPtr(), R0.getRawPtr(),R1.getRawPtr(), R2.getRawPtr(), R3.getRawPtr(), nx, ny, border, rho.get_dx(), rho.get_dy(), theta, gasGam, INNERTILEDIM_X, INNERTILEDIM_Y);
set_flux_args(fluxArgs[1], L_device.getRawPtr(), Q0.getRawPtr(), Q1.getRawPtr(), Q2.getRawPtr(), Q3.getRawPtr(), R0.getRawPtr(),R1.getRawPtr(), R2.getRawPtr(), R3.getRawPtr(), nx, ny, border, rho.get_dx(), rho.get_dy(), theta, gasGam, INNERTILEDIM_X, INNERTILEDIM_Y);

// Set TIME argument
set_dt_args(dtArgs, L_device.getRawPtr(), dt_device.getRawPtr(), nElements, rho.get_dx(), rho.get_dy(), cfl_number);

// Set Rk arguments
set_rk_args(RKArgs[0], dt_device.getRawPtr(), rho_device.getRawPtr(), rho_u_device.getRawPtr(), rho_v_device.getRawPtr(), E_device.getRawPtr(), R0.getRawPtr(), R1.getRawPtr(), R2.getRawPtr(), R3.getRawPtr(), Q0.getRawPtr(), Q1.getRawPtr(), Q2.getRawPtr(), Q3.getRawPtr(), nx, ny, border); 
set_rk_args(RKArgs[1], dt_device.getRawPtr(), Q0.getRawPtr(), Q1.getRawPtr(), Q2.getRawPtr(), Q3.getRawPtr(), R0.getRawPtr(), R1.getRawPtr(), R2.getRawPtr(), R3.getRawPtr(), rho_device.getRawPtr(), rho_u_device.getRawPtr(), rho_v_device.getRawPtr(), E_device.getRawPtr(), nx, ny, border); 


L_device.set(FLT_MAX);

/*
R0.upload(zeros.get_ptr()); 
R1.upload(zeros.get_ptr()); 
R2.upload(zeros.get_ptr()); 
R3.upload(zeros.get_ptr()); 

Q0.upload(zeros.get_ptr()); 
Q1.upload(zeros.get_ptr()); 
Q2.upload(zeros.get_ptr()); 
Q3.upload(zeros.get_ptr()); 
*/

R0.set(0,0,0,nx,ny,border); 
R1.set(0,0,0,nx,ny,border); 
R2.set(0,0,0,nx,ny,border); 
R3.set(0,0,0,nx,ny,border); 

Q0.set(0,0,0,nx,ny,border); 
Q1.set(0,0,0,nx,ny,border); 
Q2.set(0,0,0,nx,ny,border); 
Q3.set(0,0,0,nx,ny,border); 


rho_device.upload(rho.get_ptr());
rho_u_device.upload(rho_u.get_ptr());
rho_v_device.upload(rho_v.get_ptr());
E_device.upload(E.get_ptr());

// Update boudries
callCollectiveSetBCPeriodic(gridBC, blockBC, BCArgs[0]);

//Create cuda stream
cudaStream_t stream1;
cudaStreamCreate(&stream1);
cudaEvent_t dt_complete;
cudaEventCreate(&dt_complete);


while (currentTime < timeLength && step < maxStep){	
	
	//RK1	
	//Compute flux
	callFluxKernel(gridBlockFlux, threadBlockFlux, 0, fluxArgs[0]);	
	
	// Compute timestep (based on CFL condition)
	callDtKernel(TIMETHREADS, dtArgs);
	
	cudaMemcpyAsync(dt_host, dt_device.getRawPtr(), sizeof(float), cudaMemcpyDeviceToHost, stream1);
	cudaEventRecord(dt_complete, stream1);

	// Perform RK1 step
	callRKKernel(gridBlockRK, threadBlockRK, 0, RKArgs[0]);
	
	//Update boudries
	callCollectiveSetBCPeriodic(gridBC, blockBC, BCArgs[1]);		

	//RK2
	// Compute flux
	callFluxKernel(gridBlockFlux, threadBlockFlux, 1, fluxArgs[1]);

	//Perform RK2 step
	callRKKernel(gridBlockRK, threadBlockRK, 1, RKArgs[1]);	

	//cudaEventRecord(srteam_sync, srteam1);

	callCollectiveSetBCPeriodic(gridBC, blockBC, BCArgs[2]);

	cudaEventSynchronize(dt_complete);

	step++;	
	currentTime += *dt_host;	
//	printf("Step: %i, current time: %.6f dt:%.6f\n" , step,currentTime, dt_host[0]);

}


//cuProfilerStop();
//cudaProfilerStop();

printf("Elapsed time %.5f", get_wall_time() - timeStart);

E_device.download(E.get_ptr());
rho_u_device.download(rho_u.get_ptr());
rho_v_device.download(rho_v.get_ptr());
rho_device.download(rho_dummy.get_ptr());

rho_dummy.printToFile(rho_file, true, false);


Config.exactSolution(E_dummy, currentTime);
E_dummy.printToFile(E_file, true, false);


float LinfError = Linf(E_dummy, rho_dummy);
float L1Error = L1(E_dummy, rho_dummy); 
float L1Error2 = L1test(E_dummy, rho_dummy);

printf("nx: %i\t Linf error %.9f\t L1 error %.7f L1test erro %.7f", nx, LinfError, L1Error, L1Error2);


printf("nx: %i step: %i, current time: %.6f dt:%.6f\n" , nx, step,currentTime, dt_host[0]); 


/*
cudaMemcpy(L_host, L_device, sizeof(float)*(nElements), cudaMemcpyDeviceToHost);
for (int i =0; i < nElements; i++)
	printf(" %.7f ", L_host[i]); 
*/


printf("%s\n", cudaGetErrorString(cudaGetLastError()));

return(0);
}
Beispiel #10
0
static void deal_512bits(MD5_STRUCT *rec, UCHAR *data)
{
	UINT4 x[16];
	UINT4 a,b,c,d;
	int i,j;
	
	memset(x, 0, sizeof(x));
	
	for(i=0,j=0; i<16; i++,j+=4) {
		x[i]= *(UINT4 *)(data+j);
	}
	a = rec->sa;
	b = rec->sb;
	c = rec->sc;
	d = rec->sd;

	/* Round 1*/
	R1(a,b,c,d, x[ 0], 7, 0xd76aa478);
	R1(d,a,b,c, x[ 1],12, 0xe8c7b756);
	R1(c,d,a,b, x[ 2],17, 0x242070db);
	R1(b,c,d,a, x[ 3],22, 0xc1bdceee);
	R1(a,b,c,d, x[ 4], 7, 0xf57c0faf);
	R1(d,a,b,c, x[ 5],12, 0x4787c62a);
	R1(c,d,a,b, x[ 6],17, 0xa8304613);
	R1(b,c,d,a, x[ 7],22, 0xfd469501);
	R1(a,b,c,d, x[ 8], 7, 0x698098d8);
	R1(d,a,b,c, x[ 9],12, 0x8b44f7af);
	R1(c,d,a,b, x[10],17, 0xffff5bb1);
	R1(b,c,d,a, x[11],22, 0x895cd7be);
	R1(a,b,c,d, x[12], 7, 0x6b901122);
	R1(d,a,b,c, x[13],12, 0xfd987193);
	R1(c,d,a,b, x[14],17, 0xa679438e);
	R1(b,c,d,a, x[15],22, 0x49b40821);
	
	/* Round 2*/
	R2(a,b,c,d, x[ 1], 5, 0xf61e2562);
	R2(d,a,b,c, x[ 6], 9, 0xc040b340);
	R2(c,d,a,b, x[11],14, 0x265e5a51);
	R2(b,c,d,a, x[ 0],20, 0xe9b6c7aa);
	R2(a,b,c,d, x[ 5], 5, 0xd62f105d);
	R2(d,a,b,c, x[10], 9, 0x2441453 );
	R2(c,d,a,b, x[15],14, 0xd8a1e681);
	R2(b,c,d,a, x[ 4],20, 0xe7d3fbc8);
	R2(a,b,c,d, x[ 9], 5, 0x21e1cde6);
	R2(d,a,b,c, x[14], 9, 0xc33707d6);
	R2(c,d,a,b, x[ 3],14, 0xf4d50d87);
	R2(b,c,d,a, x[ 8],20, 0x455a14ed);
	R2(a,b,c,d, x[13], 5, 0xa9e3e905);
	R2(d,a,b,c, x[ 2], 9, 0xfcefa3f8);
	R2(c,d,a,b, x[ 7],14, 0x676f02d9);
	R2(b,c,d,a, x[12],20, 0x8d2a4c8a);
	
	/*Round 3*/
	R3(a,b,c,d, x[ 5], 4, 0xfffa3942);
	R3(d,a,b,c, x[ 8],11, 0x8771f681);
	R3(c,d,a,b, x[11],16, 0x6d9d6122);
	R3(b,c,d,a, x[14],23, 0xfde5380c);
	R3(a,b,c,d, x[ 1], 4, 0xa4beea44);
	R3(d,a,b,c, x[ 4],11, 0x4bdecfa9);
	R3(c,d,a,b, x[ 7],16, 0xf6bb4b60);
	R3(b,c,d,a, x[10],23, 0xbebfbc70);
	R3(a,b,c,d, x[13], 4, 0x289b7ec6);
	R3(d,a,b,c, x[ 0],11, 0xeaa127fa);
	R3(c,d,a,b, x[ 3],16, 0xd4ef3085);
	R3(b,c,d,a, x[ 6],23, 0x4881d05 );
	R3(a,b,c,d, x[ 9], 4, 0xd9d4d039);
	R3(d,a,b,c, x[12],11, 0xe6db99e5);
	R3(c,d,a,b, x[15],16, 0x1fa27cf8);
	R3(b,c,d,a, x[ 2],23, 0xc4ac5665);
	
	/* Round 4*/
	R4(a,b,c,d, x[ 0], 6, 0xf4292244);
	R4(d,a,b,c, x[ 7],10, 0x432aff97);
	R4(c,d,a,b, x[14],15, 0xab9423a7);
	R4(b,c,d,a, x[ 5],21, 0xfc93a039);
	R4(a,b,c,d, x[12], 6, 0x655b59c3);
	R4(d,a,b,c, x[ 3],10, 0x8f0ccc92);
	R4(c,d,a,b, x[10],15, 0xffeff47d);
	R4(b,c,d,a, x[ 1],21, 0x85845dd1);
	R4(a,b,c,d, x[ 8], 6, 0x6fa87e4f);
	R4(d,a,b,c, x[15],10, 0xfe2ce6e0);
	R4(c,d,a,b, x[ 6],15, 0xa3014314);
	R4(b,c,d,a, x[13],21, 0x4e0811a1);
	R4(a,b,c,d, x[ 4], 6, 0xf7537e82);
	R4(d,a,b,c, x[11],10, 0xbd3af235);
	R4(c,d,a,b, x[ 2],15, 0x2ad7d2bb);
	R4(b,c,d,a, x[ 9],21, 0xeb86d391);
	
	rec->sa += a;
	rec->sb += b;
	rec->sc += c;
	rec->sd += d;

	
	return;
}
Beispiel #11
0
void GarbleBlock(unsigned char *block,uint32_t a,uint32_t b,uint32_t c,uint32_t d,uint32_t e)
{
	uint32_t W[16];
	for(int i=0;i<16;i++) W[i]=(block[4*i+0]<<24)|(block[4*i+1]<<16)|(block[4*i+2]<<8)|block[4*i+3];

    R0(a,b,c,d,e, 0); R0(e,a,b,c,d, 1); R0(d,e,a,b,c, 2); R0(c,d,e,a,b, 3);
    R0(b,c,d,e,a, 4); R0(a,b,c,d,e, 5); R0(e,a,b,c,d, 6); R0(d,e,a,b,c, 7);
    R0(c,d,e,a,b, 8); R0(b,c,d,e,a, 9); R0(a,b,c,d,e,10); R0(e,a,b,c,d,11);
    R0(d,e,a,b,c,12); R0(c,d,e,a,b,13); R0(b,c,d,e,a,14); R0(a,b,c,d,e,15);
    R1(e,a,b,c,d,16); R1(d,e,a,b,c,17); R1(c,d,e,a,b,18); R1(b,c,d,e,a,19);
    R2(a,b,c,d,e,20); R2(e,a,b,c,d,21); R2(d,e,a,b,c,22); R2(c,d,e,a,b,23);
    R2(b,c,d,e,a,24); R2(a,b,c,d,e,25); R2(e,a,b,c,d,26); R2(d,e,a,b,c,27);
    R2(c,d,e,a,b,28); R2(b,c,d,e,a,29); R2(a,b,c,d,e,30); R2(e,a,b,c,d,31);
    R2(d,e,a,b,c,32); R2(c,d,e,a,b,33); R2(b,c,d,e,a,34); R2(a,b,c,d,e,35);
    R2(e,a,b,c,d,36); R2(d,e,a,b,c,37); R2(c,d,e,a,b,38); R2(b,c,d,e,a,39);
    R3(a,b,c,d,e,40); R3(e,a,b,c,d,41); R3(d,e,a,b,c,42); R3(c,d,e,a,b,43);
    R3(b,c,d,e,a,44); R3(a,b,c,d,e,45); R3(e,a,b,c,d,46); R3(d,e,a,b,c,47);
    R3(c,d,e,a,b,48); R3(b,c,d,e,a,49); R3(a,b,c,d,e,50); R3(e,a,b,c,d,51);
    R3(d,e,a,b,c,52); R3(c,d,e,a,b,53); R3(b,c,d,e,a,54); R3(a,b,c,d,e,55);
    R3(e,a,b,c,d,56); R3(d,e,a,b,c,57); R3(c,d,e,a,b,58); R3(b,c,d,e,a,59);
    R4(a,b,c,d,e,60); R4(e,a,b,c,d,61); R4(d,e,a,b,c,62); R4(c,d,e,a,b,63);
    R4(b,c,d,e,a,64); R4(a,b,c,d,e,65); R4(e,a,b,c,d,66); R4(d,e,a,b,c,67);
    R4(c,d,e,a,b,68); R4(b,c,d,e,a,69); R4(a,b,c,d,e,70); R4(e,a,b,c,d,71);
    R4(d,e,a,b,c,72); R4(c,d,e,a,b,73); R4(b,c,d,e,a,74); R4(a,b,c,d,e,75);
    R4(e,a,b,c,d,76); R4(d,e,a,b,c,77); R4(c,d,e,a,b,78); R4(b,c,d,e,a,79);

	for(int i=0;i<64;i++) block[i]=W[i/4]>>(i%4)*8;
}
Beispiel #12
0
void md5_block_host_order (MD5_CTX *c, const void *data, size_t num)
	{
	const MD5_LONG *X=data;
	register unsigned MD32_REG_T A,B,C,D;

	A=c->A;
	B=c->B;
	C=c->C;
	D=c->D;

	for (;num--;X+=HASH_LBLOCK)
		{
	/* Round 0 */
	R0(A,B,C,D,X[ 0], 7,0xd76aa478L);
	R0(D,A,B,C,X[ 1],12,0xe8c7b756L);
	R0(C,D,A,B,X[ 2],17,0x242070dbL);
	R0(B,C,D,A,X[ 3],22,0xc1bdceeeL);
	R0(A,B,C,D,X[ 4], 7,0xf57c0fafL);
	R0(D,A,B,C,X[ 5],12,0x4787c62aL);
	R0(C,D,A,B,X[ 6],17,0xa8304613L);
	R0(B,C,D,A,X[ 7],22,0xfd469501L);
	R0(A,B,C,D,X[ 8], 7,0x698098d8L);
	R0(D,A,B,C,X[ 9],12,0x8b44f7afL);
	R0(C,D,A,B,X[10],17,0xffff5bb1L);
	R0(B,C,D,A,X[11],22,0x895cd7beL);
	R0(A,B,C,D,X[12], 7,0x6b901122L);
	R0(D,A,B,C,X[13],12,0xfd987193L);
	R0(C,D,A,B,X[14],17,0xa679438eL);
	R0(B,C,D,A,X[15],22,0x49b40821L);
	/* Round 1 */
	R1(A,B,C,D,X[ 1], 5,0xf61e2562L);
	R1(D,A,B,C,X[ 6], 9,0xc040b340L);
	R1(C,D,A,B,X[11],14,0x265e5a51L);
	R1(B,C,D,A,X[ 0],20,0xe9b6c7aaL);
	R1(A,B,C,D,X[ 5], 5,0xd62f105dL);
	R1(D,A,B,C,X[10], 9,0x02441453L);
	R1(C,D,A,B,X[15],14,0xd8a1e681L);
	R1(B,C,D,A,X[ 4],20,0xe7d3fbc8L);
	R1(A,B,C,D,X[ 9], 5,0x21e1cde6L);
	R1(D,A,B,C,X[14], 9,0xc33707d6L);
	R1(C,D,A,B,X[ 3],14,0xf4d50d87L);
	R1(B,C,D,A,X[ 8],20,0x455a14edL);
	R1(A,B,C,D,X[13], 5,0xa9e3e905L);
	R1(D,A,B,C,X[ 2], 9,0xfcefa3f8L);
	R1(C,D,A,B,X[ 7],14,0x676f02d9L);
	R1(B,C,D,A,X[12],20,0x8d2a4c8aL);
	/* Round 2 */
	R2(A,B,C,D,X[ 5], 4,0xfffa3942L);
	R2(D,A,B,C,X[ 8],11,0x8771f681L);
	R2(C,D,A,B,X[11],16,0x6d9d6122L);
	R2(B,C,D,A,X[14],23,0xfde5380cL);
	R2(A,B,C,D,X[ 1], 4,0xa4beea44L);
	R2(D,A,B,C,X[ 4],11,0x4bdecfa9L);
	R2(C,D,A,B,X[ 7],16,0xf6bb4b60L);
	R2(B,C,D,A,X[10],23,0xbebfbc70L);
	R2(A,B,C,D,X[13], 4,0x289b7ec6L);
	R2(D,A,B,C,X[ 0],11,0xeaa127faL);
	R2(C,D,A,B,X[ 3],16,0xd4ef3085L);
	R2(B,C,D,A,X[ 6],23,0x04881d05L);
	R2(A,B,C,D,X[ 9], 4,0xd9d4d039L);
	R2(D,A,B,C,X[12],11,0xe6db99e5L);
	R2(C,D,A,B,X[15],16,0x1fa27cf8L);
	R2(B,C,D,A,X[ 2],23,0xc4ac5665L);
	/* Round 3 */
	R3(A,B,C,D,X[ 0], 6,0xf4292244L);
	R3(D,A,B,C,X[ 7],10,0x432aff97L);
	R3(C,D,A,B,X[14],15,0xab9423a7L);
	R3(B,C,D,A,X[ 5],21,0xfc93a039L);
	R3(A,B,C,D,X[12], 6,0x655b59c3L);
	R3(D,A,B,C,X[ 3],10,0x8f0ccc92L);
	R3(C,D,A,B,X[10],15,0xffeff47dL);
	R3(B,C,D,A,X[ 1],21,0x85845dd1L);
	R3(A,B,C,D,X[ 8], 6,0x6fa87e4fL);
	R3(D,A,B,C,X[15],10,0xfe2ce6e0L);
	R3(C,D,A,B,X[ 6],15,0xa3014314L);
	R3(B,C,D,A,X[13],21,0x4e0811a1L);
	R3(A,B,C,D,X[ 4], 6,0xf7537e82L);
	R3(D,A,B,C,X[11],10,0xbd3af235L);
	R3(C,D,A,B,X[ 2],15,0x2ad7d2bbL);
	R3(B,C,D,A,X[ 9],21,0xeb86d391L);

	A = c->A += A;
	B = c->B += B;
	C = c->C += C;
	D = c->D += D;
		}
	}
int main(int argc, char* argv[]) {
	omp_set_num_threads(4);
	//=========================================================================================================
	ChSystemGPU * system_gpu = new ChSystemGPU;
	ChCollisionSystemGPU *mcollisionengine = new ChCollisionSystemGPU();
	system_gpu->SetIntegrationType(ChSystem::INT_ANITESCU);

	//=========================================================================================================
	system_gpu->SetMaxiter(max_iter);
	system_gpu->SetIterLCPmaxItersSpeed(max_iter);
	((ChLcpSolverGPU *) (system_gpu->GetLcpSolverSpeed()))->SetMaxIteration(max_iter);
	system_gpu->SetTol(0);
	system_gpu->SetTolSpeeds(0);
	((ChLcpSolverGPU *) (system_gpu->GetLcpSolverSpeed()))->SetTolerance(0);
	((ChLcpSolverGPU *) (system_gpu->GetLcpSolverSpeed()))->SetCompliance(0, 0, 0);
	((ChLcpSolverGPU *) (system_gpu->GetLcpSolverSpeed()))->SetContactRecoverySpeed(5);
	((ChLcpSolverGPU *) (system_gpu->GetLcpSolverSpeed()))->SetSolverType(ACCELERATED_PROJECTED_GRADIENT_DESCENT);
	((ChCollisionSystemGPU *) (system_gpu->GetCollisionSystem()))->SetCollisionEnvelope(particle_radius.x * .05);
	mcollisionengine->setBinsPerAxis(R3(num_per_dir.x * 2, num_per_dir.y * 2, num_per_dir.z * 2));
	mcollisionengine->setBodyPerBin(100, 50);
	system_gpu->Set_G_acc(ChVector<>(0, gravity, 0));
	system_gpu->SetStep(timestep);
	//=========================================================================================================
	cout << num_per_dir.x << " " << num_per_dir.y << " " << num_per_dir.z << " " << num_per_dir.x * num_per_dir.y * num_per_dir.z << endl;
	//addPerturbedLayer(R3(0, -5 +container_thickness-particle_radius.y, 0), ELLIPSOID, particle_radius, num_per_dir, R3(.01, .01, .01), 10, 1, system_gpu);
	addHCPCube(num_per_dir.x, num_per_dir.y, num_per_dir.z, 1, particle_radius.x, 1, true, 0,  -6 +container_thickness+particle_radius.y, 0, 0, system_gpu);
	//=========================================================================================================

	ChSharedBodyPtr L = ChSharedBodyPtr(new ChBody(new ChCollisionModelParallel));
	ChSharedBodyPtr R = ChSharedBodyPtr(new ChBody(new ChCollisionModelParallel));
	ChSharedBodyPtr F = ChSharedBodyPtr(new ChBody(new ChCollisionModelParallel));
	ChSharedBodyPtr B = ChSharedBodyPtr(new ChBody(new ChCollisionModelParallel));
	ChSharedBodyPtr Bottom = ChSharedBodyPtr(new ChBody(new ChCollisionModelParallel));

	InitObject(L, 100000, Vector(-container_size.x + container_thickness, container_height - container_thickness, 0), Quaternion(1, 0, 0, 0), container_friction, container_friction, 0, true, true,
			-20, -20);
	InitObject(R, 100000, Vector(container_size.x - container_thickness, container_height - container_thickness, 0), Quaternion(1, 0, 0, 0), container_friction, container_friction, 0, true, true, -20,
			-20);
	InitObject(F, 100000, Vector(0, container_height - container_thickness, -container_size.z + container_thickness), Quaternion(1, 0, 0, 0), container_friction, container_friction, 0, true, true,
			-20, -20);
	InitObject(B, 100000, Vector(0, container_height - container_thickness, container_size.z - container_thickness), Quaternion(1, 0, 0, 0), container_friction, container_friction, 0, true, true, -20,
			-20);
	InitObject(Bottom, 100000, Vector(0, container_height - container_size.y, 0), Quaternion(1, 0, 0, 0), container_friction, container_friction, 0, true, true, -20, -20);

	AddCollisionGeometry(L, BOX, Vector(container_thickness, container_size.y, container_size.z), Vector(0, 0, 0), Quaternion(1, 0, 0, 0));
	AddCollisionGeometry(R, BOX, Vector(container_thickness, container_size.y, container_size.z), Vector(0, 0, 0), Quaternion(1, 0, 0, 0));
	AddCollisionGeometry(F, BOX, Vector(container_size.x, container_size.y, container_thickness), Vector(0, 0, 0), Quaternion(1, 0, 0, 0));
	AddCollisionGeometry(B, BOX, Vector(container_size.x, container_size.y, container_thickness), Vector(0, 0, 0), Quaternion(1, 0, 0, 0));
	AddCollisionGeometry(Bottom, BOX, Vector(container_size.x, container_thickness, container_size.z), Vector(0, 0, 0), Quaternion(1, 0, 0, 0));

	FinalizeObject(L, (ChSystemGPU *) system_gpu);
	FinalizeObject(R, (ChSystemGPU *) system_gpu);
	FinalizeObject(F, (ChSystemGPU *) system_gpu);
	FinalizeObject(B, (ChSystemGPU *) system_gpu);
	FinalizeObject(Bottom, (ChSystemGPU *) system_gpu);

	impactor = ChSharedBodyPtr(new ChBody(new ChCollisionModelParallel));
	InitObject(impactor, 1500, Vector(-container_size.x,container_height + container_size.y*2,0), Quaternion(1, 0, 0, 0), 1, 1, 0, true, false, -1, -2);
	AddCollisionGeometry(impactor, SPHERE, ChVector<>(.5,0,0), Vector(0, 0, 0), Quaternion(1, 0, 0, 0));
	FinalizeObject(impactor, (ChSystemGPU *) system_gpu);
	impactor->SetPos_dt(Vector(2.5,0,0));

	//=========================================================================================================
	//////Rendering specific stuff:
//	ChOpenGLManager * window_manager = new ChOpenGLManager();
//	ChOpenGL openGLView(window_manager, system_gpu, 800, 600, 0, 0, "Test_Solvers");
//	openGLView.render_camera->camera_position = glm::vec3(0, -5, -10);
//	openGLView.render_camera->camera_look_at = glm::vec3(0, -5, 0);
//	openGLView.render_camera->camera_scale = .1;
//	openGLView.SetCustomCallback(RunTimeStep);
//	openGLView.StartSpinning(window_manager);
//	window_manager->CallGlutMainLoop();
	//=========================================================================================================

	for (int i = 0; i < num_steps; i++) {
		system_gpu->DoStepDynamics(timestep);
		double TIME = system_gpu->GetChTime();
		double STEP = system_gpu->GetTimerStep();
		double BROD = system_gpu->GetTimerCollisionBroad();
		double NARR = system_gpu->GetTimerCollisionNarrow();
		double LCP = system_gpu->GetTimerLcp();
		double UPDT = system_gpu->GetTimerUpdate();
		int BODS = system_gpu->GetNbodies();
		int CNTC = system_gpu->GetNcontacts();
		int REQ_ITS = ((ChLcpSolverGPU*) (system_gpu->GetLcpSolverSpeed()))->GetTotalIterations();

		printf("%7.4f|%7.4f|%7.4f|%7.4f|%7.4f|%7.4f|%7d|%7d|%7d\n", TIME, STEP, BROD, NARR, LCP, UPDT, BODS, CNTC, REQ_ITS);
//		if (i % 1000 == 0) {
//			cout << "SAVED STATE" << endl;
//			DumpObjects(system_gpu, "diagonal_impact_settled.txt", "\t");
//		}
		RunTimeStep(system_gpu, i);
	}

	DumpObjects(system_gpu, "diagonal_impact_settled.txt", "\t");

}
#include "../../common/common.h"
#include "../../common/generation.h"
#include "../../common/parser.h"
#include "../../common/input_output.h"
real gravity = -9.80665;
real timestep = .0005;
real3 particle_radius = R3(.05, .05, .05);
real seconds_to_simulate = timestep*10;

int max_iter = 25;

int num_steps = seconds_to_simulate / timestep;

real3 container_size = R3(3, 1, 1.5);
real container_thickness = .05;
real container_height = -5;
real container_friction = .5;

int3 num_per_dir = I3((container_size - particle_radius * 2) / particle_radius);

ChSharedBodyPtr impactor;

template<class T>
void RunTimeStep(T* mSys, const int frame) {

}

int main(int argc, char* argv[]) {
	omp_set_num_threads(4);
	//=========================================================================================================
	ChSystemGPU * system_gpu = new ChSystemGPU;
Beispiel #15
0
void SHA1::Transform(word32 *state, const word32 *data)
{
	word32 W[16];
    /* Copy context->state[] to working vars */
    word32 a = state[0];
    word32 b = state[1];
    word32 c = state[2];
    word32 d = state[3];
    word32 e = state[4];
    /* 4 rounds of 20 operations each. Loop unrolled. */
    R0(a,b,c,d,e, 0); R0(e,a,b,c,d, 1); R0(d,e,a,b,c, 2); R0(c,d,e,a,b, 3);
    R0(b,c,d,e,a, 4); R0(a,b,c,d,e, 5); R0(e,a,b,c,d, 6); R0(d,e,a,b,c, 7);
    R0(c,d,e,a,b, 8); R0(b,c,d,e,a, 9); R0(a,b,c,d,e,10); R0(e,a,b,c,d,11);
    R0(d,e,a,b,c,12); R0(c,d,e,a,b,13); R0(b,c,d,e,a,14); R0(a,b,c,d,e,15);
    R1(e,a,b,c,d,16); R1(d,e,a,b,c,17); R1(c,d,e,a,b,18); R1(b,c,d,e,a,19);
    R2(a,b,c,d,e,20); R2(e,a,b,c,d,21); R2(d,e,a,b,c,22); R2(c,d,e,a,b,23);
    R2(b,c,d,e,a,24); R2(a,b,c,d,e,25); R2(e,a,b,c,d,26); R2(d,e,a,b,c,27);
    R2(c,d,e,a,b,28); R2(b,c,d,e,a,29); R2(a,b,c,d,e,30); R2(e,a,b,c,d,31);
    R2(d,e,a,b,c,32); R2(c,d,e,a,b,33); R2(b,c,d,e,a,34); R2(a,b,c,d,e,35);
    R2(e,a,b,c,d,36); R2(d,e,a,b,c,37); R2(c,d,e,a,b,38); R2(b,c,d,e,a,39);
    R3(a,b,c,d,e,40); R3(e,a,b,c,d,41); R3(d,e,a,b,c,42); R3(c,d,e,a,b,43);
    R3(b,c,d,e,a,44); R3(a,b,c,d,e,45); R3(e,a,b,c,d,46); R3(d,e,a,b,c,47);
    R3(c,d,e,a,b,48); R3(b,c,d,e,a,49); R3(a,b,c,d,e,50); R3(e,a,b,c,d,51);
    R3(d,e,a,b,c,52); R3(c,d,e,a,b,53); R3(b,c,d,e,a,54); R3(a,b,c,d,e,55);
    R3(e,a,b,c,d,56); R3(d,e,a,b,c,57); R3(c,d,e,a,b,58); R3(b,c,d,e,a,59);
    R4(a,b,c,d,e,60); R4(e,a,b,c,d,61); R4(d,e,a,b,c,62); R4(c,d,e,a,b,63);
    R4(b,c,d,e,a,64); R4(a,b,c,d,e,65); R4(e,a,b,c,d,66); R4(d,e,a,b,c,67);
    R4(c,d,e,a,b,68); R4(b,c,d,e,a,69); R4(a,b,c,d,e,70); R4(e,a,b,c,d,71);
    R4(d,e,a,b,c,72); R4(c,d,e,a,b,73); R4(b,c,d,e,a,74); R4(a,b,c,d,e,75);
    R4(e,a,b,c,d,76); R4(d,e,a,b,c,77); R4(c,d,e,a,b,78); R4(b,c,d,e,a,79);
    /* Add the working vars back into context.state[] */
    state[0] += a;
    state[1] += b;
    state[2] += c;
    state[3] += d;
    state[4] += e;
}
Beispiel #16
0
static void
_md5_update_digest (md5_t *ctx)
{
  uint32_t AA, BB, CC, DD;
  uint32_t X[MD5_BLOCK_WORDS_LENGTH];
  unsigned int j;

  /* Note there are no endian issues here, compiler is required to
   * handle shifts correctly
   */
  for (j = 0; j < MD5_BLOCK_WORDS_LENGTH; j++)
    X[j] = ((uint32_t)M[j*4]
            | ((uint32_t)M[j*4+1] << 8)
            | ((uint32_t)M[j*4+2] << 16)
            | ((uint32_t)M[j*4+3] << 24));

  AA = A;
  BB = B;
  CC = C;
  DD = D;

  /* Round 1 */
  R1 (A, B, C, D,  0,  7,  1);
  R1 (D, A, B, C,  1, 12,  2);
  R1 (C, D, A, B,  2, 17,  3);
  R1 (B, C, D, A,  3, 22,  4);
  R1 (A, B, C, D,  4,  7,  5);
  R1 (D, A, B, C,  5, 12,  6);
  R1 (C, D, A, B,  6, 17,  7);
  R1 (B, C, D, A,  7, 22,  8);
  R1 (A, B, C, D,  8,  7,  9);
  R1 (D, A, B, C,  9, 12, 10);
  R1 (C, D, A, B, 10, 17, 11);
  R1 (B, C, D, A, 11, 22, 12);
  R1 (A, B, C, D, 12,  7, 13);
  R1 (D, A, B, C, 13, 12, 14);
  R1 (C, D, A, B, 14, 17, 15);
  R1 (B, C, D, A, 15, 22, 16);

  /* Round 2 */
  R2 (A, B, C, D,  1,  5, 17);
  R2 (D, A, B, C,  6,  9, 18);
  R2 (C, D, A, B, 11, 14, 19);
  R2 (B, C, D, A,  0, 20, 20);
  R2 (A, B, C, D,  5,  5, 21);
  R2 (D, A, B, C, 10,  9, 22);
  R2 (C, D, A, B, 15, 14, 23);
  R2 (B, C, D, A,  4, 20, 24);
  R2 (A, B, C, D,  9,  5, 25);
  R2 (D, A, B, C, 14,  9, 26);
  R2 (C, D, A, B,  3, 14, 27);
  R2 (B, C, D, A,  8, 20, 28);
  R2 (A, B, C, D, 13,  5, 29);
  R2 (D, A, B, C,  2,  9, 30);
  R2 (C, D, A, B,  7, 14, 31);
  R2 (B, C, D, A, 12, 20, 32);

  /* Round 3 */
  R3 (A, B, C, D,  5,  4, 33);
  R3 (D, A, B, C,  8, 11, 34);
  R3 (C, D, A, B, 11, 16, 35);
  R3 (B, C, D, A, 14, 23, 36);
  R3 (A, B, C, D,  1,  4, 37);
  R3 (D, A, B, C,  4, 11, 38);
  R3 (C, D, A, B,  7, 16, 39);
  R3 (B, C, D, A, 10, 23, 40);
  R3 (A, B, C, D, 13,  4, 41);
  R3 (D, A, B, C,  0, 11, 42);
  R3 (C, D, A, B,  3, 16, 43);
  R3 (B, C, D, A,  6, 23, 44);
  R3 (A, B, C, D,  9,  4, 45);
  R3 (D, A, B, C, 12, 11, 46);
  R3 (C, D, A, B, 15, 16, 47);
  R3 (B, C, D, A,  2, 23, 48);

  /* Round 4 */
  R4 (A, B, C, D,  0,  6, 49);
  R4 (D, A, B, C,  7, 10, 50);
  R4 (C, D, A, B, 14, 15, 51);
  R4 (B, C, D, A,  5, 21, 52);
  R4 (A, B, C, D, 12,  6, 53);
  R4 (D, A, B, C,  3, 10, 54);
  R4 (C, D, A, B, 10, 15, 55);
  R4 (B, C, D, A,  1, 21, 56);
  R4 (A, B, C, D,  8,  6, 57);
  R4 (D, A, B, C, 15, 10, 58);
  R4 (C, D, A, B,  6, 15, 59);
  R4 (B, C, D, A, 13, 21, 60);
  R4 (A, B, C, D,  4,  6, 61);
  R4 (D, A, B, C, 11, 10, 62);
  R4 (C, D, A, B,  2, 15, 63);
  R4 (B, C, D, A,  9, 21, 64);

  A = A + AA;
  B = B + BB;
  C = C + CC;
  D = D + DD;
}
Beispiel #17
0
static void sha1_transform(uint32_t state[5], const uint8_t buffer[64])
{
    uint32_t block[80];
    unsigned int i, a, b, c, d, e;

    a = state[0];
    b = state[1];
    c = state[2];
    d = state[3];
    e = state[4];
#if CONFIG_SMALL
    for (i = 0; i < 80; i++) {
        int t;
        if (i < 16)
            t = AV_RB32(buffer + 4 * i);
        else
            t = rol(block[i-3] ^ block[i-8] ^ block[i-14] ^ block[i-16], 1);
        block[i] = t;
        t += e + rol(a, 5);
        if (i < 40) {
            if (i < 20)
                t += ((b&(c^d))^d)     + 0x5A827999;
            else
                t += ( b^c     ^d)     + 0x6ED9EBA1;
        } else {
            if (i < 60)
                t += (((b|c)&d)|(b&c)) + 0x8F1BBCDC;
            else
                t += ( b^c     ^d)     + 0xCA62C1D6;
        }
        e = d;
        d = c;
        c = rol(b, 30);
        b = a;
        a = t;
    }
#else
    for (i = 0; i < 15; i += 5) {
        R0(a, b, c, d, e, 0 + i);
        R0(e, a, b, c, d, 1 + i);
        R0(d, e, a, b, c, 2 + i);
        R0(c, d, e, a, b, 3 + i);
        R0(b, c, d, e, a, 4 + i);
    }
    R0(a, b, c, d, e, 15);
    R1(e, a, b, c, d, 16);
    R1(d, e, a, b, c, 17);
    R1(c, d, e, a, b, 18);
    R1(b, c, d, e, a, 19);
    for (i = 20; i < 40; i += 5) {
        R2(a, b, c, d, e, 0 + i);
        R2(e, a, b, c, d, 1 + i);
        R2(d, e, a, b, c, 2 + i);
        R2(c, d, e, a, b, 3 + i);
        R2(b, c, d, e, a, 4 + i);
    }
    for (; i < 60; i += 5) {
        R3(a, b, c, d, e, 0 + i);
        R3(e, a, b, c, d, 1 + i);
        R3(d, e, a, b, c, 2 + i);
        R3(c, d, e, a, b, 3 + i);
        R3(b, c, d, e, a, 4 + i);
    }
    for (; i < 80; i += 5) {
        R4(a, b, c, d, e, 0 + i);
        R4(e, a, b, c, d, 1 + i);
        R4(d, e, a, b, c, 2 + i);
        R4(c, d, e, a, b, 3 + i);
        R4(b, c, d, e, a, 4 + i);
    }
#endif
    state[0] += a;
    state[1] += b;
    state[2] += c;
    state[3] += d;
    state[4] += e;
}
Beispiel #18
0
void md5_block_data_order (MD5_CTX *c, const void *data_, int num)
	{
	const unsigned char *data=data_;
	register unsigned long A,B,C,D,l;
	/*
	 * In case you wonder why A-D are declared as long and not
	 * as MD5_LONG. Doing so results in slight performance
	 * boost on LP64 architectures. The catch is we don't
	 * really care if 32 MSBs of a 64-bit register get polluted
	 * with eventual overflows as we *save* only 32 LSBs in
	 * *either* case. Now declaring 'em long excuses the compiler
	 * from keeping 32 MSBs zeroed resulting in 13% performance
	 * improvement under SPARC Solaris7/64 and 5% under AlphaLinux.
	 * Well, to be honest it should say that this *prevents* 
	 * performance degradation.
	 *
	 *				<*****@*****.**>
	 */
#ifndef MD32_XARRAY
	/* See comment in crypto/sha/sha_locl.h for details. */
	unsigned long	XX0, XX1, XX2, XX3, XX4, XX5, XX6, XX7,
			XX8, XX9,XX10,XX11,XX12,XX13,XX14,XX15;
# define X(i)	XX##i
#else
	MD5_LONG XX[MD5_LBLOCK];
# define X(i)	XX[i]
#endif

	A=c->A;
	B=c->B;
	C=c->C;
	D=c->D;

	for (;num--;)
		{
	HOST_c2l(data,l); X( 0)=l;		HOST_c2l(data,l); X( 1)=l;
	/* Round 0 */
	R0(A,B,C,D,X( 0), 7,0xd76aa478L);	HOST_c2l(data,l); X( 2)=l;
	R0(D,A,B,C,X( 1),12,0xe8c7b756L);	HOST_c2l(data,l); X( 3)=l;
	R0(C,D,A,B,X( 2),17,0x242070dbL);	HOST_c2l(data,l); X( 4)=l;
	R0(B,C,D,A,X( 3),22,0xc1bdceeeL);	HOST_c2l(data,l); X( 5)=l;
	R0(A,B,C,D,X( 4), 7,0xf57c0fafL);	HOST_c2l(data,l); X( 6)=l;
	R0(D,A,B,C,X( 5),12,0x4787c62aL);	HOST_c2l(data,l); X( 7)=l;
	R0(C,D,A,B,X( 6),17,0xa8304613L);	HOST_c2l(data,l); X( 8)=l;
	R0(B,C,D,A,X( 7),22,0xfd469501L);	HOST_c2l(data,l); X( 9)=l;
	R0(A,B,C,D,X( 8), 7,0x698098d8L);	HOST_c2l(data,l); X(10)=l;
	R0(D,A,B,C,X( 9),12,0x8b44f7afL);	HOST_c2l(data,l); X(11)=l;
	R0(C,D,A,B,X(10),17,0xffff5bb1L);	HOST_c2l(data,l); X(12)=l;
	R0(B,C,D,A,X(11),22,0x895cd7beL);	HOST_c2l(data,l); X(13)=l;
	R0(A,B,C,D,X(12), 7,0x6b901122L);	HOST_c2l(data,l); X(14)=l;
	R0(D,A,B,C,X(13),12,0xfd987193L);	HOST_c2l(data,l); X(15)=l;
	R0(C,D,A,B,X(14),17,0xa679438eL);
	R0(B,C,D,A,X(15),22,0x49b40821L);
	/* Round 1 */
	R1(A,B,C,D,X( 1), 5,0xf61e2562L);
	R1(D,A,B,C,X( 6), 9,0xc040b340L);
	R1(C,D,A,B,X(11),14,0x265e5a51L);
	R1(B,C,D,A,X( 0),20,0xe9b6c7aaL);
	R1(A,B,C,D,X( 5), 5,0xd62f105dL);
	R1(D,A,B,C,X(10), 9,0x02441453L);
	R1(C,D,A,B,X(15),14,0xd8a1e681L);
	R1(B,C,D,A,X( 4),20,0xe7d3fbc8L);
	R1(A,B,C,D,X( 9), 5,0x21e1cde6L);
	R1(D,A,B,C,X(14), 9,0xc33707d6L);
	R1(C,D,A,B,X( 3),14,0xf4d50d87L);
	R1(B,C,D,A,X( 8),20,0x455a14edL);
	R1(A,B,C,D,X(13), 5,0xa9e3e905L);
	R1(D,A,B,C,X( 2), 9,0xfcefa3f8L);
	R1(C,D,A,B,X( 7),14,0x676f02d9L);
	R1(B,C,D,A,X(12),20,0x8d2a4c8aL);
	/* Round 2 */
	R2(A,B,C,D,X( 5), 4,0xfffa3942L);
	R2(D,A,B,C,X( 8),11,0x8771f681L);
	R2(C,D,A,B,X(11),16,0x6d9d6122L);
	R2(B,C,D,A,X(14),23,0xfde5380cL);
	R2(A,B,C,D,X( 1), 4,0xa4beea44L);
	R2(D,A,B,C,X( 4),11,0x4bdecfa9L);
	R2(C,D,A,B,X( 7),16,0xf6bb4b60L);
	R2(B,C,D,A,X(10),23,0xbebfbc70L);
	R2(A,B,C,D,X(13), 4,0x289b7ec6L);
	R2(D,A,B,C,X( 0),11,0xeaa127faL);
	R2(C,D,A,B,X( 3),16,0xd4ef3085L);
	R2(B,C,D,A,X( 6),23,0x04881d05L);
	R2(A,B,C,D,X( 9), 4,0xd9d4d039L);
	R2(D,A,B,C,X(12),11,0xe6db99e5L);
	R2(C,D,A,B,X(15),16,0x1fa27cf8L);
	R2(B,C,D,A,X( 2),23,0xc4ac5665L);
	/* Round 3 */
	R3(A,B,C,D,X( 0), 6,0xf4292244L);
	R3(D,A,B,C,X( 7),10,0x432aff97L);
	R3(C,D,A,B,X(14),15,0xab9423a7L);
	R3(B,C,D,A,X( 5),21,0xfc93a039L);
	R3(A,B,C,D,X(12), 6,0x655b59c3L);
	R3(D,A,B,C,X( 3),10,0x8f0ccc92L);
	R3(C,D,A,B,X(10),15,0xffeff47dL);
	R3(B,C,D,A,X( 1),21,0x85845dd1L);
	R3(A,B,C,D,X( 8), 6,0x6fa87e4fL);
	R3(D,A,B,C,X(15),10,0xfe2ce6e0L);
	R3(C,D,A,B,X( 6),15,0xa3014314L);
	R3(B,C,D,A,X(13),21,0x4e0811a1L);
	R3(A,B,C,D,X( 4), 6,0xf7537e82L);
	R3(D,A,B,C,X(11),10,0xbd3af235L);
	R3(C,D,A,B,X( 2),15,0x2ad7d2bbL);
	R3(B,C,D,A,X( 9),21,0xeb86d391L);

	A = c->A += A;
	B = c->B += B;
	C = c->C += C;
	D = c->D += D;
		}
	}
Beispiel #19
0
int main(int argc, char* argv[]) 
{
	bool visualize = true;
	int threads = 8;
	int config = 0;
	real gravity = -9.81;			//acceleration due to gravity
	real timestep = .01;			//step size
	real time_to_run = 1;			//length of simulation
	real current_time = 0;

	int num_steps = time_to_run / timestep;
	int max_iteration = 15;
	int tolerance = 0;

	//=========================================================================================================
	// Create system
	//=========================================================================================================
	ChSystemParallel * system_gpu = new ChSystemParallel;

	//=========================================================================================================
	// Populate the system with bodies/constraints/forces/etc.
	//=========================================================================================================
	ChVector<> lpos(0, 0, 0);
	ChQuaternion<> quat(1, 0, 0, 0);
	real container_width = 5;		//width of area with particles
	real container_length = 25;		//length of area that roller will go over
	real container_thickness = .25;     	//thickness of container walls
	real container_height = 2;		//height of the outer walls
	real particle_radius = .58;

	// Create a material (will be used by both objects)
	ChSharedPtr<ChMaterialSurface> material;
	material = ChSharedPtr<ChMaterialSurface>(new ChMaterialSurface);
	material->SetFriction(0.4);

	// Create a ball
	ChSharedBodyPtr ball = ChSharedBodyPtr(new ChBody(new ChCollisionModelParallel));
	InitObject(ball, 
		1, 				// mass
		ChVector<>(0, 10, 0), 		// position
		ChQuaternion<>(1, 0, 0, 0), 	// rotation
		material, 			// material
		true, 				// collide?
		false, 				// static?
		-15, -15);			// collision family
	ball->SetPos_dt(ChVector<>(0,0,10));
	AddCollisionGeometry(ball, SPHERE, particle_radius, lpos, quat);
	FinalizeObject(ball, (ChSystemParallel *) system_gpu);

	// Create a bin for the ball to fall into
	ChSharedBodyPtr bin = ChSharedBodyPtr(new ChBody(new ChCollisionModelParallel));
	InitObject(bin, 
		1, 				// mass
		ChVector<>(0, 0, 0), 		// position
		ChQuaternion<>(1, 0, 0, 0), 	// rotation
		material, 			// material
		true, 				// collide?
		true, 				// static?
		-20, -20); 			// collision family
	AddCollisionGeometry(bin, BOX, ChVector<>(container_width, container_thickness, container_length), lpos, quat);
	AddCollisionGeometry(bin, BOX, Vector(container_thickness, container_height, container_length), Vector(-container_width + container_thickness, container_height, 0), quat);
	AddCollisionGeometry(bin, BOX, Vector(container_thickness, container_height, container_length), Vector(container_width - container_thickness, container_height, 0), quat);
	AddCollisionGeometry(bin, BOX, Vector(container_width, container_height, container_thickness), Vector(0, container_height, -container_length + container_thickness), quat);
	AddCollisionGeometry(bin, BOX, Vector(container_width, container_height, container_thickness), Vector(0, container_height, container_length - container_thickness), quat);
	FinalizeObject(bin, (ChSystemParallel *) system_gpu);

	//=========================================================================================================
	// Edit system settings
	//=========================================================================================================
	system_gpu->SetIntegrationType(ChSystem::INT_ANITESCU);
	system_gpu->SetParallelThreadNumber(threads);
	system_gpu->SetMaxiter(max_iteration);
	system_gpu->SetIterLCPmaxItersSpeed(max_iteration);
	system_gpu->SetTol(1e-3);
	system_gpu->SetTolSpeeds(1e-3);
	system_gpu->Set_G_acc(ChVector<>(0, gravity, 0));
	system_gpu->SetStep(timestep);

	((ChLcpSolverParallel *) (system_gpu->GetLcpSolverSpeed()))->SetMaxIteration(max_iteration);
	((ChLcpSolverParallel *) (system_gpu->GetLcpSolverSpeed()))->SetTolerance(0);
	((ChLcpSolverParallel *) (system_gpu->GetLcpSolverSpeed()))->SetCompliance(0, 0, 0);
	((ChLcpSolverParallel *) (system_gpu->GetLcpSolverSpeed()))->SetContactRecoverySpeed(300);
	((ChLcpSolverParallel *) (system_gpu->GetLcpSolverSpeed()))->SetSolverType(ACCELERATED_PROJECTED_GRADIENT_DESCENT);

	((ChCollisionSystemParallel *) (system_gpu->GetCollisionSystem()))->SetCollisionEnvelope(particle_radius * .05);
	((ChCollisionSystemParallel *) (system_gpu->GetCollisionSystem()))->setBinsPerAxis(R3(10, 10, 10));
	((ChCollisionSystemParallel *) (system_gpu->GetCollisionSystem()))->setBodyPerBin(100, 50);

	omp_set_num_threads(threads);

	//=========================================================================================================
	// Enter the time loop and render the simulation
	//=========================================================================================================
	if (visualize) {
		ChOpenGLManager * window_manager = new ChOpenGLManager();
		ChOpenGL openGLView(window_manager, system_gpu, 800, 600, 0, 0, "Test_Solvers");
		openGLView.render_camera->camera_pos = Vector(0, 5, -20);
		openGLView.render_camera->look_at = Vector(0, 0, 0);
		openGLView.SetCustomCallback(RunTimeStep);
		openGLView.StartSpinning(window_manager);
		window_manager->CallGlutMainLoop();
	}

	return 0;
}
Beispiel #20
0
void md5_block_host_order (MD5_CTX *c, const void *data, int num)
	{
	const MD5_LONG *X=data;
	register unsigned long A,B,C,D;
	/*
	 * In case you wonder why A-D are declared as long and not
	 * as MD5_LONG. Doing so results in slight performance
	 * boost on LP64 architectures. The catch is we don't
	 * really care if 32 MSBs of a 64-bit register get polluted
	 * with eventual overflows as we *save* only 32 LSBs in
	 * *either* case. Now declaring 'em long excuses the compiler
	 * from keeping 32 MSBs zeroed resulting in 13% performance
	 * improvement under SPARC Solaris7/64 and 5% under AlphaLinux.
	 * Well, to be honest it should say that this *prevents* 
	 * performance degradation.
	 *
	 *				<*****@*****.**>
	 */

	A=c->A;
	B=c->B;
	C=c->C;
	D=c->D;

	for (;num--;X+=HASH_LBLOCK)
		{
	/* Round 0 */
	R0(A,B,C,D,X[ 0], 7,0xd76aa478L);
	R0(D,A,B,C,X[ 1],12,0xe8c7b756L);
	R0(C,D,A,B,X[ 2],17,0x242070dbL);
	R0(B,C,D,A,X[ 3],22,0xc1bdceeeL);
	R0(A,B,C,D,X[ 4], 7,0xf57c0fafL);
	R0(D,A,B,C,X[ 5],12,0x4787c62aL);
	R0(C,D,A,B,X[ 6],17,0xa8304613L);
	R0(B,C,D,A,X[ 7],22,0xfd469501L);
	R0(A,B,C,D,X[ 8], 7,0x698098d8L);
	R0(D,A,B,C,X[ 9],12,0x8b44f7afL);
	R0(C,D,A,B,X[10],17,0xffff5bb1L);
	R0(B,C,D,A,X[11],22,0x895cd7beL);
	R0(A,B,C,D,X[12], 7,0x6b901122L);
	R0(D,A,B,C,X[13],12,0xfd987193L);
	R0(C,D,A,B,X[14],17,0xa679438eL);
	R0(B,C,D,A,X[15],22,0x49b40821L);
	/* Round 1 */
	R1(A,B,C,D,X[ 1], 5,0xf61e2562L);
	R1(D,A,B,C,X[ 6], 9,0xc040b340L);
	R1(C,D,A,B,X[11],14,0x265e5a51L);
	R1(B,C,D,A,X[ 0],20,0xe9b6c7aaL);
	R1(A,B,C,D,X[ 5], 5,0xd62f105dL);
	R1(D,A,B,C,X[10], 9,0x02441453L);
	R1(C,D,A,B,X[15],14,0xd8a1e681L);
	R1(B,C,D,A,X[ 4],20,0xe7d3fbc8L);
	R1(A,B,C,D,X[ 9], 5,0x21e1cde6L);
	R1(D,A,B,C,X[14], 9,0xc33707d6L);
	R1(C,D,A,B,X[ 3],14,0xf4d50d87L);
	R1(B,C,D,A,X[ 8],20,0x455a14edL);
	R1(A,B,C,D,X[13], 5,0xa9e3e905L);
	R1(D,A,B,C,X[ 2], 9,0xfcefa3f8L);
	R1(C,D,A,B,X[ 7],14,0x676f02d9L);
	R1(B,C,D,A,X[12],20,0x8d2a4c8aL);
	/* Round 2 */
	R2(A,B,C,D,X[ 5], 4,0xfffa3942L);
	R2(D,A,B,C,X[ 8],11,0x8771f681L);
	R2(C,D,A,B,X[11],16,0x6d9d6122L);
	R2(B,C,D,A,X[14],23,0xfde5380cL);
	R2(A,B,C,D,X[ 1], 4,0xa4beea44L);
	R2(D,A,B,C,X[ 4],11,0x4bdecfa9L);
	R2(C,D,A,B,X[ 7],16,0xf6bb4b60L);
	R2(B,C,D,A,X[10],23,0xbebfbc70L);
	R2(A,B,C,D,X[13], 4,0x289b7ec6L);
	R2(D,A,B,C,X[ 0],11,0xeaa127faL);
	R2(C,D,A,B,X[ 3],16,0xd4ef3085L);
	R2(B,C,D,A,X[ 6],23,0x04881d05L);
	R2(A,B,C,D,X[ 9], 4,0xd9d4d039L);
	R2(D,A,B,C,X[12],11,0xe6db99e5L);
	R2(C,D,A,B,X[15],16,0x1fa27cf8L);
	R2(B,C,D,A,X[ 2],23,0xc4ac5665L);
	/* Round 3 */
	R3(A,B,C,D,X[ 0], 6,0xf4292244L);
	R3(D,A,B,C,X[ 7],10,0x432aff97L);
	R3(C,D,A,B,X[14],15,0xab9423a7L);
	R3(B,C,D,A,X[ 5],21,0xfc93a039L);
	R3(A,B,C,D,X[12], 6,0x655b59c3L);
	R3(D,A,B,C,X[ 3],10,0x8f0ccc92L);
	R3(C,D,A,B,X[10],15,0xffeff47dL);
	R3(B,C,D,A,X[ 1],21,0x85845dd1L);
	R3(A,B,C,D,X[ 8], 6,0x6fa87e4fL);
	R3(D,A,B,C,X[15],10,0xfe2ce6e0L);
	R3(C,D,A,B,X[ 6],15,0xa3014314L);
	R3(B,C,D,A,X[13],21,0x4e0811a1L);
	R3(A,B,C,D,X[ 4], 6,0xf7537e82L);
	R3(D,A,B,C,X[11],10,0xbd3af235L);
	R3(C,D,A,B,X[ 2],15,0x2ad7d2bbL);
	R3(B,C,D,A,X[ 9],21,0xeb86d391L);

	A = c->A += A;
	B = c->B += B;
	C = c->C += C;
	D = c->D += D;
		}
	}
Beispiel #21
0
/* transform one 512bit block. this is the core of the algorithm. */
static void
sha1_transform(uint32_t state[5], char buf[SHA1_BLOCKSIZE])
{
	uint32_t a, b, c, d, e;
	uint32_t *block = (uint32_t *)buf;
#ifdef SHA1_SHORTCODE
	uint8_t i;
#endif

	/* copy state to working vars */
	a = state[0];
	b = state[1];
	c = state[2];
	d = state[3];
	e = state[4];

#ifdef SHA1_SHORTCODE
	for (i = 0; i < 80; i++) {
		uint32_t t;

		if (i < 20)
			t = ((b & (c ^ d)) ^ d)       + 0x5A827999;
		else if (i < 40)
			t = (b ^ c ^ d)               + 0x6ED9EBA1;
		else if (i < 60)
			t = (((b | c) & d) | (b & c)) + 0x8F1BBCDC;
		else
			t = (b ^ c ^ d)               + 0xCA62C1D6;

		t += (i < 16) ? blk0(i) : blk(i);
		t += e + rol(a, 5);

		e = d;
		d = c;
		c = rol(b, 30);
		b = a;
		a = t;
	}
#else

/* R0 and R1, R2, R3, R4 are the different operations used in SHA1 */
#define R0(v,w,x,y,z,i) \
	z += ((w&(x^y))^y)     + blk0(i) + 0x5A827999 + rol(v, 5); w = rol(w, 30)
#define R1(v,w,x,y,z,i) \
	z += ((w&(x^y))^y)     + blk(i)  + 0x5A827999 + rol(v, 5); w = rol(w, 30)
#define R2(v,w,x,y,z,i) \
	z += (w^x^y)           + blk(i)  + 0x6ED9EBA1 + rol(v, 5); w = rol(w, 30)
#define R3(v,w,x,y,z,i) \
	z += (((w|x)&y)|(w&x)) + blk(i)  + 0x8F1BBCDC + rol(v, 5); w = rol(w, 30)
#define R4(v,w,x,y,z,i) \
	z += (w^x^y)           + blk(i)  + 0xCA62C1D6 + rol(v, 5); w = rol(w, 30)

	/* 4 rounds of 20 operations each. loop unrolled. */
	R0(a,b,c,d,e, 0); R0(e,a,b,c,d, 1); R0(d,e,a,b,c, 2); R0(c,d,e,a,b, 3);
	R0(b,c,d,e,a, 4); R0(a,b,c,d,e, 5); R0(e,a,b,c,d, 6); R0(d,e,a,b,c, 7);
	R0(c,d,e,a,b, 8); R0(b,c,d,e,a, 9); R0(a,b,c,d,e,10); R0(e,a,b,c,d,11);
	R0(d,e,a,b,c,12); R0(c,d,e,a,b,13); R0(b,c,d,e,a,14); R0(a,b,c,d,e,15);
	R1(e,a,b,c,d,16); R1(d,e,a,b,c,17); R1(c,d,e,a,b,18); R1(b,c,d,e,a,19);
	R2(a,b,c,d,e,20); R2(e,a,b,c,d,21); R2(d,e,a,b,c,22); R2(c,d,e,a,b,23);
	R2(b,c,d,e,a,24); R2(a,b,c,d,e,25); R2(e,a,b,c,d,26); R2(d,e,a,b,c,27);
	R2(c,d,e,a,b,28); R2(b,c,d,e,a,29); R2(a,b,c,d,e,30); R2(e,a,b,c,d,31);
	R2(d,e,a,b,c,32); R2(c,d,e,a,b,33); R2(b,c,d,e,a,34); R2(a,b,c,d,e,35);
	R2(e,a,b,c,d,36); R2(d,e,a,b,c,37); R2(c,d,e,a,b,38); R2(b,c,d,e,a,39);
	R3(a,b,c,d,e,40); R3(e,a,b,c,d,41); R3(d,e,a,b,c,42); R3(c,d,e,a,b,43);
	R3(b,c,d,e,a,44); R3(a,b,c,d,e,45); R3(e,a,b,c,d,46); R3(d,e,a,b,c,47);
	R3(c,d,e,a,b,48); R3(b,c,d,e,a,49); R3(a,b,c,d,e,50); R3(e,a,b,c,d,51);
	R3(d,e,a,b,c,52); R3(c,d,e,a,b,53); R3(b,c,d,e,a,54); R3(a,b,c,d,e,55);
	R3(e,a,b,c,d,56); R3(d,e,a,b,c,57); R3(c,d,e,a,b,58); R3(b,c,d,e,a,59);
	R4(a,b,c,d,e,60); R4(e,a,b,c,d,61); R4(d,e,a,b,c,62); R4(c,d,e,a,b,63);
	R4(b,c,d,e,a,64); R4(a,b,c,d,e,65); R4(e,a,b,c,d,66); R4(d,e,a,b,c,67);
	R4(c,d,e,a,b,68); R4(b,c,d,e,a,69); R4(a,b,c,d,e,70); R4(e,a,b,c,d,71);
	R4(d,e,a,b,c,72); R4(c,d,e,a,b,73); R4(b,c,d,e,a,74); R4(a,b,c,d,e,75);
	R4(e,a,b,c,d,76); R4(d,e,a,b,c,77); R4(c,d,e,a,b,78); R4(b,c,d,e,a,79);
#endif

	/* add the working vars back into state */
	state[0] += a;
	state[1] += b;
	state[2] += c;
	state[3] += d;
	state[4] += e;
}
Beispiel #22
0
FenPrincipale::FenPrincipale()
{	
	showMaximized();
	//showNormal();

	QMenu *menuFichier = menuBar()->addMenu("&Fichier");

	QAction *actionLoadImage = menuFichier->addAction("&Load Image");	
	actionLoadImage->setIcon(QIcon("Icons/fileopen.png"));
	menuFichier->addAction(actionLoadImage);

	QAction *actionExit = menuFichier->addAction("&Quitter");
	actionExit->setIcon(QIcon("Icons/fileclose.png"));
	menuFichier->addAction(actionExit);

	//QMenu *menuTools = menuBar()->addMenu("&Tools");

	QMenu *menuComm = menuBar()->addMenu("&Communication");

	QAction *actionSend = menuComm->addAction("&Send to server");	
	actionSend->setIcon(QIcon("Icons/ok.png"));

	// Création de la barre d'outils

    QToolBar *toolBarFichier = addToolBar("Fichier");
    toolBarFichier->addAction(actionLoadImage);
	toolBarFichier->addAction(actionExit);
	toolBarFichier->addSeparator();
	toolBarFichier->addAction(actionSend);
	
	QObject::connect(actionLoadImage, SIGNAL(triggered()), this, SLOT(LoadImageW()));
    QObject::connect(actionExit, SIGNAL(triggered()), this, SLOT(close()));
    QObject::connect(actionSend, SIGNAL(triggered()), this, SLOT(SendServer()));
	QObject::connect(actionSend, SIGNAL(triggered()), this, SLOT(ShowResults()));
    
	//
	// Création des docks
	//

	// dock IMAGE

	dockImage = new QDockWidget("Image", this);
	setCentralWidget(dockImage);

	ImageWidget = new QWidget;
	dockImage->setWidget(ImageWidget);

	// dock SERVEUR

	dockServeur = new QDockWidget("Serveur", this);
	addDockWidget(Qt::LeftDockWidgetArea, dockServeur);


	QWidget *paramDock = new QWidget;
	dockServeur->setWidget(paramDock);

	QSize s(220,20);

	adressServer1 = new QLineEdit(QString("138.195.102.25"));
	adressServer1->setMaximumSize(s);

	QHBoxLayout *adressLayout = new QHBoxLayout;
	adressLayout->addWidget(adressServer1);

	QWidget *adressWidget = new QWidget;
	adressWidget->setLayout(adressLayout);

	portAdressServer = new QLineEdit(QString("6006"));
	portAdressServer->setMaximumSize(s);

	QHBoxLayout *portLayout = new QHBoxLayout;
	portLayout->addWidget(portAdressServer);

	QWidget *portAdressWidget = new QWidget;
	portAdressWidget->setLayout(portLayout);

	QLabel *adressLabel = new QLabel("Adresse IP",paramDock);
	QLabel *portLabel = new QLabel("Port",paramDock);

	QPushButton *okServer = new QPushButton("Send");
	QObject::connect(okServer, SIGNAL(clicked()),this,SLOT(SendServer()));
	QObject::connect(okServer, SIGNAL(clicked()),this,SLOT(ShowResults()));

	QVBoxLayout *paramLayout = new QVBoxLayout(paramDock);
	paramLayout->addWidget(adressLabel);
	paramLayout->addWidget(adressWidget);
	paramLayout->addWidget(portLabel);
	paramLayout->addWidget(portAdressWidget);
	paramLayout->addWidget(okServer);
	paramLayout->setAlignment(Qt::AlignLeft);
	paramDock->setLayout(paramLayout);
	//dockServeur->setGeometry(QRect(100,200,200,250));
	dockServeur->setMaximumSize(250,200);

	// dock RESULTATS

	dockResults = new QDockWidget("Resultats",this);
	addDockWidget(Qt::RightDockWidgetArea, dockResults);
	dockResults->setMaximumWidth(250);

	WidgetResults = new QWidget;
	scrollArea = new QScrollArea;

	dockResults->setWidget(scrollArea);


	

	QPixmap *mini = new QPixmap(QString("test.jpg"));
	Result R(mini,98,"t");
	QPixmap *mini2 = new QPixmap(QString("9143.gif.jpg"));
	Result R2(mini2,95,"v");
	QPixmap *mini3 = new QPixmap(QString("test.jpg"));
	Result R3(mini3,92,"t");
	QPixmap *mini4 = new QPixmap(QString("test.jpg"));
	Result R4(mini4,90,"t");
	QPixmap *mini5 = new QPixmap(QString("test.jpg"));
	Result R5(mini5,88,"t");
	QPixmap *mini6 = new QPixmap(QString("test.jpg"));
	Result R6(mini6,86,"t");
	QPixmap *mini7 = new QPixmap(QString("test.jpg"));
	Result R7(mini7,84,"t");
	QPixmap *mini8 = new QPixmap(QString("test.jpg"));
	Result R8(mini8,82,"t");
	QPixmap *mini9 = new QPixmap(QString("test.jpg"));
	Result R9(mini9,81,"t");
	QPixmap *mini10 = new QPixmap(QString("test.jpg"));
	Result R10(mini10,79,"t");
	QPixmap *mini11 = new QPixmap(QString("test.jpg"));
	Result R11(mini11,78,"t");
	QPixmap *mini12 = new QPixmap(QString("test.jpg"));
	Result R12(mini12,77,"t");
	QPixmap *mini13 = new QPixmap(QString("test.jpg"));
	Result R13(mini13,76,"t");
	QPixmap *mini14 = new QPixmap(QString("test.jpg"));
	Result R14(mini14,75,"t");

	T.push_back(R);
	T.push_back(R2);
	T.push_back(R3);
	T.push_back(R4);
	T.push_back(R5);
	T.push_back(R6);
	T.push_back(R7);
	T.push_back(R8);
	T.push_back(R9);
	T.push_back(R10);
	T.push_back(R11);
	T.push_back(R12);
	T.push_back(R13);
	T.push_back(R14);

}