[Crypto] Implementing DES (1)
아직 작성이 완료되지 않은 글입니다.
이 글은 Christof Paar & Jan Pelzl의 Understanding Cryptography를 기반으로 작성된 글입니다.
DES에 대한 기본적인 이해와 Block Cypher의 기본적인 특성에 대한 이해를 전제로 합니다.
0. Precondition
- 입력은 항상 8바이트이며,
char *형태로 받는다.
입력을 8바이트로 고정하는 이유는 Operation Mode에 대한 고려를 피하기 위함이다. - 출력은 cyphertext를 byte단위로 끊어 hex로 출력한다.
- DES는 bitwise한 연산이 많은데, bitwise 연산을 쓸 경우 endianness때문에 고려해야할 것이 많아지므로
unsigned int *배열의 각 원소가 각 비트에 대응되도록 짰다. - 배열은 0부터 시작하지만 여기서는 편의를 위해 인덱스를 1부터 시작하도록 했다.
따라서 여기서 사용하는 모든 배열의 크기는 원래 필요한 크기보다 하나씩 크다.
1. 전처리
unsigned int *to_bitarray(const char *source) {
// Discard leading byte of buffer
unsigned int *buffer = malloc(65 * sizeof(unsigned int));
// unsigned int temp;
unsigned char current_byte = 0;
for (int i = 0; i < 8; i++) {
current_byte = source[i];
for (int j = 0; j < 8; j++) {
buffer[i * 8 + j + 1] = ((current_byte & (1 << (7 - j))) >> (7 - j));
}
}
return buffer;
}
주어진 입력을
Leave a comment