Exemplo n.º 1
0
CoulombPBCAATemp::Return_t
CoulombPBCAATemp::evaluateForPbyP(ParticleSet& P)
{
  if(is_active)
  {
    SR2=0.0;
    Return_t res=myConst;
    const DistanceTableData *d_aa = P.DistTables[0];
    for(int iat=0; iat<NumCenters; iat++)
    {
      Return_t z=0.5*Zat[iat];
      for(int nn=d_aa->M[iat],jat=iat+1; nn<d_aa->M[iat+1]; ++nn,++jat)
      {
        Return_t e=z*Zat[jat]*d_aa->rinv(nn)*rVs->splint(d_aa->r(nn));
        SR2(iat,jat)=e;
        SR2(jat,iat)=e;
        res+=e+e;
      }
    }
    return res+evalLR(P);
  }
  else
    return Value;
}
Exemplo n.º 2
0
void encrypt_64blocks(u256 x[32], u256 rk[40][16]) {

  int i, j;
  u256 rc, tmp[8];
  rc = _mm256_set_epi64x(0x000000FF000000FFull,
                         0x000000FF000000FFull,
                         0x000000FF000000FFull,
                         0x000000FF000000FFull);

  for(i = 0; i < 40; i++){
    //SubBytes
    for(j = 0; j < 4; j++) {
      tmp[7] = XOR(x[2 + 8*j], NOR(XOR(x[3 + 8*j], NOR(x[0 + 8*j],x[1 + 8*j])),XOR(x[7 + 8*j], NOR(x[4 + 8*j],x[5 + 8*j]))));
      tmp[6] = XOR(x[3 + 8*j], NOR(x[0 + 8*j],x[1 + 8*j]));
      tmp[5] = XOR(x[7 + 8*j], NOR(x[4 + 8*j],x[5 + 8*j]));
      tmp[4] = XOR(x[4 + 8*j], NOR(XOR(x[2 + 8*j], NOR(XOR(x[3 + 8*j], NOR(x[0 + 8*j],x[1 + 8*j])),XOR(x[7 + 8*j], NOR(x[4 + 8*j],x[5 + 8*j])))),XOR(x[3 + 8*j], NOR(x[0 + 8*j],x[1 + 8*j]))));
      tmp[3] = XOR(x[6 + 8*j], NOR(XOR(x[7 + 8*j], NOR(x[4 + 8*j],x[5 + 8*j])),x[4 + 8*j]));
      tmp[2] = XOR(x[1 + 8*j], NOR(x[5 + 8*j],x[6 + 8*j]));
      tmp[1] = XOR(x[0 + 8*j], NOR(XOR(x[1 + 8*j], NOR(x[5 + 8*j],x[6 + 8*j])),XOR(x[2 + 8*j], NOR(XOR(x[3 + 8*j], NOR(x[0 + 8*j],x[1 + 8*j])),XOR(x[7 + 8*j], NOR(x[4 + 8*j],x[5 + 8*j]))))));
      tmp[0] = XOR(x[5 + 8*j], NOR(XOR(x[6 + 8*j], NOR(XOR(x[7 + 8*j], NOR(x[4 + 8*j],x[5 + 8*j])),x[4 + 8*j])),XOR(x[0 + 8*j], NOR(XOR(x[1 + 8*j], NOR(x[5 + 8*j],x[6 + 8*j])),XOR(x[2 + 8*j], NOR(XOR(x[3 + 8*j], NOR(x[0 + 8*j],x[1 + 8*j])),XOR(x[7 + 8*j], NOR(x[4 + 8*j],x[5 + 8*j]))))))));

      x[0 + 8*j] = tmp[7];
      x[1 + 8*j] = tmp[6];
      x[2 + 8*j] = tmp[5];
      x[3 + 8*j] = tmp[4];
      x[4 + 8*j] = tmp[3];
      x[5 + 8*j] = tmp[2];
      x[6 + 8*j] = tmp[1];
      x[7 + 8*j] = tmp[0];
    }

    //AddConstant
    //This only adds c2. The other constants are added with the key
    x[22] = XOR(x[22], rc);
  
    //AddKey
    x[0] = XOR(x[0], rk[i][0]);
    x[1] = XOR(x[1], rk[i][1]);
    x[2] = XOR(x[2], rk[i][2]);
    x[3] = XOR(x[3], rk[i][3]);
    x[4] = XOR(x[4], rk[i][4]);
    x[5] = XOR(x[5], rk[i][5]);
    x[6] = XOR(x[6], rk[i][6]);
    x[7] = XOR(x[7], rk[i][7]);
    x[8] = XOR(x[8], rk[i][8]);
    x[9] = XOR(x[9], rk[i][9]);
    x[10] = XOR(x[10], rk[i][10]);
    x[11] = XOR(x[11], rk[i][11]);
    x[12] = XOR(x[12], rk[i][12]);
    x[13] = XOR(x[13], rk[i][13]);
    x[14] = XOR(x[14], rk[i][14]);
    x[15] = XOR(x[15], rk[i][15]);
    
    //ShiftRows
    x[8]  = SR1(x[8]);  x[16] = SR2(x[16]); x[24] = SR3(x[24]);
    x[9]  = SR1(x[9]);  x[17] = SR2(x[17]); x[25] = SR3(x[25]);
    x[10] = SR1(x[10]); x[18] = SR2(x[18]); x[26] = SR3(x[26]);
    x[11] = SR1(x[11]); x[19] = SR2(x[19]); x[27] = SR3(x[27]);
    x[12] = SR1(x[12]); x[20] = SR2(x[20]); x[28] = SR3(x[28]);
    x[13] = SR1(x[13]); x[21] = SR2(x[21]); x[29] = SR3(x[29]);
    x[14] = SR1(x[14]); x[22] = SR2(x[22]); x[30] = SR3(x[30]);
    x[15] = SR1(x[15]); x[23] = SR2(x[23]); x[31] = SR3(x[31]);

    //MixColumns
    tmp[0] = x[24]; tmp[1] = x[25]; tmp[2] = x[26]; tmp[3] = x[27];
    tmp[4] = x[28]; tmp[5] = x[29]; tmp[6] = x[30]; tmp[7] = x[31];

    x[24] = XOR(x[16], x[0]); x[28] = XOR(x[20], x[4]);
    x[25] = XOR(x[17], x[1]); x[29] = XOR(x[21], x[5]);
    x[26] = XOR(x[18], x[2]); x[30] = XOR(x[22], x[6]);
    x[27] = XOR(x[19], x[3]); x[31] = XOR(x[23], x[7]);

    x[16] = XOR(x[8],  x[16]); x[20] = XOR(x[12], x[20]);
    x[17] = XOR(x[9],  x[17]); x[21] = XOR(x[13], x[21]);
    x[18] = XOR(x[10], x[18]); x[22] = XOR(x[14], x[22]);
    x[19] = XOR(x[11], x[19]); x[23] = XOR(x[15], x[23]);

    x[8]  = x[0]; x[12] = x[4];
    x[9]  = x[1]; x[13] = x[5];
    x[10] = x[2]; x[14] = x[6];
    x[11] = x[3]; x[15] = x[7];


    x[0] = XOR(tmp[0], x[24]); x[4] = XOR(tmp[4], x[28]);
    x[1] = XOR(tmp[1], x[25]); x[5] = XOR(tmp[5], x[29]);
    x[2] = XOR(tmp[2], x[26]); x[6] = XOR(tmp[6], x[30]);
    x[3] = XOR(tmp[3], x[27]); x[7] = XOR(tmp[7], x[31]); 
  }
}