GSM ネットワーク KASUMI 暗号にレインボー テーブル攻撃のオンライン フェーズを実装しようとしています。
私は完全な 128 ビットのキースペースを 32 ビットのみ使用していません。以下は私の実装です。2 25行と各行に 2 7.88チェーン リンクを含む単一のレインボー テーブルを生成しました。これにより、73% の成功率が得られるはずです。
スペースを節約するために、エンドポイントのみを保存します。テーブルはバイナリ ファイルとして保存されます。終点がテーブル内のどの位置にあるかを確認することで、始点を見つけることができます。したがって、3 番目のエンドポイントの開始点は md5 が 3 であり、4 番目のエンドポイントは md5 が 4 というようになります。
問題は、ランダムなキーでテストすると、成功率が 10 ~ 15% になることです。適切なチェーンを生成することを確認するために、開始点をキーとして使用しました。ここでは、期待される 100% の成功が得られます。
エンディアンと関係があるのではないかと心配していますが、よくわかりません。
#include <stdio.h>
#include <stdint.h>
#include <pthread.h>
#include <time.h>
#include <openssl/md5.h>
#include <stdlib.h>
#include "cipher/kasumi.h"
#include "misc.h"
uint16_t * reduction(uint32_t m){
static uint16_t data[8];
data[0]=m>>16;
data[1]=m;
return data;
}
int inTable(uint32_t key,uint32_t * ciphertext, uint32_t * text){
uint16_t buffer[10000],*temp2,keys[8];
uint32_t endpoint, ep;
uint32_t cipher[2];
int cntr = 0,i,j,y,k;
FILE *ptr;
ptr = fopen("test32.bin","rb"); // r for read, b for binary */
for(;;){
size_t n=fread(buffer,sizeof(buffer),1,ptr);
k=0;
for(i=0;i<5000;i++){
endpoint = buffer[k] <<16 | buffer[k+1];
k=k+2;
if(endpoint==key){
temp2 = keyGen(cntr);
for (y = 0; y < 8; y++){
keys[y] = temp2[y%2];
}
for (j = 0; j < 236; j++){
keyschedule(keys);
temp2 = kasumi_enc(text);
cipher[0] = temp2[0]<<16 | temp2[1];
cipher[1] = temp2[2]<<16 | temp2[3];
ep = keys[0] << 16 | keys[1];
if(cipher[0]==ciphertext[0]&&cipher[1]==ciphertext[1]){
printf("Key found %i steps into chain \n", j);
printf("Key is the following: %04x \n",ep);
fclose(ptr);
return 1;
}
for (y = 0; y < 8; y++){
keys[y] = temp2[y % 2];
}
}
}
cntr = cntr+1;
}
if(n==0){
fclose(ptr);
return -1;
}
}
}
int onlinePhase(uint32_t * ciphertext, uint32_t * text){
int t, i;
uint16_t * temp;
uint32_t ep;
uint16_t key[8];
inTable(ciphertext[0],ciphertext,text);
temp = reduction(ciphertext[0]);
//reduciton function
for (i = 0; i < 8; i++){
key[i] = temp[i%2];
}
for (t = 0; t < 236; t++){
keyschedule(key);
temp = kasumi_enc(text);
//reduction function
for (i = 0; i < 8; i++){
key[i] = temp[i % 2];
}
ep = key[0]<<16 | key[1];
i=inTable(ep,ciphertext,text);
if (i>0)
return 1;
}
return 0;
}
uint16_t * randomme(){
int byte_count = 4;
static uint16_t data[8];
FILE *fp;
fp = fopen("/dev/urandom", "r");
fread(&data, 1, byte_count, fp);
fclose(fp);
return data;
}
int main(){
int i, j = 0, cntr = 0;
uint16_t key[8], * temp;
uint32_t text[2] = {
0xFEDCBA09, 0x87654321
};
uint32_t ciphertext[2];
while(j < 100){
temp = randomme();
for(i=0;i<8;i++){
*(key+i)=temp[i%2];
}
keyschedule(key);
temp = kasumi_enc(text);
ciphertext[0] = temp[0]<<16 | temp[1];
ciphertext[1] = temp[2]<<16 | temp[3];
printf("ciphertext %08x %08x \n",ciphertext[0],ciphertext[1]);
printf("key %04x %04x \n",key[0],key[1]);
cntr=cntr+onlinePhase(ciphertext, text);
j++;
}
printf("%i\n",cntr);
printf("%i\n",(cntr/j *100));
return 0;
}