Esempio n. 1
0
void Rijndael::Init(bool Encrypt,const byte *key,uint keyLen,const byte * initVector)
{
  uint uKeyLenInBytes;
  switch(keyLen)
  {
    case 128:
      uKeyLenInBytes = 16;
      m_uRounds = 10;
      break;
    case 192:
      uKeyLenInBytes = 24;
      m_uRounds = 12;
      break;
    case 256:
      uKeyLenInBytes = 32;
      m_uRounds = 14;
      break;
  }

  byte keyMatrix[_MAX_KEY_COLUMNS][4];

  for(uint i = 0; i < uKeyLenInBytes; i++)
    keyMatrix[i >> 2][i & 3] = key[i]; 

  for(int i = 0; i < MAX_IV_SIZE; i++)
    m_initVector[i] = initVector[i];

  keySched(keyMatrix);

  if(!Encrypt)
    keyEncToDec();
}
Esempio n. 2
0
void Rijndael::init(Direction dir,const byte * key,byte * initVector)
{
  m_direction = dir;

  byte keyMatrix[_MAX_KEY_COLUMNS][4];

  for(uint i = 0;i < uKeyLenInBytes;i++)
    keyMatrix[i >> 2][i & 3] = key[i]; 

  for(int i = 0;i < MAX_IV_SIZE;i++)
    m_initVector[i] = initVector[i];

  keySched(keyMatrix);

  if(m_direction == Decrypt)
    keyEncToDec();
}
Esempio n. 3
0
void Rijndael::Init(bool Encrypt,const byte *key,uint keyLen,const byte * initVector)
{
#ifdef USE_SSE
  // Check SSE here instead of constructor, so if object is a part of some
  // structure memset'ed before use, this variable is not lost.
  int CPUInfo[4];
  __cpuid(CPUInfo, 1);
  AES_NI=(CPUInfo[2] & 0x2000000)!=0;
#endif

  uint uKeyLenInBytes;
  switch(keyLen)
  {
    case 128:
      uKeyLenInBytes = 16;
      m_uRounds = 10;
      break;
    case 192:
      uKeyLenInBytes = 24;
      m_uRounds = 12;
      break;
    case 256:
      uKeyLenInBytes = 32;
      m_uRounds = 14;
      break;
  }

  byte keyMatrix[_MAX_KEY_COLUMNS][4];

  for(uint i = 0; i < uKeyLenInBytes; i++)
    keyMatrix[i >> 2][i & 3] = key[i];

  if (initVector==NULL)
    memset(m_initVector, 0, sizeof(m_initVector));
  else
    for(int i = 0; i < MAX_IV_SIZE; i++)
      m_initVector[i] = initVector[i];

  keySched(keyMatrix);

  if(!Encrypt)
    keyEncToDec();
}