Ejemplo n.º 1
0
void aesOmac1Mode(u8* output, u8* input, int len, u8* aes_key_data, int aes_key_bits) {
  int i,j;
  AES_KEY aes_key;
  AES_set_encrypt_key(aes_key_data, aes_key_bits, &aes_key);

  u8 running[0x10]; memset(running, 0, 0x10);
  u8 hash[0x10];
  u8 worthless[0x10];
//  u8 final[0x10];
  i=0;
  AES_encrypt(running, worthless, &aes_key);
  rol1(worthless);

  if(len > 0x10) {
    for(i=0;i<(len-0x10);i+=0x10) {
      for(j=0;j<0x10;j++) hash[j] = running[j] ^ input[i+j];
      AES_encrypt(hash, running, &aes_key);
    }
  }
  int overrun = len&0xF;
  if( (len%0x10) == 0 ) overrun = 0x10;

  memset(hash, 0, 0x10);
  memcpy(hash, &input[i], overrun);

  if(overrun != 0x10) {
    hash[overrun] = 0x80;
    rol1(worthless);
  }

  for(j=0;j<0x10;j++) hash[j] ^= running[j] ^ worthless[j];
  AES_encrypt(hash, output, &aes_key);
}
Ejemplo n.º 2
0
/*
  Hashes 'data', which should be a pointer to 512 bits of data (sixteen
  32 bit ints), into the ongoing 160 bit hash value (five 32 bit ints)
  'hash'
*/
int 
sha_hash(int *data, int *hash)  
{
  int W[80];
  unsigned int A=hash[0], B=hash[1], C=hash[2], D=hash[3], E=hash[4];
  unsigned int t, x, TEMP;

  for (t=0; t<16; t++) 
    {
#ifndef WORDS_BIGENDIAN
      W[t]=switch_endianness(data[t]);
#else 
      W[t]=data[t];
#endif
    }


  /* SHA1 Data expansion */
  for (t=16; t<80; t++) 
    {
      x=W[t-3] ^ W[t-8] ^ W[t-14] ^ W[t-16];
      W[t]=rol1(x);
    }

  /* SHA1 main loop (t=0 to 79) 
   This is broken down into four subloops in order to use
   the correct round function and constant */
  for (t=0; t<20; t++) 
    {
      TEMP=rol5(A) + f1(B,C,D) + E + W[t] + K1;
      E=D;
      D=C;
      C=rol30(B);
      B=A;
      A=TEMP;
    }
  for (; t<40; t++) 
    {
      TEMP=rol5(A) + f2(B,C,D) + E + W[t] + K2;
      E=D;
      D=C;
      C=rol30(B);
      B=A;
      A=TEMP;
    }
  for (; t<60; t++) 
    {
      TEMP=rol5(A) + f3(B,C,D) + E + W[t] + K3;
      E=D;
      D=C;
      C=rol30(B);
      B=A;
      A=TEMP;
    }
  for (; t<80; t++) 
    {
      TEMP=rol5(A) + f2(B,C,D) + E + W[t] + K4;
      E=D;
      D=C;
      C=rol30(B);
      B=A;
      A=TEMP;
    }
  hash[0]+=A; 
  hash[1]+=B;
  hash[2]+=C;
  hash[3]+=D;
  hash[4]+=E;
  return 0;
}