a
[AES] GPU cuda
박은성/
2022. 4. 4. 20:13
반응형
__device__ void rotateLeft(byte *A){
byte i;
byte aux = A[0];
for(i=0; i<3; i++){
A[i] = A[i+1];
}
A[3] = aux;
}
__global__ void key_expansion(byte *key, byte *expanded_key, byte *d_sbox, byte *d_rcon)}
byte temp[4];
byte c = 16;
byte j, a, i = 0;
for(j; j<16; j++){
expanded_key[j] = key[j];
}
if(c % 16 == 0){ //c가 16의 배수일 때
rotateLeft(temp);
for(a; a<4; a++){
temp[a] = get_sbox(temp[a], d_sbox);
}
temp[0] = temp[0] ^ d_rcon[i];
i++;
}
for(a; a<4; a++){
expanded_key[c] = expanded_key[c-16] ^ temp[a];
c++;
}
}
}
__device__ void add_round_key(byte *state, int round, byte *expanded_key){
int i,j;
for(i = 0;i< 4; i++){
for(j = 0;j< 4; j++){
state[i*4+j] ^= expanded_key[round*16 +i*4 +j];
}
}
}
__device__ void subbytes(byte *state, byte *d_sbox){
byte i,j;
for(i=0; i<4; i++){
for(j=0; j<4; j++){
state[j*4+i] = get_sbox(state[j*4+i], d_sbox);
}
}
}
반응형