Пример #1
0
void rijndaelDecrypt_Final(const u32 rk[/*44*/], u8 pt[16], int rank)
{
	//printf("In AES final thread\n");
	float tempArray[4];
	int i = 0;
	u32 s[4], t0 = 0, t1 = 0, t2 = 0, t3 = 0;

	int Nr = 10;

	int * s_sign = (int*)s;
	MPI_Recv(s_sign, 4, MPI_INT, rank - 1, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
	ROUND(9, &t0, &t1, &t2, &t3, s[0], s[1], s[2], s[3], rk);

	/*
	 * apply last round and
	 * map cipher state to byte array block:
	 */

	rk += Nr << 2;

	s[0] = TD41(t0) ^ TD42(t3) ^ TD43(t2) ^ TD44(t1) ^ rk[0];
	PUTU32(pt     , s[0]);
	s[1] = TD41(t1) ^ TD42(t0) ^ TD43(t3) ^ TD44(t2) ^ rk[1];
	PUTU32(pt +  4, s[1]);
	s[2] = TD41(t2) ^ TD42(t1) ^ TD43(t0) ^ TD44(t3) ^ rk[2];
	PUTU32(pt +  8, s[2]);
	s[3] = TD41(t3) ^ TD42(t2) ^ TD43(t1) ^ TD44(t0) ^ rk[3];
	PUTU32(pt + 12, s[3]);

	for(i=0; i <4; i++)
	{
		union {
			float f;
			unsigned char b[4];
		} u;

		u.b[3] = pt[4*i+0];
		u.b[2] = pt[4*i+1];
		u.b[1] = pt[4*i+2];
		u.b[0] = pt[4*i+3];

		tempArray[i] = u.f;
		//printf("%f ",tempArray[i]);
	}

	//printf("\n");
	//for(i = 1; i <= 4; i++)
	//printf("Sent the values to %d\n", rank + 1);
	MPI_Send(tempArray, 4, MPI_FLOAT, rank + 1, 0, MPI_COMM_WORLD);
}
Пример #2
0
void rijndaelDecrypt_Final(const u32 rk[/*44*/], u8 pt[16], int rank)
{
  u32 s[4], t0 = 0, t1 = 0, t2 = 0, t3 = 0;

  int Nr = 10;

  int * s_sign = (int*)s;
  MPI_Recv(s_sign, 4, MPI_INT, rank - 1, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
//printf("read:rank %d val: %#x,%#x,%#x,%#x\n",rank,s_sign[0],s_sign[1],s_sign[2],s_sign[3]);
  ROUND(9, &t0, &t1, &t2, &t3, s[0], s[1], s[2], s[3], rk);

  /*
   * apply last round and
   * map cipher state to byte array block:
   */

	rk += Nr << 2;

        s[0] = TD41(t0) ^ TD42(t3) ^ TD43(t2) ^ TD44(t1) ^ rk[0];
        PUTU32(pt     , s[0]);
        s[1] = TD41(t1) ^ TD42(t0) ^ TD43(t3) ^ TD44(t2) ^ rk[1];
        PUTU32(pt +  4, s[1]);
        s[2] = TD41(t2) ^ TD42(t1) ^ TD43(t0) ^ TD44(t3) ^ rk[2];
        PUTU32(pt +  8, s[2]);
        s[3] = TD41(t3) ^ TD42(t2) ^ TD43(t1) ^ TD44(t0) ^ rk[3];
        PUTU32(pt + 12, s[3]);

/*
  s[0] = TE41(t0) ^ TE42(t1) ^ TE43(t2) ^ TE44(t3) ^ rk[8];
  PUTU32(ct     , s[0]);
  s[1] = TE41(t1) ^ TE42(t2) ^ TE43(t3) ^ TE44(t0) ^ rk[9];
  PUTU32(ct +  4, s[1]);
  s[2] = TE41(t2) ^ TE42(t3) ^ TE43(t0) ^ TE44(t1) ^ rk[10];
  PUTU32(ct +  8, s[2]);
  s[3] = TE41(t3) ^ TE42(t0) ^ TE43(t1) ^ TE44(t2) ^ rk[11];
  PUTU32(ct + 12, s[3]);
*/
}
Пример #3
0
void rijndaelDecrypt(const u32 rk[/*44*/], const u8 ct[16], u8 pt[16])
{
	u32 s0, s1, s2, s3, t0, t1, t2, t3;
	const int Nr = 10;
#ifndef FULL_UNROLL
	int r;
#endif /* ?FULL_UNROLL */

	/*
	 * map byte array block to cipher state
	 * and add initial round key:
	 */
	s0 = GETU32(ct     ) ^ rk[0];
	s1 = GETU32(ct +  4) ^ rk[1];
	s2 = GETU32(ct +  8) ^ rk[2];
	s3 = GETU32(ct + 12) ^ rk[3];

#define ROUND(i,d,s) \
d##0 = TD0(s##0) ^ TD1(s##3) ^ TD2(s##2) ^ TD3(s##1) ^ rk[4 * i]; \
d##1 = TD0(s##1) ^ TD1(s##0) ^ TD2(s##3) ^ TD3(s##2) ^ rk[4 * i + 1]; \
d##2 = TD0(s##2) ^ TD1(s##1) ^ TD2(s##0) ^ TD3(s##3) ^ rk[4 * i + 2]; \
d##3 = TD0(s##3) ^ TD1(s##2) ^ TD2(s##1) ^ TD3(s##0) ^ rk[4 * i + 3]

#ifdef FULL_UNROLL

	ROUND(1,t,s);
	ROUND(2,s,t);
	ROUND(3,t,s);
	ROUND(4,s,t);
	ROUND(5,t,s);
	ROUND(6,s,t);
	ROUND(7,t,s);
	ROUND(8,s,t);
	ROUND(9,t,s);

	rk += Nr << 2;

#else  /* !FULL_UNROLL */

	/* Nr - 1 full rounds: */
	r = Nr >> 1;
	for (;;) {
		ROUND(1,t,s);
		rk += 8;
		if (--r == 0)
			break;
		ROUND(0,s,t);
	}

#endif /* ?FULL_UNROLL */

#undef ROUND

	/*
	 * apply last round and
	 * map cipher state to byte array block:
	 */
	s0 = TD41(t0) ^ TD42(t3) ^ TD43(t2) ^ TD44(t1) ^ rk[0];
	PUTU32(pt     , s0);
	s1 = TD41(t1) ^ TD42(t0) ^ TD43(t3) ^ TD44(t2) ^ rk[1];
	PUTU32(pt +  4, s1);
	s2 = TD41(t2) ^ TD42(t1) ^ TD43(t0) ^ TD44(t3) ^ rk[2];
	PUTU32(pt +  8, s2);
	s3 = TD41(t3) ^ TD42(t2) ^ TD43(t1) ^ TD44(t0) ^ rk[3];
	PUTU32(pt + 12, s3);
}