Advertisement
Guest User

Untitled

a guest
Nov 21st, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.05 KB | None | 0 0
  1. __global__
  2. void aes(unsigned char * in_bytes, unsigned char * key, int nBlocks) {
  3.   int id = blockIdx.x * blockDim.x + threadIdx.x;
  4.   __shared__ unsigned char cache[CACHE_SIZE];
  5.  
  6.   if (id <= nBlocks) {
  7.     int idBlock = id * 16;
  8.     for(int i = 0, idP = idBlock; i < 16; i++, idP++)
  9.       cache[threadIdx.x * 16 + i] = in_bytes[idP];
  10.  
  11.     __syncthreads();
  12.  
  13.     unsigned char state[16];
  14.     //Copia os primeiros 16 bytes para a memoria
  15.     for(int i = 0; i < 16; i++)
  16.       state[i] = cache[threadIdx.x * 16 + i];
  17.  
  18.     //Adiciona a primeira chave
  19.     addRoundKey(state, key);
  20.  
  21.     //N-1 rodadas
  22.     for(int i = 0; i < (R_ROUNDS -1); i++) {
  23.       subBytes(state);
  24.       shiftRows(state);
  25.       mixColumns(state);
  26.  
  27.       //Seleciona a próxima chave
  28.       addRoundKey(state, key + (16 * (i + 1)));
  29.     }
  30.  
  31.     //Última rodada
  32.     subBytes(state);
  33.     shiftRows(state);
  34.     addRoundKey(state, key + 160);
  35.  
  36.     //Copia a resposta para a memória
  37.     for(int i = 0, idP = idBlock; i < 16; i++, idP++)
  38.       in_bytes[idP] = state[i];
  39.   }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement