Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- __global__
- void aes(unsigned char * in_bytes, unsigned char * key, int nBlocks) {
- int id = blockIdx.x * blockDim.x + threadIdx.x;
- __shared__ unsigned char cache[CACHE_SIZE];
- if (id <= nBlocks) {
- int idBlock = id * 16;
- for(int i = 0, idP = idBlock; i < 16; i++, idP++)
- cache[threadIdx.x * 16 + i] = in_bytes[idP];
- __syncthreads();
- unsigned char state[16];
- //Copia os primeiros 16 bytes para a memoria
- for(int i = 0; i < 16; i++)
- state[i] = cache[threadIdx.x * 16 + i];
- //Adiciona a primeira chave
- addRoundKey(state, key);
- //N-1 rodadas
- for(int i = 0; i < (R_ROUNDS -1); i++) {
- subBytes(state);
- shiftRows(state);
- mixColumns(state);
- //Seleciona a próxima chave
- addRoundKey(state, key + (16 * (i + 1)));
- }
- //Última rodada
- subBytes(state);
- shiftRows(state);
- addRoundKey(state, key + 160);
- //Copia a resposta para a memória
- for(int i = 0, idP = idBlock; i < 16; i++, idP++)
- in_bytes[idP] = state[i];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement